private void RegenerateRadius()
        {
            int radius = selectedCharTurn.character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.MOB] * selectedCharTurn.character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.AP] - (EncounterInfo.currentTurn().selectedCharTurn.stepsSet - 2);

            switch (selectedCharTurn.character.rotationIndex)
            {
            case (int)BaseCharacter.Rotation.Up:
                CombatProcessor.radiusTiles = MapListUtility.returnValidMapRadius(radius, EncounterInfo.currentTurn().selectedCharTurn.returnCompleteArea(), selectedCharTurn.character.position - new Vector2(0, 64));
                CombatProcessor.radiusTiles.RemoveAll(t => t.distanceCoordsFrom(selectedCharTurn.character.position) > radius - 2);
                break;

            case (int)BaseCharacter.Rotation.Down:
                CombatProcessor.radiusTiles = MapListUtility.returnValidMapRadius(radius, EncounterInfo.currentTurn().selectedCharTurn.returnCompleteArea(), selectedCharTurn.character.position + new Vector2(0, 64));
                CombatProcessor.radiusTiles.RemoveAll(t => t.distanceCoordsFrom(selectedCharTurn.character.position + new Vector2(0, 64)) > radius - 2);
                break;

            case (int)BaseCharacter.Rotation.Right:
                CombatProcessor.radiusTiles = MapListUtility.returnValidMapRadius(radius, EncounterInfo.currentTurn().selectedCharTurn.returnCompleteArea(), selectedCharTurn.character.position + new Vector2(64, 0));

                CombatProcessor.radiusTiles.RemoveAll(t => t.distanceCoordsFrom(selectedCharTurn.character.position + new Vector2(64, 0)) > radius - 2);
                break;

            case (int)BaseCharacter.Rotation.Left:
                CombatProcessor.radiusTiles = MapListUtility.returnValidMapRadius(radius, EncounterInfo.currentTurn().selectedCharTurn.returnCompleteArea(), selectedCharTurn.character.position - new Vector2(64, 0));
                CombatProcessor.radiusTiles.RemoveAll(t => t.distanceCoordsFrom(selectedCharTurn.character.position) > radius - 2);
                break;
            }

            //CombatProcessor.radiusTiles.RemoveAll(t => t.distanceCoordsFrom(selectedCharTurn.character.position) > radius - 1);
            bRegenerateRadius = false;
        }
        public CharacterTurn(BaseCharacter bs, MapZone zone, List <BasicTile> bt, TurnSet parent)
        {
            characterAP = bs.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.AP];
            parentTS    = parent;
            character   = bs;
            turns.Clear();
            characterArea.Clear();
            int temp     = bs.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.AP];
            int maxMoves = bs.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.MOB];

            for (int i = 1; i < temp + 1; i++)
            {
                turns.Add(new TurnInfo(maxMoves));
                //     characterArea.Add(MapListUtility.returnMapRadius((i - 1) * maxMoves, i * maxMoves, bt, bs));
                if (i > 1)
                {
                    for (int j = 1; j < 2; j++)
                    {
                        List <BasicTile> list = MapListUtility.returnValidMapRadius((i - 1) * maxMoves + maxMoves, bt, bs.position).Except(characterArea[i - 1 - j]).ToList();
                        characterArea.Add(list);
                    }
                }
                else
                {
                    characterArea.Add(MapListUtility.returnValidMapRadius((i - 1) * maxMoves + maxMoves, bt, bs.position));
                }
            }
        }
        public bool bCanHitTarget(BaseCharacter caster, BaseCharacter target, List <BasicTile> bt)
        {
            if (bCanNotTargetSelf && caster == target)
            {
                return(false);
            }

            if (IsAbilityAvailable(caster.trueSTATChart()))
            {
                if (MapListUtility.returnValidMapRadius(abilityMinRange, abilityMaxRange, bt, target.position).Find(t => t.mapPosition.Location == caster.position.ToPoint()) != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        public static void AIPreCalculate(List <BasicTile> moveRadius, CharacterTurn ct)
        {
            BaseCharacter            caster = ct.character;
            List <List <BasicTile> > abilityRangesAttack        = new List <List <BasicTile> >();
            List <List <BasicTile> > abilityRangesSupport       = new List <List <BasicTile> >();
            List <BaseCharacter>     possibleTargetCharsAttack  = new List <BaseCharacter>();
            List <BaseCharacter>     possibleTargetCharsSupport = new List <BaseCharacter>();

            List <BaseCharacter> possibleAITargetsAttack  = new List <BaseCharacter>();
            List <BaseCharacter> possibleAITargetsSupport = new List <BaseCharacter>();

            possibleAITargets.Clear();

            List <BasicAbility> attackAbilities  = caster.AbilityList().FindAll(abi => abi.abilityType == (int)BasicAbility.ABILITY_TYPE.ATTACK);
            List <BasicAbility> supportAbilities = caster.AbilityList().FindAll(abi => abi.abilityType == (int)BasicAbility.ABILITY_TYPE.SUPPORT);
            bool bCharHasSupportAbis             = supportAbilities.Count > 0;

            #region supportCheck
            if (bCharHasSupportAbis)
            {
                var listOfCharactersTemp = ct.parentTS.charactersInGroup;

                foreach (var character in listOfCharactersTemp)
                {
                    if (character.bIsAlive)
                    {
                        possibleTargetCharsSupport.Add(character);
                    }
                }

                foreach (var ability in supportAbilities)
                {
                    foreach (var character in possibleTargetCharsSupport)
                    {
                        if (character.NeedsHealing(3))
                        {
                            abilityRangesSupport.Add(MapListUtility.returnValidMapRadius(ability.abilityMinRange, ability.abilityMaxRange, CombatProcessor.zoneTiles, (character.position / 64).ToPoint().ToVector2() * 64));
                            Vector2 positionGridCaster = new Vector2((int)(caster.position.X / 64), (int)(caster.position.Y / 64));
                            var     test = abilityRangesSupport[abilityRangesSupport.Count - 1].Find(t => moveRadius.Contains(t) || (t.positionGrid.X == positionGridCaster.X && t.positionGrid.Y == positionGridCaster.Y));
                            if (test != null)
                            {
                                if (!possibleAITargetsSupport.Contains(character))
                                {
                                    possibleAITargetsSupport.Add(character);
                                }
                            }
                        }
                    }
                }
            }


            #endregion

            var listOfCharacters = ct.parentTS.targetGroups[GamePlayUtility.Randomize(0, ct.parentTS.targetGroups.Count - 1)].charactersInGroup;

            if (attackAbilities.Count != 0)
            {
                foreach (var character in listOfCharacters)
                {
                    if (character.bIsAlive)
                    {
                        possibleTargetCharsAttack.Add(character);
                    }
                }
            }

            if (possibleAITargetsSupport.Count == 0 && attackAbilities.Count != 0)
            {
                bCharHasSupportAbis = false; //If nothing is in need of healing, try prioiritize attacking instead.
            }


            foreach (var ability in attackAbilities)
            {
                if (ability.IsAbilityAvailable(caster.trueSTATChart()))
                {
                    if (ability.abilityFightStyle == (int)BasicAbility.ABILITY_CAST_TYPE.MELEE)
                    {
                        foreach (var character in possibleTargetCharsAttack)
                        {
                            abilityRangesAttack.Add(MapListUtility.returnValidMapRadius(ability.abilityMinRange, ability.abilityMaxRange, CombatProcessor.zoneTiles, (character.position / 64).ToPoint().ToVector2() * 64));
                            Vector2 positionGridCaster = new Vector2((int)(caster.position.X / 64), (int)(caster.position.Y / 64));
                            var     test = abilityRangesAttack[abilityRangesAttack.Count - 1].Find(t => moveRadius.Contains(t) || (t.positionGrid.X == positionGridCaster.X && t.positionGrid.Y == positionGridCaster.Y));
                            if (test != null)
                            {
                                if (!possibleAITargetsAttack.Contains(character))
                                {
                                    possibleAITargetsAttack.Add(character);
                                }
                            }
                        }
                    }
                    else if (ability.abilityFightStyle == (int)BasicAbility.ABILITY_CAST_TYPE.RANGED || ability.abilityFightStyle == (int)BasicAbility.ABILITY_CAST_TYPE.MAGIC)
                    {
                        abilityRangesAttack.Add(MapListUtility.returnValidMapRadius(ability.abilityMinRange, ability.abilityMaxRange, CombatProcessor.zoneTiles, (caster.position / 64).ToPoint().ToVector2() * 64));

                        foreach (var item in possibleTargetCharsAttack)
                        {
                            if (ability.abilityCanHitTargetInRange(caster, item))
                            {
                                if (!possibleAITargetsAttack.Contains(item))
                                {
                                    possibleAITargetsAttack.Add(item);
                                }
                            }
                        }
                    }
                    //else if (ability.abilityFightStyle == (int)BasicAbility.ABILITY_CAST_TYPE.RANGED)
                    //{
                    //    abilityRanges.Add(MapListUtility.returnValidMapRadius(ability.abilityMinRange, ability.abilityMaxRange, CombatProcessor.zoneTiles, (caster.position / 64).ToPoint().ToVector2() * 64));

                    //    foreach (var item in heroCharactersStillAlive)
                    //    {
                    //        if (ability.abilityCanHitTargetInRange(caster, item))
                    //        {
                    //            if (!possibleAITargets.Contains(item))
                    //            {
                    //                possibleAITargets.Add(item);
                    //            }
                    //        }
                    //    }
                    //}
                }
            }

            if (!bCharHasSupportAbis)
            {
                possibleAITargets = new List <BaseCharacter>(possibleAITargetsAttack);
            }
            else
            {
                bool  bShouldSupport        = false;
                float percentageSupportAbis = (float)((float)supportAbilities.Count / (float)caster.AbilityList().Count);
                float percentageAttackAbis  = 1 - percentageSupportAbis;
                percentageSupportAbis *= 100f;
                percentageAttackAbis  *= 100f;
                int amountOfEnemies      = possibleAITargetsAttack.Count();
                int amountOfAlliesInNeed = possibleAITargetsSupport.Count();
                if (amountOfAlliesInNeed > amountOfEnemies)
                {
                    int percent = GamePlayUtility.Randomize(30, (int)(percentageSupportAbis + 20));
                    if (percent > GamePlayUtility.Randomize(40, 70))
                    {
                        bShouldSupport = true;
                    }
                }

                if (bShouldSupport)
                {
                    possibleAITargets = new List <BaseCharacter>(possibleAITargetsSupport);
                    bDoSupport        = true;
                }
                else if (possibleTargetCharsAttack.Count != 0)
                {
                    possibleAITargets = new List <BaseCharacter>(possibleAITargetsAttack);
                    bDoSupport        = false;
                }
            }
        }
Beispiel #5
0
        public static KeyValuePair <List <List <BasicTile> >, List <BasicAbility> > returnTilesToAttackFrom(List <BasicTile> moveRadius, List <BasicTile> allTiles, BaseCharacter caster, BaseCharacter target)
        {
            List <BasicAbility>      tempAbilityList = new List <BasicAbility>();
            List <List <BasicTile> > abilityRanges   = new List <List <BasicTile> >();
            //   Console.WriteLine("---------------Report Begin----------");
            //  Console.WriteLine("Checking if enemy has an ability to attack the selected partymember with: " + caster.CharacterName + caster.position);
            List <BasicAbility> abilityCheckList = new List <BasicAbility>();

            if (bDoSupport)
            {
                abilityCheckList.AddRange(caster.AbilityList().FindAll(abi => abi.abilityType == (int)BasicAbility.ABILITY_TYPE.SUPPORT));
            }
            else
            {
                abilityCheckList.AddRange(caster.AbilityList().FindAll(abi => abi.abilityType == (int)BasicAbility.ABILITY_TYPE.ATTACK));
            }

            foreach (var ability in abilityCheckList)
            {
                if (ability.IsAbilityAvailable(caster.trueSTATChart()))
                {
                    if (ability.abilityType == (int)BasicAbility.ABILITY_TYPE.ATTACK && ability.abilityFightStyle == (int)BasicAbility.ABILITY_CAST_TYPE.MELEE && (ability.targetableTypes.Contains(target.CCC.equippedClass.classType) || ability.targetableTypes.Count == 0))
                    {
                        abilityRanges.Add(MapListUtility.returnValidMapRadius(ability.abilityMinRange, ability.abilityMaxRange, allTiles, (target.position / 64).ToPoint().ToVector2() * 64));
                        var test = abilityRanges[abilityRanges.Count - 1].Find(t => moveRadius.Contains(t));
                        if (test != null)
                        {
                            tempAbilityList.Add(ability);
                            Console.WriteLine(ability.ToString() + " is in range!");
                        }
                        else
                        {
                            abilityRanges.RemoveAt(abilityRanges.Count - 1);
                        }
                    }
                    else if (ability.abilityType == (int)BasicAbility.ABILITY_TYPE.ATTACK && (ability.abilityFightStyle == (int)BasicAbility.ABILITY_CAST_TYPE.RANGED || ability.abilityFightStyle == (int)BasicAbility.ABILITY_CAST_TYPE.MAGIC) && (ability.targetableTypes.Contains(target.CCC.equippedClass.classType) || ability.targetableTypes.Count == 0))
                    {
                        if (ability.abilityCanHitTargetInRange(caster, target))
                        {
                            abilityRanges.Add(MapListUtility.returnValidMapRadius(ability.abilityMinRange, ability.abilityMaxRange, allTiles, (target.position / 64).ToPoint().ToVector2() * 64));
                            tempAbilityList.Add(ability);
                            Console.WriteLine(ability.ToString() + " is in range!");
                        }
                        else
                        {
                            // abilityRanges.RemoveAt(abilityRanges.Count - 1);
                        }
                    }
                    else if (ability.abilityType == (int)BasicAbility.ABILITY_TYPE.SUPPORT && (ability.targetableTypes.Contains(target.CCC.equippedClass.classType) || ability.targetableTypes.Count == 0))
                    {
                        abilityRanges.Add(MapListUtility.returnValidMapRadius(ability.abilityMinRange, ability.abilityMaxRange, allTiles, (target.position / 64).ToPoint().ToVector2() * 64));
                        var test = abilityRanges[abilityRanges.Count - 1].Find(t => moveRadius.Contains(t));
                        if (test != null)
                        {
                            tempAbilityList.Add(ability);
                            Console.WriteLine(ability.ToString() + " is in range!");
                        }
                        else
                        {
                            // abilityRanges.RemoveAt(abilityRanges.Count - 1);
                        }
                    }
                }
            }
            List <BasicTile> temp = new List <BasicTile>();

            foreach (var range in abilityRanges)
            {
                temp.AddRange(range.Except(temp));
            }
            temp.RemoveAll(t => !moveRadius.Contains(t));
            if (abilityRanges.Count == 0 && tempAbilityList.Count != 0)
            {
                abilityRanges.Add(new List <BasicTile>());
            }
            //   Console.WriteLine("---------------Report End----------");
            return(new KeyValuePair <List <List <BasicTile> >, List <BasicAbility> >(abilityRanges, tempAbilityList));
        }
        public void ReGenerateTurn(List <BasicTile> bt)
        {
            bAttackedThisCT = false;
            abiUsedInfo     = null;
            turns.Clear();
            characterArea.Clear();
            int temp     = character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.AP];
            int maxMoves = character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.MOB];

            for (int i = 1; i < temp + 1; i++)
            {
                turns.Add(new TurnInfo(maxMoves));
                if (i > 1)
                {
                    for (int j = 1; j < 2; j++)
                    {
                        List <BasicTile> list = MapListUtility.returnValidMapRadius((i - 1) * maxMoves + maxMoves, bt, character.position).Except(characterArea[i - 1 - j]).ToList();
                        characterArea.Add(list);
                    }
                }
                else
                {
                    characterArea.Add(MapListUtility.returnValidMapRadius((i - 1) * maxMoves + maxMoves, bt, character.position));
                }
            }



            try
            {
                var tempT = bt.Find(t => t.positionGrid.ToPoint() == (character.position / 64).ToPoint());
                if (tempT != null && !characterArea[0].Contains(tempT))
                {
                    characterArea[0].Add(tempT);
                }

                if (characterArea[0].Count == 0)
                {
                    characterArea[0].Add(bt.Find(t => t.mapPosition.Location.ToVector2() == character.position));
                }
            }
            catch
            {
            }

            bool bStuffToAdjust = false;
            List <KeyValuePair <BasicTile, int> > allUniqueTiles = new List <KeyValuePair <BasicTile, int> >();
            List <KeyValuePair <BasicTile, int> > duplicates     = new List <KeyValuePair <BasicTile, int> >();

            for (int i = 0; i < characterArea.Count; i++)
            {
                for (int j = 0; j < characterArea[i].Count; j++)
                {
                    if (allUniqueTiles.Find(t => t.Key == characterArea[i][j]).Equals(default(KeyValuePair <BasicTile, int>)))
                    {
                        allUniqueTiles.Add(new KeyValuePair <BasicTile, int>(characterArea[i][j], i));
                    }
                    else
                    {
                        bStuffToAdjust = true;
                        duplicates.Add(new KeyValuePair <BasicTile, int>(characterArea[i][j], i));
                    }
                }
            }

            if (bStuffToAdjust)
            {
                for (int i = 0; i < duplicates.Count; i++)
                {
                    characterArea[duplicates[i].Value].Remove(duplicates[i].Key);
                }
            }
        }