From ffc67c18ef6a8113fb60076d5679dab481ae0ede Mon Sep 17 00:00:00 2001 From: Kinglykrab Date: Sat, 27 Jan 2018 18:32:00 -0500 Subject: [PATCH] Fixed merchantlist probability. NPCs were setting a singular chance value and each item was checking based on this value, making the probability field not a random chance per item. This removes the probability field from NPCs, SetMerchantProbability() and GetMerchantProbability() and makes the probability field truly random chance. Special thanks to ChaosSlayerZ for noticing the issue here: http://www.eqemulator.org/forums/showthread.php?t=41731 --- zone/client_process.cpp | 2 +- zone/entity.cpp | 1 - zone/lua_general.cpp | 1 - zone/lua_npc.cpp | 12 ---------- zone/lua_npc.h | 2 -- zone/npc.h | 1 - zone/perl_npc.cpp | 50 ----------------------------------------- zone/zonedump.h | 1 - 8 files changed, 1 insertion(+), 69 deletions(-) diff --git a/zone/client_process.cpp b/zone/client_process.cpp index ef7469aaefe..21863dbd357 100644 --- a/zone/client_process.cpp +++ b/zone/client_process.cpp @@ -887,7 +887,7 @@ void Client::BulkSendMerchantInventory(int merchant_id, int npcid) { uint8 handychance = 0; for (itr = merlist.begin(); itr != merlist.end() && i <= numItemSlots; ++itr) { MerchantList ml = *itr; - if (merch->CastToNPC()->GetMerchantProbability() > ml.probability) + if (ml.probability != 100 && zone->random.Int(1, 100) > ml.probability) continue; if (GetLevel() < ml.level_required) diff --git a/zone/entity.cpp b/zone/entity.cpp index 4b0599541fc..74208f08571 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -644,7 +644,6 @@ void EntityList::AddCorpse(Corpse *corpse, uint32 in_id) void EntityList::AddNPC(NPC *npc, bool SendSpawnPacket, bool dontqueue) { npc->SetID(GetFreeID()); - npc->SetMerchantProbability((uint8) zone->random.Int(0, 99)); parse->EventNPC(EVENT_SPAWN, npc, nullptr, "", 0); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index aad0be464d4..ec22fec1b35 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -1464,7 +1464,6 @@ void lua_create_npc(luabind::adl::object table, float x, float y, float z, float LuaCreateNPCParse(healscale, float, 0); LuaCreateNPCParse(no_target_hotkey, bool, false); LuaCreateNPCParse(raid_target, bool, false); - LuaCreateNPCParse(probability, uint8, 0); NPC* npc = new NPC(npc_type, nullptr, glm::vec4(x, y, z, heading), FlyMode3); npc->GiveNPCTypeData(npc_type); diff --git a/zone/lua_npc.cpp b/zone/lua_npc.cpp index 50ff597f67c..164e4146cc0 100644 --- a/zone/lua_npc.cpp +++ b/zone/lua_npc.cpp @@ -488,16 +488,6 @@ void Lua_NPC::MerchantCloseShop() { self->MerchantCloseShop(); } -void Lua_NPC::SetMerchantProbability(uint8 amt) { - Lua_Safe_Call_Void(); - self->SetMerchantProbability(amt); -} - -uint8 Lua_NPC::GetMerchantProbability() { - Lua_Safe_Call_Int(); - return self->GetMerchantProbability(); -} - int Lua_NPC::GetRawAC() { Lua_Safe_Call_Int(); return self->GetRawAC(); @@ -608,8 +598,6 @@ luabind::scope lua_register_npc() { .def("GetScore", (int(Lua_NPC::*)(void))&Lua_NPC::GetScore) .def("MerchantOpenShop", (void(Lua_NPC::*)(void))&Lua_NPC::MerchantOpenShop) .def("MerchantCloseShop", (void(Lua_NPC::*)(void))&Lua_NPC::MerchantCloseShop) - .def("SetMerchantProbability", (void(Lua_NPC::*)(void))&Lua_NPC::SetMerchantProbability) - .def("GetMerchantProbability", (uint8(Lua_NPC::*)(void))&Lua_NPC::GetMerchantProbability) .def("GetRawAC", (int(Lua_NPC::*)(void))&Lua_NPC::GetRawAC) .def("GetAvoidanceRating", &Lua_NPC::GetAvoidanceRating); } diff --git a/zone/lua_npc.h b/zone/lua_npc.h index d3d673641ea..cab47b5d6b8 100644 --- a/zone/lua_npc.h +++ b/zone/lua_npc.h @@ -123,8 +123,6 @@ class Lua_NPC : public Lua_Mob int GetScore(); void MerchantOpenShop(); void MerchantCloseShop(); - void SetMerchantProbability(uint8 amt); - uint8 GetMerchantProbability(); int GetRawAC(); int GetAvoidanceRating(); }; diff --git a/zone/npc.h b/zone/npc.h index 4c67dd1d2bf..2023c1b1db0 100644 --- a/zone/npc.h +++ b/zone/npc.h @@ -537,7 +537,6 @@ class NPC : public Mob std::list mercDataList; bool raid_target; - uint8 probability; bool ignore_despawn; //NPCs with this set to 1 will ignore the despawn value in spawngroup private: diff --git a/zone/perl_npc.cpp b/zone/perl_npc.cpp index 64e71d82ff6..18594e17ad4 100644 --- a/zone/perl_npc.cpp +++ b/zone/perl_npc.cpp @@ -2304,54 +2304,6 @@ XS(XS_NPC_GetScore) XSRETURN(1); } -XS(XS_NPC_SetMerchantProbability); -XS(XS_NPC_SetMerchantProbability) { - dXSARGS; - if (items != 2) - Perl_croak(aTHX_ "Usage: NPC::SetMerchantProbability(THIS, Probability)"); - { - NPC *THIS; - uint8 Probability = (uint8)SvIV(ST(1)); - - if (sv_derived_from(ST(0), "NPC")) { - IV tmp = SvIV((SV*)SvRV(ST(0))); - THIS = INT2PTR(NPC *,tmp); - } - else - Perl_croak(aTHX_ "THIS is not of type NPC"); - if(THIS == nullptr) - Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); - - THIS->SetMerchantProbability(Probability); - } - XSRETURN_EMPTY; -} - -XS(XS_NPC_GetMerchantProbability); -XS(XS_NPC_GetMerchantProbability) { - dXSARGS; - if (items != 1) - Perl_croak(aTHX_ "Usage: NPC::GetMerchantProbability(THIS)"); - { - NPC *THIS; - uint8 RETVAL; - dXSTARG; - - if (sv_derived_from(ST(0), "NPC")) { - IV tmp = SvIV((SV*)SvRV(ST(0))); - THIS = INT2PTR(NPC *,tmp); - } - else - Perl_croak(aTHX_ "THIS is not of type NPC"); - if(THIS == NULL) - Perl_croak(aTHX_ "THIS is NULL, avoiding crash."); - - RETVAL = THIS->GetMerchantProbability(); - XSprePUSH; PUSHu((UV)RETVAL); - } - XSRETURN(1); -} - XS(XS_NPC_AddMeleeProc); XS(XS_NPC_AddMeleeProc) { dXSARGS; @@ -2677,8 +2629,6 @@ XS(boot_NPC) newXSproto(strcpy(buf, "GetAvoidanceRating"), XS_NPC_GetAvoidanceRating, file, "$"); newXSproto(strcpy(buf, "GetSpawnKillCount"), XS_NPC_GetSpawnKillCount, file, "$"); newXSproto(strcpy(buf, "GetScore"), XS_NPC_GetScore, file, "$"); - newXSproto(strcpy(buf, "SetMerchantProbability"), XS_NPC_SetMerchantProbability, file, "$$"); - newXSproto(strcpy(buf, "GetMerchantProbability"), XS_NPC_GetMerchantProbability, file, "$"); newXSproto(strcpy(buf, "AddMeleeProc"), XS_NPC_AddMeleeProc, file, "$$$"); newXSproto(strcpy(buf, "AddRangedProc"), XS_NPC_AddRangedProc, file, "$$$"); newXSproto(strcpy(buf, "AddDefensiveProc"), XS_NPC_AddDefensiveProc, file, "$$$"); diff --git a/zone/zonedump.h b/zone/zonedump.h index 2bd78c2d8da..d305e410556 100644 --- a/zone/zonedump.h +++ b/zone/zonedump.h @@ -126,7 +126,6 @@ struct NPCType float healscale; bool no_target_hotkey; bool raid_target; - uint8 probability; uint8 armtexture; uint8 bracertexture; uint8 handtexture;