public override StateOperationResult OnSelectPosition(FDPosition position)
        {
            if (this.magicRange == null)
            {
                // should not happen
                return(StateOperationResult.Clear());
            }

            if (this.magicRange.Contains(position))
            {
                DirectRangeFinder rangeFinder = new DirectRangeFinder(gameAction.GetField(), position, this.Magic.EffectScope);
                FDRange           magicScope  = rangeFinder.CalculateRange();

                List <FDCreature> targets = gameAction.GetCreatureInRange(magicScope, CreatureFaction.Enemy);
                if (targets == null || targets.Count == 0)
                {
                    // Cannot spell on that position, do nothing
                    return(StateOperationResult.None());
                }
                else
                {
                    gameAction.DoCreatureSpellMagic(this.Creature.CreatureId, this.Magic.MagicId, position);
                    return(StateOperationResult.Clear());
                }
            }
            else
            {
                // Cancel the magic
                return(StateOperationResult.Pop());
            }
        }
Ejemplo n.º 2
0
        public override StateOperationResult OnSelectIndex(int index)
        {
            if (index < 0)
            {
                // Cancel
                return(StateOperationResult.None());
            }

            switch (this.subState)
            {
            case SubActionState.SelectExchangeItem:
                return(OnSelectedExchangeItem(index));

            case SubActionState.SelectEquipItem:
                return(OnSelectedEquipItem(index));

            case SubActionState.SelectUseItem:
                return(OnSelectedUseItem(index));

            case SubActionState.SelectDiscardItem:
                return(OnSelectedDiscardItem(index));

            default:
                return(StateOperationResult.Pop());
            }
        }
Ejemplo n.º 3
0
        private StateOperationResult OnConfrimRestAll(int index)
        {
            if (index == 1)
            {
                gameAction.DoCreatureAllRest();
                return(StateOperationResult.Clear());
            }

            return(StateOperationResult.None());
        }
Ejemplo n.º 4
0
        private StateOperationResult OnSelectedExchangeItem(int index)
        {
            if (index < 0)
            {
                return(StateOperationResult.Pop());
            }

            // Selete Target Friend
            SelectItemExchangeTargetState exchangeTargetState = new SelectItemExchangeTargetState(gameAction, this.CreatureId, index);

            return(StateOperationResult.Push(exchangeTargetState));
        }
Ejemplo n.º 5
0
        public override StateOperationResult OnSelectIndex(int index)
        {
            switch (subState)
            {
            case SubState.ConfirmRestAll:
                return(OnConfrimRestAll(index));

            default:
                break;
            }

            return(StateOperationResult.None());
        }
Ejemplo n.º 6
0
        private StateOperationResult OnSelectedUseItem(int index)
        {
            int itemId = this.Creature.Data.GetItemAt(index);

            if (itemId < 0)
            {
                // Item not found, should not reach here
                return(StateOperationResult.Clear());
            }

            // Selete Target Friend
            SelectItemUseTargetState selectTargetState = new SelectItemUseTargetState(gameAction, this.CreatureId, index);

            return(StateOperationResult.Push(selectTargetState));
        }
Ejemplo n.º 7
0
        private StateOperationResult OnQuitGameConfirmed(int index)
        {
            if (index == 1)
            {
                Debug.Log("Quiting Game...");

                // Quit Game
                SendPack(new SystemPack(SystemPack.Command.Quit));

                return(StateOperationResult.Clear());
            }
            else
            {
                return(StateOperationResult.None());
            }
        }
