Fixed some bugs. Fixed looping in AI. Rewrote death actions with tiles and death conditions

This commit is contained in:
mamontow 2021-09-01 00:08:07 +03:00
parent 2f14bd0bd2
commit 2a33f6acf4
7 changed files with 85 additions and 100 deletions

View File

@ -215,31 +215,31 @@ AnimatorController:
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: BackToIdle - m_Name: BackToIdle
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: Build - m_Name: Build
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: TreeAttack - m_Name: TreeAttack
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: Move - m_Name: Move
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
m_AnimatorLayers: m_AnimatorLayers:
- serializedVersion: 5 - serializedVersion: 5
m_Name: Base Layer m_Name: Base Layer
@ -492,7 +492,7 @@ AnimatorState:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: Movement m_Name: Movement
m_Speed: 2 m_Speed: 3
m_CycleOffset: 0 m_CycleOffset: 0
m_Transitions: m_Transitions:
- {fileID: 354894258193955894} - {fileID: 354894258193955894}

View File

@ -18857,7 +18857,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f701310aaea215a4d9e0c8646d3e1ecd, type: 3} m_Script: {fileID: 11500000, guid: f701310aaea215a4d9e0c8646d3e1ecd, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
nextTileMoveTime: 1 nextTileMoveTime: 0.7
moveDistance: 1 moveDistance: 1
moveVFX: {fileID: 2040783568} moveVFX: {fileID: 2040783568}
--- !u!114 &1503763734 --- !u!114 &1503763734
@ -18926,7 +18926,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 754e9bf36b6ab0b40a8b71c58aa34b04, type: 3} m_Script: {fileID: 11500000, guid: 754e9bf36b6ab0b40a8b71c58aa34b04, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
isAIActive: 0 isAIActive: 1
botState: 0 botState: 0
leftInput: {x: 0, y: 0} leftInput: {x: 0, y: 0}
rightInput: {x: 0, y: 0} rightInput: {x: 0, y: 0}
@ -22869,7 +22869,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f701310aaea215a4d9e0c8646d3e1ecd, type: 3} m_Script: {fileID: 11500000, guid: f701310aaea215a4d9e0c8646d3e1ecd, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
nextTileMoveTime: 1 nextTileMoveTime: 0.7
moveDistance: 1 moveDistance: 1
moveVFX: {fileID: 1307683756} moveVFX: {fileID: 1307683756}
--- !u!114 &1801060024 --- !u!114 &1801060024
@ -22884,8 +22884,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4b3c4882af86905429c1c42aabf068c1, type: 3} m_Script: {fileID: 11500000, guid: 4b3c4882af86905429c1c42aabf068c1, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
neutralCaptureTime: 1 neutralCaptureTime: 0.2
enemyCaptureTime: 2 enemyCaptureTime: 0.4
capVFX: {fileID: 442387583353148024, guid: 53959bc898e9a644daad0282881d596a, type: 3} capVFX: {fileID: 442387583353148024, guid: 53959bc898e9a644daad0282881d596a, type: 3}
--- !u!114 &1801060025 --- !u!114 &1801060025
MonoBehaviour: MonoBehaviour:
@ -22938,7 +22938,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5182c2cb5eef6d849b560f764c4a0ed6, type: 3} m_Script: {fileID: 11500000, guid: 5182c2cb5eef6d849b560f764c4a0ed6, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
startHealth: 120 startHealth: 10000
currentHealth: 0 currentHealth: 0
playerImpactVFX: {fileID: 2957420090356197408, guid: 5d1244f7b80cadd428a70173a01ce889, playerImpactVFX: {fileID: 2957420090356197408, guid: 5d1244f7b80cadd428a70173a01ce889,
type: 3} type: 3}
@ -24850,8 +24850,7 @@ Transform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1923264931} m_GameObject: {fileID: 1923264931}
m_LocalRotation: {x: 0.029971035, y: -0.000000004076362, z: 0.0000000075761575, m_LocalRotation: {x: 0.029971035, y: 0.000000004076362, z: -0.000000007576159, w: 0.9995508}
w: 0.9995508}
m_LocalPosition: {x: 0, y: 0.87083435, z: -14.50833} m_LocalPosition: {x: 0, y: 0.87083435, z: -14.50833}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
@ -25539,7 +25538,7 @@ Transform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1946816075} m_GameObject: {fileID: 1946816075}
m_LocalRotation: {x: 0.5257311, y: -0.000000007318311, z: 0.000000004522964, w: 0.85065085} m_LocalRotation: {x: 0.5257311, y: 0.0000000073183117, z: -0.0000000045229647, w: 0.85065085}
m_LocalPosition: {x: 0, y: 13, z: -6.5} m_LocalPosition: {x: 0, y: 13, z: -6.5}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:

