Exemplo n.º 1
0
        private IEnumerator DetermineCharacterActions(IList <Character> chars, IList <IPlayable> plays, HashSet <Character> playerActionSet)
        {
            ICollection <PooledBehaviour> declarations = new List <PooledBehaviour>();

            for (int i = 0; i < chars.Count; i++)
            {
                Character c = chars[i];

                if (c.Stats.State == State.ALIVE)
                {
                    PooledBehaviour textbox = null;

                    // Only show when player controlled is asked to make a move
                    bool brainIsPlayer = (c.Brain is Player);

                    // Helps show user which character is doing stuff
                    if (brainIsPlayer)
                    {
                        textbox = AddText(string.Format(PLAYER_QUESTION, c.Look.DisplayName));
                    }

                    // Wait until this is true until we ask the next character what action they want to perform
                    bool isActionTaken = false;

                    // Pass to the Brain a func that lets that lets them pass us what action they want to take
                    c.Brain.PreActionSetup(
                        temporarySpells,
                        (p) => InBattlePlayHandler(playerActionSet, plays, c, ref isActionTaken, p));

                    // Let brain decide now
                    c.Brain.DetermineAction();

                    // Wait until they choose a move. (This so the player can wait as long as they want)
                    yield return(new WaitWhile(() => !isActionTaken));

                    ClearActionGrid();

                    if (textbox != null)
                    {
                        ObjectPoolManager.Instance.Return(textbox); // Remove "What will X do?" textbox, reduce clutter
                    }

                    if (brainIsPlayer)
                    {
                        Spell spell = plays.Last().MySpell;
                        declarations.Add(AddText(
                                             new TextBox(
                                                 spell.SpellDeclareText,
                                                 spell.Book.TextboxTooltip
                                                 ))); // "X will do Y" helper textbox
                    }
                }
            }

            // Remove all "X will do Y" texts
            foreach (PooledBehaviour pb in declarations)
            {
                ObjectPoolManager.Instance.Return(pb);
            }
        }
Exemplo n.º 2
0
        public PooledBehaviour AddTextBox(TextBox textBox)
        {
            while (transform.childCount > MAX_NUMBER_OF_TEXTBOXES)
            {
                ObjectPoolManager.Instance.Return(transform.GetComponentsInChildren <PooledBehaviour>()[0]);
            }
            if (string.IsNullOrEmpty(textBox.RawText))
            {
                return(null);
            }
            PooledBehaviour pb = ObjectPoolManager.Instance.Get(textBoxes[textBox.Type]);

            Util.Parent(pb.gameObject, gameObject);
            pb.transform.SetAsLastSibling();
            textBox.SetupPrefab(pb.gameObject);
            textBox.Write();
            return(pb);
        }