Exemplo n.º 1
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            base.OnDone(agent, context);

            Container agentContainer = agent.GetComponent <Container>();
            Axe       axe            = agentContainer.GetItem() as Axe; // Should probably error check this

            Component target     = context.target as Component;
            Door      targetDoor = target.GetComponent <Door>();

            bool broke = targetDoor.Break(axe.Hit());

            failMsg = "Didn't Break!";
            if (!axe.gameObject.activeSelf)
            {
                // The axe broke so we'll drop it
                agentContainer.DropItem();
                failMsg = "Axe Broke!";
            }

            if (broke)
            {
                // Add the new room to memory
                Memory memory = agent.GetComponent <Memory>();
                if (memory != null)
                {
                    memory.AddLocationToMemory(targetDoor.leadsToRoom);
                }
            }

            return(broke);
        }
Exemplo n.º 2
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            //destroy plant if finished
            Weed weed = context.target as Weed;

            var backpack = agent.GetComponent <Container>();

            backpack.items[resource] += amountToHarvest;

            if (fromBros)
            {
                var       bro    = context.target as BroForReal;
                Container broBag = bro.GetComponent <Container>();
                broBag.items[resource] -= amountToHarvest;
            }
            else if (weed != null && weed.ToString() != "Null" && weed.ToString() != "null")
            {
                weed.amount -= amountToHarvest;
                if (weed.amount <= 0)
                {
                    GameObject weedObj = weed.gameObject;
                    Destroy(weedObj);
                }
            }
            // Refresh list
            RefreshTargets();

            return(base.OnDone(agent, context));
        }
Exemplo n.º 3
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            Container c = agent.GetComponent <Container>();

            c.items[item] -= amountToUse;
            return(base.OnDone(agent, context));
        }
Exemplo n.º 4
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            // Done harvesting.
            var inventory = agent.GetComponent <Container>();

            inventory.items[Item.Part2] += 1;
            return(base.OnDone(agent, context));
        }
Exemplo n.º 5
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            // Done harvesting.
            var backpack = agent.GetComponent <Container>();

            backpack.items[resource] += amountToHarvest;
            return(base.OnDone(agent, context));
        }
Exemplo n.º 6
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            // Done harvesting.
            var inventory = agent.GetComponent <Container> ();

            inventory.items [resource] += amountToCollect;
            return(base.OnDone(agent, context));
        }
Exemplo n.º 7
0
Arquivo: With.cs Projeto: lulzzz/sito
        public override JSValue Evaluate(Context context)
        {
            JSValue          scopeObject = null;
            WithContext      intcontext  = null;
            Action <Context> action      = null;

            if (context._executionMode >= ExecutionMode.Resume)
            {
                action = context.SuspendData[this] as Action <Context>;
                if (action != null)
                {
                    action(context);
                    return(null);
                }
            }

            if (context._executionMode != ExecutionMode.Resume && context.Debugging)
            {
                context.raiseDebugger(_scope);
            }

            scopeObject = _scope.Evaluate(context);
            if (context._executionMode == ExecutionMode.Suspend)
            {
                context.SuspendData[this] = null;
                return(null);
            }

            intcontext = new WithContext(scopeObject, context);
            action     = c =>
            {
                try
                {
                    intcontext._executionMode = c._executionMode;
                    intcontext._executionInfo = c._executionInfo;
                    intcontext.Activate();
                    c._lastResult    = _body.Evaluate(intcontext) ?? intcontext._lastResult;
                    c._executionMode = intcontext._executionMode;
                    c._executionInfo = intcontext._executionInfo;
                    if (c._executionMode == ExecutionMode.Suspend)
                    {
                        c.SuspendData[this] = action;
                    }
                }
                finally
                {
                    intcontext.Deactivate();
                }
            };

            if (context.Debugging && !(_body is CodeBlock))
            {
                context.raiseDebugger(_body);
            }

            action(context);
            return(null);
        }
Exemplo n.º 8
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            var backpack = agent.GetComponent <Container>();
            var target   = context.target as HarvestPoint;

            ++target.GetComponent <Container>().items[itemToDrop];
            --backpack.items[itemToDrop];

            return(base.OnDone(agent, context));
        }
Exemplo n.º 9
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            base.OnDone(agent, context);
            Container container      = agent.GetComponent <Container>();
            Memory    locationMemory = agent.GetComponent <Memory>();

            container.DropItem(locationMemory.GetCurrentLocation().transform);

            return(true);
        }
Exemplo n.º 10
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            var inventory = agent.GetComponent <Container>();
            var tool      = inventory.tool.GetComponent <ToolComponent>();

            tool.use(toolDamage);
            if (tool.destroyed())
            {
                Destroy(inventory.tool);
                inventory.tool = null;
            }
            return(base.OnDone(agent, context));
        }
Exemplo n.º 11
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            var backpack = agent.GetComponent <Container>();
            var tool     = backpack.tool.GetComponent <ToolComponent>();

            tool.Use(toolDamage);
            if (tool.IsDestroyed)
            {
                Destroy(backpack.tool);
                backpack.tool = null;
            }
            return(base.OnDone(agent, context));
        }
Exemplo n.º 12
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            base.OnDone(agent, context);
            targetPositions[agent].ReturnSelf();

            SightSensor sight = agent.GetComponent <SightSensor>();

            if (sight != null)
            {
                sight.LookAround();
            }
            return(true);
        }
