public ActionResults Build(EmptyLand emptyLand, Player player) { if (emptyLand.OwnerId != player.Id) { return(ActionResults.Failed("You do not own this building.")); } // Check for materials var results = ActionResults.Empty; foreach (var buildMaterial in this.BuildMaterials) { var playerItem = player.Inventory.Items.FirstOrDefault(item => item.ItemType.GetType() == buildMaterial.ItemType.GetType()); if (playerItem == null || playerItem.Quantity < buildMaterial.Quantity) { results.AddResult(ActionResult.Failed($"You need {buildMaterial.Quantity} {buildMaterial.ItemType.Name} to build a farm.")); } } if (results.HasResults) { return(results); } DomainEvents.Raise(new FarmBuiltEvent(player, this)); return(ActionResults.Success("You built a farm. Time to start planting.")); }
public ActionResults Work(Player player) { if (!player.IsAlive) { return(ActionResults.Failed("You're dead.")); } if (this.Inventory?.Items?.FirstOrDefault()?.Quantity == 0) { return(ActionResults.Failed("All the mature trees are gone. Wait for them to grow.")); } if (player.Energy < this.EnergyRequirement) { return(ActionResults.Failed("You don't have enough energy to work in the forest.")); } var workResults = ActionResults.Success("You gather some wood in the forest."); player.ReduceEnergy(this.EnergyRequirement); player.EarnMoney(this.Wage); player.Inventory.AddItem(1, new BasicBuildingMaterial()); ReduceTreeCount(); CheckForInjury(player, workResults); DomainEvents.Raise(new PlayerWorkedEvent(player, this)); DomainEvents.Raise(new ForestWorkedEvent(this)); return(workResults); }
public IActionResult Post([FromBody] BuildFarmPostModel model) { var player = ObjectFactory.Container.GetInstance <GetPlayerService>().GetByUserId(User.Identity.GetId()); var building = ObjectFactory.Container.GetInstance <GetBuildingService>().GetBuildingByTownIdBuildingId(player.CurrentTown, model.BuildingId); var results = ActionResults.Empty; if (building is EmptyLand) { var farm = new Farm( building.Id, building.TownId, building.XCoordinate, building.YCoordinate, player.DisplayName + "'s Farm", ((EmptyLand)building).OwnerId, ((EmptyLand)building).IsForSale, ((EmptyLand)building).Price, ((EmptyLand)building).ModifiedDate, ((EmptyLand)building).CreatedDate); results = farm.Build((EmptyLand)building, player); } else { results = ActionResults.Failed("You can only build new buildings on empty land."); } return(Ok(results)); }
public ActionResults Purchase(Player purchasingPlayer) { if (!this.IsForSale) { return(ActionResults.Failed("This land is not for sale.")); } if (purchasingPlayer.CurrentTown != this.TownId) { return(ActionResults.Failed("You must be in the same town as the land to purchase it.")); } if (purchasingPlayer.MoneyOnHand < this.Price) { return(ActionResults.Failed("You do not have enough money to purchase this land.")); } var results = ActionResults.Success($"You've puchased the empty land for ${this.Price}. Time to start building!"); DomainEvents.Raise <BuildingPurchasedEvent>(new BuildingPurchasedEvent(this, purchasingPlayer)); return(results); }
public ActionResults Work(Player player) { if (!player.IsAlive) { return(ActionResults.Failed("You're dead.")); } if (player.Energy < this.EnergyRequirement) { return(ActionResults.Failed("You don't have enough energy to work in the mines.")); } var workResults = ActionResults.Success($"You earn ${this.Wage} working in the mines."); player.ReduceEnergy(this.EnergyRequirement); player.EarnMoney(this.Wage); player.ReduceHappiness(this.HappinessEffect); CheckForInjury(player, workResults); DomainEvents.Raise <PlayerWorkedEvent>(new PlayerWorkedEvent(player, this)); return(workResults); }