public void heroMove(GameObject newPos) { hide(); if (hero.FreeMoveSpaces > 0) { hero.FreeMoveSpaces--; } else { timeTrack.tick(); if (timeTrack.getTime() > 7) { if (GameObject.Find("GameManager").GetComponent <GameManager>().getEventsApplied().Contains(EventKind.Event19) && timeTrack.getTime() > 8) { hero.setWillpowerPoints(hero.getWillpowerPoints() - 3); } else if (GameObject.Find("GameManager").GetComponent <GameManager>().getEventsApplied().Contains(EventKind.Event26) && timeTrack.getTime() == 8) { // do nothing } else { hero.setWillpowerPoints(hero.getWillpowerPoints() - 2); } } } setCurrentPosition(newPos); hero.setRank(newPos.GetComponent <Node>().getRank()); if (PV.IsMine) { PV.RPC("updateRank", RpcTarget.AllBuffered, hero.getRank()); } foreach (GameObject farmer in farmersCarried) { farmer.GetComponent <FarmerController>().setNode(newPos); } // pick up items on the ground on specific region if (newPos.GetComponent <Node>().GetRegion().getRank() == 72 && newPos.GetComponent <Node>().GetRegion().hasItem()) { List <Item> itemOnGround = newPos.GetComponent <Node>().GetRegion().getItems(); foreach (Item i in itemOnGround.ToArray()) { if (i.GetType() == typeof(Wineskin)) { hero.pickUpItemOnGround(newPos.GetComponent <Node>().GetRegion(), new Wineskin(ItemWeight.Light)); GameObject.Find("GameManager").GetComponent <GameManager>().updateEvent(EventKind.Event30, false, new Vector3(0, 0, 0), null, null); } } } if (newPos.GetComponent <Node>().GetRegion().getRank() == 57 && newPos.GetComponent <Node>().GetRegion().hasItem()) { List <Item> itemOnGround = newPos.GetComponent <Node>().GetRegion().getItems(); foreach (Item i in itemOnGround.ToArray()) { if (i.GetType() == typeof(Shield)) { hero.pickUpItemOnGround(newPos.GetComponent <Node>().GetRegion(), new Shield(ItemWeight.Heavy)); GameObject.Find("GameManager").GetComponent <GameManager>().updateEvent(EventKind.Event29, false, new Vector3(0, 0, 0), null, null); } } } // track some events if (newPos.GetComponent <Node>().GetRegion().getRank() >= 22 && newPos.GetComponent <Node>().GetRegion().getRank() <= 24) { if (GameObject.Find("R (24)").GetComponent <Node>().GetRegion().getEvents().Contains(EventKind.Event21)) { hero.setWillpowerPoints(hero.getWillpowerPoints() - 4); GameObject.Find("R (24)").GetComponent <Node>().GetRegion().removeEvent(EventKind.Event21); GameObject.Find("GameManager").GetComponent <GameManager>().updateEvent(EventKind.Event21, false, new Vector3(0, 0, 0), "", ""); } } if (newPos.GetComponent <Node>().GetRegion().getRank() == 57 && newPos.GetComponent <Node>().GetRegion().getEvents() != null) { List <EventKind> list = newPos.GetComponent <Node>().GetRegion().getEvents(); foreach (EventKind ek in list.ToArray()) { if (ek == EventKind.Event8) { GameObject EventUI = GameObject.Find("EventParent").transform.GetChild(0).gameObject; GameObject DUI = null; GameObject EUI = null; GameObject YesButton = null; GameObject NoButton = null; for (int i = 0; i < EventUI.transform.childCount; i++) { if (EventUI.transform.GetChild(i).transform.name == "Description") { DUI = EventUI.transform.GetChild(i).gameObject; } if (EventUI.transform.GetChild(i).transform.name == "Effect") { EUI = EventUI.transform.GetChild(i).gameObject; } if (EventUI.transform.GetChild(i).transform.name == "EventYes") { YesButton = EventUI.transform.GetChild(i).gameObject; } if (EventUI.transform.GetChild(i).transform.name == "EventNo") { NoButton = EventUI.transform.GetChild(i).gameObject; } } DUI.GetComponent <Text>().text = ""; EUI.GetComponent <Text>().text = "Want to buy 2 wp with 2 golds?"; YesButton.SetActive(true); NoButton.SetActive(true); EventUI.SetActive(true); } if (ek == EventKind.Event3) { hero.setStrengthPoints(hero.getStrengthPoints() + 1); GameObject.Find("GameManager").GetComponent <GameManager>().updateEvent(EventKind.Event3, false, new Vector3(0, 0, 0), "", ""); newPos.GetComponent <Node>().GetRegion().removeEvent(EventKind.Event3); } } } if (newPos.GetComponent <Node>().GetRegion().getHerb() && newPos.GetComponent <Node>().GetRegion().getRank() != 0) { newPos.GetComponent <Node>().GetRegion().setHerb(false); GameObject FogInfo = GameObject.Find("FogInfo").transform.GetChild(0).gameObject; GameObject DUI = null; string toDisplay = "Herb picked"; for (int i = 0; i < FogInfo.transform.childCount - 1; i++) { if (FogInfo.transform.GetChild(i).transform.name == "Description") { DUI = FogInfo.transform.GetChild(i).gameObject; } } DUI.GetComponent <Text>().text = toDisplay; FogInfo.SetActive(true); hero.setHerb(true); GameObject.Find("GameManager").GetComponent <GameManager>().updateHerb(false, new Vector3(0, 0, 0)); } if (newPos.GetComponent <Node>().GetRegion().getRank() == 0 && hero.getHerb()) { hero.setHerb(false); newPos.GetComponent <Node>().GetRegion().setHerb(true); GameObject FogInfo = GameObject.Find("FogInfo").transform.GetChild(0).gameObject; GameObject DUI = null; string toDisplay = "Herb dropped"; for (int i = 0; i < FogInfo.transform.childCount - 1; i++) { if (FogInfo.transform.GetChild(i).transform.name == "Description") { DUI = FogInfo.transform.GetChild(i).gameObject; } } DUI.GetComponent <Text>().text = toDisplay; FogInfo.SetActive(true); hero.setHerb(false); GameObject.FindObjectOfType <GameManager>().HerbInCastle = true; } if (newPos.GetComponent <Node>().GetRegion().hasItem()) { List <Item> items = newPos.GetComponent <Node>().GetRegion().getItems(); Item toPick = null; foreach (Item i in items) { if (i.GetType() == typeof(Runestone)) { toPick = i; } } if (toPick != null) { hero.pickUpItemOnGround(newPos.GetComponent <Node>().GetRegion(), toPick); GameObject RunestoneUI = GameObject.Find("RunestoneUI").transform.GetChild(0).gameObject; GameObject DUI = null; string toDisplay = "One rune stone found and picked up!"; for (int i = 0; i < RunestoneUI.transform.childCount - 1; i++) { if (RunestoneUI.transform.GetChild(i).transform.name == "Description") { DUI = RunestoneUI.transform.GetChild(i).gameObject; } } DUI.GetComponent <Text>().text = toDisplay; RunestoneUI.SetActive(true); } } // when step on a fog, reveal and activate it. GameObject gameManager = GameObject.Find("GameManager"); foreach (TileUnit u in newPos.GetComponent <Node>().GetRegion().getTileUnits().ToArray()) { if (u.GetType() == typeof(Fog)) { ((Fog)u).reveal(); // update() in gameManager calls every frame, I don't know if that means each method, so here I call manually //gameManager.GetComponent<GameManager>().updateFog(); ((Fog)u).activate(this.hero); //gameManager.GetComponent<GameManager>().updateFog(); } } foreach (GameObject m in gameManager.GetComponent <GameManager>().getMonsterList()) { if (m.GetComponent <MonsterController>().getCurrentPosition().GetComponent <Node>().getRank() == currentPosition.GetComponent <Node>().getRank()) { foreach (GameObject farmer in farmersCarried) { farmer.SetActive(false); } farmersCarried = new List <GameObject>(); } } if (newPos.GetComponent <Node>().getRank() == 0) { for (int i = 0; i < farmersCarried.Count; i++) { gameManager.GetComponent <GameManager>().getCastle().addGoldenShield(); farmersCarried[i].SetActive(false); } gameManager.GetComponent <GameManager>().getCastleHealth().GetComponent <UnityEngine.UI.Text>().text = gameManager.GetComponent <GameManager>().getCastle().getNumGoldenShields().ToString(); farmersCarried = new List <GameObject>(); } }