From 6252255f70f172617d02ad1dc2adcd8b0d176e79 Mon Sep 17 00:00:00 2001 From: James Huston Date: Wed, 20 Dec 2023 18:37:26 -0500 Subject: [PATCH] Initial working inventory to client --- conf/mod_araxianpcbot.conf.dist | 93 ++++++++++++++++++++ src/AraxiaNpcBotCommands.cpp | 150 +++++++++++++++++--------------- 2 files changed, 175 insertions(+), 68 deletions(-) diff --git a/conf/mod_araxianpcbot.conf.dist b/conf/mod_araxianpcbot.conf.dist index 961a688..f13ff98 100644 --- a/conf/mod_araxianpcbot.conf.dist +++ b/conf/mod_araxianpcbot.conf.dist @@ -2,3 +2,96 @@ [worldserver] AraxiaNpcBot.Enabled = 1 + +################################################################################################### +# LOGGING SYSTEM SETTINGS +# +# Appender config values: Given an appender "name" +# Appender.name +# Description: Defines 'where to log'. +# Format: Type,LogLevel,Flags,optional1,optional2,optional3 +# +# Type +# 0 - (None) +# 1 - (Console) +# 2 - (File) +# 3 - (DB) +# +# LogLevel +# 0 - (Disabled) +# 1 - (Fatal) +# 2 - (Error) +# 3 - (Warning) +# 4 - (Info) +# 5 - (Debug) +# 6 - (Trace) +# +# Flags: +# 0 - None +# 1 - Prefix Timestamp to the text +# 2 - Prefix Log Level to the text +# 4 - Prefix Log Filter type to the text +# 8 - Append timestamp to the log file name. Format: YYYY-MM-DD_HH-MM-SS +# (Only used with Type = 2) +# 16 - Make a backup of existing file before overwrite +# (Only used with Mode = w) +# +# Colors (read as optional1 if Type = Console) +# Format: "fatal error warn info debug trace" +# 0 - BLACK +# 1 - RED +# 2 - GREEN +# 3 - BROWN +# 4 - BLUE +# 5 - MAGENTA +# 6 - CYAN +# 7 - GREY +# 8 - YELLOW +# 9 - LRED +# 10 - LGREEN +# 11 - LBLUE +# 12 - LMAGENTA +# 13 - LCYAN +# 14 - WHITE +# Example: "1 9 3 6 5 8" +# +# File: Name of the file (read as optional1 if Type = File) +# Allows to use one "%s" to create dynamic files +# +# Mode: Mode to open the file (read as optional2 if Type = File) +# a - (Append) +# w - (Overwrite) +# +# MaxFileSize: Maximum file size of the log file before creating a new log file +# (read as optional3 if Type = File) +# Size is measured in bytes expressed in a 64-bit unsigned integer. +# Maximum value is 4294967295 (4 GB). Leave blank for no limit. +# NOTE: Does not work with dynamic filenames. +# Example: 536870912 (512 MB) +# + +# note that do to what I think is a bug in the Worldserver you must +# copy all 3 of these log lines into your worldserver.conf file +# or else it will not work. + +Appender.AraxiaNpcBotLog=2,5,0,modaraxianpcbot.log,w +Appender.AraxiaNpcBotConsole=1,4,0,"1 9 3 6 5 8" + +# Logger config values: Given a logger "name" +# Logger.name +# Description: Defines 'What to log' +# Format: LogLevel,AppenderList +# +# LogLevel +# 0 - (Disabled) +# 1 - (Fatal) +# 2 - (Error) +# 3 - (Warning) +# 4 - (Info) +# 5 - (Debug) +# 6 - (Trace) +# +# AppenderList: List of appenders linked to logger +# (Using spaces as separator). +# +Logger.araxianpcbot=4,AraxaiNpcBotLog AraxiaNpcBotConsole diff --git a/src/AraxiaNpcBotCommands.cpp b/src/AraxiaNpcBotCommands.cpp index 4c32b1f..db60fc2 100644 --- a/src/AraxiaNpcBotCommands.cpp +++ b/src/AraxiaNpcBotCommands.cpp @@ -3,6 +3,7 @@ #include "Chat.h" #include "Player.h" #include "Unit.h" +#include "ObjectMgr.h" #include "Creature.h" #include "botcommon.h" @@ -21,17 +22,17 @@ class AraxiaNpcBotCommands : public CommandScript ChatCommandTable GetCommands() const override { - static ChatCommandTable inventoryCommandTable = + static ChatCommandTable inventoryCommandTable = { {"get", HandleGetInventory, 1, Console::No } }; - static ChatCommandTable rootCommandTable = + static ChatCommandTable rootCommandTable = { {"inv", inventoryCommandTable} }; - static ChatCommandTable araxiaNpcBotTable = + static ChatCommandTable araxiaNpcBotTable = { {"anpc", rootCommandTable} }; @@ -50,65 +51,64 @@ class AraxiaNpcBotCommands : public CommandScript uint32 entry = target->GetEntry(); - //handler->SendSysMessage("Target Id: " + + //handler->SendSysMessage("Target Id: " + // std::to_string(entry)); // load our bot data from the database; NpcBotData const* botData = BotDataMgr::SelectNpcBotData(entry); if(!botData) { + LOG_DEBUG("AraxiaNpcBot", "No bot data found for entry " + std::to_string(entry)); return false; } - EquipmentInfo const* deinfo = BotDataMgr::GetBotEquipmentInfo(entry); - if (!deinfo) + + std::map itemToTemplate; + + ObjectGuid ownerGuid = ObjectGuid(HighGuid::Player, 0, botData->owner); + std::vector items; + CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_NPCBOT_EQUIP_BY_ITEM_INSTANCE); + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 + //"SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text, guid, itemEntry, owner_guid " + // "FROM item_instance WHERE guid IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_SYNCH + + for (uint8 i = 0; i != BOT_INVENTORY_SIZE; ++i) + stmt->SetData(i, botData->equips[i]); + + PreparedQueryResult iiresult = CharacterDatabase.Query(stmt); + if (iiresult) { - return false; + do + { + Field* fields2 = iiresult->Fetch(); + uint32 itemGuidLow = fields2[11].Get(); + uint32 itemId = fields2[12].Get(); + //Item* item = new Item; + //ASSERT(item->LoadFromDB(itemGuidLow, ownerGuid, fields2, itemId)); + itemToTemplate[itemGuidLow] = itemId; + } while (iiresult->NextRow()); } - std::map itemList; - //handler->SendSysMessage("Bot Owner: " + std::to_string(botData->owner)); - - itemList.insert(std::pair("mainhand", botData->equips[BOT_SLOT_MAINHAND])); - itemList.insert(std::pair("offhand", botData->equips[BOT_SLOT_OFFHAND])); - itemList.insert(std::pair("ranged", botData->equips[BOT_SLOT_RANGED])); - itemList.insert(std::pair("head", botData->equips[BOT_SLOT_HEAD])); - itemList.insert(std::pair("shoulders", botData->equips[BOT_SLOT_SHOULDERS])); - itemList.insert(std::pair("chest", botData->equips[BOT_SLOT_CHEST])); - itemList.insert(std::pair("waist", botData->equips[BOT_SLOT_WAIST])); - itemList.insert(std::pair("legs", botData->equips[BOT_SLOT_LEGS])); - itemList.insert(std::pair("feet", botData->equips[BOT_SLOT_FEET])); - itemList.insert(std::pair("wrist", botData->equips[BOT_SLOT_WRIST])); - itemList.insert(std::pair("hands", botData->equips[BOT_SLOT_HANDS])); - itemList.insert(std::pair("back", botData->equips[BOT_SLOT_BACK])); - itemList.insert(std::pair("body", botData->equips[BOT_SLOT_BODY])); - itemList.insert(std::pair("finger1", botData->equips[BOT_SLOT_FINGER1])); - itemList.insert(std::pair("finger2", botData->equips[BOT_SLOT_FINGER2])); - itemList.insert(std::pair("trinket1", botData->equips[BOT_SLOT_TRINKET1])); - itemList.insert(std::pair("trinket2", botData->equips[BOT_SLOT_TRINKET2])); - itemList.insert(std::pair("neck", botData->equips[BOT_SLOT_NECK])); - -/* - handler->SendSysMessage("MainHand: " + std::to_string(itemList["mainhand"])); - handler->SendSysMessage("OffHand: " + std::to_string(itemList["offhand"])); - handler->SendSysMessage("Ranged: " + std::to_string(itemList["ranged"])); - handler->SendSysMessage("Head: " + std::to_string(itemList["head"])); - handler->SendSysMessage("Shoulders: " + std::to_string(itemList["shoulders"])); - handler->SendSysMessage("Chest: " + std::to_string(itemList["chest"])); - handler->SendSysMessage("Waist: " + std::to_string(itemList["waist"])); - handler->SendSysMessage("Legs: " + std::to_string(itemList["legs"])); - handler->SendSysMessage("Feet: " + std::to_string(itemList["feet"])); - handler->SendSysMessage("Wrist: " + std::to_string(itemList["wrist"])); - handler->SendSysMessage("Hands: " + std::to_string(itemList["hands"])); - handler->SendSysMessage("Back: " + std::to_string(itemList["back"])); - handler->SendSysMessage("Body: " + std::to_string(itemList["body"])); - handler->SendSysMessage("Finger1: " + std::to_string(itemList["finger1"])); - handler->SendSysMessage("Finger2: " + std::to_string(itemList["finger2"])); - handler->SendSysMessage("Trinket1: " + std::to_string(itemList["trinket1"])); - handler->SendSysMessage("Trinket2: " + std::to_string(itemList["trinket2"])); - handler->SendSysMessage("Neck: " + std::to_string(itemList["neck"])); -*/ + std::map itemList; + itemList.insert(std::pair("mainhand", itemToTemplate[botData->equips[BOT_SLOT_MAINHAND]])); + itemList.insert(std::pair("offhand", itemToTemplate[botData->equips[BOT_SLOT_OFFHAND]])); + itemList.insert(std::pair("ranged", itemToTemplate[botData->equips[BOT_SLOT_RANGED]])); + itemList.insert(std::pair("head", itemToTemplate[botData->equips[BOT_SLOT_HEAD]])); + itemList.insert(std::pair("shoulders", itemToTemplate[botData->equips[BOT_SLOT_SHOULDERS]])); + itemList.insert(std::pair("chest", itemToTemplate[botData->equips[BOT_SLOT_CHEST]])); + itemList.insert(std::pair("waist", itemToTemplate[botData->equips[BOT_SLOT_WAIST]])); + itemList.insert(std::pair("legs", itemToTemplate[botData->equips[BOT_SLOT_LEGS]])); + itemList.insert(std::pair("feet", itemToTemplate[botData->equips[BOT_SLOT_FEET]])); + itemList.insert(std::pair("wrist", itemToTemplate[botData->equips[BOT_SLOT_WRIST]])); + itemList.insert(std::pair("hands", itemToTemplate[botData->equips[BOT_SLOT_HANDS]])); + itemList.insert(std::pair("back", itemToTemplate[botData->equips[BOT_SLOT_BACK]])); + itemList.insert(std::pair("body", itemToTemplate[botData->equips[BOT_SLOT_BODY]])); + itemList.insert(std::pair("finger1", itemToTemplate[botData->equips[BOT_SLOT_FINGER1]])); + itemList.insert(std::pair("finger2", itemToTemplate[botData->equips[BOT_SLOT_FINGER2]])); + itemList.insert(std::pair("trinket1", itemToTemplate[botData->equips[BOT_SLOT_TRINKET1]])); + itemList.insert(std::pair("trinket2", itemToTemplate[botData->equips[BOT_SLOT_TRINKET2]])); + itemList.insert(std::pair("neck", itemToTemplate[botData->equips[BOT_SLOT_NECK]])); std::string inv = GetInventoryOutput(entry, itemList); @@ -119,25 +119,39 @@ class AraxiaNpcBotCommands : public CommandScript static std::string GetInventoryOutput(uint32 botEntry, std::map items) { - std::string output = "AraxiaNpcBot:inv.get:" + std::to_string(botEntry) + "::"; - output += "mainhand:" + std::to_string(items["mainhand"]) + "::"; - output += "offhand:" + std::to_string(items["offhand"]) + "::"; - output += "ranged:" + std::to_string(items["ranged"]) + "::"; - output += "head:" + std::to_string(items["head"]) + "::"; - output += "shoulders:" + std::to_string(items["shoulders"]) + "::"; - output += "chest:" + std::to_string(items["chest"]) + "::"; - output += "waist:" + std::to_string(items["waist"]) + "::"; - output += "legs:" + std::to_string(items["legs"]) + "::"; - output += "feet:" + std::to_string(items["feet"]) + "::"; - output += "wrist:" + std::to_string(items["wrist"]) + "::"; - output += "hands:" + std::to_string(items["hands"]) + "::"; - output += "back:" + std::to_string(items["back"]) + "::"; - output += "body:" + std::to_string(items["body"]) + "::"; - output += "finger1:" + std::to_string(items["finger1"]) + "::"; - output += "finger2:" + std::to_string(items["finger2"]) + "::"; - output += "trinket1:" + std::to_string(items["trinket1"]) + "::"; - output += "trinket2:" + std::to_string(items["trinket2"]) + "::"; - output += "neck:" + std::to_string(items["neck"]); + std::string output = "AraxiaNpcBot:inv.get:" + std::to_string(botEntry) + "#"; + + // loop over all of the keys in items + for (auto const& item : items) + { + // ItemTemplate const* it = sObjectMgr->GetItemTemplate(item.second); + // if (!it) + // { + // continue; + // } + output += item.first + ":" + std::to_string(item.second) + "#"; + } + + // output += "mainhand:" + std::to_string(items["mainhand"]) + "#"; + // output += "offhand:" + std::to_string(items["offhand"]) + "#"; + // output += "ranged:" + std::to_string(items["ranged"]) + "#"; + // output += "head:" + std::to_string(items["head"]) + "#"; + // output += "shoulders:" + std::to_string(items["shoulders"]) + "#"; + // output += "chest:" + std::to_string(items["chest"]) + "#"; + // output += "waist:" + std::to_string(items["waist"]) + "#"; + // output += "legs:" + std::to_string(items["legs"]) + "#"; + // output += "feet:" + std::to_string(items["feet"]) + "#"; + // output += "wrist:" + std::to_string(items["wrist"]) + "#"; + // output += "hands:" + std::to_string(items["hands"]) + "#"; + // output += "back:" + std::to_string(items["back"]) + "#"; + // output += "body:" + std::to_string(items["body"]) + "#"; + // output += "finger1:" + std::to_string(items["finger1"]) + "#"; + // output += "finger2:" + std::to_string(items["finger2"]) + "#"; + // output += "trinket1:" + std::to_string(items["trinket1"]) + "#"; + // output += "trinket2:" + std::to_string(items["trinket2"]) + "#"; + // output += "neck:" + std::to_string(items["neck"]); + + LOG_DEBUG("AraxiaNpcBot", "Output: " + output); return output; }