Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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."));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }