Add all Wariors

This commit is contained in:
Uamgl 2022-03-25 19:34:26 +02:00
parent 7ad754b56e
commit 0cef3f4972
25 changed files with 558 additions and 282 deletions

View File

@ -38,7 +38,7 @@ MonoBehaviour:
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0} InvisibleMaterial: {fileID: 0}
- isPlayer: 0 - isPlayer: 0
isAI: 0 isAI: 1
spawnPos: spawnPos:
x: 0 x: 0
z: 0 z: 0
@ -50,7 +50,7 @@ MonoBehaviour:
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0} InvisibleMaterial: {fileID: 0}
- isPlayer: 0 - isPlayer: 0
isAI: 0 isAI: 1
spawnPos: spawnPos:
x: 0 x: 0
z: 0 z: 0

View File

@ -31,3 +31,21 @@ MonoBehaviour:
maxHP: 1000 maxHP: 1000
manaRegen: 100 manaRegen: 100
maxMana: 1000 maxMana: 1000
- wariorPrefab: {fileID: 3762867976042010436, guid: d00f156879942114488e4db0689a3fb7, type: 3}
Type: 1
_weapon:
name:
icon: {fileID: 0}
objectToThrow: {fileID: 0}
VFXGameObject: {fileID: 0}
modifiedDamage: 0
damage: 0
speed: 0
disnatce: 0
reloadTime: 0
shots: 0
shotSound: {fileID: 0}
hitSound: {fileID: 0}
maxHP: 1000
manaRegen: 100
maxMana: 1000

View File

