/// <summary> /// Finish cooking the microwaved meal. /// </summary> private void FinishCooking() { spriteRenderer.sprite = SPRITE_OFF; if (isServer) { GameObject mealPrefab = CraftingManager.Meals.FindOutputMeal(meal); SpawnResult result = Spawn.ServerPrefab(mealPrefab, GetComponent <RegisterTile>().WorldPosition, transform.parent); //If the resulting meal has a stackable component, set the amount to mealCount to ensure that food in = food out. Stackable stck = result.GameObject.GetComponent <Stackable>(); if (stck != null && mealCount != 0) { //Get difference between new item's initial amount and the amount held by mealCount (amount of ingredient). int stckChanger = mealCount - stck.Amount; //If stckChanger is 0, do nothing. //If stckChanger is positive, add to stack. if (stckChanger > 0) { stck.ServerIncrease(stckChanger); } else if (stckChanger < 0) { //If stckChanger is positive, remove stack. stck.ServerConsume(-stckChanger); } } } meal = null; mealCount = 0; }
/// <summary> /// Finish cooking the microwaved meal. /// </summary> private void FinishCooking() { spriteRenderer.sprite = SPRITE_OFF; if (isServer && mealCount > 0) { GameObject mealPrefab = CraftingManager.Meals.FindOutputMeal(meal); Vector3Int spawnPosition = GetComponent <RegisterTile>().WorldPosition; SpawnResult result = Spawn.ServerPrefab(mealPrefab, spawnPosition, transform.parent); Stackable stck = result.GameObject.GetComponent <Stackable>(); if (stck != null) // If the meal has a stackable component, set the correct number of meals { int mealDeficit = mealCount - stck.InitialAmount; while (mealDeficit > 0) { mealDeficit = stck.ServerIncrease(mealDeficit); if (mealDeficit > 0) { result = Spawn.ServerPrefab(mealPrefab, spawnPosition, transform.parent); stck = result.GameObject.GetComponent <Stackable>(); mealDeficit -= stck.InitialAmount; } } if (mealDeficit < 0) // Reduce the stack if our last spawned stackable results in too many meals { stck.ServerConsume(-mealDeficit); } } else if (mealCount > 1) // Spawn non-stackable meals { Spawn.ServerPrefab(mealPrefab, spawnPosition, transform.parent, count: mealCount - 1); } } meal = null; mealCount = 0; }