public bool AddResource(ResourcesBag resourcesBag, string resourceName, float value = 1f) { if (resourcesBag.GetResource(resourceName) >= value) { resourcesBag.RemoveResource(resourceName, value); bankBag.AddResource(resourceName, value); return(true); } else { return(false); } }
protected void Update() { if (resource == null || resource.GetCapacity() < ResourcePerAction) { failCallback(this); return; } if (Time.time > gatherCooldown) { gatherCooldown = float.MaxValue; resource.RemoveResource(ResourcePerAction); resourcesBag.AddResource(resource.GetName(), ResourcePerAction); doneCallback(this); } }
public override void Run(IReGoapAction previous, IReGoapAction next, IReGoapActionSettings settings, ReGoapState goalState, Action <IReGoapAction> done, Action <IReGoapAction> fail) { base.Run(previous, next, settings, goalState, done, fail); SetNeededResources(settings); if (resource == null || resource.GetCapacity() < ResourcePerAction) { failCallback(this); } else { ReGoapLogger.Log("[GatherResourceAction] acquired " + ResourcePerAction + " " + resource.GetName()); resource.RemoveResource(ResourcePerAction); bag.AddResource(resource.GetName(), ResourcePerAction); doneCallback(this); } }
protected void Update() { if (resource == null || resource.GetCapacity() < ResourcePerAction) { failCallback(this); return; } if (Time.time > gatherCooldown) { gatherCooldown = float.MaxValue; ReGoapLogger.Log("[GatherResourceAction] acquired " + ResourcePerAction + " " + resource.GetName()); resource.RemoveResource(ResourcePerAction); bag.AddResource(resource.GetName(), ResourcePerAction); doneCallback(this); } }
protected void Update() { if (resource == null || resource.GetCapacity() < ResourcePerAction) { failCallback(this); return; } if (Time.time > gatherCooldown) { gatherCooldown = float.MaxValue; ReGoapLogger.Log("[GatherResourceAction] acquired " + ResourcePerAction + " " + resource.GetName()); resource.RemoveResource(ResourcePerAction); bag.AddResource(resource.GetName(), ResourcePerAction); doneCallback(this); if (settings.HasKey("resource")) { ((IResource)settings.Get("resource")).Unreserve(GetHashCode()); } } }
public bool CraftResource(ResourcesBag crafterBag, IRecipe recipe, float value = 1f) { // check Recipe, could be removed since the agent already check for recipe items foreach (var pair in recipe.GetNeededResources()) { if (crafterBag.GetResource(pair.Key) < pair.Value * value) { //throw new UnityException(string.Format("[Workstation] Trying to craft recipe '{0}' without having enough '{1}' resources.", recipe.GetCraftedResource(), pair.Key)); return(false); } } // if can go loop again and remove needed resources foreach (var pair in recipe.GetNeededResources()) { crafterBag.RemoveResource(pair.Key, pair.Value * value); } var resource = recipe.GetCraftedResource(); crafterBag.AddResource(resource, value); return(true); }