예제 #1
0
        public override void Attack(CreatureEntity aEnemy, bool onlyRemote)
        {
            try {
                NWCreature self  = (NWCreature)fSelf;
                NWCreature enemy = (NWCreature)aEnemy;

                int dist = MathHelper.Distance(self.Location, aEnemy.Location);

                bool shooting = false;
                int  highestDamage;
                Item weapon = null;

                if (self.Entry.Flags.Contains(CreatureFlags.esMind) && (self.Entry.Flags.Contains(CreatureFlags.esUseItems)))
                {
                    bool canShoot = self.CanShoot(enemy);

                    BestWeaponSigns bw = new BestWeaponSigns();
                    if (canShoot)
                    {
                        bw.Include(BestWeaponSigns.CanShoot);
                    }
                    if (onlyRemote)
                    {
                        bw.Include(BestWeaponSigns.OnlyShoot);
                    }

                    highestDamage = self.CheckEquipment((float)dist, bw);

                    weapon = self.GetItemByEquipmentKind(BodypartType.bp_RHand);
                    ItemFlags ifs = (weapon != null) ? weapon.Flags : new ItemFlags();

                    shooting = (canShoot && weapon != null && (ifs.HasIntersect(ItemFlags.if_ThrowWeapon, ItemFlags.if_ShootWeapon)));
                }
                else
                {
                    highestDamage = self.DamageBase;
                }

                int     skDamage      = 0;
                SkillID sk            = self.GetAttackSkill(dist, ref skDamage);
                bool    attackBySkill = (sk != SkillID.Sk_None && (skDamage > highestDamage || AuxUtils.Chance(15)));

                if (attackBySkill)
                {
                    EffectExt ext = new EffectExt();
                    ext.SetParam(EffectParams.ep_Creature, aEnemy);
                    self.UseSkill(sk, ext);
                }
                else
                {
                    if (shooting)
                    {
                        self.ShootTo(enemy, weapon);
                    }
                    else
                    {
                        if (!onlyRemote)
                        {
                            if (dist == 1)
                            {
                                self.AttackTo(AttackKind.Melee, enemy, null, null);
                            }
                            else
                            {
                                ExtPoint next = self.GetStep(aEnemy.Location);
                                if (!next.IsEmpty)
                                {
                                    StepTo(next.X, next.Y);
                                }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                Logger.Write("BeastBrain.attack(): " + ex.Message);
            }
        }