Esempio n. 1
0
 private void cancelAction()
 {
     if (inOuterMenu)
     {
         if (Actions.Count > 0)
         {
             ThinkAction lastAction = Actions[Actions.Count - 1];
             Actions.RemoveAt(Actions.Count - 1);
             CurrentPartyMember = lastAction.Actor;
             if (!ThinkMenuOption.IsDefaultOptionName(lastAction.OptionName))
             {
                 Inventory inventory = getInventoryFromThinkActionType(lastAction.Type, CurrentPartyMember);
                 if (inventory != null)
                 {
                     inventory.AddItem(lastAction.OptionName, CurrentPartyMember);
                 }
             }
             repopulateMenuOptions();
             Logger.Log("Back to action selection for party member " + (Actions.Count + 1).ToString());
         }
     }
     else
     {
         hideOpenMenu();
     }
 }
        public Think(Battle battle)
            : base(battle)
        {
            CurrentThinkActionType = ThinkActionType.None;
            currentThinkAction = null;
            CurrentOptionNameIndex = 0;
            MenuOptions = null;
            inOuterMenu = true;
            CurrentOuterMenuOptionIndex = 0;

            weaponMenuOptions = new Dictionary<CharacterClass, List<ThinkMenuOption>>();
            foreach (CharacterClass characterClass in Enum.GetValues(typeof(CharacterClass)))
                weaponMenuOptions.Add(characterClass, new List<ThinkMenuOption>());
            shieldMenuOptions = new List<ThinkMenuOption>();
            itemMenuOptions = new List<ThinkMenuOption>();

            Actions = new List<ThinkAction>(battle.PlayerParty.Count);

            inputButtonListener = new InputButtonListener(new Dictionary<InputButton, ButtonEventHandlers> {
                { InputButton.Up, new ButtonEventHandlers(down: upHandler) },
                { InputButton.Down, new ButtonEventHandlers(down: downHandler) },
                { InputButton.Left, new ButtonEventHandlers(down: leftHandler) },
                { InputButton.Right, new ButtonEventHandlers(down: rightHandler) },
                { InputButton.A, new ButtonEventHandlers(up: selectOption) },
                { InputButton.B, new ButtonEventHandlers(up: cancelAction) }
            });
        }
Esempio n. 3
0
        public Think(Battle battle)
            : base(battle)
        {
            CurrentThinkActionType      = ThinkActionType.None;
            currentThinkAction          = null;
            CurrentOptionNameIndex      = 0;
            MenuOptions                 = null;
            inOuterMenu                 = true;
            CurrentOuterMenuOptionIndex = 0;

            weaponMenuOptions = new Dictionary <CharacterClass, List <ThinkMenuOption> >();
            foreach (CharacterClass characterClass in Enum.GetValues(typeof(CharacterClass)))
            {
                weaponMenuOptions.Add(characterClass, new List <ThinkMenuOption>());
            }
            shieldMenuOptions = new List <ThinkMenuOption>();
            itemMenuOptions   = new List <ThinkMenuOption>();

            Actions = new List <ThinkAction>(battle.PlayerParty.Count);

            inputButtonListener = new InputButtonListener(new Dictionary <InputButton, ButtonEventHandlers> {
                { InputButton.Up, new ButtonEventHandlers(down: upHandler) },
                { InputButton.Down, new ButtonEventHandlers(down: downHandler) },
                { InputButton.Left, new ButtonEventHandlers(down: leftHandler) },
                { InputButton.Right, new ButtonEventHandlers(down: rightHandler) },
                { InputButton.A, new ButtonEventHandlers(up: selectOption) },
                { InputButton.B, new ButtonEventHandlers(up: cancelAction) }
            });
        }
 public HandleStatusEffects(Battle battle, StatusEffectEvent statusEffectEvent, ThinkAction thinkAction = null, PartyMember partyMember = null)
     : base(battle)
 {
     if (thinkAction == null && partyMember == null)
         throw new Exception("Either ThinkAction or PartyMember must not be null");
     this.thinkAction = thinkAction;
     this.partyMember = partyMember ?? thinkAction.Actor;
     this.statusEffectEvent = statusEffectEvent;
 }
 public UseItem(Battle battle, ThinkAction thinkAction)
     : base(battle)
 {
     if (thinkAction == null)
         throw new Exception("ThinkAction cannot be null");
     this.thinkAction = thinkAction;
     scriptRunner = null;
     item = null;
 }
