public static void removeItemBoosts (SquirrelPlayerCharacter mySquirrel, SSGameItem myItem) { if (myItem.itemBenefit != "none") { string statToReduce; int amountToReduce; statToReduce = myItem.itemBenefit.Substring (3,1); amountToReduce = int.Parse(myItem.itemBenefit.Substring (1,1)); switch (statToReduce) { case "A": CreatePCSquirrel.pcSquirrel.clothingRunBoost -= amountToReduce; CreatePCSquirrel.pcSquirrel.clothingJumpBoost -= amountToReduce; CreatePCSquirrel.pcSquirrel.clothingClimbBoost -= amountToReduce; CreatePCSquirrel.pcSquirrel.squirrelMaxHealthValue -= amountToReduce; CreatePCSquirrel.pcSquirrel.squirrelCurrentHealthValue -= amountToReduce; break; case "C": CreatePCSquirrel.pcSquirrel.clothingClimbBoost -= amountToReduce; break; case "H": CreatePCSquirrel.pcSquirrel.squirrelMaxHealthValue -= amountToReduce; CreatePCSquirrel.pcSquirrel.squirrelCurrentHealthValue -= amountToReduce; break; case "J": CreatePCSquirrel.pcSquirrel.clothingJumpBoost -= amountToReduce; break; case "R": CreatePCSquirrel.pcSquirrel.clothingRunBoost -= amountToReduce; break; default: Debug.Log ("Error removing clothing boost"); break; } } }
} // end update void OnGUI () { GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUI.skin.label.richText = true; GUI.skin.label.fontSize = Screen.width/1536*82; GUI.skin.label.fontStyle = FontStyle.Normal; GUI.skin.label.fixedWidth = Screen.width-20; GUI.skin.button.alignment = TextAnchor.MiddleCenter; GUI.skin.button.richText = true; GUI.skin.button.fontStyle = FontStyle.Normal; if (displayWardrobeContents) { invBGObject.GetComponent<SpriteRenderer> ().sprite = invBGSprite.GetComponent<SpriteRenderer> ().sprite; exitButtonObject.GetComponent<SpriteRenderer> ().sprite = exitButtonSprite.GetComponent<SpriteRenderer> ().sprite; GUI.skin.button.fontSize = Screen.width / 1536 * 36; GUI.skin.label.alignment = TextAnchor.MiddleLeft; GUI.skin.label.fontSize = Screen.width / 1536 * 28; GUI.skin.verticalScrollbar.fixedWidth = Screen.width * 0.05f; GUI.skin.verticalScrollbarThumb.fixedWidth = Screen.width * 0.05f; scrollPosition = GUI.BeginScrollView (new Rect (inventoryWindowX, inventoryWindowY, inventoryWindowWidth, inventoryWindowHeight), scrollPosition, new Rect (0, 0, inventoryWindowWidth - Screen.width * 0.05f - 1, Mathf.Max (inventoryWindowHeight, invListUsed.Count * (buttonSize + 5))), false, true); GUILayout.BeginVertical (); for (i = 0; i < invListUsed.Count; i++) { // deterime button text for list itemNameForList = invListUsed[i].itemName; if (invListUsed [i].itemBenefit == "none") { benefitMessage = ""; } else { benefitMessage = "\nBenefit: " + invListUsed[i].itemBenefit; } if (invListUsed [i].itemName == "My Acorn Stash") { benefitMessage = "\nTotal: " + CreatePCSquirrel.pcSquirrel.squirrelAcornsSaved; } // begin listing the buttons in a scroll box GUILayout.BeginHorizontal (); if (GUILayout.Button (invListUsed[i].itemButtonPic, GUILayout.Height (buttonSize), GUILayout.Width (buttonSize))) { if (invListUsed [i].itemName == "My Acorn Stash") { CreatePCSquirrel.pcSquirrel.squirrelAcornsInHand += CreatePCSquirrel.pcSquirrel.squirrelAcornsSaved; CreatePCSquirrel.pcSquirrel.squirrelAcornsSaved = 0; if (!MasterObjectList.inventory.Contains (MasterObjectList.masterItemList.Find (item => item.itemName == "Stash Acorns"))) { MasterObjectList.inventory.Add (MasterObjectList.masterItemList.Find (item => item.itemName == "Stash Acorns")); } } // when button is tapped... // if the item is a consumable, add the item to character's inventory if ((invListUsed [i].itemID >= 1000) && (invListUsed [i].itemID < 2000)) { MasterObjectList.inventory.Add (invListUsed [i]); } // if button is remove item, remove that item and add it to the wardrobe if ((invListUsed [i].itemID == 2000) && (CreatePCSquirrel.pcSquirrel.itemWornOnHeadID != 2000)) { prevItemWorn = SquirrelPlayerCharacter.getHeadItemWorn(CreatePCSquirrel.pcSquirrel); SquirrelPlayerCharacter.removeItemBoosts(CreatePCSquirrel.pcSquirrel, prevItemWorn); // remove item boosts invListUsed.Add (prevItemWorn); // add worn item to inventory SquirrelPlayerCharacter.setItemWorn (CreatePCSquirrel.pcSquirrel, MasterObjectList.masterItemList.Find(item => item.itemName == "Remove Head Item")); } if ((invListUsed [i].itemID == 3000) && (CreatePCSquirrel.pcSquirrel.itemWornOnBodyID != 3000)) { prevItemWorn = SquirrelPlayerCharacter.getBodyItemWorn(CreatePCSquirrel.pcSquirrel); SquirrelPlayerCharacter.removeItemBoosts(CreatePCSquirrel.pcSquirrel, prevItemWorn); // remove item boosts invListUsed.Add (prevItemWorn); // add worn item to inventory SquirrelPlayerCharacter.setItemWorn (CreatePCSquirrel.pcSquirrel, MasterObjectList.masterItemList.Find(item => item.itemName == "Remove Body Item")); } if ((invListUsed [i].itemID == 4000) && (CreatePCSquirrel.pcSquirrel.itemWornOnFeetID != 4000)) { prevItemWorn = SquirrelPlayerCharacter.getFootItemWorn(CreatePCSquirrel.pcSquirrel); SquirrelPlayerCharacter.removeItemBoosts(CreatePCSquirrel.pcSquirrel, prevItemWorn); // remove item boosts invListUsed.Add (prevItemWorn); // add worn item to inventory SquirrelPlayerCharacter.setItemWorn (CreatePCSquirrel.pcSquirrel, MasterObjectList.masterItemList.Find(item => item.itemName == "Remove Foot Item")); } // if item is clothing, check to see if its slot is empty // if so, add it as an item worn // otherwise add it to the character's inventory if ((invListUsed [i].itemID > 2000) && (invListUsed [i].itemID < 3000)) { if (CreatePCSquirrel.pcSquirrel.itemWornOnHeadID == 2000) { SquirrelPlayerCharacter.setItemWorn (CreatePCSquirrel.pcSquirrel, invListUsed [i]); } else { MasterObjectList.inventory.Add (invListUsed [i]); } } if ((invListUsed [i].itemID > 3000) && (invListUsed [i].itemID < 4000)) { if (CreatePCSquirrel.pcSquirrel.itemWornOnBodyID == 3000) { SquirrelPlayerCharacter.setItemWorn (CreatePCSquirrel.pcSquirrel, invListUsed [i]); } else { MasterObjectList.inventory.Add (invListUsed [i]); } } if ((invListUsed [i].itemID > 4000) && (invListUsed [i].itemID < 5000)) { if (CreatePCSquirrel.pcSquirrel.itemWornOnFeetID == 4000) { SquirrelPlayerCharacter.setItemWorn (CreatePCSquirrel.pcSquirrel, invListUsed [i]); } else { MasterObjectList.inventory.Add (invListUsed [i]); } } // if item is a special item (ie- a star) // add the item to character's inventory if (invListUsed [i].itemID >= 5000) { MasterObjectList.inventory.Add (invListUsed [i]); // add item item to character's inventory } // remove the item from the list (unless it's a remove item button) if ((invListUsed [i].itemName != "Remove Head Item") && (invListUsed [i].itemName != "Remove Body Item") && (invListUsed [i].itemName != "Remove Foot Item")) { invListUsed.Remove (invListUsed[i]); } // sort the list invListUsed.Sort ((a,b) => a.itemID.CompareTo(b.itemID)); } // end button functions GUILayout.Label (itemNameForList + benefitMessage, GUILayout.MinHeight (buttonSize)); GUILayout.EndHorizontal (); } GUILayout.EndVertical (); GUI.EndScrollView (); } else { invBGObject.GetComponent<SpriteRenderer> ().sprite = null; exitButtonObject.GetComponent<SpriteRenderer> ().sprite = null; } }
public static void setItemWorn (SquirrelPlayerCharacter mySquirrel, SSGameItem myItem) { if ((myItem.itemID >= 2000) && (myItem.itemID < 3000)) { mySquirrel.itemWornOnHeadID = myItem.itemID; mySquirrel.itemWornOnHead = myItem; mySquirrel.spriteWornOnHead = myItem.itemDressupSprite; ReSkinHeadGearAnimation.headGearSpriteSheetName = "sprite-worn-" + myItem.itemPicName; } if ((myItem.itemID >= 3000) && (myItem.itemID < 4000)) { mySquirrel.itemWornOnBodyID = myItem.itemID; mySquirrel.itemWornOnBody = myItem; mySquirrel.spriteWornOnBody = myItem.itemDressupSprite; ReSkinBodyGearAnimation.bodyGearSpriteSheetName = "sprite-worn-" + myItem.itemPicName; } if ((myItem.itemID >= 4000) && (myItem.itemID < 5000)) { mySquirrel.itemWornOnFeetID = myItem.itemID; mySquirrel.itemWornOnFeet = myItem; mySquirrel.spriteWornOnFeet = myItem.itemDressupSprite; ReSkinFootGearAnimation.footGearSpriteSheetName = "sprite-worn-" + myItem.itemPicName; } if (myItem.itemBenefit != "none") { string statToBoost; int amountToBoost; statToBoost = myItem.itemBenefit.Substring (3,1); amountToBoost = int.Parse(myItem.itemBenefit.Substring (1,1)); switch (statToBoost) { case "A": CreatePCSquirrel.pcSquirrel.clothingRunBoost += amountToBoost; CreatePCSquirrel.pcSquirrel.clothingJumpBoost += amountToBoost; CreatePCSquirrel.pcSquirrel.clothingClimbBoost += amountToBoost; CreatePCSquirrel.pcSquirrel.squirrelMaxHealthValue += amountToBoost; CreatePCSquirrel.pcSquirrel.squirrelCurrentHealthValue += amountToBoost; SoundEffects.PlaySoundOnHeal (); break; case "C": CreatePCSquirrel.pcSquirrel.clothingClimbBoost += amountToBoost; SoundEffects.PlaySoundOnPickUp (); break; case "H": CreatePCSquirrel.pcSquirrel.squirrelMaxHealthValue += amountToBoost; CreatePCSquirrel.pcSquirrel.squirrelCurrentHealthValue += amountToBoost; SoundEffects.PlaySoundOnHeal (); break; case "J": CreatePCSquirrel.pcSquirrel.clothingJumpBoost += amountToBoost; SoundEffects.PlaySoundOnPickUp (); break; case "R": CreatePCSquirrel.pcSquirrel.clothingRunBoost += amountToBoost; SoundEffects.PlaySoundOnPickUp (); break; default: Debug.Log ("Error adding clothing boost"); break; } } }
void UseItem (SSGameItem myItem) { switch (myItem.itemID) { case 1001: // chocolate doughnut // in order to eat a doughnut, the character needs to be in the neighborhood or adventure, // and not currently under the effect of another doughnut if ((Application.loadedLevel == 11) && (!ItemEffectConsumeDoughnut.isTimerRunning)) { ItemEffectConsumeDoughnut.timerDoughnutTypeString = "c"; ItemEffectConsumeDoughnut.startDoughnutTimer = true; invListUsed.Remove (myItem); } else { SoundEffects.PlayHuhUnh (); } break; case 1002: // jelly doughnut if ((Application.loadedLevel == 11) && (!ItemEffectConsumeDoughnut.isTimerRunning)) { ItemEffectConsumeDoughnut.timerDoughnutTypeString = "j"; ItemEffectConsumeDoughnut.startDoughnutTimer = true; invListUsed.Remove (myItem); } else { SoundEffects.PlayHuhUnh (); } break; case 1003: // sugar doughnut if (((Application.loadedLevel == 10) || (Application.loadedLevel == 11)) && (!ItemEffectConsumeDoughnut.isTimerRunning)) { ItemEffectConsumeDoughnut.timerDoughnutTypeString = "s"; ItemEffectConsumeDoughnut.startDoughnutTimer = true; invListUsed.Remove (myItem); } else { SoundEffects.PlayHuhUnh (); } break; case 1004: // grapes if (CreatePCSquirrel.pcSquirrel.squirrelCurrentHealthValue < 7) { ItemEffectHealthyGrapes.GrapesEffect (); invListUsed.Remove (myItem); } else { SoundEffects.PlayHuhUnh (); } break; case 1005: // apple if ((Application.loadedLevel == 10) || (Application.loadedLevel == 11)) { if (Squirrel_Controller.facingRight) { facingFactor = 1.0f; } else { facingFactor = -1.0f; } Instantiate(applePrefab, new Vector3(myPCSquirrel.transform.position.x + 1.5f * facingFactor, myPCSquirrel.transform.position.y - 1.0f , transform.position.z), Quaternion.identity); invListUsed.Remove (myItem); SoundEffects.PlayDroppedApple (); } else { SoundEffects.PlayHuhUnh (); } break; case 1006: // banana if (CreatePCSquirrel.pcSquirrel.squirrelCurrentHealthValue < CreatePCSquirrel.pcSquirrel.squirrelMaxHealthValue) { ItemEffectHealthyBanana.BananaEffect(); invListUsed.Remove (myItem); } else { SoundEffects.PlayHuhUnh (); } break; case 5001: // climb star CreatePCSquirrel.pcSquirrel.squirrelClimbValue ++; invListUsed.Remove (myItem); break; case 5002: // health star CreatePCSquirrel.pcSquirrel.squirrelMaxHealthValue ++; CreatePCSquirrel.pcSquirrel.squirrelCurrentHealthValue ++; SoundEffects.PlaySoundOnHeal (); invListUsed.Remove (myItem); break; case 5003: // jump star CreatePCSquirrel.pcSquirrel.squirrelJumpValue ++; invListUsed.Remove (myItem); break; case 5004: // run star CreatePCSquirrel.pcSquirrel.squirrelRunValue ++; invListUsed.Remove (myItem); break; default: // clothing // add previously worn item to inventory if ((myItem.itemID > 2000) && (myItem.itemID < 3000)) { prevItemWorn = SquirrelPlayerCharacter.getHeadItemWorn(CreatePCSquirrel.pcSquirrel); if (prevItemWorn.itemID != 2000) { SquirrelPlayerCharacter.removeItemBoosts(CreatePCSquirrel.pcSquirrel, prevItemWorn); // remove item boosts invListUsed.Add (SquirrelPlayerCharacter.getHeadItemWorn(CreatePCSquirrel.pcSquirrel)); // add worn item to inventory } } else if ((myItem.itemID > 3000) && (myItem.itemID < 4000)) { prevItemWorn = SquirrelPlayerCharacter.getBodyItemWorn(CreatePCSquirrel.pcSquirrel); if (prevItemWorn.itemID != 3000) { SquirrelPlayerCharacter.removeItemBoosts(CreatePCSquirrel.pcSquirrel, prevItemWorn); // remove item boosts invListUsed.Add (SquirrelPlayerCharacter.getBodyItemWorn(CreatePCSquirrel.pcSquirrel)); // add worn item to inventory } } else if ((myItem.itemID > 4000) && (myItem.itemID < 5000)) { prevItemWorn = SquirrelPlayerCharacter.getFootItemWorn(CreatePCSquirrel.pcSquirrel); if (prevItemWorn.itemID != 4000) { SquirrelPlayerCharacter.removeItemBoosts(CreatePCSquirrel.pcSquirrel, prevItemWorn); // remove item boosts invListUsed.Add (SquirrelPlayerCharacter.getFootItemWorn(CreatePCSquirrel.pcSquirrel)); // add worn item to inventory } } // set the worn item slot to the selected item SquirrelPlayerCharacter.setItemWorn (CreatePCSquirrel.pcSquirrel, myItem); // remove the item from the list invListUsed.Remove (myItem); // sort the list invListUsed.Sort ((a,b) => a.itemID.CompareTo(b.itemID)); break; // default clothing } // end switch statement } // end use item method
void TransferItem (SSGameItem myItem) { MasterObjectList.wardrobe.Add (myItem); MasterObjectList.inventory.Remove (myItem); SoundEffects.PlaySquirrelStashed (); }
} // end OnGUI void SellItem (SSGameItem myItem) { saleMade = true; // see section in Update method itemSold = myItem; SoundEffects.PlayNutsDropping (); }
} // end update void OnGUI () { GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUI.skin.label.richText = true; GUI.skin.label.fontSize = Screen.width/1536*54; GUI.skin.label.fontStyle = FontStyle.Normal; GUI.skin.button.alignment = TextAnchor.MiddleCenter; GUI.skin.button.richText = true; GUI.skin.button.fontStyle = FontStyle.Normal; if (displayInventoryContents) { GUI.skin.button.fontSize = Screen.width / 1536 * 36; GUI.skin.verticalScrollbar.fixedWidth = Screen.width * 0.05f; GUI.skin.verticalScrollbarThumb.fixedWidth = Screen.width * 0.05f; GUI.skin.label.alignment = TextAnchor.MiddleLeft; GUILayout.BeginArea (new Rect (msgWindowX, msgWindowY, msgWindowWidth, msgWindowHeight )); //message Window GUI.skin.label.fixedWidth = 0; GUI.skin.label.fontSize = Screen.width / 1536 * 48; GUI.skin.label.alignment = TextAnchor.UpperCenter; GUI.skin.label.wordWrap = true; GUI.skin.label.richText = true; GUI.skin.label.fontStyle = FontStyle.Normal; GUI.color = Color.red; GUILayout.Label(actionMessage, GUILayout.MinHeight(50), GUILayout.MaxHeight(150)); GUI.color = Color.white; GUILayout.EndArea(); GUI.skin.label.fontSize = Screen.width / 1536 * 32; scrollPosition = GUI.BeginScrollView (new Rect (inventoryWindowX, inventoryWindowY, inventoryWindowWidth, inventoryWindowHeight), scrollPosition, new Rect (0, 0, inventoryWindowWidth - Screen.width * 0.05f - 1, Mathf.Max (inventoryWindowHeight, invListUsed.Count * (buttonSize + 5))), false, true); GUILayout.BeginVertical (); for (i = 0; i < invListUsed.Count; i++) { // determine message next to button itemNameForList = invListUsed[i].itemName; if ((invListUsed [i].itemCost != 0) && (typeOfAction == InventoryAcitonType.Sell)) { costMessage = "\nSell price: " + invListUsed [i].itemCost; } else { costMessage = ""; } if (invListUsed [i].itemBenefit == "none") { benefitMessage = ""; } else { benefitMessage = "\nBenefit: " + invListUsed[i].itemBenefit; } // make the list of buttons GUILayout.BeginHorizontal (); if (GUILayout.Button (invListUsed[i].itemButtonPic, GUILayout.Height (buttonSize), GUILayout.Width (buttonSize))) { if (invListUsed [i].itemName == "Stash Acorns") { performStashAcorns = true; // see section in Update method } // if its the remove hat button (and the hat slot is not empty) if ((invListUsed [i].itemID == 2000) && (SquirrelPlayerCharacter.getHeadItemWorn(CreatePCSquirrel.pcSquirrel).itemID != 2000)) { prevItemWorn = SquirrelPlayerCharacter.getHeadItemWorn(CreatePCSquirrel.pcSquirrel); SquirrelPlayerCharacter.removeItemBoosts(CreatePCSquirrel.pcSquirrel, prevItemWorn); // remove item boosts invListUsed.Add (prevItemWorn); // add worn item to inventory SquirrelPlayerCharacter.setItemWorn (CreatePCSquirrel.pcSquirrel, invListUsed [i]); // empty out the slot } // if its the remove shirt button (and the slot is not empty) if ((invListUsed [i].itemID == 3000) && (SquirrelPlayerCharacter.getBodyItemWorn(CreatePCSquirrel.pcSquirrel).itemID != 3000)) { prevItemWorn = SquirrelPlayerCharacter.getBodyItemWorn(CreatePCSquirrel.pcSquirrel); SquirrelPlayerCharacter.removeItemBoosts(CreatePCSquirrel.pcSquirrel, prevItemWorn); // remove item boosts invListUsed.Add (prevItemWorn); // add worn item to inventory SquirrelPlayerCharacter.setItemWorn (CreatePCSquirrel.pcSquirrel, invListUsed [i]); // empty out the slot } // if its the remove shoes button (and the slot is not empty) if ((invListUsed [i].itemID == 4000) && (SquirrelPlayerCharacter.getFootItemWorn(CreatePCSquirrel.pcSquirrel).itemID != 4000)) { prevItemWorn = SquirrelPlayerCharacter.getFootItemWorn(CreatePCSquirrel.pcSquirrel); SquirrelPlayerCharacter.removeItemBoosts(CreatePCSquirrel.pcSquirrel, prevItemWorn); // remove item boosts invListUsed.Add (prevItemWorn); // add worn item to inventory SquirrelPlayerCharacter.setItemWorn (CreatePCSquirrel.pcSquirrel, invListUsed [i]); // empty out the slot } if ((invListUsed [i].itemID != 2000) && (invListUsed [i].itemID != 3000) // if its not one of the inventory managaement buttons && (invListUsed [i].itemID != 4000) && invListUsed [i].itemID != 2) { switch (typeOfAction) { // do something with it case InventoryAcitonType.Sell: SellItem (invListUsed[i]); break; case InventoryAcitonType.Transfer: TransferItem (invListUsed[i]); break; case InventoryAcitonType.Use: UseItem (invListUsed[i]); break; default: break; } //end switch (typeOfAction) } // resort the inventory list after performing the actions invListUsed.Sort ((a,b) => a.itemID.CompareTo(b.itemID)); } // end button functions GUI.skin.label.fixedWidth = Screen.width * (inventoryWindowWidth - 0.05f) - buttonSize; GUI.skin.label.alignment = TextAnchor.MiddleLeft; GUILayout.Label (itemNameForList + costMessage + benefitMessage, GUILayout.MinHeight (buttonSize)); GUI.skin.label.fixedWidth = 0; GUILayout.EndHorizontal (); } // end for loop GUILayout.EndVertical (); GUI.EndScrollView (); } // end display inventory contents } // end OnGUI