@ -48,7 +48,7 @@ namespace AI
private void InitAI(AIBase agent) private void InitAI(AIBase agent)
{ {
SetBehaviour(BotState.Patrol, agent); SetBehaviour(BotState.Patrol, agent,500);
} }
private void StartPatrolBehaviour(AIBase agent) private void StartPatrolBehaviour(AIBase agent)
@ -68,7 +68,7 @@ namespace AI
List<(float dist, UnitBase unit)> res = new List<(float, UnitBase)>(); List<(float dist, UnitBase unit)> res = new List<(float, UnitBase)>();
try try
{ {
res.AddRange(from color in (UnitColor[]) Enum.GetValues(typeof(UnitColor)) res.AddRange(from color in (UnitColor[]) Enum.GetValues(typeof(UnitColor))
where HexManager.UnitCurrentCell.ContainsKey(color) && where HexManager.UnitCurrentCell.ContainsKey(color) &&
HexManager.UnitCurrentCell[color].unit.IsVisible && HexManager.UnitCurrentCell[color].unit.IsVisible &&
@ -95,7 +95,7 @@ namespace AI
var attack = agent.UnitBase.Inventory.Where(x => x.Item is Bonus { BonusType: BonusType.Attack }).ToList(); var attack = agent.UnitBase.Inventory.Where(x => x.Item is Bonus { BonusType: BonusType.Attack }).ToList();
if (agent.CurentState is BotState.Attack && agent.UnitBase.AttackBonus == 0 && attack.Count > 0) if (agent.CurentState is BotState.Attack && agent.UnitBase.AttackBonus == 0 && attack.Count > 0)
{ {
SetBehaviour(BotState.AttackBonusUsage, agent); SetBehaviour(BotState.AttackBonusUsage, agent,500);
return BotState.AttackBonusUsage; return BotState.AttackBonusUsage;
} }
@ -106,18 +106,18 @@ namespace AI
if (agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToRetreet || if (agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToRetreet ||
agent.UnitBase.BaseView.AvailableShots == 0) agent.UnitBase.BaseView.AvailableShots == 0)
{ {
SetBehaviour(BotState.Retreet, agent); SetBehaviour(BotState.Retreet, agent,500);
return BotState.Retreet; return BotState.Retreet;
} }
if (Vector3.Distance(agent.UnitBase.Instance.transform.position, enemy.Instance.transform.position) <= if (Vector3.Distance(agent.UnitBase.Instance.transform.position, enemy.Instance.transform.position) <=
agent.UnitBase.Weapon.disnatce) agent.UnitBase.Weapon.disnatce)
{ {
SetBehaviour(BotState.Attack, agent); SetBehaviour(BotState.Attack, agent,500);
return BotState.Attack; return BotState.Attack;
} }
SetBehaviour(BotState.Agressive, agent); SetBehaviour(BotState.Agressive, agent,500);
return BotState.Agressive; return BotState.Agressive;
} }
@ -130,7 +130,7 @@ namespace AI
? agent.UnitBase.InventoryDefence.Count ? agent.UnitBase.InventoryDefence.Count
: agent.UnitBase.Inventory.Count) < agent.UnitBase.InventoryCapacity / 2) : agent.UnitBase.Inventory.Count) < agent.UnitBase.InventoryCapacity / 2)
{ {
SetBehaviour(BotState.CollectingBonus, agent); SetBehaviour(BotState.CollectingBonus, agent,500);
return BotState.CollectingBonus; return BotState.CollectingBonus;
} }
} }
@ -141,39 +141,36 @@ namespace AI
if (protect.Count > 0 && agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToUseProtectBonus && if (protect.Count > 0 && agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToUseProtectBonus &&
agent.UnitBase.DefenceBonus == 0) agent.UnitBase.DefenceBonus == 0)
{ {
SetBehaviour(BotState.ProtectBonusUsage, agent); SetBehaviour(BotState.ProtectBonusUsage, agent,500);
return BotState.ProtectBonusUsage; return BotState.ProtectBonusUsage;
} }
SetBehaviour(BotState.Patrol, agent);
SetBehaviour(BotState.Patrol, agent,500);
return BotState.Patrol; return BotState.Patrol;
} }
private void SetBehaviour(BotState state, AIBase agent) private void SetBehaviour(BotState state, AIBase agent, int dist)
{ {
switch (state) switch (state)
{ {
case BotState.Patrol: case BotState.Patrol:
StartPatrolBehaviour(agent); StartPatrolBehaviour(agent);
break; break;
case BotState.Agressive: case BotState.Agressive:
MoveToEnemy(agent); MoveToEnemy(agent, dist);
break; break;
case BotState.Attack: case BotState.Attack:
AttackEnemy(agent); AttackEnemy(agent);
break; break;
case BotState.CollectingBonus: case BotState.CollectingBonus:
if (agent != (AIAgent)agent) break; StartPatrolBehaviour(agent);
MoveToBonus((AIAgent)agent);
break; break;
case BotState.ProtectBonusUsage: case BotState.ProtectBonusUsage:
if (agent != (AIAgent)agent) break; StartPatrolBehaviour(agent);
UseBonus((AIAgent)agent, BonusType.Defence);
break; break;
case BotState.AttackBonusUsage: case BotState.AttackBonusUsage:
if (agent != (AIAgent)agent) break; StartPatrolBehaviour(agent);
UseBonus((AIAgent)agent, BonusType.Attack);
break; break;
case BotState.Dead: case BotState.Dead:
break; break;
@ -185,7 +182,7 @@ namespace AI
} }
} }
private void UseBonus(AIAgent agent, BonusType type) private void UseBonus(AIBase agent, BonusType type)
{ {
var attack = agent.UnitBase.Inventory.Where(x => x.Item is Bonus bonus && bonus.BonusType == type).ToList(); var attack = agent.UnitBase.Inventory.Where(x => x.Item is Bonus bonus && bonus.BonusType == type).ToList();
if (attack.Count == 0 || !agent.UnitBase.IsAlive) if (attack.Count == 0 || !agent.UnitBase.IsAlive)
@ -233,7 +230,7 @@ namespace AI
HexGrid.HexDistance), itemToMove.Value); HexGrid.HexDistance), itemToMove.Value);
} }
private void MoveToBonus(AIAgent agent) private void MoveToBonus(AIBase agent)
{ {
if (HexManager.UnitCurrentCell.TryGetValue(agent.UnitBase.Color, out var value)) if (HexManager.UnitCurrentCell.TryGetValue(agent.UnitBase.Color, out var value))
@ -249,17 +246,23 @@ namespace AI
agent.AttackTarget(new Vector2(dir.x, dir.z)); agent.AttackTarget(new Vector2(dir.x, dir.z));
} }
private void MoveToEnemy(AIBase agent) private void MoveToEnemy(AIBase agent, int dist)
{ {
var enemies = HexManager.UnitCurrentCell.Where(unit => var enemies = HexManager.UnitCurrentCell.Where(unit =>
unit.Value.unit.Color != agent.UnitBase.Color && unit.Value.unit.Color != agent.UnitBase.Color &&
Vector3.Distance(unit.Value.unit.Instance.transform.position, Vector3.Distance(unit.Value.unit.Instance.transform.position,
agent.UnitBase.Instance.transform.position) <= 6 * HexGrid.HexDistance).ToList(); agent.UnitBase.Instance.transform.position) <= dist * HexGrid.HexDistance).ToList();
if (enemies[Random.Range(0, enemies.Count)].Value.unit.Color == agent.UnitBase.Color) return; if (enemies[Random.Range(0, enemies.Count)].Value.unit.Color == agent.UnitBase.Color) return;
Pathfinding.FindPath(HexManager.UnitCurrentCell[agent.UnitBase.Color].cell, Pathfinding.FindPath(HexManager.UnitCurrentCell[agent.UnitBase.Color].cell,
enemies[Random.Range(0, enemies.Count)].Value.cell, agent.currentPath); enemies[Random.Range(0, enemies.Count)].Value.cell, agent.currentPath);
} }
private void CatchHex(AIBase agent)
{
Pathfinding.FindPath(HexManager.UnitCurrentCell[agent.UnitBase.Color].cell, HexManager.CellByColor[UnitColor.Grey].Where(x => x != null).ToList()[
Random.Range(0, HexManager.CellByColor[UnitColor.Grey].Count - 1)]
, agent.currentPath);
}
} }

View File

