private void OnPlayerSpeedChanged(Player player, UnitMoveType moveType, float rate)
 {
     if (player.BoltEntity.Controller != null)
     {
         PlayerSpeedRateChangedEvent speedChangeEvent = PlayerSpeedRateChangedEvent.Create(player.BoltEntity.Controller, ReliabilityModes.ReliableOrdered);
         speedChangeEvent.MoveType  = (int)moveType;
         speedChangeEvent.SpeedRate = rate;
         speedChangeEvent.Send();
     }
 }
Ejemplo n.º 2
0
    public void SetSpeedRate(UnitMoveType type, float rate)
    {
        if (rate < 0)
        {
            rate = 0.0f;
        }

        if (speedRates[type] == rate)
        {
            return;
        }

        speedRates[type] = rate;
    }
        public float BaseSpeedByType(UnitMoveType moveType)
        {
            switch (moveType)
            {
            case UnitMoveType.Walk:
                return(walkSpeed);

            case UnitMoveType.Run:
                return(runSpeed);

            case UnitMoveType.RunBack:
                return(runBackSpeed);

            default:
                throw new ArgumentOutOfRangeException(nameof(moveType), moveType, "Unknown movement type!");
            }
        }
Ejemplo n.º 4
0
        public override void MovementInform(MovementGeneratorType movementType, uint pointId)
        {
            if (movementType == MovementGeneratorType.Waypoint && pointId == 2)
            {
                me.SetSheath(SheathState.Melee);
                me.RemoveAllAuras();

                Player owner = me.GetCharmerOrOwner().ToPlayer();
                if (owner)
                {
                    owner.RemoveAura(SpellIds.EyeFlightBoost);
                    for (UnitMoveType i = 0; i < UnitMoveType.Max; ++i)
                    {
                        me.SetSpeedRate(i, owner.GetSpeedRate(i));
                    }

                    Talk(TextIds.TalkControl, owner);
                }
                me.SetDisableGravity(false);
                DoCast(me, SpellIds.EyeFlight);
            }

            if (movementType == MovementGeneratorType.Point && pointId == 1)
            {
                me.SetDisableGravity(true);
                me.SetControlled(true, UnitState.Root);
                _scheduler.Schedule(System.TimeSpan.FromSeconds(5), task =>
                {
                    DoCast(me, SpellIds.EyeFlightBoost);

                    me.SetControlled(false, UnitState.Root);

                    Player owner = me.GetCharmerOrOwner().ToPlayer();
                    if (owner)
                    {
                        for (UnitMoveType i = 0; i < UnitMoveType.Max; ++i)
                        {
                            me.SetSpeedRate(i, owner.GetSpeedRate(i));
                        }
                        Talk(TextIds.TalkMoveStart, owner);
                    }
                    me.GetMotionMaster().MovePath(me.GetEntry() * 100, false);
                });
            }
        }
