Skip to content

Commit

Permalink
Couple of Fixes and Feature Updates
Browse files Browse the repository at this point in the history
* Couple of Fixes and Feature Updates (#1120)
- Fixed: Re-Coded @KarmaChange and @FameChange triggers not setting variables correctly. (Issue #1118)
	ARGN1 now return as the amount of Karma/Fame being added.
	LOCAL.OLD and LOCAL.NEW removed, while ARGN1 is writeable, it's impossible to track that values in the trigger.
	ARGO now return the source of karma/fame income if exists.
- Added: @KarmaChanged and @FameChanged triggers to track Karma/Fame changes after @KarmaChange/@FameChange triggered.
	ARGN1 returns the amount of Karma/Fame being added.
	LOCAL.OLD returns the karma value before added anything.
	LOCAL.NEW returns the current player karma.
	This trigger has no RETURN value to block hardcoded events while it triggers after everything finished.
- Fixed: f_onchar_create_init is not called. (Issue: #1117)
- Fixed: IF and QVAL statements cannot evaluate correctly 32bit+ bitwise conditions. (Issue: #1078)
- Added: @PartyAdd trigger. (Feature Request: #1054)
	I: The player who is joining to the party.
	SRC: The player who is inviting.
	Return 1: Cancels the action.
- Added: LOCAL.SOUND and LOCAL.ANIM under @start (Skill) and @SkillStart triggers to override sound and animations before start crafting or gathering.
- Fixed: FACTION property not saved and load correctly under [CHARDEF] definition. (Issue: #1059 and #1083)
- Added: COMBAT_PARALYZE_CANSWING flag.
- Fixed: pet issue of AttackingIsACrime.
- Added: Added CAN_I_EQUIPONCAST (08000000) flag for items to let scripters customize allowed items while EquippedCast disabled.
- Fixed: Spells can trigger @success triggers and play animations if they paralyzed after selected skill.
- Fixed: Motivation < 0 causes STATF_WAR flag stay infinitely on characters. (Issue: #517)
- Fixed: The issue where characters can spawn out of the rooms. (Issue: #1084)
- Fixed: More1 and More2 values readn as integer instead of dword (unsigned integer) (Issue: #784)
  • Loading branch information
xwerswoodx authored Oct 11, 2023
1 parent 06e8378 commit fb36db1
Show file tree
Hide file tree
Showing 25 changed files with 198 additions and 95 deletions.
22 changes: 22 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3352,6 +3352,28 @@ Additionally, the problem of zig-zag issue following in the South direction has
26-09-2023, Drk84
- Fixed: Ship plank disappearing when closed before its timer expires or after a save is performed.

02-10-2023, xwerswoodx
- Fixed: Re-Coded @KarmaChange and @FameChange triggers not setting variables correctly. (Issue #1118)
ARGN1 now return as the amount of Karma/Fame being added.
ARGN2 is now return oldKarma. (ARGN2 + ARGN1 == New Karma)
LOCAL.NEW removed, while ARGN1 is writeable, it's impossible to track it inside the trigger.
ARGO now return the source of karma/fame income if exists.
- Fixed: f_onchar_create_init is not called. (Issue: #1117)
- Fixed: IF and QVAL statements cannot evaluate correctly 32bit+ bitwise conditions. (Issue: #1078)
- Added: @PartyAdd trigger. (Feature Request: #1054)
I: The player who is joining to the party.
SRC: The player who is inviting.
Return 1: Cancels the action.
- Added: LOCAL.SOUND and LOCAL.ANIM under @Start (Skill) and @SkillStart triggers to override sound and animations before start crafting or gathering.
- Fixed: FACTION property not saved and load correctly under [CHARDEF] definition. (Issue: #1059 and #1083)
- Added: Added COMBAT_PARALYZE_CANSWING (080000) to combat flags to let characters continue attack while paralyzed like old behaviour. (Issue: #1124)
- Fixed: ATTACK command causes the player getting criminal without checking AttackingIsACrime value in sphere.ini (Issue: #1123)
- Added: Added CAN_I_EQUIPONCAST (08000000) flag for items to let scripters customize allowed items while EquippedCast disabled.
- Fixed: Spells can trigger @Success triggers and play animations if they paralyzed after selected skill.
- Fixed: Motivation < 0 causes STATF_WAR flag stay infinitely on characters. (Issue: #517)
- Fixed: The issue where characters can spawn out of the rooms. (Issue: #1084)
- Fixed: More1 and More2 values readn as integer instead of dword (unsigned integer) (Issue: #784)

07-10-2023, Nolok
- Added: FUNC keyword to item templates and template-triggers with special parsing (@Create, @CreateLoot, @NPCRestock). It allows to call a function with arguments on the last created ITEM.
Default object: the item. SRC: the character holding it.
Expand Down
4 changes: 2 additions & 2 deletions src/common/CScriptObj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ bool CScriptObj::_Evaluate_Conditional_EvalSingle(SubexprData& sdata, CTextConso
// If an expression is enclosed by parentheses, ParseScriptText needs to read both the open and the closed one, we cannot
// pass the string starting with the character after the '('.
ParseScriptText(ptcSubexpr, pSrc, 0, pArgs);
fVal = bool(Exp_GetVal(ptcSubexpr));
fVal = bool(Exp_GetLLVal(ptcSubexpr));
}

-- pContext->_iEvaluate_Conditional_Reentrant;
Expand Down Expand Up @@ -1708,7 +1708,7 @@ bool CScriptObj::Evaluate_QvalConditional(lpctstr ptcKey, CSString& sVal, CTextC
tchar* ptcTemp = Str_GetTemp();
Str_CopyLimitNull(ptcTemp, ppCmds[0], STR_TEMPLENGTH);
ParseScriptText(ptcTemp, pSrc, 0, pArgs, pContext);
const bool fCondition = Exp_GetVal(ptcTemp);
const bool fCondition = Exp_GetLLVal(ptcTemp);

// Get the retval we want
// (we might as well work on the transformed original string, since at this point we don't care if we corrupt other arguments)
Expand Down
6 changes: 3 additions & 3 deletions src/game/CBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void CBaseBaseDef::DelInstance()
--_dwInstances;
}

CFactionDef CBaseBaseDef::GetFaction()
CCFaction CBaseBaseDef::GetFaction()
{
return _pFaction;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ bool CBaseBaseDef::r_WriteVal( lpctstr ptcKey, CSString & sVal, CTextConsole * p

case OBC_FACTION:
case OBC_SLAYER:
sVal.FormatHex((dword)GetFaction().GetFactionID());
sVal.FormatULLHex(_pFaction.GetFactionID());
break;

case OBC_ARMOR:
Expand Down Expand Up @@ -329,7 +329,7 @@ bool CBaseBaseDef::r_LoadVal( CScript & s )
break;
case OBC_FACTION:
case OBC_SLAYER:
GetFaction().SetFactionID( (NPC_FACTION)s.GetArgVal() );
_pFaction.SetFactionID( static_cast<NPC_FACTION>(s.GetArgULLVal()) );
return true;
//Set as number only
case OBC_EXPANSION:
Expand Down
5 changes: 3 additions & 2 deletions src/game/CBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ struct CBaseBaseDef : public CResourceLink, public CEntityProps
dword m_Can; // Base attribute flags. CAN_C_GHOST, etc
RESDISPLAY_VERSION _iEraLimitProps; // Don't allow to have properties newer than the given era.

CFactionDef _pFaction;
CCFaction _pFaction;


public:
CFactionDef GetFaction();
CCFaction GetFaction();

/**
* @brief Gets definition string.
Expand Down Expand Up @@ -153,6 +153,7 @@ struct CBaseBaseDef : public CResourceLink, public CEntityProps
#define CAN_I_FORCEDC 0x1000000 // Can force DClick skipping other checks (LOS,Distance, Cont...).
#define CAN_I_DAMAGEABLE 0x2000000 // Display item health bar on HS clients >= 7.0.30.0 (MORE1L = cur hitpoints / MORE1H = max hitpoints)
#define CAN_I_BLOCKLOS_HEIGHT 0x4000000 // blocks LOS without blocking walkchecks, but only if the item is too high for the viewer.
#define CAN_I_EQUIPONCAST 0x8000000 // Allow items to stay equipped while EquippedCast disabled in sphere.ini.

// (CItemBase) CanEquip specific defs.
#define CAN_U_ALL 0x000 // Can be used by everyone.
Expand Down
5 changes: 3 additions & 2 deletions src/game/CObjBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ enum CTRIG_TYPE : short
CTRIG_ExpChange, // EXP is going to change
CTRIG_ExpLevelChange, // Experience LEVEL is going to change
CTRIG_Falling, // CHAR IS FALLING
CTRIG_FameChange, // Fame chaged
CTRIG_FameChange, // Fame is changing
CTRIG_FollowersUpdate, // Adding or removing CurFollowers.

CTRIG_GetHit, // I just got hit.
Expand Down Expand Up @@ -1174,7 +1174,7 @@ enum CTRIG_TYPE : short
CTRIG_itemUNEQUIP, // i have unequipped (or try to unequip) an item.

CTRIG_Jailed, // I'm up to be send to jail, or to be forgiven.
CTRIG_KarmaChange, // Karma chaged
CTRIG_KarmaChange, // Karma is changing
CTRIG_Kill, // I have just killed someone.
CTRIG_LogIn, // Client logs in.
CTRIG_LogOut, // Client logs out (21).
Expand All @@ -1200,6 +1200,7 @@ enum CTRIG_TYPE : short
CTRIG_NPCSeeWantItem, // (NPC only) i see something good.
CTRIG_NPCSpecialAction, // (NPC only) performing some special actions (spyder's web, dragon's breath...).

CTRIG_PartyAdd, // Player joined to the party.
CTRIG_PartyDisband, // I just disbanded my party.
CTRIG_PartyInvite, // SRC invited me to join a party, so I may chose.
CTRIG_PartyLeave, // I'm leaving this party.
Expand Down
3 changes: 2 additions & 1 deletion src/game/CServerConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ enum COMBATFLAGS_TYPE
COMBAT_ANIM_HIT_SMOOTH = 0x10000, // The hit animation has the same duration as the swing delay, instead of having a fixed fast duration and being idle until the delay has expired.
// WARNING: doesn't work with Gargoyles due to the new animation packet not accepting a custom animation duration!
COMBAT_FIRSTHIT_INSTANT = 0x20000, // The first hit in a fight doesn't wait for the recoil time (OSI like)
COMBAT_NPC_BONUSDAMAGE = 0x40000 // NPC will get full bonus damage from various sources.
COMBAT_NPC_BONUSDAMAGE = 0x40000, // NPC will get full bonus damage from various sources.
COMBAT_PARALYZE_CANSWING = 0x80000 // Characters can continue attacking while paralyzed. (Old sphere behaviour)
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/game/CWorldImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,12 @@ bool CImportFile::ImportWSC( CScript & s, word wModeFlags )
}
else if ( s.IsKey("MORE" ))
{
pItem->m_itNormal.m_more1 = atoi(pArg);
pItem->m_itNormal.m_more1 = Str_ToUI(pArg);
continue;
}
else if ( s.IsKey("MORE2" ))
{
pItem->m_itNormal.m_more2 = atoi(pArg);
pItem->m_itNormal.m_more2 = Str_ToUI(pArg);
continue;
}
else if ( s.IsKey("DYEABLE" ))
Expand Down
11 changes: 5 additions & 6 deletions src/game/chars/CChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ lpctstr const CChar::sm_szTrigName[CTRIG_QTY+1] = // static
"@ExpChange", // EXP is going to change
"@ExpLevelChange", // Experience LEVEL is going to change
"@Falling", //char is falling from height >= 10
"@FameChange", // Fame changed
"@FameChange", // Fame is changing
"@FollowersUpdate",

"@GetHit", // I just got hit.
Expand Down Expand Up @@ -129,8 +129,8 @@ lpctstr const CChar::sm_szTrigName[CTRIG_QTY+1] = // static
"@itemUNEQUIP", // i have unequipped (or try to unequip) an item

"@Jailed",
"@KarmaChange", // Karma chaged
"@Kill", //+I have just killed someone
"@KarmaChange", // Karma is changing
"@Kill", // +I have just killed someone
"@LogIn", // Client logs in
"@LogOut", // Client logs out (21)
"@Mount", // I'm trying to mount my horse (or whatever)
Expand All @@ -155,6 +155,7 @@ lpctstr const CChar::sm_szTrigName[CTRIG_QTY+1] = // static
"@NPCSeeWantItem", // (NPC only) i see something good.
"@NPCSpecialAction", // Idle

"@PartyAdd", // Player joined the party.
"@PartyDisband", //I just disbanded my party
"@PartyInvite", //SRC invited me to join a party, so I may chose
"@PartyLeave",
Expand Down Expand Up @@ -319,9 +320,7 @@ CChar::CChar( CREID_TYPE baseID ) :
// SubscribeComponent Prop Components
TrySubscribeComponentProps<CCPropsChar>();
TrySubscribeComponentProps<CCPropsItemChar>();

// SubscribeComponent regular Components
SubscribeComponent(new CCFaction());
SubscribeComponent(new CCFaction(pCharDef->GetFaction()));

ASSERT(IsDisconnected());
}
Expand Down
10 changes: 5 additions & 5 deletions src/game/chars/CChar.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@ public: void StatFlag_Mod(uint64 uiStatFlag, bool fMod) noexcept;
SKILLLOCK_TYPE Stat_GetLock(STAT_TYPE stat);
void Stat_SetLock(STAT_TYPE stat, SKILLLOCK_TYPE state);
short GetKarma() const;
void SetKarma(short iNewKarma);
void SetKarma(short iNewKarma, CChar* pNPC = nullptr);
ushort GetFame() const;
void SetFame(ushort uiNewFame);
void SetFame(ushort uiNewFame, CChar* pNPC = nullptr);

void Stat_StrCheckEquip();

Expand Down Expand Up @@ -606,7 +606,7 @@ public: void StatFlag_Mod(uint64 uiStatFlag, bool fMod) noexcept;
* @param iBottom is the lower value you can have for this execution.
* @param bMessage show message to the char or not.
*/
void Noto_Karma( int iKarmaChange, int iBottom = INT32_MIN, bool fMessage = false );
void Noto_Karma( int iKarmaChange, int iBottom = INT32_MIN, bool fMessage = false, CChar* pNPC = nullptr );

/**
* @brief Update Fame with the given value.
Expand All @@ -615,7 +615,7 @@ public: void StatFlag_Mod(uint64 uiStatFlag, bool fMod) noexcept;
* Can't never exceed g_Cfg.m_iMaxFame and can't never be lower than 0.
* @param iFameChange is the amount of fame to change over the current one.
*/
void Noto_Fame( int iFameChange );
void Noto_Fame( int iFameChange, CChar* pNPC = nullptr );

/**
* @brief I have a new notoriety Level? check it and show a message if so.
Expand Down Expand Up @@ -1256,7 +1256,7 @@ public: void StatFlag_Mod(uint64 uiStatFlag, bool fMod) noexcept;
void NPC_Act_Fight();
void NPC_Act_Idle();
void NPC_Act_Looting();
void NPC_Act_Flee();
bool NPC_Act_Flee();
void NPC_Act_Goto(int iDist = 30);
void NPC_Act_Runto(int iDist = 30);
bool NPC_Act_Food();
Expand Down
1 change: 0 additions & 1 deletion src/game/chars/CCharBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ void CCharBase::CopyBasic( const CCharBase * pCharDef )
_uiRange = pCharDef->_uiRange;

m_BaseResources = pCharDef->m_BaseResources;
_pFaction = pCharDef->_pFaction;

CBaseBaseDef::CopyBasic( pCharDef ); // This will overwrite the CResourceLink!!
}
Expand Down
16 changes: 11 additions & 5 deletions src/game/chars/CCharFight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,20 @@ bool CChar::OnAttackedBy(CChar * pCharSrc, bool fCommandPet, bool fShouldReveal)
Memory_AddObjTypes(pCharSrc, wMemTypes);
Attacker_Add(pCharSrc);

// Are they a criminal for it ? Is attacking me a crime ?
if ((Noto_GetFlag(pCharSrc) == NOTO_GOOD) && fAggreived)
if ((Noto_GetFlag(pCharSrc) == NOTO_GOOD) && fAggreived )
{
if (IsClientActive()) // I decide if this is a crime.
OnNoticeCrime(pCharSrc, this);
{
if (!fCommandPet || g_Cfg.m_fAttackingIsACrime)
{
OnNoticeCrime(pCharSrc, this);
CChar* pCharMark = pCharSrc->IsStatFlag(STATF_PET) ? pCharSrc->NPC_PetGetOwner() : pCharSrc;
if (pCharMark != pCharSrc)
OnNoticeCrime(pCharMark, this);
}
}
else
{
// If it is a pet then this a crime others can report.
CChar * pCharMark = IsStatFlag(STATF_PET) ? NPC_PetGetOwner() : this;
pCharSrc->CheckCrimeSeen(Skill_GetActive(), pCharMark, nullptr, nullptr);
}
Expand Down Expand Up @@ -1567,7 +1573,7 @@ WAR_SWING_TYPE CChar::Fight_CanHit(CChar * pCharSrc, bool fSwingNoRange)
// We can't hit them right now. Because we can't see them or reach them (invis/hidden).
// Why the target is freeze we are change the attack type to swinging? Player can still attack paralyzed or sleeping characters.
// We make sure that the target is freeze or sleeping must wait ready for attack!
else if ( (pCharSrc->IsStatFlag(STATF_HIDDEN | STATF_INVISIBLE | STATF_SLEEPING)) || (IsStatFlag(STATF_FREEZE | STATF_SLEEPING)) ) // STATF_FREEZE | STATF_SLEEPING
else if ( (pCharSrc->IsStatFlag(STATF_HIDDEN | STATF_INVISIBLE | STATF_SLEEPING)) || (IsStatFlag(STATF_FREEZE) && (!IsSetCombatFlags(COMBAT_PARALYZE_CANSWING))) || (IsStatFlag(STATF_SLEEPING)) ) // STATF_FREEZE | STATF_SLEEPING
{
return WAR_SWING_SWINGING;
}
Expand Down
7 changes: 4 additions & 3 deletions src/game/chars/CCharNPCAct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ void CChar::NPC_Act_Looting()
ItemBounce(pItem, false);
}

void CChar::NPC_Act_Flee()
bool CChar::NPC_Act_Flee()
{
ADDTOCALLSTACK("CChar::NPC_Act_Flee");
ASSERT(m_pNPC);
Expand All @@ -1581,13 +1581,14 @@ void CChar::NPC_Act_Flee()
if ( ++ m_atFlee.m_iStepsCurrent >= m_atFlee.m_iStepsMax )
{
Skill_Start( SKILL_NONE );
return;
return false;
}
if ( ! NPC_Act_Follow( true, m_atFlee.m_iStepsMax ))
{
Skill_Start( SKILL_NONE );
return;
return false;
}
return true;
}

void CChar::NPC_Act_Runto(int iDist)
Expand Down
13 changes: 12 additions & 1 deletion src/game/chars/CCharNPCAct_Fight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,18 @@ void CChar::NPC_Act_Fight()
{
m_atFlee.m_iStepsMax = 20; // how long should it take to get there.
m_atFlee.m_iStepsCurrent = 0; // how long has it taken ?
Skill_Start(NPCACT_FLEE); // Run away!
if (NPC_Act_Flee())
{
Skill_Start(NPCACT_FLEE); // Run away!
}
else
{
//We have to clean STATF_WAR if npc motivation below zero but can't see the target or flee target is invalid.
Skill_Start(SKILL_NONE);
StatFlag_Clear(STATF_WAR);
Attacker_Delete(pChar, true, ATTACKER_CLEAR_DISTANCE);
m_Fight_Targ_UID.InitUID();
}
return;
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/game/chars/CCharNotoriety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void CChar::Noto_ChangeNewMsg( int iPrvLevel )
}
}

void CChar::Noto_Fame( int iFameChange )
void CChar::Noto_Fame( int iFameChange, CChar* pNPC )
{
ADDTOCALLSTACK("CChar::Noto_Fame");

Expand Down Expand Up @@ -503,11 +503,11 @@ void CChar::Noto_Fame( int iFameChange )
//if ( ! iFameChange )
// return;

SetFame((ushort)(iFame + iFameChange));
SetFame((ushort)(iFame + iFameChange), pNPC);
Noto_ChangeDeltaMsg( (int)GetFame() - iFame, g_Cfg.GetDefaultMsg( DEFMSG_NOTO_FAME ) );
}

void CChar::Noto_Karma( int iKarmaChange, int iBottom, bool fMessage )
void CChar::Noto_Karma( int iKarmaChange, int iBottom, bool fMessage, CChar* pNPC )
{
ADDTOCALLSTACK("CChar::Noto_Karma");

Expand Down Expand Up @@ -541,7 +541,7 @@ void CChar::Noto_Karma( int iKarmaChange, int iBottom, bool fMessage )
//if ( ! iKarmaChange )
// return;

SetKarma((short)(iKarma + iKarmaChange));
SetKarma((short)(iKarma + iKarmaChange), pNPC);
Noto_ChangeDeltaMsg( (int)GetKarma() - iKarma, g_Cfg.GetDefaultMsg( DEFMSG_NOTO_KARMA ) );
NotoSave_Update();
if ( fMessage == true )
Expand Down Expand Up @@ -612,8 +612,9 @@ void CChar::Noto_Kill(CChar * pKill, int iTotalKillers)
return;

int iPrvLevel = Noto_GetLevel(); // store title before fame/karma changes to check if it got changed
Noto_Fame(g_Cfg.Calc_FameKill(pKill) / iTotalKillers);
Noto_Karma(g_Cfg.Calc_KarmaKill(pKill, NotoThem) / iTotalKillers);

Noto_Fame(g_Cfg.Calc_FameKill(pKill) / iTotalKillers, pKill);
Noto_Karma(g_Cfg.Calc_KarmaKill(pKill, NotoThem) / iTotalKillers, INT32_MIN, false, pKill);

if ( g_Cfg.m_bExperienceSystem && (g_Cfg.m_iExperienceMode & EXP_MODE_RAISE_COMBAT) )
{
Expand Down
Loading

0 comments on commit fb36db1

Please sign in to comment.