コード例 #1
0
        public override TaskStatus OnUpdate()
        {
            outStorageStructure.Value = null;

            if (SearchFor.NearestStorageStructure(originStructure.Value.GetComponent <Structure>().plot, originStructure.Value.transform.position, out StorageStructure targetStorage))
            {
                outStorageStructure.Value = targetStorage.gameObject;
            }

            return(outStorageStructure.Value ? TaskStatus.Success : TaskStatus.Failure);
        }
コード例 #2
0
        /*
         * is gatherer
         * search storage
         * search item on the ground
         * search source
         * store item
         * gather source
         */

        public override TaskStatus OnUpdate()
        {
            base.OnUpdate();

            outItem.Value    = null;
            outStorage.Value = null;
            outSource.Value  = null;

            GatherStructure gatherStructure = citizen.workplace.GetComponent <GatherStructure>();

            if (!gatherStructure)
            {
                return(TaskStatus.Failure);
            }

            if (SearchFor.NearestStorageStructure(gatherStructure.plot, transform.position, out StorageStructure storage))
            {
                outStorage.Value = storage.gameObject;
            }
            else
            {
                //TODO: "No storage" notification
                return(TaskStatus.Failure);
            }

            if (SearchFor.ItemOnTheGround(gatherStructure.itemType, gatherStructure.plot, gatherStructure.transform.position, out GameObject item))
            {
                outItem.Value = item;
            }
            else
            {
                Source source = gatherStructure.sources.FirstOrDefault(s => s && s.gameObject.activeSelf);
                //Source.list.FindAll(s => s.itemType == gatherStructure.itemType && !s.ReservedBy && s.Health.HP > 0 && Distance.Manhattan2D(gatherStructure.transform.position, s.transform.position) < gatherStructure.rangeOfSearch).OrderBy(s => Distance.Manhattan2D(gatherStructure.transform.position, s.transform.position)).FirstOrDefault();
                if (source)
                {
                    outSource.Value = source.gameObject;
                }
            }

            return(TaskStatus.Success);
        }
コード例 #3
0
        public override TaskStatus OnUpdate()
        {
            base.OnUpdate();

            outCraftedItem.Value     = null;
            outTargetStorage.Value   = null;
            outMissingItemType.Value = null;
            outMissingCount.Value    = 0;
            outMissingFuel.Value     = 0;
            outItemTypeToCraft.Value = null;

            CraftStructure craftStructure = citizen.workplace.GetComponent <CraftStructure>();

            if (!craftStructure)
            {
                return(TaskStatus.Failure);
            }

            //Store craftedItem
            if (craftStructure.craftedItem)
            {
                outCraftedItem.Value = craftStructure.craftedItem.gameObject;
                if (SearchFor.NearestStorageStructure(craftStructure.plot, craftStructure.transform.position, out StorageStructure targetStorage))
                {
                    outTargetStorage.Value = targetStorage.gameObject;
                    return(TaskStatus.Success);
                }
                else
                {
                    Debug.LogError("No StorageStructure on plot", craftStructure.plot);
                    return(TaskStatus.Failure);
                }
            }
            else
            {
                //Find first uncomplete order
                CraftStructure.CraftOrder order = craftStructure.GetOrder();
                if (order != null)
                {
                    //craftStructure.currentItemType = order.itemType;

                    //Find what is missing
                    List <ItemCount> missing = order.itemType.blueprint.MissingResources(craftStructure.storage);
                    if (missing.Count > 0)
                    {
                        outMissingItemType.Value = missing[0].type;
                        outMissingCount.Value    = missing[0].count;
                        return(TaskStatus.Success);
                    }
                    else
                    {
                        if (craftStructure.IsFueled)
                        {
                            //Refuel
                            outMissingFuel.Value = order.itemType.blueprint.duration - craftStructure.fuel;
                            if (outMissingFuel.Value > 0)
                            {
                                return(TaskStatus.Success);
                            }

                            /*
                             * if (missingFuel > 0)
                             * {
                             *      Item fuelItem = null;
                             *      Storage sourceStorage = null;
                             *
                             *      if (!fuelItem)
                             *              SearchFor.FuelInStorageStructures(transform.position, out fuelItem, out sourceStorage);
                             *      if (!fuelItem)
                             *              SearchFor.FuelInCraftStructures(transform.position, out fuelItem);
                             *      if (!fuelItem)
                             *              SearchFor.FuelInShopStructures(transform.position, out fuelItem, out sourceStorage);
                             *
                             *      if (fuelItem)
                             *              citizen.fsm.Store(fuelItem, sourceStorage, craftStructure.storage);
                             * }
                             */
                        }
                        else
                        {
                            //Craft
                            outItemTypeToCraft.Value = order.itemType;
                            return(TaskStatus.Success);
                        }
                    }
                }
            }

            return(TaskStatus.Success);
        }