diff --git a/changelog.txt b/changelog.txt index 380793866..f5b75ff98 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,9 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- +== 11/06/2014 == +demonstar55: Tracking default sort will now be correct order +Trevius: Fixed dynamic merchant list loading. Allows any merchant to be used in any zone. + == 11/03/2014 == Secrets: Fixed an overflow in melee lifetap calculations (int16 vs int32) Secrets: Fixed overflow on AC and ATK values that can go out of range. diff --git a/zone/entity.cpp b/zone/entity.cpp index d5354386f..76b9eb8d4 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -63,6 +63,7 @@ extern uint16 adverrornum; Entity::Entity() { id = 0; + spawn_timestamp = time(nullptr); } Entity::~Entity() @@ -2934,8 +2935,14 @@ void EntityList::SignalMobsByNPCID(uint32 snpc, int signal_id) } } +bool tracking_compare(const std::pair &a, const std::pair &b) +{ + return a.first->GetSpawnTimeStamp() > b.first->GetSpawnTimeStamp(); +} + bool EntityList::MakeTrackPacket(Client *client) { + std::list > tracking_list; uint32 distance = 0; float MobDistance; @@ -2950,60 +2957,42 @@ bool EntityList::MakeTrackPacket(Client *client) if (distance < 300) distance = 300; - uint32 spe= 0; - bool ret = false; - - spe = mob_list.size() + 50; - - uchar *buffer1 = new uchar[sizeof(Track_Struct)]; - Track_Struct *track_ent = (Track_Struct*) buffer1; - - uchar *buffer2 = new uchar[sizeof(Track_Struct)*spe]; - Tracking_Struct *track_array = (Tracking_Struct*) buffer2; - memset(track_array, 0, sizeof(Track_Struct)*spe); - - uint32 array_counter = 0; - Group *g = client->GetGroup(); - auto it = mob_list.begin(); - while (it != mob_list.end()) { - if (it->second && ((MobDistance = it->second->DistNoZ(*client)) <= distance)) { - if ((it->second != client) && it->second->IsTrackable()) { - memset(track_ent, 0, sizeof(Track_Struct)); - Mob *cur_entity = it->second; - track_ent->entityid = cur_entity->GetID(); - track_ent->distance = MobDistance; - track_ent->level = cur_entity->GetLevel(); - track_ent->NPC = !cur_entity->IsClient(); - if (g && cur_entity->IsClient() && g->IsGroupMember(cur_entity->CastToMob())) - track_ent->GroupMember = 1; - else - track_ent->GroupMember = 0; - strn0cpy(track_ent->name, cur_entity->GetName(), sizeof(track_ent->name)); - memcpy(&track_array->Entrys[array_counter], track_ent, sizeof(Track_Struct)); - array_counter++; - } - } + for (auto it = mob_list.cbegin(); it != mob_list.cend(); ++it) { + if (!it->second || it->second == client || !it->second->IsTrackable()) + continue; - ++it; + MobDistance = it->second->DistNoZ(*client); + if (MobDistance > distance) + continue; + + tracking_list.push_back(std::make_pair(it->second, MobDistance)); } - if (array_counter <= spe) { - EQApplicationPacket* outapp = new EQApplicationPacket(OP_Track,sizeof(Track_Struct)*(array_counter)); - memcpy(outapp->pBuffer, track_array,sizeof(Track_Struct)*(array_counter)); - outapp->priority = 6; - client->QueuePacket(outapp); - safe_delete(outapp); - ret = true; - } else { - LogFile->write(EQEMuLog::Status, "ERROR: Unable to transmit a Tracking_Struct packet. Mobs in zone = %i. Mobs in packet = %i", array_counter, spe); + tracking_list.sort(tracking_compare); + EQApplicationPacket *outapp = new EQApplicationPacket(OP_Track, sizeof(Track_Struct) * tracking_list.size()); + Tracking_Struct *outtrack = (Tracking_Struct *)outapp->pBuffer; + outapp->priority = 6; + + int index = 0; + for (auto it = tracking_list.cbegin(); it != tracking_list.cend(); ++it, ++index) { + Mob *cur_entity = it->first; + outtrack->Entrys[index].entityid = cur_entity->GetID(); + outtrack->Entrys[index].distance = it->second; + outtrack->Entrys[index].level = cur_entity->GetLevel(); + outtrack->Entrys[index].NPC = !cur_entity->IsClient(); + if (g && cur_entity->IsClient() && g->IsGroupMember(cur_entity->CastToMob())) + outtrack->Entrys[index].GroupMember = 1; + else + outtrack->Entrys[index].GroupMember = 0; + strn0cpy(outtrack->Entrys[index].name, cur_entity->GetName(), sizeof(outtrack->Entrys[index].name)); } - safe_delete_array(buffer1); - safe_delete_array(buffer2); + client->QueuePacket(outapp); + safe_delete(outapp); - return ret; + return true; } void EntityList::MessageGroup(Mob *sender, bool skipclose, uint32 type, const char *message, ...) diff --git a/zone/entity.h b/zone/entity.h index ad5de09bf..2e6990231 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -97,6 +97,7 @@ public: const Beacon *CastToBeacon() const; inline const uint16& GetID() const { return id; } + inline const time_t& GetSpawnTimeStamp() const { return spawn_timestamp; } virtual const char* GetName() { return ""; } bool CheckCoordLosNoZLeaps(float cur_x, float cur_y, float cur_z, float trg_x, float trg_y, float trg_z, float perwalk=1); @@ -112,6 +113,7 @@ protected: uint32 pDBAsyncWorkID; private: uint16 id; + time_t spawn_timestamp; }; class EntityList diff --git a/zone/mob.cpp b/zone/mob.cpp index 513057fed..5a56a2180 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -608,7 +608,7 @@ int32 Mob::CalcMaxMana() { int32 Mob::CalcMaxHP() { max_hp = (base_hp + itembonuses.HP + spellbonuses.HP); - max_hp += max_hp * ((aabonuses.MaxHPChange + spellbonuses.MaxHPChange + itembonuses.MaxHPChange) / 10000); + max_hp += max_hp * ((aabonuses.MaxHPChange + spellbonuses.MaxHPChange + itembonuses.MaxHPChange) / 10000.0f); return max_hp; } diff --git a/zone/spell_effects.cpp b/zone/spell_effects.cpp index b97ca0244..924af5555 100644 --- a/zone/spell_effects.cpp +++ b/zone/spell_effects.cpp @@ -299,7 +299,7 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial) //This effect can also do damage by percent. if (val < 0) { - if (-val > spell.max[i]) + if (spell.max[i] && -val > spell.max[i]) val = -spell.max[i]; if (caster) @@ -309,7 +309,7 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial) else { - if (val > spell.max[i]) + if (spell.max[i] && val > spell.max[i]) val = spell.max[i]; if(caster) @@ -2647,7 +2647,7 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial) case SE_Taunt: { if (IsNPC()){ - caster->Taunt(this->CastToNPC(), false, spell.base[i]); + caster->Taunt(this->CastToNPC(), false, static_cast(spell.base[i])); if (spell.base2[i] > 0) CastToNPC()->SetHate(caster, (CastToNPC()->GetHateAmount(caster) + spell.base2[i])); @@ -3558,6 +3558,8 @@ void Mob::DoBuffTic(uint16 spell_id, int slot, uint32 ticsremaining, uint8 caste case SE_WipeHateList: { + if (IsMezSpell(spell_id)) + break; int wipechance = spells[spell_id].base[i]; int bonus = 0; diff --git a/zone/zone.cpp b/zone/zone.cpp index 476a61f2a..add9e7c6e 100644 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -445,7 +445,7 @@ void Zone::LoadNewMerchantData(uint32 merchantid) { std::list merlist; std::string query = StringFormat("SELECT item, slot, faction_required, level_required, alt_currency_cost, " - "classes_required FROM merchantlist WHERE merchantid=%d ORDER BY slot", merchantid); + "classes_required, probability FROM merchantlist WHERE merchantid=%d ORDER BY slot", merchantid); auto results = database.QueryDatabase(query); if (!results.Success()) { LogFile->write(EQEMuLog::Error, "Error in LoadNewMerchantData query '%s' %s", query.c_str(), results.ErrorMessage().c_str()); @@ -459,8 +459,9 @@ void Zone::LoadNewMerchantData(uint32 merchantid) { ml.slot = atoul(row[1]); ml.faction_required = atoul(row[2]); ml.level_required = atoul(row[3]); - ml.alt_currency_cost = atoul(row[3]); - ml.classes_required = atoul(row[4]); + ml.alt_currency_cost = atoul(row[4]); + ml.classes_required = atoul(row[5]); + ml.probability = atoul(row[6]); merlist.push_back(ml); }