Skip to content

Commit

Permalink
Fixed merchantlist probability.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Kinglykrab committed Jan 27, 2018
1 parent 8e9fa38 commit ffc67c1
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 69 deletions.
2 changes: 1 addition & 1 deletion zone/client_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion zone/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion zone/lua_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions zone/lua_npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions zone/lua_npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
1 change: 0 additions & 1 deletion zone/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ class NPC : public Mob
std::list<MercData> mercDataList;

bool raid_target;
uint8 probability;
bool ignore_despawn; //NPCs with this set to 1 will ignore the despawn value in spawngroup

private:
Expand Down
50 changes: 0 additions & 50 deletions zone/perl_npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, "$$$");
Expand Down
1 change: 0 additions & 1 deletion zone/zonedump.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ struct NPCType
float healscale;
bool no_target_hotkey;
bool raid_target;
uint8 probability;
uint8 armtexture;
uint8 bracertexture;
uint8 handtexture;
Expand Down

0 comments on commit ffc67c1

Please sign in to comment.