Esempio n. 6
0
        private void takeFromInventory(ThinkAction thinkAction, PartyMember partyMember)
        {
            Inventory inventory = getInventoryFromThinkActionType(thinkAction.Type, partyMember);

            if (inventory != null)
            {
                inventory.UseItem(thinkAction.OptionName, partyMember);
            }
        }
 public Attack(Battle battle, ThinkAction thinkAction)
     : base(battle)
 {
     if (thinkAction == null)
         throw new Exception("ThinkAction cannot be null");
     this.thinkAction = thinkAction;
     scriptStartTime = 0.0f;
     scriptStartTimer = 0.0f;
 }
Esempio n. 8
0
 public Attack(Battle battle, ThinkAction thinkAction)
     : base(battle)
 {
     if (thinkAction == null)
     {
         throw new Exception("ThinkAction cannot be null");
     }
     this.thinkAction = thinkAction;
     scriptStartTime  = 0.0f;
     scriptStartTimer = 0.0f;
 }
 public HandleStatusEffects(Battle battle, StatusEffectEvent statusEffectEvent, ThinkAction thinkAction = null, PartyMember partyMember = null)
     : base(battle)
 {
     if (thinkAction == null && partyMember == null)
     {
         throw new Exception("Either ThinkAction or PartyMember must not be null");
     }
     this.thinkAction       = thinkAction;
     this.partyMember       = partyMember ?? thinkAction.Actor;
     this.statusEffectEvent = statusEffectEvent;
 }
Esempio n. 10
0
 public UseItem(Battle battle, ThinkAction thinkAction)
     : base(battle)
 {
     if (thinkAction == null)
     {
         throw new Exception("ThinkAction cannot be null");
     }
     this.thinkAction = thinkAction;
     scriptRunner     = null;
     item             = null;
 }
Esempio n. 11
0
        private void pushStateForThinkAction(ThinkAction thinkAction)
        {
            if (thinkAction == null)
            {
                return;
            }

            if (!statusEffectsCompleteForAction && thinkAction.Actor.Alive)
            {
                PushState(new HandleStatusEffects(Battle, StatusEffectEvent.BeforeAct, thinkAction: thinkAction));
                return;
            }

            if (!thinkAction.Actor.Alive || !thinkAction.Active)
            {
                if (!ThinkMenuOption.IsDefaultOptionName(thinkAction.OptionName))
                {
                    Inventory inventory = getInventoryFromThinkActionType(thinkAction.Type, thinkAction.Actor);
                    if (inventory != null)
                    {
                        inventory.AddItem(thinkAction.OptionName, thinkAction.Actor);
                    }
                }
                getNextThinkAction();
                return;
            }

            if (thinkAction.Target.Alive)
            {
                if (thinkAction.Type == ThinkActionType.Attack)
                {
                    PushState(new Attack(Battle, thinkAction));
                }
                else
                {
                    PushState(new UseItem(Battle, thinkAction));
                }
            }
            else
            {
                if (Battle.PlayerParty.Count > 0 && Battle.EnemyParty.Count > 0)
                {
                    PushState(new SelectTarget(Battle, thinkAction));
                }
                else
                {
                    Finish();
                }
            }
        }
 public SelectTarget(Battle battle, ThinkAction thinkAction)
     : base(battle)
 {
     if (thinkAction == null)
         throw new Exception("ThinkAction cannot be null");
     this.thinkAction = thinkAction;
     isEnemy = Battle.GetPartyForPartyMember(thinkAction.Actor) == Battle.EnemyParty;
     inputButtonListener = isEnemy ? null : new InputButtonListener(new Dictionary<InputButton, ButtonEventHandlers> {
         { InputButton.Up, new ButtonEventHandlers(down: chooseTargetUp) },
         { InputButton.Down, new ButtonEventHandlers(down: chooseTargetDown) },
         { InputButton.Left, new ButtonEventHandlers(down: chooseTargetLeft) },
         { InputButton.Right, new ButtonEventHandlers(down: chooseTargetRight) },
         { InputButton.A, new ButtonEventHandlers(up: selectTarget) },
         { InputButton.B, new ButtonEventHandlers(up: cancelTargetSelection) }
     });
 }
        public override void BeforeActUpdate(ThinkAction thinkAction, Delta delta)
        {
            base.BeforeActUpdate(thinkAction, delta);

            if (!thinkActionActivationDecided)
            {
                if (Game1.Random.Next(100) <= chanceOfEffect)
                    thinkAction.Active = false;
                thinkActionActivationDecided = true;
            }
            else if (thinkAction.Active)
                finished = true;
            else
                updateShockEffect(thinkAction.Actor, delta);

            checkFinish(thinkAction.Actor);
        }
 public SelectTarget(Battle battle, ThinkAction thinkAction)
     : base(battle)
 {
     if (thinkAction == null)
     {
         throw new Exception("ThinkAction cannot be null");
     }
     this.thinkAction    = thinkAction;
     isEnemy             = Battle.GetPartyForPartyMember(thinkAction.Actor) == Battle.EnemyParty;
     inputButtonListener = isEnemy ? null : new InputButtonListener(new Dictionary <InputButton, ButtonEventHandlers> {
         { InputButton.Up, new ButtonEventHandlers(down: chooseTargetUp) },
         { InputButton.Down, new ButtonEventHandlers(down: chooseTargetDown) },
         { InputButton.Left, new ButtonEventHandlers(down: chooseTargetLeft) },
         { InputButton.Right, new ButtonEventHandlers(down: chooseTargetRight) },
         { InputButton.A, new ButtonEventHandlers(up: selectTarget) },
         { InputButton.B, new ButtonEventHandlers(up: cancelTargetSelection) }
     });
 }
