void CHotKey::Save(std::ostream& OutFile) const #else void CHotKey::Save(ostream& OutFile) const #endif { //write out the event name #if _MSC_VER >= 1300 OutFile << strlen(GetEventName()) << std::endl; OutFile << GetEventName() << std::endl; //write out the event name OutFile << strlen(GetDescription()) << std::endl; OutFile << GetDescription() << std::endl; //write out if it is modifiable or not OutFile << ((IsUserChangable()) ? 1 : 0) << std::endl; #else OutFile << strlen(GetEventName()) << endl; OutFile << GetEventName() << endl; //write out the event name OutFile << strlen(GetDescription()) << endl; OutFile << GetDescription() << endl; //write out if it is modifiable or not OutFile << ((IsUserChangable()) ? 1 : 0) << endl; #endif //lists that we need to save const CUIEventList* pLists[] = {&m_StartEventList, &m_EndEventList}; for(uint32 nCurrList = 0; nCurrList < sizeof(pLists) / sizeof(pLists[0]); nCurrList++) { //write out the number of events in the current list uint32 nNumEvents = pLists[nCurrList]->GetSize(); #if _MSC_VER >= 1300 OutFile << nNumEvents << std::endl; #else OutFile << nNumEvents << endl; #endif for(uint32 nCurrEvent = 0; nCurrEvent < nNumEvents; nCurrEvent++) { //cache the event so we don't have to use this ugly thing over and over CUIEvent& Event = *((*pLists[nCurrList])[nCurrEvent]); #if _MSC_VER >= 1300 OutFile << Event.GetType() << std::endl; OutFile << GetEventValue(Event) << std::endl; #else OutFile << Event.GetType() << endl; OutFile << GetEventValue(Event) << endl; #endif } } }
double RandomPlayerbotMgr::GetSellMultiplier(Player* bot) { uint32 id = bot->GetObjectGuid(); uint32 value = GetEventValue(id, "sellmultiplier"); if (!value) { value = urand(80, 250); uint32 validIn = urand(sPlayerbotAIConfig.minRandomBotsPriceChangeInterval, sPlayerbotAIConfig.maxRandomBotsPriceChangeInterval); SetEventValue(id, "sellmultiplier", value, validIn); } return (double)value / 100.0; }
double RandomPlayerbotMgr::GetBuyMultiplier(Player* bot) { uint32 id = bot->GetGUID(); uint32 value = GetEventValue(id, "buymultiplier"); if (!value) { value = urand(1, 120); uint32 validIn = urand(sPlayerbotAIConfig.minRandomBotsPriceChangeInterval, sPlayerbotAIConfig.maxRandomBotsPriceChangeInterval); SetEventValue(id, "buymultiplier", value, validIn); } return (double)value / 100.0; }
void CPUTGUIElement::SetEvents(StringMap eventMap[], CPUTCallbackHandler *pHandler) { if(mEventHandler) { mKeyDown.value = GetEventValue(eventMap, mKeyDown.key); mKeyUp.value = GetEventValue(eventMap, mKeyUp.key); mClick.value = GetEventValue(eventMap, mClick.key); mDown.value = GetEventValue(eventMap, mDown.key); mUp.value = GetEventValue(eventMap, mUp.key); mIn.value = GetEventValue(eventMap, mIn.key); mOut.value = GetEventValue(eventMap, mOut.key); mpHandler = pHandler; } }
//saves the key to the registry bool CHotKey::SaveToRegistry(CGenRegMgr& RegMgr, const char* pszRegDir, const char* pszName) const { CString sKeyName; //write the name of the hotkey sKeyName.Format("%sName", pszName); RegMgr.SetStringValue(pszRegDir, sKeyName, (GetEventName()) ? GetEventName() : ""); //write the description sKeyName.Format("%sDescription", pszName); RegMgr.SetStringValue(pszRegDir, sKeyName, (GetDescription()) ? GetDescription() : ""); //write if it is changable or not sKeyName.Format("%sChangable", pszName); RegMgr.SetStringBoolValue(pszRegDir, sKeyName, IsUserChangable()); //lists that we need to save const CUIEventList* pLists[] = {&m_StartEventList, &m_EndEventList}; for(uint32 nCurrList = 0; nCurrList < sizeof(pLists) / sizeof(pLists[0]); nCurrList++) { //get the number of events in this list uint32 nNumEvents = pLists[nCurrList]->GetSize(); //get the number of events for this hotkey sKeyName.Format("%sList%dNumEvents", pszName, nCurrList); RegMgr.SetDwordValue(pszRegDir, sKeyName, nNumEvents); //write all the events for(uint32 nCurrEvent = 0; nCurrEvent < nNumEvents; nCurrEvent++) { //cache the event so we don't have to use this ugly thing over and over CUIEvent& Event = *((*pLists[nCurrList])[nCurrEvent]); //write out the event type sKeyName.Format("%sList%dEvent%dType", pszName, nCurrList, nCurrEvent); RegMgr.SetDwordValue(pszRegDir, sKeyName, Event.GetType()); //now write out the event value sKeyName.Format("%sList%dEvent%dValue", pszName, nCurrList, nCurrEvent); RegMgr.SetDwordValue(pszRegDir, sKeyName, GetEventValue(Event)); } } return true; }
uint32 RandomPlayerbotMgr::GetLootAmount(Player* bot) { uint32 id = bot->GetObjectGuid(); return GetEventValue(id, "lootamount"); }
bool RandomPlayerbotMgr::IsRandomBot(uint32 bot) { return GetEventValue(bot, "add"); }
void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed) { SetNextCheckDelay(sPlayerbotAIConfig.randomBotUpdateInterval * 1000); if (!sPlayerbotAIConfig.randomBotAutologin || !sPlayerbotAIConfig.enabled) return; sLog.outBasic("Processing random bots..."); int maxAllowedBotCount = GetEventValue(0, "bot_count"); if (!maxAllowedBotCount) { maxAllowedBotCount = urand(sPlayerbotAIConfig.minRandomBots, sPlayerbotAIConfig.maxRandomBots); SetEventValue(0, "bot_count", maxAllowedBotCount, urand(sPlayerbotAIConfig.randomBotCountChangeMinInterval, sPlayerbotAIConfig.randomBotCountChangeMaxInterval)); } list<uint32> bots = GetBots(); int botCount = bots.size(); int allianceNewBots = 0, hordeNewBots = 0; int randomBotsPerInterval = (int)urand(sPlayerbotAIConfig.minRandomBotsPerInterval, sPlayerbotAIConfig.maxRandomBotsPerInterval); if (!processTicks) { if (sPlayerbotAIConfig.randomBotLoginAtStartup) randomBotsPerInterval = bots.size(); } while (botCount++ < maxAllowedBotCount) { bool alliance = botCount % 2; uint32 bot = AddRandomBot(alliance); if (bot) { if (alliance) allianceNewBots++; else hordeNewBots++; bots.push_back(bot); } else break; } int botProcessed = 0; for (list<uint32>::iterator i = bots.begin(); i != bots.end(); ++i) { uint32 bot = *i; if (ProcessBot(bot)) botProcessed++; if (botProcessed >= randomBotsPerInterval) break; } sLog.outString("%d bots processed. %d alliance and %d horde bots added. %d bots online. Next check in %d seconds", botProcessed, allianceNewBots, hordeNewBots, playerBots.size(), sPlayerbotAIConfig.randomBotUpdateInterval); if (processTicks++ == 1) PrintStats(); }
bool RandomPlayerbotMgr::ProcessBot(uint32 bot) { uint32 isValid = GetEventValue(bot, "add"); if (!isValid) { Player* player = GetPlayerBot(bot); if (!player || !player->GetGroup()) { sLog.outDetail("Bot %d expired", bot); SetEventValue(bot, "add", 0, 0); } return true; } if (!GetPlayerBot(bot)) { sLog.outDetail("Bot %d logged in", bot); AddPlayerBot(bot, 0); if (!GetEventValue(bot, "online")) { SetEventValue(bot, "online", 1, sPlayerbotAIConfig.minRandomBotInWorldTime); } return true; } Player* player = GetPlayerBot(bot); if (!player) return false; PlayerbotAI* ai = player->GetPlayerbotAI(); if (!ai) return false; if (player->GetGroup()) { sLog.outDetail("Skipping bot %d as it is in group", bot); return false; } if (player->IsDead()) { if (!GetEventValue(bot, "dead")) { sLog.outDetail("Setting dead flag for bot %d", bot); uint32 randomTime = urand(sPlayerbotAIConfig.minRandomBotReviveTime, sPlayerbotAIConfig.maxRandomBotReviveTime); SetEventValue(bot, "dead", 1, randomTime); SetEventValue(bot, "revive", 1, randomTime - 60); return false; } if (!GetEventValue(bot, "revive")) { sLog.outDetail("Reviving dead bot %d", bot); SetEventValue(bot, "dead", 0, 0); SetEventValue(bot, "revive", 0, 0); RandomTeleport(player, player->GetMapId(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ()); return true; } return false; } uint32 randomize = GetEventValue(bot, "randomize"); if (!randomize) { sLog.outDetail("Randomizing bot %d", bot); Randomize(player); uint32 randomTime = urand(sPlayerbotAIConfig.minRandomBotRandomizeTime, sPlayerbotAIConfig.maxRandomBotRandomizeTime); ScheduleRandomize(bot, randomTime); return true; } uint32 logout = GetEventValue(bot, "logout"); if (!logout) { sLog.outDetail("Logging out bot %d", bot); LogoutPlayerBot(bot); SetEventValue(bot, "logout", 1, sPlayerbotAIConfig.maxRandomBotInWorldTime); return true; } uint32 teleport = GetEventValue(bot, "teleport"); if (!teleport) { sLog.outDetail("Random teleporting bot %d", bot); RandomTeleportForLevel(ai->GetBot()); SetEventValue(bot, "teleport", 1, sPlayerbotAIConfig.maxRandomBotInWorldTime); return true; } return false; }
bool RandomPlayerbotMgr::ProcessBot(uint32 bot) { uint32 isValid = GetEventValue(bot, "add"); if (!isValid) { Player* player = GetPlayerBot(bot); if (!player || !player->GetGroup()) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Bot %d expired", bot); SetEventValue(bot, "add", 0, 0); } return true; } if (!GetPlayerBot(bot)) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Bot %d logged in", bot); AddPlayerBot(bot, 0); if (!GetEventValue(bot, "online")) { SetEventValue(bot, "online", 1, sPlayerbotAIConfig.minRandomBotInWorldTime); } return true; } Player* player = GetPlayerBot(bot); if (!player) return false; PlayerbotAI* ai = player->GetPlayerbotAI(); if (!ai) return false; if (player->GetGroup()) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Skipping bot %d as it is in group", bot); return false; } if (player->isDead()) { if (!GetEventValue(bot, "dead")) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Setting dead flag for bot %d", bot); uint32 randomTime = urand(sPlayerbotAIConfig.minRandomBotReviveTime, sPlayerbotAIConfig.maxRandomBotReviveTime); SetEventValue(bot, "dead", 1, randomTime); SetEventValue(bot, "revive", 1, randomTime - 60); return false; } if (!GetEventValue(bot, "revive")) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Reviving dead bot %d", bot); SetEventValue(bot, "dead", 0, 0); SetEventValue(bot, "revive", 0, 0); RandomTeleport(player, player->GetMapId(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ()); return true; } return false; } if (player->GetGuild() && player->GetGuild()->GetLeaderGUID() == player->GetGUID()) { for (vector<Player*>::iterator i = players.begin(); i != players.end(); ++i) sGuildTaskMgr.Update(*i, player); } uint32 randomize = GetEventValue(bot, "randomize"); if (!randomize) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Randomizing bot %d", bot); Randomize(player); uint32 randomTime = urand(sPlayerbotAIConfig.minRandomBotRandomizeTime, sPlayerbotAIConfig.maxRandomBotRandomizeTime); ScheduleRandomize(bot, randomTime); return true; } uint32 logout = GetEventValue(bot, "logout"); if (!logout) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Logging out bot %d", bot); LogoutPlayerBot(bot); SetEventValue(bot, "logout", 1, sPlayerbotAIConfig.maxRandomBotInWorldTime); return true; } uint32 teleport = GetEventValue(bot, "teleport"); if (!teleport) { sLog->outMessage("playerbot", LOG_LEVEL_INFO, "Random teleporting bot %d", bot); RandomTeleportForLevel(ai->GetBot()); SetEventValue(bot, "teleport", 1, sPlayerbotAIConfig.maxRandomBotInWorldTime); return true; } return false; }