MCPcopy Create free account
hub / github.com/EQEmu/EQEmu / LootSimulatorController

Method LootSimulatorController

zone/sidecar_api/loot_simulator_controller.cpp:7–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5extern Zone *zone;
6
7void SidecarApi::LootSimulatorController(const httplib::Request &req, httplib::Response &res)
8{
9 int loottable_id = req.has_param("loottable_id") ? std::stoi(req.get_param_value("loottable_id")) : 4027;
10 int npc_id = req.has_param("npc_id") ? std::stoi(req.get_param_value("npc_id")) : 32040; // lord nagafen
11 auto iterations = 100;
12 auto log_enabled = false;
13
14 EQEmuLogSys::Instance()->log_settings[Logs::Loot].log_to_console = 0;
15
16 nlohmann::json j;
17
18 auto npc_type = content_db.LoadNPCTypesData(npc_id);
19 if (npc_type) {
20 auto npc = new NPC(
21 npc_type,
22 nullptr,
23 glm::vec4(0, 0, 0, 0),
24 GravityBehavior::Water
25 );
26 BenchTimer benchmark;
27
28 // depop the previous one
29 for (auto &n: entity_list.GetNPCList()) {
30 if (n.second->GetNPCTypeID() == npc_id) {
31 LogInfo("found npc id [{}]", npc_id);
32 n.second->Depop(false);
33 }
34 }
35
36 entity_list.Process();
37 entity_list.MobProcess();
38 npc->SetRecordLootStats(true);
39
40 for (int i = 0; i < iterations; i++) {
41 npc->AddLootTable(loottable_id);
42
43 for (auto &id: zone->GetGlobalLootTables(npc)) {
44 npc->AddLootTable(id);
45 }
46 }
47
48 entity_list.AddNPC(npc);
49
50 j["data"]["loottable_id"] = loottable_id;
51 j["data"]["npc_id"] = npc_id;
52 j["data"]["npc_name"] = npc->GetCleanName();
53 j["data"]["rolled_items_count"] = npc->GetRolledItems().size();
54 j["data"]["iterations"] = iterations;
55
56 // npc level loot table
57 auto loot_table = zone->GetLootTable(loottable_id);
58 if (!loot_table) {
59 res.status = 400;
60 j["error"] = fmt::format("Loot table not found [{}]", loottable_id);
61 res.set_content(j.dump(), "application/json");
62 return;
63 }
64

Callers

nothing calls this directly

Calls 15

has_paramMethod · 0.80
get_param_valueMethod · 0.80
LoadNPCTypesDataMethod · 0.80
MobProcessMethod · 0.80
SetRecordLootStatsMethod · 0.80
AddNPCMethod · 0.80
GetLootTableMethod · 0.80
set_contentMethod · 0.80
dumpMethod · 0.80
GetLootTableEntriesMethod · 0.80
GetRolledItemCountMethod · 0.80
push_backMethod · 0.80

Tested by

no test coverage detected