View File

@ -31,6 +31,9 @@ public class AI_BotController : MonoBehaviour
private bool isAttackedOnce = false; private bool isAttackedOnce = false;
private int _maxTriesToCalculatePath = 15;
private int _triesToCalculatePath = 15;
private void Awake() private void Awake()
{ {
_playerState = GetComponent<PlayerState>(); _playerState = GetComponent<PlayerState>();
@ -99,14 +102,24 @@ public class AI_BotController : MonoBehaviour
//calculate path //calculate path
TileInfo currentTile = _playerState.currentTile; TileInfo currentTile = _playerState.currentTile;
TileInfo targetPathTile = TileManagment.GetClosestOtherTile(currentTile, _playerState.ownerIndex, _startBotPoint); TileInfo targetPathTile = TileManagment.GetClosestOtherTile(currentTile, _playerState.ownerIndex, _startBotPoint);
_triesToCalculatePath++;
//Debug.Log(targetPathTile); //Debug.Log(targetPathTile);
if (!RecalculatePath(currentTile, targetPathTile)) if (!RecalculatePath(currentTile, targetPathTile) && _triesToCalculatePath < _maxTriesToCalculatePath)
{ {
StartPatrolBehaviour(); StartPatrolBehaviour();
botState = BotState.Patrol;
return; return;
} }
else
{
targetPathTile = TileManagment.GetRandomOtherTile(_playerState.ownerIndex);
RecalculatePath(currentTile, targetPathTile);
}
if (_currentFollowingPath.Count > 0)
{
botState = BotState.Patrol; botState = BotState.Patrol;
_triesToCalculatePath = 0;
}
} }
private void SetInitialBotParams() private void SetInitialBotParams()

View File

