コード例 #1
0
        private void SendChannelEnd()
        {
            PacketOut Out = new PacketOut((byte)Opcodes.F_USE_ABILITY, 20);

            Out.WriteUInt16(0);
            Out.WriteUInt16(_channelInfo.Entry);
            Out.WriteUInt16(_host.Oid);
            Out.WriteUInt16(_channelInfo.ConstantInfo.EffectID);

            if (_target != null && !(_target is GroundTarget))
            {
                Out.WriteUInt16(_target.Oid);
            }
            else if (_channelInfo?.Range == 0)
            {
                Out.WriteUInt16(_host.Oid);
            }
            else
            {
                Out.WriteUInt16(0);
            }

            Out.WriteByte(4); // channel end
            Out.WriteByte(0);
            Out.WriteUInt16(0);
            Out.WriteUInt16(_target != null ? (ushort)(_host.GetDistanceToObject(_target, true) * 12) : (ushort)0);
            Out.WriteByte(_castSequence);
            Out.WriteUInt16(0);
            Out.WriteByte(0);
            _host.DispatchPacket(Out, true);

            Out = new PacketOut((byte)Opcodes.F_CAST_PLAYER_EFFECT, 200);
            Out.WriteUInt16(_host.Oid);
            Out.WriteUInt16(_host.Oid);
            Out.WriteUInt16(_baseEntry);
            Out.WriteByte((byte)_channelInfo.ConstantInfo.EffectID);
            Out.WriteByte((byte)0); //parried, crit, dodged, etc
            Out.WriteByte((byte)0);
            Out.WriteByte((byte)0);
            _host.DispatchPacket(Out, true);
        }
コード例 #2
0
        protected void TryUseAbilities()
        {
            if (_unit.AbtInterface.NPCAbilities == null)
            {
                return;
            }

            if (Combat.IsFighting && Combat.CurrentTarget != null && _unit.AbtInterface.CanCastCooldown(0) && TCPManager.GetTimeStampMS() > _nextTryCastTime)
            {
                long curTimeMs = TCPManager.GetTimeStampMS();

                float rangeFactor = _unit.StsInterface.GetStatPercentageModifier(Stats.Range);

                uint AllowPercentAbilityCycle = 0;

                if (CurTarget != null)
                {
                    var prm = new List <object>()
                    {
                        CurTarget
                    };
                    _unit.EvtInterface.AddEvent(SetOldTarget, 2000, 1, prm);
                    CurTarget = null;
                }

                foreach (NPCAbility ability in _unit.AbtInterface.NPCAbilities)
                {
                    // If ability is set to Active = 0 it will not be played
                    if (ability.Active == 0)
                    {
                        continue;
                    }

                    // If target is below MinRange that is set in creature_abilities we don't want to run this particular skill
                    if (ability.MinRange != 0 && _unit.GetDistanceToObject(_unit.CbtInterface.GetCurrentTarget()) < ability.MinRange)
                    {
                        continue;
                    }

                    // This disable Shockwave (punt) for Keep Lords that are inside room
                    if (ability.Entry == 13528 && _unit.GetDistanceToWorldPoint(_unit.WorldSpawnPoint) < 49)
                    {
                        continue;
                    }

                    if (ability.DisableAtHealthPercent != 0)
                    {
                        if (_unit.Health + 1 < (_unit.TotalHealth * ability.DisableAtHealthPercent) / 100)
                        {
                            continue;
                        }
                    }

                    if (ability.ActivateAtHealthPercent != 0)
                    {
                        // This checks if we can add new ability to ability cycle
                        if (ability.AbilityCycle == 1 && _unit.Health < (_unit.TotalHealth * ability.ActivateAtHealthPercent) / 100)
                        {
                            AllowPercentAbilityCycle = 1;
                        }

                        // This checks if we can reset the ability if NPC healed - if it's still on cooldwon, we do not refresh it
                        if (ability.AbilityCycle == 0 && ability.AbilityUsed == 1 && (_unit.Health > (_unit.TotalHealth * ability.ActivateAtHealthPercent) / 100) && _oneshotPercentCast < curTimeMs)
                        {
                            ability.AbilityUsed = 0;
                        }

                        // This will play ability after NPC is wounded below X %
                        if (ability.AbilityCycle == 0 && ability.AbilityUsed == 0 && (_unit.Health < (_unit.TotalHealth * ability.ActivateAtHealthPercent) / 100) && _oneshotPercentCast < curTimeMs)
                        {
                            // This set random target if needed
                            if (ability.RandomTarget == 1)
                            {
                                SetRandomTarget();
                            }

                            // This list of parameters is passed to the function that delays the cast by 1000 ms
                            var prms = new List <object>()
                            {
                                _unit, ability.Entry, ability.RandomTarget
                            };

                            if (ability.Text != "")
                            {
                                _unit.Say(ability.Text.Replace("<character name>", _unit.CbtInterface.GetCurrentTarget().Name));
                            }
                            _unit.EvtInterface.AddEvent(StartDelayedCast, 1000, 1, prms);
                            _oneshotPercentCast = TCPManager.GetTimeStampMS() + ability.Cooldown * 1000;
                            ability.AbilityUsed = 1;
                            continue;
                        }
                    }

                    if (ability.AutoUse && !_unit.AbtInterface.IsCasting() && ability.CooldownEnd < curTimeMs && _unit.AbtInterface.CanCastCooldown(ability.Entry) && curTimeMs > _combatStart + ability.TimeStart * 1000)
                    {
                        uint ExtraRange = 0;
                        if (Combat != null && Combat.CurrentTarget != null && Combat.CurrentTarget.IsMoving)
                        {
                            ExtraRange = 5;
                        }


                        if ((ability.Range == 0 || _unit.IsInCastRange(Combat.CurrentTarget, Math.Max(5 + ExtraRange, (uint)(ability.Range * rangeFactor)))))
                        {
                            if (ability.ActivateAtHealthPercent == 0 || AllowPercentAbilityCycle == 1)
                            {
                                if (!_unit.LOSHit(Combat.CurrentTarget))
                                {
                                    _nextTryCastTime = TCPManager.GetTimeStampMS() + 1000;
                                }
                                else
                                {
                                    // This set random target if needed
                                    if (ability.RandomTarget == 1)
                                    {
                                        SetRandomTarget();
                                    }

                                    // This list of parameters is passed to the function that delays the cast by 1000 ms
                                    var prms = new List <object>()
                                    {
                                        _unit, ability.Entry, ability.RandomTarget
                                    };

                                    if (ability.Text != "")
                                    {
                                        _unit.Say(ability.Text.Replace("<character name>", _unit.CbtInterface.GetCurrentTarget().Name), ChatLogFilters.CHATLOGFILTERS_MONSTER_SAY);
                                    }
                                    _unit.EvtInterface.AddEvent(StartDelayedCast, 1000, 1, prms);

                                    //_unit.AbtInterface.StartCast(_unit, ability.Entry, 1);
                                    ability.CooldownEnd = curTimeMs + ability.Cooldown * 1000;
                                }

                                break;
                            }
                        }
                        else
                        {
                            //AbilityInfo abInfo = AbilityMgr.GetAbilityInfo(abilityID);
                            Chase(_unit.CbtInterface.GetCurrentTarget(), true, true, ability.Range);
                        }
                    }
                }
            }
        }