// commented since it is simply List.Add /* public bool addItemForSale(ItemForSale itemForSale) { itemsForSale.Add(itemForSale); } */ // can not check the input item since it is an instance // use a newly created enum class ItemForSale /* public bool buyItemForSale(Hero hero, Item item) { if (hero != null && item != null && itemsForSale.ContainsKey(item)) { int price = itemsForSale[item]; if(hero.getGold() >= price) { itemsForSale.Remove(item); hero.setGold(hero.getGold() - price); hero.addItem(item); return true; } } return false; } */ public bool buyItemForSale(Hero hero, ItemForSale item) { if (hero != null && itemsForSale.Contains(item)) { int price = 2; if (isMine && hero.getHeroKind() == HeroKind.Dwarf && item == ItemForSale.SP) price = 1; // dwarf get a discount if (hero.getGold() >= price) { Item newItem=new Item(ItemWeight.Light); //ItemWeight.Light as placehoder for initialization if (item== ItemForSale.SP) { hero.setGold(hero.getGold() - price); hero.setStrengthPoints(hero.getStrengthPoints() + 1); return true; } else { if (item == ItemForSale.Wineskin) newItem = new Wineskin(ItemWeight.Light); if (item == ItemForSale.Falcon) newItem = new Falcon(ItemWeight.Heavy); if (item == ItemForSale.Telescope) newItem = new Telescope(ItemWeight.Light); if (item == ItemForSale.Helm) newItem = new Helm(ItemWeight.Light); if (item == ItemForSale.Shield) newItem = new Shield(ItemWeight.Heavy); if (item == ItemForSale.Bow) newItem = new Bow(ItemWeight.Heavy); } hero.setGold(hero.getGold() - price); hero.addItem(newItem); return true; } } return false; }
public bool activate(Hero hero) { //need to reveal first; if (this.revealed != true) { reveal(); } string description = ""; if (this.fogKind != FogKind.None) { if (this.fogKind == FogKind.TwoWP) { hero.setWillpowerPoints(hero.getWillpowerPoints() + 2); } if (this.fogKind == FogKind.Witch) { int roll = Random.Range(1, 7); Debug.Log(roll); int rank = -1; Region r = null; if (roll == 1 || roll == 2) { r = GameObject.Find("R (37)").GetComponent <Node>().GetRegion(); rank = 37; Vector3 position = new Vector3(-3.72f, 0.0f, -4.35f); GameObject.Find("GameManager").GetComponent <GameManager>().updateHerb(true, position); } if (roll == 3 || roll == 4) { r = GameObject.Find("R (67)").GetComponent <Node>().GetRegion(); rank = 67; Vector3 position = new Vector3(5.17f, 0.0f, -2.02f); GameObject.Find("GameManager").GetComponent <GameManager>().updateHerb(true, position); } if (roll == 5 || roll == 6) { r = GameObject.Find("R (61)").GetComponent <Node>().GetRegion(); rank = 61; Vector3 position = new Vector3(6.24f, 0.0f, 1.18f); GameObject.Find("GameManager").GetComponent <GameManager>().updateHerb(true, position); } r.setHerb(true); string show = revealedFogDescription(); string show2 = show + "\n\nHerb is on space " + rank; GameObject FogInfo = GameObject.Find("FogInfo").transform.GetChild(0).gameObject; GameObject DUI = null; 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 = show2; FogInfo.SetActive(true); GameObject.Find("GameManager").GetComponent <GameManager>().witchFound = true; } if (this.fogKind == FogKind.ThreeWP) { hero.setWillpowerPoints(hero.getWillpowerPoints() + 3); } if (this.fogKind == FogKind.SP) { hero.setStrengthPoints(hero.getStrengthPoints() + 1); } if (this.fogKind == FogKind.Gold) { hero.setGold(hero.getGold() + 1); } if (this.fogKind == FogKind.Wineskin) { Wineskin wineskin = (Wineskin)this.hiddenObject; hero.addItem(wineskin); Debug.Log("wineskin added"); } if (this.fogKind == FogKind.Event) { ((Event)getHiddenObject()).applyEventEffect(); } if (this.fogKind != FogKind.Event && this.fogKind != FogKind.Witch) { // method below return a string of the description // event has its own description, so first check whether what hidden is event or not description = revealedFogDescription(); GameObject FogInfo = GameObject.Find("FogInfo").transform.GetChild(0).gameObject; GameObject DUI = null; for (int i = 0; i < FogInfo.transform.childCount; i++) { if (FogInfo.transform.GetChild(i).transform.name == "Description") { DUI = FogInfo.transform.GetChild(i).gameObject; } } DUI.GetComponent <Text>().text = description; FogInfo.SetActive(true); } // after the fog effect, set fogkind to None this.fogKind = FogKind.None; GameObject.Find("GameManager").GetComponent <GameManager>().updateFog(); return(true); } return(false); // the fog has already been activated }