void GuildTaskMgr::CheckItemTask(uint32 itemId, uint32 obtained, Player* ownerPlayer, Player* bot, bool byMail) { uint32 guildId = bot->GetGuildId(); if (!guildId) return; uint32 owner = (uint32)ownerPlayer->GetGUID().GetRawValue(); sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: checking guild task", bot->GetGuild()->GetName().c_str(), ownerPlayer->GetName().c_str()); uint32 itemTask = GetTaskValue(owner, guildId, "itemTask"); if (itemTask != itemId) { sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: item %u is not guild task item (%u)", bot->GetGuild()->GetName().c_str(), ownerPlayer->GetName().c_str(), itemId, itemTask); return; } if (byMail) { ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemId); if (!proto) return; uint32 money = GetTaskValue(owner, guildId, "payment"); SetTaskValue(owner, guildId, "payment", money + auctionbot.GetBuyPrice(proto) * obtained, sPlayerbotAIConfig.maxGuildTaskRewardTime); } uint32 count = GetTaskValue(owner, guildId, "itemCount"); if (obtained >= count) { sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: guild task complete", bot->GetGuild()->GetName().c_str(), ownerPlayer->GetName().c_str()); SetTaskValue(owner, guildId, "reward", 1, urand(sPlayerbotAIConfig.minGuildTaskRewardTime, sPlayerbotAIConfig.maxGuildTaskRewardTime)); ChatHandler(ownerPlayer->GetSession()).PSendSysMessage("You have completed a guild task"); } else { sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: guild task progress", bot->GetGuild()->GetName().c_str(), ownerPlayer->GetName().c_str()); SetTaskValue(owner, guildId, "itemCount", count - obtained, sPlayerbotAIConfig.maxGuildTaskChangeTime); SetTaskValue(owner, guildId, "thanks", 1, urand(sPlayerbotAIConfig.minGuildTaskRewardTime, sPlayerbotAIConfig.maxGuildTaskRewardTime)); } }
bool GuildTaskMgr::CreateItemTask(uint32 owner, uint32 guildId) { Player* player = sObjectMgr->GetPlayerByLowGUID(owner); if (!player) return false; uint32 itemId = sRandomItemMgr.GetRandomItem(RANDOM_ITEM_GUILD_TASK); if (!itemId) { sLog->outMessage("gtask", LOG_LEVEL_ERROR, "%s / %s: no items avaible for item task", sGuildMgr->GetGuildById(guildId)->GetName().c_str(), player->GetName().c_str()); return false; } uint32 count = GetMaxItemTaskCount(itemId); sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: item task %u (x%d)", sGuildMgr->GetGuildById(guildId)->GetName().c_str(), player->GetName().c_str(), itemId, count); SetTaskValue(owner, guildId, "itemCount", count, sPlayerbotAIConfig.maxGuildTaskChangeTime); SetTaskValue(owner, guildId, "itemTask", itemId, sPlayerbotAIConfig.maxGuildTaskChangeTime); return true; }
bool GuildTaskMgr::CreateKillTask(uint32 owner, uint32 guildId) { Player* player = sObjectMgr->GetPlayerByLowGUID(owner); if (!player) return false; vector<uint32> ids; CreatureTemplateContainer const* creatureTemplateContainer = sObjectMgr->GetCreatureTemplates(); for (CreatureTemplateContainer::const_iterator i = creatureTemplateContainer->begin(); i != creatureTemplateContainer->end(); ++i) { CreatureTemplate const& co = i->second; if (co.rank != CREATURE_ELITE_RARE) continue; if (co.minlevel > player->getLevel() || co.maxlevel < player->getLevel() - 5) continue; ids.push_back(i->first); } if (ids.empty()) { sLog->outMessage("gtask", LOG_LEVEL_ERROR, "%s / %s: no rare creatures available for kill task", sGuildMgr->GetGuildById(guildId)->GetName().c_str(), player->GetName().c_str()); return false; } uint32 index = urand(0, ids.size() - 1); uint32 creatureId = ids[index]; sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: kill task %u", sGuildMgr->GetGuildById(guildId)->GetName().c_str(), player->GetName().c_str(), creatureId); SetTaskValue(owner, guildId, "killTask", creatureId, sPlayerbotAIConfig.maxGuildTaskChangeTime); return true; }
void GuildTaskMgr::CheckKillTask(Player* player, Unit* victim) { uint32 owner = player->GetGUID().GetCounter(); Creature* creature = victim->ToCreature(); if (!creature) return; map<uint32,uint32> tasks = GetTaskValues(owner, "killTask"); for (map<uint32,uint32>::iterator i = tasks.begin(); i != tasks.end(); ++i) { uint32 guildId = i->first; uint32 value = i->second; Guild* guild = sGuildMgr->GetGuildById(guildId); if (value != creature->GetCreatureTemplate()->Entry) continue; sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: guild task complete", guild->GetName().c_str(), player->GetName().c_str()); SetTaskValue(owner, guildId, "reward", 1, urand(sPlayerbotAIConfig.minGuildTaskRewardTime, sPlayerbotAIConfig.maxGuildTaskRewardTime)); ChatHandler(player->GetSession()).PSendSysMessage("You have completed a guild task"); } }
bool GuildTaskMgr::Reward(uint32 owner, uint32 guildId) { Guild *guild = sGuildMgr->GetGuildById(guildId); if (!guild) return false; Player* player = sObjectMgr->GetPlayerByLowGUID(owner); if (!player) return false; Player* leader = sObjectMgr->GetPlayerByLowGUID(guild->GetLeaderGUID()); if (!leader) return false; uint32 itemTask = GetTaskValue(owner, guildId, "itemTask"); uint32 killTask = GetTaskValue(owner, guildId, "killTask"); if (!itemTask && !killTask) return false; ostringstream body; body << "Hello, " << player->GetName() << ",\n"; body << "\n"; if (itemTask) { ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemTask); if (!proto) return false; body << "We wish to thank you for the " << proto->Name1 << " you provided so kindly. We really appreciate this and may this small gift bring you our thanks!\n"; body << "\n"; body << "Many thanks,\n"; body << guild->GetName() << "\n"; body << leader->GetName() << "\n"; } else if (killTask) { CreatureTemplate const* proto = sObjectMgr->GetCreatureTemplate(killTask); if (!proto) return false; body << "We wish to thank you for the " << proto->Name << " you've killed recently. We really appreciate this and may this small gift bring you our thanks!\n"; body << "\n"; body << "Many thanks,\n"; body << guild->GetName() << "\n"; body << leader->GetName() << "\n"; } SQLTransaction trans = CharacterDatabase.BeginTransaction(); MailDraft draft("Thank You", body.str()); uint32 itemId = sRandomItemMgr.GetRandomItem(RANDOM_ITEM_GUILD_TASK_REWARD); if (itemId) { Item* item = Item::CreateItem(itemId, 1, leader); item->SaveToDB(trans); draft.AddItem(item); } draft.AddMoney(GetTaskValue(owner, guildId, "payment")).SendMailTo(trans, MailReceiver(player), MailSender(leader)); CharacterDatabase.CommitTransaction(trans); SetTaskValue(owner, guildId, "activeTask", 0, 0); return true; }
void GuildTaskMgr::Update(Player* player, Player* guildMaster) { if (!sPlayerbotAIConfig.guildTaskEnabled) return; uint32 guildId = guildMaster->GetGuildId(); if (!guildId || !guildMaster->GetPlayerbotAI() || !guildMaster->GetGuild()) return; if (!player->IsFriendlyTo(guildMaster)) return; DenyReason reason = PLAYERBOT_DENY_NONE; PlayerbotSecurityLevel secLevel = guildMaster->GetPlayerbotAI()->GetSecurity()->LevelFor(player, &reason); if (secLevel == PLAYERBOT_SECURITY_DENY_ALL || (secLevel == PLAYERBOT_SECURITY_TALK && reason != PLAYERBOT_DENY_FAR)) { sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: skipping guild task update - not enough security level, reason = %u", guildMaster->GetGuild()->GetName().c_str(), player->GetName().c_str(), reason); return; } uint32 owner = (uint32)player->GetGUID().GetRawValue(); uint32 activeTask = GetTaskValue(owner, guildId, "activeTask"); if (!activeTask) { SetTaskValue(owner, guildId, "killTask", 0, 0); SetTaskValue(owner, guildId, "itemTask", 0, 0); SetTaskValue(owner, guildId, "itemCount", 0, 0); SetTaskValue(owner, guildId, "killTask", 0, 0); SetTaskValue(owner, guildId, "killCount", 0, 0); SetTaskValue(owner, guildId, "payment", 0, 0); SetTaskValue(owner, guildId, "thanks", 1, 2 * sPlayerbotAIConfig.maxGuildTaskChangeTime); SetTaskValue(owner, guildId, "reward", 1, 2 * sPlayerbotAIConfig.maxGuildTaskChangeTime); uint32 task = CreateTask(owner, guildId); if (task == GUILD_TASK_TYPE_NONE) { sLog->outMessage("gtask", LOG_LEVEL_ERROR, "%s / %s: error creating guild task", guildMaster->GetGuild()->GetName().c_str(), player->GetName().c_str()); } uint32 time = urand(sPlayerbotAIConfig.minGuildTaskChangeTime, sPlayerbotAIConfig.maxGuildTaskChangeTime); SetTaskValue(owner, guildId, "activeTask", task, time); SetTaskValue(owner, guildId, "advertisement", 1, urand(sPlayerbotAIConfig.minGuildTaskAdvertisementTime, sPlayerbotAIConfig.maxGuildTaskAdvertisementTime)); sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: guild task %u is set for %u secs", guildMaster->GetGuild()->GetName().c_str(), player->GetName().c_str(), task, time); return; } uint32 advertisement = GetTaskValue(owner, guildId, "advertisement"); if (!advertisement) { sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: sending advertisement", guildMaster->GetGuild()->GetName().c_str(), player->GetName().c_str()); if (SendAdvertisement(owner, guildId)) { SetTaskValue(owner, guildId, "advertisement", 1, urand(sPlayerbotAIConfig.minGuildTaskAdvertisementTime, sPlayerbotAIConfig.maxGuildTaskAdvertisementTime)); } else { sLog->outMessage("gtask", LOG_LEVEL_ERROR, "%s / %s: error sending advertisement", guildMaster->GetGuild()->GetName().c_str(), player->GetName().c_str()); } } uint32 thanks = GetTaskValue(owner, guildId, "thanks"); if (!thanks) { sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: sending thanks", guildMaster->GetGuild()->GetName().c_str(), player->GetName().c_str()); if (SendThanks(owner, guildId)) { SetTaskValue(owner, guildId, "thanks", 1, 2 * sPlayerbotAIConfig.maxGuildTaskChangeTime); SetTaskValue(owner, guildId, "payment", 0, 0); } else { sLog->outMessage("gtask", LOG_LEVEL_ERROR, "%s / %s: error sending thanks", guildMaster->GetGuild()->GetName().c_str(), player->GetName().c_str()); } } uint32 reward = GetTaskValue(owner, guildId, "reward"); if (!reward) { sLog->outMessage("gtask", LOG_LEVEL_DEBUG, "%s / %s: sending reward", guildMaster->GetGuild()->GetName().c_str(), player->GetName().c_str()); if (Reward(owner, guildId)) { SetTaskValue(owner, guildId, "reward", 1, 2 * sPlayerbotAIConfig.maxGuildTaskChangeTime); SetTaskValue(owner, guildId, "payment", 0, 0); } else { sLog->outMessage("gtask", LOG_LEVEL_ERROR, "%s / %s: error sending reward", guildMaster->GetGuild()->GetName().c_str(), player->GetName().c_str()); } } }
void CSVAddPlan::Save() { bool bEnd = false; string strUserID = GetWebUserID(); HitLog LogItem; LogItem.sUserName = strUserID; LogItem.sHitPro = "Plan Set"; LogItem.sHitFunc = "Save"; LogItem.sDesc = szSaveAddInPlan; DWORD dcalBegin=GetTickCount(); InsertHitRecord(LogItem.sUserName, LogItem.sHitPro, LogItem.sHitFunc, LogItem.sDesc, 0, 0); OPEnd: if(bEnd) { DWORD dcalEnd=GetTickCount(); InsertHitRecord(LogItem.sUserName, LogItem.sHitPro, LogItem.sHitFunc, LogItem.sDesc, 1, dcalEnd -dcalBegin); return; } ADD_PLAN_OK addPlan; bool bCheck = 0; addPlan.szName = m_pName->text(); std::list<string> errorMsgList; if (addPlan.szName.empty()) { errorMsgList.push_back(m_FormShowText.szErrorMsg); AddRangeTable->ShowErrorMsg(errorMsgList); //m_pPlanNameError->show(); bEnd = true; goto OPEnd; } //else //{ // AddRangeTable -> HideAllErrorMsg(); // //m_pPlanNameError-> hide(); //} std::string str1 = m_pTasklist->m_pStart[1]->text(); //Jansion.zhou 2006-12-25 //m_pErrMsg->setText(""); //m_pErrMsg->hide(); addPlan.nIndex = m_nIndex; std::list<string> tasknamelist; std::list<string>::iterator m_pItem; bool IsSave = false; bool IsConn = GetAllTaskName(tasknamelist); if(IsConn) { OutputDebugString("----------------isconn true------------------\n"); for(m_pItem = tasknamelist.begin(); m_pItem != tasknamelist.end(); m_pItem++) { std::string str = *m_pItem; if(strcmp(str.c_str(), addPlan.szName.c_str()) == 0) { IsSave = true; break; } } if(strcmp(chgstr.c_str(), "") == 0) { if(!IsSave) { OutputDebugString("----------------Issave false------------------\n"); OBJECT hTask = CreateTask(addPlan.szName); SetTaskValue("Type", m_FormShowText.szPlanTypeRel, hTask); char buf[256]; for(int i = 0; i < 7; i++) { itoa(i, buf, 10); std::string temp = m_pTasklist->m_pStart[i]->text(); std::string temp1 = "start"; temp1 += buf; SetTaskValue(temp1, temp, hTask); temp = m_pTasklist->m_pEnd[i]->text(); temp1 = "end"; temp1 += buf; SetTaskValue(temp1, temp, hTask); temp1 = "Allow"; temp1 += buf; std::string temp3 = m_pTasklist->m_pCombo[i]->currentText(); if(strcmp(temp3.c_str(), strAllown.c_str()) == 0) { SetTaskValue(temp1, m_FormShowText.szStatusAllow, hTask); } else { SetTaskValue(temp1, m_FormShowText.szStatusDeny, hTask); } } SetTaskValue("Description", textarea->text(), hTask); SubmitTask(hTask); //Jansion.zhou 2006-12-25 //m_pErrMsg->setText(""); //m_pErrMsg->hide(); addPlan.nIndex = m_nIndex; //插记录到UserOperateLog表 string strUserID = GetWebUserID(); TTime mNowTime = TTime::GetCurrentTimeEx(); OperateLog m_pOperateLog; m_pOperateLog.InsertOperateRecord("UserOperateLog",strUserID,mNowTime.Format(),strTypeAdd,strTimeTaskPlan,m_pName->text()); emit Successful(addPlan); } else { OutputDebugString("----------------Issave true------------------\n"); //Jansion.zhou 2006-12-25 //m_pErrMsg->setText(m_FormShowText.szErrorMsg1); //m_pErrMsg->show(); errorMsgList.push_back(m_FormShowText.szErrorMsg1); AddRangeTable->ShowErrorMsg(errorMsgList); } } else { std::string str; for(m_pItem = tasknamelist.begin(); m_pItem != tasknamelist.end(); m_pItem++) { str = *m_pItem; if(strcmp(str.c_str(), addPlan.szName.c_str()) == 0) { if(strcmp(str.c_str(), chgstr.c_str()) != 0) { IsSave = true; break; } else { IsSave = false; break; } } } if(!IsSave) { OutputDebugString("----------------Issave00 false------------------\n"); OBJECT hTask = GetTask(chgstr); SetTaskValue("Type", m_FormShowText.szPlanTypeRel, hTask); char buf[256]; for(int i = 0; i < 7; i++) { itoa(i, buf, 10); std::string temp = m_pTasklist->m_pStart[i]->text(); std::string temp1 = "start"; temp1 += buf; SetTaskValue(temp1, temp, hTask); temp = m_pTasklist->m_pEnd[i]->text(); temp1 = "end"; temp1 += buf; SetTaskValue(temp1, temp, hTask); temp1 = "Allow"; temp1 += buf; std::string temp3 = m_pTasklist->m_pCombo[i]->currentText(); if(strcmp(temp3.c_str(), strAllown.c_str()) == 0) { SetTaskValue(temp1, m_FormShowText.szStatusAllow, hTask); } else { SetTaskValue(temp1, m_FormShowText.szStatusDeny, hTask); } } SetTaskValue("Description", textarea->text(), hTask); EditTask(hTask,addPlan.szName); //Jansion.zhou 2006-12-25 //m_pErrMsg->setText(""); //m_pErrMsg->hide(); addPlan.nIndex = m_nIndex; //插记录到UserOperateLog表 string strUserID = GetWebUserID(); TTime mNowTime = TTime::GetCurrentTimeEx(); OperateLog m_pOperateLog; m_pOperateLog.InsertOperateRecord("UserOperateLog",strUserID,mNowTime.Format(),strTypeEdit,strTimeTaskPlan,m_pName->text()); chgstr = ""; emit Successful(addPlan); } else { OutputDebugString("----------------Issave000 true------------------\n"); //Jansion.zhou 2006-12-25 //m_pErrMsg->setText(m_FormShowText.szErrorMsg1); //m_pErrMsg->show(); errorMsgList.push_back(m_FormShowText.szErrorMsg1); AddRangeTable->ShowErrorMsg(errorMsgList); } } } else { } DWORD dcalEnd1=GetTickCount(); InsertHitRecord(LogItem.sUserName, LogItem.sHitPro, LogItem.sHitFunc, LogItem.sDesc, 1, dcalEnd1 - dcalBegin); }