public bool IsValidTactic(ushort tacticEntry)
        {
            AbilityConstants constInfo = AbilityMgr.GetAbilityInfo(tacticEntry).ConstantInfo;

            if (constInfo.MinimumRank > _unitOwner.AdjustedLevel)
            {
                return(false);
            }

            if (constInfo.MasteryTree == 0)
            {
                return(true);
            }

            int destTree = constInfo.MasteryTree - 1;

            for (int i = 0; i < MAX_TREE_ABILITIES; ++i)
            {
                if (_masteryAbilities[destTree, i] != null && _masteryAbilities[destTree, i].Entry == tacticEntry)
                {
                    return(_activeSkillsInTree[destTree, i] == 1);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public void AddAbilities(ushort minBound, ushort maxBound)
        {
            if (maxBound == 0)
            {
                AbilityInfo abInfo = AbilityMgr.GetAbilityInfo(minBound);
                if (abInfo != null && abInfo.ConstantInfo.MinimumRank <= Level)
                {
                    NPCAbility npcAbility = new NPCAbility(abInfo.Entry, abInfo.ConstantInfo.AIRange, (byte)abInfo.Cooldown, true, "");
                    AbtInterface.NPCAbilities.Add(npcAbility);
                    SendPetAbility(npcAbility);
                }
            }

            else
            {
                for (ushort i = minBound; i <= maxBound; ++i)
                {
                    AbilityInfo abInfo = AbilityMgr.GetAbilityInfo(i);
                    if (abInfo == null || abInfo.ConstantInfo.MinimumRank > Level)
                    {
                        continue;
                    }
                    NPCAbility npcAbility = new NPCAbility(abInfo.Entry, abInfo.ConstantInfo.AIRange, (byte)abInfo.Cooldown, true, "");
                    AbtInterface.NPCAbilities.Add(npcAbility);
                    SendPetAbility(npcAbility);
                }
            }
        }
        private void StartDelayedCast(object creature)
        {
            var Params = (List <object>)creature;

            Unit   _unit   = Params[0] as Unit;
            ushort Ability = (ushort)Params[1];

            // This is used by random ability cast
            if (_unit != null && !_unit.IsDead)
            {
                _unit.AbtInterface.StartCast(_unit, Ability, 1);

                if (!(_unit is Pet))
                {
                    _unit.MvtInterface.StopMove();
                    AbilityInfo AbiInfo = AbilityMgr.GetAbilityInfo(Ability);
                    if (!AbiInfo.CanCastWhileMoving)
                    {
                        _unit.EvtInterface.AddEvent(DelayedChase, AbiInfo.CastTime + 100, 1);
                    }
                    else
                    {
                        Chase(_unit.CbtInterface.GetCurrentTarget(), true);
                    }
                }
            }
        }
        public bool StartCastAtPos(Unit instigator, ushort abilityID, Point3D worldPos, ushort zoneId, byte castSequence)
        {
            if (PreventCasting)
            {
                if (_Owner is Player)
                {
                    Player owner = _Owner as Player;
                    owner?.SendClientMessage("A developer has disabled all abilities.", ChatLogFilters.CHATLOGFILTERS_USER_ERROR);
                }
                return(false);
            }

            // Allow only interruption of channeled skills of a different ID to the skill being used
            if (IsCasting() && (!_abilityProcessor.IsChannelling || _abilityProcessor.AbInfo.Entry == abilityID))
            {
                return(false);
            }

            AbilityInfo abInfo = AbilityMgr.GetAbilityInfo(abilityID);

            if (abInfo == null || (abInfo.ConstantInfo.Origin != AbilityOrigin.AO_ITEM && !IsValidAbility(abInfo)))
            {
                return(false);
            }
            try
            {
                if (AbilityMgr.HasCommandsFor(abilityID) || abInfo.ConstantInfo.ChannelID != 0)
                {
                    if (_abilityProcessor == null)
                    {
                        _abilityProcessor = new AbilityProcessor(_unitOwner, this);
                    }

                    abInfo.Instigator = instigator;

                    if (!_abilityProcessor.HasInfo())
                    {
                        _abilityProcessor.StartAbilityAtPos(abInfo, castSequence, worldPos, zoneId);
                    }
                    return(true);
                }
                if (_Owner is Player)
                {
                    var owner = _Owner as Player;
                    owner?.SendClientMessage(abilityID + " " + AbilityMgr.GetAbilityNameFor(abilityID) + " has no implementation.", ChatLogFilters.CHATLOGFILTERS_USER_ERROR);
                }
                return(false);
            }

            catch (Exception e)
            {
                if (_Owner is Player)
                {
                    var owner = _Owner as Player;
                    owner?.SendClientMessage(abilityID + " " + AbilityMgr.GetAbilityNameFor(abilityID) + " threw an unhandled " + e.GetType().Name + " from " + e.TargetSite + ".");
                }
                return(false);
            }
        }
        public void GrantAbility(ushort abilityEntry)
        {
            _abilities.Add(AbilityMgr.GetAbilityInfo(abilityEntry));
            _abilitySet.Add(abilityEntry);

            SendAbilityLevels();

            ResendCooldown(abilityEntry);
        }
        /// <summary>
        /// Sets and transmits the cooldown of the given ability.
        /// </summary>
        /// <param name="abilityId">Ifd of ability to reset</param>
        /// <param name="duration">Cooldown duration in milliseconds, -1 to reset</param>
        /// <param name="silent">False to transmit new value to client, true otherwise</param>
        public void SetCooldown(ushort abilityId, long duration, bool silent = false)
        {
            #if DEBUG && ABILITY_DEVELOPMENT
            duration = 0;
            #endif

            if (abilityId == ushort.MaxValue)
            {
                return;
            }
            AbilityInfo abInfo = AbilityMgr.GetAbilityInfo(abilityId);
            if (abInfo.IgnoreCooldownReduction == 1 && (abInfo.Cooldown * 1000) >= duration)
            {
                long nextTimestamp = 0;
                if (abInfo.CDcap != null && abInfo.CDcap * 1000 > duration)
                {
                    nextTimestamp = (abInfo.CDcap * 1000) + TCPManager.GetTimeStampMS();
                }

                else
                {
                    nextTimestamp = (abInfo.Cooldown * 1000) + TCPManager.GetTimeStampMS();
                }

                Cooldowns[abilityId] = nextTimestamp;

                if (silent)
                {
                    return;
                }

                PacketOut Out = new PacketOut((byte)Opcodes.F_SET_ABILITY_TIMER, 12);
                Out.WriteUInt16(abilityId);
                Out.Fill(0, 2);
                Out.WriteUInt32(((uint)abInfo.Cooldown * 1000));
                Out.Fill(0, 4);
                if (_Owner.IsPet())
                {
                    _Owner.GetPet().Owner.SendPacket(Out);
                }
                else
                {
                    _playerOwner?.SendPacket(Out);
                }
            }

            if (abInfo.IgnoreCooldownReduction != 1 || (abInfo.IgnoreCooldownReduction == 1 && (abInfo.Cooldown * 1000) < duration))
            {
                long nextTimestamp = 0;

                if (abInfo.CDcap != null && abInfo.CDcap * 1000 > duration)
                {
                    nextTimestamp = (abInfo.CDcap * 1000) + TCPManager.GetTimeStampMS();
                }

                else
                {
                    nextTimestamp = (duration) + TCPManager.GetTimeStampMS();
                }

                if (duration == -1 && abInfo.CDcap == null)
                {
                    nextTimestamp = 0;
                }
                Cooldowns[abilityId] = nextTimestamp;

                if (silent)
                {
                    return;
                }

                PacketOut Out = new PacketOut((byte)Opcodes.F_SET_ABILITY_TIMER, 12);
                Out.WriteUInt16(abilityId);
                Out.Fill(0, 2);
                Out.WriteUInt32(duration != -1 ? (uint)duration : 0);
                Out.Fill(0, 4);
                if (_Owner.IsPet())
                {
                    _Owner.GetPet().Owner.SendPacket(Out);
                }
                else
                {
                    _playerOwner?.SendPacket(Out);
                }
            }
        }
        public bool StartCast(Unit instigator, ushort abilityID, byte castSequence, byte cooldownGroup = 0, byte overrideAbilityLevel = 0, bool enemyVisible = true, bool friendlyVisible = true, bool moving = false)
        {
            if (PreventCasting)
            {
                if (_Owner is Player)
                {
                    (_Owner as Player)?.SendClientMessage("A developer has disabled all abilities.", ChatLogFilters.CHATLOGFILTERS_USER_ERROR);
                }
                return(false);
            }

            // Allow only interruption of channeled skills of a different ID to the skill being used
            if (IsCasting() && (!_abilityProcessor.IsChannelling || _abilityProcessor.AbInfo.Entry == abilityID))
            {
                return(false);
            }

            AbilityInfo abInfo = AbilityMgr.GetAbilityInfo(abilityID);

            if (abInfo == null || (abInfo.ConstantInfo.Origin != AbilityOrigin.AO_ITEM && !IsValidAbility(abInfo)))
            {
                return(false);
            }

            //Fix so that WE/WH cant use all their 3 openers at the same time, this is in conjunction with whats in AbilityProcessor
            if (_Owner is Player)
            {
                if ((_Owner as Player).StealthLevel == 0 && (abilityID == 9406 || abilityID == 9401 || abilityID == 9411 || abilityID == 8091 || abilityID == 8096 || abilityID == 8098))
                {
                    return(false);
                }
            }

            try
            {
                if (AbilityMgr.HasCommandsFor(abilityID) || abInfo.ConstantInfo.ChannelID != 0)
                {
                    if (_abilityProcessor == null)
                    {
                        _abilityProcessor = new AbilityProcessor(_unitOwner, this);
                    }

                    abInfo.Instigator = instigator;
                    abInfo.Level      = overrideAbilityLevel;

                    return(_abilityProcessor.StartAbility(abInfo, castSequence, cooldownGroup, enemyVisible, friendlyVisible, moving));
                }
                if (_Owner is Player)
                {
                    Player owner = _Owner as Player;
                    owner?.SendClientMessage(abilityID + " " + AbilityMgr.GetAbilityNameFor(abilityID) + " has no implementation.", ChatLogFilters.CHATLOGFILTERS_USER_ERROR);
                }
                return(false);
            }

            catch (Exception e)
            {
                if (_Owner is Player)
                {
                    (_Owner as Player)?.SendClientMessage(abilityID + " " + AbilityMgr.GetAbilityNameFor(abilityID) + " threw an unhandled " + e.GetType().Name + " from " + e.TargetSite + ".");
                }
                Log.Error("Ability System", e.ToString());
                return(false);
            }
        }