public HarvestAction(AIAgent agent, IHarvestable harvestable) : base(agent) { Name = "Harvesting"; _harvestable = harvestable; BaseUtility = 5; }
public override void Interact() { if (!PlayerManager.instance.isAlive) { return; } base.Interact(); SoundManager.instance.PlaySound("SwordSwing", 0.25f); // Get colliders Collider2D[] hits = Physics2D.OverlapCircleAll(PlayerManager.instance.interactArea.position, attackRange, swordMask); // Damage trees foreach (Collider2D hit in hits) { IHarvestable harvestable = hit.gameObject.GetComponent <IHarvestable>(); if (harvestable != null) { harvestable.TakeDamage(dmgAmount); } break; } }
private void Attack() { Debug.Log(name + " Attacked"); // Get colliders Collider2D[] hits = Physics2D.OverlapCircleAll(attackArea.position, attackRange, attackMask); // Damage houses/player foreach (Collider2D hit in hits) { IHarvestable harvestable = hit.gameObject.GetComponent <IHarvestable>(); if (harvestable != null) { harvestable.TakeDamage(dmgAmount); } else { // Check if a player is attacked IDamageable damageable = hit.gameObject.GetComponent <IDamageable>(); if (damageable != null) { damageable.TakeDamage(dmgAmount); } } } }
public override InteractResult OnActLeft(InteractionContext context) { if (context.HasBlock) { if (context.Block is PlantBlock) { var plant = EcoSim.PlantSim.GetPlant(context.BlockPosition.Value); if (plant != null && plant is IHarvestable) { IHarvestable harvestable = (IHarvestable)plant; if (plant.Dead) { EcoSim.PlantSim.DestroyPlant(plant, DeathType.Harvesting); return(InteractResult.Success); } else { Result result = harvestable.TryHarvest(context.Player, false); if (result.Success) { this.BurnCalories(context.Player); } return((InteractResult)result); } } else { return((InteractResult)this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, false)); } } else if (context.Block.Is <Diggable>()) { if (TreeEntity.TreeRootsBlockDigging(context)) { return(InteractResult.FailureLocStr("You attempt to dig up the soil, but the roots are too strong!")); } Result result = this.PlayerDeleteBlock(context.BlockPosition.Value, context.Player, true, 1, new DirtItem()); if (result.Success) { var plant = EcoSim.PlantSim.GetPlant(context.BlockPosition.Value + Vector3i.Up); if (plant != null) { EcoSim.PlantSim.DestroyPlant(plant, DeathType.Harvesting); } } return((InteractResult)result); } else { return(InteractResult.NoOp); } } else { return(InteractResult.NoOp); } }
public override bool Test(IActor a, GameObject target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback) { if (!base.Test(a, target, isAutonomous, ref greyedOutTooltipCallback)) { return(false); } IHarvestable plant = target as IHarvestable; if (plant == null) { return(false); } if (!plant.IsSeed) { return(false); } PlantableComponent component = target.GetComponent <PlantableComponent>(); if (component == null) { return(false); } return(component.PlayerKnowledgeOfPlantableType == PlayerDisclosure.Concealed); }
public void BeginHarvest(IHarvestable harvestable) { currentHarvestable = harvestable; if (Harvesting) { harvestableUpdated = true; return; } StartCoroutine(Harvest()); }
void StartHarvest(IHarvestable harvestable) { if (!_harvesting && harvestable != null) { // Turn off movement if we need to stay for harvest if (harvestable.StayToHarvest()) { _behaviour.canMove = false; } _harvesting = true; harvestable.Harvest(CollectHarvest); } }
public void HarvestPlant() { ISoil soil = new Soil(); IPlant plant = new IdentifiedSeed("Carrot", PlantType.Vegetable); plant.Plant(soil); plant = plant.Grow(); // Seedling plant = plant.Grow(); // Vegetative plant = plant.Grow(); // Flowering plant = plant.Grow(); // Harvestable IHarvestable product = plant.Harvest(); Assert.Equal(typeof(Vegetable), product.GetType()); }
public Quality GetQuality(IGameObject obj) { Ingredient ingredient = obj as Ingredient; if (ingredient != null) { return(ingredient.GetQuality()); } else { ICraft craft = obj as ICraft; if (craft != null) { return(craft.GetQuality()); } else { IFoodContainer food = obj as IFoodContainer; if (food != null) { return(food.FoodQuality); } else { IHarvestable harvestable = obj as IHarvestable; if (harvestable != null) { return(harvestable.GetQuality()); } else { return(Quality.Neutral); } } } } }
public HarvestCommand(IHarvestable objectToHarvest) { _objectToHarvest = objectToHarvest; (_objectToHarvest as IDestroyable).OnDestroyed += OnObjectDestroyedOutside; }
protected void OnObjectDestroyedOutside(object source, EventArgs e) { (source as IDestroyable).OnDestroyed -= OnObjectDestroyedOutside; _objectToHarvest = null; Finish(false); }
public void Add(IHarvestable harvestable) { _harvestables.Add(harvestable); }
private static void Harvest(IHarvestable harvestable) { harvestable.Harvest(); }
public Building(IHarvestable ID) { _harvestable = ID; }
public override IEnumerator Execute() { List<IResource> resources = null; MoveToAction goTo; if (_harvestable == null) { //trying get from visible actors var harvestables = _agent.GetItems<IHarvestable>(h=>h.CanHarvest); //trying get from memory if (harvestables == null) { var harvestablesInMemory = _agent.GetItemsFromMemory(typeof (IHarvestable)); if (harvestablesInMemory.Count != 0) { harvestablesInMemory.SortActorsByDisntace(_agent.Character.Position); var info = harvestablesInMemory.FirstOrDefault(); if (info == null) { Debug.Log("there are no harvestables in memory"); Cancel(); yield break; } goTo = new MoveToAction(_agent, info.Position); yield return _agent.StartCoroutine(goTo.Execute()); yield return new WaitForSeconds(1f); harvestables = _agent.GetItems<IHarvestable>(h => h.CanHarvest); } } harvestables.SortActorsByDisntace(_agent.Character.Position); if (harvestables != null) _harvestable = harvestables.FirstOrDefault(); } if (_harvestable == null) { Debug.Log("Nearby there are no harvestables"); Cancel(); yield break; } //if we are to far away from target if ((_harvestable.Position - _agent.Character.Position).magnitude > 1) { goTo = new MoveToAction(_agent, _harvestable.Position); yield return _agent.StartCoroutine(goTo.Execute()); } //get reference to ienumerator to be able to stop coroutine _harvesting = _harvestable.Harvest((result)=> resources = result); //run character visulization of harvesting _agent.Character.Harvest(_harvestable); yield return _agent.StartCoroutine(_harvesting); if (resources == null || resources.Count == 0) { Debug.Log("Harvesting failed"); Finished(false); } //collect harvest basket var makeBasket = new CollectHarvestBasketAction(_agent, resources); yield return _agent.StartCoroutine(makeBasket.Execute()); Finished(true); }
public void Harvest(IHarvestable harvestable) { print("Harvesting the " +harvestable.Name); }