void HandleQuestgiverHello(QuestGiverHello packet) { Creature creature = GetPlayer().GetNPCIfCanInteractWith(packet.QuestGiverGUID, NPCFlags.QuestGiver, NPCFlags2.None); if (creature == null) { Log.outDebug(LogFilter.Network, "WORLD: HandleQuestgiverHello - {0} not found or you can't interact with him.", packet.QuestGiverGUID.ToString()); return; } // remove fake death if (GetPlayer().HasUnitState(UnitState.Died)) { GetPlayer().RemoveAurasByType(AuraType.FeignDeath); } // Stop the npc if moving creature.PauseMovement(WorldConfig.GetUIntValue(WorldCfg.CreatureStopForPlayer)); creature.SetHomePosition(creature.GetPosition()); _player.PlayerTalkClass.ClearMenus(); if (creature.GetAI().GossipHello(_player)) { return; } GetPlayer().PrepareGossipMenu(creature, creature.GetCreatureTemplate().GossipMenuId, true); GetPlayer().SendPreparedGossip(creature); }
void HandleQuestgiverHello(QuestGiverHello packet) { Creature creature = GetPlayer().GetNPCIfCanInteractWith(packet.QuestGiverGUID, NPCFlags.QuestGiver, NPCFlags2.None); if (creature == null) { Log.outDebug(LogFilter.Network, "WORLD: HandleQuestgiverHello - {0} not found or you can't interact with him.", packet.QuestGiverGUID.ToString()); return; } // remove fake death if (GetPlayer().HasUnitState(UnitState.Died)) { GetPlayer().RemoveAurasByType(AuraType.FeignDeath); } // Stop the npc if moving creature.StopMoving(); if (Global.ScriptMgr.OnGossipHello(GetPlayer(), creature)) { return; } GetPlayer().PrepareGossipMenu(creature, creature.GetCreatureTemplate().GossipMenuId, true); GetPlayer().SendPreparedGossip(creature); creature.GetAI().GossipHello(GetPlayer()); }
public static uint XPGain(Player player, Unit u, bool isBattleGround = false) { Creature creature = u.ToCreature(); uint gain = 0; if (!creature || creature.CanGiveExperience()) { float xpMod = 1.0f; gain = BaseGain(player.getLevel(), u.getLevel()); if (gain != 0 && creature) { // Players get only 10% xp for killing creatures of lower expansion levels than himself if ((creature.GetCreatureTemplate().HealthScalingExpansion < (int)GetExpansionForLevel(player.getLevel()))) { gain = (uint)Math.Round(gain / 10.0f); } if (creature.isElite()) { // Elites in instances have a 2.75x XP bonus instead of the regular 2x world bonus. if (u.GetMap().IsDungeon()) { xpMod *= 2.75f; } else { xpMod *= 2.0f; } } xpMod *= creature.GetCreatureTemplate().ModExperience; } xpMod *= isBattleGround ? WorldConfig.GetFloatValue(WorldCfg.RateXpBgKill) : WorldConfig.GetFloatValue(WorldCfg.RateXpKill); if (creature && creature.m_PlayerDamageReq != 0) // if players dealt less than 50% of the damage and were credited anyway (due to CREATURE_FLAG_EXTRA_NO_PLAYER_DAMAGE_REQ), scale XP gained appropriately (linear scaling) { xpMod *= 1.0f - 2.0f * creature.m_PlayerDamageReq / creature.GetMaxHealth(); } gain = (uint)(gain * xpMod); } Global.ScriptMgr.OnGainCalculation(gain, player, u); return(gain); }
void HandleGossipHello(Hello packet) { Creature unit = GetPlayer().GetNPCIfCanInteractWith(packet.Unit, NPCFlags.Gossip); if (unit == null) { Log.outDebug(LogFilter.Network, "WORLD: HandleGossipHello - {0} not found or you can not interact with him.", packet.Unit.ToString()); return; } // set faction visible if needed var factionTemplateEntry = CliDB.FactionTemplateStorage.LookupByKey(unit.getFaction()); if (factionTemplateEntry != null) { GetPlayer().GetReputationMgr().SetVisible(factionTemplateEntry); } GetPlayer().RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Talk); if (unit.IsArmorer() || unit.IsCivilian() || unit.IsQuestGiver() || unit.IsServiceProvider() || unit.IsGuard()) { unit.StopMoving(); } // If spiritguide, no need for gossip menu, just put player into resurrect queue if (unit.IsSpiritGuide()) { Battleground bg = GetPlayer().GetBattleground(); if (bg) { bg.AddPlayerToResurrectQueue(unit.GetGUID(), GetPlayer().GetGUID()); Global.BattlegroundMgr.SendAreaSpiritHealerQuery(GetPlayer(), bg, unit.GetGUID()); return; } } if (!Global.ScriptMgr.OnGossipHello(GetPlayer(), unit)) { GetPlayer().PrepareGossipMenu(unit, unit.GetCreatureTemplate().GossipMenuId, true); GetPlayer().SendPreparedGossip(unit); } unit.GetAI().sGossipHello(GetPlayer()); }
void HandleGossipHello(Hello packet) { Creature unit = GetPlayer().GetNPCIfCanInteractWith(packet.Unit, NPCFlags.Gossip, NPCFlags2.None); if (unit == null) { Log.outDebug(LogFilter.Network, "WORLD: HandleGossipHello - {0} not found or you can not interact with him.", packet.Unit.ToString()); return; } // set faction visible if needed var factionTemplateEntry = CliDB.FactionTemplateStorage.LookupByKey(unit.GetFaction()); if (factionTemplateEntry != null) { GetPlayer().GetReputationMgr().SetVisible(factionTemplateEntry); } GetPlayer().RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Interacting); // Stop the npc if moving unit.PauseMovement(WorldConfig.GetUIntValue(WorldCfg.CreatureStopForPlayer)); unit.SetHomePosition(unit.GetPosition()); // If spiritguide, no need for gossip menu, just put player into resurrect queue if (unit.IsSpiritGuide()) { Battleground bg = GetPlayer().GetBattleground(); if (bg) { bg.AddPlayerToResurrectQueue(unit.GetGUID(), GetPlayer().GetGUID()); Global.BattlegroundMgr.SendAreaSpiritHealerQuery(GetPlayer(), bg, unit.GetGUID()); return; } } _player.PlayerTalkClass.ClearMenus(); if (!unit.GetAI().GossipHello(_player)) { GetPlayer().PrepareGossipMenu(unit, unit.GetCreatureTemplate().GossipMenuId, true); GetPlayer().SendPreparedGossip(unit); } }
void HandleSellItem(SellItem packet) { if (packet.ItemGUID.IsEmpty()) { return; } var pl = GetPlayer(); Creature creature = pl.GetNPCIfCanInteractWith(packet.VendorGUID, NPCFlags.Vendor, NPCFlags2.None); if (creature == null) { Log.outDebug(LogFilter.Network, "WORLD: HandleSellItemOpcode - {0} not found or you can not interact with him.", packet.VendorGUID.ToString()); pl.SendSellError(SellResult.CantFindVendor, null, packet.ItemGUID); return; } if (creature.GetCreatureTemplate().FlagsExtra.HasFlag(CreatureFlagsExtra.NoSellVendor)) { _player.SendSellError(SellResult.CantSellToThisMerchant, creature, packet.ItemGUID); return; } // remove fake death if (pl.HasUnitState(UnitState.Died)) { pl.RemoveAurasByType(AuraType.FeignDeath); } Item pItem = pl.GetItemByGuid(packet.ItemGUID); if (pItem != null) { // prevent sell not owner item if (pl.GetGUID() != pItem.GetOwnerGUID()) { pl.SendSellError(SellResult.CantSellItem, creature, packet.ItemGUID); return; } // prevent sell non empty bag by drag-and-drop at vendor's item list if (pItem.IsNotEmptyBag()) { pl.SendSellError(SellResult.CantSellItem, creature, packet.ItemGUID); return; } // prevent sell currently looted item if (pl.GetLootGUID() == pItem.GetGUID()) { pl.SendSellError(SellResult.CantSellItem, creature, packet.ItemGUID); return; } // prevent selling item for sellprice when the item is still refundable // this probably happens when right clicking a refundable item, the client sends both // CMSG_SELL_ITEM and CMSG_REFUND_ITEM (unverified) if (pItem.IsRefundable()) { return; // Therefore, no feedback to client } // special case at auto sell (sell all) if (packet.Amount == 0) { packet.Amount = pItem.GetCount(); } else { // prevent sell more items that exist in stack (possible only not from client) if (packet.Amount > pItem.GetCount()) { pl.SendSellError(SellResult.CantSellItem, creature, packet.ItemGUID); return; } } ItemTemplate pProto = pItem.GetTemplate(); if (pProto != null) { if (pProto.GetSellPrice() > 0) { ulong money = pProto.GetSellPrice() * packet.Amount; if (!_player.ModifyMoney((long)money)) // ensure player doesn't exceed gold limit { _player.SendSellError(SellResult.CantSellItem, creature, packet.ItemGUID); return; } _player.UpdateCriteria(CriteriaType.MoneyEarnedFromSales, money); _player.UpdateCriteria(CriteriaType.SellItemsToVendors, 1); if (packet.Amount < pItem.GetCount()) // need split items { Item pNewItem = pItem.CloneItem(packet.Amount, pl); if (pNewItem == null) { Log.outError(LogFilter.Network, "WORLD: HandleSellItemOpcode - could not create clone of item {0}; count = {1}", pItem.GetEntry(), packet.Amount); pl.SendSellError(SellResult.CantSellItem, creature, packet.ItemGUID); return; } pItem.SetCount(pItem.GetCount() - packet.Amount); pl.ItemRemovedQuestCheck(pItem.GetEntry(), packet.Amount); if (pl.IsInWorld) { pItem.SendUpdateToPlayer(pl); } pItem.SetState(ItemUpdateState.Changed, pl); pl.AddItemToBuyBackSlot(pNewItem); if (pl.IsInWorld) { pNewItem.SendUpdateToPlayer(pl); } } else { pl.RemoveItem(pItem.GetBagSlot(), pItem.GetSlot(), true); pl.ItemRemovedQuestCheck(pItem.GetEntry(), pItem.GetCount()); Item.RemoveItemFromUpdateQueueOf(pItem, pl); pl.AddItemToBuyBackSlot(pItem); } } else { pl.SendSellError(SellResult.CantSellItem, creature, packet.ItemGUID); } return; } } pl.SendSellError(SellResult.CantSellItem, creature, packet.ItemGUID); return; }
void HandleTrainerBuySpell(TrainerBuySpell packet) { Creature trainer = _player.GetNPCIfCanInteractWith(packet.TrainerGUID, NPCFlags.Trainer); if (trainer == null) { Log.outDebug(LogFilter.Network, "WORLD: HandleTrainerBuySpell - {0} not found or you can not interact with him.", packet.TrainerGUID.ToString()); return; } // remove fake death if (_player.HasUnitState(UnitState.Died)) { _player.RemoveAurasByType(AuraType.FeignDeath); } // check race for mount trainers if (trainer.GetCreatureTemplate().TrainerType == TrainerType.Mounts) { Race trainerRace = trainer.GetCreatureTemplate().TrainerRace; if (trainerRace != 0) { if (_player.GetRace() != trainerRace) { return; } } } // check class for class trainers if (_player.GetClass() != trainer.GetCreatureTemplate().TrainerClass&& trainer.GetCreatureTemplate().TrainerType == TrainerType.Class) { return; } // check present spell in trainer spell list var trainerSpells = trainer.GetTrainerSpells(); if (trainerSpells == null) { SendTrainerBuyFailed(packet.TrainerGUID, packet.SpellID, 0); return; } var trainerSpell = trainerSpells.spellList.LookupByKey(packet.SpellID); if (trainerSpell == null) { SendTrainerBuyFailed(packet.TrainerGUID, packet.SpellID, 0); return; } // can't be learn, cheat? Or double learn with lags... if (_player.GetTrainerSpellState(trainerSpell) != TrainerSpellState.Green) { SendTrainerBuyFailed(packet.TrainerGUID, packet.SpellID, 0); return; } // apply reputation discount uint nSpellCost = (uint)(Math.Floor((double)trainerSpell.MoneyCost) * _player.GetReputationPriceDiscount(trainer)); // check money requirement if (!_player.HasEnoughMoney(nSpellCost)) { SendTrainerBuyFailed(packet.TrainerGUID, packet.SpellID, 1); return; } _player.ModifyMoney(-nSpellCost); trainer.SendPlaySpellVisualKit(179, 0, 0); // 53 SpellCastDirected _player.SendPlaySpellVisualKit(362, 1, 0); // 113 EmoteSalute // learn explicitly or cast explicitly if (trainerSpell.IsCastable()) { _player.CastSpell(GetPlayer(), trainerSpell.SpellID, true); } else { _player.LearnSpell(packet.SpellID, false); } }