From cb3d36f15b4561ceeafc6917e9428cabeed61a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caner=20K=C4=B1l=C4=B1=C3=A7o=C4=9Flu?= Date: Mon, 11 Nov 2024 16:12:05 +0300 Subject: [PATCH] @Eat trigger stat increases are not disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trigger was triggered after values ​​were changed and hits, stam, mana gain could not be turned off. --- Changelog.txt | 3 ++ src/game/chars/CCharAct.cpp | 105 +++++++++++++++++++++++------------- 2 files changed, 72 insertions(+), 36 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 034689fd8..2bdd53b39 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3914,3 +3914,6 @@ Added: 'H' shortcut for variables to get the value as hexadecimal. 13-10-2024, Jhobean - Added: @PetRelease trigger work like @petdesert and return 1 to prevent the pet from being released. + +-11-11-2024, canerksk +- Fixed: Hits, stam and mana increases were not disabled in the Eat trigger, now if the local values ​​are zero, hits, stam, mana are set to not increase. Those who want to increase can enter these local values. Also, anim and sound were added to the local variables. The trigger was not triggered after the values ​​changed, as a temporary solution, it was made to trigger after the values ​​changed, so now when you eat a meal, @Eat is triggered twice, once before the values ​​change and once after the values ​​change. \ No newline at end of file diff --git a/src/game/chars/CCharAct.cpp b/src/game/chars/CCharAct.cpp index b4c427f1a..7a251ba49 100644 --- a/src/game/chars/CCharAct.cpp +++ b/src/game/chars/CCharAct.cpp @@ -3413,56 +3413,89 @@ bool CChar::ItemEquip( CItem * pItem, CChar * pCharMsg, bool fFromDClick ) // OnEat() // Generating eating animation // also calling @Eat and setting food's level (along with other possible stats 'local.hits',etc?) -void CChar::EatAnim(CItem* pItem, ushort uiQty) +void CChar::EatAnim(CItem *pItem, ushort uiQty) { - ADDTOCALLSTACK("CChar::EatAnim"); + ADDTOCALLSTACK("CChar::EatAnim"); ASSERT(pItem); //Should never happen, but make sure item is valid. - static const SOUND_TYPE sm_EatSounds[] = { 0x03a, 0x03b, 0x03c }; - Sound(sm_EatSounds[g_Rand.GetVal(ARRAY_COUNT(sm_EatSounds))]); - - if ( !IsStatFlag(STATF_ONHORSE) ) - UpdateAnimate(ANIM_EAT); + static const SOUND_TYPE sm_EatSounds[] = { 0x03a, 0x03b, 0x03c }; EMOTEFLAGS_TYPE eFlag = (IsPlayer() ? EMOTEF_HIDE_EAT_PLAYER : EMOTEF_HIDE_EAT_NPC); if (!IsSetEmoteFlag(eFlag)) { - tchar* pszMsg = Str_GetTemp(); + tchar *pszMsg = Str_GetTemp(); snprintf(pszMsg, Str_TempLength(), g_Cfg.GetDefaultMsg(DEFMSG_MSG_EATSOME), pItem->GetName()); Emote(pszMsg); } - ushort uiHits = 0; - ushort uiMana = 0; - ushort uiStam = (ushort)( g_Rand.GetVal2(3, 6) + (uiQty / 5) ); - ushort uiFood = uiQty; - ushort uiStatsLimit = 0; - if (IsTrigUsed(TRIGGER_EAT)) - { - CScriptTriggerArgs Args(uiStatsLimit); - Args.m_VarsLocal.SetNumNew("Hits", uiHits); - Args.m_VarsLocal.SetNumNew("Mana", uiMana); - Args.m_VarsLocal.SetNumNew("Stam", uiStam); - Args.m_VarsLocal.SetNumNew("Food", uiFood); + SOUND_TYPE sound = sm_EatSounds[g_Rand.GetVal(ARRAY_COUNT(sm_EatSounds))]; + ANIM_TYPE animType = ANIM_EAT; + ushort uiHits = 0; + ushort uiMana = 0; + ushort uiStam = (ushort)(g_Rand.GetVal2(3, 6) + (uiQty / 5)); + ushort uiFood = uiQty; + ushort uiStatsLimit = 0; + CScriptTriggerArgs Args(uiStatsLimit); + if (IsTrigUsed(TRIGGER_EAT)) + { + Args.m_VarsLocal.SetNumNew("Hits", uiHits); + Args.m_VarsLocal.SetNumNew("Mana", uiMana); + Args.m_VarsLocal.SetNumNew("Stam", uiStam); + Args.m_VarsLocal.SetNumNew("Food", uiFood); + Args.m_VarsLocal.SetNumNew("Anim", animType); + Args.m_VarsLocal.SetNumNew("Sound", sound); Args.m_pO1 = pItem; - if ( OnTrigger(CTRIG_Eat, this, &Args) == TRIGRET_RET_TRUE ) - return; + if (OnTrigger(CTRIG_Eat, this, &Args) == TRIGRET_RET_TRUE) + return; + + uiHits = (ushort)(Args.m_VarsLocal.GetKeyNum("Hits")); + uiMana = (ushort)(Args.m_VarsLocal.GetKeyNum("Mana")); + uiStam = (ushort)(Args.m_VarsLocal.GetKeyNum("Stam")); + uiFood = (ushort)(Args.m_VarsLocal.GetKeyNum("Food")); + animType = static_cast(Args.m_VarsLocal.GetKeyNum("Anim")); + sound = (SOUND_TYPE)(Args.m_VarsLocal.GetKeyNum("Sound")); + uiStatsLimit = (ushort)(Args.m_iN1); + } - uiHits = (ushort)(Args.m_VarsLocal.GetKeyNum("Hits")) + Stat_GetVal(STAT_STR); - uiMana = (ushort)(Args.m_VarsLocal.GetKeyNum("Mana")) + Stat_GetVal(STAT_INT); - uiStam = (ushort)(Args.m_VarsLocal.GetKeyNum("Stam")) + Stat_GetVal(STAT_DEX); - uiFood = (ushort)(Args.m_VarsLocal.GetKeyNum("Food")) + Stat_GetVal(STAT_FOOD); - uiStatsLimit = (ushort)(Args.m_iN1); - } + Sound(sound); + + if (!IsStatFlag(STATF_ONHORSE)) + UpdateAnimate(animType); + + if (uiHits > 0) + { + uiHits += Stat_GetVal(STAT_STR); + UpdateStatVal(STAT_STR, uiHits, uiStatsLimit); + } + if (uiMana > 0) + { + uiMana += Stat_GetVal(STAT_INT); + UpdateStatVal(STAT_INT, uiMana, uiStatsLimit); + } + if (uiStam > 0) + { + uiStam += Stat_GetVal(STAT_DEX); + UpdateStatVal(STAT_DEX, uiStam, uiStatsLimit); + } + if (uiFood > 0) + { + uiFood += Stat_GetVal(STAT_FOOD); + UpdateStatVal(STAT_FOOD, uiFood, uiStatsLimit); + } + + // It didn't mean much since it wasn't triggered after the values ​​changed. + if (IsTrigUsed(TRIGGER_EAT)) + { + Args.m_VarsLocal.SetNumNew("Hits", uiHits); + Args.m_VarsLocal.SetNumNew("Mana", uiMana); + Args.m_VarsLocal.SetNumNew("Stam", uiStam); + Args.m_VarsLocal.SetNumNew("Food", uiFood); + Args.m_VarsLocal.SetNumNew("Anim", animType); + Args.m_VarsLocal.SetNumNew("Sound", sound); + Args.m_pO1 = pItem; + OnTrigger(CTRIG_Eat, this, &Args); + } - if ( uiHits ) - UpdateStatVal(STAT_STR, uiHits, uiStatsLimit); - if ( uiMana ) - UpdateStatVal(STAT_INT, uiMana, uiStatsLimit); - if ( uiStam ) - UpdateStatVal(STAT_DEX, uiStam, uiStatsLimit); - if ( uiFood ) - UpdateStatVal(STAT_FOOD, uiFood, uiStatsLimit); } // Some outside influence may be revealing us.