Skip to content

Commit

Permalink
Added adjustment from all angles to make cover work with field of view
Browse files Browse the repository at this point in the history
  • Loading branch information
samsmithnz committed May 20, 2021
1 parent 0216a31 commit 53006f9
Show file tree
Hide file tree
Showing 11 changed files with 1,585 additions and 1,208 deletions.
8 changes: 4 additions & 4 deletions src/Battle.Logic/CharacterCover/Cover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,19 @@ private static List<Vector3> FindAdjacentCover(Vector3 currentLocation, int widt
}

//Get possible tiles, within constraints of map, including only square titles from current position (not diagonally)
if (validTiles[Convert.ToInt32(currentLocation.X), Convert.ToInt32(zMax)] == "W")
if (validTiles[Convert.ToInt32(currentLocation.X), Convert.ToInt32(zMax)] == "")
{
result.Add(new Vector3(currentLocation.X, 0f, zMax));
}
if (validTiles[Convert.ToInt32(xMax), Convert.ToInt32(currentLocation.Z)] == "W")
if (validTiles[Convert.ToInt32(xMax), Convert.ToInt32(currentLocation.Z)] == "")
{
result.Add(new Vector3(xMax, 0f, currentLocation.Z));
}
if (validTiles[Convert.ToInt32(currentLocation.X), Convert.ToInt32(zMin)] == "W")
if (validTiles[Convert.ToInt32(currentLocation.X), Convert.ToInt32(zMin)] == "")
{
result.Add(new Vector3(currentLocation.X, 0f, zMin));
}
if (validTiles[Convert.ToInt32(xMin), Convert.ToInt32(currentLocation.Z)] == "W")
if (validTiles[Convert.ToInt32(xMin), Convert.ToInt32(currentLocation.Z)] == "")
{
result.Add(new Vector3(xMin, 0f, currentLocation.Z));
}
Expand Down
30 changes: 30 additions & 0 deletions src/Battle.Logic/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,48 @@ public List<Character> GetCharactersInView(string[,] map, List<Team> teams)
{
foreach (Character character in team.Characters)
{
bool addedCharacter = false;
foreach (Vector3 location in fovVectors)
{
if (character.Location == location)
{
addedCharacter = true;
results.Add(character);
break;
}
}
if (addedCharacter == false && LocationIsAdjacentToList(character.Location, fovVectors) == true)
{
results.Add(character);
}
}
}

return results;
}

private static bool LocationIsAdjacentToList(Vector3 location, List<Vector3> list)
{
foreach (Vector3 item in list)
{
if (item.X - 1 == location.X && item.Z == location.Z)
{
return true;
}
else if (item.X + 1 == location.X && item.Z == location.Z)
{
return true;
}
else if (item.X == location.X && item.Z - 1 == location.Z )
{
return true;
}
else if (item.X == location.X && item.Z + 1 == location.Z)
{
return true;
}
}
return false;
}
}
}
2 changes: 1 addition & 1 deletion src/Battle.Logic/Encounters/Encounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static EncounterResult AttackCharacterWithAreaOfEffect(Character sourceCh
List<Vector3> area = FieldOfViewAreaEffectCalculator.GetAreaOfEffect(map, throwingTargetLocation, weapon.AreaEffectRadius);
foreach (Vector3 item in area)
{
if (map[(int)item.X, (int)item.Z] == "W")
if (map[(int)item.X, (int)item.Z] == "")
{
map[(int)item.X, (int)item.Z] = "";
log.Add("Cover removed from " + item.ToString());
Expand Down
40 changes: 39 additions & 1 deletion src/Battle.Logic/Map/MapGeneration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using Battle.Logic.Utility;

namespace Battle.Logic.Map
Expand All @@ -13,7 +16,7 @@ public static class MapGeneration
{
if (((x != 0 && z != 0) || (x != xMax - 1 && z != zMax - 1)) && probOfMapBeingBlocked > RandomNumber.GenerateRandomNumber(1, 100))
{
map[x, z] = "W";
map[x, z] = "";
}
}
}
Expand All @@ -34,5 +37,40 @@ public static void DebugPrintOutMap(string[,] map, int xMax, int zMax)
}
}

public static string GetMapString(string[,] map, int xMax, int zMax)
{
StringBuilder sb = new();
sb.Append(Environment.NewLine);
for (int z = zMax-1; z >= 0; z--)
{
for (int x = 0; x < xMax; x++)
{
if (map[x, z] != "")
{
sb.Append(map[x, z] + " ");
}
else
{
sb.Append("");
}
}
sb.Append(Environment.NewLine);
}
return sb.ToString();
}

