bool ChatHandler::HandleQuestFinishCommand(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); // reward_slot is for when quest has choice of rewards (0 is the first choice, 1 is the second choice, ...) // reward_slot will default to 0 if none is specified uint32 reward_slot; if(quest_id== 0) { quest_id = GetQuestIDFromLink(args); if(quest_id== 0) return false; if(strstr(args,"|r")) { reward_slot = atol(strstr(args,"|r")+2); } else { reward_slot = 0; } } else if(strchr(args,' ')) { reward_slot = atol(strchr(args,' ')+1); } else { reward_slot = 0; } // currently Quest::reward_choiceitem declaration is // uint32 reward_choiceitem[6]; // so reward_slot must be 0 to 5 if(reward_slot > 5) { reward_slot = 0; } std::string recout = "|cff00ff00"; Quest * qst = QuestStorage.LookupEntry(quest_id); if(qst) { if (plr->HasFinishedQuest(quest_id)) recout += "Player has already completed that quest.\n\n"; else { QuestLogEntry * IsPlrOnQuest = plr->GetQuestLogForEntry(quest_id); if (IsPlrOnQuest) { uint32 giver_id = 0; std::string my_query = ""; my_query = "SELECT id FROM creature_quest_starter WHERE quest = " + MyConvertIntToString(quest_id); QueryResult *creatureResult = WorldDatabase.Query(my_query.c_str()); if(creatureResult) { Field *creatureFields = creatureResult->Fetch(); giver_id = creatureFields[0].GetUInt32(); delete creatureResult; } else { my_query = "SELECT id FROM gameobject_quest_starter WHERE quest = " + MyConvertIntToString(quest_id); QueryResult *objectResult = WorldDatabase.Query(my_query.c_str()); if(objectResult) { Field *objectFields = objectResult->Fetch(); giver_id = objectFields[0].GetUInt32(); delete objectResult; } } if(giver_id == 0) SystemMessage(m_session, "Unable to find quest giver creature or object."); else { // I need some way to get the guid without targeting the creature or looking through all the spawns... Object *quest_giver = 0; for(uint32 guid=1; guid < plr->GetMapMgr()->CreatureStorage.size(); guid++) { Creature *pCreature = plr->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(pCreature) { if(pCreature->GetEntry() == giver_id) //found creature { quest_giver = (Object*)pCreature; guid = plr->GetMapMgr()->CreatureStorage.size(); } } } if(quest_giver) { GreenSystemMessage(m_session, "Found a quest_giver creature."); sQuestMgr.OnActivateQuestGiver(quest_giver, plr); sQuestMgr.GiveQuestRewardReputation(plr, qst, quest_giver); } else RedSystemMessage(m_session, "Unable to find quest_giver object."); } IsPlrOnQuest->Finish(); recout += "Player was on that quest, but has now completed it."; } else { recout += "The quest has now been completed for that player."; } sGMLog.writefromsession( m_session, "completed quest %u [%s] for player %s", quest_id, qst->title, plr->GetName() ); sQuestMgr.BuildQuestComplete(plr, qst); plr->AddToFinishedQuests(quest_id); // Quest Rewards : Copied from QuestMgr::OnQuestFinished() // Reputation reward for(int z = 0; z < 6; z++) { if( qst->reward_repfaction[z] ) { int32 amt = 0; uint32 fact = qst->reward_repfaction[z]; if( qst->reward_repvalue[z] ) { amt = qst->reward_repvalue[z]; } if( qst->reward_replimit && (plr->GetStanding(fact) >= (int32)qst->reward_replimit) ) { continue; } amt = float2int32( float( amt ) * sWorld.getRate( RATE_QUESTREPUTATION ) ); plr->ModStanding( fact, amt ); } } // Static Item reward for(uint32 i = 0; i < 4; ++i) { if(qst->reward_item[i]) { ItemPrototype *proto = ItemPrototypeStorage.LookupEntry(qst->reward_item[i]); if(!proto) { sLog.outError("Invalid item prototype in quest reward! ID %d, quest %d", qst->reward_item[i], qst->id); } else { Item *add; SlotResult slotresult; add = plr->GetItemInterface()->FindItemLessMax(qst->reward_item[i], qst->reward_itemcount[i], false); if (!add) { slotresult = plr->GetItemInterface()->FindFreeInventorySlot(proto); if(!slotresult.Result) { plr->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL); } else { Item *itm = objmgr.CreateItem(qst->reward_item[i], plr); if( itm ) { itm->SetStackCount( uint32(qst->reward_itemcount[i])); if( !plr->GetItemInterface()->SafeAddItem(itm,slotresult.ContainerSlot, slotresult.Slot) ) { itm->DeleteMe(); } } } } else { add->SetStackCount( add->GetStackCount() + qst->reward_itemcount[i]); add->m_isDirty = true; } } } } // Choice Rewards -- Defaulting to choice 0 for ".quest complete" command if(qst->reward_choiceitem[reward_slot]) { ItemPrototype *proto = ItemPrototypeStorage.LookupEntry(qst->reward_choiceitem[reward_slot]); if(!proto) { sLog.outError("Invalid item prototype in quest reward! ID %d, quest %d", qst->reward_choiceitem[reward_slot], qst->id); } else { Item *add; SlotResult slotresult; add = plr->GetItemInterface()->FindItemLessMax(qst->reward_choiceitem[reward_slot], qst->reward_choiceitemcount[reward_slot], false); if (!add) { slotresult = plr->GetItemInterface()->FindFreeInventorySlot(proto); if(!slotresult.Result) { plr->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL); } else { Item *itm = objmgr.CreateItem(qst->reward_choiceitem[reward_slot], plr); if( itm ) { itm->SetStackCount( uint32(qst->reward_choiceitemcount[reward_slot])); if( !plr->GetItemInterface()->SafeAddItem(itm,slotresult.ContainerSlot, slotresult.Slot) ) { itm->DeleteMe(); } } } } else { add->SetStackCount( add->GetStackCount() + qst->reward_choiceitemcount[reward_slot]); add->m_isDirty = true; } } } // if daily then append to finished dailies if ( qst->is_repeatable == arcemu_QUEST_REPEATABLE_DAILY ) plr->PushToFinishedDailies( qst->id ); // Remove quests that are listed to be removed on quest complete. set<uint32>::iterator iter = qst->remove_quest_list.begin(); for(; iter != qst->remove_quest_list.end(); ++iter) { if( !plr->HasFinishedQuest( (*iter ) )) plr->AddToFinishedQuests( (*iter ) ); } #ifdef ENABLE_ACHIEVEMENTS plr->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST_COUNT, 1, 0, 0); if( qst->reward_money > 0 ) { // Money reward // Check they don't have more than the max gold if( sWorld.GoldCapEnabled && (plr->GetGold() + qst->reward_money) <= sWorld.GoldLimit ) { plr->ModGold( qst->reward_money ); } plr->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_QUEST_REWARD_GOLD, qst->reward_money, 0, 0); } plr->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUESTS_IN_ZONE, qst->zone_id, 0, 0); plr->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST, qst->id, 0, 0); #endif } } 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 ChatHandler::HandleItemCommand(const char* args, WorldSession *m_session) { char* pitem = strtok((char*)args, " "); if (!pitem) return false; uint64 guid = m_session->GetPlayer()->GetSelection(); if(guid == 0) { SystemMessage(m_session, "No selection."); return true; } Creature * pCreature = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!pCreature) { SystemMessage(m_session, "You should select a creature."); return true; } uint32 item = atoi(pitem); int amount = -1; char* pamount = strtok(NULL, " "); if (pamount) amount = atoi(pamount); if (amount == -1) { SystemMessage(m_session, "You need to specify an amount."); return true; } uint32 costid = 0; char * pcostid = strtok(NULL, " "); if ( pcostid ) costid = atoi( pcostid ); ItemExtendedCostEntry * ec = ( costid > 0 ) ? dbcItemExtendedCost.LookupEntryForced( costid ) : NULL; if ( costid > 0 && dbcItemExtendedCost.LookupEntryForced( costid ) == NULL ) { SystemMessage( m_session, "You've entered invalid extended cost id." ); return true; } ItemPrototype* tmpItem = ItemPrototypeStorage.LookupEntry(item); std::stringstream sstext; if(tmpItem) { std::stringstream ss; ss << "INSERT INTO vendors VALUES ('" << pCreature->GetUInt32Value(OBJECT_FIELD_ENTRY) << "', '" << item << "', '" << amount << "', 0, 0, " << costid << " )" << '\0'; WorldDatabase.Execute( ss.str().c_str() ); pCreature->AddVendorItem( item, amount, ec ); sstext << "Item '" << item << "' '" << tmpItem->Name1 << "' Added to list"; if ( costid > 0 ) sstext << "with extended cost " << costid; sstext << '\0'; } else { sstext << "Item '" << item << "' Not Found in Database." << '\0'; } sGMLog.writefromsession(m_session, "added item %u to vendor %u", item, pCreature->GetEntry()); SystemMessage(m_session, sstext.str().c_str()); return true; }
void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data ) { if (!_player->IsInWorld()) return; uint64 guid,item; uint32 bid,buyout,etime; // etime is in minutes recv_data >> guid >> item; recv_data >> bid >> buyout >> etime; Creature * pCreature = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if( !pCreature || !pCreature->auctionHouse ) return; // NPC doesnt exist or isnt an auctioneer // Get item Item * pItem = _player->GetItemInterface()->GetItemByGUID(item); if( !pItem || pItem->IsSoulbound() || pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_CONJURED ) ) { WorldPacket data(SMSG_AUCTION_COMMAND_RESULT, 8); data << uint32(0); data << uint32(AUCTION_CREATE); data << uint32(AUCTION_ERROR_ITEM); SendPacket(&data); return; }; AuctionHouse * ah = pCreature->auctionHouse; uint32 item_worth = pItem->GetProto()->SellPrice * pItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT); uint32 item_deposit = (uint32)(item_worth * ah->deposit_percent) * (uint32)(etime / 240.0f); // deposit is per 4 hours if (_player->GetUInt32Value(PLAYER_FIELD_COINAGE) < item_deposit) // player cannot afford deposit { WorldPacket data(SMSG_AUCTION_COMMAND_RESULT, 8); data << uint32(0); data << uint32(AUCTION_CREATE); data << uint32(AUCTION_ERROR_MONEY); SendPacket(&data); return; } pItem = _player->GetItemInterface()->SafeRemoveAndRetreiveItemByGuid(item, false); if (!pItem){ WorldPacket data(SMSG_AUCTION_COMMAND_RESULT, 8); data << uint32(0); data << uint32(AUCTION_CREATE); data << uint32(AUCTION_ERROR_ITEM); SendPacket(&data); return; }; if( pItem->IsInWorld() ) { pItem->RemoveFromWorld(); } pItem->SetOwner(NULL); pItem->m_isDirty = true; pItem->SaveToDB(INVENTORY_SLOT_NOT_SET, 0, true, NULL); // Create auction Auction * auct = new Auction; auct->BuyoutPrice = buyout; auct->ExpiryTime = (uint32)UNIXTIME + (etime * 60); auct->HighestBid = bid; auct->HighestBidder = 0; // hm auct->Id = sAuctionMgr.GenerateAuctionId(); auct->Owner = _player->GetLowGUID(); auct->pItem = pItem; auct->Deleted = false; auct->DeletedReason = 0; auct->DepositAmount = item_deposit; // remove deposit _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)item_deposit); // Add and save auction to DB ah->AddAuction(auct); auct->SaveToDB(ah->GetID()); // Send result packet WorldPacket data(SMSG_AUCTION_COMMAND_RESULT, 8); data << auct->Id; data << uint32(AUCTION_CREATE); data << uint32(AUCTION_ERROR_NONE); SendPacket(&data); }
void Spell::FillTargetMap(uint32 i) { //Spell::prepare() has already a m_caster->IsInWorld() check so if now the caster is no more in world something bad happened. ARCEMU_ASSERT(m_caster->IsInWorld()); uint32 TargetType = 0; TargetType |= GetTargetType(m_spellInfo->EffectImplicitTargetA[i], i); //never get info from B if it is 0 :P if(m_spellInfo->EffectImplicitTargetB[i] != 0) TargetType |= GetTargetType(m_spellInfo->EffectImplicitTargetB[i], i); if(TargetType & SPELL_TARGET_NOT_IMPLEMENTED) return; if(TargetType & SPELL_TARGET_NO_OBJECT) //summon spells that appear infront of caster { HandleTargetNoObject(); return; } //always add this guy :P if(!(TargetType & (SPELL_TARGET_AREA | SPELL_TARGET_AREA_SELF | SPELL_TARGET_AREA_CURTARGET | SPELL_TARGET_AREA_CONE | SPELL_TARGET_OBJECT_SELF | SPELL_TARGET_OBJECT_PETOWNER))) { Object* target = m_caster->GetMapMgr()->_GetObject(m_targets.m_unitTarget); AddTarget(i, TargetType, target); } if(TargetType & SPELL_TARGET_OBJECT_SELF) AddTarget(i, TargetType, m_caster); if(TargetType & (SPELL_TARGET_AREA | SPELL_TARGET_AREA_SELF)) //targetted aoe AddAOETargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets); //TODO: arcemu, doesn't support summon slots? /*if (TargetType & SPELL_TARGET_OBJECT_CURTOTEMS && u_caster != NULL) for (uint32 i=1; i<5; ++i) //totem slots are 1, 2, 3, 4 AddTarget(i, TargetType, u_caster->m_summonslot[i]);*/ if(TargetType & SPELL_TARGET_OBJECT_CURPET && p_caster != NULL) AddTarget(i, TargetType, p_caster->GetSummon()); if(TargetType & SPELL_TARGET_OBJECT_PETOWNER) { uint64 guid = m_targets.m_unitTarget; if(GET_TYPE_FROM_GUID(guid) == HIGHGUID_TYPE_PET) { Pet* p = m_caster->GetMapMgr()->GetPet(GET_LOWGUID_PART(guid)); if(p != NULL) AddTarget(i, TargetType, p->GetPetOwner()); } } //targets party, not raid if((TargetType & SPELL_TARGET_AREA_PARTY) && !(TargetType & SPELL_TARGET_AREA_RAID)) { if(p_caster == NULL && !m_caster->IsPet() && (!m_caster->IsCreature() || !m_caster->IsTotem())) AddAOETargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets); //npcs else AddPartyTargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets); //players/pets/totems } if(TargetType & SPELL_TARGET_AREA_RAID) { if(p_caster == NULL && !m_caster->IsPet() && (!m_caster->IsCreature() || !m_caster->IsTotem())) AddAOETargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets); //npcs else AddRaidTargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets, (TargetType & SPELL_TARGET_AREA_PARTY) ? true : false); //players/pets/totems } if(TargetType & SPELL_TARGET_AREA_CHAIN) AddChainTargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets); //target cone if(TargetType & SPELL_TARGET_AREA_CONE) AddConeTargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets); if(TargetType & SPELL_TARGET_OBJECT_SCRIPTED) AddScriptedOrSpellFocusTargets(i, TargetType, GetRadius(i), m_spellInfo->MaxTargets); }
bool ChatHandler::HandleGenerateWaypoints(const char* args, WorldSession * m_session) { Creature* cr = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(m_session->GetPlayer()->GetSelection())); if(!cr) { SystemMessage(m_session, "You should select a creature."); return true; } if( cr->m_spawn == NULL ) { SystemMessage(m_session, "You cannot add waypoints to a creature that is not saved."); return true; } if(cr->GetAIInterface() == NULL) { SystemMessage(m_session, "Creature was not initialized correctly."); return true; } if(cr->GetAIInterface()->GetWayPointsCount())//ALREADY HAVE WAYPOINTS { SystemMessage(m_session, "The creature already has waypoints"); return false; } if(m_session->GetPlayer()->waypointunit != NULL) { SystemMessage(m_session, "You are already showing waypoints, hide them first."); return true; } if(!cr->GetSQL_id()) { SystemMessage(m_session, "This creature did not get a valid spawn_id."); return true; } uint32 r; uint32 n; if(sscanf(args, "%u %u", &r, &n) != 2) { SystemMessage(m_session, "Randomly generate wps params: range count"); return true; } for(uint32 i = 0; i < n; i++) { float ang = rand()/100.0f; float ran = (RandomUInt(r*10))/10.0f; while(ran < 1) { ran = (RandomUInt(r*10))/10.0f; } float x = cr->GetPositionX()+ran*sin(ang); float y = cr->GetPositionY()+ran*cos(ang); float z = cr->GetCHeightForPosition(true, x, y, cr->GetPositionZ()); WayPoint* wp = new WayPoint; wp->id = (uint32)cr->GetAIInterface()->GetWayPointsCount()+1; wp->x = x; wp->y = y; wp->z = z; wp->orientation = 0.0f; wp->waittime = 5000; wp->flags = 0; wp->forwardInfo = NULL; wp->backwardInfo = NULL; cr->GetAIInterface()->addWayPoint(wp); } cr->GetAIInterface()->setMoveType(1); m_session->GetPlayer()->waypointunit = cr->GetAIInterface(); cr->GetAIInterface()->showWayPoints(m_session->GetPlayer(),cr->GetAIInterface()->WayPointsShowingBackwards()); return true; }
////////////////////////////////////////////////////////////// /// This function handles CMSG_GOSSIP_HELLO: ////////////////////////////////////////////////////////////// void WorldSession::HandleGossipHelloOpcode( WorldPacket & recv_data ) { if(!_player->IsInWorld()) return; uint64 guid; list<QuestRelation *>::iterator it; std::set<uint32> ql; recv_data >> guid; Creature *qst_giver = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!qst_giver) return; //stop when talked to for 3 min if(qst_giver->GetAIInterface()) qst_giver->GetAIInterface()->StopMovement(180000); // unstealth meh if( _player->IsStealth() ) _player->RemoveAllAuraType( SPELL_AURA_MOD_STEALTH ); // reputation _player->Reputation_OnTalk(qst_giver->m_factionDBC); DEBUG_LOG( "WORLD: Received CMSG_GOSSIP_HELLO from %u",GUID_LOPART(guid) ); GossipScript * Script = qst_giver->GetCreatureName() ? qst_giver->GetCreatureName()->gossip_script : NULL; if(!Script) return; if (qst_giver->isQuestGiver() && qst_giver->HasQuests()) { WorldPacket data; data.SetOpcode(SMSG_GOSSIP_MESSAGE); Script->GossipHello(qst_giver, _player, false); if(!_player->CurrentGossipMenu) return; _player->CurrentGossipMenu->BuildPacket(data); uint32 count=0;//sQuestMgr.ActiveQuestsCount(qst_giver, GetPlayer()); size_t pos=data.wpos(); data << uint32(count); for (it = qst_giver->QuestsBegin(); it != qst_giver->QuestsEnd(); ++it) { uint32 status = sQuestMgr.CalcQuestStatus(qst_giver, GetPlayer(), *it); if (status >= QMGR_QUEST_CHAT) { if (!ql.count((*it)->qst->id) ) { ql.insert((*it)->qst->id); count++; data << (*it)->qst->id; /*data << status;//sQuestMgr.CalcQuestStatus(qst_giver, GetPlayer(), *it); data << uint32(0);*/ switch(status) { case QMGR_QUEST_NOT_FINISHED: data << uint32(4) << uint32(0); break; case QMGR_QUEST_FINISHED: data << uint32(4) << uint32(1); break; case QMGR_QUEST_CHAT: data << QMGR_QUEST_AVAILABLE << uint32(0); break; default: data << status << uint32(0); break; } LocalizedQuest * lq = (language>0) ? sLocalizationMgr.GetLocalizedQuest((*it)->qst->id,language):NULL; if(lq) data << lq->Title; else data << (*it)->qst->title; } } } data.wpos(pos); data << count; SendPacket(&data); DEBUG_LOG( "WORLD: Sent SMSG_GOSSIP_MESSAGE" ); } else { Script->GossipHello(qst_giver, _player, true); } }
// Charter part void WorldSession::HandleCharterBuy(WorldPacket & recv_data) { uint8 error; uint64 creature_guid; uint32 crap; uint64 crap2; string name, unkstr; uint32 Data[7]; uint16 crap10; uint32 crap11; uint32 crap12, PetitionSignerCount; string crap13; uint32 arena_index; recv_data >> creature_guid; recv_data >> crap >> crap2; recv_data >> name >> unkstr; recv_data >> Data[0] >> Data[1] >> Data[2] >> Data[3] >> Data[4] >> Data[5] >> Data[6]; recv_data >> crap10; recv_data >> crap11 >> crap12 >> PetitionSignerCount; for(uint32 s = 0; s < 10; ++s) recv_data >> crap13; recv_data >> arena_index; Creature* crt = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(creature_guid)); if(!crt) { Disconnect(); return; } if( arena_index >= NUM_CHARTER_TYPES ) return; //All arena organizers should be allowed to create arena charter's if( !crt->ArenaOrganizersFlags() ) { 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; } if(!sWorld.VerifyName(name.c_str(), name.length())) { SendNotification("That name is invalid or contains invalid characters."); 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]) { sChatHandler.SystemMessage(this,"You don't have enough money!"); 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(NULLITEM, NULLITEM, INV_ERR_INVENTORY_FULL); return; } error = _player->GetItemInterface()->CanReceiveItem(ip,1, NULL); if(error) { _player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM,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->Bind(ITEM_BIND_ON_PICKUP); i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 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->DeleteMe(); i = NULL; return; } c->SaveToDB(); SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1); _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) { 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; } if(!sWorld.VerifyName(name.c_str(), name.length())) { SendNotification("That name is invalid or contains invalid characters."); 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(NULLITEM, NULLITEM, INV_ERR_INVENTORY_FULL); return; } error = _player->GetItemInterface()->CanReceiveItem(ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER),1, NULL); if(error) { _player->GetItemInterface()->BuildInventoryChangeError(NULLITEM, NULLITEM,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->Bind(ITEM_BIND_ON_PICKUP); i->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 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->DeleteMe(); i = NULL; 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 _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -1000); _player->SaveToDB(false); } } }
bool ChatHandler::HandleQuestFinishCommand(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)) recout += "Player has already completed that quest.\n\n"; else { QuestLogEntry * IsPlrOnQuest = plr->GetQuestLogForEntry(quest_id); if (IsPlrOnQuest) { uint32 giver_id = 0; std::string my_query = ""; my_query = "SELECT id FROM creature_quest_starter WHERE quest = " + string(args); QueryResult *creatureResult = WorldDatabase.Query(my_query.c_str()); if(creatureResult) { Field *creatureFields = creatureResult->Fetch(); giver_id = creatureFields[0].GetUInt32(); delete creatureResult; } else { my_query = "SELECT id FROM gameobject_quest_starter WHERE quest = " + string(args); QueryResult *objectResult = WorldDatabase.Query(my_query.c_str()); if(objectResult) { Field *objectFields = objectResult->Fetch(); giver_id = objectFields[0].GetUInt32(); delete objectResult; } } if(giver_id == 0) SystemMessage(m_session, "Unable to find quest giver creature or object."); else { // I need some way to get the guid without targeting the creature or looking through all the spawns... Object *quest_giver; for(uint32 guid=1; guid < plr->GetMapMgr()->m_CreatureArraySize; guid++) { Creature *pCreature = plr->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(pCreature) { if(pCreature->GetEntry() == giver_id) //found creature { quest_giver = (Object*)pCreature; guid = plr->GetMapMgr()->m_CreatureArraySize; } } } if(quest_giver) { GreenSystemMessage(m_session, "Found a quest_giver creature."); //WorldPacket data; //sQuestMgr.BuildOfferReward(&data, qst, quest_giver, 1); //m_session->SendPacket(&data); sQuestMgr.GiveQuestRewardReputation(plr, qst, quest_giver); } else RedSystemMessage(m_session, "Unable to find quest_giver object."); } sQuestMgr.GenerateQuestXP(plr, qst); sQuestMgr.BuildQuestComplete(plr, qst); IsPlrOnQuest->Finish(); recout += "Player was on that quest, but has now completed it."; } else recout += "The quest has now been completed for that player."; plr->AddToFinishedQuests(quest_id); } } 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 ChatHandler::HandleQuestListCommand(const char * args, WorldSession * m_session) { uint32 quest_giver = 0; if(*args) quest_giver = atol(args); else { uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { SystemMessage(m_session, "You must target an npc or specify an id."); return true; } Creature *unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(unit) { if (!unit->isQuestGiver()) { SystemMessage(m_session, "Unit is not a valid quest giver."); return true; } if (!unit->HasQuests()) { SystemMessage(m_session, "NPC does not have any quests."); return true; } quest_giver = unit->GetEntry(); } } string recout = "|cff00ff00Quest matches: id: title\n\n"; SendMultilineMessage(m_session, recout.c_str()); uint32 count = 0; uint32 quest_id = 0; Quest * qst; Field *fields; if(quest_giver == 0) { Player *plr = getSelectedChar(m_session, true); if(!plr) { plr = m_session->GetPlayer(); SystemMessage(m_session, "Auto-targeting self."); } if(plr) { if(plr->HasQuests()) { QueryResult *playerResult = CharacterDatabase.Query("SELECT quest_id FROM questlog WHERE player_guid=%u", plr->GetLowGUID()); if(playerResult) { do { fields = playerResult->Fetch(); quest_id = fields[0].GetUInt32(); qst = QuestStorage.LookupEntry(quest_id); string qid = MyConvertIntToString(quest_id); const char * qname = qst->title; recout = "|cff00ccff"; recout += qid.c_str(); recout += ": "; recout += qname; recout += "\n"; SendMultilineMessage(m_session, recout.c_str()); count++; if(count == 25) { RedSystemMessage(m_session, "More than 25 results returned. aborting."); break; } } while(playerResult->NextRow()); delete playerResult; } } } } else { QueryResult *creatureResult = WorldDatabase.Query("SELECT quest FROM creature_quest_starter WHERE id = %u", quest_giver); if(!creatureResult) { recout = "|cff00ccffNo quests found for the specified NPC id.\n\n"; SendMultilineMessage(m_session, recout.c_str()); return true; } do { Field *fields = creatureResult->Fetch(); uint32 quest_id = fields[0].GetUInt32(); qst = QuestStorage.LookupEntry(quest_id); if(qst==NULL) continue; string qid = MyConvertIntToString(quest_id); const char * qname = qst->title; recout = "|cff00ccff"; recout += qid.c_str(); recout += ": "; recout += qname; recout += "\n"; SendMultilineMessage(m_session, recout.c_str()); count++; if(count == 25) { RedSystemMessage(m_session, "More than 25 results returned. aborting."); break; } }while (creatureResult->NextRow()); delete creatureResult; } if (count == 0) { recout = "|cff00ccffNo matches found.\n\n"; SendMultilineMessage(m_session, recout.c_str()); } return true; }
void WorldSession::HandleAuctionSellItem(WorldPacket& recv_data) { CHECK_INWORLD_RETURN uint64 auctioneer, bid, buyout; uint32 itemsCount, etime; recv_data >> auctioneer; recv_data >> itemsCount; uint64 itemGUIDs[MAX_AUCTION_ITEMS]; // 160 slot = 4x 36 slot bag + backpack 16 slot uint32 count[MAX_AUCTION_ITEMS]; for (uint32 i = 0; i < itemsCount; ++i) { recv_data >> itemGUIDs[i]; recv_data >> count[i]; if (!itemGUIDs[i] || !count[i] || count[i] > 1000) return; } recv_data >> bid; recv_data >> buyout; recv_data >> etime; if (!bid || !etime) return; Creature* pCreature = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(auctioneer)); if (!pCreature || !pCreature->auctionHouse) return; // NPC doesn't exist or isn't an auctioneer AuctionHouse* ah = pCreature->auctionHouse; etime *= MINUTE; switch (etime) { case 1 * MIN_AUCTION_TIME: case 2 * MIN_AUCTION_TIME: case 4 * MIN_AUCTION_TIME: break; default: return; } Item* items[MAX_AUCTION_ITEMS]; uint32 finalCount = 0; for (uint32 i = 0; i < itemsCount; ++i) { Item* item = _player->GetItemInterface()->GetItemByGUID(itemGUIDs[i]); if (!item) { _player->SendAuctionCommandResult(NULL, AUCTION_CREATE, ERR_AUCTION_ITEM_NOT_FOUND); return; } items[i] = item; finalCount += count[i]; } if (!finalCount) { _player->SendAuctionCommandResult(NULL, AUCTION_CREATE, ERR_AUCTION_DATABASE_ERROR); return; } for (uint32 i = 0; i < itemsCount; ++i) { Item* item = items[i]; if (item->GetStackCount() < finalCount) { _player->SendAuctionCommandResult(NULL, AUCTION_CREATE, ERR_AUCTION_DATABASE_ERROR); return; } } for (uint32 i = 0; i < itemsCount; ++i) { Item* item = items[i]; uint32 auctionTime = uint32(etime); AuctionHouse* ah = pCreature->auctionHouse; uint32 item_worth = item->GetProto()->SellPrice * item->GetStackCount(); uint32 item_deposit = (uint32)(item_worth * ah->deposit_percent) * (uint32)(etime / 240.0f); // deposit is per 4 hours if (!_player->HasGold((uint64)item_deposit)) { _player->SendAuctionCommandResult(NULL, AUCTION_CREATE, ERR_AUCTION_NOT_ENOUGHT_MONEY); return; } _player->TakeGold(-int32(item_deposit)); item = _player->GetItemInterface()->SafeRemoveAndRetreiveItemByGuid(itemGUIDs[i], false); if (!item) { _player->SendAuctionCommandResult(NULL, AUCTION_CREATE, ERR_AUCTION_ITEM_NOT_FOUND); return; }; if (item->IsInWorld()) { item->RemoveFromWorld(); } item->SetOwner(NULL); item->m_isDirty = true; item->SaveToDB(INVENTORY_SLOT_NOT_SET, 0, true, NULL); // Create auction Auction* auct = new Auction; auct->BuyoutPrice = buyout; auct->ExpiryTime = (uint32)UNIXTIME + (etime * 60); auct->StartingPrice = bid; auct->HighestBid = 0; auct->HighestBidder = 0; // hm auct->Id = sAuctionMgr.GenerateAuctionId(); auct->Owner = _player->GetLowGUID(); auct->pItem = item; auct->Deleted = false; auct->DeletedReason = 0; auct->DepositAmount = item_deposit; // Add and save auction to DB ah->AddAuction(auct); auct->SaveToDB(ah->GetID()); // Send result packet _player->SendAuctionCommandResult(NULL, AUCTION_CREATE, ERR_AUCTION_OK); } ah->SendOwnerListPacket(_player, &recv_data); }
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession* m_session) { uint64 guid = m_session->GetPlayer()->GetSelection(); if(guid == 0) { SystemMessage(m_session, "No selection."); return true; } Creature* unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!unit) { SystemMessage(m_session, "You should select a creature."); return true; } if(unit->IsPet()) { SystemMessage(m_session, "You can't delete a pet."); return true; } sGMLog.writefromsession(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f", unit->GetSQL_id(), unit->GetCreatureInfo()->Name, unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()); unit->GetAIInterface()->hideWayPoints(m_session->GetPlayer()); unit->DeleteFromDB(); if(unit->IsSummon()) { unit->Delete(); } else { if(unit->m_spawn) { uint32 cellx = uint32(((_maxX - unit->m_spawn->x) / _cellSize)); uint32 celly = uint32(((_maxY - unit->m_spawn->y) / _cellSize)); if(cellx <= _sizeX && celly <= _sizeY) { CellSpawns* sp = unit->GetMapMgr()->GetBaseMap()->GetSpawnsList(cellx, celly); if(sp != NULL) { for(CreatureSpawnList::iterator itr = sp->CreatureSpawns.begin(); itr != sp->CreatureSpawns.end(); ++itr) if((*itr) == unit->m_spawn) { sp->CreatureSpawns.erase(itr); break; } } delete unit->m_spawn; unit->m_spawn = NULL; } } unit->RemoveFromWorld(false, true); } BlueSystemMessage(m_session, "Creature deleted"); return true; }
void WorldSession::HandleAuctionPlaceBid(WorldPacket& recv_data) { CHECK_INWORLD_RETURN uint64 guid; recv_data >> guid; uint32 auction_id, price; recv_data >> auction_id >> price; Creature* pCreature = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if (!pCreature || !pCreature->auctionHouse) return; // Find Item AuctionHouse* ah = pCreature->auctionHouse; Auction* auct = ah->GetAuction(auction_id); if (auct == 0 || !auct->Owner || !_player) { SendAuctionPlaceBidResultPacket(0, ERR_AUCTION_DATABASE_ERROR); return; } if (auct->Owner == _player->GetGUID()) { SendAuctionPlaceBidResultPacket(0, ERR_AUCTION_BID_OWN); return; } if (auct->HighestBid > price && price != auct->BuyoutPrice) { //HACK: Don't know the correct error code... SendAuctionPlaceBidResultPacket(0, ERR_AUCTION_DATABASE_ERROR); return; } if (!_player->HasGold(price)) { SendAuctionPlaceBidResultPacket(0, ERR_AUCTION_NOT_ENOUGHT_MONEY); return; } _player->ModGold(-(int32)price); if (auct->HighestBidder != 0) { // Return the money to the last highest bidder. char subject[100]; snprintf(subject, 100, "%u:0:0", (int)auct->pItem->GetEntry()); sMailSystem.SendAutomatedMessage(AUCTION, ah->GetID(), auct->HighestBidder, subject, "", auct->HighestBid, 0, 0, MAIL_STATIONERY_AUCTION); // Do not send out bid notification, when current highest bidder and new bidder are the same player.. if (auct->HighestBidder != (uint32)_player->GetLowGUID()) ah->SendAuctionOutBidNotificationPacket(auct, _player->GetGUID(), price); } if (auct->BuyoutPrice == price) { auct->HighestBidder = _player->GetLowGUID(); auct->HighestBid = price; // we used buyout on the item. ah->QueueDeletion(auct, AUCTION_REMOVE_WON); SendAuctionPlaceBidResultPacket(auct->Id, ERR_AUCTION_OK); ah->SendAuctionBuyOutNotificationPacket(auct); } else { // update most recent bid auct->HighestBidder = _player->GetLowGUID(); auct->HighestBid = price; auct->UpdateInDB(); SendAuctionPlaceBidResultPacket(auct->Id, ERR_AUCTION_OK); } ah->SendAuctionList(_player, &recv_data); }
bool ChatHandler::HandleGenerateWaypoints(const char* args, WorldSession * m_session) { Creature * cr = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(m_session->GetPlayer()->GetSelection())); if(!cr) { SystemMessage(m_session, "You should select a creature."); return true; } if(cr->GetAIInterface()->GetWayPointsCount())//ALREADY HAVE WAYPOINTS { SystemMessage(m_session, "The creature already has waypoints"); return false; } if(m_session->GetPlayer()->waypointunit != NULL) { SystemMessage(m_session, "You are already showing waypoints, hide them first."); return true; } if(!cr->GetSQL_id()) return false; char* pR = strtok((char*)args, " "); if(!pR) { SystemMessage(m_session, "Randomly generate wps params: range count"); return true; } int r = atoi(pR); char *pC=strtok(NULL, " "); if(!pC) { SystemMessage(m_session, "Randomly generate wps params: range count"); return true; } int n = atol(pC); for(int i=0;i<n;i++) { float ang = rand()/100.0f; float ran = (rand()%(r*10))/10.0f; while(ran<1) { ran = (rand()%(r*10))/10.0f; } float x = cr->GetPositionX()+ran*sin(ang); float y = cr->GetPositionY()+ran*cos(ang); float z = cr->GetMapMgr()->GetBaseMap()->GetLandHeight(x,y); WayPoint* wp = new WayPoint; wp->id = (uint32)cr->GetAIInterface()->GetWayPointsCount()+1; wp->x = x; wp->y = y; wp->z = z; wp->waittime = 5000; wp->flags = 0; wp->forwardemoteoneshot = 0; wp->forwardemoteid = 0; wp->backwardemoteoneshot = 0; wp->backwardemoteid = 0; wp->forwardskinid = 0; wp->backwardskinid = 0; cr->GetAIInterface()->addWayPoint(wp); } if(cr->m_spawn && cr->m_spawn->movetype != 1) /* move random */ { cr->m_spawn->movetype = 1; cr->GetAIInterface()->m_moveType = 1; WorldDatabase.Execute("UPDATE creature_spawns SET movetype = 1 WHERE id = %u", cr->GetSQL_id()); } m_session->GetPlayer()->waypointunit = cr->GetAIInterface(); cr->GetAIInterface()->showWayPoints(m_session->GetPlayer(),cr->GetAIInterface()->m_WayPointsShowBackwards); return true; }
/*Loot type MUST be 1-corpse, go 2-skinning/herbalism/minning 3-Fishing */ void Player::SendLoot(uint64 guid, uint8 loot_type, uint32 mapid) { Group* m_Group = m_playerInfo->m_Group; if(!IsInWorld()) return; Loot* pLoot = NULL; uint32 guidtype = GET_TYPE_FROM_GUID(guid); int8 loot_method; if(m_Group != NULL) loot_method = m_Group->GetMethod(); else loot_method = PARTY_LOOT_FFA; if(guidtype == HIGHGUID_TYPE_UNIT) { Creature* pCreature = GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!pCreature)return; pLoot = &pCreature->loot; m_currentLoot = pCreature->GetGUID(); } else if(guidtype == HIGHGUID_TYPE_GAMEOBJECT) { GameObject* pGO = GetMapMgr()->GetGameObject(GET_LOWGUID_PART(guid)); if(!pGO)return; pGO->SetByte(GAMEOBJECT_BYTES_1, 0, 0); pLoot = &pGO->loot; m_currentLoot = pGO->GetGUID(); } else if((guidtype == HIGHGUID_TYPE_PLAYER)) { Player* p = GetMapMgr()->GetPlayer((uint32)guid); if(!p)return; pLoot = &p->loot; m_currentLoot = p->GetGUID(); } else if((guidtype == HIGHGUID_TYPE_CORPSE)) { Corpse* pCorpse = objmgr.GetCorpse((uint32)guid); if(!pCorpse)return; pLoot = &pCorpse->loot; m_currentLoot = pCorpse->GetGUID(); } else if((guidtype == HIGHGUID_TYPE_ITEM)) { Item* pItem = GetItemInterface()->GetItemByGUID(guid); if(!pItem) return; pLoot = pItem->loot; m_currentLoot = pItem->GetGUID(); } if(!pLoot) { // something whack happened.. damn cheaters.. return; } // add to looter set pLoot->looters.insert(GetLowGUID()); WorldPacket data, data2(32); data.SetOpcode(SMSG_LOOT_RESPONSE); m_lootGuid = guid; data << uint64(guid); data << uint8(loot_type); //loot_type; data << uint32(pLoot->gold); data << uint8(0); //loot size reserve std::vector<__LootItem>::iterator iter = pLoot->items.begin(); uint32 count = 0; uint8 slottype = 0; for(uint32 x = 0; iter != pLoot->items.end(); iter++, x++) { if(iter->iItemsCount == 0) continue; LooterSet::iterator itr = iter->has_looted.find(GetLowGUID()); if(iter->has_looted.end() != itr) continue; ItemPrototype* itemProto = iter->item.itemproto; if(!itemProto) continue; // check if it's on ML if so only quest items and ffa loot should be shown based on mob if(loot_method == PARTY_LOOT_MASTER && m_Group && m_Group->GetLooter() != m_playerInfo) // pass on all ffa_loot and the grey / white items if(!iter->ffa_loot && !(itemProto->Quality < m_Group->GetThreshold())) continue; // team check if( itemProto->HasFlag2(ITEM_FLAG2_HORDE_ONLY) && IsTeamAlliance() ) continue; if( itemProto->HasFlag2(ITEM_FLAG2_ALLIANCE_ONLY) && IsTeamHorde() ) continue; //quest items check. type 4/5 //quest items that don't start quests. if((itemProto->Bonding == ITEM_BIND_QUEST) && !(itemProto->QuestId) && !HasQuestForItem(itemProto->ItemId)) continue; if((itemProto->Bonding == ITEM_BIND_QUEST2) && !(itemProto->QuestId) && !HasQuestForItem(itemProto->ItemId)) continue; //quest items that start quests need special check to avoid drops all the time. if((itemProto->Bonding == ITEM_BIND_QUEST) && (itemProto->QuestId) && GetQuestLogForEntry(itemProto->QuestId)) continue; if((itemProto->Bonding == ITEM_BIND_QUEST2) && (itemProto->QuestId) && GetQuestLogForEntry(itemProto->QuestId)) continue; if((itemProto->Bonding == ITEM_BIND_QUEST) && (itemProto->QuestId) && HasFinishedQuest(itemProto->QuestId)) continue; if((itemProto->Bonding == ITEM_BIND_QUEST2) && (itemProto->QuestId) && HasFinishedQuest(itemProto->QuestId)) continue; //check for starting item quests that need questlines. if((itemProto->QuestId && itemProto->Bonding != ITEM_BIND_QUEST && itemProto->Bonding != ITEM_BIND_QUEST2)) { Quest* pQuest = QuestStorage.LookupEntry(itemProto->QuestId); if(pQuest) { uint32 finishedCount = 0; //check if its a questline. for(uint32 i = 0; i < pQuest->count_requiredquests; i++) { if(pQuest->required_quests[i]) { if(!HasFinishedQuest(pQuest->required_quests[i]) || GetQuestLogForEntry(pQuest->required_quests[i])) { } else { finishedCount++; } } } } } slottype = 0; if(m_Group != NULL && loot_type < 2) { switch(loot_method) { case PARTY_LOOT_MASTER: slottype = 2; break; case PARTY_LOOT_GROUP: case PARTY_LOOT_RR: case PARTY_LOOT_NBG: slottype = 1; break; default: slottype = 0; break; } // only quality items are distributed if(itemProto->Quality < m_Group->GetThreshold()) { slottype = 0; } // if all people passed anyone can loot it? :P if(iter->passed) slottype = 0; // All players passed on the loot //if it is ffa loot and not an masterlooter if(iter->ffa_loot) slottype = 0; } data << uint8(x); data << uint32(itemProto->ItemId); data << uint32(iter->iItemsCount); //nr of items of this type data << uint32(iter->item.displayid); if(iter->iRandomSuffix) { data << uint32(Item::GenerateRandomSuffixFactor(itemProto)); data << uint32(-int32(iter->iRandomSuffix->id)); } else if(iter->iRandomProperty) { data << uint32(0); data << uint32(iter->iRandomProperty->ID); } else { data << uint32(0); data << uint32(0); } data << slottype; // "still being rolled for" flag if(slottype == 1) { if(iter->roll == NULL && !iter->passed) { int32 ipid = 0; uint32 factor = 0; if(iter->iRandomProperty) ipid = iter->iRandomProperty->ID; else if(iter->iRandomSuffix) { ipid = -int32(iter->iRandomSuffix->id); factor = Item::GenerateRandomSuffixFactor(iter->item.itemproto); } if(iter->item.itemproto) { iter->roll = new LootRoll(60000, (m_Group != NULL ? m_Group->MemberCount() : 1), guid, x, itemProto->ItemId, factor, uint32(ipid), GetMapMgr()); data2.Initialize(SMSG_LOOT_START_ROLL); data2 << guid; data2 << uint32(mapid); data2 << uint32(x); data2 << uint32(itemProto->ItemId); data2 << uint32(factor); if(iter->iRandomProperty) data2 << uint32(iter->iRandomProperty->ID); else if(iter->iRandomSuffix) data2 << uint32(ipid); else data2 << uint32(0); data2 << uint32(iter->iItemsCount); data2 << uint32(60000); // countdown data2 << uint8(7); // some sort of flags that require research } Group* pGroup = m_playerInfo->m_Group; if(pGroup) { pGroup->Lock(); for(uint32 i = 0; i < pGroup->GetSubGroupCount(); ++i) { for(GroupMembersSet::iterator itr2 = pGroup->GetSubGroup(i)->GetGroupMembersBegin(); itr2 != pGroup->GetSubGroup(i)->GetGroupMembersEnd(); ++itr2) { PlayerInfo* pinfo = *itr2; if(pinfo->m_loggedInPlayer && pinfo->m_loggedInPlayer->GetItemInterface()->CanReceiveItem(itemProto, iter->iItemsCount) == 0) { if(pinfo->m_loggedInPlayer->m_passOnLoot) iter->roll->PlayerRolled(pinfo->m_loggedInPlayer, 3); // passed else pinfo->m_loggedInPlayer->SendPacket(&data2); } } } pGroup->Unlock(); } else { m_session->SendPacket(&data2); } } } count++; } data.wpos(13); data << uint8(count); m_session->SendPacket(&data); SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_LOOTING); }
void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data ) { if(!_player->IsInWorld()) return; uint64 guid; recv_data >> guid; uint32 auction_id, price; recv_data >> auction_id >> price; Creature * pCreature = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!pCreature || !pCreature->auctionHouse || price == 0) return; // Find Item AuctionHouse * ah = pCreature->auctionHouse; Auction * auct = ah->GetAuction(auction_id); if(auct == 0 || !auct->Owner || !_player || auct->Owner == _player->GetGUID()) return; if(auct->HighestBid > price && price != auct->BuyoutPrice) return; if(_player->GetUInt32Value(PLAYER_FIELD_COINAGE) < price) return; _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -((int32)price)); if(auct->HighestBidder != 0) { // Return the money to the last highest bidder. char subject[100]; snprintf(subject, 100, "%u:0:0", (int)auct->pItem->GetEntry()); sMailSystem.SendAutomatedMessage(AUCTION, ah->GetID(), auct->HighestBidder, subject, "", auct->HighestBid, 0, 0, 62); } if(auct->BuyoutPrice == price) { auct->HighestBidder = _player->GetLowGUID(); auct->HighestBid = price; // we used buyout on the item. ah->QueueDeletion(auct, AUCTION_REMOVE_WON); // send response packet WorldPacket data(SMSG_AUCTION_COMMAND_RESULT, 12); data << auct->Id << uint32(AUCTION_CANCEL) << uint32(0) << uint32(0); SendPacket(&data); } else { // update most recent bid auct->HighestBidder = _player->GetLowGUID(); auct->HighestBid = price; auct->UpdateInDB(); // send response packet WorldPacket data(SMSG_AUCTION_COMMAND_RESULT, 12); data << auct->Id << uint32(AUCTION_CANCEL) << uint32(0); SendPacket(&data); } }
bool ChatHandler::HandleQuestAddStartCommand(const char * args, WorldSession * m_session) { if(!*args) return false; uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { SystemMessage(m_session, "You must target an npc."); return false; } Creature *unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!unit) { SystemMessage(m_session, "You must target an npc."); return false; } if (!unit->isQuestGiver()) { SystemMessage(m_session, "Unit is not a valid quest giver."); return false; } uint32 quest_id = atol(args); Quest * qst = QuestStorage.LookupEntry(quest_id); if (qst == NULL) { SystemMessage(m_session, "Invalid quest selected, unable to add quest to the specified NPC."); return false; } std::string quest_giver = MyConvertIntToString(unit->GetEntry()); std::string my_query1 = "SELECT id FROM creature_quest_starter WHERE id = " + quest_giver + " AND quest = " + string(args); QueryResult *selectResult1 = WorldDatabase.Query(my_query1.c_str()); if (selectResult1) { delete selectResult1; SystemMessage(m_session, "Quest was already found for the specified NPC."); } else { std::string my_insert1 = "INSERT INTO creature_quest_starter (id, quest) VALUES (" + quest_giver + "," + string(args) + ")"; QueryResult *insertResult1 = WorldDatabase.Query(my_insert1.c_str()); if (insertResult1) delete insertResult1; } std::string my_query2 = "SELECT id FROM gameobject_quest_starter WHERE id = " + quest_giver + " AND quest = " + string(args); QueryResult *selectResult2 = WorldDatabase.Query(my_query2.c_str()); if (selectResult2) delete selectResult2; else { std::string my_insert2 = "INSERT INTO gameobject_quest_starter (id, quest) VALUES (" + quest_giver + "," + string(args) + ")"; QueryResult *insertResult2 = WorldDatabase.Query(my_insert2.c_str()); if (insertResult2) delete insertResult2; } sQuestMgr.LoadExtraQuestStuff(); QuestRelation *qstrel = new QuestRelation; qstrel->qst = qst; qstrel->type = QUESTGIVER_QUEST_START; uint8 qstrelid = (uint8)unit->GetQuestRelation(quest_id); unit->FindQuest(quest_id, qstrelid); unit->AddQuest(qstrel); unit->_LoadQuests(); const char * qname = qst->title; std::string recout = "|cff00ff00Added Quest to NPC as starter: "; recout += "|cff00ccff"; recout += qname; recout += "\n\n"; SendMultilineMessage(m_session, recout.c_str()); return true; }
void WorldSession::HandleTrainerBuySpellOpcode(WorldPacket& recvPacket) { if(!_player->IsInWorld()) return; uint64 Guid; uint32 TeachingSpellID; recvPacket >> Guid >> TeachingSpellID; Creature *pCreature = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(Guid)); if(pCreature == 0) return; Trainer *pTrainer = pCreature->GetTrainer(); if(pTrainer == 0 || !CanTrainAt(_player, pTrainer)) return; TrainerSpell * pSpell=NULL; for(vector<TrainerSpell>::iterator itr = pTrainer->Spells.begin(); itr != pTrainer->Spells.end(); ++itr) { if( ( itr->pCastRealSpell && itr->pCastRealSpell->Id == TeachingSpellID ) || ( itr->pLearnSpell && itr->pLearnSpell->Id == TeachingSpellID ) ) { pSpell = &(*itr); } } if(pSpell == NULL) return; if(TrainerGetSpellStatus(pSpell) > 0) return; _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)pSpell->Cost); if( pSpell->pCastSpell) { // Cast teaching spell on player pCreature->CastSpell(_player, pSpell->pCastSpell, true); } if( pSpell->pLearnSpell ) { packetSMSG_PLAY_SPELL_VISUAL pck; pck.guid = pCreature->GetGUID(); pck.visualid = 0x5b3; _player->OutPacketToSet( SMSG_PLAY_SPELL_VISUAL, sizeof(packetSMSG_PLAY_SPELL_VISUAL), &pck, true ); pck.guid = _player->GetGUID(); pck.visualid = 0x16a; _player->OutPacketToSet( 0x1F7, sizeof(packetSMSG_PLAY_SPELL_VISUAL), &pck, true ); // add the spell _player->addSpell( pSpell->pLearnSpell->Id ); uint32 i; for( i = 0; i < 3; ++i) { if(pSpell->pLearnSpell->Effect[i] == SPELL_EFFECT_PROFICIENCY || pSpell->pLearnSpell->Effect[i] == SPELL_EFFECT_LEARN_SPELL || pSpell->pLearnSpell->Effect[i] == SPELL_EFFECT_WEAPON) { _player->CastSpell(_player, pSpell->pLearnSpell, true); break; } } for( i = 0; i < 3; ++i) { if( pSpell->pLearnSpell->Effect[i] == SPELL_EFFECT_SKILL ) { uint32 skill = pSpell->pLearnSpell->EffectMiscValue[i]; uint32 val = (pSpell->pLearnSpell->EffectBasePoints[i]+1) * 75; if( val > 350 ) val = 350; if( _player->_GetSkillLineMax(skill) >= val ) return; if( skill == SKILL_RIDING ) _player->_AddSkillLine( skill, val, val ); else { if( _player->_HasSkillLine(skill) ) _player->_ModifySkillMaximum(skill, val); else _player->_AddSkillLine( skill, 1, val); } } } } if(pSpell->DeleteSpell) { // Remove old spell. if( pSpell->pLearnSpell ) _player->removeSpell(pSpell->DeleteSpell, true, true, pSpell->pLearnSpell->Id); else if(pSpell->pCastSpell) _player->removeSpell(pSpell->DeleteSpell, true, true, pSpell->pCastRealSpell->Id); else _player->removeSpell(pSpell->DeleteSpell,true,false,0); } }
bool ChatHandler::HandleQuestDelFinishCommand(const char * args, WorldSession * m_session) { if(!*args) return false; uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { SystemMessage(m_session, "You must target an npc."); return false; } Creature *unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!unit) { SystemMessage(m_session, "You must target an npc."); return false; } if (!unit->isQuestGiver()) { SystemMessage(m_session, "Unit is not a valid quest giver."); return false; } uint32 quest_id = atol(args); Quest * qst = QuestStorage.LookupEntry(quest_id); if (qst == NULL) { SystemMessage(m_session, "Invalid Quest selected."); return false; } std::string quest_giver = MyConvertIntToString(unit->GetEntry()); std::string my_query1 = "SELECT id FROM creature_quest_finisher WHERE id = " + quest_giver + " AND quest = " + string(args); QueryResult *selectResult1 = WorldDatabase.Query(my_query1.c_str()); if (selectResult1) delete selectResult1; else { SystemMessage(m_session, "Quest was NOT found for the specified NPC."); return true; } std::string my_delete1 = "DELETE FROM creature_quest_finisher WHERE id = " + quest_giver + " AND quest = " + string(args); QueryResult *deleteResult1 = WorldDatabase.Query(my_delete1.c_str()); if (deleteResult1) delete deleteResult1; std::string my_query2 = "SELECT id FROM gameobject_quest_finisher WHERE id = " + quest_giver + " AND quest = " + string(args); QueryResult *selectResult2 = WorldDatabase.Query(my_query2.c_str()); if (selectResult2) { delete selectResult2; std::string my_delete2 = "DELETE FROM gameobject_quest_finisher WHERE id = " + quest_giver + " AND quest = " + string(args); QueryResult *deleteResult2 = WorldDatabase.Query(my_delete2.c_str()); if (deleteResult2) delete deleteResult2; } sQuestMgr.LoadExtraQuestStuff(); QuestRelation *qstrel = new QuestRelation; qstrel->qst = qst; qstrel->type = QUESTGIVER_QUEST_END; uint8 qstrelid = (uint8)unit->GetQuestRelation(quest_id); unit->FindQuest(quest_id, qstrelid); unit->DeleteQuest(qstrel); unit->_LoadQuests(); const char * qname = qst->title; std::string recout = "|cff00ff00Deleted Quest from NPC: "; recout += "|cff00ccff"; recout += qname; recout += "\n\n"; SendMultilineMessage(m_session, recout.c_str()); return true; }
// 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::HandleTrainerBuySpellOpcode(WorldPacket& recvPacket) { if(!_player->IsInWorld()) return; //////////////////////////////////////////////////////////////////////////////// // As of 3.1.3 the client sends this when buying a spell // // {CLIENT} Packet: (0x01B2) CMSG_TRAINER_BUY_SPELL PacketSize = 12 TimeStamp = 39035859 // A0 85 00 06 7A 00 30 F1 2D 85 00 00 // // Structure: // uint64 GUID - GUID of the trainer // uint32 spellid - ID of the spell being bought //////////////////////////////////////////////////////////////////////////////// uint64 Guid; uint32 TeachingSpellID; recvPacket >> Guid >> TeachingSpellID; Creature *pCreature = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(Guid)); /////////////////////////////////////////// Checks ////////////////////////////////////// if(pCreature == NULL) return; Trainer *pTrainer = pCreature->GetTrainer(); if(pTrainer == NULL || !CanTrainAt(_player, pTrainer)) return; // Check if the trainer offers that spell TrainerSpell * pSpell = NULL; for(vector<TrainerSpell>::iterator itr = pTrainer->Spells.begin(); itr != pTrainer->Spells.end(); ++itr) { if( ( itr->pCastSpell && itr->pCastSpell->Id == TeachingSpellID ) || ( itr->pLearnSpell && itr->pLearnSpell->Id == TeachingSpellID ) ) { pSpell = &(*itr); } } // If the trainer doesn't offer it, this is probably some packet mangling if(pSpell == NULL){ // Disconnecting the player this->Disconnect(); return; } // We can't learn it if(TrainerGetSpellStatus(pSpell) > 0) return; //////////////////////////////////////////// Teaching //////////////////////////////////// _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)pSpell->Cost); if( pSpell->pCastSpell) { _player->CastSpell( _player, pSpell->pCastSpell->Id, true ); } else { /////////////////////////////////////// Showing the learning spellvisuals////////////// packetSMSG_PLAY_SPELL_VISUAL pck; pck.guid = pCreature->GetGUID(); pck.visualid = 0x5b3; _player->OutPacketToSet( SMSG_PLAY_SPELL_VISUAL, sizeof(packetSMSG_PLAY_SPELL_VISUAL), &pck, true ); pck.guid = _player->GetGUID(); pck.visualid = 0x16a; _player->OutPacketToSet( SMSG_PLAY_SPELL_IMPACT, sizeof(packetSMSG_PLAY_SPELL_VISUAL), &pck, true ); /////////////////////////////////////////////////////////////////////////////////////// // add the spell itself _player->addSpell( pSpell->pLearnSpell->Id ); } if(pSpell->DeleteSpell) { // Remove old spell. if( pSpell->pLearnSpell ) _player->removeSpell(pSpell->DeleteSpell, true, true, pSpell->pLearnSpell->Id); else if(pSpell->pCastSpell) _player->removeSpell(pSpell->DeleteSpell, true, true, pSpell->pCastRealSpell->Id); else _player->removeSpell(pSpell->DeleteSpell,true,false,0); } _player->_UpdateSkillFields(); ///////////////////////////////////////////////////////////////////////////////// // As of 3.1.3 this is sent after buying the spell // // // {SERVER} Packet: (0x01B3) SMSG_TRAINER_BUY_SUCCEEDED PacketSize = 12 TimeStamp = 39035968 // A0 85 00 06 7A 00 30 F1 2D 85 00 00 // // structure: // // uint64 GUID - GUID of the trainer // uint32 spellid - ID of the spell we bought ////////////////////////////////////////////////////////////////////////////////// WorldPacket data( SMSG_TRAINER_BUY_SUCCEEDED, 12 ); data << uint64( Guid ) << uint32( TeachingSpellID ); this->SendPacket( &data ); }
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; }
////////////////////////////////////////////////////////////// /// This function handles CMSG_GOSSIP_SELECT_OPTION: ////////////////////////////////////////////////////////////// void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket & recv_data ) { if(!_player->IsInWorld()) return; //WorldPacket data; uint32 option; uint32 unk24; uint64 guid; int8 extra=0; recv_data >> guid >> unk24 >> option; sLog.outDetail("WORLD: CMSG_GOSSIP_SELECT_OPTION Option %i Guid %.8X", option, guid ); GossipScript * Script= NULL; Object * qst_giver= NULL; uint32 guidtype = GET_TYPE_FROM_GUID(guid); if(guidtype==HIGHGUID_TYPE_UNIT) { Creature *crt = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!crt) return; qst_giver=crt; Script=crt->GetCreatureInfo()?crt->GetCreatureInfo()->gossip_script:NULL; } else if(guidtype==HIGHGUID_TYPE_ITEM) { Item * pitem = _player->GetItemInterface()->GetItemByGUID(guid); if(pitem== NULL) return; qst_giver=pitem; Script=pitem->GetProto()->gossip_script; } else if(guidtype==HIGHGUID_TYPE_GAMEOBJECT) { GameObject *gobj = _player->GetMapMgr()->GetGameObject(GET_LOWGUID_PART(guid)); if(!gobj) return; qst_giver=gobj; Script=gobj->GetInfo()->gossip_script; } if(!Script||!qst_giver) return; uint32 IntId = 1; if(_player->CurrentGossipMenu) { GossipMenuItem item = _player->CurrentGossipMenu->GetItem(option); IntId = item.IntId; extra = item.Extra; } if(extra) { string str; if(recv_data.rpos()!=recv_data.wpos()) recv_data >> str; Script->GossipSelectOption(qst_giver, _player, option, IntId, str.c_str()); } else
bool ChatHandler::HandleWPAddCommand(const char* args, WorldSession *m_session) { uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { SystemMessage(m_session, "No Selection"); return true; } AIInterface* ai = NULL; Creature* pCreature = NULLCREATURE; Player* p = m_session->GetPlayer(); if(p->waypointunit != NULL) { SystemMessage(m_session, "Using Previous Unit."); ai = p->waypointunit; if(!ai) { SystemMessage(m_session, "Invalid Creature, please select another one."); return true; } pCreature = TO_CREATURE(ai->GetUnit()); if(!pCreature) { SystemMessage(m_session, "Invalid Creature, please select another one."); return true; } } else { pCreature = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!pCreature) { SystemMessage(m_session, "You should select a creature."); return true; } if( pCreature->m_spawn == NULL ) { SystemMessage(m_session, "You cannot add waypoints to a creature that is not saved."); return true; } ai = pCreature->GetAIInterface(); } char* pWaitTime = strtok((char*)args, " "); uint32 WaitTime = (pWaitTime)? atoi(pWaitTime) : 10000; char* pFlags = strtok(NULL, " "); uint32 Flags = (pFlags)? atoi(pFlags) : 0 ; char* pForwardEmoteId = strtok(NULL, " "); uint32 ForwardEmoteId = (pForwardEmoteId)? atoi(pForwardEmoteId) : 0; char* pBackwardEmoteId = strtok(NULL, " "); uint32 BackwardEmoteId = (pBackwardEmoteId)? atoi(pBackwardEmoteId) : 0; char* pForwardSkinId = strtok(NULL, " "); uint32 ForwardSkinId = (pForwardSkinId)? atoi(pForwardSkinId) : pCreature->GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); char* pBackwardSkinId = strtok(NULL, " "); uint32 BackwardSkinId = (pBackwardSkinId)? atoi(pBackwardSkinId) : pCreature->GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); char* pForwardEmoteOneShot = strtok(NULL, " "); uint32 ForwardEmoteOneShot = (pForwardEmoteOneShot)? atoi(pForwardEmoteOneShot) : 1; char* pBackwardEmoteOneShot = strtok(NULL, " "); uint32 BackwardEmoteOneShot = (pBackwardEmoteOneShot)? atoi(pBackwardEmoteOneShot) : 1; char* pForwardStandState = strtok(NULL, " "); uint32 ForwardStandState = (pForwardStandState)? atoi(pForwardStandState) : 0; char* pBackwardStandState = strtok(NULL, " "); uint32 BackwardStandState = (pBackwardStandState)? atoi(pBackwardStandState) : 0; char* pForwardSpellToCast = strtok(NULL, " "); uint32 ForwardSpellToCast = (pForwardSpellToCast)? atoi(pForwardSpellToCast) : 0; char* pBackwardSpellToCast = strtok(NULL, " "); uint32 BackwardSpellToCast = (pBackwardSpellToCast)? atoi(pBackwardSpellToCast) : 0; WayPoint* wp = new WayPoint; bool showing = ai->WayPointsShowing(); wp->id = (uint32)ai->GetWayPointsCount()+1; wp->x = p->GetPositionX(); wp->y = p->GetPositionY(); wp->z = p->GetPositionZ(); wp->orientation = p->GetOrientation(); wp->waittime = WaitTime; wp->flags = Flags; wp->forwardInfo = new ConditionalData(((ForwardEmoteOneShot > 0) ? true : false), ForwardEmoteId, ForwardSkinId, (ForwardStandState > 8 ? 0 : ForwardStandState), ForwardSpellToCast, ""); if(wp->forwardInfo->EmoteID == 0 && wp->forwardInfo->SkinID == 0 && wp->forwardInfo->StandState == 0 && wp->forwardInfo->SpellToCast == 0 && wp->forwardInfo->SayText.length() == 0) { delete wp->forwardInfo; wp->forwardInfo = NULL; } wp->backwardInfo = new ConditionalData(((BackwardEmoteOneShot > 0) ? true : false), BackwardEmoteId, BackwardSkinId, (BackwardStandState > 8 ? 0 : BackwardStandState), BackwardSpellToCast, ""); if(wp->backwardInfo->EmoteID == 0 && wp->backwardInfo->SkinID == 0 && wp->backwardInfo->StandState == 0 && wp->backwardInfo->SpellToCast == 0 && wp->backwardInfo->SayText.length() == 0) { delete wp->backwardInfo; wp->backwardInfo = NULL; } if(showing) ai->hideWayPoints(p); ai->addWayPoint(wp); ai->saveWayPoints(); if(showing) ai->showWayPoints(p, ai->WayPointsShowingBackwards()); SystemMessage(m_session, "Waypoint %u added.", wp->id); return true; }
void WorldSession::HandleTrainerBuySpellOpcode(WorldPacket& recvPacket) { CHECK_INWORLD_RETURN; uint64 Guid; uint32 TeachingSpellID; recvPacket >> Guid >> TeachingSpellID; Creature* pCreature = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(Guid)); if(pCreature == NULL) return; Trainer *pTrainer = pCreature->GetTrainer(); if(pTrainer == NULL || !CanTrainAt(_player, pTrainer)) return; TrainerSpell* pSpell = NULL; for(vector<TrainerSpell>::iterator itr = pTrainer->Spells.begin(); itr != pTrainer->Spells.end(); itr++) { if( ( itr->pCastRealSpell && itr->pCastRealSpell->Id == TeachingSpellID ) || ( itr->pLearnSpell && itr->pLearnSpell->Id == TeachingSpellID ) ) { pSpell = &(*itr); } } if(pSpell == NULL) return; if(TrainerGetSpellStatus(pSpell) > 0) return; _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)pSpell->Cost); if( pSpell->pCastSpell) { // Cast teaching spell on player pCreature->CastSpell(_player, pSpell->pCastSpell, true); } if( pSpell->pLearnSpell ) { packetSMSG_PLAY_SPELL_VISUAL pck; pck.guid = pCreature->GetGUID(); pck.visualid = 0x5b3; _player->OutPacketToSet( SMSG_PLAY_SPELL_VISUAL, sizeof(packetSMSG_PLAY_SPELL_VISUAL), &pck, true ); pck.guid = _player->GetGUID(); pck.visualid = 0x16a; _player->OutPacketToSet( SMSG_PLAY_SPELL_IMPACT, sizeof(packetSMSG_PLAY_SPELL_VISUAL), &pck, true ); // add the spell _player->addSpell( pSpell->pLearnSpell->Id ); uint32 i; for( i = 0; i < 3; ++i) { if(pSpell->pLearnSpell->Effect[i] == SPELL_EFFECT_PROFICIENCY || pSpell->pLearnSpell->Effect[i] == SPELL_EFFECT_LEARN_SPELL || pSpell->pLearnSpell->Effect[i] == SPELL_EFFECT_WEAPON) { _player->CastSpell(_player, pSpell->pLearnSpell, true); break; } } for( i = 0; i < 3; ++i) { if( pSpell->pLearnSpell->Effect[i] == SPELL_EFFECT_SKILL ) { uint32 skill = pSpell->pLearnSpell->EffectMiscValue[i]; uint32 val = (pSpell->pLearnSpell->EffectBasePoints[i]+1) * 75; if( val > 350 ) val = 350; if( _player->_GetSkillLineMax(skill) >= val ) return; if( skill == SKILL_RIDING ) _player->_AddSkillLine( skill, val, val ); else { if( _player->_HasSkillLine(skill) ) _player->_ModifySkillMaximum(skill, val); else _player->_AddSkillLine( skill, 1, val); } } } } if(pSpell->DeleteSpell) { // Remove old spell. if( pSpell->pLearnSpell ) _player->removeSpell(pSpell->DeleteSpell, true, true, pSpell->pLearnSpell->Id); else if(pSpell->pCastSpell) _player->removeSpell(pSpell->DeleteSpell, true, true, pSpell->pCastRealSpell->Id); else _player->removeSpell(pSpell->DeleteSpell,true,false,0); } ///////////////////////////////////////////////////////////////////////////////// // As of 3.1.3 this is sent after buying the spell // // // {SERVER} Packet: (0x01B3) SMSG_TRAINER_BUY_SUCCEEDED PacketSize = 12 TimeStamp = 39035968 // A0 85 00 06 7A 00 30 F1 2D 85 00 00 // // structure: // // uint64 GUID - GUID of the trainer // uint32 spellid - ID of the spell we bought ////////////////////////////////////////////////////////////////////////////////// WorldPacket data(SMSG_TRAINER_BUY_SUCCEEDED, 12); data << uint64(Guid) << uint32(TeachingSpellID); this->SendPacket(&data); }
bool ChatHandler::HandleAddAIAgentCommand(const char* args, WorldSession *m_session) { char* agent = strtok((char*)args, " "); if(!agent) return false; char* procEvent = strtok(NULL, " "); if(!procEvent) return false; char* procChance = strtok(NULL, " "); if(!procChance) return false; char* procCount = strtok(NULL, " "); if(!procCount) return false; char* spellId = strtok(NULL, " "); if(!spellId) return false; char* spellType = strtok(NULL, " "); if(!spellType) return false; char* spelltargetType = strtok(NULL, " "); if(!spelltargetType) return false; char* spellCooldown = strtok(NULL, " "); if(!spellCooldown) return false; char* floatMisc1 = strtok(NULL, " "); if(!floatMisc1) return false; char* Misc2 = strtok(NULL, " "); if(!Misc2) return false; Creature* target = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(m_session->GetPlayer()->GetSelection())); if(!target) { RedSystemMessage(m_session, "You have to select a Creature!"); return false; } std::stringstream qry; qry << "INSERT INTO ai_agents SET entry = '" << target->GetUInt32Value(OBJECT_FIELD_ENTRY) << "', type = '" << atoi(agent) << "', event = '" << atoi(procEvent)<< "', chance = '" << atoi(procChance)<< "', maxcount = '" << atoi(procCount)<< "', spell = '" << atoi(spellId)<< "', spelltype = '" << atoi(spellType)<< "', targettype_overwrite = '" << atoi(spelltargetType)<< "', cooldown_overwrite = '" << atoi(spellCooldown)<< "', floatMisc1 = '" << atof(floatMisc1)<< "', Misc2 ='" << atoi(Misc2)<< "'"; WorldDatabase.Execute( qry.str().c_str( ) ); AI_Spell * sp = new AI_Spell; sp->agent = atoi(agent); sp->procChance = atoi(procChance); /* sp->procCount = atoi(procCount);*/ sp->spell = dbcSpell.LookupEntry(atoi(spellId)); sp->spellType = atoi(spellType); // sp->spelltargetType = atoi(spelltargetType); sp->floatMisc1 = (float)atof(floatMisc1); sp->Misc2 = (uint32)atof(Misc2); sp->cooldown = (uint32)atoi(spellCooldown); sp->procCount=0; sp->procCounter=0; sp->cooldowntime=0; sp->minrange = GetMinRange(dbcSpellRange.LookupEntry(dbcSpell.LookupEntry(atoi(spellId))->rangeIndex)); sp->maxrange = GetMaxRange(dbcSpellRange.LookupEntry(dbcSpell.LookupEntry(atoi(spellId))->rangeIndex)); target->GetProto()->spells.push_back(sp); if(sp->agent == AGENT_CALLFORHELP) target->GetAIInterface()->m_canCallForHelp = true; else if(sp->agent == AGENT_FLEE) target->GetAIInterface()->m_canFlee = true; else if(sp->agent == AGENT_RANGED) target->GetAIInterface()->m_canRangedAttack = true; else target->GetAIInterface()->addSpellToList(sp); return true; }
void WorldSession::HandleGossipHelloOpcode( WorldPacket & recv_data ) { CHECK_INWORLD_RETURN; uint64 guid; list<QuestRelation *>::iterator it; std::set<uint32> ql; recv_data >> guid; Creature* TalkingWith = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!TalkingWith) return; //stop when talked to for 3 min if(TalkingWith->GetAIInterface()) TalkingWith->GetAIInterface()->StopMovement(180000); // unstealth meh if( _player->InStealth() ) _player->RemoveAllAurasOfType( SPELL_AURA_MOD_STEALTH ); // reputation _player->Reputation_OnTalk(TalkingWith->m_factionDBC); DEBUG_LOG( "WORLD"," Received CMSG_GOSSIP_HELLO from %u",GUID_LOPART(guid) ); GossipScript * Script = TalkingWith->GetCreatureInfo() ? TalkingWith->GetCreatureInfo()->gossip_script : NULL; if(!Script) return; if (TalkingWith->isQuestGiver() && TalkingWith->HasQuests()) { WorldPacket data; data.SetOpcode(SMSG_GOSSIP_MESSAGE); Script->GossipHello(TalkingWith, _player, false); if(!_player->CurrentGossipMenu) return; _player->CurrentGossipMenu->BuildPacket(data); uint32 count=0;//sQuestMgr.ActiveQuestsCount(TalkingWith, GetPlayer()); size_t pos=data.wpos(); data << uint32(count); for (it = TalkingWith->QuestsBegin(); it != TalkingWith->QuestsEnd(); ++it) { uint32 status = sQuestMgr.CalcQuestStatus(TalkingWith, GetPlayer(), *it); if (status >= QMGR_QUEST_CHAT) { if (!ql.count((*it)->qst->id) ) { ql.insert((*it)->qst->id); count++; data << (*it)->qst->id; switch(status) { case QMGR_QUEST_NOT_FINISHED: data << uint32(4) << uint32(0); break; case QMGR_QUEST_FINISHED: data << uint32(4) << uint32(1); break; case QMGR_QUEST_CHAT: data << QMGR_QUEST_AVAILABLE << uint32(0); break; default: data << status << uint32(0); break; } data << (*it)->qst->title; } } } data.wpos(pos); data << count; SendPacket(&data); DEBUG_LOG( "WORLD"," Sent SMSG_GOSSIP_MESSAGE" ); } else { Script->GossipHello(TalkingWith, _player, true); } }
void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data ) { if(!_player->IsInWorld()) return; uint64 guid; recv_data >> guid; uint32 auction_id, price; recv_data >> auction_id >> price; Creature * pCreature = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!pCreature || !pCreature->auctionHouse) return; // Find Item AuctionHouse * ah = pCreature->auctionHouse; Auction * auct = ah->GetAuction(auction_id); if(auct == 0 || !auct->Owner || !_player) { SendAuctionPlaceBidResultPacket(0, AUCTION_ERROR_INTERNAL); return; } if(auct->Owner == _player->GetGUID()) { SendAuctionPlaceBidResultPacket(0, AUCTION_ERROR_BID_OWN_AUCTION); return; } if(auct->HighestBid > price && price != auct->BuyoutPrice) { //HACK: Don't know the correct error code... SendAuctionPlaceBidResultPacket(0, AUCTION_ERROR_INTERNAL); return; } if(_player->GetUInt32Value(PLAYER_FIELD_COINAGE) < price) { SendAuctionPlaceBidResultPacket(0, AUCTION_ERROR_MONEY); return; } _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -((int32)price)); if(auct->HighestBidder != 0) { // Return the money to the last highest bidder. char subject[100]; snprintf(subject, 100, "%u:0:0", (int)auct->pItem->GetEntry()); sMailSystem.SendAutomatedMessage(AUCTION, ah->GetID(), auct->HighestBidder, subject, "", auct->HighestBid, 0, 0, 62); // Do not send out bid notification, when current highest bidder and new bidder are the same player.. if(auct->HighestBidder != (uint32)_player->GetLowGUID()) ah->SendAuctionOutBidNotificationPacket(auct, _player->GetGUID(), price); } if(auct->BuyoutPrice == price) { auct->HighestBidder = _player->GetLowGUID(); auct->HighestBid = price; // we used buyout on the item. ah->QueueDeletion(auct, AUCTION_REMOVE_WON); SendAuctionPlaceBidResultPacket(auct->Id, AUCTION_ERROR_NONE); ah->SendAuctionBuyOutNotificationPacket(auct); } else { // update most recent bid auct->HighestBidder = _player->GetLowGUID(); auct->HighestBid = price; auct->UpdateInDB(); SendAuctionPlaceBidResultPacket(auct->Id, AUCTION_ERROR_NONE); } }
void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket & recv_data ) { CHECK_INWORLD_RETURN; //WorldPacket data; uint32 option; uint32 unk24; uint64 guid; bool Coded = false; uint32 BoxMoney = 0; std::string BoxMessage; recv_data >> guid >> unk24 >> option; DEBUG_LOG("WORLD","CMSG_GOSSIP_SELECT_OPTION Option %i Guid %.8X", option, guid ); GossipScript * Script = NULL; Object* qst_giver = NULL; uint32 guidtype = GET_TYPE_FROM_GUID(guid); if(guidtype==HIGHGUID_TYPE_UNIT) { Creature* crt = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!crt) return; qst_giver=crt; Script=crt->GetCreatureInfo()?crt->GetCreatureInfo()->gossip_script:NULL; } else if(guidtype==HIGHGUID_TYPE_ITEM) { Item* pitem = _player->GetItemInterface()->GetItemByGUID(guid); if(pitem==NULL) return; qst_giver=pitem; Script=pitem->GetProto()->gossip_script; } else if(guidtype==HIGHGUID_TYPE_GAMEOBJECT) { GameObject* gobj = _player->GetMapMgr()->GetGameObject(GET_LOWGUID_PART(guid)); if(!gobj) return; qst_giver=gobj; Script=gobj->GetInfo()->gossip_script; } if(!Script||!qst_giver) return; uint32 IntId = 1; if(_player->CurrentGossipMenu) { GossipMenuItem item = _player->CurrentGossipMenu->GetItem(option); IntId = item.IntId; Coded = item.Coded; } if(Coded) { if(recv_data.rpos()!=recv_data.wpos()) recv_data >> BoxMessage; Script->GossipSelectOption(qst_giver, _player, option, IntId, BoxMessage.c_str()); } else
bool ChatHandler::HandleWaypointAddFlyCommand(const char * args, WorldSession * m_session) { uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { SystemMessage(m_session, "No Selection"); return true; } AIInterface* ai = NULL; Creature* pCreature = NULL; Player* p = m_session->GetPlayer(); if(p->waypointunit != NULL) { SystemMessage(m_session, "Using Previous Unit."); ai = p->waypointunit; if(!ai) { SystemMessage(m_session, "Invalid Creature, please select another one."); return true; } pCreature = TO_CREATURE(ai->GetUnit()); if(!pCreature) { SystemMessage(m_session, "Invalid Creature, please select another one."); return true; } } else { pCreature = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!pCreature) { SystemMessage(m_session, "You should select a creature."); return true; } ai = pCreature->GetAIInterface(); } char* pWaitTime = strtok((char*)args, " "); uint32 WaitTime = (pWaitTime)? atoi(pWaitTime) : 0; char* pForwardEmoteId = strtok(NULL, " "); uint32 ForwardEmoteId = (pForwardEmoteId)? atoi(pForwardEmoteId) : 0; char* pBackwardEmoteId = strtok(NULL, " "); uint32 BackwardEmoteId = (pBackwardEmoteId)? atoi(pBackwardEmoteId) : 0; char* pForwardSkinId = strtok(NULL, " "); uint32 ForwardSkinId = (pForwardSkinId)? atoi(pForwardSkinId) : pCreature->GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); char* pBackwardSkinId = strtok(NULL, " "); uint32 BackwardSkinId = (pBackwardSkinId)? atoi(pBackwardSkinId) : pCreature->GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); char* pForwardEmoteOneShot = strtok(NULL, " "); uint32 ForwardEmoteOneShot = (pForwardEmoteOneShot)? atoi(pForwardEmoteOneShot) : 1; char* pBackwardEmoteOneShot = strtok(NULL, " "); uint32 BackwardEmoteOneShot = (pBackwardEmoteOneShot)? atoi(pBackwardEmoteOneShot) : 1; char* pForwardStandState = strtok(NULL, " "); uint32 ForwardStandState = (pForwardStandState)? atoi(pForwardStandState) : 0; char* pBackwardStandState = strtok(NULL, " "); uint32 BackwardStandState = (pBackwardStandState)? atoi(pBackwardStandState) : 0; char* pForwardSpellToCast = strtok(NULL, " "); uint32 ForwardSpellToCast = (pForwardSpellToCast)? atoi(pForwardSpellToCast) : 0; char* pBackwardSpellToCast = strtok(NULL, " "); uint32 BackwardSpellToCast = (pBackwardSpellToCast)? atoi(pBackwardSpellToCast) : 0; WayPoint* wp = new WayPoint; bool showing = ai->m_WayPointsShowing; wp->id = (uint32)ai->GetWayPointsCount()+1; wp->x = p->GetPositionX(); wp->y = p->GetPositionY(); wp->z = p->GetPositionZ(); wp->o = p->GetOrientation(); wp->waittime = WaitTime; wp->flags = 768; wp->forwardemoteoneshot = (ForwardEmoteOneShot>0)?true:false; wp->forwardemoteid = ForwardEmoteId; wp->backwardemoteoneshot = (BackwardEmoteOneShot>0)?true:false; wp->backwardemoteid = BackwardEmoteId; wp->forwardskinid = ForwardSkinId; wp->backwardskinid = BackwardSkinId; wp->forwardStandState = ForwardStandState > 8 ? 0 : ForwardStandState ; wp->backwardStandState = BackwardStandState > 8 ? 0 : BackwardStandState ; wp->forwardSpellToCast = ForwardSpellToCast; wp->backwardSpellToCast = BackwardSpellToCast; wp->forwardSayText = ""; wp->backwardSayText = ""; if(showing) ai->hideWayPoints(p); ai->addWayPoint(wp); ai->saveWayPoints(); if(showing) ai->showWayPoints(p,ai->m_WayPointsShowBackwards); SystemMessage(m_session, "Waypoint %u added.", wp->id); return true; }
// Charter part void WorldSession::HandleCharterBuy(WorldPacket & recv_data) { /* {CLIENT} Packet: (0x01BD) CMSG_PETITION_BUY PacketSize = 85 |------------------------------------------------|----------------| |00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |0123456789ABCDEF| |------------------------------------------------|----------------| |50 91 00 00 6E 13 01 F0 00 00 00 00 00 00 00 00 |P...n...........| |00 00 00 00 53 74 6F 72 6D 62 72 69 6E 67 65 72 |....Stormbringer| |73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |s...............| |00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| |00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 |................| |00 00 00 00 00 |..... | ------------------------------------------------------------------- */ if(!_player->IsInWorld()) return; uint64 creature_guid; uint64 crap; uint32 crap2; string name; uint8 error; uint32 crap3,crap4,crap5,crap6,crap7,crap8,crap9,crap10,crap11,arena_index,crap12; uint16 crap13; uint8 crap14; uint32 crap15; recv_data >> creature_guid >> crap >> crap2 >> name; recv_data >> crap3 >> crap4 >> crap5 >> crap6 >> crap7 >> crap8 >> crap9 >> crap10 >> crap11 >> crap12 >> crap13 >> crap14 >> arena_index >> crap15; Creature * crt = _player->GetMapMgr()->GetCreature(GET_LOWGUID_PART(creature_guid)); if(!crt) { Disconnect(); return; } if(crt->GetEntry()==19861 || crt->GetEntry()==18897 || crt->GetEntry()==19856 || crt->GetEntry()==sWorld.m_CustomCharterGiver ) /* i am lazy! */ { uint32 arena_type = arena_index - 1; if(arena_type > 2) return; if(_player->m_arenaTeams[arena_type] || _player->m_charters[arena_index]) { SendNotification(_player->GetSession()->LocalizedWorldSrv(71)); return; } ArenaTeam * t = objmgr.GetArenaTeamByName(name, arena_type); if(t != NULL) { sChatHandler.SystemMessage(this,_player->GetSession()->LocalizedWorldSrv(72)); return; } if(objmgr.GetCharterByName(name, (CharterTypes)arena_index)) { sChatHandler.SystemMessage(this,_player->GetSession()->LocalizedWorldSrv(72)); return; } if(_player->m_charters[arena_type]) { SendNotification(_player->GetSession()->LocalizedWorldSrv(73)); 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]) 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(0, 0, INV_ERR_INVENTORY_FULL); return; } error = _player->GetItemInterface()->CanReceiveItem(ip,1); 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, c->GetID()); i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883); if( !_player->GetItemInterface()->AddItemToFreeSlot(i) ) { c->Destroy(); i->DeleteMe(); return; } c->SaveToDB(); /*WorldPacket data(45); BuildItemPushResult(&data, _player->GetGUID(), ITEM_PUSH_TYPE_RECEIVE, 1, item_ids[arena_type], 0); SendPacket(&data);*/ SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1); _player->ModUnsigned32Value(PLAYER_FIELD_COINAGE, -(int32)costs[arena_type]); _player->m_charters[arena_index] = c; _player->SaveToDB(false); } } else { Guild * g = objmgr.GetGuildByGuildName(name); Charter * c = objmgr.GetCharterByName(name, CHARTER_TYPE_GUILD); if(g != 0 || c != 0) { SendNotification(_player->GetSession()->LocalizedWorldSrv(74)); return; } if(_player->m_charters[CHARTER_TYPE_GUILD]) { SendNotification(_player->GetSession()->LocalizedWorldSrv(75)); return; } ItemPrototype * ip = ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER); assert(ip); SlotResult res = _player->GetItemInterface()->FindFreeInventorySlot(ip); if(res.Result == 0) { _player->GetItemInterface()->BuildInventoryChangeError(0, 0, INV_ERR_INVENTORY_FULL); return; } error = _player->GetItemInterface()->CanReceiveItem(ItemPrototypeStorage.LookupEntry(ITEM_ENTRY_GUILD_CHARTER),1); 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, c->GetID()); i->SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, 57813883); if( !_player->GetItemInterface()->AddItemToFreeSlot(i) ) { c->Destroy(); i->DeleteMe(); return; } c->SaveToDB(); /*data.clear(); data.resize(45); BuildItemPushResult(&data, _player->GetGUID(), ITEM_PUSH_TYPE_RECEIVE, 1, ITEM_ENTRY_GUILD_CHARTER, 0); SendPacket(&data);*/ SendItemPushResult(i, false, true, false, true, _player->GetItemInterface()->LastSearchItemBagSlot(), _player->GetItemInterface()->LastSearchItemSlot(), 1); _player->m_charters[CHARTER_TYPE_GUILD] = c; _player->SaveToDB(false); } } }