Exemplo n.º 13
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            var target = context.target as UnknownPile;

            target.removeItem(item);
            target.setSearched(true);

            // Done harvesting.
            var inventory = agent.GetComponent <Container>();

            inventory.items[item] += 1;

            return(base.OnDone(agent, context));
        }
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            var inventory = agent.GetComponent <Container>();

            foreach (var item in ingredients)
            {
                inventory.items[item.item] -= item.amount;
            }
            foreach (var item in products)
            {
                inventory.items[item.item] += item.amount;
            }
            return(base.OnDone(agent, context));
        }
Exemplo n.º 15
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            // Done harvesting.
            var backpack = agent.GetComponent <Container>();

            backpack.items[resource] += amountToHarvest;
            var tool = backpack.tool.GetComponent <ToolComponent>();

            tool.Use(toolDamage);
            if (tool.IsDestroyed)
            {
                Destroy(backpack.tool);
                backpack.tool = null;
            }
            return(base.OnDone(agent, context));
        }
Exemplo n.º 16
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            base.OnDone(agent, context);

            Component    target       = context.target as Component;
            HealthSensor targetHealth = target.GetComponent <HealthSensor>();

            if (targetHealth != null)
            {
                targetHealth.Damage(power);
                return(true);
            }

            Debug.LogError("No health sensor for target!");
            return(false);
        }
Exemplo n.º 17
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            base.OnDone(agent, context);
            Component target     = context.target as Component;
            Item      targetItem = target.GetComponent <Item>();
            Container container  = agent.GetComponent <Container>();

            // Someone took the item by the time we got here
            if (targetItem.type != itemType)
            {
                return(false);
            }

            container.PickUpItem(targetItem);
            return(true);
        }
Exemplo n.º 18
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            var target     = context.target as Component;
            var supplyPile = target.GetComponent <Container>();

            if (supplyPile.items[resource] < amountToTake)
            {
                // Someone got here before us.
                return(false);
            }
            supplyPile.items[resource] -= amountToTake;

            // TODO: Play animations when a task is done.
            var backpack = agent.GetComponent <Container>();

            backpack.items[resource] += amountToTake;

            return(base.OnDone(agent, context));;
        }
Exemplo n.º 19
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            base.OnDone(agent, context);

            Component  target           = context.target as Component;
            Searchable targetSearchable = target.GetComponent <Searchable>();

            if (targetSearchable.Search() != ItemType.None)
            {
                Container agentContainer = agent.GetComponent <Container>();
                Item      foundItem      = targetSearchable.RetrieveItem();
                agentContainer.PickUpItem(foundItem);
                successMsg = "Found " + foundItem.type;
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 20
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            base.OnDone(agent, context);

            Container agentContainer = agent.GetComponent <Container>();

            if (agentContainer.GetItemType() != ItemType.Key)
            {
                // We don't have a key anymore
                return(false);
            }

            Door target = context.target as Door;

            target.Unlock();
            // Destroy the key
            Item key = agentContainer.DropItem();

            key.Hide();

            return(true);
        }
Exemplo n.º 21
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            base.OnDone(agent, context);

            Door target = context.target as Door;

            if (target.IsLocked())
            {
                return(false);
            }
            else
            {
                target.Open();
                // Add the new room to memory
                Memory memory = agent.GetComponent <Memory>();
                if (memory != null)
                {
                    memory.AddLocationToMemory(target.leadsToRoom);
                }
            }

            return(true);
        }
Exemplo n.º 22
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            var target     = context.target as Component;
            var supplyPile = target.GetComponent <Container>();

            if (supplyPile.items[Item.NewTool] == 0)
            {
                return(false);
            }
            supplyPile.items[Item.NewTool] -= 1;

            // Create the tool and add it to the agent.

            var backpack = agent.GetComponent <Container>();
            // TODO: Use GameObjectPool to pool tools instead of instantiating new
            //       ones all the time.
            var prefab = Resources.Load <GameObject>(backpack.toolType);
            var tool   = Instantiate(prefab, agent.transform.position, agent.transform.rotation);

            backpack.tool         = tool;
            tool.transform.parent = agent.transform;

            return(base.OnDone(agent, context));
        }
Exemplo n.º 23
0
 protected override bool OnDone(GoapAgent agent, WithContext context)
 {
     if (context.target.GetType() == typeof(Weed))
     {
         Weed weed = context.target as Weed;
         if (weed != null && weed.ToString() != "Null" && weed.ToString() != "null")
         {
             weed.amount -= eatAmount;
         }
         if (weed.amount <= 0)
         {
             GameObject weedObj = weed.gameObject;
             Destroy(weedObj);
         }
     }
     else
     {
         Candy candy = context.target as Candy;
         if (candy != null && candy.ToString() != "Null" && candy.ToString() != "null")
         {
             candy.amount -= eatAmount;
         }
         if (candy.amount <= 0)
         {
             GameObject candyObj = candy.gameObject;
             Destroy(candyObj);
         }
     }
     if (agent.GetType() == typeof(Dog))
     {
         Dog dog = agent as Dog;
         dog.wantMoreFood();
     }
     RefreshTargets();
     return(base.OnDone(agent, context));
 }
Exemplo n.º 24
0
 /// <summary>
 /// Returns false if the action can not be performed.
 /// Override this to implement the affect of completing the action.
 /// </summary>
 protected virtual bool OnDone(GoapAgent agent, WithContext context)
 {
     context.isDone = true;
     DebugUtils.Log(GetType().Name + " DONE!");
     return(true);
 }
Exemplo n.º 25
0
 protected override bool OnDone(GoapAgent agent, WithContext context)
 {
     return(base.OnDone(agent, context));
 }
Exemplo n.º 26
0
 protected override bool OnDone(GoapAgent agent, WithContext context)
 {
     base.OnDone(agent, context);
     SimulationManager.instance.Stop();
     return(true);
 }