Beispiel #1
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);
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public static Board getBoardFromBattleGameData(BattleGameData battleGameData, BattleGame battleGame)
        {
            Board b = new Board(battleGame, battleGameData.tileMapData.battleTileArray.GetLength(0));
            b.board = copyTileArray(battleGameData.tileMapData.battleTileArray);

            return b;
        }
Beispiel #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;
                }
            }

        }
Beispiel #5
0
        private List<AIAction> getAIActions(BattleGame game, AIActionType type)
        {
            List<AIAction> retvalList = new List<AIAction>();
            switch (type)
            {
                case AIActionType.Attack:
                    retvalList.AddRange(getAIAttackActions(game));
                    break;
                case AIActionType.RangedAttack:
                    retvalList.AddRange(getAIRangedAttackActions(game));
                    break;
                case AIActionType.Heal:
                    retvalList.AddRange(getAIHealActions(game));
                    break;
                default:
                    break;
            }

            //Remove any actions that cost too much AP
            for (int i = retvalList.Count - 1; i >= 0; i--)
            {
                int apCost = retvalList[i].battleActionList.Sum(x => x.AP);
                if (apCost > game.ActiveCharacter.ap)
                {
                    retvalList.RemoveAt(i);
                }
            }

            return retvalList;
        }
Beispiel #6
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;
                }
            }
        }
Beispiel #7
0
        private List <AIAction> getAIActions(BattleGame game, AIActionType type)
        {
            List <AIAction> retvalList = new List <AIAction>();

            switch (type)
            {
            case AIActionType.Attack:
                retvalList.AddRange(getAIAttackActions(game));
                break;

            case AIActionType.RangedAttack:
                retvalList.AddRange(getAIRangedAttackActions(game));
                break;

            case AIActionType.Heal:
                retvalList.AddRange(getAIHealActions(game));
                break;

            default:
                break;
            }

            //Remove any actions that cost too much AP
            for (int i = retvalList.Count - 1; i >= 0; i--)
            {
                int apCost = retvalList[i].battleActionList.Sum(x => x.AP);
                if (apCost > game.ActiveCharacter.ap)
                {
                    retvalList.RemoveAt(i);
                }
            }

            return(retvalList);
        }
Beispiel #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);
            }
        }
Beispiel #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);
        }
Beispiel #10
0
 public void Damage(int amount, BattleGame game)
 {
     this.hp -= amount;
     if (this.hp <= 0)
     {
         Kill(game);
     }
 }
Beispiel #11
0
        //get a list of all healing abilities / items.
        //currently only abilities that are for self
        private List <AIAction> getAIHealActions(BattleGame game)
        {
            List <AIAction> aiActionList = new List <AIAction>();

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

            foreach (var a in character.abilityList)
            {
                if (a.cooldown > 0 && a.canUseSelf())
                {
                    if (a.activeEffects.Select(x => x.statType == StatType.Heal) != null)
                    {
                        List <BattleAction> battleActionList = new List <BattleAction>()
                        {
                            new BattleAction()
                            {
                                AP = a.ap, ability = a, character = character, targetCharacter = character, targetTile = targetTile, actionType = BattleActionType.UseAbility
                            }
                        };
                        aiActionList.Add(new AIAction()
                        {
                            actionType = AIActionType.Heal, cost = a.ap, battleActionList = battleActionList
                        });
                    }
                }
            }

            var usableItems = from data in character.inventory
                              where data is UsableItem
                              select data;

            foreach (var i in usableItems.ToList())
            {
                UsableItem tempItem = (UsableItem)i;

                if (tempItem.activeEffects != null)
                {
                    if (i.activeEffects.Select(x => x.statType == StatType.Heal) != null)
                    {
                        List <BattleAction> battleActionList = new List <BattleAction>()
                        {
                            new BattleAction()
                            {
                                AP = tempItem.actionPoints, item = tempItem, character = character, targetCharacter = character, targetTile = targetTile, actionType = BattleActionType.UseItem
                            }
                        };
                        aiActionList.Add(new AIAction()
                        {
                            actionType = AIActionType.Heal, cost = tempItem.actionPoints, battleActionList = battleActionList
                        });
                    }
                }
            }

            return(AIActionList);
        }
Beispiel #12
0
        private static bool UseAbilityLOSEmpty(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            if (target.empty)
            {
                return UseAbilityLOS(character, ability, target, game);
            }

            return false;

        }
Beispiel #13
0
        public void Heal(int amount, BattleGame game)
        {
            this.hp += amount;
            if (this.hp > this.totalHP)
            {
                this.hp = this.totalHP;
            }

            game.battleLog.AddEntry(string.Format("{0} was healed for {1}", this.name, amount));
        }
Beispiel #14
0
        public static List<BattleAction> getBattleActionList(EnemyCharacter character, BattleGame game)
        {
            List<BattleAction> retvalList = character.aiActor.getBattleActionList(game);

            if (retvalList.Count == 0)
            {
                retvalList.Add(getEndTurnAction(character));
            }

            return retvalList;
        }
