/// <summary> /// Do the setup, and continue leftover crafting processes (used when loading from save /// </summary> /// <param name="mydat"></param> public void SetUp(BuildingData mydat, BuildingInventoryController _inv, int _lastCheckId, float[] CraftingProcessProgress) { SetUp(mydat, _inv); lastCheckId = _lastCheckId; for (int i = 0; i < myCraftingProcesses.Length; i++) { if (i < CraftingProcessProgress.Length) { if (CraftingProcessProgress[i] >= 0) { myCraftingProcesses[i].isCrafting = true; myCraftingProcesses[i].curCraftingProgress = CraftingProcessProgress[i]; } else if (CraftingProcessProgress[i] <= -2) { myCraftingProcesses[i].isEnabled = false; } } } if (myCraftingProcesses.Length > 0) { lastCheckId = lastCheckId % myCraftingProcesses.Length; } }
public void UpdateSelf(Construction _construction) { RemoveSelfFromTile(); myConstruction = _construction; myData = myConstruction.myData; isConstruction = true; /*if (isSpaceLanding) * GetComponentInChildren<SpriteGraphicsController>().DoSpaceLanding(null);*/ myRend = GetComponentInChildren <SpriteGraphicsController>(); GenericUpdateSelf(myConstruction.locations, _construction.center); if (myConstruction.isConstruction) { myRend.SetBuildState(SpriteGraphicsController.BuildState.construction); } else { myRend.SetBuildState(SpriteGraphicsController.BuildState.destruction); } myInventory = myConstruction.constructionInventory; isInventorySetup = true; buildingInventoryUpdatedCallback?.Invoke(); StopAnimations(); }
public void SetUp() { int childs = InventoryParent.childCount; for (int i = childs - 1; i >= 0; i--) { Destroy(InventoryParent.GetChild(i).gameObject); } childs = Parent.childCount; for (int i = childs - 1; i > 0; i--) { Destroy(Parent.GetChild(i).gameObject); } var worldObject = GetComponent <BuildingWorldObject>(); crafter = worldObject.myCrafter; inventory = worldObject.myInventory; inventory.drawInventoryEvent += SetUp; craftingProcesses.Clear(); timeoutCounters.Clear(); if (crafter != null) { for (int i = 0; i < crafter.myCraftingProcesses.Length; i++) { CraftingProcess curProcess = crafter.myCraftingProcesses[i] as CraftingProcess; if (curProcess != null) { GameObject pDisp = Instantiate(ProcessDisplayPrefab, Parent); craftingProcesses.Add(pDisp); timeoutCounters.Add(infoDisplayTimeoutTime - 1f); for (int input = 0; input < curProcess.inputItemIds.Length; input++) { GameObject pIn = Instantiate(ProcessinoutPrefab, pDisp.GetComponent <MiniGUI_CraftingProcess>().InputsParent); pIn.GetComponent <MiniGUI_InOutDisplay>().itemImage.sprite = DataHolder.s.GetItem(curProcess.inputItemIds[input]).GetSprite(); pIn.GetComponent <MiniGUI_InOutDisplay>().totalText.text = curProcess.inputItemAmounts[input].ToString(); } for (int output = 0; output < curProcess.outputItemIds.Length; output++) { GameObject pOut = Instantiate(ProcessinoutPrefab, pDisp.GetComponent <MiniGUI_CraftingProcess>().OutputsParent); pOut.GetComponent <MiniGUI_InOutDisplay>().itemImage.sprite = DataHolder.s.GetItem(curProcess.outputItemIds[output]).GetSprite(); pOut.GetComponent <MiniGUI_InOutDisplay>().totalText.text = curProcess.outputItemAmounts[output].ToString(); } //craftingProcesses[craftingProcesses.Count-1].SetActive(false); } } } foreach (InventoryItemSlot it in inventory.inventory) { Instantiate(InventoryListingPrefab, InventoryParent).GetComponent <MiniGUI_InventoryListing>().SetUp(it, inventory, true); } }
/// <summary> /// Do the setup tasks, which means figuring out which crafting processes this building can do based on the BuildingData and the RecipeSet /// </summary> /// <param name="mydat"></param> public void SetUp(BuildingData mydat, BuildingInventoryController _inv) { inventory = _inv; myData = mydat; CraftingNode[] ps = DataHolder.s.GetCraftingProcessesOfType(mydat.myType); if (ps != null) { if (mydat.myType == BuildingData.ItemType.Miner) { //myCraftingProcesses = new CraftingProcess[ps.Length]; myCraftingProcesses = new CraftingProcess[ps.Length]; for (int i = 0; i < ps.Length; i++) { if (DataHolder.s.UniqueNameToOreId(DataHolder.s.GetConnections(ps[i], false)[0].itemUniqueName, out int oreId)) { myCraftingProcesses[i] = new CraftingProcess( new List <DataHolder.CountedItem>(), DataHolder.s.GetConnections(ps[i], false), ps[i].timeCost ); } } } else { myCraftingProcesses = new CraftingProcess[ps.Length]; for (int i = 0; i < ps.Length; i++) { myCraftingProcesses[i] = new CraftingProcess( DataHolder.s.GetConnections(ps[i], true), DataHolder.s.GetConnections(ps[i], false), ps[i].timeCost ); } } } else if (mydat.myType == BuildingData.ItemType.Base) { //myCraftingProcesses = new IProcess[1]; //myCraftingProcesses[0] = new InputProcess(myBelts); // This logic is now handled by the BuildingInventoryController and the BuildingInOutController } if (myCraftingProcesses.Length > 0) { isActive = true; } else { stopAnimationsEvent?.Invoke(); } }
public bool UpdateCraftingProcess(float efficiency, BuildingInventoryController inventory) { if (!isEnabled) { return(false); } if (!isCrafting) { for (int i = 0; i < outputItems.Length; i++) { if (!inventory.CheckAddItem(outputItems[i], outputItemAmounts[i], true)) { return(false); } } for (int i = 0; i < inputItems.Length; i++) { if (!inventory.CheckTakeItem(inputItems[i], inputItemAmounts[i], false)) { return(false); } } for (int i = 0; i < inputItems.Length; i++) { inventory.TryTakeItem(inputItems[i], inputItemAmounts[i], false); } isCrafting = true; } if (isCrafting) { curCraftingProgress += efficiency; if (curCraftingProgress >= craftingProgressTickReq) { for (int i = 0; i < outputItems.Length; i++) { inventory.TryAddItem(outputItems[i], outputItemAmounts[i], true); } isCrafting = false; curCraftingProgress = 0; return(false); } return(true); } return(false); }
public Construction(BuildingData buildingData, int _direction, Position _center, List <InventoryItemSlot> materials, List <InventoryItemSlot> _afterConstructionInventory, bool _isConstruction) { center = _center; direction = _direction; myData = buildingData; if (myData.myType != BuildingData.ItemType.Belt && myData.myType != BuildingData.ItemType.Connector) { locations = myData.shape.CoveredPositions(center); } else { locations.Clear(); locations.Add(center); } isConstruction = _isConstruction; constructionInventory = new BuildingInventoryController(); constructionInventory.SetUpConstruction(_center, materials); afterConstructionInventory = _afterConstructionInventory; }
public void UpdateSelf(Building _building) { RemoveSelfFromTile(); // Only update if the building has changed if (myBuilding != null && !myBuilding.center.isValid() && myBuilding.myPositions != null && myBuilding.myPositions.Count > 0 && myBuilding.myPositions[0] == _building.myPositions[0]) { return; } myBuilding = _building; myData = _building.buildingData; isConstruction = false; /*if (isSpaceLanding) * GetComponentInChildren<SpriteGraphicsController>().DoSpaceLanding(null);*/ myRend = GetComponentInChildren <SpriteGraphicsController>(); GenericUpdateSelf(myBuilding.myPositions, _building.center); myRend.SetBuildState(SpriteGraphicsController.BuildState.built); myCrafter = myBuilding.craftController; myCrafter.continueAnimationsEvent -= ContinueAnimations; myCrafter.continueAnimationsEvent += ContinueAnimations; myCrafter.stopAnimationsEvent -= StopAnimations; myCrafter.stopAnimationsEvent += StopAnimations; myInventory = myBuilding.invController; isInventorySetup = true; buildingInventoryUpdatedCallback?.Invoke(); StopAnimations(); if (_building.buildingData.uniqueName == "bRocket" && !isSpaceLandingTriggered) { isSpaceLandingTriggered = true; GetComponentInChildren <SpriteGraphicsController>().DoSpaceLanding(null); } }
public static void RemoveStorageBuilding(BuildingInventoryController controller) { storageBuildings.Remove(controller); }
public static void RegisterStorageBuilding(BuildingInventoryController controller) { storageBuildings.Add(controller); }