void PutBottleToBeercase(GameObject bottle, GameObject beercase) { if (bottle == null || beercase == null) { BottleRecycling.DebugPrint("BeercaseManager: Error when trying to put empty bottle to empty beercase."); return; } // Add BeercaseFilled -component if (beercase.GetComponent <BeercaseFilled>() == null) { beercase.AddComponent <BeercaseFilled>(); } try { Destroy(beercase.GetComponent <PlayMakerFSM>()); // Remove PlayMakerFSM from Beercase } catch { } BeercaseFilled beercaseFilled = beercase.GetComponent <BeercaseFilled>(); // Only 24 bottles fits to beercase (duh) if (beercaseFilled.totalBottles >= 24) { return; } beercaseFilled.AddBottleToBeerCase(bottle); // Add Empty Bottle to Beercase PlaySound(bottle_empty_2, beercase.transform.position); // Play Sound }
IEnumerator SpawnSavedFilledBeercases(SaveData saveData) { yield return(new WaitForEndOfFrame()); // wait one frame for apparently no reason // Create Empty Beercase prefab filledBeercasePrefab = GetEmptyBeercase(); filledBeercasePrefab.SetActive(true); if (filledBeercasePrefab.GetComponent <PlayMakerFSM>()) { GameObject.Destroy(filledBeercasePrefab.GetComponent <PlayMakerFSM>()); // Destroy FSM Component from clone. } yield return(new WaitForEndOfFrame()); // wait one frame after destroying fsm // Destroy all existing child bottles from Beercase prefab. foreach (Transform child in filledBeercasePrefab.GetComponentsInChildren <Transform>()) { if (child != filledBeercasePrefab.transform) { GameObject.Destroy(child.gameObject); } } yield return(new WaitForEndOfFrame()); // wait one frame before creating empty bottles to case. if (saveData.filledBeercases.Count > 0) { foreach (SaveDataFilledBeercase filledBeercase in saveData.filledBeercases) { // Create new Beercase GameObject newCase = GameObject.Instantiate(filledBeercasePrefab) as GameObject; newCase.transform.position = filledBeercase.Position; newCase.transform.eulerAngles = new Vector3(filledBeercase.RotX, filledBeercase.RotY, filledBeercase.RotZ); newCase.name = "empty(itemx)"; // Make Beercase Fillable BeercaseFilled filled = newCase.AddComponent <BeercaseFilled>(); // Add Empty Bottles GameObjects to New Beercase for (int i = 0; i < filledBeercase.bottleAmount; i++) { filled.AddBottleToBeerCase(GameObject.Instantiate(emptyBottlePrefab) as GameObject); } } } // Empty Beercase prefab is not needed anymore; destroy it. GameObject.Destroy(filledBeercasePrefab); yield return(null); }
public override void OnSave() { // Called once, when save and quit // Serialize your save file here. SaveData sd = new SaveData(); sd.unredeemedBottleDeposit = bottleRecyclingManager.totalMoneyAmountFromBottles; // Save Empty Bottles and Beercases, if set so. if ((bool)saveEmptyBottles.GetValue() || (bool)saveFilledBeercases.GetValue()) { foreach (GameObject go in GameObject.FindGameObjectsWithTag("PART")) { // empty bottles if (go.name == "empty bottle(Clone)" && (bool)saveEmptyBottles.GetValue()) { if (isBoozeBottle(go.transform)) // ignore booze bottles { continue; } SaveDataEmptyBottle emptyBottle = CreateSaveDataEmptyBottle(go); sd.emptyBottles.Add(emptyBottle); continue; } // filled beercases if (go.name == "empty(itemx)" && (bool)saveFilledBeercases.GetValue()) { BeercaseFilled filled = go.GetComponent <BeercaseFilled>(); if (filled) { SaveDataFilledBeercase filledBeercase = CreateSaveDataFilledBeercase(go); sd.filledBeercases.Add(filledBeercase); continue; } } } } // save to file SaveLoad.SerializeSaveFile(this, sd, "BottleRecyclingSave.save"); }
float GetBottleValue(Transform bottleTransform) { if (bottleTransform == null) { return(0); } switch (bottleTransform.name) { case "empty bottle(Clone)": // empty bottle return(1); case "empty(itemx)": // empty beercase // filled case BeercaseFilled filled = bottleTransform.GetComponent <BeercaseFilled>(); if (filled != null) { int totalValue = 14 + (filled.totalBottles * 1); return(totalValue); } // casual case return(14); default: // custom bottles if (customBottles.Count > 0) { if (customBottles.Contains(bottleTransform.name)) { int index = customBottles.IndexOf(bottleTransform.name); if (index <= customBottlePrices.Count) { return(customBottlePrices[index]); } } } // fail-safe return(1); } }
private void OnTriggerStay(Collider other) { if (other.tag != "PART" || other.gameObject.layer == LayerMask.NameToLayer("Wheel") || isTeimoTakingBottle || !OpenStore.Value || BrokenWindow.Value > 0) { return; } Rigidbody rb = other.GetComponent <Rigidbody>(); if (rb) { if (rb.velocity.magnitude > 0.25f) { return; } } // empty beer bottle if (other.name == "empty bottle(Clone)") { if (!BottleRecycling.isBoozeBottle(other.transform)) // ignore booze bottles { StartCoroutine(TeimoTakesBottle(other.transform)); // start teimo bottle returning sequence } } // empty beercase if (other.name == "empty(itemx)") { // identify gameobject as beercase from fsm id... PlayMakerFSM fsm = other.GetComponent <PlayMakerFSM>(); if (fsm) { if (fsm.FsmVariables.FindFsmString("ID").Value.Contains("beercase")) { StartCoroutine(TeimoTakesBottle(other.transform)); // start teimo bottle returning sequence return; } } // ... if it's not casual beercase, check if it has been filled with empty bottles. BeercaseFilled filled = other.GetComponent <BeercaseFilled>(); if (filled) { StartCoroutine(TeimoTakesBottle(other.transform)); // start teimo bottle returning sequence } } // last we check for possible custom bottles if (customBottles.Count > 0) { if (customBottles.Contains(other.name)) { int index = customBottles.IndexOf(other.name); if (index != -1) { StartCoroutine(TeimoTakesBottle(other.transform)); } } } }