public void SendTaxiMenu(Creature unit) { // find current node uint curloc = Global.ObjectMgr.GetNearestTaxiNode(unit.GetPositionX(), unit.GetPositionY(), unit.GetPositionZ(), unit.GetMapId(), GetPlayer().GetTeam()); if (curloc == 0) { return; } bool lastTaxiCheaterState = GetPlayer().isTaxiCheater(); if (unit.GetEntry() == 29480) { GetPlayer().SetTaxiCheater(true); // Grimwing in Ebon Hold, special case. NOTE: Not perfect, Zul'Aman should not be included according to WoWhead, and I think taxicheat includes it. } ShowTaxiNodes data = new ShowTaxiNodes(); data.WindowInfo.HasValue = true; data.WindowInfo.Value.UnitGUID = unit.GetGUID(); data.WindowInfo.Value.CurrentNode = (int)curloc; GetPlayer().m_taxi.AppendTaximaskTo(data, lastTaxiCheaterState); SendPacket(data); GetPlayer().SetTaxiCheater(lastTaxiCheaterState); }
void HandleQueryBattlePetName(QueryBattlePetName queryBattlePetName) { QueryBattlePetNameResponse response = new(); response.BattlePetID = queryBattlePetName.BattlePetID; Creature summonedBattlePet = ObjectAccessor.GetCreatureOrPetOrVehicle(_player, queryBattlePetName.UnitGUID); if (!summonedBattlePet || !summonedBattlePet.IsSummon()) { SendPacket(response); return; } response.CreatureID = summonedBattlePet.GetEntry(); response.Timestamp = summonedBattlePet.GetBattlePetCompanionNameTimestamp(); Unit petOwner = summonedBattlePet.ToTempSummon().GetSummonerUnit(); if (!petOwner.IsPlayer()) { SendPacket(response); return; } BattlePet battlePet = petOwner.ToPlayer().GetSession().GetBattlePetMgr().GetPet(queryBattlePetName.BattlePetID); if (battlePet == null) { SendPacket(response); return; } response.Name = battlePet.PacketInfo.Name; if (battlePet.DeclinedName != null) { response.HasDeclined = true; response.DeclinedNames = battlePet.DeclinedName; } response.Allow = !response.Name.IsEmpty(); SendPacket(response); }
void HandleTrainerList(Hello packet) { Creature npc = GetPlayer().GetNPCIfCanInteractWith(packet.Unit, NPCFlags.Trainer); if (!npc) { Log.outDebug(LogFilter.Network, $"WorldSession.SendTrainerList - {packet.Unit.ToString()} not found or you can not interact with him."); return; } uint trainerId = Global.ObjectMgr.GetCreatureDefaultTrainer(npc.GetEntry()); if (trainerId != 0) { SendTrainerList(npc, trainerId); } else { Log.outDebug(LogFilter.Network, $"WorldSession.SendTrainerList - Creature id {npc.GetEntry()} has no trainer data."); } }
void HandleBattlemasterHello(Hello hello) { Creature unit = GetPlayer().GetNPCIfCanInteractWith(hello.Unit, NPCFlags.BattleMaster); if (!unit) { return; } // Stop the npc if moving unit.StopMoving(); BattlegroundTypeId bgTypeId = Global.BattlegroundMgr.GetBattleMasterBG(unit.GetEntry()); if (!GetPlayer().GetBGAccessByLevel(bgTypeId)) { // temp, must be gossip message... SendNotification(CypherStrings.YourBgLevelReqError); return; } Global.BattlegroundMgr.SendBattlegroundList(GetPlayer(), hello.Unit, bgTypeId); }
public void SendTaxiMenu(Creature unit) { // find current node uint curloc = Global.ObjectMgr.GetNearestTaxiNode(unit.GetPositionX(), unit.GetPositionY(), unit.GetPositionZ(), unit.GetMapId(), GetPlayer().GetTeam()); if (curloc == 0) { return; } bool lastTaxiCheaterState = GetPlayer().isTaxiCheater(); if (unit.GetEntry() == 29480) { GetPlayer().SetTaxiCheater(true); // Grimwing in Ebon Hold, special case. NOTE: Not perfect, Zul'Aman should not be included according to WoWhead, and I think taxicheat includes it. } ShowTaxiNodes data = new ShowTaxiNodes(); data.WindowInfo.HasValue = true; data.WindowInfo.Value.UnitGUID = unit.GetGUID(); data.WindowInfo.Value.CurrentNode = (int)curloc; GetPlayer().m_taxi.AppendTaximaskTo(data, lastTaxiCheaterState); byte[] reachableNodes = new byte[PlayerConst.TaxiMaskSize]; Global.TaxiPathGraph.GetReachableNodesMask(CliDB.TaxiNodesStorage.LookupByKey(curloc), reachableNodes); for (var i = 0; i < PlayerConst.TaxiMaskSize; ++i) { data.CanLandNodes[i] &= reachableNodes[i]; data.CanUseNodes[i] &= reachableNodes[i]; } SendPacket(data); GetPlayer().SetTaxiCheater(lastTaxiCheaterState); }
void HandleBattlemasterHello(Hello hello) { Creature unit = GetPlayer().GetNPCIfCanInteractWith(hello.Unit, NPCFlags.BattleMaster, NPCFlags2.None); if (!unit) { return; } // Stop the npc if moving unit.PauseMovement(WorldConfig.GetUIntValue(WorldCfg.CreatureStopForPlayer)); unit.SetHomePosition(unit.GetPosition()); BattlegroundTypeId bgTypeId = Global.BattlegroundMgr.GetBattleMasterBG(unit.GetEntry()); if (!GetPlayer().GetBGAccessByLevel(bgTypeId)) { // temp, must be gossip message... SendNotification(CypherStrings.YourBgLevelReqError); return; } Global.BattlegroundMgr.SendBattlegroundList(GetPlayer(), hello.Unit, bgTypeId); }
public uint SendChat(Creature source, byte textGroup, WorldObject whisperTarget = null, ChatMsg msgType = ChatMsg.Addon, Language language = Language.Addon, CreatureTextRange range = CreatureTextRange.Normal, uint sound = 0, Team team = Team.Other, bool gmOnly = false, Player srcPlr = null) { if (source == null) { return(0); } var sList = mTextMap.LookupByKey(source.GetEntry()); if (sList == null) { Log.outError(LogFilter.Sql, "GossipManager: Could not find Text for Creature({0}) Entry {1} in 'creature_text' table. Ignoring.", source.GetName(), source.GetEntry()); return(0); } var textGroupContainer = sList.LookupByKey(textGroup); if (textGroupContainer.Empty()) { Log.outError(LogFilter.ChatSystem, "GossipManager: Could not find TextGroup {0} for Creature({1}) GuidLow {2} Entry {3}. Ignoring.", textGroup, source.GetName(), source.GetGUID().ToString(), source.GetEntry()); return(0); } List <CreatureTextEntry> tempGroup = new List <CreatureTextEntry>(); var repeatGroup = source.GetTextRepeatGroup(textGroup); foreach (var entry in textGroupContainer) { if (!repeatGroup.Contains(entry.id)) { tempGroup.Add(entry); } } if (tempGroup.Empty()) { source.ClearTextRepeatGroup(textGroup); tempGroup = textGroupContainer; } var textEntry = tempGroup.SelectRandomElementByWeight(t => t.probability); ChatMsg finalType = (msgType == ChatMsg.Addon) ? textEntry.type : msgType; Language finalLang = (language == Language.Addon) ? textEntry.lang : language; uint finalSound = textEntry.sound; if (sound != 0) { finalSound = sound; } else { BroadcastTextRecord bct = CliDB.BroadcastTextStorage.LookupByKey(textEntry.BroadcastTextId); if (bct != null) { uint broadcastTextSoundId = bct.SoundEntriesID[source.GetGender() == Gender.Female ? 1 : 0]; if (broadcastTextSoundId != 0) { finalSound = broadcastTextSoundId; } } } if (range == CreatureTextRange.Normal) { range = textEntry.TextRange; } if (finalSound != 0) { SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly); } Unit finalSource = source; if (srcPlr) { finalSource = srcPlr; } if (textEntry.emote != 0) { SendEmote(finalSource, textEntry.emote); } if (srcPlr) { PlayerTextBuilder builder = new PlayerTextBuilder(source, finalSource, finalSource.GetGender(), finalType, textEntry.groupId, textEntry.id, finalLang, whisperTarget); SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly); } else { CreatureTextBuilder builder = new CreatureTextBuilder(finalSource, finalSource.GetGender(), finalType, textEntry.groupId, textEntry.id, finalLang, whisperTarget); SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly); } source.SetTextRepeatId(textGroup, textEntry.id); return(textEntry.duration); }
public void SendListInventory(ObjectGuid vendorGuid) { Creature vendor = GetPlayer().GetNPCIfCanInteractWith(vendorGuid, NPCFlags.Vendor); if (vendor == null) { Log.outDebug(LogFilter.Network, "WORLD: SendListInventory - {0} not found or you can not interact with him.", vendorGuid.ToString()); GetPlayer().SendSellError(SellResult.CantFindVendor, null, ObjectGuid.Empty); return; } // remove fake death if (GetPlayer().HasUnitState(UnitState.Died)) { GetPlayer().RemoveAurasByType(AuraType.FeignDeath); } // Stop the npc if moving if (vendor.HasUnitState(UnitState.Moving)) { vendor.StopMoving(); } VendorItemData vendorItems = vendor.GetVendorItems(); int rawItemCount = vendorItems != null?vendorItems.GetItemCount() : 0; VendorInventory packet = new VendorInventory(); packet.Vendor = vendor.GetGUID(); float discountMod = GetPlayer().GetReputationPriceDiscount(vendor); byte count = 0; for (uint slot = 0; slot < rawItemCount; ++slot) { VendorItem vendorItem = vendorItems.GetItem(slot); if (vendorItem == null) { continue; } VendorItemPkt item = new VendorItemPkt(); PlayerConditionRecord playerCondition = CliDB.PlayerConditionStorage.LookupByKey(vendorItem.PlayerConditionId); if (playerCondition != null) { if (!ConditionManager.IsPlayerMeetingCondition(_player, playerCondition)) { item.PlayerConditionFailed = (int)playerCondition.Id; } } if (vendorItem.Type == ItemVendorType.Item) { ItemTemplate itemTemplate = Global.ObjectMgr.GetItemTemplate(vendorItem.item); if (itemTemplate == null) { continue; } int leftInStock = vendorItem.maxcount == 0 ? -1 : (int)vendor.GetVendorItemCurrentCount(vendorItem); if (!GetPlayer().IsGameMaster()) { if (!Convert.ToBoolean(itemTemplate.GetAllowableClass() & GetPlayer().getClassMask()) && itemTemplate.GetBonding() == ItemBondingType.OnAcquire) { continue; } if ((itemTemplate.GetFlags2().HasAnyFlag(ItemFlags2.FactionHorde) && GetPlayer().GetTeam() == Team.Alliance) || (itemTemplate.GetFlags2().HasAnyFlag(ItemFlags2.FactionAlliance) && GetPlayer().GetTeam() == Team.Horde)) { continue; } if (leftInStock == 0) { continue; } } if (!Global.ConditionMgr.IsObjectMeetingVendorItemConditions(vendor.GetEntry(), vendorItem.item, _player, vendor)) { Log.outDebug(LogFilter.Condition, "SendListInventory: conditions not met for creature entry {0} item {1}", vendor.GetEntry(), vendorItem.item); continue; } int price = (int)(vendorItem.IsGoldRequired(itemTemplate) ? Math.Floor(itemTemplate.GetBuyPrice() * discountMod) : 0); int priceMod = GetPlayer().GetTotalAuraModifier(AuraType.ModVendorItemsPrices); if (priceMod != 0) { price -= MathFunctions.CalculatePct(price, priceMod); } item.MuID = (int)slot + 1; item.Durability = (int)itemTemplate.MaxDurability; item.ExtendedCostID = (int)vendorItem.ExtendedCost; item.Type = (int)vendorItem.Type; item.Quantity = leftInStock; item.StackCount = (int)itemTemplate.GetBuyCount(); item.Price = (ulong)price; item.DoNotFilterOnVendor = vendorItem.IgnoreFiltering; item.Item.ItemID = vendorItem.item; if (!vendorItem.BonusListIDs.Empty()) { item.Item.ItemBonus.HasValue = true; item.Item.ItemBonus.Value.BonusListIDs = vendorItem.BonusListIDs; } packet.Items.Add(item); } else if (vendorItem.Type == ItemVendorType.Currency) { CurrencyTypesRecord currencyTemplate = CliDB.CurrencyTypesStorage.LookupByKey(vendorItem.item); if (currencyTemplate == null) { continue; } if (vendorItem.ExtendedCost == 0) { continue; // there's no price defined for currencies, only extendedcost is used } item.MuID = (int)slot + 1; // client expects counting to start at 1 item.ExtendedCostID = (int)vendorItem.ExtendedCost; item.Item.ItemID = vendorItem.item; item.Type = (int)vendorItem.Type; item.StackCount = (int)vendorItem.maxcount; item.DoNotFilterOnVendor = vendorItem.IgnoreFiltering; packet.Items.Add(item); } else { continue; } if (++count >= SharedConst.MaxVendorItems) { break; } } SendPacket(packet); }
void HandlePetSpellAutocast(PetSpellAutocast packet) { Creature pet = ObjectAccessor.GetCreatureOrPetOrVehicle(GetPlayer(), packet.PetGUID); if (!pet) { Log.outError(LogFilter.Network, "WorldSession.HandlePetSpellAutocast: {0} not found.", packet.PetGUID.ToString()); return; } if (pet != GetPlayer().GetGuardianPet() && pet != GetPlayer().GetCharmed()) { Log.outError(LogFilter.Network, "WorldSession.HandlePetSpellAutocast: {0} isn't pet of player {1} ({2}).", packet.PetGUID.ToString(), GetPlayer().GetName(), GetPlayer().GetGUID().ToString()); return; } SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(packet.SpellID, pet.GetMap().GetDifficultyID()); if (spellInfo == null) { Log.outError(LogFilter.Network, "WorldSession.HandlePetSpellAutocast: Unknown spell id {0} used by {1}.", packet.SpellID, packet.PetGUID.ToString()); return; } List <Unit> pets = new(); foreach (Unit controlled in _player.m_Controlled) { if (controlled.GetEntry() == pet.GetEntry() && controlled.IsAlive()) { pets.Add(controlled); } } foreach (Unit petControlled in pets) { // do not add not learned spells/ passive spells if (!petControlled.HasSpell(packet.SpellID) || !spellInfo.IsAutocastable()) { return; } CharmInfo charmInfo = petControlled.GetCharmInfo(); if (charmInfo == null) { Log.outError(LogFilter.Network, "WorldSession.HandlePetSpellAutocastOpcod: object {0} is considered pet-like but doesn't have a charminfo!", petControlled.GetGUID().ToString()); return; } if (petControlled.IsPet()) { petControlled.ToPet().ToggleAutocast(spellInfo, packet.AutocastEnabled); } else { charmInfo.ToggleCreatureAutocast(spellInfo, packet.AutocastEnabled); } charmInfo.SetSpellAutocast(spellInfo, packet.AutocastEnabled); } }