mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-11 03:31:08 +00:00
[Loot] Remove from shared memory, simplification (#3988)
* First pass of pulling loot out of shared memory, functional * More code cleanup * More cleanup * More cleanup * More cleanup * Add loot reload type * Reload, logging * Update npc.h * Cleanup * Logging, don't load attempt to load loottable id 0 * Update worldserver.cpp * Update client.cpp * Update zone_loot.cpp * PR feedback * Update zone.cpp * Memory leak suggestion * Update CMakeLists.txt * Post rebase issues
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include "../../common/json/json.hpp"
|
||||
#include "../zone.h"
|
||||
|
||||
extern Zone* zone;
|
||||
extern Zone *zone;
|
||||
|
||||
void SidecarApi::LootSimulatorController(const httplib::Request &req, httplib::Response &res)
|
||||
{
|
||||
@@ -17,7 +17,7 @@ void SidecarApi::LootSimulatorController(const httplib::Request &req, httplib::R
|
||||
|
||||
auto npc_type = content_db.LoadNPCTypesData(npc_id);
|
||||
if (npc_type) {
|
||||
auto npc = new NPC(
|
||||
auto npc = new NPC(
|
||||
npc_type,
|
||||
nullptr,
|
||||
glm::vec4(0, 0, 0, 0),
|
||||
@@ -47,51 +47,64 @@ void SidecarApi::LootSimulatorController(const httplib::Request &req, httplib::R
|
||||
|
||||
entity_list.AddNPC(npc);
|
||||
|
||||
j["data"]["loottable_id"] = loottable_id;
|
||||
j["data"]["loottable_id"] = loottable_id;
|
||||
j["data"]["npc_id"] = npc_id;
|
||||
j["data"]["npc_name"] = npc->GetCleanName();
|
||||
j["data"]["rolled_items_count"] = npc->GetRolledItems().size();
|
||||
j["data"]["iterations"] = iterations;
|
||||
|
||||
// npc level loot table
|
||||
auto loot_table = database.GetLootTable(loottable_id);
|
||||
auto loot_table = zone->GetLootTable(loottable_id);
|
||||
if (!loot_table) {
|
||||
res.status = 400;
|
||||
j["error"] = fmt::format("Loot table not found [{}]", loottable_id);
|
||||
res.set_content(j.dump(), "application/json");
|
||||
return;
|
||||
}
|
||||
for (uint32 i = 0; i < loot_table->NumEntries; i++) {
|
||||
auto le = loot_table->Entries[i];
|
||||
|
||||
nlohmann::json jle;
|
||||
jle["lootdrop_id"] = le.lootdrop_id;
|
||||
jle["droplimit"] = le.droplimit;
|
||||
jle["mindrop"] = le.mindrop;
|
||||
jle["multiplier"] = le.multiplier;
|
||||
jle["probability"] = le.probability;
|
||||
auto le = zone->GetLootTableEntries(loottable_id);
|
||||
|
||||
auto loot_drop = database.GetLootDrop(le.lootdrop_id);
|
||||
if (!loot_drop) {
|
||||
// translate above for loop using le
|
||||
for (auto &e: le) {
|
||||
auto loot_drop = zone->GetLootdrop(e.lootdrop_id);
|
||||
if (!loot_drop.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (uint32 ei = 0; ei < loot_drop->NumEntries; ei++) {
|
||||
auto e = loot_drop->Entries[ei];
|
||||
int rolled_count = npc->GetRolledItemCount(e.item_id);
|
||||
const EQ::ItemData *item = database.GetItem(e.item_id);
|
||||
LogLootDetail(
|
||||
"# Lootdrop ID [{}] drop_limit [{}] min_drop [{}] mult [{}] probability [{}]",
|
||||
e.lootdrop_id,
|
||||
e.droplimit,
|
||||
e.mindrop,
|
||||
e.multiplier,
|
||||
e.probability
|
||||
);
|
||||
|
||||
nlohmann::json jle;
|
||||
jle["lootdrop_id"] = e.lootdrop_id;
|
||||
jle["droplimit"] = e.droplimit;
|
||||
jle["mindrop"] = e.mindrop;
|
||||
jle["multiplier"] = e.multiplier;
|
||||
jle["probability"] = e.probability;
|
||||
|
||||
auto loot_drop_entries = zone->GetLootdropEntries(e.lootdrop_id);
|
||||
int slot = 0;
|
||||
|
||||
for (auto &f: loot_drop_entries) {
|
||||
int rolled_count = npc->GetRolledItemCount(f.item_id);
|
||||
const EQ::ItemData *item = database.GetItem(f.item_id);
|
||||
|
||||
auto rolled_percentage = (float) ((float) ((float) rolled_count / (float) iterations) * 100);
|
||||
|
||||
nlohmann::json drop;
|
||||
drop["slot"] = ei;
|
||||
drop["item_id"] = e.item_id;
|
||||
drop["slot"] = slot;
|
||||
drop["item_id"] = f.item_id;
|
||||
drop["item_name"] = item->Name;
|
||||
drop["chance"] = fmt::format("{:.2f}", e.chance);
|
||||
drop["chance"] = fmt::format("{:.2f}", f.chance);
|
||||
drop["simulate_rolled_count"] = rolled_count;
|
||||
drop["simulate_rolled_percentage"] = fmt::format("{:.2f}", rolled_percentage);
|
||||
jle["drops"].push_back(drop);
|
||||
slot++;
|
||||
}
|
||||
|
||||
j["lootdrops"].push_back(jle);
|
||||
@@ -99,66 +112,58 @@ void SidecarApi::LootSimulatorController(const httplib::Request &req, httplib::R
|
||||
|
||||
// global loot
|
||||
for (auto &id: zone->GetGlobalLootTables(npc)) {
|
||||
loot_table = database.GetLootTable(id);
|
||||
loot_table = zone->GetLootTable(id);
|
||||
if (!loot_table) {
|
||||
LogInfo("Global Loot table not found [{}]", id);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (uint32 i = 0; i < loot_table->NumEntries; i++) {
|
||||
auto le = loot_table->Entries[i];
|
||||
le = zone->GetLootTableEntries(id);
|
||||
|
||||
LogInfo(
|
||||
"# Lootdrop ID [{}] drop_limit [{}] min_drop [{}] mult [{}] probability [{}]",
|
||||
le.lootdrop_id,
|
||||
le.droplimit,
|
||||
le.mindrop,
|
||||
le.multiplier,
|
||||
le.probability
|
||||
);
|
||||
|
||||
nlohmann::json jle;
|
||||
jle["lootdrop_id"] = le.lootdrop_id;
|
||||
jle["droplimit"] = le.droplimit;
|
||||
jle["mindrop"] = le.mindrop;
|
||||
jle["multiplier"] = le.multiplier;
|
||||
jle["probability"] = le.probability;
|
||||
|
||||
auto loot_drop = database.GetLootDrop(le.lootdrop_id);
|
||||
if (!loot_drop) {
|
||||
// translate above for loop using le
|
||||
for (auto &e: le) {
|
||||
auto loot_drop = zone->GetLootdrop(e.lootdrop_id);
|
||||
if (!loot_drop.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (uint32 ei = 0; ei < loot_drop->NumEntries; ei++) {
|
||||
auto e = loot_drop->Entries[ei];
|
||||
int rolled_count = npc->GetRolledItemCount(e.item_id);
|
||||
const EQ::ItemData *item = database.GetItem(e.item_id);
|
||||
LogLootDetail(
|
||||
"# Lootdrop ID [{}] drop_limit [{}] min_drop [{}] mult [{}] probability [{}]",
|
||||
e.lootdrop_id,
|
||||
e.droplimit,
|
||||
e.mindrop,
|
||||
e.multiplier,
|
||||
e.probability
|
||||
);
|
||||
|
||||
auto rolled_percentage = (float) ((float) ((float) rolled_count / (float) iterations) *
|
||||
100);
|
||||
nlohmann::json jle;
|
||||
jle["lootdrop_id"] = e.lootdrop_id;
|
||||
jle["droplimit"] = e.droplimit;
|
||||
jle["mindrop"] = e.mindrop;
|
||||
jle["multiplier"] = e.multiplier;
|
||||
jle["probability"] = e.probability;
|
||||
|
||||
auto loot_drop_entries = zone->GetLootdropEntries(e.lootdrop_id);
|
||||
int slot = 0;
|
||||
|
||||
LogInfo(
|
||||
"-- [{}] item_id [{}] chance [{}] rolled_count [{}] ({:.2f}%) name [{}]",
|
||||
ei,
|
||||
e.item_id,
|
||||
e.chance,
|
||||
rolled_count,
|
||||
rolled_percentage,
|
||||
item->Name
|
||||
);
|
||||
for (auto &f: loot_drop_entries) {
|
||||
int rolled_count = npc->GetRolledItemCount(f.item_id);
|
||||
const EQ::ItemData *item = database.GetItem(f.item_id);
|
||||
|
||||
auto rolled_percentage = (float) ((float) ((float) rolled_count / (float) iterations) * 100);
|
||||
|
||||
nlohmann::json drop;
|
||||
drop["slot"] = ei;
|
||||
drop["item_id"] = e.item_id;
|
||||
drop["slot"] = slot;
|
||||
drop["item_id"] = f.item_id;
|
||||
drop["item_name"] = item->Name;
|
||||
drop["chance"] = fmt::format("{:.2f}", e.chance);
|
||||
drop["chance"] = fmt::format("{:.2f}", f.chance);
|
||||
drop["simulate_rolled_count"] = rolled_count;
|
||||
drop["simulate_rolled_percentage"] = fmt::format("{:.2f}", rolled_percentage);
|
||||
jle["drops"].push_back(drop);
|
||||
|
||||
j["global"]["lootdrops"].push_back(jle);
|
||||
slot++;
|
||||
}
|
||||
|
||||
j["global"]["lootdrops"].push_back(jle);
|
||||
}
|
||||
}
|
||||
j["data"]["time"] = benchmark.elapsed();
|
||||
|
||||
Reference in New Issue
Block a user