<commit_before>/**
 Copyright (C) 2013 by <NAME>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

/// <reference path="../objects/gameEntityObject.ts" />
/// <reference path="../../tile/components/animatedSpriteComponent.ts" />
/// <reference path="../gameStateMachine.ts" />
/// <reference path="./gameMapState.ts" />
/// <reference path="./combat/combatBeginTurnState.ts" />
/// <reference path="./combat/combatEndTurnState.ts" />
/// <reference path="./combat/combatVictoryState.ts" />
/// <reference path="./combat/combatDefeatState.ts" />
/// <reference path="./combat/combatStartState.ts" />
/// <reference path="../components/combatCameraComponent.ts" />
/// <reference path="../models/entityModel.ts" />
/// <reference path="../models/creatureModel.ts" />


module pow2 {


   // Combat State Machine
   //--------------------------------------------------------------------------
   export class CombatStateMachine extends StateMachine {
      parent:GameStateMachine;
      defaultState:string = CombatStartState.NAME;
      states:IState[] = [
         new CombatStartState(),
         new CombatVictoryState(),
         new CombatDefeatState(),
         new CombatBeginTurnState(),
         new CombatEndTurnState()
      ];

      party:GameEntityObject[] = [];
      enemies:GameEntityObject[] = [];
      turnList:GameEntityObject[] = [];

      current:GameEntityObject;
      currentDone:boolean = false;


      isFriendlyTurn():boolean {
         return this.current && !!_.find(this.party,(h) => {
            return h.id === this.current.id;
         });
      }

      getLiveParty():GameEntityObject[] {
         return _.reject(this.party,(obj:GameEntityObject) => {
            return obj.isDefeated();
         });
      }
      getLiveEnemies():GameEntityObject[] {
         return _.reject(this.enemies,(obj:GameEntityObject) => {
            return obj.isDefeated();
         });
      }

      getRandomPartyMember():GameEntityObject {
         var players:GameEntityObject[] = _.shuffle(this.party);
         while(players.length > 0){
            var p = players.shift();
            if(!p.isDefeated()){
               return p;
            }
         }
         return null;
      }

      getRandomEnemy():GameEntityObject {
         var players:GameEntityObject[] = _.shuffle(this.enemies);
         while(players.length > 0){
            var p = players.shift();
            if(!p.isDefeated()){
               return p;
            }
         }
         return null;
      }

      partyDefeated():boolean {
         var deadList = _.reject(this.party,(obj:GameEntityObject) => {
            return obj.model.attributes.hp <= 0;
         });
         return deadList.length === 0;
      }
      enemiesDefeated():boolean {
         return _.reject(this.enemies,(obj:GameEntityObject) => {
            return obj.model.attributes.hp <= 0;
         }).length === 0;
      }

      keyListener:any = null;
      constructor(parent:GameStateMachine){
         super();
         this.parent = parent;
      }
   }


   // Combat States
   //--------------------------------------------------------------------------
   export class CombatState extends State {
      enter(machine:CombatStateMachine){
         super.enter(machine);
         machine.keyListener = (e) => {
            if(this.keyPress(machine,e.keyCode) === false){
               e.preventDefault();
               return false;
            }
            return true;
         };
         $(window).on('keypress',machine.keyListener);
      }
      exit(machine:CombatStateMachine){
         $(window).off('keypress',machine.keyListener);
         super.exit(machine);<commit_msg>Don't process key input when combat is paused.<commit_after>/**
 Copyright (C) 2013 by <NAME>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

/// <reference path="../objects/gameEntityObject.ts" />
/// <reference path="../../tile/components/animatedSpriteComponent.ts" />
/// <reference path="../gameStateMachine.ts" />
/// <reference path="./gameMapState.ts" />
/// <reference path="./combat/combatBeginTurnState.ts" />
/// <reference path="./combat/combatEndTurnState.ts" />
/// <reference path="./combat/combatVictoryState.ts" />
/// <reference path="./combat/combatDefeatState.ts" />
/// <reference path="./combat/combatStartState.ts" />
/// <reference path="../components/combatCameraComponent.ts" />
/// <reference path="../models/entityModel.ts" />
/// <reference path="../models/creatureModel.ts" />


module pow2 {


   // Combat State Machine
   //--------------------------------------------------------------------------
   export class CombatStateMachine extends StateMachine {
      parent:GameStateMachine;
      defaultState:string = CombatStartState.NAME;
      states:IState[] = [
         new CombatStartState(),
         new CombatVictoryState(),
         new CombatDefeatState(),
         new CombatBeginTurnState(),
         new CombatEndTurnState()
      ];

      party:GameEntityObject[] = [];
      enemies:GameEntityObject[] = [];
      turnList:GameEntityObject[] = [];

      current:GameEntityObject;
      currentDone:boolean = false;


      isFriendlyTurn():boolean {
         return this.current && !!_.find(this.party,(h) => {
            return h.id === this.current.id;
         });
      }

      getLiveParty():GameEntityObject[] {
         return _.reject(this.party,(obj:GameEntityObject) => {
            return obj.isDefeated();
         });
      }
      getLiveEnemies():GameEntityObject[] {
         return _.reject(this.enemies,(obj:GameEntityObject) => {
            return obj.isDefeated();
         });
      }

      getRandomPartyMember():GameEntityObject {
         var players:GameEntityObject[] = _.shuffle(this.party);
         while(players.length > 0){
            var p = players.shift();
            if(!p.isDefeated()){
               return p;
            }
         }
         return null;
      }

      getRandomEnemy():GameEntityObject {
         var players:GameEntityObject[] = _.shuffle(this.enemies);
         while(players.length > 0){
            var p = players.shift();
            if(!p.isDefeated()){
               return p;
            }
         }
         return null;
      }

      partyDefeated():boolean {
         var deadList = _.reject(this.party,(obj:GameEntityObject) => {
            return obj.model.attributes.hp <= 0;
         });
         return deadList.length === 0;
      }
      enemiesDefeated():boolean {
         return _.reject(this.enemies,(obj:GameEntityObject) => {
            return obj.model.attributes.hp <= 0;
         }).length === 0;
      }

      keyListener:any = null;
      constructor(parent:GameStateMachine){
         super();
         this.parent = parent;
      }
   }


   // Combat States
   //--------------------------------------------------------------------------
   export class CombatState extends State {
      enter(machine:CombatStateMachine){
         super.enter(machine);
         machine.keyListener = (e) => {
            if(machine.paused === false && this.keyPress(machine,e.keyCode) === false){
               e.preventDefault();
               return false;
            }
            return true;
         };
         $(window).on('keypress',machine.keyListener);
      }
      exit(machine:CombatStateMachine){
         $(window).off('keypress',machine.keyListener);
         super.exit(machine);
{'fraction_non_alphanumeric': 0.1672822590253783, 'fraction_numerical': 0.003574407244132015, 'mean_word_length': 2.0086021505376346, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1771165', 'n_tokens_mistral': 2258, 'n_tokens_neox': 2173, 'n_words': 466}