Exemple #1
0
        private BattleFleet GetEnemiesFleetsById(string enemy)
        {
            var fleets = new BattleFleet(FleetType.Enemy)
            {
                Name      = this.GetEnemyNameFromId(enemy),
                Rank      = this.GetEnemyEncounterRankFromId(enemy),
                Formation = this.GetEnemyFormationFromId(enemy)
            };

            fleets.Update(this.GetEnemiesFromId(enemy).Select(f => new FleetData(f)).ToArray());

            return(fleets);
        }
Exemple #2
0
        private async Task HandleBattle(MovingFleetData movingFleet, PlanetData attackerPlanet, PlanetData defenderPlanet)
        {
            if (attackerPlanet.OwnerId == null)
            {
                throw new InvalidOperationException($"Attacker planet {attackerPlanet.Name} is neutral.");
            }
            var attacker                = new BattleFleet(movingFleet.Fleet.Ships, attackerPlanet.Power);
            var defender                = new BattleFleet(defenderPlanet.Ships, defenderPlanet.Power);
            var battleOutcome           = _battleStrategy.Calculate(attacker, defender);
            var previousDefenderOwnerId = defenderPlanet.OwnerId;
            var attackerStats           = _state.PlayerStates[attackerPlanet.OwnerId.Value].Statistics;

            attackerStats.ShipsDestroyed += defender.Ships - battleOutcome.DefenderShips;
            attackerStats.ShipsLost      += attacker.Ships - battleOutcome.AttackerShips;
            if (battleOutcome.AttackerShips > 0)
            {
                attackerStats.BattlesWon += 1;
                defenderPlanet.OwnerId    = movingFleet.OwnerUserId;
                defenderPlanet.Ships      = battleOutcome.AttackerShips;
            }
            else
            {
                attackerStats.BattlesLost += 1;
                defenderPlanet.Ships       = battleOutcome.DefenderShips;
            }
            var attackOutcome = battleOutcome.AttackerShips > 0 ? AttackOutcome.Win : AttackOutcome.Defeat;
            var attackEnded   = new AttackHappened(
                _state.RoomId,
                attackerUserId: movingFleet.OwnerUserId,
                defenderUserId: previousDefenderOwnerId,
                planetName: defenderPlanet.Name,
                outcome: attackOutcome);

            if (previousDefenderOwnerId != null)
            {
                var defenderStats = _state.PlayerStates[previousDefenderOwnerId.Value].Statistics;
                defenderStats.ShipsDestroyed += attacker.Ships - battleOutcome.AttackerShips;
                defenderStats.ShipsLost      += defender.Ships - battleOutcome.DefenderShips;
                if (attackOutcome == AttackOutcome.Win)
                {
                    defenderStats.BattlesLost += 1;
                }
                else
                {
                    defenderStats.BattlesWon += 1;
                }
            }
            await NotifyEverybody(attackEnded);
        }
 public BattleFleetViewModel(BattleFleet fleets, string defaultName)
 {
     this._fleet        = fleets;
     this._defaultName  = defaultName;
     this._combinedName = fleets.Type == FleetType.Friend ? "連合艦隊" : "敵連合艦隊";
 }
        private BattleFleet GetEnemiesFleetsById(string enemy)
        {
            var fleets = new BattleFleet(FleetType.Enemy)
            {
                Name = this.GetEnemyNameFromId(enemy),
                Rank = this.GetEnemyEncounterRankFromId(enemy),
                Formation = this.GetEnemyFormationFromId(enemy)
            };

            fleets.Update(this.GetEnemiesFromId(enemy).Select(f => new FleetData(f)).ToArray());

            return fleets;
        }
Exemple #5
0
        public void FirstBattleTest()
        {
            WeaponModel xLaser = new WeaponModel()
            {
                ID          = "xLaser",
                Name        = "Taim & Bak KX9 laser cannon",
                Damage      = 10,
                Accuracy    = 1,
                Capacity    = 0,
                ReloadTimer = 1
            };
            WeaponModel tLaser = new WeaponModel()
            {
                ID          = "tLaser",
                Name        = "L-s1 laser cannon",
                Damage      = 10,
                Accuracy    = 1,
                Capacity    = 0,
                ReloadTimer = 1
            };
            WeaponModel torpedo = new WeaponModel()
            {
                ID          = "torpedo",
                Name        = "Krupx MG7 proton torpedo launcher",
                Damage      = 10,
                Accuracy    = 1,
                Capacity    = 3,
                ReloadTimer = 10
            };

            ShipModel xWingModel = new ShipModel()
            {
                ID               = "xwing",
                Name             = "T-65 X-Wing Starfighter",
                Class            = ShipClass.Fighter,
                OffensiveWeapons = new List <WeaponModel>()
                {
                    xLaser, xLaser, xLaser, xLaser, torpedo, torpedo
                },
                Shields      = 100,
                HullStrength = 100
            };
            ShipModel tieModel = new ShipModel()
            {
                ID               = "tie",
                Name             = "TIE/LN Starfighter",
                Class            = ShipClass.Fighter,
                OffensiveWeapons = new List <WeaponModel>()
                {
                    tLaser, tLaser
                },
                Shields      = 0,
                HullStrength = 100
            };

            Ship xWing = new Ship()
            {
                ID    = "xWing",
                Name  = "X-Wing",
                Model = xWingModel,
            };
            Ship tie = new Ship()
            {
                ID    = "tie",
                Name  = "TIE Fighter",
                Model = tieModel,
            };

            Fleet rebelFleet = new Fleet();

            rebelFleet.Ships.Add(xWing);
            Fleet impFleet = new Fleet();

            impFleet.Ships.Add(tie);

            BattleFleet rebels = new BattleFleet(rebelFleet);
            BattleFleet imps   = new BattleFleet(impFleet);

            rebels.Reset();
            rebels.Attack(imps);
        }