Esempio n. 1
0
        public override void OnStart()
        {
            base.OnStart();

            craftStructure = _craftStructure.Value.GetComponent <CraftStructure>();
            timer          = 0;
            returnItem     = null;
        }
Esempio n. 2
0
 public override void OnEnter()
 {
     if (!citizen)
     {
         citizen = Owner.GetComponent <Citizen>();
     }
     craftStructure            = _craftStructure.Value.GetComponent <CraftStructure>();
     itemType                  = (ItemType)_itemType.Value;
     craftStructure.ReservedBy = citizen;
 }
Esempio n. 3
0
        public override TaskStatus OnUpdate()
        {
            base.OnUpdate();

            CraftStructure cs = citizen.workplace ? citizen.workplace.GetComponent <CraftStructure>() : null;

            outCraftStructure.Value = cs ? cs.gameObject : null;

            return(cs ? TaskStatus.Success : TaskStatus.Failure);
        }
Esempio n. 4
0
    public static bool FuelInCraftStructures(Vector3 position, out Item item)
    {
        CraftStructure craftStructure = CraftStructure.list
                                        .FindAll(s => s.craftedItem && s.craftedItem.type.fuelValue > 0)
                                        .OrderBy(s => (s.transform.position - position).sqrMagnitude)
                                        .FirstOrDefault();

        if (craftStructure)
        {
            item = craftStructure.craftedItem;
            return(true);
        }

        item = null;
        return(false);
    }
Esempio n. 5
0
    public static bool ItemInCraftStructures(ItemType itemType, Vector3 position, out Item item, CraftStructure exclude = null)
    {
        CraftStructure craftStructure = CraftStructure.list
                                        .FindAll(s => s != exclude && s.craftedItem && s.craftedItem.type == itemType)
                                        .OrderBy(s => (s.transform.position - position).sqrMagnitude)
                                        .FirstOrDefault();

        if (craftStructure)
        {
            item = craftStructure.craftedItem;
            return(true);
        }

        item = null;
        return(false);
    }
Esempio n. 6
0
        public void Hide(bool freeReservation = true)
        {
            if (structure)
            {
                if (freeReservation)
                {
                    structure.ReservedBy = null;
                }
                structure.storage.onItemsUpdate -= UpdateRequiredList;
            }

            structure                  = null;
            itemType                   = null;
            canvas.enabled             = false;
            productsScrollList.enabled = false;

            if (Player.instance)
            {
                Player.instance.controlsEnabled = true;
            }
        }
Esempio n. 7
0
        public void Show(CraftStructure structure)
        {
            if (!this.structure)
            {
                this.structure             = structure;
                structure.ReservedBy       = Player.instance;
                canvas.enabled             = true;
                productsScrollList.enabled = true;

                Player.instance.controlsEnabled = false;

                productsScrollList.Draw(structure.itemTypes.Count, 0);
                productsScrollList.UpdateNavigation();

                structure.storage.onItemsUpdate += UpdateRequiredList;

                fuelSlider.gameObject.SetActive(structure.fuelMax > 0);
                progressSlider.gameObject.SetActive(structure.fuelMax > 0);
                progressSlider.value = 0;

                controlsUnlocked = false;
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
 public static bool CraftStructureWithItemType(ItemType itemType, Vector3 position, out CraftStructure craftStructure, bool onlyWithoutWorker = true)
 {
     craftStructure = CraftStructure.list
                      .FindAll(s => s.itemTypes.Contains(itemType) && (onlyWithoutWorker? !s.worker : true))
                      .OrderBy(s => (s.transform.position - position).sqrMagnitude)
                      .FirstOrDefault();
     return(craftStructure);
 }