@ -48,7 +48,7 @@ namespace AI
private void InitAI(AIBase agent) private void InitAI(AIBase agent)
{ {
SetBehaviour(BotState.Patrol, agent); SetBehaviour(BotState.Patrol, agent,500);
} }
private void StartPatrolBehaviour(AIBase agent) private void StartPatrolBehaviour(AIBase agent)
@ -68,7 +68,7 @@ namespace AI
List<(float dist, UnitBase unit)> res = new List<(float, UnitBase)>(); List<(float dist, UnitBase unit)> res = new List<(float, UnitBase)>();
try try
{ {
res.AddRange(from color in (UnitColor[]) Enum.GetValues(typeof(UnitColor)) res.AddRange(from color in (UnitColor[]) Enum.GetValues(typeof(UnitColor))
where HexManager.UnitCurrentCell.ContainsKey(color) && where HexManager.UnitCurrentCell.ContainsKey(color) &&
HexManager.UnitCurrentCell[color].unit.IsVisible && HexManager.UnitCurrentCell[color].unit.IsVisible &&
@ -95,7 +95,7 @@ namespace AI
var attack = agent.UnitBase.Inventory.Where(x => x.Item is Bonus { BonusType: BonusType.Attack }).ToList(); var attack = agent.UnitBase.Inventory.Where(x => x.Item is Bonus { BonusType: BonusType.Attack }).ToList();
if (agent.CurentState is BotState.Attack && agent.UnitBase.AttackBonus == 0 && attack.Count > 0) if (agent.CurentState is BotState.Attack && agent.UnitBase.AttackBonus == 0 && attack.Count > 0)
{ {
SetBehaviour(BotState.AttackBonusUsage, agent); SetBehaviour(BotState.AttackBonusUsage, agent,500);
return BotState.AttackBonusUsage; return BotState.AttackBonusUsage;
} }
@ -106,18 +106,18 @@ namespace AI
if (agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToRetreet || if (agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToRetreet ||
agent.UnitBase.BaseView.AvailableShots == 0) agent.UnitBase.BaseView.AvailableShots == 0)
{ {
SetBehaviour(BotState.Retreet, agent); SetBehaviour(BotState.Retreet, agent,500);
return BotState.Retreet; return BotState.Retreet;
} }
if (Vector3.Distance(agent.UnitBase.Instance.transform.position, enemy.Instance.transform.position) <= if (Vector3.Distance(agent.UnitBase.Instance.transform.position, enemy.Instance.transform.position) <=
agent.UnitBase.Weapon.disnatce) agent.UnitBase.Weapon.disnatce)
{ {
SetBehaviour(BotState.Attack, agent); SetBehaviour(BotState.Attack, agent,500);
return BotState.Attack; return BotState.Attack;
} }
SetBehaviour(BotState.Agressive, agent); SetBehaviour(BotState.Agressive, agent,500);
return BotState.Agressive; return BotState.Agressive;
} }
@ -130,7 +130,7 @@ namespace AI
? agent.UnitBase.InventoryDefence.Count ? agent.UnitBase.InventoryDefence.Count
: agent.UnitBase.Inventory.Count) < agent.UnitBase.InventoryCapacity / 2) : agent.UnitBase.Inventory.Count) < agent.UnitBase.InventoryCapacity / 2)
{ {
SetBehaviour(BotState.CollectingBonus, agent); SetBehaviour(BotState.CollectingBonus, agent,500);
return BotState.CollectingBonus; return BotState.CollectingBonus;
} }
} }
@ -141,39 +141,36 @@ namespace AI
if (protect.Count > 0 && agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToUseProtectBonus && if (protect.Count > 0 && agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToUseProtectBonus &&
agent.UnitBase.DefenceBonus == 0) agent.UnitBase.DefenceBonus == 0)
{ {
SetBehaviour(BotState.ProtectBonusUsage, agent); SetBehaviour(BotState.ProtectBonusUsage, agent,500);
return BotState.ProtectBonusUsage; return BotState.ProtectBonusUsage;
} }
SetBehaviour(BotState.Patrol, agent);
SetBehaviour(BotState.Patrol, agent,500);
return BotState.Patrol; return BotState.Patrol;
} }
private void SetBehaviour(BotState state, AIBase agent) private void SetBehaviour(BotState state, AIBase agent, int dist=6)
{ {
switch (state) switch (state)
{ {
case BotState.Patrol: case BotState.Patrol:
StartPatrolBehaviour(agent); StartPatrolBehaviour(agent);
break; break;
case BotState.Agressive: case BotState.Agressive:
MoveToEnemy(agent); MoveToEnemy(agent, dist);
break; break;
case BotState.Attack: case BotState.Attack:
AttackEnemy(agent); AttackEnemy(agent);
break; break;
case BotState.CollectingBonus: case BotState.CollectingBonus:
if (agent != (AIAgent)agent) break; StartPatrolBehaviour(agent);
MoveToBonus((AIAgent)agent);
break; break;
case BotState.ProtectBonusUsage: case BotState.ProtectBonusUsage:
if (agent != (AIAgent)agent) break; StartPatrolBehaviour(agent);
UseBonus((AIAgent)agent, BonusType.Defence);
break; break;
case BotState.AttackBonusUsage: case BotState.AttackBonusUsage:
if (agent != (AIAgent)agent) break; StartPatrolBehaviour(agent);
UseBonus((AIAgent)agent, BonusType.Attack);
break; break;
case BotState.Dead: case BotState.Dead:
break; break;
@ -185,7 +182,7 @@ namespace AI
} }
} }
private void UseBonus(AIAgent agent, BonusType type) private void UseBonus(AIBase agent, BonusType type)
{ {
var attack = agent.UnitBase.Inventory.Where(x => x.Item is Bonus bonus && bonus.BonusType == type).ToList(); var attack = agent.UnitBase.Inventory.Where(x => x.Item is Bonus bonus && bonus.BonusType == type).ToList();
if (attack.Count == 0 || !agent.UnitBase.IsAlive) if (attack.Count == 0 || !agent.UnitBase.IsAlive)
@ -233,7 +230,7 @@ namespace AI
HexGrid.HexDistance), itemToMove.Value); HexGrid.HexDistance), itemToMove.Value);
} }
private void MoveToBonus(AIAgent agent) private void MoveToBonus(AIBase agent)
{ {
if (HexManager.UnitCurrentCell.TryGetValue(agent.UnitBase.Color, out var value)) if (HexManager.UnitCurrentCell.TryGetValue(agent.UnitBase.Color, out var value))
@ -244,18 +241,17 @@ namespace AI
private void AttackEnemy(AIBase agent) private void AttackEnemy(AIBase agent)
{ {
var enemy = GetNearestUnit(agent.UnitBase.Weapon.disnatce, agent.UnitBase); var enemy = GetNearestUnit(agent.UnitBase.Weapon.disnatce, agent.UnitBase);
if (enemy.Color == agent.UnitBase.Color) return;
var dir = DirectionHelper.DirectionTo(agent.UnitBase.Instance.transform.position, var dir = DirectionHelper.DirectionTo(agent.UnitBase.Instance.transform.position,
enemy.Instance.transform.position); enemy.Instance.transform.position);
agent.AttackTarget(new Vector2(dir.x, dir.z)); agent.AttackTarget(new Vector2(dir.x, dir.z));
} }
private void MoveToEnemy(AIBase agent) private void MoveToEnemy(AIBase agent, int dist)
{ {
var enemies = HexManager.UnitCurrentCell.Where(unit => var enemies = HexManager.UnitCurrentCell.Where(unit =>
unit.Value.unit.Color != agent.UnitBase.Color && unit.Value.unit.Color != agent.UnitBase.Color &&
Vector3.Distance(unit.Value.unit.Instance.transform.position, Vector3.Distance(unit.Value.unit.Instance.transform.position,
agent.UnitBase.Instance.transform.position) <= 6 * HexGrid.HexDistance).ToList(); agent.UnitBase.Instance.transform.position) <= dist * HexGrid.HexDistance).ToList();
if (enemies[Random.Range(0, enemies.Count)].Value.unit.Color == agent.UnitBase.Color) return; if (enemies[Random.Range(0, enemies.Count)].Value.unit.Color == agent.UnitBase.Color) return;
Pathfinding.FindPath(HexManager.UnitCurrentCell[agent.UnitBase.Color].cell, Pathfinding.FindPath(HexManager.UnitCurrentCell[agent.UnitBase.Color].cell,

View File

@ -239,7 +239,7 @@ namespace Units
_weapon.Fire(_instance.transform, _direction, this); _weapon.Fire(_instance.transform, _direction, this);
if (IsPlayer) if (IsPlayer)
OnShoot.Invoke(wariorData.Wariors[0], _unitData.color); OnShoot.Invoke(wariorData.Wariors[1], _unitData.color);
} }
protected override void UpdateBarCanvas() protected override void UpdateBarCanvas()

View File

@ -94,7 +94,7 @@ namespace Chars
if (unitInfo.isAI) if (unitInfo.isAI)
{ {
AIAgent agent = new AIAgent(enemy); AIPatrol agent = new AIPatrol(enemy);
enemy.OnSpawned += x => _controllers.Add(agent); enemy.OnSpawned += x => _controllers.Add(agent);
enemy.OnDeath += x => { _controllers.Remove(agent); }; enemy.OnDeath += x => { _controllers.Remove(agent); };
} }
@ -121,7 +121,7 @@ namespace Chars
Spawn(info, cellToSpawn[Random.Range(0, cellToSpawn.Count - 1)]); Spawn(info, cellToSpawn[Random.Range(0, cellToSpawn.Count - 1)]);
_uiController.CheatMenu.OnEnemyDeath(); _uiController.CheatMenu.OnEnemyDeath();
}, 1f); }, 5f);
} }
} }
} }