@ -54,7 +54,11 @@ public class CaptureController : MonoBehaviour
{ {
_playerState.SetNewState(CharacterState.Capture); _playerState.SetNewState(CharacterState.Capture);
if (!tile.easyCaptureFor.Contains(_playerState.ownerIndex)) if (tile.easyCaptureFor.Contains(_playerState.ownerIndex) || tile.isLocked)
{
CaptureTile(tile);
}
else
{ {
if (tile.tileOwnerIndex == TileOwner.Neutral) if (tile.tileOwnerIndex == TileOwner.Neutral)
{ {
@ -67,10 +71,6 @@ public class CaptureController : MonoBehaviour
StartCoroutine(_currentCoroutine); StartCoroutine(_currentCoroutine);
} }
} }
else
{
CaptureTile(tile);
}
} }
@ -98,7 +98,7 @@ public class CaptureController : MonoBehaviour
private void CaptureTile(TileInfo tile) private void CaptureTile(TileInfo tile)
{ {
TileManagment.ChangeTileOwner(tile, _playerState.ownerIndex); TileManagment.ChangeTileOwner(tile, _playerState);
_playerState.SetNewState(CharacterState.Idle); _playerState.SetNewState(CharacterState.Idle);
if (capVFX != null) if (capVFX != null)
{ {

View File

@ -15,7 +15,7 @@ public class DeathChecker : MonoBehaviour
private List<float> lastDeathTime = new List<float>(); private List<float> lastDeathTime = new List<float>();
private float updateTime = 1f; private float updateTime = 1f;
private int spawnSafezone = 2; private int spawnSafezone = 1;
public static Action<PlayerState> OnPlayerDeath; public static Action<PlayerState> OnPlayerDeath;
@ -36,6 +36,44 @@ public class DeathChecker : MonoBehaviour
InvokeRepeating("Checker", 1f, updateTime); InvokeRepeating("Checker", 1f, updateTime);
} }
private void CheckPlayersDeath(PlayerState agressor)
{
List<PlayerState> thisIterationDeadPlayers = new List<PlayerState>();
foreach (var player in agressor.enemies)
{
if (!GameManager.activePlayers.Contains(player)
|| Vector3.Distance(agressor.transform.position, player.transform.position)>1.5f*TileManagment.tileOffset)
{
continue;
}
TileInfo playerTile = player.currentTile;
if (player.currentTile.canMove)
{
playerTile = player.targetMoveTile;
}
var myAdjacentTiles = TileManagment.GetOwnerAdjacentTiles(playerTile, player.ownerIndex);
int canStandTiles = 0;
foreach (var tile in myAdjacentTiles)
{
if (tile.canMove)
{
canStandTiles++;
}
}
if (canStandTiles > 0)
{
continue;
}
thisIterationDeadPlayers.Add(player);
Debug.Log("Found " + canStandTiles + " canStand tiles in " + myAdjacentTiles.Count + " adjacent");
}
foreach (var player in thisIterationDeadPlayers)
{
MakeDead(player);
}
}
private void SetupLastDeathTimes(List<PlayerState> players) private void SetupLastDeathTimes(List<PlayerState> players)
{ {
foreach (var player in players) foreach (var player in players)
@ -44,54 +82,6 @@ public class DeathChecker : MonoBehaviour
} }
} }
private void CheckPlayersDeath()
{
List<PlayerState> thisIterationDeadPlayers = new List<PlayerState>();
foreach (var player in GameManager.activePlayers)
{
var playerTile = player.currentTile;
var myAdjacentTiles = TileManagment.GetOwnerAdjacentTiles(playerTile, player.ownerIndex);
int cantStandTilesCounter = 0;
int tileCounter = 0;
foreach (var tile in myAdjacentTiles)
{
tileCounter++;
if (!tile.canMove)
{
cantStandTilesCounter++;
}
}
if (cantStandTilesCounter >= myAdjacentTiles.Count)
{
thisIterationDeadPlayers.Add(player);
}
/*if (playerTile.tileOwnerIndex != player.ownerIndex)
{
int cantStandTilesCounter = 0;
int tileCounter = 0;
foreach (var tile in myAdjacentTiles)
{
tileCounter++;
if (!tile.canMove)
{
cantStandTilesCounter++;
}
}
if (cantStandTilesCounter >= myAdjacentTiles.Count)
{
thisIterationDeadPlayers.Add(player);
}
}*/
}
foreach (var player in thisIterationDeadPlayers)
{
MakeDead(player);
}
}
public void MakeDead(PlayerState player) public void MakeDead(PlayerState player)
{ {
@ -166,10 +156,10 @@ public class DeathChecker : MonoBehaviour
private void PlayerDeadActions(PlayerState player) private void PlayerDeadActions(PlayerState player)
{ {
List<TileInfo> playerTiles = TileManagment.GetCharacterTiles(player); List<TileInfo> playerTiles = TileManagment.GetCharacterTiles(player);
TileManagment.SetEasyCaptureForPlayers(playerTiles, player.enemies); TileManagment.LockTiles(playerTiles, true);
player.SetDead(); player.SetDead();
//Debug.Log("player " + player.name + " dead"); Debug.Log("player " + player.name + " dead");
if (deathParticles) if (deathParticles)
{ {
@ -184,12 +174,7 @@ public class DeathChecker : MonoBehaviour
TileInfo resTile = GetAvailableResTile(player, playerTiles); TileInfo resTile = GetAvailableResTile(player, playerTiles);
if (resTile) if (resTile)
{ {
TileManagment.RemoveEasyCaptureForTiles(playerTiles); TileManagment.LockTiles(playerTiles, false);
foreach (var enemy in player.enemies)
{
TileManagment.CheckIfSurroundedByOwner(TileManagment.levelTiles, enemy.ownerIndex, playerTiles[0]);
}
player.SetAlive(resTile.tilePosition); player.SetAlive(resTile.tilePosition);

View File

@ -18,7 +18,6 @@ public class TileInfo : MonoBehaviour
public bool isBorderTile = false; public bool isBorderTile = false;
public bool isChecked = false;
public bool isLocked = false; public bool isLocked = false;
#region Pathfinding values #region Pathfinding values

View File

@ -12,7 +12,7 @@ public class TileManagment : MonoBehaviour
public static List<List<TileInfo>> charTiles = new List<List<TileInfo>>(); public static List<List<TileInfo>> charTiles = new List<List<TileInfo>>();
public static Action OnInitialized; public static Action OnInitialized;
public static Action OnAnyTileCaptured; public static Action<PlayerState> OnAnyTileCaptured;
public static List<Material> tileMaterialsStatic; public static List<Material> tileMaterialsStatic;
@ -29,6 +29,7 @@ public class TileManagment : MonoBehaviour
private void Awake() private void Awake()
{ {
InitTileManager(); InitTileManager();
Debug.Log("tile offset is " + tileOffset + " points");
} }
private void InitTileManager() private void InitTileManager()
@ -83,8 +84,10 @@ public class TileManagment : MonoBehaviour
tile.GetComponent<Renderer>().material = tileMaterialsStatic[(int)tile.tileOwnerIndex]; tile.GetComponent<Renderer>().material = tileMaterialsStatic[(int)tile.tileOwnerIndex];
} }
public static void ChangeTileOwner(TileInfo tile, TileOwner newOwner) public static void ChangeTileOwner(TileInfo tile, PlayerState newPlayer)
{ {
tile.isLocked = false;
TileOwner newOwner = newPlayer.ownerIndex;
TileOwner oldOwner = tile.tileOwnerIndex; TileOwner oldOwner = tile.tileOwnerIndex;
tile.tileOwnerIndex = newOwner; tile.tileOwnerIndex = newOwner;
tile.GetComponent<Renderer>().material = tileMaterialsStatic[(int)tile.tileOwnerIndex]; tile.GetComponent<Renderer>().material = tileMaterialsStatic[(int)tile.tileOwnerIndex];
@ -92,7 +95,7 @@ public class TileManagment : MonoBehaviour
charTiles[(int)newOwner].Add(tile); charTiles[(int)newOwner].Add(tile);
charTiles[(int)oldOwner].Remove(tile); charTiles[(int)oldOwner].Remove(tile);
OnAnyTileCaptured?.Invoke(); OnAnyTileCaptured?.Invoke(newPlayer);
CheckSurroundedTiles(levelTiles, newOwner, oldOwner); CheckSurroundedTiles(levelTiles, newOwner, oldOwner);
@ -242,30 +245,24 @@ public class TileManagment : MonoBehaviour
return playerTiles; return playerTiles;
} }
public static void SetEasyCaptureForPlayers(List<TileInfo> tiles, List<PlayerState> enemies) public static void LockTiles(List<TileInfo> tiles, bool lockState)
{ {
if (enemies.Count <= 0)
{
return;
}
foreach (TileInfo tile in tiles) foreach (TileInfo tile in tiles)
{ {
tile.isLocked = true; tile.isLocked = lockState;
foreach (var enemy in enemies)
{
tile.easyCaptureFor.Add(enemy.ownerIndex);
}
} }
} }
public static void RemoveEasyCaptureForTiles(List<TileInfo> tiles)
/*public static void RemoveEasyCaptureForTiles(List<TileInfo> tiles)
{ {
foreach (TileInfo tile in tiles) foreach (TileInfo tile in tiles)
{ {
tile.easyCaptureFor.Clear(); tile.easyCaptureFor.Clear();
tile.isLocked = false; tile.isLocked = false;
} }
} }*/
/*public static TileInfo GetClosestOwnerTile(TileInfo startTile, TileOwner owner, float searchRadius) /*public static TileInfo GetClosestOwnerTile(TileInfo startTile, TileOwner owner, float searchRadius)
{ {
@ -323,13 +320,8 @@ public class TileManagment : MonoBehaviour
{ {
tile.checkedFor.Clear(); tile.checkedFor.Clear();
foreach (var owner in checkPlayers) foreach (var owner in checkPlayers)
{
//tile.checkedFor.Remove(newOwner);
if (!tile.isLocked)
{ {
tile.easyCaptureFor.Remove(owner); tile.easyCaptureFor.Remove(owner);
//tile.easyCaptureFor.Clear();
}
} }
@ -392,13 +384,10 @@ public class TileManagment : MonoBehaviour
} }
foreach (TileInfo tile in connectedTiles) foreach (TileInfo tile in connectedTiles)
{
if (!tile.isLocked)
{ {
tile.easyCaptureFor.Add(ownerIndex); tile.easyCaptureFor.Add(ownerIndex);
} }
} }
}
private Vector3[] GetBasicDirections(int directionsAmount) private Vector3[] GetBasicDirections(int directionsAmount)
{ {