protected override bool InnerIsFulfilled() { Toy toy = tree.AttachedBrain.GetComponent <Toy>(); // If the toy does not have a resourcefield assigned then return failure if (toy.AssignedResourceField == null) { return(false); } // If the resourcefield is non existent anymore or the amount is 0 return failure if (!toy.AssignedResourceField || toy.AssignedResourceField.TotalRemaining <= 0) { toy.AssignedResourceField = null; return(false); } // if the values have been set inside the treeEditor then populate them with references if (resourceFieldValue != null) { resourceFieldValue.SetValue(toy.AssignedResourceField); } if (resourceTypeValue != null) { resourceTypeValue.SetValue(toy.AssignedResourceField.Type); } if (toolTypeValue != null) { toolTypeValue.SetValue(ResourceTypeForToolType.Instance.Get(toy.AssignedResourceField.Type)); } // lastly return success return(true); }
protected override bool InnerIsFulfilled() { Vector3 randomVec = new Vector3(Random.Range(from.x, to.x), Random.Range(from.y, to.y), Random.Range(from.z, to.z)); vector.SetValue(randomVec); return(true); }
private IEnumerator Gather(Resource resource, DynamicValue delayedTime) { if (resource.TryCollecting(ActiveTool != null ? ActiveTool.Tool : null)) { Animator.SetTrigger("hit"); yield return(new WaitForSeconds(0.1f)); float animationTime = MecanimUtil.GetActiveAnimationDuration(Animator, 0); yield return(new WaitForSeconds(animationTime * 0.8f)); Resource.GatheringDrop gatheringDrop = resource.Gather(out ResourceItem item); switch (gatheringDrop) { case Resource.GatheringDrop.SpawnInWorld: ItemInWorld.CreateItem(item, transform.position + transform.up * 1.8f); break; case Resource.GatheringDrop.DirectlyIntoInventory: if (Inventory.CapacityLeft < item.TotalWeight && Inventory.Add(item) == false) { goto case Resource.GatheringDrop.SpawnInWorld; } break; default: Debug.LogError("case " + gatheringDrop + " not found!"); break; } delayedTime.SetValue(new DelayedTime(true, animationTime * 0.2f + 1)); } else { Animator.SetTrigger("fail"); yield return(new WaitForSeconds(0.1f)); float animationTime = MecanimUtil.GetActiveAnimationDuration(Animator, 0) + 1; delayedTime.SetValue(new DelayedTime(true, animationTime)); } }
protected override bool InnerIsFulfilled() { ItemInWorld item = tree.AttachedBrain.GetComponent <Toy>().AssignedItemToPickUp; if (item == null) { return(false); } location.SetValue(item.transform.position); return(true); }
public DynamicValue Gather(Resource resource) { DynamicValue delayedTime = ScriptableObject.CreateInstance <DynamicValue>(); if (resource.CheckCollectionRequirements(this) == false) { delayedTime.SetValue(new DelayedTime(false, 0)); return(delayedTime); } StartCoroutine(Gather(resource, delayedTime)); return(delayedTime); }
//TODO: Consider replacing this with an mecanim event private IEnumerator Equip(ToolType toolType, DynamicValue delayedTime) { if (toolType == ToolType.None) // unequip tool { if (ActiveTool == null) { delayedTime.SetValue(new DelayedTime(true, 0)); yield break; } Animator.SetBool("equip", false); yield return(new WaitForSeconds(0.2f)); float timeToFinish = MecanimUtil.GetActiveAnimationDuration(Animator, 0); delayedTime.SetValue(new DelayedTime(true, timeToFinish)); // Get rid of active tool Destroy(ActiveTool.gameObject, timeToFinish * 0.3f); ActiveTool = null; yield return(new WaitForSeconds(timeToFinish)); Animator.runtimeAnimatorController = AnimatorDict.Instance.GetRuntimeAnimationController(toolType); yield break; } // Does the Toy already have a Tool equipped? if (ActiveTool != null) { // if it is the same then just return success if (ActiveTool.Tool.ToolType == toolType) { delayedTime.SetValue(new DelayedTime(true, 0)); yield break; } // If it is not the same, then unequip it first yield return(Equip(ToolType.None, ScriptableObject.CreateInstance <DynamicValue>())); } // equip tool Tool toEquip = Inventory.GetTool(toolType); if (toEquip == null) // tool not found { Animator.SetTrigger("toolWrong"); yield return(new WaitForSeconds(0.2f)); delayedTime.SetValue(new DelayedTime(false, MecanimUtil.GetActiveAnimationDuration(Animator, 0))); } else { // tool found Animator.runtimeAnimatorController = AnimatorDict.Instance.GetRuntimeAnimationController(toolType); yield return(null); float timeToFinish = MecanimUtil.GetActiveAnimationDuration(Animator, 0); delayedTime.SetValue(new DelayedTime(true, timeToFinish)); yield return(new WaitForSeconds(timeToFinish * 0.3f)); // Instantiate tool model ActiveTool = Instantiate(toEquip.ToolModel, ToolSocketR); ActiveTool.transform.localPosition = Vector3.zero; ActiveTool.transform.localRotation = Quaternion.identity; ActiveTool.Tool = toEquip; } }