public void Handle(FarmBuiltEvent domainEvent) { foreach (var buildMaterial in domainEvent.Farm.BuildMaterials) { domainEvent.Player.Inventory.RemoveItems(buildMaterial.Quantity, buildMaterial.ItemType); } _playerRepository.Update(domainEvent.Player); _townBuildingRepository.Update(domainEvent.Farm); }
public void Execute() { var random = new Random(); IEnumerable <Forest> forests = _townBuildingRepository.GetByBuildingType <Forest>(typeof(Forest)); foreach (var forest in forests) { var roll = random.Next(1, 100); // 20% chance of new growth in the forest if (roll <= 20) { forest.IncreaseTreeCount(1); _townBuildingRepository.Update(forest); } } }
public void Handle(BuildingPurchasedEvent domainEvent) { // The building has now owner, so it is being sold by the town if (String.IsNullOrEmpty(domainEvent.Building.OwnerId)) { var town = _townRepository.Get(domainEvent.Building.TownId); town.IncreaseAccountBalance((int)domainEvent.Building.Price); _townRepository.Update(town); } // The building has an owner who should be paid for the sale else { var previousOwner = _playerRepository.Get(domainEvent.Building.OwnerId); previousOwner.EarnMoney((int)domainEvent.Building.Price); _playerRepository.UpdateStats(previousOwner); } domainEvent.PurchasingPlayer.SpendMoney((int)domainEvent.Building.Price); domainEvent.Building.ChangeOwnership(domainEvent.PurchasingPlayer.Id); _playerRepository.UpdateStats(domainEvent.PurchasingPlayer); _townBuildingRepository.Update(domainEvent.Building); }
public void Handle(ForestWorkedEvent domainEvent) { _townBuildingRepository.Update(domainEvent.Forest); }