diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 4bb7df4dc..1f613a885 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -2,7 +2,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) SET(common_sources BasePacket.cpp - callback_manager.cpp classes.cpp Condition.cpp crash.cpp @@ -94,7 +93,6 @@ SET(common_headers BasePacket.h bodytypes.h breakdowns.h - callback_manager.h classes.h common_profile.h Condition.h diff --git a/common/Item.cpp b/common/Item.cpp index 5c302d77e..e7012c471 100644 --- a/common/Item.cpp +++ b/common/Item.cpp @@ -65,7 +65,6 @@ ItemInst::ItemInst(const Item_Struct* item, int16 charges) { m_color = 0; m_merchantcount = 1; m_SerialNumber = GetNextItemInstSerialNumber(); - m_on_destroy = GetEQCallback("OnItemInstDestroy"); } ItemInst::ItemInst(SharedDatabase *db, uint32 item_id, int16 charges) { @@ -81,7 +80,6 @@ ItemInst::ItemInst(SharedDatabase *db, uint32 item_id, int16 charges) { m_color = 0; m_merchantcount = 1; m_SerialNumber = GetNextItemInstSerialNumber(); - m_on_destroy = GetEQCallback("OnItemInstDestroy"); } ItemInstQueue::~ItemInstQueue() { @@ -172,16 +170,12 @@ ItemInst::ItemInst(const ItemInst& copy) } m_SerialNumber = copy.m_SerialNumber; m_custom_data = copy.m_custom_data; - m_on_destroy = copy.m_on_destroy; + m_timers = copy.m_timers; } // Clean up container contents ItemInst::~ItemInst() { - if(m_on_destroy) { - m_on_destroy(this); - } - Clear(); } @@ -1685,7 +1679,7 @@ EvoItemInst::EvoItemInst(const EvoItemInst ©) { else m_scaledItem = nullptr; - m_on_destroy = GetEQCallback("OnItemInstDestroy"); + m_timers = copy.m_timers; } EvoItemInst::EvoItemInst(const ItemInst &basecopy) { @@ -1725,7 +1719,7 @@ EvoItemInst::EvoItemInst(const ItemInst &basecopy) { m_activated = false; m_evolveInfo = nullptr; m_scaledItem = nullptr; - m_on_destroy = copy->m_on_destroy; + m_timers = copy->m_timers; } EvoItemInst::EvoItemInst(const Item_Struct* item, int16 charges) { @@ -1746,13 +1740,9 @@ EvoItemInst::EvoItemInst(const Item_Struct* item, int16 charges) { m_activated = false; m_evolveInfo = nullptr; m_scaledItem = nullptr; - m_on_destroy = GetEQCallback("OnItemInstDestroy"); } EvoItemInst::~EvoItemInst() { - if(m_on_destroy) { - m_on_destroy(this); - } safe_delete(m_scaledItem); } diff --git a/common/Item.h b/common/Item.h index 16b53deab..bb4c865c8 100644 --- a/common/Item.h +++ b/common/Item.h @@ -37,7 +37,7 @@ class EvolveInfo; // Stores information about an evolving item family #include "../common/eq_packet_structs.h" #include "../common/eq_constants.h" #include "../common/item_struct.h" -#include "callback_manager.h" +#include "../common/timer.h" // Helper typedefs typedef std::list::const_iterator iter_queue; @@ -266,8 +266,6 @@ public: m_instnodrop = false; m_merchantslot = 0; m_color = 0; - - m_on_destroy = GetEQCallback("OnItemInstDestroy"); } ItemInst(const ItemInst& copy); @@ -381,6 +379,8 @@ public: inline int32 GetSerialNumber() const { return m_SerialNumber; } inline void SetSerialNumber(int32 id) { m_SerialNumber = id; } + std::map& GetTimers() { return m_timers; } + protected: ////////////////////////// // Protected Members @@ -407,7 +407,7 @@ protected: // Items inside of this item (augs or contents); std::map m_contents; // Zero-based index: min=0, max=9 std::map m_custom_data; - eqemu_callback m_on_destroy; + std::map m_timers; }; class EvoItemInst: public ItemInst { diff --git a/common/callback_manager.cpp b/common/callback_manager.cpp deleted file mode 100644 index f20c88578..000000000 --- a/common/callback_manager.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "callback_manager.h" - -std::map callback_functions; - -void RegisterEQCallback(std::string name, eqemu_callback func) { - callback_functions[name] = func; -} - -eqemu_callback GetEQCallback(std::string name) { - auto iter = callback_functions.find(name); - if(iter == callback_functions.end()) { - return nullptr; - } - - return iter->second; -} diff --git a/common/callback_manager.h b/common/callback_manager.h deleted file mode 100644 index 78ba7b301..000000000 --- a/common/callback_manager.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef EQEMU_CALLBACK_MANAGER_H -#define EQEMU_CALLBACK_MANAGER_H - -#include -#include - -typedef std::function eqemu_callback; - -void RegisterEQCallback(std::string name, eqemu_callback func); -eqemu_callback GetEQCallback(std::string name); - -#endif diff --git a/common/timer.cpp b/common/timer.cpp index e13fd2a9f..637c8a563 100644 --- a/common/timer.cpp +++ b/common/timer.cpp @@ -30,6 +30,14 @@ uint32 current_time = 0; uint32 last_time = 0; +Timer::Timer() { + timer_time = 0; + start_time = current_time; + set_at_trigger = timer_time; + pUseAcurateTiming = false; + enabled = false; +} + Timer::Timer(uint32 in_timer_time, bool iUseAcurateTiming) { timer_time = in_timer_time; start_time = current_time; diff --git a/common/timer.h b/common/timer.h index 7ac31e489..1e3ab97e0 100644 --- a/common/timer.h +++ b/common/timer.h @@ -29,6 +29,7 @@ class Timer { public: + Timer(); Timer(uint32 timer_time, bool iUseAcurateTiming = false); Timer(uint32 start, uint32 timer, bool iUseAcurateTiming); ~Timer() { } @@ -62,9 +63,6 @@ private: // Instead of Check() setting the start_time = now, // it it sets it to start_time += timer_time bool pUseAcurateTiming; - -// static uint32 current_time; -// static uint32 last_time; }; #endif diff --git a/zone/QuestInterface.h b/zone/QuestInterface.h index 46baa2f1a..1d4ab4276 100644 --- a/zone/QuestInterface.h +++ b/zone/QuestInterface.h @@ -38,12 +38,13 @@ public: virtual int EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data) { return 0; } virtual int EventEncounter(QuestEventID evt, std::string encounter_name, uint32 extra_data) { return 0; } - virtual bool HasQuestSub(uint32 npcid, const char *subname) { return false; } - virtual bool HasGlobalQuestSub(const char *subname) { return false; } - virtual bool PlayerHasQuestSub(const char *subname) { return false; } - virtual bool GlobalPlayerHasQuestSub(const char *subname) { return false; } - virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname) { return false; } - virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname) { return false; } + virtual bool HasQuestSub(uint32 npcid, QuestEventID evt) { return false; } + virtual bool HasGlobalQuestSub(QuestEventID evt) { return false; } + virtual bool PlayerHasQuestSub(QuestEventID evt) { return false; } + virtual bool GlobalPlayerHasQuestSub(QuestEventID evt) { return false; } + virtual bool SpellHasQuestSub(uint32 spell_id, QuestEventID evt) { return false; } + virtual bool ItemHasQuestSub(ItemInst *itm, QuestEventID evt) { return false; } + virtual bool EncounterHasQuestSub(std::string encounter_name, QuestEventID evt) { return false; } virtual void LoadNPCScript(std::string filename, int npc_id) { } virtual void LoadGlobalNPCScript(std::string filename) { } diff --git a/zone/QuestParserCollection.cpp b/zone/QuestParserCollection.cpp index c2899031b..a13fc0b28 100644 --- a/zone/QuestParserCollection.cpp +++ b/zone/QuestParserCollection.cpp @@ -80,18 +80,18 @@ void QuestParserCollection::ReloadQuests(bool reset_timers) { } } -bool QuestParserCollection::HasQuestSub(uint32 npcid, const char *subname) { - return HasQuestSubLocal(npcid, subname) || HasQuestSubGlobal(subname); +bool QuestParserCollection::HasQuestSub(uint32 npcid, QuestEventID evt) { + return HasQuestSubLocal(npcid, evt) || HasQuestSubGlobal(evt); } -bool QuestParserCollection::HasQuestSubLocal(uint32 npcid, const char *subname) { +bool QuestParserCollection::HasQuestSubLocal(uint32 npcid, QuestEventID evt) { std::map::iterator iter = _npc_quest_status.find(npcid); if(iter != _npc_quest_status.end()) { //loaded or failed to load if(iter->second != QuestFailedToLoad) { std::map::iterator qiter = _interfaces.find(iter->second); - if(qiter->second->HasQuestSub(npcid, subname)) { + if(qiter->second->HasQuestSub(npcid, evt)) { return true; } } @@ -102,7 +102,7 @@ bool QuestParserCollection::HasQuestSubLocal(uint32 npcid, const char *subname) _npc_quest_status[npcid] = qi->GetIdentifier(); qi->LoadNPCScript(filename, npcid); - if(qi->HasQuestSub(npcid, subname)) { + if(qi->HasQuestSub(npcid, evt)) { return true; } } else { @@ -112,21 +112,21 @@ bool QuestParserCollection::HasQuestSubLocal(uint32 npcid, const char *subname) return false; } -bool QuestParserCollection::HasQuestSubGlobal(const char *subname) { +bool QuestParserCollection::HasQuestSubGlobal(QuestEventID evt) { if(_global_npc_quest_status == QuestUnloaded) { std::string filename; QuestInterface *qi = GetQIByGlobalNPCQuest(filename); if(qi) { qi->LoadGlobalNPCScript(filename); _global_npc_quest_status = qi->GetIdentifier(); - if(qi->HasGlobalQuestSub(subname)) { + if(qi->HasGlobalQuestSub(evt)) { return true; } } } else { if(_global_npc_quest_status != QuestFailedToLoad) { std::map::iterator qiter = _interfaces.find(_global_npc_quest_status); - if(qiter->second->HasGlobalQuestSub(subname)) { + if(qiter->second->HasGlobalQuestSub(evt)) { return true; } } @@ -134,49 +134,49 @@ bool QuestParserCollection::HasQuestSubGlobal(const char *subname) { return false; } -bool QuestParserCollection::PlayerHasQuestSub(const char *subname) { - return PlayerHasQuestSubLocal(subname) || PlayerHasQuestSubGlobal(subname); +bool QuestParserCollection::PlayerHasQuestSub(QuestEventID evt) { + return PlayerHasQuestSubLocal(evt) || PlayerHasQuestSubGlobal(evt); } -bool QuestParserCollection::PlayerHasQuestSubLocal(const char *subname) { +bool QuestParserCollection::PlayerHasQuestSubLocal(QuestEventID evt) { if(_player_quest_status == QuestUnloaded) { std::string filename; QuestInterface *qi = GetQIByPlayerQuest(filename); if(qi) { _player_quest_status = qi->GetIdentifier(); qi->LoadPlayerScript(filename); - return qi->PlayerHasQuestSub(subname); + return qi->PlayerHasQuestSub(evt); } } else if(_player_quest_status != QuestFailedToLoad) { std::map::iterator iter = _interfaces.find(_player_quest_status); - return iter->second->PlayerHasQuestSub(subname); + return iter->second->PlayerHasQuestSub(evt); } return false; } -bool QuestParserCollection::PlayerHasQuestSubGlobal(const char *subname) { +bool QuestParserCollection::PlayerHasQuestSubGlobal(QuestEventID evt) { if(_global_player_quest_status == QuestUnloaded) { std::string filename; QuestInterface *qi = GetQIByPlayerQuest(filename); if(qi) { _global_player_quest_status = qi->GetIdentifier(); qi->LoadPlayerScript(filename); - return qi->GlobalPlayerHasQuestSub(subname); + return qi->GlobalPlayerHasQuestSub(evt); } } else if(_global_player_quest_status != QuestFailedToLoad) { std::map::iterator iter = _interfaces.find(_global_player_quest_status); - return iter->second->GlobalPlayerHasQuestSub(subname); + return iter->second->GlobalPlayerHasQuestSub(evt); } return false; } -bool QuestParserCollection::SpellHasQuestSub(uint32 spell_id, const char *subname) { +bool QuestParserCollection::SpellHasQuestSub(uint32 spell_id, QuestEventID evt) { std::map::iterator iter = _spell_quest_status.find(spell_id); if(iter != _spell_quest_status.end()) { //loaded or failed to load if(iter->second != QuestFailedToLoad) { std::map::iterator qiter = _interfaces.find(iter->second); - return qiter->second->SpellHasQuestSub(spell_id, subname); + return qiter->second->SpellHasQuestSub(spell_id, evt); } } else { std::string filename; @@ -184,7 +184,7 @@ bool QuestParserCollection::SpellHasQuestSub(uint32 spell_id, const char *subnam if(qi) { _spell_quest_status[spell_id] = qi->GetIdentifier(); qi->LoadSpellScript(filename, spell_id); - return qi->SpellHasQuestSub(spell_id, subname); + return qi->SpellHasQuestSub(spell_id, evt); } else { _spell_quest_status[spell_id] = QuestFailedToLoad; } @@ -192,7 +192,7 @@ bool QuestParserCollection::SpellHasQuestSub(uint32 spell_id, const char *subnam return false; } -bool QuestParserCollection::ItemHasQuestSub(ItemInst *itm, const char *subname) { +bool QuestParserCollection::ItemHasQuestSub(ItemInst *itm, QuestEventID evt) { std::string item_script; if(itm->GetItem()->ScriptFileID != 0) { item_script = "script_"; @@ -209,7 +209,7 @@ bool QuestParserCollection::ItemHasQuestSub(ItemInst *itm, const char *subname) //loaded or failed to load if(iter->second != QuestFailedToLoad) { std::map::iterator qiter = _interfaces.find(iter->second); - return qiter->second->ItemHasQuestSub(itm, subname); + return qiter->second->ItemHasQuestSub(itm, evt); } } else { std::string filename; @@ -217,7 +217,7 @@ bool QuestParserCollection::ItemHasQuestSub(ItemInst *itm, const char *subname) if(qi) { _item_quest_status[item_id] = qi->GetIdentifier(); qi->LoadItemScript(filename, itm); - return qi->ItemHasQuestSub(itm, subname); + return qi->ItemHasQuestSub(itm, evt); } else { _item_quest_status[item_id] = QuestFailedToLoad; } @@ -646,7 +646,7 @@ QuestInterface *QuestParserCollection::GetQIByPlayerQuest(std::string &filename) } QuestInterface *QuestParserCollection::GetQIByGlobalNPCQuest(std::string &filename) { - // simply look for quests/global/global_npc.pl + // simply look for /quests/global/global_npc.ext filename = "quests/"; filename += QUEST_GLOBAL_DIRECTORY; filename += "/"; diff --git a/zone/QuestParserCollection.h b/zone/QuestParserCollection.h index 11a1ed581..87cbb3efa 100644 --- a/zone/QuestParserCollection.h +++ b/zone/QuestParserCollection.h @@ -44,10 +44,10 @@ public: void Init(); void ReloadQuests(bool reset_timers = true); - bool HasQuestSub(uint32 npcid, const char *subname); - bool PlayerHasQuestSub(const char *subname); - bool SpellHasQuestSub(uint32 spell_id, const char *subname); - bool ItemHasQuestSub(ItemInst *itm, const char *subname); + bool HasQuestSub(uint32 npcid, QuestEventID evt); + bool PlayerHasQuestSub(QuestEventID evt); + bool SpellHasQuestSub(uint32 spell_id, QuestEventID evt); + bool ItemHasQuestSub(ItemInst *itm, QuestEventID evt); int EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data, std::vector *items = nullptr); @@ -59,10 +59,10 @@ public: void GetErrors(std::list &err); private: - bool HasQuestSubLocal(uint32 npcid, const char *subname); - bool HasQuestSubGlobal(const char *subname); - bool PlayerHasQuestSubLocal(const char *subname); - bool PlayerHasQuestSubGlobal(const char *subname); + bool HasQuestSubLocal(uint32 npcid, QuestEventID evt); + bool HasQuestSubGlobal(QuestEventID evt); + bool PlayerHasQuestSubLocal(QuestEventID evt); + bool PlayerHasQuestSubGlobal(QuestEventID evt); int EventNPCLocal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data, std::vector *items); int EventNPCGlobal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data, std::vector *items); diff --git a/zone/attack.cpp b/zone/attack.cpp index 51574b4b9..291d32664 100644 --- a/zone/attack.cpp +++ b/zone/attack.cpp @@ -918,7 +918,7 @@ int Mob::GetWeaponDamage(Mob *against, const ItemInst *weapon_item, uint32 *hate dmg = weapon_item->GetItem()->Damage; } - for(int x = 0; x < 5; x++){ + for(int x = 0; x < MAX_AUGMENT_SLOTS; x++){ if(weapon_item->GetAugment(x) && weapon_item->GetAugment(x)->GetItem()){ dmg += weapon_item->GetAugment(x)->GetItem()->Damage; if (hate) *hate += weapon_item->GetAugment(x)->GetItem()->Damage + weapon_item->GetAugment(x)->GetItem()->ElemDmgAmt; @@ -955,7 +955,7 @@ int Mob::GetWeaponDamage(Mob *against, const ItemInst *weapon_item, uint32 *hate dmg = weapon_item->GetItem()->Damage; } - for(int x = 0; x < 5; x++){ + for(int x = 0; x < MAX_AUGMENT_SLOTS; x++){ if(weapon_item->GetAugment(x) && weapon_item->GetAugment(x)->GetItem()){ dmg += weapon_item->GetAugment(x)->GetItem()->Damage; if (hate) *hate += weapon_item->GetAugment(x)->GetItem()->Damage + weapon_item->GetAugment(x)->GetItem()->ElemDmgAmt; @@ -992,7 +992,7 @@ int Mob::GetWeaponDamage(Mob *against, const ItemInst *weapon_item, uint32 *hate } if(weapon_item){ - for(int x = 0; x < 5; x++){ + for(int x = 0; x < MAX_AUGMENT_SLOTS; x++){ if(weapon_item->GetAugment(x) && weapon_item->GetAugment(x)->GetItem()){ if(weapon_item->GetAugment(x)->GetItem()->ElemDmgAmt) eledmg += (weapon_item->GetAugment(x)->GetItem()->ElemDmgAmt * against->ResistSpell(weapon_item->GetAugment(x)->GetItem()->ElemDmgType, 0, this) / 100); @@ -1021,7 +1021,7 @@ int Mob::GetWeaponDamage(Mob *against, const ItemInst *weapon_item, uint32 *hate } } - for(int x = 0; x < 5; x++){ + for(int x = 0; x < MAX_AUGMENT_SLOTS; x++){ if(weapon_item->GetAugment(x) && weapon_item->GetAugment(x)->GetItem()){ if(weapon_item->GetAugment(x)->GetItem()->BaneDmgBody == against->GetBodyType()){ banedmg += weapon_item->GetAugment(x)->GetItem()->BaneDmgAmt; @@ -1066,7 +1066,7 @@ int Mob::GetWeaponDamage(Mob *against, const ItemInst *weapon_item, uint32 *hate } } - for(int x = 0; x < 5; x++){ + for(int x = 0; x < MAX_AUGMENT_SLOTS; x++){ if(weapon_item->GetAugment(x) && weapon_item->GetAugment(x)->GetItem()){ if(weapon_item->GetAugment(x)->GetItem()->BaneDmgBody == against->GetBodyType()){ banedmg += weapon_item->GetAugment(x)->GetItem()->BaneDmgAmt; @@ -2020,7 +2020,7 @@ bool NPC::Death(Mob* killerMob, int32 damage, uint16 spell, SkillType attack_ski Mob *oos = nullptr; if(killerMob) { - Mob *oos = killerMob->GetOwnerOrSelf(); + oos = killerMob->GetOwnerOrSelf(); char buffer[32] = { 0 }; snprintf(buffer, 31, "%d %d %d", damage, spell, static_cast(attack_skill)); diff --git a/zone/bonuses.cpp b/zone/bonuses.cpp index 29c99ab22..ed75c0866 100644 --- a/zone/bonuses.cpp +++ b/zone/bonuses.cpp @@ -2398,26 +2398,26 @@ void NPC::CalcItemBonuses(StatBonuses *newbon) } } -void Client::CalcItemScale(bool login) +void Client::CalcItemScale() { bool changed = false; - if(CalcItemScale(0, 21, login)) + if(CalcItemScale(0, 21)) changed = true; - if(CalcItemScale(22, 30, login)) + if(CalcItemScale(22, 30)) changed = true; - if(CalcItemScale(251, 341, login)) + if(CalcItemScale(251, 341)) changed = true; - if(CalcItemScale(400, 405, login)) + if(CalcItemScale(400, 405)) changed = true; //Power Source Slot if (GetClientVersion() >= EQClientSoF) { - if(CalcItemScale(9999, 10000, login)) + if(CalcItemScale(9999, 10000)) changed = true; } @@ -2427,7 +2427,7 @@ void Client::CalcItemScale(bool login) } } -bool Client::CalcItemScale(uint32 slot_x, uint32 slot_y, bool login) +bool Client::CalcItemScale(uint32 slot_x, uint32 slot_y) { bool changed = false; int i; @@ -2442,9 +2442,9 @@ bool Client::CalcItemScale(uint32 slot_x, uint32 slot_y, bool login) EvoItemInst* e_inst = (EvoItemInst*)inst; uint16 oldexp = e_inst->GetExp(); - if(login) { - parse->EventItem(EVENT_ITEM_ENTER_ZONE, this, e_inst, nullptr, "", 0); - } + //if(login) { + // parse->EventItem(EVENT_ITEM_ENTER_ZONE, this, e_inst, nullptr, "", 0); + //} parse->EventItem(EVENT_SCALE_CALC, this, e_inst, nullptr, "", 0); if (e_inst->GetExp() != oldexp) { // if the scaling factor changed, rescale the item and update the client @@ -2466,9 +2466,9 @@ bool Client::CalcItemScale(uint32 slot_x, uint32 slot_y, bool login) EvoItemInst* e_inst = (EvoItemInst*)a_inst; uint16 oldexp = e_inst->GetExp(); - if(login) { - parse->EventItem(EVENT_ITEM_ENTER_ZONE, this, e_inst, nullptr, "", 0); - } + //if(login) { + // parse->EventItem(EVENT_ITEM_ENTER_ZONE, this, e_inst, nullptr, "", 0); + //} parse->EventItem(EVENT_SCALE_CALC, this, e_inst, nullptr, "", 0); if (e_inst->GetExp() != oldexp) @@ -2488,6 +2488,91 @@ bool Client::CalcItemScale(uint32 slot_x, uint32 slot_y, bool login) return changed; } +void Client::DoItemEnterZone() { + bool changed = false; + + if(DoItemEnterZone(0, 21)) + changed = true; + + if(DoItemEnterZone(22, 30)) + changed = true; + + if(DoItemEnterZone(251, 341)) + changed = true; + + if(DoItemEnterZone(400, 405)) + changed = true; + + //Power Source Slot + if (GetClientVersion() >= EQClientSoF) + { + if(DoItemEnterZone(9999, 10000)) + changed = true; + } + + if(changed) + { + CalcBonuses(); + } +} + +bool Client::DoItemEnterZone(uint32 slot_x, uint32 slot_y) { + bool changed = false; + for(int i = slot_x; i < slot_y; i++) { + ItemInst* inst = m_inv.GetItem(i); + if(inst == 0) + continue; + + bool update_slot = false; + if(inst->IsScaling()) + { + EvoItemInst* e_inst = (EvoItemInst*)inst; + uint16 oldexp = e_inst->GetExp(); + + parse->EventItem(EVENT_ITEM_ENTER_ZONE, this, e_inst, nullptr, "", 0); + + if (e_inst->GetExp() != oldexp) { // if the scaling factor changed, rescale the item and update the client + e_inst->ScaleItem(); + changed = true; + update_slot = true; + } + } else { + parse->EventItem(EVENT_ITEM_ENTER_ZONE, this, inst, nullptr, "", 0); + } + + //iterate all augments + for(int x = 0; x < MAX_AUGMENT_SLOTS; ++x) + { + ItemInst *a_inst = inst->GetAugment(x); + if(!a_inst) + continue; + + if(a_inst->IsScaling()) + { + EvoItemInst* e_inst = (EvoItemInst*)a_inst; + uint16 oldexp = e_inst->GetExp(); + + parse->EventItem(EVENT_ITEM_ENTER_ZONE, this, e_inst, nullptr, "", 0); + + if (e_inst->GetExp() != oldexp) + { + e_inst->ScaleItem(); + changed = true; + update_slot = true; + } + } else { + parse->EventItem(EVENT_ITEM_ENTER_ZONE, this, a_inst, nullptr, "", 0); + } + } + + if(update_slot) + { + SendItemPacket(i, inst, ItemPacketCharmUpdate); + } + } + return changed; +} + uint8 Mob::IsFocusEffect(uint16 spell_id,int effect_index, bool AA,uint32 aa_effect) { uint16 effect = 0; diff --git a/zone/client.cpp b/zone/client.cpp index 030bf77b4..396718e7d 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -1029,14 +1029,14 @@ void Client::ChannelMessageReceived(uint8 chan_num, uint8 language, uint8 lang_s case 8: { // /say if(message[0] == COMMAND_CHAR) { if(command_dispatch(this, message) == -2) { - //if(parse->PlayerHasQuestSub("EVENT_COMMAND")) { - // int i = parse->EventPlayer(EVENT_COMMAND, this, message, 0); - // if(i != 0) { - // Message(13, "Command '%s' not recognized.", message); - // } - //} else { + if(parse->PlayerHasQuestSub(EVENT_COMMAND)) { + int i = parse->EventPlayer(EVENT_COMMAND, this, message, 0); + if(i != 0) { + Message(13, "Command '%s' not recognized.", message); + } + } else { Message(13, "Command '%s' not recognized.", message); - //} + } } break; } @@ -4737,7 +4737,7 @@ void Client::ShowSkillsWindow() if(GetSkill(it->second) > 0 || MaxSkill(it->second) > 0) { WindowText += it->first; // line up the values - for (int j = 0; j < 5; j++) + for (int j = 0; j < MAX_AUGMENT_SLOTS; j++) WindowText += " "; WindowText += itoa(this->GetSkill(it->second)); if (MaxSkill(it->second) > 0) { diff --git a/zone/client.h b/zone/client.h index 7d71f4dba..9157d43c3 100644 --- a/zone/client.h +++ b/zone/client.h @@ -1013,8 +1013,10 @@ public: void MarkSingleCompassLoc(float in_x, float in_y, float in_z, uint8 count=1); - void CalcItemScale(bool login = false); - bool CalcItemScale(uint32 slot_x, uint32 slot_y, bool login = false); + void CalcItemScale(); + bool CalcItemScale(uint32 slot_x, uint32 slot_y); + void DoItemEnterZone(); + bool DoItemEnterZone(uint32 slot_x, uint32 slot_y); void SummonAndRezzAllCorpses(); void SummonAllCorpses(float dest_x, float dest_y, float dest_z, float dest_heading); void DepopAllCorpses(); diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index af7cda6d5..e0566b17b 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -9642,7 +9642,8 @@ void Client::CompleteConnect() SendAltCurrencies(); database.LoadAltCurrencyValues(CharacterID(), alternate_currency); SendAlternateCurrencyValues(); - CalcItemScale(true); + CalcItemScale(); + DoItemEnterZone(); if(zone->GetZoneID() == RuleI(World, GuildBankZoneID) && GuildBanks) GuildBanks->SendGuildBank(this); diff --git a/zone/client_process.cpp b/zone/client_process.cpp index 739a56480..8a9150eea 100644 --- a/zone/client_process.cpp +++ b/zone/client_process.cpp @@ -786,11 +786,7 @@ void Client::OnDisconnect(bool hard_disconnect) { if (MyRaid) MyRaid->MemberZoned(this); - if(this->IsClient()){ - if(parse->PlayerHasQuestSub("EVENT_DISCONNECT")) { - parse->EventPlayer(EVENT_DISCONNECT, this, "", 0); - } - } + parse->EventPlayer(EVENT_DISCONNECT, this, "", 0); } Mob *Other = trade->With(); diff --git a/zone/embparser.cpp b/zone/embparser.cpp index 07fbb587b..e85db7438 100644 --- a/zone/embparser.cpp +++ b/zone/embparser.cpp @@ -35,7 +35,7 @@ extern Zone* zone; const char *QuestEventSubroutines[_LargestEventID] = { "EVENT_SAY", - "EVENT_TRADE", + "EVENT_ITEM", "EVENT_DEATH", "EVENT_SPAWN", "EVENT_ATTACK", @@ -50,21 +50,21 @@ const char *QuestEventSubroutines[_LargestEventID] = { "EVENT_HP", "EVENT_ENTER", "EVENT_EXIT", - "EVENT_ENTER_ZONE", - "EVENT_CLICK_DOOR", + "EVENT_ENTERZONE", + "EVENT_CLICKDOOR", "EVENT_LOOT", "EVENT_ZONE", "EVENT_LEVEL_UP", "EVENT_KILLED_MERIT", "EVENT_CAST_ON", - "EVENT_TASK_ACCEPTED", + "EVENT_TASKACCEPTED", "EVENT_TASK_STAGE_COMPLETE", "EVENT_TASK_UPDATE", "EVENT_TASK_COMPLETE", "EVENT_TASK_FAIL", "EVENT_AGGRO_SAY", "EVENT_PLAYER_PICKUP", - "EVENT_POPUP_RESPONSE", + "EVENT_POPUPRESPONSE", "EVENT_PROXIMITY_SAY", "EVENT_CAST", "EVENT_CAST_BEGIN", @@ -72,8 +72,10 @@ const char *QuestEventSubroutines[_LargestEventID] = { "EVENT_ITEM_ENTER_ZONE", "EVENT_TARGET_CHANGE", "EVENT_HATE_LIST", - "EVENT_SPELL_EFFECT", - "EVENT_SPELL_BUFF_TIC", + "EVENT_SPELL_EFFECT_CLIENT", + "EVENT_SPELL_EFFECT_NPC", + "EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT", + "EVENT_SPELL_EFFECT_BUFF_TIC_NPC", "EVENT_SPELL_FADE", "EVENT_SPELL_EFFECT_TRANSLOCATE_COMPLETE", "EVENT_COMBINE_SUCCESS", @@ -95,7 +97,7 @@ const char *QuestEventSubroutines[_LargestEventID] = { "EVENT_DUEL_LOSE", "EVENT_ENCOUNTER_LOAD", "EVENT_ENCOUNTER_UNLOAD", - "EVENT_COMMAND", + "EVENT_SAY", "EVENT_DROP_ITEM", "EVENT_DESTROY_ITEM", "EVENT_FEIGN_DEATH" @@ -235,13 +237,18 @@ int PerlembParser::EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 return 0; } -bool PerlembParser::HasQuestSub(uint32 npcid, const char *subname) { +bool PerlembParser::HasQuestSub(uint32 npcid, QuestEventID evt) { std::stringstream package_name; package_name << "qst_npc_" << npcid; if(!perl) return false; + if(evt >= _LargestEventID) + return false; + + const char *subname = QuestEventSubroutines[evt]; + auto iter = npc_quest_status_.find(npcid); if(iter == npc_quest_status_.end() || iter->second == QuestFailedToLoad) { return false; @@ -250,7 +257,7 @@ bool PerlembParser::HasQuestSub(uint32 npcid, const char *subname) { return(perl->SubExists(package_name.str().c_str(), subname)); } -bool PerlembParser::HasGlobalQuestSub(const char *subname) { +bool PerlembParser::HasGlobalQuestSub(QuestEventID evt) { if(!perl) return false; @@ -258,10 +265,15 @@ bool PerlembParser::HasGlobalQuestSub(const char *subname) { return false; } + if(evt >= _LargestEventID) + return false; + + const char *subname = QuestEventSubroutines[evt]; + return(perl->SubExists("qst_global_npc", subname)); } -bool PerlembParser::PlayerHasQuestSub(const char *subname) { +bool PerlembParser::PlayerHasQuestSub(QuestEventID evt) { if(!perl) return false; @@ -269,10 +281,15 @@ bool PerlembParser::PlayerHasQuestSub(const char *subname) { return false; } + if(evt >= _LargestEventID) + return false; + + const char *subname = QuestEventSubroutines[evt]; + return(perl->SubExists("qst_player", subname)); } -bool PerlembParser::GlobalPlayerHasQuestSub(const char *subname) { +bool PerlembParser::GlobalPlayerHasQuestSub(QuestEventID evt) { if(!perl) return false; @@ -280,10 +297,15 @@ bool PerlembParser::GlobalPlayerHasQuestSub(const char *subname) { return false; } + if(evt >= _LargestEventID) + return false; + + const char *subname = QuestEventSubroutines[evt]; + return(perl->SubExists("qst_global_player", subname)); } -bool PerlembParser::SpellHasQuestSub(uint32 spell_id, const char *subname) { +bool PerlembParser::SpellHasQuestSub(uint32 spell_id, QuestEventID evt) { std::stringstream package_name; package_name << "qst_spell_" << spell_id; @@ -295,16 +317,26 @@ bool PerlembParser::SpellHasQuestSub(uint32 spell_id, const char *subname) { return false; } + if(evt >= _LargestEventID) + return false; + + const char *subname = QuestEventSubroutines[evt]; + return(perl->SubExists(package_name.str().c_str(), subname)); } -bool PerlembParser::ItemHasQuestSub(ItemInst *itm, const char *subname) { +bool PerlembParser::ItemHasQuestSub(ItemInst *itm, QuestEventID evt) { std::stringstream package_name; package_name << "qst_item_" << itm->GetID(); if(!perl) return false; + if(evt >= _LargestEventID) + return false; + + const char *subname = QuestEventSubroutines[evt]; + auto iter = item_quest_status_.find(itm->GetID()); if(iter == item_quest_status_.end() || iter->second == QuestFailedToLoad) { return false; @@ -753,8 +785,10 @@ void PerlembParser::AddQueueEvent(QuestEventID event, uint32 objid, const char * void PerlembParser::GetQuestTypes(bool &isPlayerQuest, bool &isGlobalPlayerQuest, bool &isGlobalNPC, bool &isItemQuest, bool &isSpellQuest, QuestEventID event, NPC* npcmob, ItemInst* iteminst, Mob* mob, bool global) { - if(event == EVENT_SPELL_EFFECT || - event == EVENT_SPELL_BUFF_TIC || + if(event == EVENT_SPELL_EFFECT_CLIENT || + event == EVENT_SPELL_EFFECT_NPC || + event == EVENT_SPELL_BUFF_TIC_CLIENT || + event == EVENT_SPELL_BUFF_TIC_NPC || event == EVENT_SPELL_FADE || event == EVENT_SPELL_EFFECT_TRANSLOCATE_COMPLETE) { @@ -1252,8 +1286,10 @@ void PerlembParser::ExportEventVariables(std::string &package_name, QuestEventID break; } - case EVENT_SPELL_EFFECT: - case EVENT_SPELL_BUFF_TIC: + case EVENT_SPELL_EFFECT_CLIENT: + case EVENT_SPELL_EFFECT_NPC: + case EVENT_SPELL_BUFF_TIC_CLIENT: + case EVENT_SPELL_BUFF_TIC_NPC: { ExportVar(package_name.c_str(), "caster_id", extradata); break; @@ -1289,7 +1325,9 @@ void PerlembParser::ExportEventVariables(std::string &package_name, QuestEventID } case EVENT_COMMAND: { - ExportVar(package_name.c_str(), "message", data); + ExportVar(package_name.c_str(), "text", data); + ExportVar(package_name.c_str(), "data", "0"); + ExportVar(package_name.c_str(), "langid", "0"); break; } diff --git a/zone/embparser.h b/zone/embparser.h index cd52fe9c0..2ab31e94a 100644 --- a/zone/embparser.h +++ b/zone/embparser.h @@ -65,12 +65,12 @@ public: virtual int EventItem(QuestEventID evt, Client *client, ItemInst *item, Mob *mob, std::string data, uint32 extra_data); virtual int EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data); - virtual bool HasQuestSub(uint32 npcid, const char *subname); - virtual bool HasGlobalQuestSub(const char *subname); - virtual bool PlayerHasQuestSub(const char *subname); - virtual bool GlobalPlayerHasQuestSub(const char *subname); - virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname); - virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname); + virtual bool HasQuestSub(uint32 npcid, QuestEventID evt); + virtual bool HasGlobalQuestSub(QuestEventID evt); + virtual bool PlayerHasQuestSub(QuestEventID evt); + virtual bool GlobalPlayerHasQuestSub(QuestEventID evt); + virtual bool SpellHasQuestSub(uint32 spell_id, QuestEventID evt); + virtual bool ItemHasQuestSub(ItemInst *itm, QuestEventID evt); virtual void LoadNPCScript(std::string filename, int npc_id); virtual void LoadGlobalNPCScript(std::string filename); diff --git a/zone/event_codes.h b/zone/event_codes.h index eee96bfc8..2b3315ef1 100644 --- a/zone/event_codes.h +++ b/zone/event_codes.h @@ -40,8 +40,10 @@ typedef enum { EVENT_ITEM_ENTER_ZONE, EVENT_TARGET_CHANGE, //target selected, target changed, or target removed EVENT_HATE_LIST, - EVENT_SPELL_EFFECT, - EVENT_SPELL_BUFF_TIC, + EVENT_SPELL_EFFECT_CLIENT, + EVENT_SPELL_EFFECT_NPC, + EVENT_SPELL_BUFF_TIC_CLIENT, + EVENT_SPELL_BUFF_TIC_NPC, EVENT_SPELL_FADE, EVENT_SPELL_EFFECT_TRANSLOCATE_COMPLETE, EVENT_COMBINE_SUCCESS, //PC successfully combined a recipe diff --git a/zone/inventory.cpp b/zone/inventory.cpp index 2a7cd11db..e2769b90d 100644 --- a/zone/inventory.cpp +++ b/zone/inventory.cpp @@ -333,7 +333,6 @@ void Client::DropItem(int16 slot_id) int i = parse->EventItem(EVENT_DROP_ITEM, this, inst, nullptr, "", 0); if(i != 0) { safe_delete(inst); - return; } } else { // Item doesn't exist in inventory! @@ -349,6 +348,9 @@ void Client::DropItem(int16 slot_id) database.SaveInventory(CharacterID(), nullptr, slot_id); } + if(!inst) + return; + // Package as zone object Object* object = new Object(this, inst); entity_list.AddObject(object, true); diff --git a/zone/lua_client.cpp b/zone/lua_client.cpp index c58b8c90b..fcff6e01d 100644 --- a/zone/lua_client.cpp +++ b/zone/lua_client.cpp @@ -1211,7 +1211,7 @@ luabind::scope lua_register_client() { .def("GetAAExp", (uint32(Lua_Client::*)(void))&Lua_Client::GetAAExp) .def("GetTotalSecondsPlayed", (uint32(Lua_Client::*)(void))&Lua_Client::GetTotalSecondsPlayed) .def("UpdateLDoNPoints", (void(Lua_Client::*)(int,uint32))&Lua_Client::UpdateLDoNPoints) - .def("SetDeity", (void(Lua_Client::*)(int v))&Lua_Client::SetDeity) + .def("SetDeity", (void(Lua_Client::*)(int))&Lua_Client::SetDeity) .def("AddEXP", (void(Lua_Client::*)(uint32))&Lua_Client::AddEXP) .def("AddEXP", (void(Lua_Client::*)(uint32,int))&Lua_Client::AddEXP) .def("AddEXP", (void(Lua_Client::*)(uint32,int,bool))&Lua_Client::AddEXP) diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 58babfa69..4e47bac30 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -939,11 +939,8 @@ luabind::scope lua_register_events() { luabind::value("trade", static_cast(EVENT_TRADE)), luabind::value("death", static_cast(EVENT_DEATH)), luabind::value("spawn", static_cast(EVENT_SPAWN)), - luabind::value("attack", static_cast(EVENT_ATTACK)), luabind::value("combat", static_cast(EVENT_COMBAT)), - luabind::value("aggro", static_cast(EVENT_AGGRO)), luabind::value("slay", static_cast(EVENT_SLAY)), - luabind::value("npc_slay", static_cast(EVENT_NPC_SLAY)), luabind::value("waypoint_arrive", static_cast(EVENT_WAYPOINT_ARRIVE)), luabind::value("waypoint_depart", static_cast(EVENT_WAYPOINT_DEPART)), luabind::value("timer", static_cast(EVENT_TIMER)), @@ -972,8 +969,8 @@ luabind::scope lua_register_events() { luabind::value("item_enter_zone", static_cast(EVENT_ITEM_ENTER_ZONE)), luabind::value("target_change", static_cast(EVENT_TARGET_CHANGE)), luabind::value("hate_list", static_cast(EVENT_HATE_LIST)), - luabind::value("spell_effect", static_cast(EVENT_SPELL_EFFECT)), - luabind::value("spell_buff_tic", static_cast(EVENT_SPELL_BUFF_TIC)), + luabind::value("spell_effect", static_cast(EVENT_SPELL_EFFECT_CLIENT)), + luabind::value("spell_buff_tic", static_cast(EVENT_SPELL_BUFF_TIC_CLIENT)), luabind::value("spell_fade", static_cast(EVENT_SPELL_FADE)), luabind::value("spell_effect_translocate_complete", static_cast(EVENT_SPELL_EFFECT_TRANSLOCATE_COMPLETE)), luabind::value("combine_success ", static_cast(EVENT_COMBINE_SUCCESS )), diff --git a/zone/lua_mob.h b/zone/lua_mob.h index e983f5653..37be4aec8 100644 --- a/zone/lua_mob.h +++ b/zone/lua_mob.h @@ -178,7 +178,6 @@ public: Lua_Mob GetPet(); Lua_Mob GetOwner(); Lua_HateList GetHateList(); - Lua_Mob GetHateTop(); Lua_Mob GetHateDamageTop(Lua_Mob other); Lua_Mob GetHateRandom(); diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index f2611a08b..ff8607bac 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -71,6 +71,8 @@ const char *LuaEvents[_LargestEventID] = { "event_target_change", "event_hate_list", "event_spell_effect", + "event_spell_effect", + "event_spell_buff_tic", "event_spell_buff_tic", "event_spell_fade", "event_spell_effect_translocate_complete", @@ -122,16 +124,13 @@ LuaParser::LuaParser() { NPCArgumentDispatch[EVENT_PROXIMITY_SAY] = handle_npc_event_say; NPCArgumentDispatch[EVENT_TRADE] = handle_npc_event_trade; NPCArgumentDispatch[EVENT_HP] = handle_npc_event_hp; - NPCArgumentDispatch[EVENT_ATTACK] = handle_npc_single_mob; - NPCArgumentDispatch[EVENT_AGGRO] = handle_npc_single_mob; NPCArgumentDispatch[EVENT_TARGET_CHANGE] = handle_npc_single_mob; - NPCArgumentDispatch[EVENT_CAST_ON] = handle_npc_single_mob; + NPCArgumentDispatch[EVENT_CAST_ON] = handle_npc_cast; NPCArgumentDispatch[EVENT_KILLED_MERIT] = handle_npc_single_client; - NPCArgumentDispatch[EVENT_SLAY] = handle_npc_single_client; + NPCArgumentDispatch[EVENT_SLAY] = handle_npc_single_mob; NPCArgumentDispatch[EVENT_ENTER] = handle_npc_single_client; NPCArgumentDispatch[EVENT_EXIT] = handle_npc_single_client; NPCArgumentDispatch[EVENT_TASK_ACCEPTED] = handle_npc_single_client; - NPCArgumentDispatch[EVENT_NPC_SLAY] = handle_npc_single_npc; NPCArgumentDispatch[EVENT_POPUP_RESPONSE] = handle_npc_popup; NPCArgumentDispatch[EVENT_WAYPOINT_ARRIVE] = handle_npc_waypoint; NPCArgumentDispatch[EVENT_WAYPOINT_DEPART] = handle_npc_waypoint; @@ -142,6 +141,7 @@ LuaParser::LuaParser() { NPCArgumentDispatch[EVENT_DEATH] = handle_npc_death; NPCArgumentDispatch[EVENT_CAST] = handle_npc_cast; NPCArgumentDispatch[EVENT_CAST_BEGIN] = handle_npc_cast; + NPCArgumentDispatch[EVENT_FEIGN_DEATH] = handle_npc_single_client; PlayerArgumentDispatch[EVENT_SAY] = handle_player_say; PlayerArgumentDispatch[EVENT_DEATH] = handle_player_death; @@ -168,8 +168,8 @@ LuaParser::LuaParser() { ItemArgumentDispatch[EVENT_ITEM_CLICK] = handle_item_click; ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click; - SpellArgumentDispatch[EVENT_SPELL_EFFECT] = handle_spell_effect; - SpellArgumentDispatch[EVENT_SPELL_BUFF_TIC] = handle_spell_effect; + SpellArgumentDispatch[EVENT_SPELL_EFFECT_CLIENT] = handle_spell_effect; + SpellArgumentDispatch[EVENT_SPELL_BUFF_TIC_CLIENT] = handle_spell_effect; SpellArgumentDispatch[EVENT_SPELL_FADE] = handle_spell_fade; L = nullptr; @@ -183,6 +183,7 @@ LuaParser::~LuaParser() { int LuaParser::EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data, std::vector *items) { + evt = ConvertLuaEvent(evt); if(evt >= _LargestEventID) { return 0; } @@ -191,18 +192,17 @@ int LuaParser::EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, return 0; } - if(!HasQuestSub(npc->GetNPCTypeID(), LuaEvents[evt])) { + if(!HasQuestSub(npc->GetNPCTypeID(), evt)) { return 0; } - std::stringstream package_name; - package_name << "npc_" << npc->GetNPCTypeID(); - - return _EventNPC(package_name.str(), evt, npc, init, data, extra_data, items); + std::string package_name = "npc_" + std::to_string(npc->GetNPCTypeID()); + return _EventNPC(package_name, evt, npc, init, data, extra_data, items); } int LuaParser::EventGlobalNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data, std::vector *items) { + evt = ConvertLuaEvent(evt); if(evt >= _LargestEventID) { return 0; } @@ -211,7 +211,7 @@ int LuaParser::EventGlobalNPC(QuestEventID evt, NPC* npc, Mob *init, std::string return 0; } - if(!HasGlobalQuestSub(LuaEvents[evt])) { + if(!HasGlobalQuestSub(evt)) { return 0; } @@ -278,6 +278,7 @@ int LuaParser::_EventNPC(std::string package_name, QuestEventID evt, NPC* npc, M } int LuaParser::EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) { + evt = ConvertLuaEvent(evt); if(evt >= _LargestEventID) { return 0; } @@ -286,7 +287,7 @@ int LuaParser::EventPlayer(QuestEventID evt, Client *client, std::string data, u return 0; } - if(!PlayerHasQuestSub(LuaEvents[evt])) { + if(!PlayerHasQuestSub(evt)) { return 0; } @@ -294,6 +295,7 @@ int LuaParser::EventPlayer(QuestEventID evt, Client *client, std::string data, u } int LuaParser::EventGlobalPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) { + evt = ConvertLuaEvent(evt); if(evt >= _LargestEventID) { return 0; } @@ -302,7 +304,7 @@ int LuaParser::EventGlobalPlayer(QuestEventID evt, Client *client, std::string d return 0; } - if(!GlobalPlayerHasQuestSub(LuaEvents[evt])) { + if(!GlobalPlayerHasQuestSub(evt)) { return 0; } @@ -334,7 +336,7 @@ int LuaParser::_EventPlayer(std::string package_name, QuestEventID evt, Client * auto arg_function = PlayerArgumentDispatch[evt]; arg_function(this, L, client, data, extra_data); - quest_manager.StartQuest(nullptr, client, nullptr); + quest_manager.StartQuest(client, client, nullptr); if(lua_pcall(L, 1, 1, 0)) { std::string error = lua_tostring(L, -1); AddError(error); @@ -367,6 +369,7 @@ int LuaParser::_EventPlayer(std::string package_name, QuestEventID evt, Client * } int LuaParser::EventItem(QuestEventID evt, Client *client, ItemInst *item, Mob *mob, std::string data, uint32 extra_data) { + evt = ConvertLuaEvent(evt); if(evt >= _LargestEventID) { return 0; } @@ -375,7 +378,7 @@ int LuaParser::EventItem(QuestEventID evt, Client *client, ItemInst *item, Mob * return 0; } - if(!ItemHasQuestSub(item, LuaEvents[evt])) { + if(!ItemHasQuestSub(item, evt)) { return 0; } @@ -415,7 +418,7 @@ int LuaParser::_EventItem(std::string package_name, QuestEventID evt, Client *cl auto arg_function = ItemArgumentDispatch[evt]; arg_function(this, L, client, item, 0, extra_data); - quest_manager.StartQuest(nullptr, client, item); + quest_manager.StartQuest(client, client, item); if(lua_pcall(L, 1, 1, 0)) { std::string error = lua_tostring(L, -1); AddError(error); @@ -448,18 +451,18 @@ int LuaParser::_EventItem(std::string package_name, QuestEventID evt, Client *cl } int LuaParser::EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data) { + evt = ConvertLuaEvent(evt); if(evt >= _LargestEventID) { return 0; } - std::stringstream package_name; - package_name << "spell_" << spell_id; + std::string package_name = "spell_" + std::to_string(spell_id); - if(!SpellHasQuestSub(spell_id, LuaEvents[evt])) { + if(!SpellHasQuestSub(spell_id, evt)) { return 0; } - return _EventSpell(package_name.str(), evt, npc, client, spell_id, extra_data); + return _EventSpell(package_name, evt, npc, client, spell_id, extra_data); } int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, @@ -528,13 +531,14 @@ int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, NPC* npc, } int LuaParser::EventEncounter(QuestEventID evt, std::string encounter_name, uint32 extra_data) { + evt = ConvertLuaEvent(evt); if(evt >= _LargestEventID) { return 0; } std::string package_name = "encounter_" + encounter_name; - if(!EncounterHasQuestSub(encounter_name, LuaEvents[evt])) { + if(!EncounterHasQuestSub(encounter_name, evt)) { return 0; } @@ -586,50 +590,89 @@ int LuaParser::_EventEncounter(std::string package_name, QuestEventID evt, std:: return 0; } -bool LuaParser::HasQuestSub(uint32 npc_id, const char *subname) { - std::stringstream package_name; - package_name << "npc_" << npc_id; +bool LuaParser::HasQuestSub(uint32 npc_id, QuestEventID evt) { + evt = ConvertLuaEvent(evt); + if(evt >= _LargestEventID) { + return false; + } - return HasFunction(subname, package_name.str()); -} - -bool LuaParser::HasGlobalQuestSub(const char *subname) { - return HasFunction(subname, "global_npc"); -} - -bool LuaParser::PlayerHasQuestSub(const char *subname) { - return HasFunction(subname, "player"); -} - -bool LuaParser::GlobalPlayerHasQuestSub(const char *subname) { - return HasFunction(subname, "global_player"); -} - -bool LuaParser::SpellHasQuestSub(uint32 spell_id, const char *subname) { - std::stringstream package_name; - package_name << "spell_" << spell_id; - - return HasFunction(subname, package_name.str()); -} - -bool LuaParser::ItemHasQuestSub(ItemInst *itm, const char *subname) { - std::string package_name = "item_"; - package_name += std::to_string(itm->GetID()); + std::string package_name = "npc_" + std::to_string(npc_id); + const char *subname = LuaEvents[evt]; return HasFunction(subname, package_name); } -bool LuaParser::EncounterHasQuestSub(std::string encounter_name, const char *subname) { +bool LuaParser::HasGlobalQuestSub(QuestEventID evt) { + evt = ConvertLuaEvent(evt); + if(evt >= _LargestEventID) { + return false; + } + + const char *subname = LuaEvents[evt]; + return HasFunction(subname, "global_npc"); +} + +bool LuaParser::PlayerHasQuestSub(QuestEventID evt) { + evt = ConvertLuaEvent(evt); + if(evt >= _LargestEventID) { + return false; + } + + const char *subname = LuaEvents[evt]; + return HasFunction(subname, "player"); +} + +bool LuaParser::GlobalPlayerHasQuestSub(QuestEventID evt) { + evt = ConvertLuaEvent(evt); + if(evt >= _LargestEventID) { + return false; + } + + const char *subname = LuaEvents[evt]; + return HasFunction(subname, "global_player"); +} + +bool LuaParser::SpellHasQuestSub(uint32 spell_id, QuestEventID evt) { + evt = ConvertLuaEvent(evt); + if(evt >= _LargestEventID) { + return false; + } + + std::string package_name = "spell_" + std::to_string(spell_id); + + const char *subname = LuaEvents[evt]; + return HasFunction(subname, package_name); +} + +bool LuaParser::ItemHasQuestSub(ItemInst *itm, QuestEventID evt) { + evt = ConvertLuaEvent(evt); + if(evt >= _LargestEventID) { + return false; + } + + std::string package_name = "item_"; + package_name += std::to_string(itm->GetID()); + + const char *subname = LuaEvents[evt]; + return HasFunction(subname, package_name); +} + +bool LuaParser::EncounterHasQuestSub(std::string encounter_name, QuestEventID evt) { + evt = ConvertLuaEvent(evt); + if(evt >= _LargestEventID) { + return false; + } + std::string package_name = "encounter_" + encounter_name; + const char *subname = LuaEvents[evt]; return HasFunction(subname, package_name); } void LuaParser::LoadNPCScript(std::string filename, int npc_id) { - std::stringstream package_name; - package_name << "npc_" << npc_id; + std::string package_name = "npc_" + std::to_string(npc_id); - LoadScript(filename, package_name.str()); + LoadScript(filename, package_name); } void LuaParser::LoadGlobalNPCScript(std::string filename) { @@ -652,10 +695,9 @@ void LuaParser::LoadItemScript(std::string filename, ItemInst *item) { } void LuaParser::LoadSpellScript(std::string filename, uint32 spell_id) { - std::stringstream package_name; - package_name << "spell_" << spell_id; + std::string package_name = "spell_" + std::to_string(spell_id); - LoadScript(filename, package_name.str()); + LoadScript(filename, package_name); } void LuaParser::LoadEncounterScript(std::string filename, std::string encounter_name) { @@ -843,13 +885,17 @@ void LuaParser::MapFunctions(lua_State *L) { void LuaParser::DispatchEventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data, std::vector *items) { + evt = ConvertLuaEvent(evt); + if(evt >= _LargestEventID) { + return; + } + if(!npc) return; - std::stringstream package_name; - package_name << "npc_" << npc->GetNPCTypeID(); + std::string package_name = "npc_" + std::to_string(npc->GetNPCTypeID()); - auto iter = lua_encounter_events_registered.find(package_name.str()); + auto iter = lua_encounter_events_registered.find(package_name); if(iter == lua_encounter_events_registered.end()) { return; } @@ -865,6 +911,11 @@ void LuaParser::DispatchEventNPC(QuestEventID evt, NPC* npc, Mob *init, std::str } void LuaParser::DispatchEventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) { + evt = ConvertLuaEvent(evt); + if(evt >= _LargestEventID) { + return; + } + std::string package_name = "player"; auto iter = lua_encounter_events_registered.find(package_name); @@ -883,6 +934,11 @@ void LuaParser::DispatchEventPlayer(QuestEventID evt, Client *client, std::strin } void LuaParser::DispatchEventItem(QuestEventID evt, Client *client, ItemInst *item, Mob *mob, std::string data, uint32 extra_data) { + evt = ConvertLuaEvent(evt); + if(evt >= _LargestEventID) { + return; + } + if(!item) return; @@ -905,10 +961,14 @@ void LuaParser::DispatchEventItem(QuestEventID evt, Client *client, ItemInst *it } void LuaParser::DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data) { - std::stringstream package_name; - package_name << "spell_" << spell_id; + evt = ConvertLuaEvent(evt); + if(evt >= _LargestEventID) { + return; + } - auto iter = lua_encounter_events_registered.find(package_name.str()); + std::string package_name = "spell_" + std::to_string(spell_id); + + auto iter = lua_encounter_events_registered.find(package_name); if(iter == lua_encounter_events_registered.end()) { return; } @@ -923,4 +983,27 @@ void LuaParser::DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, u } } +QuestEventID LuaParser::ConvertLuaEvent(QuestEventID evt) { + switch(evt) { + case EVENT_SLAY: + case EVENT_NPC_SLAY: + return EVENT_SLAY; + break; + case EVENT_SPELL_EFFECT_CLIENT: + case EVENT_SPELL_EFFECT_NPC: + return EVENT_SPELL_EFFECT_CLIENT; + break; + case EVENT_SPELL_BUFF_TIC_CLIENT: + case EVENT_SPELL_BUFF_TIC_NPC: + return EVENT_SPELL_BUFF_TIC_CLIENT; + break; + case EVENT_AGGRO: + case EVENT_ATTACK: + return _LargestEventID; + break; + default: + return evt; + } +} + #endif diff --git a/zone/lua_parser.h b/zone/lua_parser.h index 3f22a5aea..2e0f04dbe 100644 --- a/zone/lua_parser.h +++ b/zone/lua_parser.h @@ -35,13 +35,13 @@ public: virtual int EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data); virtual int EventEncounter(QuestEventID evt, std::string encounter_name, uint32 extra_data); - virtual bool HasQuestSub(uint32 npc_id, const char *subname); - virtual bool HasGlobalQuestSub(const char *subname); - virtual bool PlayerHasQuestSub(const char *subname); - virtual bool GlobalPlayerHasQuestSub(const char *subname); - virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname); - virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname); - virtual bool EncounterHasQuestSub(std::string encounter_name, const char *subname); + virtual bool HasQuestSub(uint32 npc_id, QuestEventID evt); + virtual bool HasGlobalQuestSub(QuestEventID evt); + virtual bool PlayerHasQuestSub(QuestEventID evt); + virtual bool GlobalPlayerHasQuestSub(QuestEventID evt); + virtual bool SpellHasQuestSub(uint32 spell_id, QuestEventID evt); + virtual bool ItemHasQuestSub(ItemInst *itm, QuestEventID evt); + virtual bool EncounterHasQuestSub(std::string encounter_name, QuestEventID evt); virtual void LoadNPCScript(std::string filename, int npc_id); virtual void LoadGlobalNPCScript(std::string filename); @@ -78,6 +78,7 @@ private: bool HasFunction(std::string function, std::string package_name); void ClearStates(); void MapFunctions(lua_State *L); + QuestEventID ConvertLuaEvent(QuestEventID evt); std::map vars_; std::map loaded_; diff --git a/zone/lua_parser_events.cpp b/zone/lua_parser_events.cpp index 1d72a09be..8c6c2856b 100644 --- a/zone/lua_parser_events.cpp +++ b/zone/lua_parser_events.cpp @@ -151,7 +151,7 @@ void handle_npc_hate(QuestInterface *parse, lua_State* L, NPC* npc, Mob *init, s void handle_npc_signal(QuestInterface *parse, lua_State* L, NPC* npc, Mob *init, std::string data, uint32 extra_data, std::vector *items) { lua_pushinteger(L, std::stoi(data)); - lua_setfield(L, -2, "signal_id"); + lua_setfield(L, -2, "signal"); } void handle_npc_timer(QuestInterface *parse, lua_State* L, NPC* npc, Mob *init, std::string data, uint32 extra_data, @@ -243,7 +243,7 @@ void handle_player_death(QuestInterface *parse, lua_State* L, Client* client, st } lua_pushinteger(L, std::stoi(sep.arg[3])); - lua_setfield(L, -2, "skill_id"); + lua_setfield(L, -2, "skill"); } void handle_player_timer(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data) { @@ -379,8 +379,8 @@ void handle_player_command(QuestInterface *parse, lua_State* L, Client* client, luabind::object args = luabind::newtable(L); int max_args = sep.GetMaxArgNum(); for(int i = 1; i < max_args; ++i) { - if(strlen(sep.arg[0]) > 0) { - args[i] = sep.arg[i]; + if(strlen(sep.arg[i]) > 0) { + args[i] = std::string(sep.arg[i]); } } diff --git a/zone/net.cpp b/zone/net.cpp index 56e44383c..878b7dcb5 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -42,7 +42,6 @@ #include "../common/memory_mapped_file.h" #include "../common/eqemu_exception.h" #include "../common/spdat.h" -#include "../common/callback_manager.h" #include "ZoneConfig.h" #include "masterentity.h" @@ -289,10 +288,6 @@ int main(int argc, char** argv) { parse->RegisterQuestInterface(perl_parser, "pl"); #endif - RegisterEQCallback("OnItemInstDestroy", [](void* item) { - quest_manager.stop_item_timers(reinterpret_cast(item)); - }); - //now we have our parser, load the quests _log(ZONE__INIT, "Loading quests"); parse->ReloadQuests(); diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index 5a3caf40b..78e7af6e8 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -119,13 +119,7 @@ void QuestManager::Process() { end = QTimerList.end(); while (cur != end) { if (cur->Timer_.Enabled() && cur->Timer_.Check()) { - - if(cur->item) { - parse->EventItem(EVENT_TIMER, cur->mob->CastToClient(), cur->item, nullptr, cur->name, 0); - - cur = QTimerList.begin(); - end = QTimerList.end(); - } else if(entity_list.IsMobInZone(cur->mob)) { + if(entity_list.IsMobInZone(cur->mob)) { if(cur->mob->IsNPC()) { parse->EventNPC(EVENT_TIMER, cur->mob->CastToNPC(), nullptr, cur->name, 0); } @@ -453,12 +447,20 @@ void QuestManager::Zone(const char *zone_name) { void QuestManager::settimer(const char *timer_name, int seconds) { QuestManagerCurrentQuestVars(); + if(questitem) { + auto timers = questitem->GetTimers(); + Timer t(seconds * 1000); + t.Start(seconds * 1000, false); + timers[timer_name] = t; + return; + } + std::list::iterator cur = QTimerList.begin(), end; end = QTimerList.end(); while (cur != end) { - if (cur->mob == owner && cur->item == questitem && cur->name == timer_name) { - cur->mob = owner; + if(cur->mob && cur->mob == owner && cur->name == timer_name) + { cur->Timer_.Enable(); cur->Timer_.Start(seconds * 1000, false); return; @@ -466,18 +468,26 @@ void QuestManager::settimer(const char *timer_name, int seconds) { cur++; } - QTimerList.push_back(QuestTimer(seconds * 1000, owner, questitem, timer_name)); + QTimerList.push_back(QuestTimer(seconds * 1000, owner, timer_name)); } void QuestManager::settimerMS(const char *timer_name, int milliseconds) { QuestManagerCurrentQuestVars(); + if(questitem) { + auto timers = questitem->GetTimers(); + Timer t(milliseconds); + t.Start(milliseconds, false); + timers[timer_name] = t; + return; + } + std::list::iterator cur = QTimerList.begin(), end; end = QTimerList.end(); while (cur != end) { - if (cur->mob == owner && cur->item == questitem && cur->name == timer_name) { - cur->mob = owner; + if(cur->mob && cur->mob == owner && cur->name == timer_name) + { cur->Timer_.Enable(); cur->Timer_.Start(milliseconds, false); return; @@ -485,7 +495,7 @@ void QuestManager::settimerMS(const char *timer_name, int milliseconds) { cur++; } - QTimerList.push_back(QuestTimer(milliseconds, owner, questitem, timer_name)); + QTimerList.push_back(QuestTimer(milliseconds, owner, timer_name)); } void QuestManager::stoptimer(const char *timer_name) { @@ -496,7 +506,7 @@ void QuestManager::stoptimer(const char *timer_name) { end = QTimerList.end(); while (cur != end) { - if(cur->mob == owner && cur->item == questitem && cur->name == timer_name) + if(cur->mob && cur->mob == owner && cur->name == timer_name) { QTimerList.erase(cur); return; @@ -513,7 +523,7 @@ void QuestManager::stopalltimers() { end = QTimerList.end(); while (cur != end) { - if(cur->mob == owner && cur->item == questitem) + if(cur->mob && cur->mob == owner) { tmp = cur; tmp++; @@ -2899,19 +2909,3 @@ ItemInst *QuestManager::GetQuestItem() const { return nullptr; } - -void QuestManager::stop_item_timers(ItemInst *item) { - if(item_timers == 0) - return; - - auto iter = QTimerList.begin(); - while(iter != QTimerList.end()) { - if(iter->item == item) { - iter = QTimerList.erase(iter); - --item_timers; - continue; - } - - ++iter; - } -} diff --git a/zone/questmgr.h b/zone/questmgr.h index c5a426b23..fa5ec0655 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -237,7 +237,6 @@ public: Mob *GetOwner() const; ItemInst *GetQuestItem() const; inline bool ProximitySayInUse() { return HaveProximitySays; } - void stop_item_timers(ItemInst *item); #ifdef BOTS int createbotcount(); @@ -258,10 +257,9 @@ private: class QuestTimer { public: - inline QuestTimer(int duration, Mob *_mob, ItemInst *_item, std::string _name) - : mob(_mob), item(_item), name(_name), Timer_(duration) { Timer_.Start(duration, false); } + inline QuestTimer(int duration, Mob *_mob, std::string _name) + : mob(_mob), name(_name), Timer_(duration) { Timer_.Start(duration, false); } Mob* mob; - ItemInst *item; std::string name; Timer Timer_; }; diff --git a/zone/spell_effects.cpp b/zone/spell_effects.cpp index b56f7b93d..6c27bec92 100644 --- a/zone/spell_effects.cpp +++ b/zone/spell_effects.cpp @@ -141,7 +141,7 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial) if(IsNPC()) { - int i = parse->EventSpell(EVENT_SPELL_EFFECT, CastToNPC(), nullptr, spell_id, caster ? caster->GetID() : 0); + int i = parse->EventSpell(EVENT_SPELL_EFFECT_NPC, CastToNPC(), nullptr, spell_id, caster ? caster->GetID() : 0); if(i != 0){ CalcBonuses(); return true; @@ -149,7 +149,7 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial) } else if(IsClient()) { - int i = parse->EventSpell(EVENT_SPELL_EFFECT, nullptr, CastToClient(), spell_id, caster ? caster->GetID() : 0); + int i = parse->EventSpell(EVENT_SPELL_EFFECT_CLIENT, nullptr, CastToClient(), spell_id, caster ? caster->GetID() : 0); if(i != 0){ CalcBonuses(); return true; @@ -3066,14 +3066,14 @@ void Mob::DoBuffTic(uint16 spell_id, uint32 ticsremaining, uint8 caster_level, M if(IsNPC()) { - int i = parse->EventSpell(EVENT_SPELL_BUFF_TIC, CastToNPC(), nullptr, spell_id, caster ? caster->GetID() : 0); + int i = parse->EventSpell(EVENT_SPELL_BUFF_TIC_NPC, CastToNPC(), nullptr, spell_id, caster ? caster->GetID() : 0); if(i != 0) { return; } } else { - int i = parse->EventSpell(EVENT_SPELL_BUFF_TIC, nullptr, CastToClient(), spell_id, caster ? caster->GetID() : 0); + int i = parse->EventSpell(EVENT_SPELL_BUFF_TIC_CLIENT, nullptr, CastToClient(), spell_id, caster ? caster->GetID() : 0); if(i != 0) { return; } diff --git a/zone/spells.cpp b/zone/spells.cpp index aab165935..d6f65a59d 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -4672,362 +4672,6 @@ bool Client::SpellGlobalCheck(uint16 Spell_ID, uint16 Char_ID) { return false; // Default is false } -//this is one nasty function... FindType and FindSpell are rather complex operations... -/*void Mob::CheckBuffs() { - if (!IsCasting()) { - - //try to summon a pet if we havent yet - CheckPet(); - - uint8 newtype[15] = { SE_ArmorClass, SE_STR, SE_DEX, SE_AGI, SE_WIS, - SE_INT, SE_CHA, SE_AttackSpeed, SE_MovementSpeed, - SE_DamageShield, SE_ResistFire, SE_ResistCold, - SE_ResistMagic, SE_ResistPoison, SE_ResistDisease }; - for (int h=0; h<15; h++) { - if (!this->FindType(newtype[h])) { - uint16 buffid = FindSpell(this->class_, this->level, - newtype[h], SPELLTYPE_SELF, 0, - GetMana()); - if (buffid != 0) { - this->CastSpell(buffid, this->GetID()); - } - } - } - } -} - -void Mob::CheckPet() { - if(HasPet()) - return; - uint16 buffid = 0; - if ((GetClass() == NECROMANCER || GetClass() == MAGICIAN)) { - if (this->GetClass() == MAGICIAN) { - buffid = FindSpell(class_, level, - SE_SummonPet, SPELLTYPE_OTHER, 0, - GetMana()); - } else if (GetClass() == NECROMANCER) { - buffid = FindSpell(class_, level, - SE_NecPet, SPELLTYPE_OTHER, 0, - GetMana()); - } - if (buffid != 0) { - CastSpell(buffid, GetID()); - } - } -} - -uint16 Mob::FindSpell(uint16 classp, uint16 level, int type, - FindSpellType spelltype, float distance, - int32 mana_avail) { - int i,j; - - int bestvalue = -1; - int bestid = 0; - - if (classp < 1) - return 0; - if (level < 1) - return 0; - classp = GetEQArrayEQClass(classp); - - // purpose: find a suited spell for a class and level and type - // the if's are here to filter out anything which isnt normal. - // its possible that we miss some valid spells, but who cares. - - for (i = 0; i < SPDAT_RECORDS; i++) { - if(!IsValidSpell(i)) - continue; - // Filter all spells that should never be used - if (spells[i].effectid[0] == SE_NegateIfCombat) - continue; - if (spells[i].targettype == ST_Group) - continue; - if (i == 2632) // fix for obsolete BST pet summon spell - continue; - if (i == 1576) // fix for torpor - continue; - if (spells[i].cast_time < 11) - continue; - if (spells[i].mana == 0) - continue; - - // now for closer checks - if (spelltype == SPELLTYPE_SELF) { - if ( i == 357) // fix for dark empathy - continue; - // check buffs 12 would be max, but 90% of all effects are in the first 4 slots - for (j = 0; j < 5; j++) { - // fix for pets - if ( spells[i].effectid[j] == SE_Illusion && - type != SE_Illusion) // only let illusions thru if explicitly requested - continue; - if (spells[i].effectid[j] == type && - spells[i].goodEffect != 0 && - spells[i].classes[classp] <= level && - spells[i].classes[classp] <= 65 && - (spells[i].recast_time < 10000 || - type == SE_SummonPet || - type == SE_SummonBSTPet) && // fix for druid pets - (type == SE_AbsorbMagicAtt || type == SE_Rune || - type == SE_NecPet || type == SE_SummonPet || - spells[i].components[0] == -1 ) && - spells[i].targettype != ST_Undead && // for necro mend series - spells[i].targettype != ST_Group && // fix for group spells - spells[i].targettype != ST_Pet && // fix for beastlords casting pet heals on self - spells[i].targettype != ST_Summoned && // fix for vs. summoned spells on normal npcs - spells[i].targettype != ST_AETarget && // dont let em cast AEtarget spells - spells[i].mana <= mana_avail && - spells[i].range >= distance) { - int32 spellvalue; - - // lets assume pet is always better if higher, so no formula needed - if (type == SE_NecPet || - type == SE_SummonPet || - type == SE_SummonBSTPet) { - spellvalue = spells[i].classes[classp]; - } else { - spellvalue = CalcSpellEffectValue_formula(spells[i].formula[j], - spells[i].base[j], - spells[i].max[j], - level, i); - } - - if (abs(spellvalue) > bestvalue) { - bestvalue = abs(spellvalue); - bestid = i; - } - } - } - } else if (spelltype == SPELLTYPE_OFFENSIVE) { - // check offensive spells - for (j = 0; j < 5; j++) { - if (spells[i].effectid[j] == SE_Illusion && - type != SE_Illusion) // only let illusions thru if explicitly requested - continue; - if (spells[i].effectid[j] == type && - spells[i].goodEffect == 0 && - spells[i].classes[classp] <= level && - spells[i].classes[classp] <= 65 && - spells[i].recast_time < 10000 && - spells[i].components[0] == -1 && - spells[i].mana <= mana_avail && - spells[i].targettype != ST_Undead && // thats for the necro mend series - spells[i].targettype != ST_Group && // fix for group spells - spells[i].targettype != ST_Pet && // fix for beastlords casting pet heals on self - spells[i].targettype != ST_Summoned && // fix for vs. summoned spells on normal npcs - spells[i].targettype != ST_AETarget && // dont let em cast AEtarget spells - spells[i].range >= distance) { - int32 spellvalue = CalcSpellEffectValue_formula(spells[i].formula[j], - spells[i].base[j], - spells[i].max[j], - level, i); - if ( abs(spellvalue) > bestvalue ) { - bestvalue = abs(spellvalue); - bestid = i; - } - } - } - } else if (spelltype == SPELLTYPE_OTHER) { - if ( i == 357) // fix for dark empathy - continue; - // healing and such - for (j = 0; j < 5; j++) { - if (spells[i].effectid[j] == SE_Illusion && - type != SE_Illusion) // only let illusions thru if explicitly requested - continue; - if (spells[i].effectid[j] == type && - spells[i].targettype != ST_Self && - spells[i].goodEffect != 0 && - spells[i].classes[classp] <= level && - spells[i].classes[classp] <= 65 && - spells[i].recast_time < 10000 && - spells[i].components[0] == -1 && - spells[i].targettype != ST_Undead && // thats for the necro mend series - spells[i].targettype != ST_Group && // fix for group spells - spells[i].targettype != ST_Pet && // fix for beastlords casting pet heals on self - spells[i].targettype != ST_Summoned && // fix for vs. summoned spells on normal npcs - spells[i].targettype != ST_AETarget && // dont let em cast AEtarget spells - spells[i].mana <= mana_avail && - spells[i].range >= distance) { - int32 spellvalue = CalcSpellEffectValue_formula(spells[i].formula[j], - spells[i].base[j], - spells[i].max[j], - level, i); - if ( abs(spellvalue) > bestvalue ) { - bestvalue = abs(spellvalue); - bestid = i; - } - } - } - } - } // for i - -// g_LogFile.write("for combination [class %02d][level %02d][SE_type %02d][type %02d] i selected the spell: %s", -// classp, level, (uint16)type, uint16(spelltype), spells[bestid].name); - return bestid; -} - -#if 0 -uint16 Mob::FindSpell(uint16 classp, uint16 level, uint8 type, uint8 spelltype) { - if (this->casting_spell_id != 0) - return 0; - - if (spelltype == 2) // for future use - spelltype = 0; - - //int count=0; - uint16 bestsofar = 0; - uint16 bestspellid = 0; - for (int i = 0; i < SPDAT_RECORDS; i++) { - if ((IsLifetapSpell(i) && spelltype == 1) || (spells[i].targettype != ST_Group && spells[i].targettype != ST_Undead && spells[i].targettype != ST_Summoned && spells[i].targettype != ST_Pet && strstr(spells[i].name,"Summoning") == nullptr)) { - int Canuse = CanUseSpell(i, classp, level); - if (Canuse != 0) { - for (int z=0; z < 12; z++) { - int spfo = CalcSpellValue(spells[i].formula[z], spells[i].base[z], spells[i].max[z], this->GetLevel()); - if (spells[i].effectid[z] == SE_ArmorClass && type == SE_ArmorClass && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_TotalHP && type == SE_TotalHP && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_STR && type == SE_STR && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_DEX && type == SE_DEX && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - - if (spells[i].effectid[z] == SE_AGI && type == SE_AGI && !FindBuff(i)) { - - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - - if (spells[i].effectid[z] == SE_WIS && type == SE_WIS && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - - if (spells[i].effectid[z] == SE_INT && type == SE_INT && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_CHA && type == SE_CHA && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - - if (spells[i].effectid[z] == SE_MovementSpeed && type == SE_MovementSpeed && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - - if (spells[i].effectid[z] == SE_AttackSpeed && type == SE_AttackSpeed && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_ResistFire && type == SE_ResistFire && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_ResistCold && type == SE_ResistCold && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_ResistMagic && type == SE_ResistMagic && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_ResistDisease && type == SE_ResistDisease && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - - } - } - if (spells[i].effectid[z] == SE_ResistPoison && type == SE_ResistPoison && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_DamageShield && type == SE_DamageShield && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_CurrentHPOnce && type == SE_CurrentHPOnce && !FindBuff(i)) { - if (spfo > 0 && (spfo + spells[i].buffduration) > bestsofar) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_SummonPet && type == SE_SummonPet && !FindBuff(i)) { - if (Canuse > bestsofar) { - bestsofar = Canuse; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_NecPet && type == SE_NecPet && !FindBuff(i)) { - if (Canuse > bestsofar) { - bestsofar = Canuse; - bestspellid = i; - } - } - if (spells[i].effectid[z] == SE_CurrentHP && type == SE_CurrentHP && !FindBuff(i)) { - if (spfo < 0 && (spells[i].buffduration + spfo) < bestsofar && spelltype == 1) { - bestsofar = ((spells[i].buffduration * -1) + spfo); - bestspellid = i; - } - if ((spfo + spells[i].buffduration) > bestsofar && spfo > 0 && spelltype == 0) { - bestsofar = spfo + spells[i].buffduration; - bestspellid = i; - } - - } - } - } - } - } - - return bestspellid; -} -#endif -*/ - // TODO get rid of this int16 Mob::GetBuffSlotFromType(uint16 type) { uint32 buff_count = GetMaxTotalSlots(); diff --git a/zone/trading.cpp b/zone/trading.cpp index e81a21d9c..54b2c50ad 100644 --- a/zone/trading.cpp +++ b/zone/trading.cpp @@ -569,7 +569,7 @@ void Client::FinishTrade(Mob* tradingWith, ServerPacket* qspack, bool finalizer) } bool quest_npc = false; - if(parse->HasQuestSub(tradingWith->GetNPCTypeID(), "EVENT_TRADE")) { + if(parse->HasQuestSub(tradingWith->GetNPCTypeID(), EVENT_TRADE)) { // This is a quest NPC quest_npc = true; }