diff --git a/Changelog.txt b/Changelog.txt index d89d9dc98..78b785edf 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -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. \ No newline at end of file +- 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. diff --git a/src/game/chars/CCharSkill.cpp b/src/game/chars/CCharSkill.cpp index 86a9a8157..c856f445e 100644 --- a/src/game/chars/CCharSkill.cpp +++ b/src/game/chars/CCharSkill.cpp @@ -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 @@ -841,7 +844,7 @@ bool CChar::Skill_MakeItem_Success() ChangeExperience(exp); } - ItemBounce(pItem); + ItemBounce(pItem, notify); return true; } diff --git a/src/game/clients/CClient.cpp b/src/game/clients/CClient.cpp index e826485dc..9da9609af 100644 --- a/src/game/clients/CClient.cpp +++ b/src/game/clients/CClient.cpp @@ -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); diff --git a/src/game/clients/CClient.h b/src/game/clients/CClient.h index 69d3a5b73..75eb43a41 100644 --- a/src/game/clients/CClient.h +++ b/src/game/clients/CClient.h @@ -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 ); diff --git a/src/game/clients/CClientTarg.cpp b/src/game/clients/CClientTarg.cpp index 7864be6ad..70d44b4b7 100644 --- a/src/game/clients/CClientTarg.cpp +++ b/src/game/clients/CClientTarg.cpp @@ -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 )) { @@ -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; @@ -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; } diff --git a/src/game/clients/CClientUse.cpp b/src/game/clients/CClientUse.cpp index 3bf016858..386c3c5ed 100644 --- a/src/game/clients/CClientUse.cpp +++ b/src/game/clients/CClientUse.cpp @@ -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); @@ -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. @@ -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: { @@ -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"); @@ -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() @@ -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 ) diff --git a/src/tables/CClient_functions.tbl b/src/tables/CClient_functions.tbl index 6996427ea..dbf69e695 100644 --- a/src/tables/CClient_functions.tbl +++ b/src/tables/CClient_functions.tbl @@ -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")