Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Eat trigger stat increases are not disabled #1333

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
105 changes: 69 additions & 36 deletions src/game/chars/CCharAct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ANIM_TYPE>(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.
Expand Down