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

Skills menu update and SkillUpdate function added #1107

Merged
merged 4 commits into from
Oct 19, 2023
Merged
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
11 changes: 10 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3397,4 +3397,13 @@ Additionally, the problem of zig-zag issue following in the South direction has
16-10-2023, Nolok
- Fixed: Memory leaks due to the old CSPtrTypeArray and CSObjArray containers, replaced with new ones using smart pointers as wrappers.
- Fixed: Possible random errors caused by reading some internal data before it was initialized during server startup (CCrypto::client_keys, holding SphereCrypt data, and ThreadHolder, holding threads data).
- Fixed: CSString instances becoming invalid after calling the Clear method.
- Fixed: CSString instances becoming invalid after calling the Clear method.

19-10-2023, Julian
- Fixed: Missing SkillUpdate function, seems I never commited it.
- Modified: @SkillMenu trigger to be able to open dialogs also, and added a few local variables.
LOCAL.ItemUsed (r) = The ID (not UID) of the item that triggered this action.
LOCAL.Skill (r) = The ID of the Skill used.
LOCAL.SkillMenu (rw) = The skill menu (sm_alchemy) or dialog (d_MyCraftingMenu) that is going to open.
- Modified: @SkillMakeItem trigger to enable/disable notification message when bouncing the crafted item.
LOCAL.Notify (rw) = 1/0. Using 0 will not show any "You put your..." message, 1 will show it. Default = 1.
5 changes: 4 additions & 1 deletion src/game/chars/CCharSkill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,13 @@ bool CChar::Skill_MakeItem_Success()
CUID uidOldAct = m_Act_UID;
m_Act_UID = pItem->GetUID();
TRIGRET_TYPE iRet = TRIGRET_RET_DEFAULT;
bool notify = true;
if ( IsTrigUsed(TRIGGER_SKILLMAKEITEM) )
{
CScriptTriggerArgs Args(iSkillLevel, quality, uidOldAct.ObjFind());
Args.m_VarsLocal.SetNum("Notify", 1);
iRet = OnTrigger(CTRIG_SkillMakeItem, this, &Args);
notify = Args.m_VarsLocal.GetKeyNum("Notify") ? true : false;
}
m_Act_UID = uidOldAct; // restore

Expand Down Expand Up @@ -841,7 +844,7 @@ bool CChar::Skill_MakeItem_Success()
ChangeExperience(exp);
}

