示例#1
0
    public SpaceUnit GetRandomEnemyTarget()
    {
        ShipManager enemyManager = GetRandomEnemyShipManager();

        if (enemyManager != null)
        {
            SpaceUnit target = enemyManager.GetRandomShip();
            if (target != null)
            {
                return(target);
            }
            target = enemyManager.GetRandomStation();
            if (target != null)
            {
                return(target);
            }
            target = enemyManager.GetRandomFighter();
            if (target != null)
            {
                return(target);
            }
            return(null);
        }
        return(null);
    }
示例#2
0
        public static Matrix <SpaceUnit> GetRectFillInvalid(this Matrix <SpaceUnit> mat, Region region)
        {
            var t = new Matrix <SpaceUnit>(region.Height, region.Width);

            var r = 0;
            var c = 0;

            for (var i = region.Top; i < region.Bottom; i++, r++, c = 0)
            {
                for (var j = region.Left; j < region.Right; j++, c++)
                {
                    if (i >= 0 && i < mat.Columns &&
                        j >= 0 && j < mat.Rows)
                    {
                        t[r, c] = mat[i, j];
                    }
                    else
                    {
                        t[r, c] = new SpaceUnit
                        {
                            Position = new Point(-1, -1)
                        }
                    }
                }
            }
            ;

            return(t);
        }
示例#3
0
 public void SetParentForAttachedWeapons(SpaceUnit parentUnit)
 {
     foreach (AttachedWeapon weapon in Weapons)
     {
         weapon.SetParent(parentUnit);
     }
 }
示例#4
0
    void DealDamage(SpaceUnit target, float damage)
    {
        Vector3 Position;

        if (hitEffect != null)
        {
            Position = hitEffect.transform.position;
        }
        else
        {
            Position = target.transform.position;
        }

        if (target is Ship)
        {
            (target as Ship).TakeDamage(attachedWeapon, Position, transform.position, damage, ignoreShields, ignoreArmor, ignoreArmorRating);
        }
        else if (target is Station)
        {
            (target as Station).TakeDamage(attachedWeapon, Position, transform.position, damage, ignoreShields, ignoreArmor, ignoreArmorRating);
        }
        else if (target is Fighter)
        {
            (target as Fighter).TakeDamage(attachedWeapon, damage, ignoreShields, ignoreArmor, ignoreArmorRating);
        }
    }
示例#5
0
    public void SetTargetForAllShips(SpaceUnit target)
    {
        bool enemy = isEnemy(target);

        foreach (Ship ship in Ships)
        {
            if (!ship.isDestroyed() && ship != target)
            {
                ship.SetNewTarget(target, enemy);
            }
        }
        foreach (FighterWing fighterWing in FighterWings)
        {
            if (!fighterWing.OwnsUnit(target as Fighter))
            {
                fighterWing.SetNewTarget(target, enemy);
            }
        }
        if (enemy)
        {
            foreach (Station station in Stations)
            {
                if (!station.isDestroyed() && station != target)
                {
                    station.SetNewTarget(target, enemy);
                }
            }
        }
    }
示例#6
0
 public void RemoveFromSelection(SpaceUnit unit)
 {
     if (unit is Ship)
     {
         SelectedShips.Remove(unit as Ship);
         RemoveShipFromSelectionGroups(unit as Ship);
         foreach (ShipManager manager in EnemyShipManagers)
         {
             if (manager.UnOwnedSelectedShip == unit)
             {
                 manager.UnOwnedSelectedShip = null;
             }
         }
     }
     else if (unit is Station)
     {
         SelectedStations.Remove(unit as Station);
         RemoveStationFromSelectionGroups(unit as Station);
         foreach (ShipManager manager in EnemyShipManagers)
         {
             if (manager.UnOwnedSelectedStation == unit)
             {
                 manager.UnOwnedSelectedStation = null;
             }
         }
     }
 }
示例#7
0
    public void SetTargetForSelectedShips(SpaceUnit target)
    {
        bool enemy = isEnemy(target);

        foreach (Ship ship in SelectedShips)
        {
            if (ship != target)
            {
                ship.SetNewTarget(target, enemy);
            }
        }
        foreach (FighterWing fighterWing in SelectedFighterWings)
        {
            if (!fighterWing.OwnsUnit(target as Fighter))
            {
                fighterWing.SetNewTarget(target, enemy);
            }
        }
        if (enemy)
        {
            foreach (Station station in SelectedStations)
            {
                if (station != target)
                {
                    station.SetNewTarget(target, enemy);
                }
            }
        }
    }
