示例#1
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);
        }
示例#2
0
文件: AI.cs 项目: mengtest/UnityRPG
        //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);
            }
        }
示例#3
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);
        }
示例#4
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);
            }
        }
示例#5
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);
     }
 }
示例#6
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);
 }
示例#7
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);
        }
示例#8
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);
            }
        }
示例#9
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);
            }
        }
示例#10
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;
            }

        }
示例#11
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);
        }
示例#12
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;
        }
示例#13
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;
        }
示例#14
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;
     }
 }
示例#15
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;
 }
示例#16
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;
            }
        }
示例#17
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;
        }
示例#18
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;
        }
示例#19
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;

        }
示例#20
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);
        }