Ejemplo n.º 8
0
        public MenuItemState(IGameAction gameAction, int creatureId, FDPosition position) : base(gameAction, position)
        {
            this.CreatureId = creatureId;
            this.Creature   = gameAction.GetCreature(creatureId);

            // Exchange
            this.SetMenu(0, MenuItemId.ItemExchange, IsMenuExchangeEnabled(), () =>
            {
                CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectAllItem);
                SendPack(pack);

                subState = SubActionState.SelectExchangeItem;
                return(StateOperationResult.None());
            });

            // Use
            this.SetMenu(1, MenuItemId.ItemUse, IsMenuUseEnabled(), () =>
            {
                CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectUseItem);
                SendPack(pack);

                subState = SubActionState.SelectUseItem;
                return(StateOperationResult.None());
            });

            // Equip
            this.SetMenu(2, MenuItemId.ItemEquip, IsMenuEquipEnabled(), () =>
            {
                CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectEquipItem);
                SendPack(pack);

                subState = SubActionState.SelectEquipItem;
                return(StateOperationResult.None());
            });

            // Discard
            this.SetMenu(3, MenuItemId.ItemDiscard, IsMenuDiscardEnabled(), () =>
            {
                CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectAllItem);
                SendPack(pack);

                subState = SubActionState.SelectDiscardItem;
                return(StateOperationResult.None());
            });
        }
Ejemplo n.º 9
0
        private StateOperationResult OnSelectedEquipItem(int index)
        {
            if (index < 0)
            {
                // Cancel the selection
                return(StateOperationResult.None());
            }

            this.Creature.Data.EquipItemAt(index);

            // Reopen the item dialog
            CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectEquipItem);

            SendPack(pack);

            subState = SubActionState.SelectEquipItem;
            return(StateOperationResult.None());
        }
Ejemplo n.º 10
0
        public override StateOperationResult OnSelectPosition(FDPosition position)
        {
            // Selecte position must be included in the range
            if (!this.ItemRange.Contains(position))
            {
                return(StateOperationResult.Pop());
            }

            // No creature or not a friend/NPC
            FDCreature targetCreature = this.gameAction.GetCreatureAt(position);

            if (targetCreature == null || targetCreature.Faction == Definitions.CreatureFaction.Enemy)
            {
                return(StateOperationResult.None());
            }

            gameAction.DoCreatureUseItem(this.CreatureId, this.SelectedItemIndex, targetCreature.CreatureId);
            return(StateOperationResult.Clear());
        }
Ejemplo n.º 11
0
        public MenuSystemState(IGameAction gameAction, FDPosition central) : base(gameAction, central)
        {
            // Matching
            this.SetMenu(0, MenuItemId.SystemMatching, false, () =>
            {
                subState = SubState.ConfirmMatching;

                MessageId message = MessageId.Create(MessageId.MessageTypes.Confirm, 1);
                TalkPack pack     = new TalkPack(null, message);
                SendPack(pack);

                return(StateOperationResult.None());
            });

            // Record
            this.SetMenu(1, MenuItemId.SystemRecord, true, () =>
            {
                ActionState nextState = new MenuRecordState(gameAction, central);
                return(StateOperationResult.Push(nextState));
            });

            // Settings
            this.SetMenu(2, MenuItemId.SystemSettings, true, () =>
            {
                ActionState nextState = new MenuSettingsState(gameAction, central);
                return(StateOperationResult.Push(nextState));
            });

            // Rest All
            this.SetMenu(3, MenuItemId.SystemRestAll, true, () =>
            {
                subState = SubState.ConfirmRestAll;

                MessageId message = MessageId.Create(MessageId.MessageTypes.Confirm, 1);
                TalkPack pack     = new TalkPack(null, message);
                SendPack(pack);

                return(StateOperationResult.None());
            });
        }
 public override StateOperationResult OnSelectPosition(FDPosition position)
 {
     if (this.AttackRange != null && this.AttackRange.Contains(position))
     {
         FDCreature target = this.gameAction.GetCreatureAt(position);
         if (target != null && target.Faction == Definitions.CreatureFaction.Enemy)
         {
             // Do the attack
             this.gameAction.DoCreatureAttack(this.Creature.CreatureId, position);
             return(StateOperationResult.Clear());
         }
         else
         {
             // Clicked in the range, but no target, let the player to click again
             return(StateOperationResult.None());
         }
     }
     else
     {
         // Clicked out of range, cancel
         return(StateOperationResult.Pop());
     }
 }
Ejemplo n.º 13
0
 private StateOperationResult OnSelectedDiscardItem(int index)
 {
     // Discard the item
     this.Creature.Data.RemoveItemAt(index);
     return(StateOperationResult.None());
 }