public static string[,] ApplyListToMap(string[,] map, List<Vector3> list, string tile)
{
foreach (Vector3 item in list)
{
if (map[(int)item.X,(int)item.Z] == "")
{
map[(int)item.X, (int)item.Z] = tile;
}
}

return map;
}

}
}
4 changes: 2 additions & 2 deletions src/Battle.Tests/CharacterCover/CoverUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class CoverUtility
}
}

//assign cover locations, (currently just "W", for "wall")
//assign cover locations, (currently just "", for "wall")
if (coverLocations != null && coverLocations.Count > 0)
{
foreach (Vector3 item in coverLocations)
{
map[(int)item.X, (int)item.Z] = "W";
map[(int)item.X, (int)item.Z] = "";
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/Battle.Tests/Encounters/AreaAttackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void FredThrowsGrenadeAndKillsJeffTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
Character jeff = CharacterPool.CreateJeffBaddie();
Expand Down Expand Up @@ -78,7 +78,7 @@ public void FredThrowsGrenadeAndKillsJeffWearingArmorTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
Character jeff = CharacterPool.CreateJeffBaddie();
Expand Down Expand Up @@ -128,7 +128,7 @@ public void FredThrowsGrenadeAndKillsJeffWearingArmorThisShreddedTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Abilities.Add(new("Shredder", AbilityType.ArmorShredding, 2));
fred.Location = new Vector3(2, 0, 0);
Expand Down Expand Up @@ -179,7 +179,7 @@ public void FredThrowsGrenadeAndHurtsJeffWearingArmorWithShreddedTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Abilities.Add(new("Shredder", AbilityType.ArmorShredding, 2));
fred.Location = new Vector3(2, 0, 0);
Expand Down Expand Up @@ -230,7 +230,7 @@ public void FredThrowsGrenadeAndInjuriesJeffTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
Character jeff = CharacterPool.CreateJeffBaddie();
Expand Down Expand Up @@ -277,7 +277,7 @@ public void FredThrowsGrenadeAndKillsJeffAndHarryTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
Character jeff = CharacterPool.CreateJeffBaddie();
Expand Down Expand Up @@ -335,7 +335,7 @@ public void FredThrowsGrenadeAndKillsJeffAndHarryIsSavedByArmorTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
Character jeff = CharacterPool.CreateJeffBaddie();
Expand Down Expand Up @@ -393,7 +393,7 @@ public void FredThrowsGrenadeAndInjuriesJeffAndKillsHarryTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
Character jeff = CharacterPool.CreateJeffBaddie();
Expand Down Expand Up @@ -449,7 +449,7 @@ public void FredThrowsGrenadeWithCriticalAbilityAndKillsJeffTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
fred.Abilities.Add(new("Biggest Booms", AbilityType.CriticalDamage, 2));
Expand Down Expand Up @@ -512,7 +512,7 @@ public void FOVFredThrowsGrenadeAndDestoriesCoverUpdatingFOVTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(5, 5);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
Character jeff = CharacterPool.CreateJeffBaddie();
Expand Down Expand Up @@ -616,7 +616,7 @@ public void NoItemAvailableToThrowTest()
{
//Arrange
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
fred.UtilityItemEquipped = null;
Expand Down
10 changes: 5 additions & 5 deletions src/Battle.Tests/Encounters/RegularAttackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public void FredAttacksWithRifleJeffBehindCoverAndInjuriesHimTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
fred.Abilities.Add(new("Bring em on", AbilityType.CriticalDamage, 3));
Expand Down Expand Up @@ -584,7 +584,7 @@ public void FredAttacksWithRifleJeffWhoIsFlankedAndKillsHimTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
fred.Abilities.Add(new("Bring em on", AbilityType.CriticalDamage, 3));
Expand Down Expand Up @@ -633,7 +633,7 @@ public void FredAttacksPlayerWhoIsOffMapTest()
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(5, 5);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
Weapon rifle = fred.WeaponEquipped;
Expand Down Expand Up @@ -667,7 +667,7 @@ public void FredAttacksWithRifleJeffBehindFullCoverAndHunkeredDownInjuriesHimTes
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
Weapon rifle = fred.WeaponEquipped;
Expand Down Expand Up @@ -710,7 +710,7 @@ public void FredAttacksWithRifleJeffBehindHalfCoverAndHunkeredDownInjuriesHimTes
// □ □ □ □ □
// □ □ P □ □
string[,] map = MapUtility.InitializeMap(10, 10);
map[2, 3] = "W"; //Add cover
map[2, 3] = ""; //Add cover
Character fred = CharacterPool.CreateFredHero();
fred.Location = new Vector3(2, 0, 0);
Weapon rifle = fred.WeaponEquipped;
Expand Down
Loading

0 comments on commit 53006f9

Please sign in to comment.