public bool Handle(DomainEventHandlerData <UpkeepCoinEvent> @event) { var snap = @event.Snapshot as GameAggregate; if (snap == null) { return(false); } var relateEvents = new List <EventBase>(); var userCastles = snap.Castles.Where(e => e.OwnerUserId == snap.UserId).ToList() ?? new List <CastleAggregate>(); foreach (var castle in userCastles) { var coins = _gameDomainService.CalculateUpkeepCoin(snap.Id, castle); snap.UserCoins -= coins; relateEvents.Add(new CastleUpkeepCointEvent(castle.Id, coins, snap.UserId, DateTime.UtcNow, DateTime.UtcNow)); //var createSoldier = _gameDomainService.GetCreateSoldierIfNeedCreate(snap, castle); //if (createSoldier != null) // relateEvents.Add(createSoldier); //var isCreated = _gameDomainService.CreateSoldierIfNeed(snap, castle); //if (!isCreated && castle.Army != Army.Neutrual && (castle.Army == Army.Blue || !snap.SelfPlaying)) //{ // var troopType = castle.GetDefaultTroopType(); // var needCoin = _gameDomainService.GetUpkeepCoinBySoldierType(castle, troopType); // coins = castle.Army == Army.Blue ? snap.UserCoins : snap.OpponentCoins; // if (needCoin > coins && castle.IsProductionState()) // { // relateEvents.Add(new SuspendCastleProductionEvent(castle.Id, castle.OwnerUserId)); // } //} } var opponentCastles = snap.Castles.Where(e => e.OwnerUserId == snap.OpponentId).ToList() ?? new List <CastleAggregate>(); foreach (var castle in opponentCastles) { var coins = _gameDomainService.CalculateUpkeepCoin(snap.Id, castle); snap.OpponentCoins -= coins; relateEvents.Add(new CastleUpkeepCointEvent(castle.Id, coins, snap.OpponentId, DateTime.UtcNow, DateTime.UtcNow)); //var createSoldier = _gameDomainService.GetCreateSoldierIfNeedCreate(snap, castle); //if (createSoldier != null) // relateEvents.Add(createSoldier); //var isCreated = _gameDomainService.CreateSoldierIfNeed(snap, castle); //if (!isCreated && castle.Army != Army.Neutrual && (castle.Army == Army.Blue || !snap.SelfPlaying)) //{ // var troopType = castle.GetDefaultTroopType(); // var needCoin = _gameDomainService.GetUpkeepCoinBySoldierType(castle, troopType); // coins = castle.Army == Army.Blue ? snap.UserCoins : snap.OpponentCoins; // if (needCoin > coins && castle.IsProductionState()) // { // relateEvents.Add(new SuspendCastleProductionEvent(castle.Id, castle.OwnerUserId)); // } //} } relateEvents.Add(_gameDomainService.UpkeepCoinEvent(snap.Speed)); _domainService.AddEvent(snap.Id, relateEvents.ToArray()); return(true); }