Exemplo n.º 1
0
        private static bool Hit(GameCharacter attacker, GameCharacter defender, BattleGame game, Ammo ammo)
        {
            int bonusDamage = 0;

            if (ammo != null)
            {
                bonusDamage = ammo.bonusDamage;

                if (ammo.activeEffects != null)
                {
                    foreach (var ae in ammo.activeEffects)
                    {
                        defender.AddActiveEffect(AbilityHelper.cloneActiveEffect(ae), game);
                    }
                }
            }

            int dmg = game.r.Next(attacker.weapon.minDamage, attacker.weapon.maxDamage) + bonusDamage;

            defender.Damage(dmg, game);

            game.battleLog.AddEntry(string.Format("{0} hit {1} for {2} damage.", attacker.name, defender.name, dmg));
            game.gameControllerScript.StartTempTextOnChar(defender, dmg, true);
            game.gameControllerScript.StartTempSpriteOnChar(defender, "DamageEffects", 1);

            if (attacker.weapon.activeEffects != null)
            {
                foreach (var ae in attacker.weapon.activeEffects)
                {
                    defender.AddActiveEffect(AbilityHelper.cloneActiveEffect(ae), game);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private static void UseAbilityTempEffect(BattleGame game, GameCharacter character, Tile target, Ability ability)
        {
            foreach (var ae in ability.activeEffects)
            {
                switch (ae.effectType)
                {
                case TempEffectType.Particle:
                    game.gameControllerScript.StartTempParticles(ae.effectName, new UnityEngine.Vector3(target.x, -target.y));
                    break;

                case TempEffectType.Sprite:
                    var spriteVector = new UnityEngine.Vector3(target.x, -target.y);
                    game.gameControllerScript.StartTempSprite(spriteVector, spriteVector, ae.effectName, ae.effectIndex);
                    break;

                case TempEffectType.Text:
                    game.gameControllerScript.StartTempText(new UnityEngine.Vector3(target.x, -target.y), UnityEngine.Color.grey, ability.name);
                    break;

                case TempEffectType.ProjectileSprite:
                    var spriteVector1 = new UnityEngine.Vector3(game.ActiveCharacter.x, -game.ActiveCharacter.y);
                    var spriteVector2 = new UnityEngine.Vector3(target.x, -target.y);

                    game.gameControllerScript.StartTempSpriteProjectile(spriteVector1, spriteVector2, ae.effectName, ae.effectIndex);

                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 3
0
        }                                                //updates every turn

        public AIActor(GameCharacter character, EnemyType type)
        {
            this.character = character;
            this.enemyType = type;

            InitActionWeight();
        }
Exemplo n.º 4
0
        private static void UseAbilityTempEffect(BattleGame game,GameCharacter character, Tile target, Ability ability)
        {

            foreach (var ae in ability.activeEffects)
            {
                switch (ae.effectType)
                {
                    case TempEffectType.Particle:
                        game.gameControllerScript.StartTempParticles(ae.effectName, new UnityEngine.Vector3(target.x, -target.y));
                        break;
                    case TempEffectType.Sprite:
                        var spriteVector = new UnityEngine.Vector3(target.x, -target.y);
                        game.gameControllerScript.StartTempSprite(spriteVector, spriteVector, ae.effectName, ae.effectIndex);
                        break;
                    case TempEffectType.Text:
                        game.gameControllerScript.StartTempText(new UnityEngine.Vector3(target.x, -target.y), UnityEngine.Color.grey, ability.name);
                        break;
                    case TempEffectType.ProjectileSprite:
                        var spriteVector1 = new UnityEngine.Vector3(game.ActiveCharacter.x, -game.ActiveCharacter.y);
                        var spriteVector2 = new UnityEngine.Vector3(target.x, -target.y);

                        game.gameControllerScript.StartTempSpriteProjectile(spriteVector1, spriteVector2, ae.effectName, ae.effectIndex);
                      
                         break;
                    default:
                         break;
                }
            }

        }
Exemplo n.º 5
0
 public void FillTile(GameCharacter gc, Tile t)
 {
     t.empty    = false;
     gc.x       = t.x;
     gc.y       = t.y;
     t.TileChar = gc.displayChar;
 }
Exemplo n.º 6
0
        //helper to cleanly remove characters from battle and keep the current character counter correct
        public void RemoveCharacter(GameCharacter character)
        {
            GameCharacter activeChar = ActiveCharacter;

            characterList.Remove(character);
            currentCharacter = characterList.IndexOf(activeChar);
        }
Exemplo n.º 7
0
        public bool MoveCharacter(GameCharacter gc, Tile Destination)
        {
            bool retval = false;

            if (Destination != null)
            {
                if (Destination.empty)
                {
                    if (!CoreHelper.checkEffect(gc.activeEffects, gc.passiveEffects, StatType.Stuck))
                    {
                        //Use Actionpoints to Move
                        Tile curTile = getTileFromLocation(gc.x, gc.y);
                        if (gc.SpendAP(getTileDistance(curTile, Destination)))
                        {
                            EmptyTile(board[gc.x, gc.y]);
                            FillTile(gc, Destination);

                            retval = true;
                        }
                    }
                }
            }

            return(retval);
        }
Exemplo n.º 8
0
        //DEPRECATED

        /*
         * public static void attackNearestPlayer(GameCharacter enemy, BattleGame game)
         * {
         *
         *  var attackTarget= getAttackablePlayer(enemy,game);
         *  if (attackTarget != null)
         *  {
         *      attackPlayer(enemy, attackTarget, game);
         *  }
         *  else
         *  {
         *      var moveTarget = findNearestPlayer(enemy, game.board, game.characterList);
         *      moveToPlayer(enemy, moveTarget, game.board);
         *  }
         *
         * }
         * */

        //DEPRECATED
        private static void attackPlayer(GameCharacter enemy, GameCharacter player, BattleGame game)
        {
            if (enemy.SpendAP(enemy.weapon.actionPoints))
            {
                CombatHelper.Attack(enemy, player, game);
            }
        }
Exemplo n.º 9
0
        public static List <BattleAction> attackNearestPlayer(GameCharacter enemy, BattleGame game)
        {
            List <BattleAction> actionList = new List <BattleAction>();

            var attackTarget = findNearestPlayer(enemy, game.board, game.characterList);

            var targetTile = game.board.getTileFromLocation(attackTarget.x, attackTarget.y);

            //path find to target
            List <Point> pointList = PathFind.Pathfind(game.board, enemy.x, enemy.y, targetTile.x, targetTile.y);

            pointList.RemoveAt(0);                   //remove the character from pathfind.
            pointList.RemoveAt(pointList.Count - 1); //remove the target from pathfind.

            foreach (var p in pointList)
            {
                actionList.Add(new BattleAction()
                {
                    AP = 1, character = enemy, actionType = BattleActionType.Move, targetTile = game.board.getTileFromPoint(p)
                });
            }

            //attack action
            actionList.Add(new BattleAction()
            {
                AP = enemy.weapon.actionPoints, character = enemy, targetTile = targetTile, actionType = BattleActionType.Attack
            });

            return(actionList);
        }
Exemplo n.º 10
0
        //DEPRECATED
        /*
        public static void attackNearestPlayer(GameCharacter enemy, BattleGame game)
        {
            
            var attackTarget= getAttackablePlayer(enemy,game);
            if (attackTarget != null)
            {
                attackPlayer(enemy, attackTarget, game);
            }
            else
            {
                var moveTarget = findNearestPlayer(enemy, game.board, game.characterList);
                moveToPlayer(enemy, moveTarget, game.board);
            }
            
        }
         * */

        //DEPRECATED
        private static void attackPlayer(GameCharacter enemy, GameCharacter player, BattleGame game)
        {
            if(enemy.SpendAP(enemy.weapon.actionPoints))
            {
                CombatHelper.Attack(enemy, player, game);
            }
        }
Exemplo n.º 11
0
        private static EnemyCharacter getEnemyFromGameCharacter(GameCharacter gameChar, EnemyType enemyType)
        {
            EnemyCharacter enemyChar = new EnemyCharacter(enemyType)
            {
                abilityList              = gameChar.abilityList,
                ac                       = gameChar.ac,
                activeEffects            = gameChar.activeEffects,
                Ammo                     = gameChar.Ammo,
                ap                       = gameChar.ap,
                attack                   = gameChar.attack,
                characterSpriteIndex     = gameChar.characterSpriteIndex,
                characterSpritesheetName = gameChar.characterSpritesheetName,
                displayChar              = gameChar.displayChar,
                enemyType                = enemyType,
                equippedArmor            = gameChar.equippedArmor,
                hp                       = gameChar.hp,
                inventory                = gameChar.inventory,
                name                     = gameChar.name,
                passiveEffects           = gameChar.passiveEffects,
                portraitSpriteIndex      = gameChar.portraitSpriteIndex,
                portraitSpritesheetName  = gameChar.portraitSpritesheetName,
                totalAP                  = gameChar.totalAP,
                totalHP                  = gameChar.totalHP,
                type                     = CharacterType.Enemy,
                weapon                   = gameChar.weapon,
                x         = gameChar.x,
                y         = gameChar.y,
                strength  = gameChar.strength,
                agility   = gameChar.agility,
                endurance = gameChar.endurance,
                spirit    = gameChar.spirit
            };

            return(enemyChar);
        }
Exemplo n.º 12
0
        public List<AIAction> AIActionList { get; set; } //updates every turn

        public AIActor(GameCharacter character, EnemyType type)
        {
            this.character = character;
            this.enemyType = type;

            InitActionWeight();

        }
Exemplo n.º 13
0
        public bool UseItem(GameCharacter character, UsableItem item, Tile targetTile)
        {
            bool usedItem = false;

            if (!CoreHelper.checkEffect(character.activeEffects, character.passiveEffects, StatType.Stun))
            {
                if (character.CheckAP(item.actionPoints))
                {
                    if (item.activeEffects != null)
                    {
                        foreach (var a in item.activeEffects)
                        {
                            character.AddActiveEffect(a, this);
                        }
                        usedItem = true;
                        character.SpendAP(item.actionPoints);
                        item.uses--;
                    }

                    else if (item.itemAbility != null)
                    {
                        bool usedAbility = AbilityHelper.UseAbility(ActiveCharacter, item.itemAbility, targetTile, this);
                        if (usedAbility)
                        {
                            usedItem = true;
                            character.SpendAP(item.actionPoints);
                            item.uses--;
                        }
                    }

                    if (item.uses <= 0)
                    {
                        //should this logic be here?
                        battleLog.AddEntry(string.Format("{0} has no more uses.", item.name));

                        ActiveCharacter.removeUsableItem(item);
                        //ActiveCharacter.inventory.Remove(item);
                    }
                }

                if (usedItem)
                {
                    battleLog.AddEntry(string.Format("{0} used item {1}", character.name, item.name));
                    return(true);
                }
                else
                {
                    battleLog.AddEntry(string.Format("{0} was unable to use item {1}", character.name, item.name));
                    return(false);
                }
            }
            else
            {
                battleLog.AddEntry(string.Format("{0} is stunned and unable to use {1}.", character.name, item.name));
            }

            return(false);
        }
Exemplo n.º 14
0
        //iterates over the path find and moves single spaces
        public static void moveToPlayer(GameCharacter enemy, GameCharacter target, Board board)
        {
            var pointList = PathFind.Pathfind(board, enemy.x, enemy.y, target.x, target.y);

            foreach (var p in pointList)
            {
                board.MoveCharacter(enemy, board.getTileFromLocation(p.x, p.y));
            }
        }
Exemplo n.º 15
0
        private static bool UseAbilityLOSEmpty(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            if (target.empty)
            {
                return(UseAbilityLOS(character, ability, target, game));
            }

            return(false);
        }
Exemplo n.º 16
0
        public void CharacterKill(GameCharacter character)
        {
            battleLog.AddEntry(string.Format("{0} was killed", character.name));

            Tile tempTile = board.getTileFromLocation(character.x, character.y);

            board.EmptyTile(tempTile);
            RemoveCharacter(character);
        }
Exemplo n.º 17
0
        private static bool UseAbilityLOSEmpty(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            if (target.empty)
            {
                return UseAbilityLOS(character, ability, target, game);
            }

            return false;

        }
Exemplo n.º 18
0
        public static bool UseAbility(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            bool useValue = false;

            if (ability.cooldownTimer == 0)
            {
                switch (ability.targetType)
                {
                case AbilityTargetType.Self:
                    useValue = UseAbilitySelf(character, ability, target, game);
                    break;

                case AbilityTargetType.SingleFriend:
                    useValue = UseAbilitySingleFriend(character, ability, target, game);
                    break;

                case AbilityTargetType.SingleFoe:
                    useValue = UseAbilitySingleFoe(character, ability, target, game);
                    break;

                case AbilityTargetType.AllFriends:
                    useValue = UseAbilityAllFriends(character, ability, target, game);
                    break;

                case AbilityTargetType.AllFoes:
                    useValue = UseAbilityAllFoes(character, ability, target, game);
                    break;

                case AbilityTargetType.PointEmpty:
                    useValue = UseAbilityPointEmpty(character, ability, target, game);
                    break;

                case AbilityTargetType.PointTarget:
                    useValue = UseAbilityPoint(character, ability, target, game);
                    break;

                case AbilityTargetType.LOSEmpty:
                    useValue = UseAbilityLOSEmpty(character, ability, target, game);
                    break;

                case AbilityTargetType.LOSTarget:
                    useValue = UseAbilityLOS(character, ability, target, game);
                    break;

                default:
                    useValue = false;
                    break;
                }
            }
            if (useValue)
            {
                ability.cooldownTimer = ability.cooldown;
            }
            return(useValue);
        }
Exemplo n.º 19
0
        public static bool Attack(GameCharacter attacker, GameCharacter defender, BattleGame game)
        {
            if (game.r.Next(20) + attacker.attack > defender.ac)
            {
                var tempTile = game.board.getTileFromLocation(defender.x, defender.y);

                return(Hit(attacker, defender, game, null));
            }
            else
            {
                game.battleLog.AddEntry(string.Format("{0} missed {1}.", attacker.name, defender.name));
                return(false);
            }
        }
Exemplo n.º 20
0
 private static bool UseAbilitySelf(GameCharacter character, Ability ability, Tile target, BattleGame game)
 {
     if (character.SpendAP(ability.ap))
     {
         return(UseAbilityOnCharList(character, target, ability, new List <GameCharacter>()
         {
             character
         }, game));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 21
0
        public static bool Attack(GameCharacter attacker, GameCharacter defender, BattleGame game)
        {
            if(game.r.Next(20) + attacker.attack > defender.ac)
            {

                var tempTile = game.board.getTileFromLocation(defender.x, defender.y);

                return Hit(attacker, defender, game,null);
            }
            else
            {
                game.battleLog.AddEntry(string.Format("{0} missed {1}.", attacker.name, defender.name));
                return false;
            }
        }
Exemplo n.º 22
0
        private static bool UseAbilityPoint(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            Tile ActiveTile = game.board.getTileFromLocation(character.x, character.y);

            int dist = PlotLine.GetPointsOnLine(character.x, character.y, target.x, target.y).Count() - 1;

            if (dist <= ability.range)
            {
                if (character.SpendAP(ability.ap))
                {
                    return(UseAbilityAOEHelper(character, ability, target, game));
                }
            }
            return(false);
        }
Exemplo n.º 23
0
        private static bool UseAbilityAllFoes(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            if (character.SpendAP(ability.ap))
            {
                var foeList = from data in game.characterList
                              where data.type != character.type
                              select data;

                return(UseAbilityOnCharList(character, target, ability, foeList.ToList(), game));
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 24
0
 private static bool UseAbilitySingleFoe(GameCharacter character, Ability ability, Tile target, BattleGame game)
 {
     if (character.SpendAP(ability.ap))
     {
         GameCharacter targetChar = game.getCharacterFromTile(target);
         if (targetChar != null & targetChar.type != character.type)
         {
             return(UseAbilityOnCharList(character, target, ability, new List <GameCharacter>()
             {
                 targetChar
             }, game));
         }
     }
     return(false);
 }
Exemplo n.º 25
0
        private static bool UseAbilityAOEHelper(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            var tileAOEList = game.board.getTileListFromPattern(target, ability.tilePatternType);

            //draw AOE effect
            foreach (var t in tileAOEList)
            {
                game.board.AddTempChar(t, '*');
                game.board.AddTempEffect(t, ability.sheetname, ability.spriteindex);


                UseAbilityTempEffect(game, character, t, ability);
            }

            var charAOEList = game.getCharactersFromTileList(tileAOEList);

            return(UseAbilityOnCharList(character, target, ability, charAOEList, game));
        }
Exemplo n.º 26
0
        private static bool UseAbilityLOS(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            Tile ActiveTile  = game.board.getTileFromLocation(character.x, character.y);
            var  tileLOSList = game.board.getBoardLOS(ActiveTile, target);

            if (tileLOSList.Count <= ability.range && tileLOSList[tileLOSList.Count - 1] == target)
            {
                if (character.SpendAP(ability.ap))
                {
                    return(UseAbilityAOEHelper(character, ability, target, game));
                }
                return(false);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 27
0
        //same as Melee attack, but add movement until we are LOS to nearest enemy
        private List <AIAction> getAIRangedAttackActions(BattleGame game)
        {
            List <AIAction> aiActionList = new List <AIAction>();

            if (character.weapon != null)
            {
                if (character.weapon.weaponType == WeaponType.OneHandRanged || character.weapon.weaponType == WeaponType.TwoHandRanged)
                {
                    //should actually find who has easiest LOS
                    GameCharacter targetCharacter = AI.findNearestPlayer(character, game.board, game.characterList);

                    Tile         characterTile = game.board.getTileFromLocation(character.x, character.y);
                    Tile         targetTile    = game.board.getTileFromLocation(targetCharacter.x, targetCharacter.y);
                    List <Point> pointList     = game.board.getPathToLOS(characterTile, targetTile);

                    int dist = pointList.Count;

                    int cost = dist + character.weapon.actionPoints;

                    List <BattleAction> battleActionList = new List <BattleAction>();

                    foreach (var p in pointList)
                    {
                        battleActionList.Add(new BattleAction()
                        {
                            AP = 1, character = character, actionType = BattleActionType.Move, targetTile = game.board.getTileFromPoint(p)
                        });
                    }

                    battleActionList.Add(new BattleAction()
                    {
                        AP = character.weapon.actionPoints, character = character, targetCharacter = targetCharacter, targetTile = game.board.getTileFromLocation(targetCharacter.x, targetCharacter.y), actionType = BattleActionType.RangedAttack
                    });


                    aiActionList.Add(new AIAction()
                    {
                        actionType = AIActionType.Attack, cost = cost, battleActionList = battleActionList
                    });
                }
            }

            return(aiActionList);
        }
Exemplo n.º 28
0
        public static GameCharacter getAttackablePlayer(GameCharacter enemy, BattleGame game)
        {
            Tile curTile  = game.board.getTileFromLocation(enemy.x, enemy.y);
            var  charList = game.getCharactersFromTileList(game.board.getTileListFromPattern(curTile, TilePatternType.FourAdj));

            var playerList = (from data in charList
                              where data.type == CharacterType.Player
                              select data).ToList();

            //for now, just return a random enemy close
            if (playerList.Count > 0)
            {
                return(charList[game.r.Next(charList.Count - 1)]);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 29
0
        //Move character without spending Action Points
        public bool MoveCharacterFree(GameCharacter gc, Tile Destination)
        {
            bool retval = false;

            if (Destination != null)
            {
                if (Destination.empty)
                {
                    if (!CoreHelper.checkEffect(gc.activeEffects, gc.passiveEffects, StatType.Stuck))
                    {
                        EmptyTile(board[gc.x, gc.y]);
                        FillTile(gc, Destination);

                        retval = true;
                    }
                }
            }
            return(retval);
        }
Exemplo n.º 30
0
        public static GameCharacter findNearestPlayer(GameCharacter enemy, Board board, List <GameCharacter> charList)
        {
            GameCharacter retval = null;
            int           dist   = 999;

            foreach (GameCharacter c in charList)
            {
                if (c.type == CharacterType.Player)
                {
                    var pointList = PathFind.Pathfind(board, enemy.x, enemy.y, c.x, c.y);
                    if (pointList.Count < dist)
                    {
                        dist   = pointList.Count;
                        retval = c;
                    }
                }
            }
            return(retval);
        }
Exemplo n.º 31
0
        private static bool UseAbilityLOS(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            Tile ActiveTile = game.board.getTileFromLocation(character.x, character.y);
            var tileLOSList = game.board.getBoardLOS(ActiveTile, target);

            if (tileLOSList.Count <= ability.range && tileLOSList[tileLOSList.Count - 1] == target)
            {
                if (character.SpendAP(ability.ap))
                {
                    return UseAbilityAOEHelper(character, ability, target, game);
                }
                return false;
            }
            else
            {
                return false;
            }

        }
Exemplo n.º 32
0
        //if we have a melee weapon, calculate nearest enemy + weapon ap
        private List <AIAction> getAIAttackActions(BattleGame game)
        {
            List <AIAction> aiActionList = new List <AIAction>();

            if (character.weapon != null)
            {
                if (character.weapon.weaponType == WeaponType.OneHandMelee || character.weapon.weaponType == WeaponType.TwoHandMelee)
                {
                    GameCharacter targetCharacter = AI.findNearestPlayer(character, game.board, game.characterList);

                    List <Point> pointList = PathFind.Pathfind(game.board, character.x, character.y, targetCharacter.x, targetCharacter.y);
                    pointList.RemoveAt(0);                   //remove the character from pathfind.
                    pointList.RemoveAt(pointList.Count - 1); //remove the target from pathfind.

                    int dist = pointList.Count;

                    int cost = dist + character.weapon.actionPoints;

                    List <BattleAction> battleActionList = new List <BattleAction>();

                    foreach (var p in pointList)
                    {
                        battleActionList.Add(new BattleAction()
                        {
                            AP = 1, character = character, actionType = BattleActionType.Move, targetTile = game.board.getTileFromPoint(p)
                        });
                    }

                    battleActionList.Add(new BattleAction()
                    {
                        AP = character.weapon.actionPoints, character = character, targetCharacter = targetCharacter, targetTile = game.board.getTileFromLocation(targetCharacter.x, targetCharacter.y), actionType = BattleActionType.Attack
                    });

                    aiActionList.Add(new AIAction()
                    {
                        actionType = AIActionType.Attack, cost = cost, battleActionList = battleActionList
                    });
                }
            }

            return(aiActionList);
        }
Exemplo n.º 33
0
        public static GameCharacter getAttackablePlayer(GameCharacter enemy, BattleGame game)
        {
            Tile curTile = game.board.getTileFromLocation(enemy.x,enemy.y);
            var charList = game.getCharactersFromTileList(game.board.getTileListFromPattern(curTile, TilePatternType.FourAdj));

            var playerList = (from data in charList
                             where data.type == CharacterType.Player
                             select data).ToList();

            //for now, just return a random enemy close 
            if (playerList.Count > 0)
            {
                return charList[game.r.Next(charList.Count - 1)];
            }
            else
            {
                return null;
            }

        }
Exemplo n.º 34
0
        private static bool UseAbilityAOEHelper(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {

            var tileAOEList = game.board.getTileListFromPattern(target, ability.tilePatternType);

            //draw AOE effect
            foreach (var t in tileAOEList)
            {
                game.board.AddTempChar(t, '*');
                game.board.AddTempEffect(t, ability.sheetname, ability.spriteindex);


                UseAbilityTempEffect(game, character, t, ability);

            }

            var charAOEList = game.getCharactersFromTileList(tileAOEList);

            return UseAbilityOnCharList(character,target, ability, charAOEList, game);

        }
Exemplo n.º 35
0
        private bool RangedAttack(GameCharacter character, Tile destination)
        {
            if (!CoreHelper.checkEffect(character.activeEffects, character.passiveEffects, StatType.Stun))
            {
                GameCharacter target = getCharacterFromTile(destination);

                if (target != null)
                {
                    if (CombatHelper.RangedAttack(character, target, destination, this))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                battleLog.AddEntry(string.Format("{0} is stunned and unable to attack.", character.name));
            }

            return(false);
        }
Exemplo n.º 36
0
        private bool Move(GameCharacter character, int x, int y)
        {
            if (!CoreHelper.checkEffect(character.activeEffects, character.passiveEffects, StatType.Stun))
            {
                bool canMove = board.MoveCharacter(character, board.getTileFromLocation(x, y));
                if (canMove)
                {
                    battleLog.AddEntry(string.Format("{0} moved to {1},{2}", character.name, x, y));
                }
                else
                {
                    battleLog.AddEntry(string.Format("{0} was unable to move to {1},{2}", character.name, x, y));
                }
                return(canMove);
            }
            else
            {
                battleLog.AddEntry(string.Format("{0} is stunned and unable to move.", character.name));
            }

            return(false);
        }
Exemplo n.º 37
0
        private bool Attack(GameCharacter character, Tile targetTile)
        {
            if (!CoreHelper.checkEffect(character.activeEffects, character.passiveEffects, StatType.Stun))
            {
                GameCharacter target = getCharacterFromTile(targetTile);
                if (target != null)
                {
                    if (character.weapon != null)
                    {
                        if (character.SpendAP(character.weapon.actionPoints))
                        {
                            return(CombatHelper.Attack(character, target, this));
                        }
                    }
                }
            }
            else
            {
                battleLog.AddEntry(string.Format("{0} is stunned and unable attack.", character.name));
            }

            return(false);
        }
Exemplo n.º 38
0
        public static List<BattleAction> attackNearestPlayer(GameCharacter enemy, BattleGame game)
        {
            List<BattleAction> actionList = new List<BattleAction>();

            var attackTarget = findNearestPlayer(enemy, game.board,game.characterList);

            var targetTile = game.board.getTileFromLocation(attackTarget.x, attackTarget.y);

            //path find to target
            List<Point> pointList = PathFind.Pathfind(game.board, enemy.x, enemy.y, targetTile.x, targetTile.y);
            pointList.RemoveAt(0); //remove the character from pathfind.
            pointList.RemoveAt(pointList.Count - 1); //remove the target from pathfind.

            foreach (var p in pointList)
            {
                actionList.Add(new BattleAction() { AP=1, character = enemy, actionType = BattleActionType.Move, targetTile = game.board.getTileFromPoint(p) });
            }

            //attack action
            actionList.Add(new BattleAction() { AP=enemy.weapon.actionPoints, character = enemy, targetTile = targetTile, actionType = BattleActionType.Attack });

            return actionList;
        }
Exemplo n.º 39
0
        public bool UseAbility(GameCharacter character, Ability ability, Tile target)
        {
            if (!CoreHelper.checkEffect(character.activeEffects, character.passiveEffects, StatType.Stun))
            {
                if (character.abilityList.Contains(ability))
                {
                    if (AbilityHelper.UseAbility(character, ability, target, this))
                    {
                        battleLog.AddEntry(string.Format("{0} used {1}", character.name, ability.name));
                        return(true);
                    }
                    else
                    {
                        battleLog.AddEntry(string.Format("{0} failed to use {1}", character.name, ability.name));
                    }
                }
            }
            else
            {
                battleLog.AddEntry(string.Format("{0} is stunned and unable to use {1}.", character.name, ability.name));
            }

            return(false);
        }
Exemplo n.º 40
0
 //helper to cleanly remove characters from battle and keep the current character counter correct
 public void RemoveCharacter(GameCharacter character)
 {
     GameCharacter activeChar = ActiveCharacter;
     characterList.Remove(character);
     currentCharacter = characterList.IndexOf(activeChar);
 }
Exemplo n.º 41
0
 public static GameCharacter findNearestPlayer( GameCharacter enemy, Board board,List<GameCharacter> charList)
 {
     GameCharacter retval = null;
     int dist = 999;
     
     foreach(GameCharacter c in charList)
     {
         if (c.type == CharacterType.Player)
         {
             var pointList = PathFind.Pathfind(board, enemy.x, enemy.y, c.x, c.y);
             if (pointList.Count < dist)
             {
                 dist = pointList.Count;
                 retval = c;
             }
         }
        
     }
     return retval;
 }
Exemplo n.º 42
0
 //iterates over the path find and moves single spaces
 public static void moveToPlayer(GameCharacter enemy, GameCharacter target, Board board)
 {
     var pointList = PathFind.Pathfind(board, enemy.x, enemy.y, target.x, target.y);
     foreach(var p in pointList)
     {
         
         board.MoveCharacter(enemy, board.getTileFromLocation(p.x, p.y));
           
        
     }
 }
Exemplo n.º 43
0
        private static bool UseAbilityPoint(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            Tile ActiveTile = game.board.getTileFromLocation(character.x, character.y);

            int dist = PlotLine.GetPointsOnLine(character.x, character.y, target.x, target.y).Count()-1;

            if(dist <= ability.range)
            {
                if (character.SpendAP(ability.ap))
                {
                    return UseAbilityAOEHelper(character, ability, target, game);
                }
            }
            return false;
        }
Exemplo n.º 44
0
        private static bool UseAbilityAllFoes(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            if (character.SpendAP(ability.ap))
            {
                var foeList = from data in game.characterList
                              where data.type != character.type
                              select data;

                return UseAbilityOnCharList(character,target, ability, foeList.ToList(), game);
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 45
0
        public bool MoveCharacter(GameCharacter gc, Tile Destination)
        {
            bool retval = false;
            if (Destination != null)
            {
                if (Destination.empty)
                {
                    if (!CoreHelper.checkEffect(gc.activeEffects, gc.passiveEffects, StatType.Stuck))
                    {
                        //Use Actionpoints to Move
                        Tile curTile = getTileFromLocation(gc.x, gc.y);
                        if (gc.SpendAP(getTileDistance(curTile, Destination)))
                        {
                            EmptyTile(board[gc.x, gc.y]);
                            FillTile(gc, Destination);

                            retval = true;
                        }
                    }
                }
            }

            return retval;
        }
Exemplo n.º 46
0
        private static EnemyCharacter getEnemyFromGameCharacter(GameCharacter gameChar, EnemyType enemyType)
        {
            EnemyCharacter enemyChar = new EnemyCharacter(enemyType)
            {
                abilityList = gameChar.abilityList,
                ac = gameChar.ac,
                activeEffects = gameChar.activeEffects,
                Ammo = gameChar.Ammo,
                ap = gameChar.ap,
                attack = gameChar.attack,
                characterSpriteIndex = gameChar.characterSpriteIndex,
                characterSpritesheetName = gameChar.characterSpritesheetName,
                displayChar = gameChar.displayChar,
                enemyType = enemyType,
                equippedArmor = gameChar.equippedArmor,
                hp = gameChar.hp,
                inventory = gameChar.inventory,
                name = gameChar.name,
                passiveEffects = gameChar.passiveEffects,
                portraitSpriteIndex = gameChar.portraitSpriteIndex,
                portraitSpritesheetName = gameChar.portraitSpritesheetName,
                totalAP = gameChar.totalAP,
                totalHP = gameChar.totalHP,
                type = CharacterType.Enemy,
                weapon = gameChar.weapon,
                x = gameChar.x,
                y = gameChar.y,
                strength = gameChar.strength,
                agility = gameChar.agility,
                endurance = gameChar.endurance,
                spirit = gameChar.spirit
          
            };

            return enemyChar;
        }
Exemplo n.º 47
0
        private bool Attack(GameCharacter character, Tile targetTile)
        {
            if (!CoreHelper.checkEffect(character.activeEffects, character.passiveEffects, StatType.Stun))
            {
                GameCharacter target = getCharacterFromTile(targetTile);
                if (target != null)
                {
                    if (character.weapon != null)
                    {
                        if (character.SpendAP(character.weapon.actionPoints))
                        {
                            return CombatHelper.Attack(character, target, this);
                        }
                    }
                }
            }
            else
            {
                battleLog.AddEntry(string.Format("{0} is stunned and unable attack.", character.name));
            }

            return false;
        }
Exemplo n.º 48
0
 private static bool UseAbilitySingleFoe(GameCharacter character, Ability ability, Tile target, BattleGame game)
 {
     if (character.SpendAP(ability.ap))
     {
         GameCharacter targetChar = game.getCharacterFromTile(target);
         if (targetChar != null & targetChar.type != character.type)
         {
             return UseAbilityOnCharList(character,target, ability, new List<GameCharacter>() { targetChar }, game);
         }
     }
     return false;
 }
Exemplo n.º 49
0
        private static void UseAbilityTempEffect(BattleGame game, GameCharacter character, GameCharacter target, Ability ability)
        {
            Tile targetTile = game.board.getTileFromPoint(new Point(target.x, target.y));
            UseAbilityTempEffect(game, character, targetTile, ability);

        }
Exemplo n.º 50
0
 private static bool UseAbilitySelf(GameCharacter character, Ability ability, Tile target, BattleGame game)
 {
     if (character.SpendAP(ability.ap))
     {
         return UseAbilityOnCharList(character,target, ability, new List<GameCharacter>() { character }, game);
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 51
0
        public void CharacterKill(GameCharacter character)
        {
            battleLog.AddEntry(string.Format("{0} was killed", character.name));

            Tile tempTile = board.getTileFromLocation(character.x,character.y);
            board.EmptyTile(tempTile);
            RemoveCharacter(character);

        }
Exemplo n.º 52
0
        private static bool UseAbilityOnCharList(GameCharacter sourceCharacter, Tile target, Ability ability, List<GameCharacter> characterList, BattleGame game)
        {

            //Draw Temp Character
             game.board.AddTempChar(target, 'X');
             game.board.AddTempEffect(target, ability.sheetname, ability.spriteindex);



            foreach(var c in characterList)
            {
                UseAbilityTempEffect(game, sourceCharacter, c, ability);
            }
             


            //special conditions if we're doing something on sourceCharacter
            if(characterList.Count ==0)
            {
                foreach (var ae in ability.activeEffects)
                {
                    if (ae.statType == StatType.Teleport)
                    {
                        game.board.MoveCharacterFree(sourceCharacter, target);
                    }
                }
            }

            foreach (var character in characterList)
            {
                foreach (var ae in ability.activeEffects)
                {
                    if (ae.statType == StatType.Teleport)
                    {
                        game.board.MoveCharacterFree(sourceCharacter, target); //for now, can only teleport self.
                    }
                    else if (ae.statType == StatType.Knockback) //move away from sourceCharacter
                    {
                        Tile sourceTile = game.board.getTileFromLocation(sourceCharacter.x, sourceCharacter.y);
                        Tile charTile = game.board.getTileFromLocation(character.x, character.y);
                        List<Tile> moveTargetList = game.board.getMoveTargetTileList(sourceTile, charTile, ae.minAmount);

                        if (moveTargetList.Count > 0)
                        {
                            Tile moveTile = moveTargetList[moveTargetList.Count - 1];
                            game.board.MoveCharacterFree(character, moveTile);
                        }
                    }
                    else if(ae.statType == StatType.Explode) //move away from target
                    {
                        Tile charTile = game.board.getTileFromLocation(character.x, character.y);
                        List<Tile> moveTargetList = game.board.getMoveTargetTileList(target, charTile, ae.minAmount);
                        if (moveTargetList.Count > 0)
                        {
                            Tile moveTile = moveTargetList[moveTargetList.Count - 1];
                            game.board.MoveCharacterFree(character, moveTile);
                        }
                    }
                    else
                    {
                        character.AddActiveEffect(cloneActiveEffect(ae), game);
                    }
                }
            }

            return true;
        }
Exemplo n.º 53
0
        public bool UseAbility(GameCharacter character, Ability ability, Tile target)
        {
            if (!CoreHelper.checkEffect(character.activeEffects, character.passiveEffects, StatType.Stun))
            {
                if (character.abilityList.Contains(ability))
                {
                    if (AbilityHelper.UseAbility(character, ability, target, this))
                    {
                        battleLog.AddEntry(string.Format("{0} used {1}", character.name, ability.name));
                        return true;
                    }
                    else
                    {
                        battleLog.AddEntry(string.Format("{0} failed to use {1}", character.name, ability.name));
                    }
                }
            }
            else
            {
                battleLog.AddEntry(string.Format("{0} is stunned and unable to use {1}.", character.name, ability.name));
            }

            return false;
        }
Exemplo n.º 54
0
 public static bool UseAbility(GameCharacter character, Ability ability, Tile target, BattleGame game)
 {
     bool useValue = false;
     if (ability.cooldownTimer == 0)
     {
         switch (ability.targetType)
         {
             case AbilityTargetType.Self:
                 useValue= UseAbilitySelf(character, ability, target, game);
                 break;
             case AbilityTargetType.SingleFriend:
                 useValue= UseAbilitySingleFriend(character, ability, target, game);
                 break;
             case AbilityTargetType.SingleFoe:
                 useValue= UseAbilitySingleFoe(character, ability, target, game);
                 break;
             case AbilityTargetType.AllFriends:
                 useValue= UseAbilityAllFriends(character, ability, target, game);
                 break;
             case AbilityTargetType.AllFoes:
                 useValue = UseAbilityAllFoes(character, ability, target, game);
                 break;
             case AbilityTargetType.PointEmpty:
                 useValue = UseAbilityPointEmpty(character, ability, target, game);
                 break;
             case AbilityTargetType.PointTarget:
                 useValue = UseAbilityPoint(character, ability, target, game);
                 break;
             case AbilityTargetType.LOSEmpty:
                 useValue = UseAbilityLOSEmpty(character, ability, target, game);
                 break;
             case AbilityTargetType.LOSTarget:
                 useValue = UseAbilityLOS(character, ability, target, game);
                 break;
             default:
                 useValue = false;
                 break;
         }
     }
     if (useValue)
     {
         ability.cooldownTimer = ability.cooldown;
     }
     return useValue;
 }
Exemplo n.º 55
0
        public bool UseItem(GameCharacter character, UsableItem item, Tile targetTile)
        {

            bool usedItem = false;

            if (!CoreHelper.checkEffect(character.activeEffects, character.passiveEffects, StatType.Stun))
            {
                if (character.CheckAP(item.actionPoints))
                {
                    if (item.activeEffects != null)
                    {
                        foreach (var a in item.activeEffects)
                        {
                            character.AddActiveEffect(a, this);
                        }
                        usedItem = true;
                        character.SpendAP(item.actionPoints);
                        item.uses--;
                    }

                    else if(item.itemAbility != null)
                    {
                        bool usedAbility = AbilityHelper.UseAbility(ActiveCharacter, item.itemAbility, targetTile, this);
                        if(usedAbility)
                        {
                            usedItem = true;
                            character.SpendAP(item.actionPoints);
                            item.uses--;
                        }
                    }

                    if (item.uses <= 0)
                    {
                        //should this logic be here?
                        battleLog.AddEntry(string.Format("{0} has no more uses.", item.name));

                        ActiveCharacter.removeUsableItem(item);
                        //ActiveCharacter.inventory.Remove(item);
                    }
                }
               
                if(usedItem)
                {
                    battleLog.AddEntry(string.Format("{0} used item {1}", character.name, item.name));
                    return true;
                }
                else
                {
                    battleLog.AddEntry(string.Format("{0} was unable to use item {1}", character.name, item.name));
                    return false;
                }
               
            }
            else{
                battleLog.AddEntry(string.Format("{0} is stunned and unable to use {1}.", character.name, item.name));
            }
            
            return false;

        }
Exemplo n.º 56
0
        public static bool RangedAttack(GameCharacter attacker, GameCharacter defender, Tile targetTile, BattleGame game)
        {
            bool retval = false;
            //check for ranged weapon
            if(attacker.weapon is RangedWeapon)
            {
                RangedWeapon w = (RangedWeapon)attacker.weapon;
                Ammo a = (Ammo)ItemHelper.getFirstItemWithID(attacker.inventory,attacker.Ammo.itemID);

                //check we have ammo 
                if(attacker.Ammo != null && attacker.Ammo.count > 0 && a.ammoType == w.ammoType)
                {

                    List<Tile> tileLOSList = game.board.getBoardLOS(game.ActiveTile, targetTile);


                    //check LOS
                    //check range
                    if (tileLOSList[tileLOSList.Count - 1] == targetTile )
                    {
                        if (tileLOSList.Count <= w.range)
                        {
                            if (attacker.SpendAP(attacker.weapon.actionPoints))
                            {
                                var attackerPos = new UnityEngine.Vector3(attacker.x, -attacker.y);
                                var targetPos = new UnityEngine.Vector3(defender.x, -defender.y);
                                game.gameControllerScript.StartTempSpriteProjectile(attackerPos, targetPos, GameConstants.rangedAttackSpritesheet, GameConstants.rangedAttackSpriteindex);


                                //check for hit
                                if (game.r.Next(20) + attacker.attack > defender.ac)
                                {
                                    retval = Hit(attacker, defender, game,a);

                                    //remove ammo
                                    attacker.inventory.Remove(a);
                                    attacker.Ammo = ItemHelper.getItemSet(attacker.inventory, a);

                                    retval = true;
                                }
                                else
                                {
                                    game.battleLog.AddEntry(string.Format("{0} missed {1}.", attacker.name, defender.name));
                                }
                            }
                        }
                        else
                        {
                            game.battleLog.AddEntry(string.Format("{0} is out of range.", defender.name));
                        }
                    }
                    else
                    {
                        game.battleLog.AddEntry(string.Format("Unable to hit {0}", defender.name));
                    }
                }
                else
                {
                    game.battleLog.AddEntry(string.Format("{0} requires {1} ammo equipped", w.name,w.ammoType));
                }
            }
            else
            {
                game.battleLog.AddEntry(string.Format("Equip a ranged weapon for ranged attack"));
            }
           
            return retval;
        }
Exemplo n.º 57
0
        public static GameCharacter getGameCharacterFromGameCharacterData(GameCharacterData data, GameDataSet gameDataSet)
        {
            GameCharacter character = new GameCharacter()
            {
                level = data.level,
                ac = data.ac,
                ap = data.ap,
                attack = data.attack,
                characterSpriteIndex = data.characterSpriteIndex,
                characterSpritesheetName = data.characterSpritesheetName,
                hp = data.hp,
                displayChar = data.displayChar,
                name = data.name,
                portraitSpriteIndex = data.portraitSpriteIndex,
                portraitSpritesheetName = data.portraitSpritesheetName,
                totalAP = data.ap,
                totalHP = data.hp,
                type = data.type,
                x = 0,
                y = 0,
                strength = data.strength,
                agility = data.agility,
                endurance = data.endurance,
                spirit = data.spirit,
                xp = ExperienceHelper.getXPAtLevel(data.level),
                talentPoints = 0,
                statPoints = 0

            };

            if (data.abilityList.Count > 0)
            {
                List<Ability> abilityList = new List<Ability>();
                foreach (var l in data.abilityList)
                {
                    if(gameDataSet.abilityDataDictionary.ContainsKey(l)){
                         abilityList.Add(AbilityFactory.getAbilityFromAbilityData(gameDataSet.abilityDataDictionary[l],gameDataSet.effectDataDictionary));
                    }
                   
                }
                character.abilityList = abilityList;
            }

            if(data.inventory.Count > 0){
                List<Item> itemList = new List<Item>();
                foreach (var i in data.inventory)
                {
                    Item tempItem = ItemFactory.getItemFromIndex(i, gameDataSet);
                    if (tempItem != null)
                    {
                        if (tempItem.type == ItemType.Ammo)
                        {
                            character.inventory.Add(tempItem);
                            character.Ammo = ItemHelper.getItemSet(character.inventory, tempItem);
                        }
                        else
                        {
                            itemList.Add(tempItem);
                        }
                    }
                }

                character.usableItemList = itemList;

                //character.inventory = itemList;
            }

            if (data.equippedArmor.Count > 0)
            {
                List<Armor> armorList = new List<Armor>();
                foreach (var a in data.equippedArmor)
                {
                    if(gameDataSet.armorDataDictionary.ContainsKey(a)){
                        armorList.Add(ItemFactory.getArmorFromArmorData(gameDataSet.armorDataDictionary[a], gameDataSet.abilityDataDictionary, gameDataSet.effectDataDictionary));
                    }
                  
                }
                character.equippedArmor = armorList;
            }

            if (data.weapon > 0)
            {
                Item i = ItemFactory.getItemFromIndex(data.weapon, gameDataSet);
                
                Weapon w = (Weapon)ItemFactory.getItemFromIndex(data.weapon, gameDataSet);

                if (w.weaponType == WeaponType.OneHandRanged || w.weaponType == WeaponType.TwoHandRanged)
                {
                    w = (RangedWeapon)w;
                }
                

                character.weapon = w;
            }

            if (data.activeEffects.Count > 0)
            {
                List<ActiveEffect> aeList = new List<ActiveEffect>();

                foreach (long l in data.activeEffects)
                {
                    if (gameDataSet.effectDataDictionary.ContainsKey(l))
                    {
                        aeList.Add(AbilityFactory.getActiveEffectFromEffectData(gameDataSet.effectDataDictionary[l]));
                    }
                }
                character.activeEffects = aeList;
            }

            if (data.passiveEffects.Count > 0)
            {
                List<PassiveEffect> peList = new List<PassiveEffect>();

                foreach (long l in data.passiveEffects)
                {
                    if (gameDataSet.effectDataDictionary.ContainsKey(l))
                    {
                        peList.Add(AbilityFactory.getPassiveEffectFromEffectData(gameDataSet.effectDataDictionary[l]));
                    }

                }
                character.passiveEffects = peList;
            }


            if (data.type == CharacterType.Enemy)
            {
                character = getEnemyFromGameCharacter(character, data.enemyType);
            }

            return character;
            
        }
Exemplo n.º 58
0
        private static bool Hit(GameCharacter attacker, GameCharacter defender, BattleGame game, Ammo ammo)
        {
            int bonusDamage = 0;
            if(ammo != null)
            {
                bonusDamage = ammo.bonusDamage;

                if (ammo.activeEffects != null)
                {
                    foreach (var ae in ammo.activeEffects)
                    {
                        defender.AddActiveEffect(AbilityHelper.cloneActiveEffect(ae), game);
                    }
                }
            }

            int dmg = game.r.Next(attacker.weapon.minDamage, attacker.weapon.maxDamage) + bonusDamage;

            defender.Damage(dmg, game);

            game.battleLog.AddEntry(string.Format("{0} hit {1} for {2} damage.", attacker.name, defender.name, dmg));
            game.gameControllerScript.StartTempTextOnChar(defender, dmg, true);
            game.gameControllerScript.StartTempSpriteOnChar(defender, "DamageEffects", 1);

            if(attacker.weapon.activeEffects != null)
            {
                foreach(var ae in attacker.weapon.activeEffects)
                {
                    defender.AddActiveEffect(AbilityHelper.cloneActiveEffect(ae), game);
                }
            }

            return true;
        }
Exemplo n.º 59
0
        //Move character without spending Action Points
        public bool MoveCharacterFree(GameCharacter gc, Tile Destination)
        {
             bool retval = false;
             if (Destination != null)
             {
                 if (Destination.empty)
                 {
                     if (!CoreHelper.checkEffect(gc.activeEffects, gc.passiveEffects, StatType.Stuck))
                     {
                         EmptyTile(board[gc.x, gc.y]);
                         FillTile(gc, Destination);

                         retval = true;
                     }
                 }
             }
             return retval;
        }
Exemplo n.º 60
0
 public void FillTile(GameCharacter gc, Tile t)
 {
     t.empty=false;
     gc.x = t.x;
     gc.y = t.y;
     t.TileChar = gc.displayChar;
 }