Пример #1
0
 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);
     }
 }
Пример #2
0
        protected override void Awake()
        {
            base.Awake();
            recipe = RawRecipe as IRecipe;
            if (recipe == null)
            {
                throw new UnityException("[CraftRecipeAction] The rawRecipe ScriptableObject must implement IRecipe.");
            }
            resourcesBag = GetComponent <ResourcesBag>();

            // could implement a more flexible system that handles dynamic resources's count
            foreach (var pair in recipe.GetNeededResources())
            {
                preconditions.Set("hasResource" + pair.Key, true);   // 添加前置条件
            }

            effects.Set("hasResource" + recipe.GetCraftedResource(), true); // 添加执行结果
        }
Пример #3
0
    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);
    }
Пример #4
0
 void Awake()
 {
     resourcesBag = GetComponent <ResourcesBag>();
 }
Пример #5
0
 protected override void Awake()
 {
     base.Awake();
     resourcesBag = GetComponent <ResourcesBag>();
 }
Пример #6
0
 void Awake()
 {
     bankBag = gameObject.AddComponent <ResourcesBag>();
 }
Пример #7
0
 protected override void Awake()
 {
     base.Awake();
     resourcesBag        = GetComponent <ResourcesBag>();
     settingsPerResource = new Dictionary <string, List <ReGoapState <string, object> > >();
 }