Ejemplo n.º 1
0
        public override void Read(PacketStream stream)
        {
            var skillId = stream.ReadUInt32();

            var skillCasterType = stream.ReadByte(); // кто применяет
            var skillCaster     = SkillCaster.GetByType((SkillCasterType)skillCasterType);

            skillCaster.Read(stream);

            var skillCastTargetType = stream.ReadByte(); // на кого применяют
            var skillCastTarget     = SkillCastTarget.GetByType((SkillCastTargetType)skillCastTargetType);

            skillCastTarget.Read(stream);

            var flag        = stream.ReadByte();
            var flagType    = flag & 15;
            var skillObject = SkillObject.GetByType((SkillObjectType)flagType);

            if (flagType > 0)
            {
                skillObject.Read(stream);
            }

            _log.Debug("StartSkill: Id {0}, flag {1}", skillId, flag);

            if (SkillManager.Instance.IsDefaultSkill(skillId) || SkillManager.Instance.IsCommonSkill(skillId))
            {
                var skill = new Skill(SkillManager.Instance.GetSkillTemplate(skillId)); // TODO переделать...
                skill.Use(Connection.ActiveChar, skillCaster, skillCastTarget, skillObject);
            }
            else if (skillCaster is SkillItem)
            {
                var item = Connection.ActiveChar.Inventory.GetItem(((SkillItem)skillCaster).ItemId);
                if (item == null || skillId != item.Template.UseSkillId)
                {
                    return;
                }
                Connection.ActiveChar.Quests.OnItemUse(item);
                var skill = new Skill(SkillManager.Instance.GetSkillTemplate(skillId));
                skill.Use(Connection.ActiveChar, skillCaster, skillCastTarget, skillObject);
            }
            else if (Connection.ActiveChar.Skills.Skills.ContainsKey(skillId))
            {
                var skill = Connection.ActiveChar.Skills.Skills[skillId];
                skill.Use(Connection.ActiveChar, skillCaster, skillCastTarget, skillObject);
            }
            else
            {
                _log.Warn("StartSkill: Id {0}, undefined use type", skillId);
            }
        }
Ejemplo n.º 2
0
        public override void Execute(Npc npc)
        {
            //先判断距离 / Judge the distance first
            bool  move   = false;
            float x      = npc.Position.X - npc.CurrentTarget.Position.X;
            float y      = npc.Position.Y - npc.CurrentTarget.Position.Y;
            float z      = npc.Position.Z - npc.CurrentTarget.Position.Z;
            float MaxXYZ = Math.Max(Math.Max(Math.Abs(x), Math.Abs(y)), Math.Abs(z));

            //如果最大值超过distance 则放弃攻击转而进行追踪 / If the maximum value exceeds distance, abandon the attack and track it
            if (MaxXYZ > distance)
            {
                var track = new Track();
                track.Pause(npc);
                track.LastPatrol = LastPatrol;
                LastPatrol       = track;
                Stop(npc);
            }
            else
            {
                LoopDelay = 3000;

                var skillId = 2u;

                var skillCasterType = SkillCasterType.Unit; // who applies / кто применяет
                var skillCaster     = SkillCaster.GetByType(skillCasterType);
                skillCaster.ObjId = npc.ObjId;

                var skillCastTargetType = 0; // on whom apply / на кого применяют
                var skillCastTarget     = SkillCastTarget.GetByType((SkillCastTargetType)skillCastTargetType);
                skillCastTarget.ObjId = npc.CurrentTarget.ObjId;

                var flag        = 0;
                var flagType    = flag & 15;
                var skillObject = SkillObject.GetByType((SkillObjectType)flagType);
                if (flagType > 0)
                {
                    skillObject.Flag = SkillObjectType.None;
                }

                var skill = new Skill(SkillManager.Instance.GetSkillTemplate(skillId)); // TODO переделать...
                skill.Use(npc, skillCaster, skillCastTarget, skillObject);

                LoopAuto(npc);
            }
        }