Ejemplo n.º 5
0
        public void SetMinion(Minion minion, bool apply)
        {
            Log.outDebug(LogFilter.Unit, "SetMinion {0} for {1}, apply {2}", minion.GetEntry(), GetEntry(), apply);

            if (apply)
            {
                if (!minion.GetOwnerGUID().IsEmpty())
                {
                    Log.outFatal(LogFilter.Unit, "SetMinion: Minion {0} is not the minion of owner {1}", minion.GetEntry(), GetEntry());
                    return;
                }

                minion.SetOwnerGUID(GetGUID());

                m_Controlled.Add(minion);

                if (IsTypeId(TypeId.Player))
                {
                    minion.m_ControlledByPlayer = true;
                    minion.SetFlag(UnitFields.Flags, UnitFlags.PvpAttackable);
                }

                // Can only have one pet. If a new one is summoned, dismiss the old one.
                if (minion.IsGuardianPet())
                {
                    Guardian oldPet = GetGuardianPet();
                    if (oldPet)
                    {
                        if (oldPet != minion && (oldPet.IsPet() || minion.IsPet() || oldPet.GetEntry() != minion.GetEntry()))
                        {
                            // remove existing minion pet
                            if (oldPet.IsPet())
                            {
                                ((Pet)oldPet).Remove(PetSaveMode.AsCurrent);
                            }
                            else
                            {
                                oldPet.UnSummon();
                            }
                            SetPetGUID(minion.GetGUID());
                            SetMinionGUID(ObjectGuid.Empty);
                        }
                    }
                    else
                    {
                        SetPetGUID(minion.GetGUID());
                        SetMinionGUID(ObjectGuid.Empty);
                    }
                }

                if (minion.HasUnitTypeMask(UnitTypeMask.Guardian))
                {
                    AddGuidValue(UnitFields.Summon, minion.GetGUID());
                }

                if (minion.m_Properties != null && minion.m_Properties.Type == SummonType.Minipet)
                {
                    SetCritterGUID(minion.GetGUID());
                    if (GetTypeId() == TypeId.Player)
                    {
                        minion.SetGuidValue(UnitFields.BattlePetCompanionGuid, GetGuidValue(PlayerFields.SummonedBattlePetId));
                    }
                }

                // PvP, FFAPvP
                minion.SetByteValue(UnitFields.Bytes2, UnitBytes2Offsets.PvpFlag, GetByteValue(UnitFields.Bytes2, UnitBytes2Offsets.PvpFlag));

                // FIXME: hack, speed must be set only at follow
                if (IsTypeId(TypeId.Player) && minion.IsPet())
                {
                    for (UnitMoveType i = 0; i < UnitMoveType.Max; ++i)
                    {
                        minion.SetSpeedRate(i, m_speed_rate[(int)i]);
                    }
                }

                // Send infinity cooldown - client does that automatically but after relog cooldown needs to be set again
                SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(minion.GetUInt32Value(UnitFields.CreatedBySpell));
                if (spellInfo != null && spellInfo.IsCooldownStartedOnEvent())
                {
                    GetSpellHistory().StartCooldown(spellInfo, 0, null, true);
                }
            }
            else
            {
                if (minion.GetOwnerGUID() != GetGUID())
                {
                    Log.outFatal(LogFilter.Unit, "SetMinion: Minion {0} is not the minion of owner {1}", minion.GetEntry(), GetEntry());
                    return;
                }

                m_Controlled.Remove(minion);

                if (minion.m_Properties != null && minion.m_Properties.Type == SummonType.Minipet)
                {
                    if (GetCritterGUID() == minion.GetGUID())
                    {
                        SetCritterGUID(ObjectGuid.Empty);
                    }
                }

                if (minion.IsGuardianPet())
                {
                    if (GetPetGUID() == minion.GetGUID())
                    {
                        SetPetGUID(ObjectGuid.Empty);
                    }
                }
                else if (minion.IsTotem())
                {
                    // All summoned by totem minions must disappear when it is removed.
                    SpellInfo spInfo = Global.SpellMgr.GetSpellInfo(minion.ToTotem().GetSpell());
                    if (spInfo != null)
                    {
                        foreach (SpellEffectInfo effect in spInfo.GetEffectsForDifficulty(Difficulty.None))
                        {
                            if (effect == null || effect.Effect != SpellEffectName.Summon)
                            {
                                continue;
                            }

                            RemoveAllMinionsByEntry((uint)effect.MiscValue);
                        }
                    }
                }

                SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(minion.GetUInt32Value(UnitFields.CreatedBySpell));
                // Remove infinity cooldown
                if (spellInfo != null && spellInfo.IsCooldownStartedOnEvent())
                {
                    GetSpellHistory().SendCooldownEvent(spellInfo);
                }

                if (RemoveGuidValue(UnitFields.Summon, minion.GetGUID()))
                {
                    // Check if there is another minion
                    foreach (var unit in m_Controlled)
                    {
                        // do not use this check, creature do not have charm guid
                        if (GetGUID() == unit.GetCharmerGUID())
                        {
                            continue;
                        }

                        Contract.Assert(unit.GetOwnerGUID() == GetGUID());
                        if (unit.GetOwnerGUID() != GetGUID())
                        {
                            Contract.Assert(false);
                        }
                        Contract.Assert(unit.IsTypeId(TypeId.Unit));

                        if (!unit.HasUnitTypeMask(UnitTypeMask.Guardian))
                        {
                            continue;
                        }

                        if (AddGuidValue(UnitFields.Summon, unit.GetGUID()))
                        {
                            // show another pet bar if there is no charm bar
                            if (IsTypeId(TypeId.Player) && GetCharmGUID().IsEmpty())
                            {
                                if (unit.IsPet())
                                {
                                    ToPlayer().PetSpellInitialize();
                                }
                                else
                                {
                                    ToPlayer().CharmSpellInitialize();
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void SetMinion(Minion minion, bool apply)
        {
            Log.outDebug(LogFilter.Unit, "SetMinion {0} for {1}, apply {2}", minion.GetEntry(), GetEntry(), apply);

            if (apply)
            {
                if (!minion.GetOwnerGUID().IsEmpty())
                {
                    Log.outFatal(LogFilter.Unit, "SetMinion: Minion {0} is not the minion of owner {1}", minion.GetEntry(), GetEntry());
                    return;
                }

                minion.SetOwnerGUID(GetGUID());

                if (!m_Controlled.Contains(minion))
                {
                    m_Controlled.Add(minion);
                }

                if (IsTypeId(TypeId.Player))
                {
                    minion.m_ControlledByPlayer = true;
                    minion.AddUnitFlag(UnitFlags.PlayerControlled);
                }

                // Can only have one pet. If a new one is summoned, dismiss the old one.
                if (minion.IsGuardianPet())
                {
                    Guardian oldPet = GetGuardianPet();
                    if (oldPet)
                    {
                        if (oldPet != minion && (oldPet.IsPet() || minion.IsPet() || oldPet.GetEntry() != minion.GetEntry()))
                        {
                            // remove existing minion pet
                            if (oldPet.IsPet())
                            {
                                ((Pet)oldPet).Remove(PetSaveMode.AsCurrent);
                            }
                            else
                            {
                                oldPet.UnSummon();
                            }
                            SetPetGUID(minion.GetGUID());
                            SetMinionGUID(ObjectGuid.Empty);
                        }
                    }
                    else
                    {
                        SetPetGUID(minion.GetGUID());
                        SetMinionGUID(ObjectGuid.Empty);
                    }
                }

                if (minion.HasUnitTypeMask(UnitTypeMask.Guardian))
                {
                    if (GetMinionGUID().IsEmpty())
                    {
                        SetMinionGUID(minion.GetGUID());
                    }
                }

                var properties = minion.m_Properties;
                if (properties != null && properties.Title == SummonTitle.Companion)
                {
                    SetCritterGUID(minion.GetGUID());
                    Player thisPlayer = ToPlayer();
                    if (thisPlayer != null)
                    {
                        if (properties.GetFlags().HasFlag(SummonPropertiesFlags.SummonFromBattlePetJournal))
                        {
                            var pet = thisPlayer.GetSession().GetBattlePetMgr().GetPet(thisPlayer.GetSummonedBattlePetGUID());
                            if (pet != null)
                            {
                                minion.SetBattlePetCompanionGUID(thisPlayer.GetSummonedBattlePetGUID());
                                minion.SetBattlePetCompanionNameTimestamp((uint)pet.NameTimestamp);
                                minion.SetWildBattlePetLevel(pet.PacketInfo.Level);

                                uint display = pet.PacketInfo.DisplayID;
                                if (display != 0)
                                {
                                    minion.SetDisplayId(display);
                                    minion.SetNativeDisplayId(display);
                                }
                            }
                        }
                    }
                }

                // PvP, FFAPvP
                minion.SetPvpFlags(GetPvpFlags());

                // FIXME: hack, speed must be set only at follow
                if (IsTypeId(TypeId.Player) && minion.IsPet())
                {
                    for (UnitMoveType i = 0; i < UnitMoveType.Max; ++i)
                    {
                        minion.SetSpeedRate(i, m_speed_rate[(int)i]);
                    }
                }

                // Send infinity cooldown - client does that automatically but after relog cooldown needs to be set again
                SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(minion.m_unitData.CreatedBySpell, GetMap().GetDifficultyID());
                if (spellInfo != null && spellInfo.IsCooldownStartedOnEvent())
                {
                    GetSpellHistory().StartCooldown(spellInfo, 0, null, true);
                }
            }
            else
            {
                if (minion.GetOwnerGUID() != GetGUID())
                {
                    Log.outFatal(LogFilter.Unit, "SetMinion: Minion {0} is not the minion of owner {1}", minion.GetEntry(), GetEntry());
                    return;
                }

                m_Controlled.Remove(minion);

                if (minion.m_Properties != null && minion.m_Properties.Title == SummonTitle.Companion)
                {
                    if (GetCritterGUID() == minion.GetGUID())
                    {
                        SetCritterGUID(ObjectGuid.Empty);
                    }
                }

                if (minion.IsGuardianPet())
                {
                    if (GetPetGUID() == minion.GetGUID())
                    {
                        SetPetGUID(ObjectGuid.Empty);
                    }
                }
                else if (minion.IsTotem())
                {
                    // All summoned by totem minions must disappear when it is removed.
                    SpellInfo spInfo = Global.SpellMgr.GetSpellInfo(minion.ToTotem().GetSpell(), GetMap().GetDifficultyID());
                    if (spInfo != null)
                    {
                        foreach (var spellEffectInfo in spInfo.GetEffects())
                        {
                            if (spellEffectInfo == null || !spellEffectInfo.IsEffect(SpellEffectName.Summon))
                            {
                                continue;
                            }

                            RemoveAllMinionsByEntry((uint)spellEffectInfo.MiscValue);
                        }
                    }
                }

                SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(minion.m_unitData.CreatedBySpell, GetMap().GetDifficultyID());
                // Remove infinity cooldown
                if (spellInfo != null && spellInfo.IsCooldownStartedOnEvent())
                {
                    GetSpellHistory().SendCooldownEvent(spellInfo);
                }

                if (GetMinionGUID() == minion.GetGUID())
                {
                    SetMinionGUID(ObjectGuid.Empty);
                    // Check if there is another minion
                    foreach (var unit in m_Controlled)
                    {
                        // do not use this check, creature do not have charm guid
                        if (GetGUID() == unit.GetCharmerGUID())
                        {
                            continue;
                        }

                        Cypher.Assert(unit.GetOwnerGUID() == GetGUID());
                        if (unit.GetOwnerGUID() != GetGUID())
                        {
                            Cypher.Assert(false);
                        }
                        Cypher.Assert(unit.IsTypeId(TypeId.Unit));

                        if (!unit.HasUnitTypeMask(UnitTypeMask.Guardian))
                        {
                            continue;
                        }

                        SetMinionGUID(unit.GetGUID());
                        // show another pet bar if there is no charm bar
                        if (GetTypeId() == TypeId.Player && GetCharmedGUID().IsEmpty())
                        {
                            if (unit.IsPet())
                            {
                                ToPlayer().PetSpellInitialize();
                            }
                            else
                            {
                                ToPlayer().CharmSpellInitialize();
                            }
                        }
                        break;
                    }
                }
            }

            UpdatePetCombatState();
        }
Ejemplo n.º 7
0
 public void SetSpeed(UnitMoveType speednr, float speed)
 {
     _speed[(byte)speednr] = speed;
 }
Ejemplo n.º 8
0
 public void SetSpeed(UnitMoveType type, float newValue)
 {
     SetSpeedRate(type, newValue / StatHelper.BaseMovementSpeed(type));
 }
Ejemplo n.º 9
0
 public float GetSpeedRate(UnitMoveType type)
 {
     return(speedRates[type]);
 }
Ejemplo n.º 10
0
 public float GetSpeed(UnitMoveType type)
 {
     return(speedRates[type] * StatHelper.BaseMovementSpeed(type));
 }
Ejemplo n.º 11
0
    public void UpdateSpeed(UnitMoveType type)
    {
        int   main_speed_mod  = 0;
        float stack_bonus     = 1.0f;
        float non_stack_bonus = 1.0f;

        switch (type)
        {
        // only apply debuffs
        case UnitMoveType.RunBack:
            break;

        case UnitMoveType.Run:
            main_speed_mod   = /*GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED)*/ 0;
            stack_bonus      = /*GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS)*/ 0;
            non_stack_bonus += /*GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK) / 100.0f*/ 0;
            break;

        default:
            Debug.LogErrorFormat("Character::UpdateSpeed: Unsupported move type - {0}", type);
            return;
        }

        // now we ready for speed calculation
        float speed = Mathf.Max(non_stack_bonus, stack_bonus);

        if (main_speed_mod != 0)
        {
            speed *= main_speed_mod;
        }

        switch (type)
        {
        case UnitMoveType.Run:
            // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need #TODO
            int normalization /* = GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED)*/ = 0;
            if (normalization > 0)
            {
                // Use speed from aura
                float max_speed = normalization / StatHelper.BaseMovementSpeed(type);
                if (speed > max_speed)
                {
                    speed = max_speed;
                }
            }

            // force minimum speed rate @ aura 437 SPELL_AURA_MOD_MINIMUM_SPEED_RATE
            int minSpeedModRate = /*GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MINIMUM_SPEED_RATE)*/ 0;
            if (minSpeedModRate != 0)
            {
                float minSpeed = minSpeedModRate / StatHelper.BaseMovementSpeed(type);
                if (speed < minSpeed)
                {
                    speed = minSpeed;
                }
            }
            break;

        default:
            break;
        }

        // Apply strongest slow aura mod to speed
        int slow = /*GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED)*/ 0;

        if (slow != 0)
        {
            speed *= slow;
        }

        float minSpeedMod = (float)/*GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MINIMUM_SPEED)*/ 0;

        if (minSpeedMod > 0)
        {
            float min_speed = minSpeedMod / 100.0f;
            if (speed < min_speed)
            {
                speed = min_speed;
            }
        }

        SetSpeedRate(type, speed);
    }
Ejemplo n.º 12
0
 public static float BaseMovementSpeed(UnitMoveType moveType)
 {
     return(baseMoveSpeed[moveType]);
 }