示例#8
0
 void ParentAttachedWeapons(SpaceUnit parentUnit)
 {
     ForeSection.SetParentForAttachedWeapons(parentUnit);
     AftSection.SetParentForAttachedWeapons(parentUnit);
     PortSection.SetParentForAttachedWeapons(parentUnit);
     StarboardSection.SetParentForAttachedWeapons(parentUnit);
     CenterSection.SetParentForAttachedWeapons(parentUnit);
 }
示例#9
0
 public void SetNewTarget(SpaceUnit target, bool isEnemy)
 {
     targetUnit = target;
     foreach (Fighter unit in Fighters)
     {
         unit.SetNewTarget(target, isEnemy);
     }
 }
示例#10
0
 public void SetNewGoalPosition(Vector3 Position)
 {
     targetUnit = null;
     foreach (Fighter unit in Fighters)
     {
         unit.SetNewGoalPosition(Position);
     }
     ResourceManager.CreateClickPing(Position);
 }
示例#11
0
        private void save_Click(object sender, EventArgs e)
        {
            SpaceUnit sp = new SpaceUnit();

            sp.Name       = txtName.Text;
            sp.BuildingId = _buildingId;
            da.AddSpaceUnit(sp);

            this.Close();
        }
示例#12
0
 public override void GetKill(SpaceUnit killedUnit)
 {
     if (killedUnit is Ship)
     {
         stationData.GetKill((killedUnit as Ship).GetShipData());
     }
     else if (killedUnit is Station)
     {
         stationData.GetKill((killedUnit as Station).stationData);
     }
 }
示例#13
0
 public bool isEnemy(SpaceUnit target)
 {
     if (shipManager != null)
     {
         return(shipManager.isEnemy(target));
     }
     else
     {
         return(false);
     }
 }
示例#14
0
 public void CaptureUnit(SpaceUnit unit)
 {
     if (unit is Ship)
     {
         CaptureShip(unit as Ship);
     }
     else if (unit is Station)
     {
         CaptureStation(unit as Station);
     }
 }
示例#15
0
 public bool isEnemy(SpaceUnit target)
 {
     if (target == null)
     {
         return(false);
     }
     if (GetShipManager() != null)
     {
         return(GetShipManager().isEnemy(target));
     }
     return(false);
 }
示例#16
0
 public void TurnOn(float time, Color color, SpaceUnit target)
 {
     gameObject.SetActive(true);
     timer                   = time;
     Color                   = color;
     Target                  = target;
     objectTarget            = true;
     lineRenderer.startColor = Color;
     lineRenderer.endColor   = Color;
     lineRenderer.SetPosition(0, transform.position);
     lineRenderer.SetPosition(1, transform.position);
 }
