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

Added: FUNC keyword to item templates triggers with special parsing (… #1105

Closed
wants to merge 4 commits into from
Closed
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
10 changes: 7 additions & 3 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3339,12 +3339,16 @@ Additionally, the problem of zig-zag issue following in the South direction has
Remember that the mana lost depends from the spell Mana base cost and eventually the LowerManaCost property if set.

14-09-2023, Drk84
-Fixed: Using ATTACKER.TARGET on a fighting NPC will return always -1. (Issue #1098)
- Fixed: Using ATTACKER.TARGET on a fighting NPC will return always -1. (Issue #1098)

15-09-2023, Drk84
Fixed: Ship plank not remaining open when turning the ship around. ( Issue #1089)
- Fixed: Ship plank not remaining open when turning the ship around. (Issue #1089)
The ship plank will now autoclose after 5 seconds.
Fixed: Client Linger Timer is 3600 seconds on stoned players. (Issue #1081)
- Fixed: Client Linger Timer is 3600 seconds on stoned players. (Issue #1081)

23-09-2023, Jhobean
Fixed: When deleting account, f_onchar_delete was not call on char and char's item was not remove causing warning on next server boot. ( Issue #1029)

24-09-2023, Nolok
- Added: FUNC keyword to item templates and template-triggers with special parsing (@CreateLoot, @NPCRestock). It allows to call a function with arguments on the last created ITEM.
Default object: the item. SRC: the character holding it.
107 changes: 65 additions & 42 deletions src/game/chars/CChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,30 @@ bool CChar::ReadScriptReduced(CResourceLock &s, bool fVendor)

int iCmd = FindTableSorted(s.GetKey(), CItem::sm_szTemplateTable, ARRAY_COUNT(CItem::sm_szTemplateTable)-1);
bool fItemCreation = false;
if ( fVendor )
if (iCmd == ITC_FUNC)
{
if (!pItem)
continue;

lptstr ptcFunctionName = s.GetArgRaw();
std::unique_ptr<CScriptTriggerArgs> pScriptArgs;
// Locate arguments for the called function
tchar* ptcArgs = strchr(ptcFunctionName, ' ');
if (ptcArgs)
{
*ptcArgs = 0;
++ptcArgs;
GETNONWHITESPACE(ptcArgs);
pScriptArgs = std::make_unique<CScriptTriggerArgs>(ptcArgs);
}
pItem->r_Call(ptcFunctionName, this, pScriptArgs.get());
if (pItem->IsDeleted())
{
fItemCreation = false;
g_Log.EventDebug("FUNC deleted the item.\n");
}
}
else if ( fVendor )
{
if (iCmd != -1)
{
Expand Down Expand Up @@ -1321,66 +1344,66 @@ bool CChar::ReadScriptReduced(CResourceLock &s, bool fVendor)
}
else
{
switch ( iCmd )
{
switch (iCmd)
{
case ITC_FULLINTERP:
{
lpctstr pszArgs = s.GetArgStr();
GETNONWHITESPACE(pszArgs);
fFullInterp = ( *pszArgs == '\0' ) ? true : ( s.GetArgVal() != 0);
{
lpctstr pszArgs = s.GetArgStr();
GETNONWHITESPACE(pszArgs);
fFullInterp = (*pszArgs == '\0') ? true : (s.GetArgVal() != 0);
continue;
}
case ITC_NEWBIESWAP:
{
if (!pItem)
continue;

if (pItem->IsAttr(ATTR_NEWBIE))
{
if (Calc_GetRandVal(s.GetArgVal()) == 0)
pItem->ClrAttr(ATTR_NEWBIE);
}
case ITC_NEWBIESWAP:
else
{
if ( !pItem )
continue;

if ( pItem->IsAttr( ATTR_NEWBIE ) )
{
if ( Calc_GetRandVal( s.GetArgVal() ) == 0 )
pItem->ClrAttr(ATTR_NEWBIE);
}
else
{
if ( Calc_GetRandVal( s.GetArgVal() ) == 0 )
pItem->SetAttr(ATTR_NEWBIE);
}
continue;
if (Calc_GetRandVal(s.GetArgVal()) == 0)
pItem->SetAttr(ATTR_NEWBIE);
}
continue;
}
case ITC_ITEM:
case ITC_CONTAINER:
case ITC_ITEMNEWBIE:
{
fItemCreation = true;
{
fItemCreation = true;

if ( IsStatFlag( STATF_CONJURED ) && iCmd != ITC_ITEMNEWBIE ) // This check is not needed.
break; // conjured creates have no loot.
if (IsStatFlag(STATF_CONJURED) && iCmd != ITC_ITEMNEWBIE) // This check is not needed (sure?).
break; // conjured creates have no loot.

pItem = CItem::CreateHeader( s.GetArgRaw(), this, iCmd == ITC_ITEMNEWBIE );
if ( pItem == nullptr )
{
m_UIDLastNewItem = GetUID(); // Setting m_UIDLastNewItem to CChar's UID to prevent calling any following functions meant to be called on that item
continue;
}
m_UIDLastNewItem.InitUID(); //Clearing the attr for the next cycle
pItem = CItem::CreateHeader(s.GetArgRaw(), this, iCmd == ITC_ITEMNEWBIE);
if (pItem == nullptr)
{
m_UIDLastNewItem = GetUID(); // Setting m_UIDLastNewItem to CChar's UID to prevent calling any following functions meant to be called on that item
continue;
}
m_UIDLastNewItem.InitUID(); //Clearing the attr for the next cycle

pItem->_iCreatedResScriptIdx = s.m_iResourceFileIndex;
pItem->_iCreatedResScriptLine = s.m_iLineNum;
pItem->_iCreatedResScriptIdx = s.m_iResourceFileIndex;
pItem->_iCreatedResScriptLine = s.m_iLineNum;

if ( iCmd == ITC_ITEMNEWBIE )
pItem->SetAttr(ATTR_NEWBIE);
if (iCmd == ITC_ITEMNEWBIE)
pItem->SetAttr(ATTR_NEWBIE);

if ( !pItem->IsItemInContainer() && !pItem->IsItemEquipped())
pItem = nullptr;
continue;
}
if (!pItem->IsItemInContainer() && !pItem->IsItemEquipped())
pItem = nullptr;
continue;
}

case ITC_BREAK:
case ITC_BUY:
case ITC_SELL:
pItem = nullptr;
continue;
}
}

}

Expand Down
1 change: 1 addition & 0 deletions src/game/items/CItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ lpctstr const CItem::sm_szTemplateTable[ITC_QTY+1] =
"BUY",
"CONTAINER",
"FULLINTERP",
"FUNC",
"ITEM",
"ITEMNEWBIE",
"NEWBIESWAP",
Expand Down
1 change: 1 addition & 0 deletions src/game/items/CItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum ITC_TYPE // Item Template commands
ITC_BUY,
ITC_CONTAINER,
ITC_FULLINTERP,
ITC_FUNC,
ITC_ITEM,
ITC_ITEMNEWBIE,
ITC_NEWBIESWAP,
Expand Down