Beispiel #15
0
        public void AddActiveEffect(ActiveEffect a, BattleGame game)
        {
            ActivateEffect(a, game);

            a.duration--;
            if (a.duration > 0)
            {
                game.battleLog.AddEntry(string.Format("{0} was added to {1}.", a.name, this.name));

                activeEffects.Add(a);
            }
        }
Beispiel #16
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);
            }
        }
Beispiel #17
0
        //Occurs once per turn
        public void RunActiveEffects(BattleGame game)
        {
            for (int i = activeEffects.Count - 1; i >= 0; i--)
            {
                ActivateEffect(activeEffects[i], game);

                activeEffects[i].duration--;
                if (activeEffects[i].duration <= 0)
                {
                    game.battleLog.AddEntry(string.Format("{0} expired on {1}.", activeEffects[i].name, this.name));

                    activeEffects.RemoveAt(i);
                }
            }
        }
Beispiel #18
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;
            }
        }
Beispiel #19
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);
        }
Beispiel #20
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;
            }

        }
Beispiel #21
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);
            }
        }
Beispiel #22
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);
        }
Beispiel #23
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;
            }

        }
Beispiel #24
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);

        }
Beispiel #25
0
        public List <BattleAction> getBattleActionList(BattleGame game)
        {
            List <BattleAction> retval = new List <BattleAction>();

            //reset the AIActionList
            AIActionList = new List <AIAction>();
            //update the weight and cost lists
            foreach (var type in actionWeightDictionary.Keys)
            {
                AIActionList.AddRange(getAIActions(game, type));
            }

            if (AIActionList.Count > 0)
            {
                AIActionList.Sort((x1, x2) => (x1.cost * (100 - x1.weight)).CompareTo(x2.cost * (100 - x2.weight)));

                //get the top weighted action
                retval.AddRange(AIActionList[0].battleActionList);
            }

            return(retval);
        }
Beispiel #26
0
        private void ActivateEffect(ActiveEffect effect, BattleGame game)
        {
            int amt = 0;

            switch (effect.statType)
            {
            case StatType.Damage:
                amt = game.r.Next(effect.minAmount, effect.maxAmount);

                game.battleLog.AddEntry(string.Format("{0} was damaged by {1} for {2}", this.name, effect.name, amt.ToString()));

                game.gameControllerScript.StartTempTextOnChar(this, amt, true);


                this.Damage(amt, game);
                break;

            case StatType.Heal:
                amt = game.r.Next(effect.minAmount, effect.maxAmount);
                game.battleLog.AddEntry(string.Format("{0} was healed by {1} for {2}", this.name, effect.name, amt.ToString()));

                game.gameControllerScript.StartTempTextOnChar(this, amt, false);


                this.Heal(amt, game);
                break;

            case StatType.Dispell:

                amt = game.r.Next(effect.minAmount, effect.maxAmount);
                game.battleLog.AddEntry(string.Format("{0} removed {1} effects from {2}", effect.name, amt, this.name));

                RemoveTopActiveEffects(amt);
                break;

            default:
                break;
            }
        }
Beispiel #27
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;
        }
Beispiel #28
0
        public List<BattleAction> getBattleActionList(BattleGame game)
        {
            List<BattleAction> retval = new List<BattleAction>();

            //reset the AIActionList
            AIActionList = new List<AIAction>();
            //update the weight and cost lists
            foreach(var type in actionWeightDictionary.Keys)
            {
                AIActionList.AddRange(getAIActions(game, type));
            }

            if (AIActionList.Count > 0)
            {
                AIActionList.Sort((x1, x2) => (x1.cost * (100 - x1.weight)).CompareTo(x2.cost * (100 - x2.weight)));

                //get the top weighted action
                retval.AddRange(AIActionList[0].battleActionList);
            }

            return retval;
       
        }
Beispiel #29
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;
     }
 }
Beispiel #30
0
        public void AddActiveEffect(ActiveEffect a, BattleGame game)
        {
            ActivateEffect(a, game);

            a.duration--;
            if (a.duration > 0)
            {
                game.battleLog.AddEntry(string.Format("{0} was added to {1}.", a.name, this.name));

                activeEffects.Add(a);
            }
        }
Beispiel #31
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);
        }
Beispiel #32
0
 public Board(BattleGame game, int size)
 {
     this.size = size;
     this.game = game;
 }
Beispiel #33
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;
        }
Beispiel #34
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);
        }
Beispiel #35
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));
        }
Beispiel #36
0
        private void ActivateEffect(ActiveEffect effect, BattleGame game)
        {
            int amt = 0;
            switch (effect.statType)
            {
                case StatType.Damage:
                     amt = game.r.Next(effect.minAmount, effect.maxAmount);

                    game.battleLog.AddEntry(string.Format("{0} was damaged by {1} for {2}", this.name, effect.name, amt.ToString()));

                    game.gameControllerScript.StartTempTextOnChar(this, amt, true);


                    this.Damage(amt, game);
                    break;
                case StatType.Heal:
                     amt = game.r.Next(effect.minAmount, effect.maxAmount);
                     game.battleLog.AddEntry(string.Format("{0} was healed by {1} for {2}", this.name, effect.name, amt.ToString()));

                     game.gameControllerScript.StartTempTextOnChar(this, amt, false);


                    this.Heal(amt, game);
                    break;
                case StatType.Dispell:

                    amt = game.r.Next(effect.minAmount, effect.maxAmount);
                    game.battleLog.AddEntry(string.Format("{0} removed {1} effects from {2}", effect.name, amt, this.name));

                    RemoveTopActiveEffects(amt);
                    break;
                default:
                    break;
            }
        }
