public void PickupItem(GameObject item) { if (playerInventory == null) { playerInventory = CurrentLevelVariableManagement.GetMainInventoryReference().GetComponent <InventoryFunctions> (); } //This does not check the resourcereference property of the attached script as a comparison, only the tag. Consider changing later. if (item.CompareTag("ExpNodule")) { transform.parent.gameObject.GetComponent <PlayerHealthPanelManager> ().OnExperienceNodulePickedUp(); Destroy(item); } else if (item.CompareTag("Coin")) { transform.parent.gameObject.GetComponent <PlayerHealthPanelManager> ().OnCoinPickedUp(1); Destroy(item); } else { ResourceReferenceWithStack pendingObject = item.GetComponent <DroppedItemProperties> ().localResourceReference; if (!playerInventory.AssignNewItemToBestSlot(pendingObject)) { Debug.LogError("ERROR WHEN ASSIGNING OBJECT"); } else { Destroy(item); } } }
//When a new item is added. public void OnNewItemAddedToPlayerInventory() { switch (CurrentLevelVariableManagement.GetMainGameData().currentLevel) { case 0: //Check to make sure the objective has not already been completed //Wooden Pickaxe Objective if (objectives [0].completed == false) { //Check whether the player has the hatchet. if (CurrentLevelVariableManagement.GetMainInventoryReference().GetComponent <InventoryFunctions> ().CheckForCertainInventoryItem(new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Wooden Pickaxe"), 1)) != null) { OnObjectiveHasBeenCompleted(1); } } // // //Wooden Sword Objective // if (objectives [3].completed == false) { // if (ModifiesSlotContent.DetermineWhetherPlayerHasCertainInventoryItem(new UISlotContentReference(ResourceDatabase.GetItemByParameter ("Wooden Pickaxe"), 1)) != null) { // OnObjectiveHasBeenCompleted(4); // } // } break; default: Debug.LogError("Objective Manager does not have a definition for this level!"); break; } }
//Done during the InitializePurchasePanels phase (no real dependencies). void InitializePurchasePanelReference() { //Define required components. currentItemIcon = transform.Find("Animation Controller").Find("Item Icon").GetComponent <SpriteRenderer> (); cost = transform.Find("Animation Controller").Find("Value").Find("Cost").GetComponent <TextMesh> (); //Not accessible in the editor, but can be modified via code. (Looks weird otherwise). cost.GetComponent <MeshRenderer> ().sortingLayerName = "PPanelFront"; cost.GetComponent <MeshRenderer> ().sortingOrder = 0; player = CurrentLevelVariableManagement.GetPlayerReference().transform; playerInventory = CurrentLevelVariableManagement.GetMainInventoryReference().gameObject.GetComponent <InventoryFunctions> (); StartCoroutine(CheckForPurchase()); }
//Initializing the NPC protected override void InitializeCharacter() { //Get required components. playerTransform = CurrentLevelVariableManagement.GetPlayerReference().transform; playerInventory = CurrentLevelVariableManagement.GetMainInventoryReference().GetComponent <InventoryFunctions> (); //Initialize the NPC before starting to walk around. InitializeNPC(); //Create and start the coroutine. walkAroundCoroutine = WalkAround(); StartCoroutine(walkAroundCoroutine); }
//When an item drop hits the player. void OnTriggerEnter2D(Collider2D externalTrigger) { if (playerInventory == null) { playerInventory = CurrentLevelVariableManagement.GetMainInventoryReference().GetComponent <InventoryFunctions> (); } if (((externalTrigger.gameObject.GetComponent <DroppedItemProperties> () != null || externalTrigger.gameObject.CompareTag("Coin") || externalTrigger.gameObject.CompareTag("ExpNodule"))) && playerInventory.IsInitialized()) { PickupItem(externalTrigger.gameObject); } }
/******************************* MOUSE CLICK MANAGER *******************************/ public void OnPointerClick(PointerEventData data) { if (data.button == PointerEventData.InputButton.Left) { if (currentlyAssigned != null) { if (CurrentLevelVariableManagement.GetPlayerReference().GetComponent <PlayerHealthPanelManager> ().GiveMoneyToPlayer(-currentlyAssigned.price)) { //Add the deassigned item to the player inventory and deduct the price of the item. CurrentLevelVariableManagement.GetMainInventoryReference().GetComponent <InventoryFunctions> ().AssignNewItemToBestSlot(new ResourceReferenceWithStack(currentlyAssigned.mainContentReference.uiSlotContent, 1)); ModifyCurrentItemStack(-1); } } } }
void InitializeSpriteChildren() { mainPlayerAction = transform.parent.parent.gameObject.GetComponent <PlayerAction> (); playerInventory = CurrentLevelVariableManagement.GetMainInventoryReference().GetComponent <InventoryFunctions> (); //Just setting up the basic race costume. body = transform.Find("Body").GetComponent <SpriteRenderer> (); head = transform.Find("Head").GetComponent <SpriteRenderer> (); idleArm = transform.Find("Hands").Find("IdleHand").GetComponent <SpriteRenderer> (); holdingArm = transform.Find("Hands").Find("HoldingHand").GetComponent <SpriteRenderer> (); topLeg = transform.Find("Legs").Find("Top Leg").GetComponent <SpriteRenderer> (); bottomLeg = transform.Find("Legs").Find("Bottom Leg").GetComponent <SpriteRenderer> (); holdingItem = holdingArm.transform.Find("HoldingItem"); Profession currentPlayerProfession = CurrentLevelVariableManagement.GetMainGameData().chosenProfession; UpdatePlayerProfession(currentPlayerProfession); }
/**************************** TUTORIAL ****************************/ public void OnCurrentLevelCompleted() { Debug.Log("Gathering player data..."); //Get player money. GetComponent <GameData> ().currentPlayerMoney = CurrentLevelVariableManagement.GetPlayerReference().GetComponent <PlayerHealthPanelManager> ().GetPlayerMoney(); Debug.Log("Set player money to " + GetComponent <GameData> ().currentPlayerMoney); //Get player items. GetComponent <GameData> ().currentPlayerItems = CurrentLevelVariableManagement.GetMainInventoryReference().GetComponent <InventoryFunctions> ().GetAllPlayerItems(); Debug.Log("Player has " + GetComponent <GameData> ().currentPlayerItems.Length + " items"); Debug.Log("Tutorial has been completed!"); //Increment the current level. GetComponent <GameData> ().currentLevel += 1; //Load the Profession Chooser for the next level SceneManager.LoadScene("Profession Chooser"); }