Esempio n. 15
0
        public override void Update(Delta delta)
        {
            if (Battle.PlayerParty.Count == 0 || Battle.EnemyParty.Count == 0)
            {
                Finish();
                return;
            }
            else if (currentThinkActionFinished)
            {
                if (allPartyMembersIdle())
                {
                    getNextThinkAction();
                }
                return;
            }

            ThinkAction thinkAction = null;

            if (currentThinkActionType == ThinkActionType.UseItem)
            {
                if (currentThinkActionIndex >= useItemThinkActions.Count)
                {
                    currentThinkActionIndex        = 0;
                    statusEffectsCompleteForAction = false;
                    currentThinkActionType         = ThinkActionType.Attack;
                    return;
                }

                thinkAction = useItemThinkActions[currentThinkActionIndex];
            }
            else if (currentThinkActionType == ThinkActionType.Attack)
            {
                if (currentThinkActionIndex >= attackThinkActions.Count)
                {
                    Finish();
                    return;
                }

                thinkAction = attackThinkActions[currentThinkActionIndex];
            }

            pushStateForThinkAction(thinkAction);
        }
Esempio n. 16
0
        private void selectAction()
        {
            if (MenuOptions[CurrentOptionNameIndex].Disabled)
            {
                return;
            }

            ThinkMenuOption option = MenuOptions[CurrentOptionNameIndex];

            currentThinkAction = new ThinkAction(CurrentThinkActionType, option.Name, CurrentPartyMember);
            if (CurrentThinkActionType == ThinkActionType.Defend)
            {
                finishThinkForCurrentPartyMember();
            }
            else
            {
                currentThinkAction.InfiniteInInventory = option.Amount < 0;
                PushState(new SelectTarget(Battle, currentThinkAction));
            }
        }
Esempio n. 17
0
        private ThinkAction thinkForEnemyPartyMember(PartyMember partyMember, Battle battle)
        {
            Party  party      = battle.GetPartyForPartyMember(partyMember);
            string searchTerm = partyMember.Data.Name.ToUpperFirstChar();
            List <KeyValuePair <string, int> > options = new List <KeyValuePair <string, int> >(party.WeaponInventories[CharacterClass.Enemy].GetSortedItems(partyMember).Where(item => item.Key.StartsWith(searchTerm)));
            ThinkAction thinkAction;

            if (options.Count > 0)
            {
                string weaponName = options.Sample().Key;
                thinkAction = new ThinkAction(ThinkActionType.Attack, weaponName, partyMember, ChooseTargetForEnemyPartyMember(battle));
                thinkAction.Actor.EquipWeapon(weaponName);
                takeFromInventory(thinkAction, partyMember);
            }
            else
            {
                thinkAction = new ThinkAction(ThinkActionType.Defend, "", partyMember);
            }
            return(thinkAction);
        }
