Exemplo n.º 1
0
        public void SetEscortPaused(bool on)
        {
            if (!HasEscortState(EscortState.Escorting))
            {
                return;
            }

            if (on)
            {
                AddEscortState(EscortState.Paused);
                IMovementGenerator movementGenerator = me.GetMotionMaster().GetMotionSlot(MovementSlot.Idle);
                if (movementGenerator != null)
                {
                    movementGenerator.Pause(0);
                }
            }
            else
            {
                RemoveEscortState(EscortState.Paused);
                _resume = true;
            }
        }
Exemplo n.º 2
0
        public bool SetCharmedBy(Unit charmer, CharmType type, AuraApplication aurApp = null)
        {
            if (!charmer)
            {
                return(false);
            }

            // dismount players when charmed
            if (IsTypeId(TypeId.Player))
            {
                RemoveAurasByType(AuraType.Mounted);
            }

            if (charmer.IsTypeId(TypeId.Player))
            {
                charmer.RemoveAurasByType(AuraType.Mounted);
            }

            Cypher.Assert(type != CharmType.Possess || charmer.IsTypeId(TypeId.Player));
            Cypher.Assert((type == CharmType.Vehicle) == IsVehicle());

            Log.outDebug(LogFilter.Unit, "SetCharmedBy: charmer {0} (GUID {1}), charmed {2} (GUID {3}), type {4}.", charmer.GetEntry(), charmer.GetGUID().ToString(), GetEntry(), GetGUID().ToString(), type);

            if (this == charmer)
            {
                Log.outFatal(LogFilter.Unit, "Unit:SetCharmedBy: Unit {0} (GUID {1}) is trying to charm itself!", GetEntry(), GetGUID().ToString());
                return(false);
            }

            if (IsTypeId(TypeId.Player) && ToPlayer().GetTransport())
            {
                Log.outFatal(LogFilter.Unit, "Unit:SetCharmedBy: Player on transport is trying to charm {0} (GUID {1})", GetEntry(), GetGUID().ToString());
                return(false);
            }

            // Already charmed
            if (!GetCharmerGUID().IsEmpty())
            {
                Log.outFatal(LogFilter.Unit, "Unit:SetCharmedBy: {0} (GUID {1}) has already been charmed but {2} (GUID {3}) is trying to charm it!", GetEntry(), GetGUID().ToString(), charmer.GetEntry(), charmer.GetGUID().ToString());
                return(false);
            }

            CastStop();
            CombatStop(); // @todo CombatStop(true) may cause crash (interrupt spells)

            Player playerCharmer = charmer.ToPlayer();

            // Charmer stop charming
            if (playerCharmer)
            {
                playerCharmer.StopCastingCharm();
                playerCharmer.StopCastingBindSight();
            }

            // Charmed stop charming
            if (IsTypeId(TypeId.Player))
            {
                ToPlayer().StopCastingCharm();
                ToPlayer().StopCastingBindSight();
            }

            // StopCastingCharm may remove a possessed pet?
            if (!IsInWorld)
            {
                Log.outFatal(LogFilter.Unit, "Unit:SetCharmedBy: {0} (GUID {1}) is not in world but {2} (GUID {3}) is trying to charm it!", GetEntry(), GetGUID().ToString(), charmer.GetEntry(), charmer.GetGUID().ToString());
                return(false);
            }

            // charm is set by aura, and aura effect remove handler was called during apply handler execution
            // prevent undefined behaviour
            if (aurApp != null && aurApp.GetRemoveMode() != 0)
            {
                return(false);
            }

            _oldFactionId = GetFaction();
            SetFaction(charmer.GetFaction());

            // Set charmed
            charmer.SetCharm(this, true);

            if (IsTypeId(TypeId.Unit))
            {
                IMovementGenerator movementGenerator = GetMotionMaster().GetMotionSlot(MovementSlot.Idle);
                if (movementGenerator != null)
                {
                    movementGenerator.Pause(0);
                }

                GetMotionMaster().Clear(MovementSlot.Active);

                StopMoving();

                ToCreature().GetAI().OnCharmed(true);
            }
            else
            {
                Player player = ToPlayer();
                if (player)
                {
                    if (player.IsAFK())
                    {
                        player.ToggleAFK();
                    }

                    if (charmer.IsTypeId(TypeId.Unit)) // we are charmed by a creature
                    {
                        // change AI to charmed AI on next Update tick
                        NeedChangeAI = true;
                        if (IsAIEnabled)
                        {
                            IsAIEnabled = false;
                            player.GetAI().OnCharmed(true);
                        }
                    }

                    player.SetClientControl(this, false);
                }
            }

            // charm is set by aura, and aura effect remove handler was called during apply handler execution
            // prevent undefined behaviour
            if (aurApp != null && aurApp.GetRemoveMode() != 0)
            {
                return(false);
            }

            // Pets already have a properly initialized CharmInfo, don't overwrite it.
            if (type != CharmType.Vehicle && GetCharmInfo() == null)
            {
                InitCharmInfo();
                if (type == CharmType.Possess)
                {
                    GetCharmInfo().InitPossessCreateSpells();
                }
                else
                {
                    GetCharmInfo().InitCharmCreateSpells();
                }
            }

            if (playerCharmer)
            {
                switch (type)
                {
                case CharmType.Vehicle:
                    AddUnitFlag(UnitFlags.PlayerControlled);
                    playerCharmer.SetClientControl(this, true);
                    playerCharmer.VehicleSpellInitialize();
                    break;

                case CharmType.Possess:
                    AddUnitState(UnitState.Possessed);
                    AddUnitFlag(UnitFlags.PlayerControlled);
                    charmer.AddUnitFlag(UnitFlags.RemoveClientControl);
                    playerCharmer.SetClientControl(this, true);
                    playerCharmer.PossessSpellInitialize();
                    break;

                case CharmType.Charm:
                    if (IsTypeId(TypeId.Unit) && charmer.GetClass() == Class.Warlock)
                    {
                        CreatureTemplate cinfo = ToCreature().GetCreatureTemplate();
                        if (cinfo != null && cinfo.CreatureType == CreatureType.Demon)
                        {
                            // to prevent client crash
                            SetClass(Class.Mage);

                            // just to enable stat window
                            if (GetCharmInfo() != null)
                            {
                                GetCharmInfo().SetPetNumber(Global.ObjectMgr.GeneratePetNumber(), true);
                            }

                            // if charmed two demons the same session, the 2nd gets the 1st one's name
                            SetPetNameTimestamp((uint)GameTime.GetGameTime());     // cast can't be helped
                        }
                    }
                    playerCharmer.CharmSpellInitialize();
                    break;

                default:
                case CharmType.Convert:
                    break;
                }
            }
            return(true);
        }