public void LoadSavedTiles() { buildable_Manager = Buildable_Manager.instance; Item_Manager item_Manager = Item_Manager.instance; if (savedAreaTiles.savedTiles == null) { return; } if (savedAreaTiles.savedTiles.Length <= 0) { return; } SetCurrentArea((AreaID)savedAreaTiles.areaID); SetupGrid(); SetGridFromTileMap(); foreach (STile sTile in savedAreaTiles.savedTiles) { if (sTile.hasMachine == true) { MachinePrototype proto = buildable_Manager.GetMachinePrototype(sTile.machineName); proto.machineCondition = sTile.machineCondition; Item machineItem = item_Manager.CreateInstance(item_Manager.GetPrototype(proto.name)); ShipManager.instance.PlaceMachine(machineItem, proto, new Vector2(sTile.world_x, sTile.world_y)); } else if (sTile.hasProducer == true) { ProducerPrototype proto = buildable_Manager.GetProducerPrototype(sTile.producerName); proto.machineCondition = sTile.machineCondition; proto.curProductionName = sTile.itemProduced; proto.productionStage = sTile.productionStage; Item prodItem = item_Manager.CreateInstance(item_Manager.GetPrototype(proto.name)); Producer producer = buildable_Manager.CreateProducerInstance(proto); GameObject prodGObj = buildable_Manager.SpawnProducer(producer, new Vector2(sTile.world_x, sTile.world_y)); if (prodGObj == null) { return; } prodGObj.GetComponent <Producer_Controller>().Init(prodItem, producer, grid_data[sTile.grid_x, sTile.grid_y]); } } }
public void Init(Item producerAsItem, Producer _producer, Tile_Data _baseTile) { producer = _producer; if (_baseTile.AddProducer(producer) == false) { return; } base.InitMachine(producerAsItem, producer, _baseTile, ShipManager.instance); // The machine controller sets the list of Neighbor tiles, // then we Add the producers on neighbor tiles as well foreach (Tile_Data tile in neighborTiles) { tile.AddProducer(producer); } item_Manager = Item_Manager.instance; timer = new CountdownHelper(0); //storage_inventory = new Inventory(1); inventory_Controller = GetComponentInChildren <Inventory_Controller>(); inventory_Controller.Initialize(ID_Generator.instance.GetMachineID(this), 1); // Position the growth visuals X correctly according to the machine's tile width if (growth_visuals != null) { growth_visuals.transform.localPosition = new Vector2(producer.tileWidth > 1 ? 0.5f : 0, 0.5f); } Debug.Log("Initialized a producer with a blueprint for " + producer.current_Blueprint.itemProduced.itemName); // This runs when a producer has already started producing before if (producer.current_Blueprint.itemProduced.count > 0 && producer.productionStage >= 0) { if (producer.productionStage >= 3) { itemInProduction = item_Manager.CreateInstance(item_Manager.GetPrototype(producer.current_Blueprint.itemProduced.itemName)); SetGrowthVisuals(); CompleteProduction(); return; } StartProduction(true); return; } SetProductionStage(0); // Debug.Log("Producer INITIALIZED: " + " key ingredient = " + producer.productionBlueprints[0].keyIngredient.count + " " + producer.productionBlueprints[0].keyIngredient.itemName + // " secondary ingredient " + producer.productionBlueprints[0].secondaryIngredients[0].count + " " + producer.productionBlueprints[0].secondaryIngredients[0].itemName); }
public Inventory LoadInventory(string owner_id) { Item_Manager item_Manager = Item_Manager.instance; // Try to load and return SavedInventory savedInventory = JsonLoader.instance.LoadSavedInventory(owner_id); if (savedInventory.maxSpace > 0 && savedInventory.items != null && savedInventory.items.Length > 0) { Inventory loadedInventory = new Inventory(savedInventory.maxSpace); foreach (ItemReference itemRef in savedInventory.items) { // TODO : Load the updated stats by updating the item prototype // To do this we might have to store Item stats in saved inventory with each item reference Item newItem = item_Manager.CreateInstance(item_Manager.GetPrototype(itemRef.itemName)); loadedInventory.AddItem(newItem, itemRef.count); } return(loadedInventory); } // if none found... return(null); }
void StartProduction(bool forcedStart = false) { Debug.Log("STARTING PRODUCTION ON " + producer.current_Blueprint.itemProduced.itemName); // Grab an instance of the item about to be produced itemInProduction = item_Manager.CreateInstance(item_Manager.GetPrototype(producer.current_Blueprint.itemProduced.itemName)); timeToCreate = itemInProduction.timeToCreate; // Set timer if (forcedStart == true) { float timePassed = (itemInProduction.timeToCreate * 0.25f) * producer.productionStage; timer.Reset(timeToCreate, timePassed); } else { timer.Reset(timeToCreate); } SetProductionStage(timer.elapsedPercent, forcedStart); isProducing = true; AnimateStayOn(); }