Beispiel #37
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);

        }
Beispiel #38
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;
            }
        }
Beispiel #39
0
 //function of current health + default heal weight
 private int getAIHealWeight(BattleGame game)
 {
     int curWeight = 100 - ((character.hp / character.totalHP) * 100);
     return (int)Math.Round((actionWeightDictionary[AIActionType.Heal] + (float)curWeight) / 2);
 }
Beispiel #40
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;
 }
Beispiel #41
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);
        }
Beispiel #42
0
        public void Heal(int amount, BattleGame game)
        {
            this.hp += amount;
            if (this.hp > this.totalHP)
            {
                this.hp = this.totalHP;
            }

            game.battleLog.AddEntry(string.Format("{0} was healed for {1}", this.name, amount));

        }
Beispiel #43
0
        private static bool UseAbilityLOSEmpty(GameCharacter character, Ability ability, Tile target, BattleGame game)
        {
            if (target.empty)
            {
                return(UseAbilityLOS(character, ability, target, game));
            }

            return(false);
        }
Beispiel #44
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;
        }
Beispiel #45
0
        //get a list of all healing abilities / items.  
        //currently only abilities that are for self
        private List<AIAction> getAIHealActions(BattleGame game)
        {
         
            List<AIAction> aiActionList = new List<AIAction>();
          
                Tile targetTile = game.board.getTileFromLocation(character.x, character.y);

                foreach (var a in character.abilityList)
                {
                    if (a.cooldown > 0 && a.canUseSelf())
                    {
                        if (a.activeEffects.Select(x => x.statType == StatType.Heal) != null)
                        {
                            List<BattleAction> battleActionList = new List<BattleAction>() {  
                                new BattleAction() {AP=a.ap, ability = a, character = character, targetCharacter = character, targetTile = targetTile, actionType = BattleActionType.UseAbility } };
                            aiActionList.Add(new AIAction() { actionType = AIActionType.Heal, cost = a.ap, battleActionList = battleActionList });
                        }
                    }
                }

                var usableItems = from data in character.inventory
                                  where data is UsableItem
                                  select data;

                foreach (var i in usableItems.ToList())
                {

                    UsableItem tempItem = (UsableItem)i;

                    if (tempItem.activeEffects != null)
                    {
                        if (i.activeEffects.Select(x => x.statType == StatType.Heal) != null)
                        {
                            List<BattleAction> battleActionList = new List<BattleAction>() { 
                                new BattleAction() {AP=tempItem.actionPoints,  item = tempItem, character = character, targetCharacter = character, targetTile = targetTile, actionType = BattleActionType.UseItem } };
                            aiActionList.Add(new AIAction() { actionType = AIActionType.Heal, cost = tempItem.actionPoints, battleActionList = battleActionList });
                        }
                    }
                }

            return AIActionList;
        }
Beispiel #46
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);
            }
        }
Beispiel #47
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);
        }
Beispiel #48
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);
        }
Beispiel #49
0
 public Board(BattleGame game, int size)
 {
     this.size = size;
     this.game = game;
 }
Beispiel #50
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);
            }
        }
Beispiel #51
0
        public void Kill(BattleGame game)
        {
            game.battleLog.AddEntry(string.Format("{0} was killed.", this.name));

            game.CharacterKill(this);
        }
Beispiel #52
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);
 }
Beispiel #53
0
        //function of current health + default heal weight
        private int getAIHealWeight(BattleGame game)
        {
            int curWeight = 100 - ((character.hp / character.totalHP) * 100);

            return((int)Math.Round((actionWeightDictionary[AIActionType.Heal] + (float)curWeight) / 2));
        }
Beispiel #54
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);
     }
 }
Beispiel #55
0
        //Occurs once per turn
        public void RunActiveEffects(BattleGame game)
        {
            for (int i = activeEffects.Count - 1; i >= 0; i--)
            {
                ActivateEffect(activeEffects[i], game);

                activeEffects[i].duration--;
                if (activeEffects[i].duration <= 0)
                {
                    game.battleLog.AddEntry(string.Format("{0} expired on {1}.", activeEffects[i].name, this.name));

                    activeEffects.RemoveAt(i);
                }
            }
        }
Beispiel #56
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;
 }
Beispiel #57
0
 public void Damage(int amount, BattleGame game)
 {
     this.hp -= amount;
     if (this.hp <= 0)
     {
         Kill(game);
     }
 }
Beispiel #58
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;
        }
Beispiel #59
0
        public void Kill(BattleGame game)
        {
            game.battleLog.AddEntry(string.Format("{0} was killed.", this.name));

            game.CharacterKill(this);
        }
Beispiel #60
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;
        }