Exemple #1
0
        public UInt16Array ChooseAttackPosition(Critter npc, Critter target, AttackChoice attackChoice)
        {
            var weapon = npc.GetItemById (attackChoice.WeaponId);
            if (weapon == null)
                return null;

            var weaponDistance = weapon.Proto.WeaponMaxDist (attackChoice.WeaponUse);
            var distance = Global.GetDistance (npc, target);

            if (weaponDistance < distance) {
                var direction = Global.GetDirection (npc, target);
                var hexX = npc.HexX;
                var hexY = npc.HexY;

                do {
                    npc.GetMap ().MoveHexByDir (ref hexX, ref hexY, direction, 1);
                } while(!npc.GetMap ().IsHexPassed (hexX, hexY));

                var result = new UInt16Array ();
                result.Add (hexX);
                result.Add (hexY);
                result.Add ((ushort)direction);
                return result;
            }

            return null;
        }
Exemple #2
0
        private long AttackTarget(Critter npc, Critter target, AttackChoice attackChoice)
        {
            if (npc.Stat [Stats.CurrentAP] <= 0) {
                npc.Wait (500);
                return 0;
            }

            var distance = Global.GetDistance (npc, target);
            if (distance > 1) {
                var tracedDistance = shootTracer.TraceDistance (npc.GetMap (), npc.HexX, npc.HexY, target.HexX, target.HexY, distance);
                if (tracedDistance != distance)
                    //cannot shoot through objects
                    return 0;
            }

            var currentWeapon = npc.GetItemHand ();
            if (currentWeapon.Id != attackChoice.WeaponId) {
                var map = npc.GetMap ();
                var moveItemApCost = map != null && map.IsTurnBased () ? Global.TbApCostDropItem : Global.RtApCostDropItem;

                npc.Stat [Stats.CurrentAP] -= (int)moveItemApCost * 100;
                npc.MoveItem (attackChoice.WeaponId, 1, ItemSlot.Hand1);
                currentWeapon = npc.GetItemById (attackChoice.WeaponId);
            }
            if (currentWeapon == null)
                return 0;

            if (distance > currentWeapon.Proto.Weapon_MaxDist_0) {
                return 0;
            }

            var weaponAttackApCost = currentWeapon.Proto.Weapon_ApCost_0;
            npc.Stat [Stats.CurrentAP] -= (int)weaponAttackApCost * 100;

            dynamic mainModule = ScriptEngine.GetModule ("main");
            mainModule.critter_attack (npc, target, currentWeapon.Proto, attackChoice.WeaponUse, Global.GetProtoItem (currentWeapon.Proto.Weapon_DefaultAmmoPid));
            return Global.Breaktime;
        }
Exemple #3
0
        public AttackChoice ChooseAttack(Critter npc, Critter target)
        {
            var attackChoice = new AttackChoice ();
            var currentItem = npc.GetItemHand ();
            Item weaponItem = null;

            if (currentItem != null) {
                if (CanBeMyWeapon (npc, currentItem)) {
                    weaponItem = currentItem;
                }
            } else {
                weaponItem = null;
            }

            if (weaponItem == null) {
                return null;
            }
            attackChoice.WeaponId = weaponItem.Id;
            attackChoice.WeaponUse = 0;
            attackChoice.HitLocation = HitLocation.Uncalled;

            return attackChoice;
        }