View File

@ -103,13 +103,7 @@ namespace Chars
enemy.Spawn(spawnPos.coordinates, spawnPos); enemy.Spawn(spawnPos.coordinates, spawnPos);
spawnPos.isSpawnPos = false; spawnPos.isSpawnPos = false;
<<<<<<< HEAD
enemy.BaseView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas); enemy.BaseView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas);
=======
enemy.UnitView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas);
>>>>>>> abaf11d23750589a662b4fd2daa471f53d864cf7
} }
} }
@ -127,7 +121,7 @@ namespace Chars
Spawn(info, cellToSpawn[Random.Range(0, cellToSpawn.Count - 1)]); Spawn(info, cellToSpawn[Random.Range(0, cellToSpawn.Count - 1)]);
_uiController.CheatMenu.OnEnemyDeath(); _uiController.CheatMenu.OnEnemyDeath();
}, 1f); }, 5f);
} }
} }
} }

View File

@ -0,0 +1,78 @@
using Data;
using DG.Tweening;
using HexFiled;
using Weapons;
namespace Units.Wariors.AbstractsBase
{
public abstract class Assailant : Warior
{
protected Assailant(WariorInfo data, Weapon weapon, HexGrid hexGrid, UnitColor spawnerColor) : base(data, weapon, hexGrid, spawnerColor)
{
}
public override void Move(HexDirection direction)
{
base.Move(direction);
if (_cell.GetNeighbor(direction).Color == Color ||
(_cell.GetNeighbor(direction).Color == _easyCaptureColor && _easyCaptureColor != UnitColor.Grey))
{
DoTransit(direction);
}
else if (_cell.GetNeighbor(direction).Color != UnitColor.Grey)
{
if (_mana - _hexGrid.HexHardCaptureCost <= 0) return;
IsHardToCapture = true;
DoTransit(direction);
}
else if (_mana - _hexGrid.HexCaptureCost >= 0)
{
if (_mana - _hexGrid.HexHardCaptureCost <= 0) return;
DoTransit(direction);
}
}
public override void SetCell(HexCell cell, bool isInstanceTrans = false, bool isPaintingHex = false)
{
_cell = cell;
HexManager.UnitCurrentCell[Color] = (cell, this);
if (!isInstanceTrans)
{
IsBusy = true;
_instance.transform.DOMove(_cell.transform.position, _animLength.SuperJump)
.OnComplete(() => IsBusy = false);
}
else
{
_instance.transform.DOMove(_cell.transform.position, 0.5f).SetEase(Ease.Linear);
}
if (isPaintingHex)
{
cell.PaintHex(Color, true);
}
}
protected override void CaptureHex()
{
if (!_isInfiniteMana)
{
if (IsHardToCapture)
{
_mana -= _hexGrid.HexHardCaptureCost;
}
else
{
_mana -= _hexGrid.HexCaptureCost;
}
}
BaseView.RegenMana();
UpdateBarCanvas();
IsBusy = false;
IsHardToCapture = false;
_cell.PaintHex(Color);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d501f0e4635f1f54ab2d6a99d5a6addd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using Data;
using DG.Tweening;
using HexFiled;
using Weapons;
namespace Units.Wariors.AbstractsBase
{
public class AssailantTest : Assailant
{
public AssailantTest(WariorInfo data, Weapon weapon, HexGrid hexGrid, UnitColor spawnerColor) : base(data, weapon, hexGrid, spawnerColor)
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4943e01088392604b87f1f17af7e48f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,81 @@
using Data;
using DG.Tweening;
using HexFiled;
using Weapons;
namespace Units.Wariors.AbstractsBase
{
public abstract class Invader : Warior
{
protected Invader(WariorInfo data, Weapon weapon, HexGrid hexGrid, UnitColor spawnerColor) : base(data, weapon, hexGrid, spawnerColor)
{
}
public override void Move(HexDirection direction)
{
base.Move(direction);
if (_cell.GetNeighbor(direction).Color == Color ||
(_cell.GetNeighbor(direction).Color == _easyCaptureColor && _easyCaptureColor != UnitColor.Grey))
{
DoTransit(direction);
}
else if (_cell.GetNeighbor(direction).Color != UnitColor.Grey)
{
if (_mana - _hexGrid.HexHardCaptureCost <= 0) return;
IsHardToCapture = true;
DoTransit(direction);
}
else if (_mana - _hexGrid.HexCaptureCost >= 0)
{
if (_mana - _hexGrid.HexHardCaptureCost <= 0) return;
DoTransit(direction);
}
}
public override void StartAttack()
{
}
public override void SetCell(HexCell cell, bool isInstanceTrans = false, bool isPaintingHex = false)
{
_cell = cell;
HexManager.UnitCurrentCell[Color] = (cell, this);
if (!isInstanceTrans)
{
IsBusy = true;
_instance.transform.DOMove(_cell.transform.position, _animLength.SuperJump)
.OnComplete(() => IsBusy = false);
}
else
{
_instance.transform.DOMove(_cell.transform.position, 0.5f).SetEase(Ease.Linear);
}
if (isPaintingHex)
{
cell.PaintHex(Color, true);
}
}
protected override void CaptureHex()
{
if (!_isInfiniteMana)
{
if (IsHardToCapture)
{
_mana -= _hexGrid.HexHardCaptureCost;
}
else
{
_mana -= _hexGrid.HexCaptureCost;
}
}
BaseView.RegenMana();
UpdateBarCanvas();
IsBusy = false;
IsHardToCapture = false;
_cell.PaintHex(Color);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 254aadc9cab19a04b83ca9e2d50ff068
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,30 +1,16 @@
using System; using System;
using System.Linq;
using AI;
using Data; using Data;
using DefaultNamespace;
using DG.Tweening;
using HexFiled; using HexFiled;
using Items;
using UnityEngine;
using Weapons; using Weapons;
namespace Units.Wariors.AbstractsBase namespace Units.Wariors.AbstractsBase
{ {
public abstract class Patrol : UnitBase public abstract class Patrol : Warior
{ {
protected WariorInfo _data; protected Patrol(WariorInfo data, Weapon weapon, HexGrid hexGrid, UnitColor spawnerColor) : base(data, weapon, hexGrid, spawnerColor)
public WariorInfo Data => _data;
public Patrol(WariorInfo data, Weapon weapon, HexGrid hexGrid, UnitColor spawnerColor)
{ {
Initialize(weapon, hexGrid);
_data = data;
Color = spawnerColor;
maxHP = _data.maxHP;
maxMana = _data.maxMana;
} }
public override void SetCell(HexCell cell, bool isInstanceTrans = false, bool isPaintingHex = false) public override void SetCell(HexCell cell, bool isInstanceTrans = false, bool isPaintingHex = false)
{ {
} }
@ -32,86 +18,16 @@ namespace Units.Wariors.AbstractsBase
protected override void CaptureHex() protected override void CaptureHex()
{ {
} }
public override void Move(HexDirection direction)
protected override void RegenMana()
{ {
_mana += _data.manaRegen; if (_cell.GetNeighbor(direction) == null || _cell.GetNeighbor(direction).BuildingInstance != null ||
UpdateBarCanvas(); IsBusy || IsHardToCapture ||
(_cell.GetNeighbor(direction).Color != Color
&& HexManager.UnitCurrentCell.TryGetValue(_cell.GetNeighbor(direction).Color, out var value)
&& value.cell.Equals(_cell.GetNeighbor(direction)))) return;
if (_cell.GetNeighbor(direction).Color != Color) return;
DoTransit(direction);
} }
}
protected override void Attacking()
{
Aim(_direction);
_weapon.Fire(_instance.transform, _direction, this);
}
public override void StartAttack()
{
if (IsBusy || !BaseView.Shoot()) return;
IsBusy = true;
if (_direction.Equals(Vector2.zero))
{
var enemy = AIManager.GetNearestUnit(_weapon.disnatce, this);
if (enemy == null)
_direction =
new Vector2(BaseView.transform.forward.x, BaseView.transform.forward.z);
else
{
var dir = DirectionHelper.DirectionTo(_instance.transform.position,
enemy.Instance.transform.position);
_direction = new Vector2(dir.x, dir.z);
}
}
RotateUnit(_direction);
_animator.SetTrigger("Attack");
}
public override HexCell PlaceItemAim(HexDirection direction)
{
if (_cell.GetNeighbor(direction).Color != Color)
{
BaseView.AimCanvas.SetActive(false);
return null;
}
var cell = _cell.GetNeighbor(direction);
BaseView.AimCanvas.transform.LookAt(cell.transform);
return cell;
}
protected override void Damage(int dmg)
{
if (_defenceBonus == 0 && _hp - dmg <= 0f)
{
Death();
}
if (_hp - dmg > maxHP)
{
_hp = maxHP;
}
if (_defenceBonus > 0)
{
return;
}
_hp -= dmg;
UpdateBarCanvas();
}
public override bool CanPickUpItem(Item item)
{
return false;
}
public override void PickUpItem(ItemContainer item)
{
}
}
} }

View File

@ -24,6 +24,7 @@ namespace Units.Wariors.AbstractsBase
Color = spawnerColor; Color = spawnerColor;
maxHP = _data.maxHP; maxHP = _data.maxHP;
maxMana = _data.maxMana; maxMana = _data.maxMana;
hexGrid.OnHexPainted += Death;
} }
public override void SetCell(HexCell cell, bool isInstanceTrans = false, bool isPaintingHex = false) public override void SetCell(HexCell cell, bool isInstanceTrans = false, bool isPaintingHex = false)
{ {
@ -88,9 +89,9 @@ namespace Units.Wariors.AbstractsBase
Death(); Death();
} }
if (_hp - dmg > _unitData.maxHP) if (_hp - dmg > maxHP)
{ {
_hp = _unitData.maxHP; _hp = maxHP;
} }
if (_defenceBonus > 0) if (_defenceBonus > 0)
@ -113,5 +114,8 @@ namespace Units.Wariors.AbstractsBase
public override void PickUpItem(ItemContainer item) public override void PickUpItem(ItemContainer item)
{ {
} }
private void Death(){
OnOnDeath(this);
}
} }
} }

View File

@ -0,0 +1,13 @@
using Data;
using HexFiled;
using Weapons;
namespace Units.Wariors.AbstractsBase
{
public class TestInvader : Invader
{
public TestInvader(WariorInfo data, Weapon weapon, HexGrid hexGrid, UnitColor spawnerColor) : base(data, weapon, hexGrid, spawnerColor)
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9098881405a6de64c80a1d9c4e809c9e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,222 @@
using System.Linq;
using AI;
using Data;
using DefaultNamespace;
using DG.Tweening;
using HexFiled;
using Units.Views;
using Items;
using UnityEngine;
using Weapons;
using System.Collections.Generic;
namespace Units.Wariors.AbstractsBase
{
public abstract class Warior : UnitBase
{
protected WariorInfo _data;
public WariorInfo Data => _data;
public Warior(WariorInfo data, Weapon weapon, HexGrid hexGrid, UnitColor spawnerColor)
{
Initialize(weapon, hexGrid);
_data = data;
Color = spawnerColor;
maxHP = _data.maxHP;
maxMana = _data.maxMana;
hexGrid.OnHexPainted += Death;
}
public override void Spawn(HexCoordinates hexCoordinates, HexCell spawnCell = null)
{
if (!IsAlive)
{
_cell = spawnCell != null ? spawnCell : _hexGrid.GetCellFromCoord(hexCoordinates);
IsVisible = true;
_cell.PaintHex(Color, true);
_cell.GetListNeighbours().ForEach(x => { x?.PaintHex(Color, true); });
_inventory = new List<ItemContainer>();
_inventoryDefence = new List<ItemContainer>();
_instance = UnityEngine.Object.Instantiate(_data.wariorPrefab, _cell.transform.parent);
_instance.transform.localPosition = _cell.transform.localPosition;
IsAlive = true;
_animator = _instance.GetComponent<Animator>();
BaseView = _instance.AddComponent<WariorView>();
BaseView.SetUp(_weapon, RegenMana, _data.manaRegen, CaptureHex,
this, _hexGrid.HardCaptureTime);
SetAnimLength();
MusicController.Instance.AddAudioSource(_instance);
_mana = maxMana;
_hp = maxHP;
SetUpActions();
_weapon.SetModifiedDamage(0);
IsBusy = false;
OnOnPlayerSpawned(this);
}
}
public override void Move(HexDirection direction)
{
if (_cell.GetNeighbor(direction) == null || _cell.GetNeighbor(direction).BuildingInstance != null ||
IsBusy || IsHardToCapture ||
(_cell.GetNeighbor(direction).Color != Color
&& HexManager.UnitCurrentCell.TryGetValue(_cell.GetNeighbor(direction).Color, out var value)
&& value.cell.Equals(_cell.GetNeighbor(direction)))) return;
}
protected override void DoTransit(HexDirection direction)
{
IsBusy = true;
_isCapturing = Color != _cell.GetNeighbor(direction).Color;
_cell = _cell.GetNeighbor(direction);
RotateUnit(new Vector2((_cell.transform.position - _instance.transform.position).normalized.x,
(_cell.transform.position - _instance.transform.position).normalized.z));
_animator.SetTrigger("Move");
_animator.SetBool("isMoving", IsBusy);
_instance.transform.DOMove(_cell.transform.position, _animLength.Move);
}
protected override void RegenMana()
{
_mana += _data.manaRegen;
UpdateBarCanvas();
}
protected override void Attacking()
{
Aim(_direction);
_weapon.Fire(_instance.transform, _direction, this);
}
public override void StartAttack()
{
if (IsBusy || !BaseView.Shoot()) return;
IsBusy = true;
if (_direction.Equals(Vector2.zero))
{
var enemy = AIManager.GetNearestUnit(_weapon.disnatce, this);
if (enemy == null)
_direction =
new Vector2(BaseView.transform.forward.x, BaseView.transform.forward.z);
else
{
var dir = DirectionHelper.DirectionTo(_instance.transform.position,
enemy.Instance.transform.position);
_direction = new Vector2(dir.x, dir.z);
}
}
RotateUnit(_direction);
_animator.SetTrigger("Attack");
}
public override HexCell PlaceItemAim(HexDirection direction)
{
if (_cell.GetNeighbor(direction).Color != Color)
{
BaseView.AimCanvas.SetActive(false);
return null;
}
var cell = _cell.GetNeighbor(direction);
BaseView.AimCanvas.transform.LookAt(cell.transform);
return cell;
}
protected override void Damage(int dmg)
{
if (_defenceBonus == 0 && _hp - dmg <= 0f)
{
Death();
}
if (_hp - dmg > maxHP)
{
_hp = maxHP;
}
if (_defenceBonus > 0)
{
return;
}
_hp -= dmg;
UpdateBarCanvas();
}
protected override void UpdateBarCanvas()
{
if (_hp > maxHP)
_hp = maxHP;
if (_mana > this.maxMana)
_mana = this.maxMana;
float hp = _hp;
float mana = _mana;
float maxHp = maxHP;
float maxMana = this.maxMana;
BarCanvas.ManaBar.DOFillAmount(mana / maxMana, 0.5f).SetEase(Ease.InQuad);
BarCanvas.HealthBar.DOFillAmount(hp / maxHp, 0.5f).SetEase(Ease.InQuad);
}
public override void Death()
{
BaseView.OnStep -= MoveEnd;
BaseView.OnAttackEnd -= AttackEnd;
BaseView.OnAttack -= Attacking;
BaseView.OnHit -= Damage;
IsAlive = false;
IsBusy = true;
_animator.SetTrigger("Death");
var vfx = VFXController.Instance.PlayEffect(HexGrid.Colors[Color].VFXDeathPrefab,
_instance.transform.position);
TimerHelper.Instance.StartTimer(() =>
{
UnityEngine.Object.Destroy(_instance);
OnOnDeath(this);
}, _animLength.Death);
MusicController.Instance.AddAudioSource(vfx);
MusicController.Instance.PlayAudioClip(MusicController.Instance.MusicData.SfxMusic.Death, vfx);
MusicController.Instance.RemoveAudioSource(_instance);
}
public override void Retreet(HexDirection dir)
{
if (!_isCapturing) return;
var openList = _cell.GetListNeighbours().Where(x => x != null && x.Color == Color).ToList();
if (!openList.Contains(_cell.GetNeighbor(dir)))
{
return;
}
IsBusy = false;
IsHardToCapture = false;
BaseView.StopHardCapture();
Move(dir);
}
private void Death(HexCell cell)
{
OnOnDeath(this);
}
public override bool CanPickUpItem(Item item)
{
return false;
}
public override void PickUpItem(ItemContainer item)
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2741f65aa69c69344bafff89df574321
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,14 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using AI; using AI;
using Data; using Data;
using DefaultNamespace;
using DG.Tweening;
using HexFiled; using HexFiled;
using Items;
using Units.Views;
using Units.Wariors.AbstractsBase; using Units.Wariors.AbstractsBase;
using UnityEngine;
using Weapons; using Weapons;
namespace Units.Wariors namespace Units.Wariors
@ -18,120 +11,5 @@ namespace Units.Wariors
public Holem(WariorInfo data, Weapon weapon, HexGrid hexGrid, UnitColor spawnerColor) : base(data, weapon, hexGrid, spawnerColor) public Holem(WariorInfo data, Weapon weapon, HexGrid hexGrid, UnitColor spawnerColor) : base(data, weapon, hexGrid, spawnerColor)
{ {
} }
public override void Retreet(HexDirection dir)
{
if (!_isCapturing) return;
var openList = _cell.GetListNeighbours().Where(x => x != null && x.Color == Color).ToList();
if (!openList.Contains(_cell.GetNeighbor(dir)))
{
return;
}
IsBusy = false;
IsHardToCapture = false;
BaseView.StopHardCapture();
Move(dir);
}
public override void Move(HexDirection direction)
{
if (_cell.GetNeighbor(direction) == null || _cell.GetNeighbor(direction).BuildingInstance != null ||
IsBusy || IsHardToCapture ||
(_cell.GetNeighbor(direction).Color != Color
&& HexManager.UnitCurrentCell.TryGetValue(_cell.GetNeighbor(direction).Color, out var value)
&& value.cell.Equals(_cell.GetNeighbor(direction)))) return;
if (_cell.GetNeighbor(direction).Color != Color ) return;
DoTransit(direction);
}
protected override void DoTransit(HexDirection direction)
{
IsBusy = true;
_isCapturing = Color != _cell.GetNeighbor(direction).Color;
_cell = _cell.GetNeighbor(direction);
HexManager.UnitCurrentCell[Color] = (_cell, this);
RotateUnit(new Vector2((_cell.transform.position - _instance.transform.position).normalized.x,
(_cell.transform.position - _instance.transform.position).normalized.z));
_animator.SetTrigger("Move");
_animator.SetBool("isMoving", IsBusy);
_instance.transform.DOMove(_cell.transform.position, _animLength.Move);
}
public override void Spawn(HexCoordinates hexCoordinates, HexCell spawnCell = null)
{
if (!IsAlive)
{
_cell = spawnCell != null ? spawnCell : _hexGrid.GetCellFromCoord(hexCoordinates);
IsVisible = true;
_inventory = new List<ItemContainer>();
_inventoryDefence = new List<ItemContainer>();
_instance = Object.Instantiate(_data.wariorPrefab, _cell.transform.parent);
_instance.transform.localPosition = _cell.transform.localPosition;
IsAlive = true;
_animator = _instance.GetComponent<Animator>();
BaseView = _instance.AddComponent<WariorView>();
BaseView.SetUp(_weapon, RegenMana, _data.manaRegen, CaptureHex,
this, _hexGrid.HardCaptureTime);
SetAnimLength();
MusicController.Instance.AddAudioSource(_instance);
_mana = maxMana;
_hp = maxHP;
SetUpActions();
_weapon.SetModifiedDamage(0);
IsBusy = false;
OnOnPlayerSpawned(this);
}
}
protected override void UpdateBarCanvas()
{
if (_hp > maxHP)
_hp =maxHP;
if (_mana > this.maxMana)
_mana = this.maxMana;
float hp = _hp;
float mana = _mana;
float maxHp = maxHP;
float maxMana = this.maxMana;
BarCanvas.ManaBar.DOFillAmount(mana / maxMana, 0.5f).SetEase(Ease.InQuad);
BarCanvas.HealthBar.DOFillAmount(hp / maxHp, 0.5f).SetEase(Ease.InQuad);
}
public override void Death()
{
BaseView.OnStep -= MoveEnd;
BaseView.OnAttackEnd -= AttackEnd;
BaseView.OnAttack -= Attacking;
BaseView.OnHit -= Damage;
IsAlive = false;
IsBusy = true;
_animator.SetTrigger("Death");
var vfx = VFXController.Instance.PlayEffect(HexGrid.Colors[Color].VFXDeathPrefab,
_instance.transform.position);
TimerHelper.Instance.StartTimer(() =>
{
Object.Destroy(_instance);
OnOnDeath(this);
}, _animLength.Death);
MusicController.Instance.AddAudioSource(vfx);
MusicController.Instance.PlayAudioClip(MusicController.Instance.MusicData.SfxMusic.Death, vfx);
MusicController.Instance.RemoveAudioSource(_instance);
}
} }
} }

View File

@ -31,7 +31,7 @@ namespace Units.Wariors
HexManager.CellByColor[unitColor].Where(x => x != null).ToList()[ HexManager.CellByColor[unitColor].Where(x => x != null).ToList()[
Random.Range(0, HexManager.CellByColor[unitColor].Count - 1)]; Random.Range(0, HexManager.CellByColor[unitColor].Count - 1)];
var patrol = new Holem(wariorInfo,_data.WeaponsData.WeaponsList[Random.Range(0, _data.WeaponsData.WeaponsList.Count - 1)], _hexGrid,unitColor); var patrol = new TestInvader(wariorInfo,_data.WeaponsData.WeaponsList[Random.Range(0, _data.WeaponsData.WeaponsList.Count - 1)], _hexGrid,unitColor);
AIAgent agent = new AIAgent (patrol); AIAgent agent = new AIAgent (patrol);
patrol.OnSpawned += x => _controllers.Add(agent); patrol.OnSpawned += x => _controllers.Add(agent);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long