Beispiel #1
0
        private static Grid GenerateSpellableGrid(
            bool isTargetingSelf,
            Page current,
            IButtonable previous,
            Character owner,
            SpellBook excluded,
            IEnumerable <ISpellable> spellCollection,
            Action <IPlayable> addPlay,
            Sprite sprite,
            string name,
            string description)
        {
            Grid grid = GenerateBackableGrid(previous, sprite, name, description);

            foreach (ISpellable myS in spellCollection)
            {
                ISpellable s = myS;
                if (!s.Equals(excluded))
                {
                    grid.List.Add(GenerateSpellProcess(current, grid, owner, s, addPlay, isTargetingSelf));
                }
            }

            return(grid);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a subgrid containing user's equipment
        /// </summary>
        /// <param name="previous">supergrid</param>
        /// <param name="owner">Owner of the equipment</param>
        /// <param name="handlePlayable">Playable handler</param>
        /// <param name="isInCombat">If in combat, text is "Equipment", otherwise it's the owner's name</param>
        /// <returns></returns>
        public static Grid GenerateEquipmentGrid(Page current, IButtonable previous, Character owner, Action <IPlayable> handlePlayable, bool isInCombat)
        {
            Grid grid = GenerateBackableGrid(
                previous,
                isInCombat ? EQUIPMENT : owner.Look.Sprite,
                isInCombat ? "Equipment" : owner.Look.DisplayName,
                string.Format("Manage {0}'s equipment.", owner.Look.DisplayName));

            foreach (EquipType myET in EquipType.AllTypes)
            {
                EquipType   et = myET;
                IButtonable ib = null;
                Equipment   eq = owner.Equipment;
                if (owner.Equipment.Contains(et))
                {
                    CastUnequipItem unequip = new CastUnequipItem(owner.Inventory, owner.Equipment, eq.PeekItem(et));
                    ib = GetUnequipProcess(current, unequip, owner, grid, handlePlayable);
                }
                else
                {
                    ib = GetEquipGrid(current, owner, et, owner.Inventory, grid, handlePlayable);
                }
                grid.List.Add(ib);
            }
            return(grid);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a subGrid containing all possible targets
        /// of spellable
        /// </summary>
        /// <param name="current">Page that owner is on</param>
        /// <param name="previous">supergrid containing a list of possible ISpellables to use</param>
        /// <param name="caster">User of the Spellable</param>
        /// <param name="spellable">Spellable to use on target</param>
        /// <param name="spellHandler">Spell handler</param>
        /// <returns></returns>
        public static Grid GenerateTargets(Page current, IButtonable previous, Character caster, ISpellable spellable, Sprite sprite, Action <Spell> spellHandler)
        {
            SpellBook sb = spellable.GetSpellBook();
            ICollection <Character> targets = sb.TargetType.GetTargets(caster, current);
            Grid grid = GenerateBackableGrid(previous, sb.Icon, sb.Name, sb.CreateDescription(caster));

            grid.Icon = sprite;

            ICollection <Process> targetProcesses = spellable.GetSpellBook().TargetType.GetTargetProcesses(current, spellable, caster, spellHandler);

            foreach (Process targetProcess in targetProcesses)
            {
                grid.List.Add(targetProcess);
            }

            Item item = spellable as Item;

            if (item != null && item.HasFlag(Items.Flag.OCCUPIES_SPACE))
            {
                grid.List.Add(
                    new Process(
                        string.Format("Drop"),
                        string.Format("Throw away {0}.", item.Name),
                        () => {
                    spellHandler(
                        caster.Spells.CreateSpell(current, new TossItem(item, caster.Inventory), caster, caster)
                        );
                }
                        ));
            }
            return(grid);
        }
Beispiel #4
0
        public static Grid GenerateGroupItemsGrid(
            Page current,
            IButtonable previous,
            IEnumerable <Character> party,
            Action <Spell> addPlay
            )
        {
            Grid grid = GenerateBackableGrid(previous, INVENTORY, party.FirstOrDefault().Inventory.DetailedName, party.FirstOrDefault().Inventory.DetailedDescription);

            foreach (Character partyMember in party)
            {
                if (partyMember.Stats.State == State.ALIVE)
                {
                    grid.List.Add(
                        GenerateItemsGrid(
                            current,
                            grid,
                            partyMember,
                            addPlay,
                            partyMember.Look.Sprite,
                            partyMember.Look.DisplayName,
                            string.Format("{0} will be the item's caster.",
                                          partyMember.Look.DisplayName)));
                }
                else
                {
                    grid.List.Add(new Process(partyMember.Look.DisplayName, partyMember.Look.Sprite, "This unit is dead and is unable to be a caster for any item."));
                }
            }
            return(grid);
        }
Beispiel #5
0
 /// <summary>
 /// Create a Back Process, which is used
 /// to leave a subgrid.
 /// </summary>
 /// <param name="previous"></param>
 /// <returns></returns>
 public static Process GenerateBack(IButtonable previous)
 {
     return(new Process(
                "Back",
                Util.GetSprite("plain-arrow"),
                string.Format("Go back to {0}.", previous.ButtonText),
                () => previous.Invoke()
                ));
 }
Beispiel #6
0
 public static IButtonable[] UpdateArray <T>(IButtonable[] currentArray, Tuple tuple)
 {
     IButtonable[] array = currentArray;
     if (currentArray.Length - 1 < tuple.Index)
     {
         array = new IButtonable[tuple.Index];
         Array.Copy(currentArray, array, currentArray.Length);
     }
     array[tuple.Index] = tuple.Data;
     return(array);
 }
Beispiel #7
0
        private static Process GenerateSpellProcess(Page current, IButtonable previous, Character owner, ISpellable spellable, Action <IPlayable> handlePlayable, bool isTargetingSelf)
        {
            SpellBook sb = spellable.GetSpellBook();

            return(new Process(sb.GetDetailedName(owner), sb.Icon, sb.CreateDescription(owner),
                               () => {
                if (sb.IsMeetPreTargetRequirements(owner.Stats))
                {
                    GenerateTargets(current, previous, owner, spellable, handlePlayable, isTargetingSelf).Invoke();
                }
            }));
        }
Beispiel #8
0
        /// <summary>
        /// Creates a Grid asking if the user wants to perform a task.
        /// </summary>
        /// <param name="current">Page grid is on</param>
        /// <param name="previous">Previous buttonable</param>
        /// <param name="confirm">Process serving as the confirm button</param>
        /// <param name="name">Name of this grid</param>
        /// <param name="tooltip">Tooltip of this grid</param>
        /// <param name="confirmationQuestion">Question to ask when grid is entered.</param>
        /// <returns></returns>
        public static Grid GetConfirmationGrid(Page current, IButtonable previous, Process confirm, string name, string tooltip, string confirmationQuestion)
        {
            Grid g = new Grid(name);

            g.Tooltip  = tooltip;
            g.OnEnter += () => {
                current.AddText(confirmationQuestion);
            };
            g.List.Add(PageUtil.GenerateBack(previous));
            g.List.Add(confirm);
            return(g);
        }
Beispiel #9
0
        /// <summary>
        /// Gets a confirmation page asking if the user is sure they want to do a particular action.
        /// </summary>
        /// <param name="current">The current.</param>
        /// <param name="previous">The previous.</param>
        /// <param name="confirm">The confirm.</param>
        /// <param name="name">The name.</param>
        /// <param name="tooltip">The tooltip.</param>
        /// <param name="confirmationQuestion">The confirmation question.</param>
        /// <returns></returns>
        public static Page GetConfirmationPage(Page current, IButtonable previous, Process confirm, string name, string tooltip, string confirmationQuestion)
        {
            Page p = new Page(name);

            p.Body = confirmationQuestion;

            p.Actions = new IButtonable[] {
                GenerateBack(previous),
                confirm
            };
            return(p);
        }
Beispiel #10
0
        /// <summary>
        /// Create a subgrid that can be left to a main grid.
        /// </summary>
        /// <param name="previous">Content to go back to</param>
        /// <param name="icon">Icon on the Button leading to this submenu</param>
        /// <param name="name">Name on the button leading to this submenu</param>
        /// <param name="tooltip">Description on the button leading to this submenu</param>
        /// <returns></returns>
        private static Grid GenerateBackableGrid(IButtonable previous, Sprite icon, string name, string tooltip)
        {
            Grid grid = new Grid(name);

            grid.Icon    = icon;
            grid.Tooltip = tooltip;
            List <IButtonable> buttons = new List <IButtonable>();

            buttons.Add(GenerateBack(previous));
            grid.List = buttons;
            return(grid);
        }
Beispiel #11
0
        /// <summary>
        /// Gets a basic page that can return to a previous page.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="previousIndex">Index of the previous.</param>
        /// <param name="buttons">The buttons.</param>
        /// <returns></returns>
        protected Page BasicPage(int index, int previousIndex, params IButtonable[] buttons)
        {
            Page page = Get(index);

            IButtonable[] list = new IButtonable[buttons.Length + 1];
            list[0] = PageUtil.GenerateBack(Get(previousIndex));
            for (int i = 1; i < list.Length; i++)
            {
                list[i] = buttons[i - 1];
            }
            page.Actions = list;
            return(page);
        }
Beispiel #12
0
        public static Grid GenerateGroupEquipmentGrid(IButtonable previous, Page current, ICollection <Character> party, Action <IPlayable> handlePlayable, bool isInCombat)
        {
            Grid grid = new Grid("Equipment");

            grid.List.Add(GenerateBack(previous));

            foreach (Character partyMember in party)
            {
                grid.List.Add(GenerateEquipmentGrid(current, grid, partyMember, handlePlayable, isInCombat));
            }

            return(grid);
        }
Beispiel #13
0
        private Grid SetupShopMenu <T>(IButtonable previous, string name, string spriteLoc, string tooltip, IEnumerable <T> items, Func <T, Action, Process> conversion)
        {
            Grid grid = new Grid(name);

            grid.Icon    = Util.GetSprite(spriteLoc);
            grid.Tooltip = tooltip;
            grid.OnEnter = () => {
                grid.List.Clear();
                grid.List.Add(PageUtil.GenerateBack(previous));
                foreach (T item in items)
                {
                    grid.List.Add(conversion(item, () => grid.Invoke()));
                }
                ;
            };
            return(grid);
        }
Beispiel #14
0
    private static IButtonable[] GetArray(Tuple[] indices, int smallestAllowedSize = 0)
    {
        int size = Mathf.Max(indices.Max(t => t.Index) + 1, smallestAllowedSize);

        IButtonable[] array    = new IButtonable[size];
        HashSet <int> indexSet = new HashSet <int>();

        foreach (Tuple t in indices)
        {
            if (indexSet.Contains(t.Index))
            {
                throw new UnityException(string.Format("Index collision detected at index: {0}. Tried to place {1}, but {2} was already there.", t.Data.ButtonText, array[t.Index].ButtonText));
            }
            indexSet.Add(t.Index);
            array[t.Index] = t.Data;
        }
        return(array);
    }
Beispiel #15
0
 /// <summary>
 /// Generate a Grid containing all SpellBooks
 /// in Characters.SpellBooks
 /// </summary>
 /// <param name="current">Page the Owner is on</param>
 /// <param name="previous">Previous IButtonable you want this Grid to go back to</param>
 /// <param name="owner">Owner of the SpellBooks</param>
 /// <param name="excluded">SpellBook to exclude, typically 'Attack'</param>
 /// <param name="spellCollection">SpellBooks owned by Owner</param>
 /// <param name="addPlay">Chosen action handler</param>
 /// <returns></returns>
 public static Grid GenerateSpellBooks(
     Page current,
     IButtonable previous,
     Character owner,
     SpellBook excluded,
     Action <Spell> addPlay
     )
 {
     return(GenerateSpellableGrid(
                current,
                previous,
                owner,
                excluded,
                ((IEnumerable <ISpellable>)owner.Spells).Where(s => s.GetSpellBook().Costs.Count > 0),
                addPlay,
                SPELLBOOK,
                "Spells",
                "Cast a spell."));
 }
Beispiel #16
0
 /// <summary>
 /// Generates a grid with inventory items
 /// to use
 /// </summary>
 /// <param name="current">Page the owner is on</param>
 /// <param name="previous">Main grid</param>
 /// <param name="owner">Owner of the inventory</param>
 /// <param name="addPlay">IPlayable handler</param>
 /// <param name="isInCombat">If in combat, X will use Y on Z, if out of battle, Z would use Y on themself.</param>
 /// <returns></returns>
 public static Grid GenerateItemsGrid(
     bool isInCombat,
     Page current,
     IButtonable previous,
     Character owner,
     Action <IPlayable> addPlay
     )
 {
     return(GenerateSpellableGrid(
                !isInCombat,
                current,
                previous,
                owner,
                null,
                owner.Inventory,
                addPlay,
                INVENTORY,
                string.Format("Items ({0}/{1})", owner.Inventory.TotalOccupiedSpace, owner.Inventory.Capacity),
                string.Format("Use an item.\n{0} out of {1} inventory space is occupied.", owner.Inventory.TotalOccupiedSpace, owner.Inventory.Capacity)
                ));
 }
Beispiel #17
0
 private static Process GenerateTargetProcessHelper(
     Page current,
     IButtonable previous,
     Character owner,
     Character target,
     SpellBook sb,
     Action <IPlayable> handlePlayable,
     string name,
     Sprite icon)
 {
     return(new Process(name,
                        icon,
                        sb.CreateTargetDescription(owner, target),
                        () => {
         if (sb.IsCastable(owner, target))
         {
             handlePlayable(owner.Spells.CreateSpell(current, sb, owner, target));
             previous.Invoke();
         }
     }));
 }
Beispiel #18
0
        public static Grid GenerateGroupEquipmentGrid(IButtonable previous, Page current, ICollection <Character> party, Action <Spell> spellHandler)
        {
            Grid grid = new Grid("Equipment");

            grid.Icon = EQUIPMENT;
            grid.List.Add(GenerateBack(previous));

            foreach (Character partyMember in party)
            {
                if (partyMember.Stats.State == State.ALIVE)
                {
                    grid.List.Add(GenerateEquipmentGrid(current, grid, partyMember, spellHandler, partyMember.Look.Sprite, partyMember.Look.DisplayName));
                }
                else
                {
                    grid.List.Add(new Process(partyMember.Look.DisplayName, partyMember.Look.Sprite, "This unit is dead and is unable to manage its equipment."));
                }
            }

            return(grid);
        }
Beispiel #19
0
        /// <summary>
        /// Creates a subGrid containing all possible targets
        /// of spellable
        /// </summary>
        /// <param name="current">Page that owner is on</param>
        /// <param name="previous">supergrid containing a list of possible ISpellables to use</param>
        /// <param name="owner">User of the Spellable</param>
        /// <param name="spellable">Spellable to use on target</param>
        /// <param name="handlePlayable">Playable handler</param>
        /// <param name="isTargetingSelf">If true, the target will attempt to cast the spell on themselves (used for out of combat inventories)</param>
        /// <returns></returns>
        public static Grid GenerateTargets(Page current, IButtonable previous, Character owner, ISpellable spellable, Sprite sprite, Action <IPlayable> handlePlayable, bool isTargetingSelf)
        {
            SpellBook sb = spellable.GetSpellBook();
            ICollection <Character> targets = sb.TargetType.GetTargets(owner, current);
            Grid grid = GenerateBackableGrid(previous, sb.Icon, sb.Name, sb.CreateDescription(owner));

            grid.Icon = sprite;

            foreach (Character myTarget in targets)
            {
                Character target = myTarget;

                Character spellOwner = null;
                if (isTargetingSelf)
                {
                    spellOwner = target;
                }
                else
                {
                    spellOwner = owner;
                }
                grid.List.Add(GenerateTargetProcess(current, previous, spellOwner, target, sb, handlePlayable));
            }
            Item item = spellable as Item;

            if (item != null && item.HasFlag(Items.Flag.OCCUPIES_SPACE))
            {
                grid.List.Add(
                    new Process(
                        string.Format("Drop"),
                        string.Format("Throw away {0}.", item.Name),
                        () => {
                    handlePlayable(
                        owner.Spells.CreateSpell(current, new TossItem(item, owner.Inventory), owner, owner)
                        );
                }
                        ));
            }
            return(grid);
        }
Beispiel #20
0
        /// <summary>
        /// Actions are spells without a cost.
        /// </summary>
        /// <param name="current">The current page.</param>
        /// <param name="previous">The previous page.</param>
        /// <param name="owner">The owner of the action.</param>
        /// <param name="excluded">The excluded spell.</param>
        /// <param name="concat">The spells to add alongside the spellbook's.</param>
        /// <param name="playHandler">The play handler.</param>
        /// <returns></returns>
        public static Grid GenerateActions(
            Page current,
            IButtonable previous,
            Character owner,
            SpellBook excluded,
            IEnumerable <ISpellable> concat,
            Action <Spell> playHandler
            )
        {
            List <SpellBook> spellsThatHaveACost = new List <SpellBook>();

            return(GenerateSpellableGrid(
                       current,
                       previous,
                       owner,
                       excluded,
                       ((IEnumerable <ISpellable>)owner.Spells).Where(s => s.GetSpellBook().Costs.Count <= 0).ToList().Concat(concat),
                       playHandler,
                       ACTION,
                       "Action",
                       "Perform an action."));
        }
Beispiel #21
0
 /// <summary>
 /// Generates a grid with inventory items
 /// to use
 /// </summary>
 /// <param name="current">Page the owner is on</param>
 /// <param name="previous">Main grid</param>
 /// <param name="owner">Owner of the inventory</param>
 /// <param name="addPlay">IPlayable handler</param>
 /// <returns></returns>
 public static Grid GenerateItemsGrid(
     Page current,
     IButtonable previous,
     Character owner,
     Action <Spell> addPlay,
     Sprite sprite,
     string name,
     string description
     )
 {
     return(GenerateSpellableGrid(
                current,
                previous,
                owner,
                null,
                owner.Inventory,
                addPlay,
                sprite,
                name,
                description
                ));
 }
Beispiel #22
0
 private static Process GetUnequipProcess(Page current, CastUnequipItem unequipSpell, Character owner, IButtonable previous, Action <IPlayable> handlePlayable)
 {
     return(new Process(unequipSpell.Name, unequipSpell.Icon, unequipSpell.CreateDescription(owner),
                        () => {
         handlePlayable(owner.Spells.CreateSpell(current, unequipSpell, owner, owner));
         previous.Invoke();
     },
                        () => unequipSpell.IsCastable(owner, owner)
                        ));
 }
Beispiel #23
0
        private static Grid GetEquipGrid(Page current, Character owner, EquipType et, Inventory inv, IButtonable previous, Action <IPlayable> handlePlayable)
        {
            Grid grid = GenerateBackableGrid(
                previous,
                et.Sprite,
                Util.ColorString(et.Name, Color.grey),
                string.Format("Equip an item in the <color=yellow>{0}</color> slot.", et.Name)
                );

            foreach (EquippableItem ei in inv as IEnumerable <EquippableItem> )
            {
                if (ei.Type.Equals(et))
                {
                    grid.List.Add(GenerateTargetProcessHelper(current, previous, owner, owner, new CastEquipItem(ei), handlePlayable, ei.Name, ei.Icon));
                }
            }
            return(grid);
        }
Beispiel #24
0
 /// <summary>
 /// Clears the action grid.
 /// </summary>
 public void ClearActionGrid()
 {
     Actions = new IButtonable[Grid.DEFAULT_BUTTON_COUNT];
 }
Beispiel #25
0
 private static Process GenerateTargetProcess(Page current, IButtonable previous, Character owner, Character target, SpellBook sb, Action <IPlayable> handlePlayable)
 {
     return(GenerateTargetProcessHelper(current, previous, owner, target, sb, handlePlayable, CreateDetailedTargetName(owner, target, sb), target.Look.Sprite));
 }
Beispiel #26
0
 public Tuple(int index, IButtonable data)
 {
     this.Index = index;
     this.Data  = data;
 }
Beispiel #27
0
 private Grid SetupBuyMenu(IButtonable previous)
 {
     return(SetupShopMenu <Buy>(previous, "Buy", "buy-card", string.Format("Buy items with {0}s.", MONEY.Name), buys, (b, a) => GetBuyProcess(b, a)));
 }
Beispiel #28
0
 private Grid SetupSellMenu(IButtonable previous)
 {
     return(SetupShopMenu <Item>(previous, "Sell", "sell-card", string.Format("Sell items for {0}s.", MONEY.Name), party.Shared, (i, a) => GetSellProcess(i, a)));
 }
Beispiel #29
0
 /// <summary>
 /// Creates a subGrid containing all possible targets
 /// of spellable
 /// </summary>
 /// <param name="current">Page that owner is on</param>
 /// <param name="previous">supergrid containing a list of possible ISpellables to use</param>
 /// <param name="owner">User of the Spellable</param>
 /// <param name="spellable">Spellable to use on target</param>
 /// <param name="handlePlayable">Playable handler</param>
 /// <returns></returns>
 public static Grid GenerateTargets(Page current, IButtonable previous, Character owner, ISpellable spellable, Action <IPlayable> handlePlayable, bool isTargetingSelf)
 {
     return(GenerateTargets(current, previous, owner, spellable, spellable.GetSpellBook().Icon, handlePlayable, isTargetingSelf));
 }
Beispiel #30
0
 private Grid SetupTalkMenu(IButtonable previous)
 {
     return(SetupShopMenu <Talk>(previous, "Talk", "talk", "Talk to the shopkeeper about something.", talks, (t, a) => GetTalkProcess(t, a)));
 }