예제 #1
0
        public bool AddOnExists(ShipAddOn addOn)
        {
            if (addOn != null)
            {
                return(ShipAddOns.Values.Find(x => x == addOn) != null);
            }

            return(false);
        }
예제 #2
0
        private void FindTarget()
        {
            Ship  target = null;
            float currentRangeToTargetSquared = float.MaxValue;

            bool useEnemies = ParentShip.ShipType == ShipType.AlliedShip;

            foreach (Ship ship in useEnemies ? UnderSiegeGameplayScreen.Enemies.Values.AsEnumerable <Ship>() : UnderSiegeGameplayScreen.Allies.Values.AsEnumerable <Ship>())
            {
                float distanceToTargetSquared = Vector2.Subtract(WorldPosition, ship.WorldPosition).LengthSquared();
                // Add buffer amount of 50 to stop rapid target changing
                if (distanceToTargetSquared <= ShipTurretData.Range * ShipTurretData.Range && distanceToTargetSquared + 50 <= currentRangeToTargetSquared)
                {
                    // We have a new target
                    target = ship;
                    currentRangeToTargetSquared = distanceToTargetSquared;
                }
            }

            Target = target;

            // Target the closest add ons now
            if (target != null)
            {
                ShipAddOn targetAddOn = null;
                currentRangeToTargetSquared = float.MaxValue;

                foreach (ShipAddOn shipAddOn in target.ShipAddOns.Values)
                {
                    float distanceToTargetSquared = Vector2.Subtract(WorldPosition, shipAddOn.WorldPosition).LengthSquared();
                    // Add buffer amount of 50 to stop rapid target changing
                    if (distanceToTargetSquared <= ShipTurretData.Range * ShipTurretData.Range && distanceToTargetSquared + 50 <= currentRangeToTargetSquared)
                    {
                        // We have a new target
                        targetAddOn = shipAddOn;
                        currentRangeToTargetSquared = distanceToTargetSquared;
                    }
                }

                if (targetAddOn != null)
                {
                    Target = targetAddOn;
                }
            }
        }