void AchievementInterface::GiveRewardsForAchievement(AchievementEntry * ae) { AchievementReward * ar = AchievementRewardStorage.LookupEntry( ae->ID ); if(!ar) return; // Reward: Item if( ar->ItemID ) { // Just use the in-game mail system and mail it to him. MailMessage msg; memset(&msg, 0, sizeof(MailMessage)); Item* pItem = objmgr.CreateItem( ar->ItemID, NULL ); if(!pItem) return; pItem->SaveToDB( INVENTORY_SLOT_NOT_SET, 0, true, NULL ); msg.items.push_back(pItem->GetUInt32Value(OBJECT_FIELD_GUID)); msg.body = "Your reward for completing this achievement is attached below."; msg.subject = string(ae->name); msg.sender_guid = m_player->GetGUID(); msg.player_guid = m_player->m_playerInfo->guid; msg.delivery_time = (uint32)UNIXTIME; msg.expire_time = 0; // This message NEVER expires. DEBUG_LOG("AchievementInterface","GiveRewardsForAchievement disabled until properly fixed"); // sMailSystem.DeliverMessage(&msg); pItem->Destructor(); } // Reward: Title. We don't yet support titles due to a lack of uint128. }
bool Container::SafeFullRemoveItemFromSlot(int16 slot) { if (slot < 0 || (uint32)slot >= GetProto()->ContainerSlots) return false; Item* pItem = m_Slot[slot]; if (pItem == NULL ||pItem == TO_ITEM(this)) return false; m_Slot[slot] = NULLITEM; SetUInt64Value(CONTAINER_FIELD_SLOT_1 + slot*2, 0 ); pItem->SetUInt64Value(ITEM_FIELD_CONTAINED, 0); if(pItem->IsInWorld()) { pItem->RemoveFromWorld(); } pItem->DeleteFromDB(); pItem->Destructor(); return true; }
void LootRoll::Finalize() { if( !mLootLock.AttemptAcquire() ) // only one finalization, please. players on different maps can roll, too, so this is needed. { sEventMgr.RemoveEvents(this); return; } sEventMgr.RemoveEvents(this); // this we will have to finalize with groups types.. for now // we'll just assume need before greed. person with highest roll // in need gets the item. uint32 highest = 0; int8 hightype = -1; uint64 player = 0; WorldPacket data(34); for(std::map<uint32, uint32>::iterator itr = m_NeedRolls.begin(); itr != m_NeedRolls.end(); itr++) { if(itr->second > highest) { highest = itr->second; player = itr->first; hightype = NEED; } } if(!highest) { for(std::map<uint32, uint32>::iterator itr = m_GreedRolls.begin(); itr != m_GreedRolls.end(); itr++) { if(itr->second > highest) { highest = itr->second; player = itr->first; hightype = GREED; } } } Loot * pLoot = 0; uint32 guidtype = GET_TYPE_FROM_GUID(_guid); if( guidtype == HIGHGUID_TYPE_UNIT ) { Creature* pc = _mgr->GetCreature(GET_LOWGUID_PART(_guid)); if(pc) pLoot = &pc->m_loot; } else if( guidtype == HIGHGUID_TYPE_GAMEOBJECT ) { GameObject* go = _mgr->GetGameObject(GET_LOWGUID_PART(_guid)); if(go) pLoot = &go->m_loot; } if(!pLoot) { delete this; return; } if(_slotid >= pLoot->items.size()) { delete this; return; } pLoot->items.at(_slotid).roll = NULL; uint32 itemid = pLoot->items.at(_slotid).item.itemproto->ItemId; uint32 amt = pLoot->items.at(_slotid).iItemsCount; if(!amt) { delete this; return; } Player* _player = (player) ? _mgr->GetPlayer((uint32)player) : NULL; if(!player || !_player) { /* all passed */ data.Initialize(SMSG_LOOT_ALL_PASSED); data << _guid << _groupcount << _itemid << _randomsuffixid << _randompropertyid; set<uint32>::iterator pitr = m_passRolls.begin(); while(_player == NULL && pitr != m_passRolls.end()) _player = _mgr->GetPlayer( (*(pitr++)) ); if( _player != NULL ) { if(_player->InGroup()) _player->GetGroup()->SendPacketToAll(&data); else _player->GetSession()->SendPacket(&data); } /* item can now be looted by anyone :) */ pLoot->items.at(_slotid).passed = true; delete this; return; } pLoot->items.at(_slotid).roll = 0; data.Initialize(SMSG_LOOT_ROLL_WON); data << _guid << _slotid << _itemid << _randomsuffixid << _randompropertyid; data << _player->GetGUID() << uint8(highest) << uint8(hightype); if(_player->InGroup()) _player->GetGroup()->SendPacketToAll(&data); else _player->GetSession()->SendPacket(&data); ItemPrototype* it = ItemPrototypeStorage.LookupEntry(itemid); int8 error; if((error = _player->GetItemInterface()->CanReceiveItem(it, 1, NULL))) { _player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, error); return; } Item* add = _player->GetItemInterface()->FindItemLessMax(itemid, amt, false); if (!add) { SlotResult slotresult = _player->GetItemInterface()->FindFreeInventorySlot(it); if(!slotresult.Result) { _player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL); return; } DEBUG_LOG("HandleAutostoreItem","AutoLootItem %u",itemid); Item* item = objmgr.CreateItem( itemid, _player); item->SetUInt32Value(ITEM_FIELD_STACK_COUNT,amt); if(pLoot->items.at(_slotid).iRandomProperty!=NULL) { item->SetRandomProperty(pLoot->items.at(_slotid).iRandomProperty->ID); item->ApplyRandomProperties(false); } else if(pLoot->items.at(_slotid).iRandomSuffix != NULL) { item->SetRandomSuffix(pLoot->items.at(_slotid).iRandomSuffix->id); item->ApplyRandomProperties(false); } if( _player->GetItemInterface()->SafeAddItem(item,slotresult.ContainerSlot, slotresult.Slot) ) { _player->GetSession()->SendItemPushResult(item,false,true,true,true,slotresult.ContainerSlot,slotresult.Slot,1); sQuestMgr.OnPlayerItemPickup(_player,item); } else { item->Destructor(); } } else { add->SetCount(add->GetUInt32Value(ITEM_FIELD_STACK_COUNT) + amt); add->m_isDirty = true; sQuestMgr.OnPlayerItemPickup(_player,add); _player->GetSession()->SendItemPushResult(add, false, true, true, false, _player->GetItemInterface()->GetBagSlotByGuid(add->GetGUID()), 0xFFFFFFFF, 1); } pLoot->items.at(_slotid).iItemsCount=0; // this gets sent to all looters data.Initialize(SMSG_LOOT_REMOVED); data << uint8(_slotid); Player* plr; for(LooterSet::iterator itr = pLoot->looters.begin(); itr != pLoot->looters.end(); itr++) { if((plr = _player->GetMapMgr()->GetPlayer(*itr))) plr->GetSession()->SendPacket(&data); } delete this; }
// Charter part void WorldSession::HandleCharterBuy(WorldPacket & recv_data) { CHECK_PACKET_SIZE(recv_data, 8+8+4+1+5*8+2+1+4+4); uint64 creature_guid; uint64 unk1, unk3, unk4, unk5, unk6, unk7; uint32 unk2; std::string name; uint16 unk8; uint8 unk9; uint32 arena_index; uint32 unk10; uint8 error; recv_data >> creature_guid; // NPC GUID recv_data >> unk1; // 0 recv_data >> unk2; // 0 recv_data >> name; // name // recheck CHECK_PACKET_SIZE(recv_data, 8+8+4+(name.size()+1)+5*8+2+1+4+4); recv_data >> unk3; // 0 recv_data >> unk4; // 0 recv_data >> unk5; // 0 recv_data >> unk6; // 0 recv_data >> unk7; // 0 recv_data >> unk8; // 0 recv_data >> unk9; // 0 recv_data >> arena_index; // index recv_data >> unk10; // 0 Creature* crt = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(creature_guid)); if(!crt) { Disconnect(); return; } if( arena_index >= NUM_CHARTER_TYPES ) return; if( crt->IsArenaOrganizer() ) // All arena organizers should be allowed to create arena charter's { uint32 arena_type = arena_index - 1; if(arena_type > 2) return; if(_player->m_playerInfo->arenaTeam[arena_type]) { SendNotification("You are already in an arena team."); return; } if(_player->m_playerInfo->charterId[arena_index] != 0) { SendNotification("You already have an arena charter of this type."); return; } ArenaTeam * t = objmgr.GetArenaTeamByName(name, arena_type); if(t != NULL) { sChatHandler.SystemMessage(this,"That name is already in use."); return; } if(objmgr.GetCharterByName(name, (CharterTypes)arena_index)) { sChatHandler.SystemMessage(this,"That name is already in use."); return; } static uint32 item_ids[] = {ARENA_TEAM_CHARTER_2v2, ARENA_TEAM_CHARTER_3v3, ARENA_TEAM_CHARTER_5v5}; static uint32 costs[] = {ARENA_TEAM_CHARTER_2v2_COST,ARENA_TEAM_CHARTER_3v3_COST,ARENA_TEAM_CHARTER_5v5_COST}; if(_player->GetUInt32Value(PLAYER_FIELD_COINAGE) < costs[arena_type] && !sWorld.free_arena_teams) return; // error message needed here ItemPrototype * ip = ItemPrototypeStorage.LookupEntry(item_ids[arena_type]); ASSERT(ip); SlotResult res = _player->GetItemInterface()->FindFreeInventorySlot(ip); if(res.Result == 0) { _player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL); return; } error = _player->GetItemInterface()->CanReceiveItem(ip,1, NULL); if(error) { _player->GetItemInterface()->BuildInventoryChangeError(NULL,NULL,error); } else { // Create the item and charter Item* i = objmgr.CreateItem(item_ids[arena_type], _player); Charter * c = objmgr.CreateCharter(_player->GetLowGUID(), (CharterTypes)arena_index); c->GuildName = name; c->ItemGuid = i->GetGUID(); i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1); i->SetUInt32Value(ITEM_FIELD_FLAGS, 1); i->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1, c->GetID()); i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883); if( !_player->GetItemInterface()->AddItemToFreeSlot(i) ) { c->Destroy(); c = NULL; i->Destructor(); i = NULL; return; } c->SaveToDB(); SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1); if(!sWorld.free_arena_teams) _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)costs[arena_type]); _player->m_playerInfo->charterId[arena_index] = c->GetID(); _player->SaveToDB(false); } } else { if( _player->GetUInt32Value(PLAYER_FIELD_COINAGE) < 1000 && !sWorld.free_guild_charters ) { SendNotification("You don't have enough money."); return; } if(_player->m_playerInfo->charterId[CHARTER_TYPE_GUILD] != 0) { SendNotification("You already have a guild charter."); return; } Guild * g = objmgr.GetGuildByGuildName(name); Charter * c = objmgr.GetCharterByName(name, CHARTER_TYPE_GUILD); if(g != 0 || c != 0) { SendNotification("A guild with that name already exists."); return; } ItemPrototype * ip = ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER); assert(ip); SlotResult res = _player->GetItemInterface()->FindFreeInventorySlot(ip); if(res.Result == 0) { _player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL); return; } error = _player->GetItemInterface()->CanReceiveItem(ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER),1, NULL); if(error) { _player->GetItemInterface()->BuildInventoryChangeError(NULL,NULL,error); } else { // Meh... WorldPacket data(SMSG_PLAY_OBJECT_SOUND, 12); data << uint32(0x000019C2); data << creature_guid; SendPacket(&data); // Create the item and charter Item* i = objmgr.CreateItem(ITEM_ENTRY_GUILD_CHARTER, _player); c = objmgr.CreateCharter(_player->GetLowGUID(), CHARTER_TYPE_GUILD); c->GuildName = name; c->ItemGuid = i->GetGUID(); i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1); i->SetUInt32Value(ITEM_FIELD_FLAGS, 1); i->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1, c->GetID()); i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883); if( !_player->GetItemInterface()->AddItemToFreeSlot(i) ) { c->Destroy(); i->Destructor(); return; } c->SaveToDB(); SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1); _player->m_playerInfo->charterId[CHARTER_TYPE_GUILD] = c->GetID(); // 10 silver if(!sWorld.free_guild_charters) _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -1000); _player->SaveToDB(false); } } }
void WorldSession::HandleGuildBankDepositItem(WorldPacket & recv_data) { uint64 guid; uint8 source_isfrombank; uint32 wtf; uint8 wtf2; uint32 i; Guild * pGuild = _player->m_playerInfo->guild; GuildMember * pMember = _player->m_playerInfo->guildMember; if(pGuild == NULL || pMember == NULL) return; recv_data >> guid >> source_isfrombank; if(source_isfrombank) { GuildBankTab * pSourceTab; GuildBankTab * pDestTab; Item* pSourceItem; Item* pDestItem; uint8 dest_bank; uint8 dest_bankslot; uint8 source_bank; uint8 source_bankslot; uint8 splitted_count; /* read packet */ recv_data >> dest_bank; recv_data >> dest_bankslot; recv_data >> wtf; recv_data >> source_bank; recv_data >> source_bankslot; recv_data >> wtf; recv_data >> wtf2; recv_data >> splitted_count; /* sanity checks to avoid overflows */ if(source_bankslot >= MAX_GUILD_BANK_SLOTS || dest_bankslot >= MAX_GUILD_BANK_SLOTS || source_bank >= MAX_GUILD_BANK_TABS || dest_bank >= MAX_GUILD_BANK_TABS) { return; } /* make sure we have permissions */ if(!pMember->pRank->CanPerformBankCommand(GR_RIGHT_GUILD_BANK_DEPOSIT_ITEMS, dest_bank) || !pMember->pRank->CanPerformBankCommand(GR_RIGHT_GUILD_BANK_DEPOSIT_ITEMS, source_bank)) return; /* locate the tabs */ pSourceTab = pGuild->GetBankTab((uint32)source_bank); pDestTab = pGuild->GetBankTab((uint32)dest_bank); if(pSourceTab == NULL || pDestTab == NULL) return; if(pSourceTab == pDestTab && source_bankslot == dest_bankslot) return; pSourceItem = pSourceTab->pSlots[source_bankslot]; pDestItem = pDestTab->pSlots[dest_bankslot]; if(pSourceItem == NULL && pDestItem == NULL) return; if(splitted_count) { uint32 source_count = pSourceItem->GetUInt32Value( ITEM_FIELD_STACK_COUNT ); if(pDestItem == NULL) { if(source_count == splitted_count) { // swap pSourceTab->pSlots[source_bankslot] = pDestItem; pDestTab->pSlots[dest_bankslot] = pSourceItem; } else { pSourceItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, -splitted_count ); pDestItem = objmgr.CreateItem(pSourceItem->GetEntry(), NULL); pDestItem->SetUInt32Value(ITEM_FIELD_STACK_COUNT, splitted_count); pDestItem->SetUInt32Value(ITEM_FIELD_CREATOR, pSourceItem->GetUInt32Value(ITEM_FIELD_CREATOR)); pDestTab->pSlots[dest_bankslot] = pDestItem; } } else { pDestItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, splitted_count ); if(splitted_count != source_count) pSourceItem->ModUnsigned32Value( ITEM_FIELD_STACK_COUNT, -splitted_count ); else { pSourceItem->Destructor(); pSourceItem = NULL; pSourceTab->pSlots[source_bankslot] = NULL; } } } else { // swap pSourceTab->pSlots[source_bankslot] = pDestItem; pDestTab->pSlots[dest_bankslot] = pSourceItem; } /* update the client */ if(pSourceTab == pDestTab) { /* send both slots in the packet */ pGuild->SendGuildBank(this, pSourceTab, source_bankslot, dest_bankslot); } else { /* send a packet for each different bag */ pGuild->SendGuildBank(this, pSourceTab, source_bankslot, -1); pGuild->SendGuildBank(this, pDestTab, dest_bankslot, -1); } /* update in sql */ if(pDestItem == NULL) { /* this means the source slot is no longer being used. */ CharacterDatabase.Execute("DELETE FROM guild_bankitems WHERE guildId = %u AND tabId = %u AND slotId = %u", pGuild->GetGuildId(), (uint32)pSourceTab->iTabId, (uint32)source_bankslot); } else { /* insert the new Item* */ CharacterDatabase.Execute("REPLACE INTO guild_bankitems VALUES(%u, %u, %u, %u)", pGuild->GetGuildId(), (uint32)pSourceTab->iTabId, (uint32)source_bankslot, pDestItem->GetLowGUID()); } if(pSourceItem == NULL) { /* this means the destination slot is no longer being used. */ CharacterDatabase.Execute("DELETE FROM guild_bankitems WHERE guildId = %u AND tabId = %u AND slotId = %u", pGuild->GetGuildId(), (uint32)pDestTab->iTabId, (uint32)dest_bankslot); } else { /* insert the new Item* */ CharacterDatabase.Execute("REPLACE INTO guild_bankitems VALUES(%u, %u, %u, %u)", pGuild->GetGuildId(), (uint32)pDestTab->iTabId, (uint32)dest_bankslot, pSourceItem->GetLowGUID()); } } else {
void WorldSession::HandleAcceptTrade(WorldPacket & recv_data) { if(!_player->IsInWorld() || _player->mTradeTarget == 0) return; uint32 TradeStatus = TRADE_STATUS_ACCEPTED; Player* pTarget = _player->GetTradeTarget(); if(pTarget == NULL || !pTarget->IsInWorld()) TradeStatus = TRADE_STATUS_PLAYER_NOT_FOUND; // Tell the other player we're green. if(pTarget->m_session && pTarget->m_session->GetSocket()) pTarget->m_session->SendTradeStatus(TradeStatus); _player->mTradeStatus = TradeStatus; //Both sides accepted? Let's trade! if(_player->mTradeStatus == TRADE_STATUS_ACCEPTED && pTarget->mTradeStatus == TRADE_STATUS_ACCEPTED) { // Ready! uint32 ItemCount = 0; uint32 TargetItemCount = 0; Item* pItem; // Count items on both sides, check if bags are empty. for(uint32 Index = 0; Index < 6; ++Index) { if(_player->mTradeItems[Index] != NULL) { pItem = _player->mTradeItems[Index]; if( pItem != NULL && pItem->IsContainer() && TO_CONTAINER(pItem)->HasItems()) { sCheatLog.writefromsession(this, "%s involved in bag-trick trade with %s", _player->GetName(),pTarget->GetName()); _player->GetItemInterface()->BuildInventoryChangeError( pItem, NULL, INV_ERR_CANT_TRADE_EQUIP_BAGS); TradeStatus = TRADE_STATUS_CANCELLED; break; } else ++ItemCount; } if(pTarget->mTradeItems[Index] != NULL) { pItem = pTarget->mTradeItems[Index]; if( pItem != NULL && pItem->IsContainer() && TO_CONTAINER(pItem)->HasItems() ) { sCheatLog.writefromsession(this, "%s involved in bag-trick trade with %s.", pTarget->GetName(),_player->GetName()); pTarget->GetItemInterface()->BuildInventoryChangeError( pItem, NULL, INV_ERR_CANT_TRADE_EQUIP_BAGS); TradeStatus = TRADE_STATUS_CANCELLED; break; } else ++TargetItemCount; } } //Do we have something to trade? if( ItemCount == 0 && TargetItemCount == 0 && _player->mTradeGold == 0 && pTarget->mTradeGold == 0 ) TradeStatus = TRADE_STATUS_CANCELLED; //Do we have enough free slots on both sides? else if((_player->m_ItemInterface->CalculateFreeSlots(NULL) + ItemCount) < TargetItemCount || (pTarget->m_ItemInterface->CalculateFreeSlots(NULL) + TargetItemCount) < ItemCount ) TradeStatus = TRADE_STATUS_CANCELLED; //Everything still ok? else if(TradeStatus == TRADE_STATUS_ACCEPTED) { uint64 Guid; //Swapp 6 itemslots (7th will not trade) for(uint32 Index = 0; Index < 6; ++Index) { Guid = _player->mTradeItems[Index] ? _player->mTradeItems[Index]->GetGUID() : 0; if(Guid != 0) { if( _player->mTradeItems[Index]->IsSoulbound()) _player->GetItemInterface()->BuildInventoryChangeError( _player->mTradeItems[Index], NULL, INV_ERR_CANNOT_TRADE_THAT); else { //Remove from player pItem = _player->m_ItemInterface->SafeRemoveAndRetreiveItemByGuidRemoveStats(Guid, true); //and add to pTarget if(pItem != NULL) { pItem->SetOwner(pTarget); if( !pTarget->m_ItemInterface->AddItemToFreeSlot(pItem) ) { pItem->Destructor(); pItem = NULL; } } if(GetPermissionCount()>0 || pTarget->GetSession()->GetPermissionCount()>0) sGMLog.writefromsession(this, "trade item %s with %s (soulbound = %d)", _player->mTradeItems[Index]->GetProto()->Name1, pTarget->GetName()); } } Guid = pTarget->mTradeItems[Index] ? pTarget->mTradeItems[Index]->GetGUID() : 0; if(Guid != 0) { if( pTarget->mTradeItems[Index]->IsSoulbound()) pTarget->GetItemInterface()->BuildInventoryChangeError( pTarget->mTradeItems[Index], NULL, INV_ERR_CANNOT_TRADE_THAT); else { //Remove from pTarget pItem = pTarget->m_ItemInterface->SafeRemoveAndRetreiveItemByGuidRemoveStats(Guid, true); //and add to initiator if(pItem != NULL) { pItem->SetOwner(_player); if( !_player->m_ItemInterface->AddItemToFreeSlot(pItem) ) { pItem->Destructor(); pItem = NULL; } } if(GetPermissionCount()>0 || pTarget->GetSession()->GetPermissionCount()>0) sGMLog.writefromsession(this, "trade item %s with %s", pTarget->mTradeItems[Index]->GetProto()->Name1, _player->GetName()); } } } // Trade Gold if(_player->mTradeGold) { pTarget->ModUnsigned32Value(PLAYER_FIELD_COINAGE, _player->mTradeGold); _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)_player->mTradeGold); } if(pTarget->mTradeGold) { _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, pTarget->mTradeGold); pTarget->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)pTarget->mTradeGold); } pTarget->SaveToDB(false); _player->SaveToDB(false); TradeStatus = TRADE_STATUS_COMPLETE; } SendTradeStatus(TradeStatus); if(pTarget->m_session && pTarget->m_session->GetSocket()) pTarget->m_session->SendTradeStatus(TradeStatus); // Reset Trade Vars _player->ResetTradeVariables(); pTarget->ResetTradeVariables(); } }
bool ChatHandler::HandleQuestStartCommand(const char * args, WorldSession * m_session) { if(!*args) return false; Player* plr = getSelectedChar(m_session, true); if(!plr) { plr = m_session->GetPlayer(); SystemMessage(m_session, "Auto-targeting self."); } uint32 quest_id = atol(args); std::string recout = "|cff00ff00"; Quest * qst = QuestStorage.LookupEntry(quest_id); if(qst) { if (plr->HasFinishedQuest(quest_id) || plr->HasFinishedDailyQuest(quest_id)) recout += "Player has already completed that quest."; else { QuestLogEntry * IsPlrOnQuest = plr->GetQuestLogForEntry(quest_id); if (IsPlrOnQuest) recout += "Player is currently on that quest."; else { int32 open_slot = plr->GetOpenQuestSlot(); if (open_slot == -1) { sQuestMgr.SendQuestLogFull(plr); recout += "Player's quest log is full."; } else { QuestLogEntry *qle = new QuestLogEntry(); qle->Init(qst, plr, (uint32)open_slot); qle->UpdatePlayerFields(); CALL_QUESTSCRIPT_EVENT(qle, OnQuestStart)(plr, qle); // If the quest should give any items on begin, give them the items. for(uint32 i = 0; i < 4; ++i) { if(qst->receive_items[i]) { Item* item = objmgr.CreateItem( qst->receive_items[i], plr); if(!plr->GetItemInterface()->AddItemToFreeSlot(item)) { if(item) item->Destructor(); } } } if(qst->srcitem && qst->srcitem != qst->receive_items[0]) { Item* item = objmgr.CreateItem( qst->srcitem, plr); if(item) { item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, qst->srcitemcount ? qst->srcitemcount : 1); if(!plr->GetItemInterface()->AddItemToFreeSlot(item)) { if(item) item->Destructor(); } } } plr->UpdateNearbyGameObjects(); sHookInterface.OnQuestAccept( plr, qst, NULL ); recout += "Quest has been added to the player's quest log."; } } } } else { recout += "Quest Id ["; recout += args; recout += "] was not found and unable to add it to the player's quest log."; } recout += "\n\n"; SendMultilineMessage(m_session, recout.c_str()); return true; }
bool EyeOfTheStorm::GivePoints(uint32 team, uint32 points) { if(m_ended || !m_started) return false; m_points[team] += points; if( m_points[team] >= m_resourceRewards[team] ) { m_resourceRewards[team] += m_resToGainBH; for(set<Player*>::iterator itx = m_players[team].begin(); itx != m_players[team].end(); ++itx) { Player* plr = (*itx); if(!plr) continue; (*itx)->m_bgScore.BonusHonor += m_bonusHonor; HonorHandler::AddHonorPointsToPlayer( plr, m_bonusHonor ); } } if( m_points[team] >= 1600 ) { m_points[team] = 1600; m_mapMgr->GetStateManager().UpdateWorldState( WORLDSTATE_EOTS_ALLIANCE_VICTORYPOINTS + team, m_points[team] ); m_ended = true; m_losingteam = (team) ? 0 : 1; m_nextPvPUpdateTime = 0; sEventMgr.RemoveEvents(this); sEventMgr.AddEvent(TO_CBATTLEGROUND(this), &CBattleground::Close, EVENT_BATTLEGROUND_CLOSE, 120000, 1,0); SendChatMessage( CHAT_MSG_BG_SYSTEM_NEUTRAL, 0, "|cffffff00This battleground will close in 2 minutes."); /* add the marks of honor to all players */ m_mainLock.Acquire(); for(uint32 i = 0; i < 2; ++i) { for(set<Player*>::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr) { (*itr)->Root(); if( (*itr)->HasFlag(PLAYER_FLAGS, PLAYER_FLAG_AFK) ) continue; // create eye of the storm mark of honor uint32 item_count = (i == m_losingteam) ? 1 : 3; if( i != m_losingteam ) { (*itr)->m_bgScore.BonusHonor += 2*m_bonusHonor; HonorHandler::AddHonorPointsToPlayer( (*itr), 2*m_bonusHonor ); } else { (*itr)->m_bgScore.BonusHonor += m_bonusHonor; HonorHandler::AddHonorPointsToPlayer( (*itr), m_bonusHonor ); uint32 diff = abs((int32)(m_points[i] - m_points[i ? 0 : 1])); (*itr)->GetAchievementInterface()->HandleAchievementCriteriaWinBattleground( m_mapMgr->GetMapId(), diff, ((uint32)UNIXTIME - m_startTime) / 1000, TO_CBATTLEGROUND(this)); } Item* pReward; SlotResult res; if( ( pReward = (*itr)->GetItemInterface()->FindItemLessMax(EOTS_MARK_ID, item_count, false) ) == NULL ) { res = (*itr)->GetItemInterface()->FindFreeInventorySlot( ItemPrototypeStorage.LookupEntry(EOTS_MARK_ID) ); if( !res.Result ) { (*itr)->BroadcastMessage("Could not add EOTS mark. Make sure you have room in your inventory."); continue; } pReward = objmgr.CreateItem(EOTS_MARK_ID, (*itr)); pReward->SetUInt32Value(ITEM_FIELD_STACK_COUNT, item_count); pReward->m_isDirty = true; if( !(*itr)->GetItemInterface()->SafeAddItem(pReward, res.ContainerSlot, res.Slot) ) { if( !(*itr)->GetItemInterface()->AddItemToFreeSlot(pReward) ) { pReward->Destructor(); pReward = NULL; } } (*itr)->GetSession()->SendItemPushResult(pReward,true,false,true,false,res.ContainerSlot,res.Slot, item_count); } else { pReward->m_isDirty = true; pReward->ModUnsigned32Value(ITEM_FIELD_STACK_COUNT, item_count); res.ContainerSlot = (*itr)->GetItemInterface()->GetBagSlotByGuid(pReward->GetGUID()); res.Slot = -1; (*itr)->GetSession()->SendItemPushResult(pReward,true,false,true,true,res.ContainerSlot,res.Slot, item_count); } } } UpdatePvPData(); m_mainLock.Release(); return true; } m_mapMgr->GetStateManager().UpdateWorldState( WORLDSTATE_EOTS_ALLIANCE_VICTORYPOINTS + team, m_points[team] ); return false; }