From baaf5801ff1406cf17e81f3ae91b462cfef7e819 Mon Sep 17 00:00:00 2001 From: Natedog2012 Date: Mon, 14 Dec 2015 01:18:19 -0800 Subject: [PATCH] Added ability to manipulate disciplines for perl and lua. Also ability to remove spells from spell bar with spellID. --- zone/client.h | 3 ++ zone/effects.cpp | 27 +++++++++++++++ zone/lua_client.cpp | 18 ++++++++++ zone/lua_client.h | 3 ++ zone/perl_client.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++ zone/spells.cpp | 10 ++++++ 6 files changed, 139 insertions(+) diff --git a/zone/client.h b/zone/client.h index e31f68b26..b5d3728e1 100644 --- a/zone/client.h +++ b/zone/client.h @@ -712,6 +712,7 @@ public: // use this one instead void MemSpell(uint16 spell_id, int slot, bool update_client = true); void UnmemSpell(int slot, bool update_client = true); + void UnmemSpellBySpellID(int32 spell_id); void UnmemSpellAll(bool update_client = true); void ScribeSpell(uint16 spell_id, int slot, bool update_client = true); void UnscribeSpell(int slot, bool update_client = true); @@ -925,6 +926,8 @@ public: void ResetTrade(); void DropInst(const ItemInst* inst); bool TrainDiscipline(uint32 itemid); + void TrainDiscBySpellID(int32 spell_id); + int GetDiscSlotBySpellID(int32 spellid); void SendDisciplineUpdate(); void SendDisciplineTimer(uint32 timer_id, uint32 duration); bool UseDiscipline(uint32 spell_id, uint32 target); diff --git a/zone/effects.cpp b/zone/effects.cpp index dc069fb2a..dc3392403 100644 --- a/zone/effects.cpp +++ b/zone/effects.cpp @@ -571,6 +571,33 @@ bool Client::TrainDiscipline(uint32 itemid) { return(false); } +void Client::TrainDiscBySpellID(int32 spell_id) +{ + int i; + for(i = 0; i < MAX_PP_DISCIPLINES; i++) { + if(m_pp.disciplines.values[i] == 0) { + m_pp.disciplines.values[i] = spell_id; + database.SaveCharacterDisc(this->CharacterID(), i, spell_id); + SendDisciplineUpdate(); + Message(15, "You have learned a new combat ability!"); + return; + } + } +} + +int Client::GetDiscSlotBySpellID(int32 spellid) +{ + int i; + + for(i = 0; i < MAX_PP_DISCIPLINES; i++) + { + if(m_pp.disciplines.values[i] == spellid) + return i; + } + + return -1; +} + void Client::SendDisciplineUpdate() { EQApplicationPacket app(OP_DisciplineUpdate, sizeof(Disciplines_Struct)); Disciplines_Struct *d = (Disciplines_Struct*)app.pBuffer; diff --git a/zone/lua_client.cpp b/zone/lua_client.cpp index b7dad0ce3..1e785ce9b 100644 --- a/zone/lua_client.cpp +++ b/zone/lua_client.cpp @@ -530,6 +530,11 @@ void Lua_Client::UnmemSpell(int slot, bool update_client) { self->UnmemSpell(slot, update_client); } +void Lua_Client::UnmemSpellBySpellID(int32 spell_id) { + Lua_Safe_Call_Void(); + self->UnmemSpellBySpellID(spell_id); +} + void Lua_Client::UnmemSpellAll() { Lua_Safe_Call_Void(); self->UnmemSpellAll(); @@ -575,6 +580,16 @@ void Lua_Client::TrainDisc(int itemid) { self->TrainDiscipline(itemid); } +void Lua_Client::TrainDiscBySpellID(int32 spell_id) { + Lua_Safe_Call_Void(); + self->TrainDiscBySpellID(spell_id); +} + +int Lua_Client::GetDiscSlotBySpellID(int32 spell_id) { + Lua_Safe_Call_Int(); + return self->GetDiscSlotBySpellID(spell_id); +} + void Lua_Client::UntrainDisc(int slot) { Lua_Safe_Call_Void(); self->UntrainDisc(slot); @@ -1426,6 +1441,7 @@ luabind::scope lua_register_client() { .def("MemSpell", (void(Lua_Client::*)(int,int,bool))&Lua_Client::MemSpell) .def("UnmemSpell", (void(Lua_Client::*)(int))&Lua_Client::UnmemSpell) .def("UnmemSpell", (void(Lua_Client::*)(int,bool))&Lua_Client::UnmemSpell) + .def("UnmemSpellBySpellID", (void(Lua_Client::*)(int32))&Lua_Client::UnmemSpellBySpellID) .def("UnmemSpellAll", (void(Lua_Client::*)(void))&Lua_Client::UnmemSpellAll) .def("UnmemSpellAll", (void(Lua_Client::*)(bool))&Lua_Client::UnmemSpellAll) .def("ScribeSpell", (void(Lua_Client::*)(int,int))&Lua_Client::ScribeSpell) @@ -1435,6 +1451,8 @@ luabind::scope lua_register_client() { .def("UnscribeSpellAll", (void(Lua_Client::*)(void))&Lua_Client::UnscribeSpellAll) .def("UnscribeSpellAll", (void(Lua_Client::*)(bool))&Lua_Client::UnscribeSpellAll) .def("TrainDisc", (void(Lua_Client::*)(int))&Lua_Client::TrainDisc) + .def("TrainDiscBySpellID", (void(Lua_Client::*)(int32))&Lua_Client::TrainDiscBySpellID) + .def("GetDiscSlotBySpellID", (int(Lua_Client::*)(int32))&Lua_Client::GetDiscSlotBySpellID) .def("UntrainDisc", (void(Lua_Client::*)(int))&Lua_Client::UntrainDisc) .def("UntrainDisc", (void(Lua_Client::*)(int,bool))&Lua_Client::UntrainDisc) .def("UntrainDiscAll", (void(Lua_Client::*)(void))&Lua_Client::UntrainDiscAll) diff --git a/zone/lua_client.h b/zone/lua_client.h index e50a16b98..4584edfd0 100644 --- a/zone/lua_client.h +++ b/zone/lua_client.h @@ -131,6 +131,7 @@ public: void MemSpell(int spell_id, int slot, bool update_client); void UnmemSpell(int slot); void UnmemSpell(int slot, bool update_client); + void UnmemSpellBySpellID(int32 spell_id); void UnmemSpellAll(); void UnmemSpellAll(bool update_client); void ScribeSpell(int spell_id, int slot); @@ -140,6 +141,8 @@ public: void UnscribeSpellAll(); void UnscribeSpellAll(bool update_client); void TrainDisc(int itemid); + void TrainDiscBySpellID(int32 spell_id); + int GetDiscSlotBySpellID(int32 spell_id); void UntrainDisc(int slot); void UntrainDisc(int slot, bool update_client); void UntrainDiscAll(); diff --git a/zone/perl_client.cpp b/zone/perl_client.cpp index 3858eac0e..d4c5f34d0 100644 --- a/zone/perl_client.cpp +++ b/zone/perl_client.cpp @@ -2445,6 +2445,30 @@ XS(XS_Client_UnmemSpell) XSRETURN_EMPTY; } +XS(XS_Client_UnmemSpellBySpellID); /* prototype to pass -Wmissing-prototypes */ +XS(XS_Client_UnmemSpellBySpellID) +{ + dXSARGS; + if (items != 2) + Perl_croak(aTHX_ "Usage: Client::UnmemSpellBySpellID(THIS, spell_id)"); + { + Client * THIS; + int32 spell_id = (int32)SvIV(ST(1)); + + if (sv_derived_from(ST(0), "Client")) { + IV tmp = SvIV((SV*)SvRV(ST(0))); + THIS = INT2PTR(Client *,tmp); + } + else + Perl_croak(aTHX_ "THIS is not of type Client"); + if(THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + THIS->UnmemSpellBySpellID(spell_id); + } + XSRETURN_EMPTY; +} + XS(XS_Client_UnmemSpellAll); /* prototype to pass -Wmissing-prototypes */ XS(XS_Client_UnmemSpellAll) { @@ -2568,6 +2592,57 @@ XS(XS_Client_UnscribeSpellAll) XSRETURN_EMPTY; } +XS(XS_Client_TrainDiscBySpellID); /* prototype to pass -Wmissing-prototypes */ +XS(XS_Client_TrainDiscBySpellID) +{ + dXSARGS; + if (items != 2) + Perl_croak(aTHX_ "Usage: Client::TrainDiscBySpellID(THIS, spell_id)"); + { + Client * THIS; + int32 spell_id = (int32)SvIV(ST(1)); + + if (sv_derived_from(ST(0), "Client")) { + IV tmp = SvIV((SV*)SvRV(ST(0))); + THIS = INT2PTR(Client *,tmp); + } + else + Perl_croak(aTHX_ "THIS is not of type Client"); + if(THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + THIS->TrainDiscBySpellID(spell_id); + } + XSRETURN_EMPTY; +} + +XS(XS_Client_GetDiscSlotBySpellID); /* prototype to pass -Wmissing-prototypes */ +XS(XS_Client_GetDiscSlotBySpellID) +{ + dXSARGS; + if (items != 2) + Perl_croak(aTHX_ "Usage: Client::GetDiscSlotBySpellID(THIS, spell_id)"); + { + Client * THIS; + int RETVAL; + int32 spell_id = (int32)SvIV(ST(1)); + dXSTARG; + + if (sv_derived_from(ST(0), "Client")) { + IV tmp = SvIV((SV*)SvRV(ST(0))); + THIS = INT2PTR(Client *,tmp); + } + else + Perl_croak(aTHX_ "THIS is not of type Client"); + if(THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + RETVAL = THIS->GetDiscSlotBySpellID(spell_id); + XSprePUSH; PUSHi((IV)RETVAL); + } + XSRETURN(1); +} + XS(XS_Client_UntrainDisc); /* prototype to pass -Wmissing-prototypes */ XS(XS_Client_UntrainDisc) { @@ -6443,10 +6518,13 @@ XS(boot_Client) newXSproto(strcpy(buf, "ResetAA"), XS_Client_ResetAA, file, "$"); newXSproto(strcpy(buf, "MemSpell"), XS_Client_MemSpell, file, "$$$;$"); newXSproto(strcpy(buf, "UnmemSpell"), XS_Client_UnmemSpell, file, "$$;$"); + newXSproto(strcpy(buf, "UnmemSpellBySpellID"), XS_Client_UnmemSpellBySpellID, file, "$$"); newXSproto(strcpy(buf, "UnmemSpellAll"), XS_Client_UnmemSpellAll, file, "$;$"); newXSproto(strcpy(buf, "ScribeSpell"), XS_Client_ScribeSpell, file, "$$$;$"); newXSproto(strcpy(buf, "UnscribeSpell"), XS_Client_UnscribeSpell, file, "$$;$"); newXSproto(strcpy(buf, "UnscribeSpellAll"), XS_Client_UnscribeSpellAll, file, "$;$"); + newXSproto(strcpy(buf, "TrainDiscBySpellID"), XS_Client_TrainDiscBySpellID, file, "$$"); + newXSproto(strcpy(buf, "GetDiscSlotBySpellID"), XS_Client_GetDiscSlotBySpellID, file, "$$"); newXSproto(strcpy(buf, "UntrainDisc"), XS_Client_UntrainDisc, file, "$$;$"); newXSproto(strcpy(buf, "UntrainDiscAll"), XS_Client_UntrainDiscAll, file, "$;$"); newXSproto(strcpy(buf, "IsSitting"), XS_Client_IsSitting, file, "$"); diff --git a/zone/spells.cpp b/zone/spells.cpp index 9ec68c3ff..18de9a444 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -4910,6 +4910,16 @@ void Client::UnmemSpell(int slot, bool update_client) } } +void Client::UnmemSpellBySpellID(int32 spell_id) +{ + for(int i = 0; i < MAX_PP_MEMSPELL; i++) { + if(m_pp.mem_spells[i] == spell_id) { + UnmemSpell(i, true); + break; + } + } +} + void Client::UnmemSpellAll(bool update_client) { int i;