public void OnButtonPressed()
 {
     if (inShop)
     {
         Hero hero = FindObjectOfType <HeroController>().getHero();
         if (item == null && sp)
         {
             if (hero.getHeroKind() == HeroKind.Dwarf && merchant.isMine && hero.getGold() >= 1)
             {
                 hero.setStrengthPoints(hero.getStrengthPoints() + 1);
                 hero.IncrementGold(-1);
             }
             else if (hero.getGold() >= 2)
             {
                 hero.setStrengthPoints(hero.getStrengthPoints() + 1);
                 hero.IncrementGold(-2);
             }
         }
         //Buy from witch
         else if (item.GetType() == typeof(WitchsBrew))
         {
             int cost = FindObjectOfType <GameManager>().HeroList.Count + 1;
             //Archer discount
             if (hero.getHeroKind() == HeroKind.Archer && hero.getGold() >= cost - 1)
             {
                 hero.addItem(new WitchsBrew(ItemWeight.Light));
                 hero.IncrementGold(-1 * (cost - 1));
             }
             else if (hero.getGold() >= cost)
             {
                 hero.addItem(new WitchsBrew(ItemWeight.Light));
                 hero.IncrementGold(-1 * cost);
             }
         }
         else if (hero.getGold() >= 2)
         {
             hero.addItem(item);
             hero.IncrementGold(-2);
         }
     }
     else if (item == null)
     {
         return;
     }
     else if (item.GetType().IsSubclassOf(typeof(UsableItem)))
     {
         ((UsableItem)item).Use();
     }
 }
		// 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 takeWitchsBrew(Hero hero)
        {
            if (witchsBrew != null)
            {
                hero.addItem(witchsBrew);
                witchsBrew = null;
                return(true);
            }

            return(false);
        }
예제 #4
0
        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
        }
예제 #5
0
        public bool ExecuteExchange()
        {
            //checks that both heroes still have the gold and items to be traded
            if (hero1.getGold() < goldToHero2 ||
                hero2.getGold() < goldToHero1 ||
                falcon.getUsedToday())
            {
                return(false);
            }

            foreach (Item i in itemsToHero2)
            {
                if (!hero1.IsCarrying(i))
                {
                    return(false);
                }
            }

            foreach (Item i in itemsToHero1)
            {
                if (!hero2.IsCarrying(i))
                {
                    return(false);
                }
            }

            //executes the trade
            if (tradeStatus == TradeStatus.Final)
            {
                //removes items
                hero1.setGold(hero1.getGold() - goldToHero2);
                hero2.setGold(hero2.getGold() - goldToHero1);

                foreach (Item i in itemsToHero2)
                {
                    hero1.DiscardItem(i);
                }

                foreach (Item i in itemsToHero1)
                {
                    hero2.DiscardItem(i);
                }

                //adds items
                hero1.IncrementGold(goldToHero1);
                hero2.IncrementGold(goldToHero2);

                foreach (Item i in itemsToHero1)
                {
                    hero1.addItem(i);
                }

                foreach (Item i in itemsToHero2)
                {
                    hero2.addItem(i);
                }

                falcon.setUsedToday(true);

                return(true);
            }
            else
            {
                return(false);
            }
        }