示例#17
0
    public bool isEnemy(SpaceUnit target)
    {
        ShipManager targetManager = target.GetShipManager();

        if (EnemyShipManagers.Contains(targetManager))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
 override public void Fire(SpaceUnit target) {
     if (fireTimer <= 0) {
         Vector3 dir = (target.position - transform.position).normalized;
         GameObject beamObj = new GameObject();
         LaserBeam beam = beamObj.AddComponent<LaserBeam>();
         beam.team = unit.team;
         beam.origin = transform.position;
         beam.direction = dir;
         beam.range = range;
         beam.speed = projectileSpeed;
         fireTimer += 1 / fireRate;
     }
 }
示例#19
0
 public void AddSpaceUnit(SpaceUnit unit)
 {
     if (unit is Ship)
     {
         AddShip(unit as Ship);
     }
     else if (unit is Station)
     {
         AddStation(unit as Station);
     }
     else if (unit is Fighter)
     {
         AddFighter(unit as Fighter);
     }
 }
示例#20
0
 public override void GetKill(SpaceUnit killedUnit)
 {
     if (killedUnit is Fighter)
     {
         shipData.AddExperience((killedUnit as Fighter).GetKillExperience());
     }
     else
     {
         if (killedUnit is Ship)
         {
             shipData.GetKill((killedUnit as Ship).GetShipData());
         }
         else if (killedUnit is Station)
         {
             shipData.GetKill((killedUnit as Station).stationData);
         }
     }
 }
示例#21
0
 public void RemoveUnit(SpaceUnit unit)
 {
     if (unit is Ship)
     {
         SelectedShips.Remove(unit as Ship);
         Ships.Remove(unit as Ship);
         RemoveShipFromSelectionGroups(unit as Ship);
     }
     else if (unit is Station)
     {
         SelectedStations.Remove(unit as Station);
         Stations.Remove(unit as Station);
         RemoveStationFromSelectionGroups(unit as Station);
     }
     else if (unit is Fighter)
     {
         Fighters.Remove(unit as Fighter);
     }
 }
示例#22
0
 public virtual void SetNewTarget(SpaceUnit target, bool Enemy)
 {
     if (target != null)
     {
         Target        = target;
         TargetIsEnemy = Enemy;
         if (shipOrderLine != null)
         {
             if (Enemy)
             {
                 shipOrderLine.TurnOn(1.0f, ResourceManager.gameConstants.Highlight_Enemy.GetColor(), target);
             }
             else
             {
                 shipOrderLine.TurnOn(1.0f, ResourceManager.gameConstants.Highlight_Player.GetColor(), target);
             }
         }
     }
 }
示例#23
0
 public void ReplaceTarget(SpaceUnit oldTarget, SpaceUnit newTarget)
 {
     foreach (Ship ship in Ships)
     {
         if (ship.isDestroyed())
         {
             continue;
         }
         if (ship.GetTarget() == oldTarget)
         {
             ship.SetNewTarget(newTarget, true);
         }
     }
     foreach (FighterWing fighterWing in FighterWings)
     {
         if (fighterWing.GetUnitCount() > 0 && fighterWing.GetFirstFighter().GetTarget() == oldTarget)
         {
             fighterWing.SetNewTarget(newTarget, true);
         }
     }
 }
示例#24
0
 public void Update()
 {
     if (AIControl && EnemyShipManagers.Count > 0)
     {
         if (AI_Timer > 0)
         {
             AI_Timer -= Time.deltaTime;
         }
         else
         {
             AI_Timer = 1f;
             if (enemyTarget == null)
             {
                 enemyTarget = GetRandomEnemyTarget();
                 if (enemyTarget != null)
                 {
                     SetTargetForAllShips(enemyTarget);
                 }
             }
             else if (enemyTarget != null)
             {
                 if (enemyTarget.isDestroyed())
                 {
                     enemyTarget = null;
                 }
                 else if (enemyTarget is Ship)
                 {
                     if ((enemyTarget as Ship).IsCloaked())
                     {
                         enemyTarget = null;
                     }
                 }
             }
         }
     }
 }
示例#25
0
 virtual public void Fire(SpaceUnit target) {
     // Nothing
 }
示例#26
0
        public DiskSpaceHealthCheck(long treshold = 100000000, SpaceUnit unit = SpaceUnit.Byte)
        {
            _defaultTreshold = treshold * (long)unit;

            _data.Add(REQUIRED_SPACE, _defaultTreshold);
        }
    private void PassiveAttackUpdate() {
        if (target != null && ((target.position - position).magnitude > enemyCheckRange || false)) {
            target = null;
        }

        if ((position - standPoint).magnitude > standReturnRange) {
            MoveOrder(standPoint, defaultWayPointRange);
        }

        if (enemyCheckTimer > 0) {
            enemyCheckTimer -= U.limitedDeltaTime;
        } else if (state == UnitState.IDLE || state == UnitState.MOVING) {
            if (target == null) {
                SpaceUnit enemy = EnemyCheck();
                if (enemy != null) {
                    target = enemy;
                    foreach (Weapon weapon in weapons) {
                        weapon.Attack(target);
                    }
                }
            }

            if (target != null && state == UnitState.IDLE && (target.position - position).magnitude > startChaseRange) {
                wayPoints = new Queue<Vector3>();
                Vector3 chasePos = target.position + (position - target.position).normalized * chaseRange;
                wayPoints.Enqueue(chasePos);
                wayPointRange = defaultWayPointRange;
            }            
            enemyCheckTimer += enemyCheckInterval;
        }

        if (target != null && state == UnitState.IDLE && ((target.position - position).magnitude > enemyCheckRange || (position - standPoint).magnitude > returnRange || false)) {
            MoveOrder(standPoint, defaultWayPointRange);
        }
    }
 override public void Attack(SpaceUnit target) {
     firing = true;
     this.target = target;
 }
示例#29
0
 virtual public void Attack(SpaceUnit target) {
     // Nothing
 }
示例#30
0
 public UnitWingsParentComponent(SpaceUnit parentUnit, UnitData parentUnitData)
 {
     Parent     = parentUnit;
     ParentData = parentUnitData;
 }
示例#31
0
 public void SetParent(SpaceUnit parent)
 {
     parentUnit = parent;
 }
示例#32
0
 public void GetKill(SpaceUnit target)
 {
     parentUnit.GetKill(target);
 }
示例#33
0
 public TargetInfo(SpaceUnit target, Vector2 direction, float rangeSqr)
 {
     Target    = target;
     Direction = direction;
     RangeSqr  = rangeSqr;
 }
示例#34
0
 public virtual void GetKill(SpaceUnit killedUnit)
 {
 }
示例#35
0
 public virtual void CancelOrders()
 {
     Target = null;
 }