public bool Handle(DomainEventHandlerData <DeleteSoldierEvent> data) { CastleAggregate snapshot = data.Snapshot as CastleAggregate; if (snapshot != null) { Debug.WriteLine("Soldier deleted!"); --snapshot.SoldiersAmount; List <SoldierAggregate> soldiers = snapshot.Soldiers; SoldierAggregate soldierAggregate1; if (soldiers == null) { soldierAggregate1 = null; } else { Func <SoldierAggregate, bool> predicate = e => e.Id == data.EventObject.SoldierId; soldierAggregate1 = soldiers.FirstOrDefault <SoldierAggregate>(predicate); } SoldierAggregate soldierAggregate2 = soldierAggregate1; if (soldierAggregate2 != null) { soldierAggregate2.IsDead = true; } } return(true); }
private List <SoldierModel> GetSoldiersOfCastle(CastleAggregate castle) { var availableSoldiers = castle.GetAvailableSoldiers(); var soldiers = availableSoldiers != null?Mapper.Map <List <SoldierModel> >(availableSoldiers) : new List <SoldierModel>(); foreach (var soldier in soldiers) { //soldier.UpkeepCoins = _gameDomainService.GetUpkeepCoinBySoldierType(castle, soldier.CastleTroopType.ResourceType); } return(soldiers); }
public double CalculateUpkeepCoin(Guid id, CastleAggregate castle) { return(0); //double coins = 0; //var soldiers = castle.GetAvailableSoldiers() ?? new List<SoldierAggregate>(); //foreach (var soldier in soldiers) //{ // coins += GetUpkeepCoinBySoldierType(castle, soldier.CastleTroopType.ResourceType); //} //return coins; }
public void AddSiegeEvent(GameAggregate game, CastleAggregate destinationCastle, List <SoldierAggregate> soldiers) { if (destinationCastle.Siege == null) { return; } var battleAt = GetBattleTime(game.Speed); _domain.AddEvent(game.Id, new SiegeCastleEvent(destinationCastle.Siege.OwnerUserId, destinationCastle.Id, soldiers, DateTime.UtcNow, battleAt)); }
public void AddSiegeEvent(GameAggregate game, CastleAggregate castle, CastleAggregate destinationCastle, List <SoldierAggregate> soldiers) { var battleAt = GetBattleTime(game.Speed); destinationCastle.Siege = new SiegeAggregate { Id = Guid.NewGuid(), OwnerUserId = castle.OwnerUserId, Soldiers = soldiers, BattleAt = battleAt, SiegeAt = DateTime.UtcNow }; // create siege event AddSiegeEvent(game, destinationCastle, soldiers); }
public BattleLogAggregate AttackSequence(Guid id, CastleAggregate atCastle, string attackingId, string defendingId, List <SoldierAggregate> attacking, List <SoldierAggregate> defending, int attackingBooststrength = 0, int defendingBooststrength = 0) { int dIndex = 0, aIndex = 0; var battle = new BattleLogAggregate { Id = id, // clone object Attacking = attacking.Select(e => new SoldierAggregate() { Id = e.Id, IsDead = e.IsDead, CastleTroopType = e.CastleTroopType == null ? null : new CastleTroopType() { AttackStrength = e.CastleTroopType.AttackStrength, Health = e.CastleTroopType.Health, MovementSpeed = e.CastleTroopType.MovementSpeed, ProductionSpeed = e.CastleTroopType.ProductionSpeed, ResourceType = e.CastleTroopType.ResourceType, Icon = e.CastleTroopType.Icon, RedArmyIcon = e.CastleTroopType.RedArmyIcon, BlueArmyIcon = e.CastleTroopType.BlueArmyIcon } }).ToList(), Defending = defending.Select(e => new SoldierAggregate() { Id = e.Id, IsDead = e.IsDead, CastleTroopType = e.CastleTroopType == null ? null : new CastleTroopType() { AttackStrength = e.CastleTroopType.AttackStrength, Health = e.CastleTroopType.Health, MovementSpeed = e.CastleTroopType.MovementSpeed, ProductionSpeed = e.CastleTroopType.ProductionSpeed, ResourceType = e.CastleTroopType.ResourceType, Icon = e.CastleTroopType.Icon, RedArmyIcon = e.CastleTroopType.RedArmyIcon, BlueArmyIcon = e.CastleTroopType.BlueArmyIcon } }).ToList(), Logs = new List <BattleAttackingLogAggregate>() }; while (dIndex < defending.Count && aIndex < attacking.Count) { // defending attack attacking var hit = R.NextDouble(); var wallStrength = attacking[aIndex].CastleTroopType.IsOverComeWalls ? 0 : atCastle.Strength; attacking[aIndex].CastleTroopType.Health -= Math.Round(hit * defending[dIndex].CastleTroopType.AttackStrength + defendingBooststrength + wallStrength, MidpointRounding.AwayFromZero); battle.Logs.Add(new BattleAttackingLogAggregate() { OwnerUserId = defendingId, AttackingSoldierId = defending[dIndex].Id, DefendingSoldierId = attacking[aIndex].Id, Hit = hit, Booststrength = defendingBooststrength, WallStrength = wallStrength }); if (attacking[aIndex].CastleTroopType.Health <= 0) { aIndex++; } if (aIndex >= attacking.Count) { break; } // attacking attack defending hit = R.NextDouble(); defending[dIndex].CastleTroopType.Health -= Math.Round(hit * attacking[aIndex].CastleTroopType.AttackStrength + attackingBooststrength, MidpointRounding.AwayFromZero); battle.Logs.Add(new BattleAttackingLogAggregate() { OwnerUserId = attackingId, AttackingSoldierId = attacking[aIndex].Id, DefendingSoldierId = defending[dIndex].Id, Hit = hit, Booststrength = attackingBooststrength }); if (defending[dIndex].CastleTroopType.Health <= 0) { dIndex++; } } return(battle); }
public double CalculateCoin(GameAggregate game, CastleAggregate castle) { var revenueCoins = _gameSettings.RevenueCoins * GameSpeedHelper.GetSpeedValue(game.Speed); return(revenueCoins); }