Esempio n. 18
0
 private void finishThinkForCurrentPartyMember()
 {
     if (currentThinkAction.Target != null || currentThinkAction.Type == ThinkActionType.Defend)
     {
         takeFromInventory(currentThinkAction, CurrentPartyMember);
         Actions.Add(currentThinkAction);
         Battle.LastUsedThinkActionTypes.AddOrReplace(CurrentPartyMember, new Wrapper <ThinkActionType>(currentThinkAction.Type));
         getNextPartyMember();
         repopulateMenuOptions();
         currentThinkAction = null;
         initThinkActionTypeMenu(ThinkActionType.None);
         if (Actions.Count == Battle.PlayerParty.Count)
         {
             BattleStateRenderer = null;
         }
         else
         {
             BattleStateRenderer.ResetOuterMenuTransitions();
         }
     }
 }
        private void selectAction()
        {
            if (MenuOptions[CurrentOptionNameIndex].Disabled)
                return;

            ThinkMenuOption option = MenuOptions[CurrentOptionNameIndex];
            currentThinkAction = new ThinkAction(CurrentThinkActionType, option.Name, CurrentPartyMember);
            if (CurrentThinkActionType == ThinkActionType.Defend)
                finishThinkForCurrentPartyMember();
            else
            {
                currentThinkAction.InfiniteInInventory = option.Amount < 0;
                PushState(new SelectTarget(Battle, currentThinkAction));
            }
        }
 public virtual void BeforeActUpdate(ThinkAction thinkAction, Delta delta)
 {
 }
 public virtual void BeforeActStart(ThinkAction thinkAction)
 {
 }
 private void takeFromInventory(ThinkAction thinkAction, PartyMember partyMember)
 {
     Inventory inventory = getInventoryFromThinkActionType(thinkAction.Type, partyMember);
     if (inventory != null)
         inventory.UseItem(thinkAction.OptionName, partyMember);
 }
 private ThinkAction thinkForEnemyPartyMember(PartyMember partyMember, Battle battle)
 {
     Party party = battle.GetPartyForPartyMember(partyMember);
     string searchTerm = partyMember.Data.Name.ToUpperFirstChar();
     List<KeyValuePair<string, int>> options = new List<KeyValuePair<string, int>>(party.WeaponInventories[CharacterClass.Enemy].GetSortedItems(partyMember).Where(item => item.Key.StartsWith(searchTerm)));
     ThinkAction thinkAction;
     if (options.Count > 0)
     {
         string weaponName = options.Sample().Key;
         thinkAction = new ThinkAction(ThinkActionType.Attack, weaponName, partyMember, ChooseTargetForEnemyPartyMember(battle));
         thinkAction.Actor.EquipWeapon(weaponName);
         takeFromInventory(thinkAction, partyMember);
     }
     else
         thinkAction = new ThinkAction(ThinkActionType.Defend, "", partyMember);
     return thinkAction;
 }
 public override void BeforeActStart(ThinkAction thinkAction)
 {
     base.BeforeActStart(thinkAction);
     start(thinkAction.Actor);
 }
Esempio n. 25
0
        private void pushStateForThinkAction(ThinkAction thinkAction)
        {
            if (thinkAction == null)
                return;

            if (!statusEffectsCompleteForAction && thinkAction.Actor.Alive)
            {
                PushState(new HandleStatusEffects(Battle, StatusEffectEvent.BeforeAct, thinkAction: thinkAction));
                return;
            }

            if (!thinkAction.Actor.Alive || !thinkAction.Active)
            {
                if (!ThinkMenuOption.IsDefaultOptionName(thinkAction.OptionName))
                {
                    Inventory inventory = getInventoryFromThinkActionType(thinkAction.Type, thinkAction.Actor);
                    if (inventory != null)
                        inventory.AddItem(thinkAction.OptionName, thinkAction.Actor);
                }
                getNextThinkAction();
                return;
            }

            if (thinkAction.Target.Alive)
            {
                if (thinkAction.Type == ThinkActionType.Attack)
                    PushState(new Attack(Battle, thinkAction));
                else
                    PushState(new UseItem(Battle, thinkAction));
            }
            else
            {
                if (Battle.PlayerParty.Count > 0 && Battle.EnemyParty.Count > 0)
                    PushState(new SelectTarget(Battle, thinkAction));
                else
                    Finish();
            }
        }
 private void finishThinkForCurrentPartyMember()
 {
     if (currentThinkAction.Target != null || currentThinkAction.Type == ThinkActionType.Defend)
     {
         takeFromInventory(currentThinkAction, CurrentPartyMember);
         Actions.Add(currentThinkAction);
         Battle.LastUsedThinkActionTypes.AddOrReplace(CurrentPartyMember, new Wrapper<ThinkActionType>(currentThinkAction.Type));
         getNextPartyMember();
         repopulateMenuOptions();
         currentThinkAction = null;
         initThinkActionTypeMenu(ThinkActionType.None);
         if (Actions.Count == Battle.PlayerParty.Count)
             BattleStateRenderer = null;
         else
             BattleStateRenderer.ResetOuterMenuTransitions();
     }
 }