Ejemplo n.º 1
0
        private void OnMouseDown()
        {
            if (!CombatManager.instance.FightButtonPressed())
            {
                return;
            }

            bool inRange = false;
            //TODO: Get the current hero
            GameManager GM   = GameObject.Find("GameManager").GetComponent <GameManager>();
            Hero        hero = GameObject.Find(GM.GetHeroByPID(HeroSelection.HS.mySelectedCharacter)).GetComponent <HeroController>().getHero();

            //Don't start combat if no time left
            if (!hero.HasTimeLeft())
            {
                return;
            }
            //If on same tile, you are in range
            if (hero.getRank() == currentPosition.GetComponent <Node>().getRank())
            {
                inRange = true;
            }
            else if (hero.getHeroKind() == HeroKind.Archer || hero.IsCarrying(new Bow(ItemWeight.Heavy)))
            {
                //If you are archer/have bow and are on a neighbouring tile, you are in range
                foreach (GameObject neighbour in currentPosition.GetComponent <Node>().getNeighbours())
                {
                    Node node = neighbour.GetComponent <Node>();
                    if (hero.getRank() == node.getRank())
                    {
                        inRange = true;
                    }
                }
            }
            if (!inRange)
            {
                return;
            }
            bool princePresent        = false;
            ThoraldController thorald = FindObjectOfType <ThoraldController>();

            if (thorald != null && thorald.currentPosition.GetComponent <Node>().getRank() == currentPosition.GetComponent <Node>().getRank())
            {
                princePresent = true;
            }
            //Search for heroes to join the fight
            GameManager gm     = FindObjectOfType <GameManager>();
            List <Hero> heroes = new List <Hero>();

            foreach (GameObject g in gm.HeroList)
            {
                Hero h = g.GetComponent <HeroController>().getHero();
                if (h.Equals(hero))
                {
                    break;
                }
                if (h.getRank() == currentPosition.GetComponent <Node>().getRank())
                {
                    heroes.Add(h);
                }
                else if (h.getHeroKind() == HeroKind.Archer || hero.IsCarrying(new Bow(ItemWeight.Heavy)))
                {
                    foreach (GameObject neighbour in currentPosition.GetComponent <Node>().getNeighbours())
                    {
                        Node node = neighbour.GetComponent <Node>();
                        if (h.getRank() == node.getRank())
                        {
                            heroes.Add(h);
                            break;
                        }
                    }
                }
            }
            CombatManager.instance.setMonsterFighterID(currentPosition.GetComponent <Node>().getRank());
            CombatParty party = new CombatParty(hero);

            StartCoroutine(CombatManager.instance.CallForHelp(party, heroes, monster, princePresent));
            //Combat combat = new Combat(party, monster, princePresent);
            //CombatManager.instance.StartCombatRound(combat);
        }
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);
            }
        }