ItemBounce(pItem);
ItemBounce(pItem, notify);
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/game/clients/CClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,9 @@ bool CClient::r_Verb( CScript & s, CTextConsole * pSrc ) // Execute command from
case CV_SKILLSELECT:
Event_Skill_Use( g_Cfg.FindSkillKey( s.GetArgStr() ) );
break;
case CV_SKILLUPDATE:
addSkillWindow(g_Cfg.FindSkillKey(s.GetArgStr()));
break;
case CV_SUMMON:
{
ASSERT(m_pChar);
Expand Down
1 change: 1 addition & 0 deletions src/game/clients/CClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ class CClient : public CSObjListRec, public CScriptObj, public CChatChanMember,
int Cmd_Extract( CScript * pScript, const CRectMap &rect, int & zlowest );
int Cmd_Skill_Menu_Build( const CResourceID& rid, int iSelect, CMenuItem* item, int iMaxSize, bool *fShowMenu, bool *fLimitReached );
public:
bool Skill_Menu(SKILL_TYPE skill, lpctstr skillmenu, ITEMID_TYPE itemused = ITEMID_NOTHING);
bool Cmd_Skill_Menu( const CResourceID& rid, int iSelect = -1 );
bool Cmd_Skill_Smith( CItem * pIngots );
bool Cmd_Skill_Magery( SPELL_TYPE iSpell, CObjBase * pSrc );
Expand Down
36 changes: 4 additions & 32 deletions src/game/clients/CClientTarg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1886,13 +1886,7 @@ bool CClient::OnTarg_Use_Item( CObjBase * pObjTarg, CPointMap & pt, ITEMID_TYPE
}
if ( pItemUse->IsType(IT_CARPENTRY_CHOP) )
{
if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_carpentry");
if ( m_pChar->OnTrigger(CTRIG_SkillMenu, m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu( g_Cfg.ResourceGetIDType( RES_SKILLMENU, "sm_carpentry" ));
return Skill_Menu(SKILL_CARPENTRY, "sm_carpentry", pItemUse->GetID());
}
if ( pItemUse->IsSameDispID( ITEMID_DAGGER ))
{
Expand All @@ -1902,13 +1896,7 @@ bool CClient::OnTarg_Use_Item( CObjBase * pObjTarg, CPointMap & pt, ITEMID_TYPE
else
m_Targ_UID.InitUID();

if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_bowcraft");
if ( m_pChar->OnTrigger(CTRIG_SkillMenu, m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu( g_Cfg.ResourceGetIDType( RES_SKILLMENU, "sm_bowcraft" ) );
return Skill_Menu(SKILL_BOWCRAFT, "sm_bowcraft", pItemUse->GetID());
}
SysMessageDefault( DEFMSG_ITEMUSE_LOG_USE );
return false;
Expand Down Expand Up @@ -2364,25 +2352,9 @@ static lpctstr const sm_Txt_LoomUse[] =
{
case IT_LEATHER:
case IT_HIDE:
{
if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_tailor_leather");
if ( m_pChar->OnTrigger("@SkillMenu", m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu( g_Cfg.ResourceGetIDType( RES_SKILLMENU, "sm_tailor_leather" ) );
}
return Skill_Menu(SKILL_TAILORING, "sm_tailor_leather", pItemTarg->GetID());
case IT_CLOTH:
{
if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_tailor_cloth");
if ( m_pChar->OnTrigger("@SkillMenu", m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu( g_Cfg.ResourceGetIDType( RES_SKILLMENU, "sm_tailor_cloth" ) );
}
return Skill_Menu(SKILL_TAILORING, "sm_tailor_cloth", pItemTarg->GetID());
default:
break;
}
Expand Down
110 changes: 42 additions & 68 deletions src/game/clients/CClientUse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,7 @@ bool CClient::Cmd_Use_Item( CItem *pItem, bool fTestTouch, bool fScript )

case IT_SHAFT:
case IT_FEATHER:
{
if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_bolts");
if ( m_pChar->OnTrigger("@SkillMenu", m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu(g_Cfg.ResourceGetIDType(RES_SKILLMENU, "sm_bolts"));
}
return Skill_Menu(SKILL_BOWCRAFT, "sm_bolts", pItem->GetID());

case IT_FISH_POLE: // Just be near water ?
addTarget(CLIMODE_TARG_USE_ITEM, g_Cfg.GetDefaultMsg(DEFMSG_FISHING_PROMT), true);
Expand Down Expand Up @@ -368,15 +360,7 @@ bool CClient::Cmd_Use_Item( CItem *pItem, bool fTestTouch, bool fScript )
}

case IT_CARPENTRY:
{
if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_carpentry");
if ( m_pChar->OnTrigger("@SkillMenu", m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu(g_Cfg.ResourceGetIDType(RES_SKILLMENU, "sm_carpentry"));
}
return Skill_Menu(SKILL_CARPENTRY, "sm_carpentry", pItem->GetID());

case IT_FORGE:
// Solve for the combination of this item with another.
Expand Down Expand Up @@ -534,48 +518,16 @@ bool CClient::Cmd_Use_Item( CItem *pItem, bool fTestTouch, bool fScript )
return true;

case IT_MORTAR:
{
if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_alchemy");
if ( m_pChar->OnTrigger("@SkillMenu", m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu(g_Cfg.ResourceGetIDType(RES_SKILLMENU, "sm_alchemy"));
}
return Skill_Menu(SKILL_ALCHEMY, "sm_alchemy", pItem->GetID());

case IT_CARTOGRAPHY:
{
if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_cartography");
if ( m_pChar->OnTrigger("@SkillMenu", m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu(g_Cfg.ResourceGetIDType(RES_SKILLMENU, "sm_cartography"));
}
return Skill_Menu(SKILL_CARTOGRAPHY, "sm_cartography", pItem->GetID());

case IT_COOKING:
{
if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_cooking");
if ( m_pChar->OnTrigger("@SkillMenu", m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu(g_Cfg.ResourceGetIDType(RES_SKILLMENU, "sm_cooking"));
}
return Skill_Menu(SKILL_COOKING, "sm_cooking", pItem->GetID());

case IT_TINKER_TOOLS:
{
if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_tinker");
if ( m_pChar->OnTrigger("@SkillMenu", m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu(g_Cfg.ResourceGetIDType(RES_SKILLMENU, "sm_tinker"));
}
return Skill_Menu(SKILL_TINKERING, "sm_tinker", pItem->GetID());

case IT_SEWING_KIT:
{
Expand Down Expand Up @@ -667,6 +619,40 @@ void CClient::Cmd_EditItem( CObjBase *pObj, int iSelect )
addItemMenu(CLIMODE_MENU_EDIT, item, count, pObj);
}


bool CClient::Skill_Menu(SKILL_TYPE skill, lpctstr skillmenu, ITEMID_TYPE itemused)
{
// Default menu is d_craft_menu
// Open in page 0, args is skill used.
// LPCTSTR dSkillMenu = "d_CraftingMenu";
CScriptTriggerArgs Args;
Args.m_VarsLocal.SetStrNew("SkillMenu", skillmenu);
Args.m_VarsLocal.SetNumNew("Skill", skill);
Args.m_VarsLocal.SetNumNew("ItemUsed", itemused);
if (IsTrigUsed(TRIGGER_SKILLMENU))
{
if (m_pChar->Skill_OnCharTrigger(skill, CTRIG_SkillMenu, &Args) == TRIGRET_RET_TRUE)
return true;

skillmenu = Args.m_VarsLocal.GetKeyStr("Skillmenu", false);
}

lpctstr SkillUsed = g_Cfg.GetSkillKey(skill);
CResourceID ridDialog = g_Cfg.ResourceGetIDType(RES_DIALOG, skillmenu);
if (ridDialog.IsValidUID()) {
return Dialog_Setup(CLIMODE_DIALOG, g_Cfg.ResourceGetIDType(RES_DIALOG, skillmenu), 0, m_pChar, SkillUsed);
} else {
CResourceID ridMenu = g_Cfg.ResourceGetIDType(RES_SKILLMENU, skillmenu);
if (ridMenu.IsValidUID()) {
return Cmd_Skill_Menu(ridMenu);
} else {
g_Log.EventError("CClient::Skill_Menu - Not valid dialog or skillmenu %s \n", skillmenu);
}
}

return false;
}

bool CClient::Cmd_Skill_Menu( const CResourceID& rid, int iSelect )
{
ADDTOCALLSTACK("CClient::Cmd_Skill_Menu");
Expand Down Expand Up @@ -1278,13 +1264,7 @@ bool CClient::Cmd_Skill_Smith( CItem *pIngots )

// Select the blacksmith item type.
// repair items or make type of items.
if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_blacksmith");
if ( m_pChar->OnTrigger("@SkillMenu", m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu(g_Cfg.ResourceGetIDType(RES_SKILLMENU, "sm_blacksmith"));
return Skill_Menu(SKILL_BLACKSMITHING, "sm_blacksmith", pIngots->GetID());
}

bool CClient::Cmd_Skill_Inscription()
Expand All @@ -1305,13 +1285,7 @@ bool CClient::Cmd_Skill_Inscription()
return false;
}

if ( IsTrigUsed(TRIGGER_SKILLMENU) )
{
CScriptTriggerArgs args("sm_inscription");
if ( m_pChar->OnTrigger("@SkillMenu", m_pChar, &args) == TRIGRET_RET_TRUE )
return true;
}
return Cmd_Skill_Menu(g_Cfg.ResourceGetIDType(RES_SKILLMENU, "sm_inscription"));
return Skill_Menu(SKILL_INSCRIPTION, "sm_inscription");
}

bool CClient::Cmd_SecureTrade( CChar *pChar, CItem *pItem )
Expand Down
1 change: 1 addition & 0 deletions src/tables/CClient_functions.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ADD(SENDPACKET, "SENDPACKET")
ADD(SHOWSKILLS, "SHOWSKILLS")
ADD(SKILLMENU, "SKILLMENU")
ADD(SKILLSELECT, "SKILLSELECT")
ADD(SKILLUPDATE, "SKILLUPDATE")
ADD(SMSG, "SMSG")
ADD(SMSGL, "SMSGL")
ADD(SMSGLEX, "SMSGLEX")
Expand Down