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();
     }
 }
Ejemplo n.º 2
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);
            }
        }