Add Patroul
This commit is contained in:
parent
b1e00327d8
commit
2af75490ba
@ -18,74 +18,49 @@ MonoBehaviour:
|
|||||||
spawnPos:
|
spawnPos:
|
||||||
x: 19
|
x: 19
|
||||||
z: 4
|
z: 4
|
||||||
unitPrefa: {fileID: 7527582019267571087, guid: f102085e8bc4cad4992d43b84dee1055, type: 3}
|
unitPrefa: {fileID: 3762867976042010436, guid: d00f156879942114488e4db0689a3fb7, type: 3}
|
||||||
color: 3
|
color: 3
|
||||||
manaRegen: 10
|
manaRegen: 10
|
||||||
maxMana: 1000
|
maxMana: 1000
|
||||||
maxHP: 100
|
maxHP: 1000
|
||||||
inventoryCapacity: 4
|
inventoryCapacity: 4
|
||||||
InvisibleMaterial: {fileID: 2100000, guid: 021ce5359e648764395415a8668a2094, type: 2}
|
InvisibleMaterial: {fileID: 2100000, guid: 021ce5359e648764395415a8668a2094, type: 2}
|
||||||
- isPlayer: 0
|
- isPlayer: 0
|
||||||
isAI: 1
|
isAI: 1
|
||||||
spawnPos:
|
spawnPos:
|
||||||
x: 3
|
|
||||||
z: 4
|
|
||||||
unitPrefa: {fileID: 3762867976042010436, guid: d00f156879942114488e4db0689a3fb7, type: 3}
|
|
||||||
color: 4
|
|
||||||
manaRegen: 100
|
|
||||||
maxMana: 1000
|
|
||||||
maxHP: 100
|
|
||||||
inventoryCapacity: 4
|
|
||||||
InvisibleMaterial: {fileID: 0}
|
|
||||||
- isPlayer: 0
|
|
||||||
isAI: 1
|
|
||||||
spawnPos:
|
|
||||||
x: -1
|
|
||||||
z: 42
|
|
||||||
unitPrefa: {fileID: 742650227762578155, guid: 97b4a76c55741764e880b63d6e1514a9, type: 3}
|
|
||||||
color: 0
|
|
||||||
manaRegen: 100
|
|
||||||
maxMana: 1000
|
|
||||||
maxHP: 100
|
|
||||||
inventoryCapacity: 4
|
|
||||||
InvisibleMaterial: {fileID: 0}
|
|
||||||
- isPlayer: 0
|
|
||||||
isAI: 1
|
|
||||||
spawnPos:
|
|
||||||
x: -17
|
|
||||||
z: 40
|
|
||||||
unitPrefa: {fileID: 8887939040951305984, guid: 1a81dbbd6ef62324491d9f58654ebe4b, type: 3}
|
|
||||||
color: 1
|
|
||||||
manaRegen: 100
|
|
||||||
maxMana: 1000
|
|
||||||
maxHP: 100
|
|
||||||
inventoryCapacity: 4
|
|
||||||
InvisibleMaterial: {fileID: 0}
|
|
||||||
_warior:
|
|
||||||
- spawnPos:
|
|
||||||
x: 0
|
x: 0
|
||||||
z: 0
|
z: 0
|
||||||
wariorPrefa: {fileID: 5982292246613942016, guid: e508e7126551af140aae54649db1a0c1, type: 3}
|
unitPrefa: {fileID: 8887939040951305984, guid: 1a81dbbd6ef62324491d9f58654ebe4b, type: 3}
|
||||||
color: 0
|
color: 1
|
||||||
manaRegen: 100
|
manaRegen: 10
|
||||||
maxMana: 1000
|
maxMana: 1000
|
||||||
maxHP: 1000
|
maxHP: 100
|
||||||
|
inventoryCapacity: 4
|
||||||
|
InvisibleMaterial: {fileID: 0}
|
||||||
|
- isPlayer: 0
|
||||||
|
isAI: 0
|
||||||
|
spawnPos:
|
||||||
|
x: 0
|
||||||
|
z: 0
|
||||||
|
unitPrefa: {fileID: 7527582019267571087, guid: f102085e8bc4cad4992d43b84dee1055, type: 3}
|
||||||
|
color: 4
|
||||||
|
manaRegen: 10
|
||||||
|
maxMana: 1000
|
||||||
|
maxHP: 100
|
||||||
|
inventoryCapacity: 4
|
||||||
|
InvisibleMaterial: {fileID: 0}
|
||||||
|
- isPlayer: 0
|
||||||
|
isAI: 0
|
||||||
|
spawnPos:
|
||||||
|
x: 0
|
||||||
|
z: 0
|
||||||
|
unitPrefa: {fileID: 742650227762578155, guid: 97b4a76c55741764e880b63d6e1514a9, type: 3}
|
||||||
|
color: 0
|
||||||
|
manaRegen: 10
|
||||||
|
maxMana: 1000
|
||||||
|
maxHP: 100
|
||||||
|
inventoryCapacity: 4
|
||||||
InvisibleMaterial: {fileID: 0}
|
InvisibleMaterial: {fileID: 0}
|
||||||
prefab: {fileID: 0}
|
|
||||||
Type: 0
|
|
||||||
_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}
|
|
||||||
playerBarCanvas: {fileID: 482855193181693567, guid: dec5dd0d644d5c548a53563e65837162, type: 3}
|
playerBarCanvas: {fileID: 482855193181693567, guid: dec5dd0d644d5c548a53563e65837162, type: 3}
|
||||||
botBarCanvas: {fileID: 482855193181693567, guid: 1af9afdbdd132df4989c826eb6cb6562, type: 3}
|
botBarCanvas: {fileID: 482855193181693567, guid: 1af9afdbdd132df4989c826eb6cb6562, type: 3}
|
||||||
attackAimCanvas: {fileID: 2273039178377770117, guid: 09a0317cbdff9fa479a18c9e20743a8e, type: 3}
|
attackAimCanvas: {fileID: 2273039178377770117, guid: 09a0317cbdff9fa479a18c9e20743a8e, type: 3}
|
||||||
|
@ -13,17 +13,8 @@ MonoBehaviour:
|
|||||||
m_Name: WariorsData
|
m_Name: WariorsData
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
_wariors:
|
_wariors:
|
||||||
- spawnPos:
|
- wariorPrefab: {fileID: 7527582019267571087, guid: f102085e8bc4cad4992d43b84dee1055, type: 3}
|
||||||
x: 0
|
Type: 1
|
||||||
z: 0
|
|
||||||
wariorPrefa: {fileID: 5982292246613942016, guid: e508e7126551af140aae54649db1a0c1, type: 3}
|
|
||||||
color: 0
|
|
||||||
manaRegen: 2
|
|
||||||
maxMana: 50
|
|
||||||
maxHP: 20
|
|
||||||
InvisibleMaterial: {fileID: 0}
|
|
||||||
prefab: {fileID: 0}
|
|
||||||
Type: 0
|
|
||||||
_weapon:
|
_weapon:
|
||||||
name:
|
name:
|
||||||
icon: {fileID: 0}
|
icon: {fileID: 0}
|
||||||
@ -37,3 +28,6 @@ MonoBehaviour:
|
|||||||
shots: 0
|
shots: 0
|
||||||
shotSound: {fileID: 0}
|
shotSound: {fileID: 0}
|
||||||
hitSound: {fileID: 0}
|
hitSound: {fileID: 0}
|
||||||
|
maxHP: 1000
|
||||||
|
manaRegen: 100
|
||||||
|
maxMana: 1000
|
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 95ff3f9dfdc9589429836c544811a695
|
guid: 1d3033378c1ed2c459e77ca30a5cc37b
|
||||||
NativeFormatImporter:
|
NativeFormatImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
mainObjectFileID: 11400000
|
mainObjectFileID: 11400000
|
@ -61,31 +61,6 @@ MonoBehaviour:
|
|||||||
maxHP: 100
|
maxHP: 100
|
||||||
inventoryCapacity: 4
|
inventoryCapacity: 4
|
||||||
InvisibleMaterial: {fileID: 0}
|
InvisibleMaterial: {fileID: 0}
|
||||||
_warior:
|
|
||||||
- spawnPos:
|
|
||||||
x: 0
|
|
||||||
z: 0
|
|
||||||
wariorPrefa: {fileID: 5982292246613942016, guid: e508e7126551af140aae54649db1a0c1, type: 3}
|
|
||||||
color: 0
|
|
||||||
manaRegen: 100
|
|
||||||
maxMana: 1000
|
|
||||||
maxHP: 100
|
|
||||||
InvisibleMaterial: {fileID: 0}
|
|
||||||
prefab: {fileID: 0}
|
|
||||||
Type: 0
|
|
||||||
_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}
|
|
||||||
playerBarCanvas: {fileID: 482855193181693567, guid: dec5dd0d644d5c548a53563e65837162, type: 3}
|
playerBarCanvas: {fileID: 482855193181693567, guid: dec5dd0d644d5c548a53563e65837162, type: 3}
|
||||||
botBarCanvas: {fileID: 482855193181693567, guid: 1af9afdbdd132df4989c826eb6cb6562, type: 3}
|
botBarCanvas: {fileID: 482855193181693567, guid: 1af9afdbdd132df4989c826eb6cb6562, type: 3}
|
||||||
attackAimCanvas: {fileID: 2273039178377770117, guid: 09a0317cbdff9fa479a18c9e20743a8e, type: 3}
|
attackAimCanvas: {fileID: 2273039178377770117, guid: 09a0317cbdff9fa479a18c9e20743a8e, type: 3}
|
||||||
|
@ -61,31 +61,6 @@ MonoBehaviour:
|
|||||||
maxHP: 100
|
maxHP: 100
|
||||||
inventoryCapacity: 4
|
inventoryCapacity: 4
|
||||||
InvisibleMaterial: {fileID: 0}
|
InvisibleMaterial: {fileID: 0}
|
||||||
_warior:
|
|
||||||
- spawnPos:
|
|
||||||
x: 0
|
|
||||||
z: 0
|
|
||||||
wariorPrefa: {fileID: 5982292246613942016, guid: e508e7126551af140aae54649db1a0c1, type: 3}
|
|
||||||
color: 0
|
|
||||||
manaRegen: 100
|
|
||||||
maxMana: 1000
|
|
||||||
maxHP: 100
|
|
||||||
InvisibleMaterial: {fileID: 0}
|
|
||||||
prefab: {fileID: 0}
|
|
||||||
Type: 0
|
|
||||||
_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}
|
|
||||||
playerBarCanvas: {fileID: 482855193181693567, guid: dec5dd0d644d5c548a53563e65837162, type: 3}
|
playerBarCanvas: {fileID: 482855193181693567, guid: dec5dd0d644d5c548a53563e65837162, type: 3}
|
||||||
botBarCanvas: {fileID: 482855193181693567, guid: 1af9afdbdd132df4989c826eb6cb6562, type: 3}
|
botBarCanvas: {fileID: 482855193181693567, guid: 1af9afdbdd132df4989c826eb6cb6562, type: 3}
|
||||||
attackAimCanvas: {fileID: 2273039178377770117, guid: 09a0317cbdff9fa479a18c9e20743a8e, type: 3}
|
attackAimCanvas: {fileID: 2273039178377770117, guid: 09a0317cbdff9fa479a18c9e20743a8e, type: 3}
|
||||||
|
@ -12,10 +12,10 @@ namespace DefaultNamespace.AI
|
|||||||
{
|
{
|
||||||
protected UnitBase _unitBase;
|
protected UnitBase _unitBase;
|
||||||
private Camera _camera;
|
private Camera _camera;
|
||||||
private BotState curentState;
|
protected BotState curentState;
|
||||||
public Queue<HexDirection> currentPath;
|
public Queue<HexDirection> currentPath;
|
||||||
public Action<AIBase> OnAgentInited;
|
public Action<AIBase> OnAgentInited;
|
||||||
private Vector2 _attackDirection;
|
protected Vector2 _attackDirection;
|
||||||
|
|
||||||
public UnitBase UnitBase => _unitBase;
|
public UnitBase UnitBase => _unitBase;
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ using DefaultNamespace.AI;
|
|||||||
using HexFiled;
|
using HexFiled;
|
||||||
using Items;
|
using Items;
|
||||||
using Units;
|
using Units;
|
||||||
|
using Units.Wariors.AbstractsBase;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Random = UnityEngine.Random;
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ namespace AI
|
|||||||
_triesToCalculatePath = 0;
|
_triesToCalculatePath = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Unit GetNearestUnit(int cellDist, UnitBase agent)
|
public static UnitBase GetNearestUnit(int cellDist, UnitBase agent)
|
||||||
{
|
{
|
||||||
List<(float dist, UnitBase unit)> res = new List<(float, UnitBase)>();
|
List<(float dist, UnitBase unit)> res = new List<(float, UnitBase)>();
|
||||||
try
|
try
|
||||||
@ -79,7 +80,7 @@ namespace AI
|
|||||||
Vector3.Distance(HexManager.UnitCurrentCell[color].unit.Instance.transform.position,
|
Vector3.Distance(HexManager.UnitCurrentCell[color].unit.Instance.transform.position,
|
||||||
agent.Instance.transform.position), HexManager.UnitCurrentCell[color].unit));
|
agent.Instance.transform.position), HexManager.UnitCurrentCell[color].unit));
|
||||||
|
|
||||||
return (Unit) (res.Count > 0 ? res.OrderBy(x => x.Item1).First().unit : null);
|
return res.Count > 0 ? res.OrderBy(x => x.Item1).First().unit : null;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -103,7 +104,7 @@ namespace AI
|
|||||||
if (enemy != null && agent.UnitBase.Hp > agent.UnitBase.maxHP * _data.PercentToRetreet && enemy.IsAlive)
|
if (enemy != null && agent.UnitBase.Hp > agent.UnitBase.maxHP * _data.PercentToRetreet && enemy.IsAlive)
|
||||||
{
|
{
|
||||||
if (agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToRetreet ||
|
if (agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToRetreet ||
|
||||||
agent.UnitBase.UnitView.AvailableShots == 0)
|
agent.UnitBase.BaseView.AvailableShots == 0)
|
||||||
{
|
{
|
||||||
SetBehaviour(BotState.Retreet, agent);
|
SetBehaviour(BotState.Retreet, agent);
|
||||||
return BotState.Retreet;
|
return BotState.Retreet;
|
||||||
@ -119,9 +120,8 @@ namespace AI
|
|||||||
SetBehaviour(BotState.Agressive, agent);
|
SetBehaviour(BotState.Agressive, agent);
|
||||||
return BotState.Agressive;
|
return BotState.Agressive;
|
||||||
}
|
}
|
||||||
if (agent == (AIAgent)agent)
|
|
||||||
{
|
var item = GetNearestItem(agent);
|
||||||
var item = GetNearestItem((AIAgent)agent);
|
|
||||||
if (item.hex != null)
|
if (item.hex != null)
|
||||||
{
|
{
|
||||||
if ((item.dist <= _data.DistaceToCollectBonus ||
|
if ((item.dist <= _data.DistaceToCollectBonus ||
|
||||||
@ -134,17 +134,17 @@ namespace AI
|
|||||||
return BotState.CollectingBonus;
|
return BotState.CollectingBonus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var protect = agent.UnitBase.InventoryDefence.Where(x => x.Item is Bonus { BonusType: BonusType.Defence })
|
|
||||||
.ToList();
|
|
||||||
if (protect.Count > 0 && agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToUseProtectBonus &&
|
|
||||||
agent.UnitBase.DefenceBonus == 0)
|
|
||||||
{
|
|
||||||
SetBehaviour(BotState.ProtectBonusUsage, agent);
|
|
||||||
return BotState.ProtectBonusUsage;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
var protect = agent.UnitBase.InventoryDefence.Where(x => x.Item is Bonus { BonusType: BonusType.Defence })
|
||||||
|
.ToList();
|
||||||
|
if (protect.Count > 0 && agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToUseProtectBonus &&
|
||||||
|
agent.UnitBase.DefenceBonus == 0)
|
||||||
|
{
|
||||||
|
SetBehaviour(BotState.ProtectBonusUsage, agent);
|
||||||
|
return BotState.ProtectBonusUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SetBehaviour(BotState.Patrol, agent);
|
SetBehaviour(BotState.Patrol, agent);
|
||||||
return BotState.Patrol;
|
return BotState.Patrol;
|
||||||
@ -199,7 +199,8 @@ namespace AI
|
|||||||
|
|
||||||
private void Retreet(AIBase agent)
|
private void Retreet(AIBase agent)
|
||||||
{
|
{
|
||||||
var enemy = GetNearestUnit(6, agent.UnitBase)?.Instance.transform;
|
var enemy = GetNearestUnit(6, agent.UnitBase)?.Instance.transform;
|
||||||
|
|
||||||
if (enemy == null)
|
if (enemy == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -211,7 +212,7 @@ namespace AI
|
|||||||
agent.currentPath.Enqueue(DirectionHelper.VectorToDirection(new Vector2(dir.x, dir.z)));
|
agent.currentPath.Enqueue(DirectionHelper.VectorToDirection(new Vector2(dir.x, dir.z)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private (int dist, HexCell hex) GetNearestItem(AIAgent agent)
|
private (int dist, HexCell hex) GetNearestItem(AIBase agent)
|
||||||
{
|
{
|
||||||
var itemsToMove =
|
var itemsToMove =
|
||||||
(from entry in ItemFabric.Items
|
(from entry in ItemFabric.Items
|
||||||
@ -250,11 +251,11 @@ namespace AI
|
|||||||
|
|
||||||
private void MoveToEnemy(AIBase agent)
|
private void MoveToEnemy(AIBase agent)
|
||||||
{
|
{
|
||||||
var enemies = HexManager.UnitCurrentCell
|
var enemies = HexManager.UnitCurrentCell.Where(unit =>
|
||||||
.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) <= 6 * HexGrid.HexDistance).ToList();
|
||||||
|
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);
|
||||||
|
278
Assets/Scripts/AI/AIManager.cs.bak
Normal file
278
Assets/Scripts/AI/AIManager.cs.bak
Normal file
@ -0,0 +1,278 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Data;
|
||||||
|
using DefaultNamespace;
|
||||||
|
using DefaultNamespace.AI;
|
||||||
|
using HexFiled;
|
||||||
|
using Items;
|
||||||
|
using Units;
|
||||||
|
using Units.Wariors.AbstractsBase;
|
||||||
|
using UnityEngine;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
|
namespace AI
|
||||||
|
{
|
||||||
|
public class AIManager
|
||||||
|
{
|
||||||
|
private int _triesToCalculatePath = 0;
|
||||||
|
private int _maxTriesToCalculatePath = 5;
|
||||||
|
private AIData _data;
|
||||||
|
|
||||||
|
private static AIManager _instance;
|
||||||
|
|
||||||
|
|
||||||
|
public static AIManager Instance
|
||||||
|
{
|
||||||
|
get => _instance;
|
||||||
|
private set => _instance ??= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public AIManager(AIData data)
|
||||||
|
{
|
||||||
|
_data = data;
|
||||||
|
Instance = this;
|
||||||
|
HexManager.agents = new Dictionary<GameObject, AIBase>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddAgent(AIBase agent)
|
||||||
|
{
|
||||||
|
agent.OnAgentInited += InitAI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveAgent(AIBase agent)
|
||||||
|
{
|
||||||
|
agent.OnAgentInited -= InitAI;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitAI(AIBase agent)
|
||||||
|
{
|
||||||
|
SetBehaviour(BotState.Patrol, agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartPatrolBehaviour(AIBase agent)
|
||||||
|
{
|
||||||
|
HexManager.GetNearestDifferCell(agent.UnitBase.Color, agent.currentPath);
|
||||||
|
while (agent.currentPath.Count == 0 && _triesToCalculatePath < _maxTriesToCalculatePath)
|
||||||
|
{
|
||||||
|
HexManager.GetNearestDifferCell(agent.UnitBase.Color, agent.currentPath);
|
||||||
|
_triesToCalculatePath++;
|
||||||
|
}
|
||||||
|
|
||||||
|
_triesToCalculatePath = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UnitBase GetNearestUnit(int cellDist, UnitBase agent)
|
||||||
|
{
|
||||||
|
List<(float dist, UnitBase unit)> res = new List<(float, UnitBase)>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
res.AddRange(from color in (UnitColor[]) Enum.GetValues(typeof(UnitColor))
|
||||||
|
where HexManager.UnitCurrentCell.ContainsKey(color) &&
|
||||||
|
HexManager.UnitCurrentCell[color].unit.IsVisible &&
|
||||||
|
HexManager.UnitCurrentCell[color] != (null, null) &&
|
||||||
|
Vector3.Distance(HexManager.UnitCurrentCell[color].unit.Instance.transform.position,
|
||||||
|
agent.Instance.transform.position) <= cellDist * HexGrid.HexDistance &&
|
||||||
|
HexManager.UnitCurrentCell[color].unit.Color != agent.Color
|
||||||
|
select (
|
||||||
|
Vector3.Distance(HexManager.UnitCurrentCell[color].unit.Instance.transform.position,
|
||||||
|
agent.Instance.transform.position), HexManager.UnitCurrentCell[color].unit));
|
||||||
|
|
||||||
|
return res.Count > 0 ? res.OrderBy(x => x.Item1).First().unit : null;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Log(e.Message + " " + agent.Color + " ");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public BotState GetNewBehaviour(AIBase agent)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
SetBehaviour(BotState.AttackBonusUsage, agent);
|
||||||
|
return BotState.AttackBonusUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var enemy = GetNearestUnit(_data.DistanceToAgr, agent.UnitBase);
|
||||||
|
if (enemy != null && agent.UnitBase.Hp > agent.UnitBase.maxHP * _data.PercentToRetreet && enemy.IsAlive)
|
||||||
|
{
|
||||||
|
if (agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToRetreet ||
|
||||||
|
agent.UnitBase.BaseView.AvailableShots == 0)
|
||||||
|
{
|
||||||
|
SetBehaviour(BotState.Retreet, agent);
|
||||||
|
return BotState.Retreet;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Vector3.Distance(agent.UnitBase.Instance.transform.position, enemy.Instance.transform.position) <=
|
||||||
|
agent.UnitBase.Weapon.disnatce)
|
||||||
|
{
|
||||||
|
SetBehaviour(BotState.Attack, agent);
|
||||||
|
return BotState.Attack;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetBehaviour(BotState.Agressive, agent);
|
||||||
|
return BotState.Agressive;
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = GetNearestItem(agent);
|
||||||
|
if (item.hex != null)
|
||||||
|
{
|
||||||
|
if ((item.dist <= _data.DistaceToCollectBonus ||
|
||||||
|
agent.UnitBase.Mana <= agent.UnitBase.maxMana * _data.ManaPercentToCollectBonus) &&
|
||||||
|
(item.hex.Item.Item.Type == ItemType.DEFENCE
|
||||||
|
? agent.UnitBase.InventoryDefence.Count
|
||||||
|
: agent.UnitBase.Inventory.Count) < agent.UnitBase.InventoryCapacity / 2)
|
||||||
|
{
|
||||||
|
SetBehaviour(BotState.CollectingBonus, agent);
|
||||||
|
return BotState.CollectingBonus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var protect = agent.UnitBase.InventoryDefence.Where(x => x.Item is Bonus { BonusType: BonusType.Defence })
|
||||||
|
.ToList();
|
||||||
|
if (protect.Count > 0 && agent.UnitBase.Hp <= agent.UnitBase.maxHP * _data.PercentToUseProtectBonus &&
|
||||||
|
agent.UnitBase.DefenceBonus == 0)
|
||||||
|
{
|
||||||
|
SetBehaviour(BotState.ProtectBonusUsage, agent);
|
||||||
|
return BotState.ProtectBonusUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SetBehaviour(BotState.Patrol, agent);
|
||||||
|
return BotState.Patrol;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetBehaviour(BotState state, AIBase agent)
|
||||||
|
{
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case BotState.Patrol:
|
||||||
|
StartPatrolBehaviour(agent);
|
||||||
|
break;
|
||||||
|
case BotState.Agressive:
|
||||||
|
MoveToEnemy(agent);
|
||||||
|
break;
|
||||||
|
case BotState.Attack:
|
||||||
|
AttackEnemy(agent);
|
||||||
|
break;
|
||||||
|
case BotState.CollectingBonus:
|
||||||
|
if (agent != (AIAgent)agent) break;
|
||||||
|
MoveToBonus((AIAgent)agent);
|
||||||
|
break;
|
||||||
|
case BotState.ProtectBonusUsage:
|
||||||
|
if (agent != (AIAgent)agent) break;
|
||||||
|
UseBonus((AIAgent)agent, BonusType.Defence);
|
||||||
|
break;
|
||||||
|
case BotState.AttackBonusUsage:
|
||||||
|
if (agent != (AIAgent)agent) break;
|
||||||
|
UseBonus((AIAgent)agent, BonusType.Attack);
|
||||||
|
break;
|
||||||
|
case BotState.Dead:
|
||||||
|
break;
|
||||||
|
case BotState.Retreet:
|
||||||
|
Retreet(agent);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(state), state, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UseBonus(AIAgent agent, BonusType type)
|
||||||
|
{
|
||||||
|
var attack = agent.UnitBase.Inventory.Where(x => x.Item is Bonus bonus && bonus.BonusType == type).ToList();
|
||||||
|
if (attack.Count == 0 || !agent.UnitBase.IsAlive)
|
||||||
|
{
|
||||||
|
GetNewBehaviour(agent);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
((Bonus)attack.First().Item).Invoke((Unit)(agent.UnitBase));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Retreet(AIBase agent)
|
||||||
|
{
|
||||||
|
var enemy = GetNearestUnit(6, agent.UnitBase)?.Instance.transform;
|
||||||
|
|
||||||
|
if (enemy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dir = -DirectionHelper.DirectionTo(agent.UnitBase.Instance.transform.position,
|
||||||
|
enemy.position);
|
||||||
|
agent.currentPath.Clear();
|
||||||
|
agent.currentPath.Enqueue(DirectionHelper.VectorToDirection(new Vector2(dir.x, dir.z)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private (int dist, HexCell hex) GetNearestItem(AIBase agent)
|
||||||
|
{
|
||||||
|
var itemsToMove =
|
||||||
|
(from entry in ItemFabric.Items
|
||||||
|
where Vector3.Distance(agent.UnitBase.Instance.transform.position, entry.Value.transform.position) <
|
||||||
|
10 * HexGrid.HexDistance
|
||||||
|
orderby Vector3.Distance(agent.UnitBase.Instance.transform.position, entry.Value.transform.position)
|
||||||
|
select entry).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
if (itemsToMove.Count == 0)
|
||||||
|
{
|
||||||
|
return (0, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
var itemToMove = itemsToMove.First();
|
||||||
|
return (
|
||||||
|
(int)(Vector3.Distance(itemToMove.Value.transform.position, agent.UnitBase.Instance.transform.position) /
|
||||||
|
HexGrid.HexDistance), itemToMove.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MoveToBonus(AIAgent agent)
|
||||||
|
{
|
||||||
|
if (HexManager.UnitCurrentCell.TryGetValue(agent.UnitBase.Color, out var value))
|
||||||
|
|
||||||
|
Pathfinding.FindPath(value.cell, GetNearestItem(agent).hex,
|
||||||
|
agent.currentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AttackEnemy(AIBase agent)
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
enemy.Instance.transform.position);
|
||||||
|
agent.AttackTarget(new Vector2(dir.x, dir.z));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MoveToEnemy(AIBase agent)
|
||||||
|
{
|
||||||
|
var enemies = HexManager.UnitCurrentCell.Where(unit =>
|
||||||
|
unit.Value.unit.Color != agent.UnitBase.Color &&
|
||||||
|
Vector3.Distance(unit.Value.unit.Instance.transform.position,
|
||||||
|
agent.UnitBase.Instance.transform.position) <= 6 * HexGrid.HexDistance).ToList();
|
||||||
|
if (enemies[Random.Range(0, enemies.Count)].Value.unit.Color == agent.UnitBase.Color) return;
|
||||||
|
|
||||||
|
Pathfinding.FindPath(HexManager.UnitCurrentCell[agent.UnitBase.Color].cell,
|
||||||
|
enemies[Random.Range(0, enemies.Count)].Value.cell, agent.currentPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public enum BotState
|
||||||
|
{
|
||||||
|
Patrol,
|
||||||
|
Agressive,
|
||||||
|
Attack,
|
||||||
|
CollectingBonus,
|
||||||
|
AttackBonusUsage,
|
||||||
|
ProtectBonusUsage,
|
||||||
|
Dead,
|
||||||
|
Retreet
|
||||||
|
}
|
||||||
|
}
|
7
Assets/Scripts/AI/AIManager.cs.bak.meta
Normal file
7
Assets/Scripts/AI/AIManager.cs.bak.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ff30a3f98994dd941bf4c9ad0038e41b
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -58,7 +58,7 @@ public class CheatMenu : MonoBehaviour
|
|||||||
playerGridGO.GetComponentInChildren<TMP_Text>().text = "Player";
|
playerGridGO.GetComponentInChildren<TMP_Text>().text = "Player";
|
||||||
AddButton(() =>
|
AddButton(() =>
|
||||||
{
|
{
|
||||||
_player.UnitView.OnHit.Invoke(_player.Data.maxHP);
|
_player.BaseView.OnHit.Invoke(_player.UnitData.maxHP);
|
||||||
scrollRect.SetActive(false);
|
scrollRect.SetActive(false);
|
||||||
}, "Kill Player", playerGrid.gameObject);
|
}, "Kill Player", playerGrid.gameObject);
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ namespace Controller
|
|||||||
|
|
||||||
hexGrid.SpawnField();
|
hexGrid.SpawnField();
|
||||||
unitFactory.Player.OnShoot += wariorFactory.Spawn;
|
unitFactory.Player.OnShoot += wariorFactory.Spawn;
|
||||||
unitFactory.Player.wariorInfo = data.UnitData.Warior[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ namespace Data
|
|||||||
public class UnitData : ScriptableObject
|
public class UnitData : ScriptableObject
|
||||||
{
|
{
|
||||||
[SerializeField] private List<UnitInfo> _units;
|
[SerializeField] private List<UnitInfo> _units;
|
||||||
[SerializeField] private List<WariorInfo> _warior;
|
|
||||||
[SerializeField] private BarCanvas playerBarCanvas;
|
[SerializeField] private BarCanvas playerBarCanvas;
|
||||||
[SerializeField] private BarCanvas botBarCanvas;
|
[SerializeField] private BarCanvas botBarCanvas;
|
||||||
[SerializeField] private GameObject attackAimCanvas;
|
[SerializeField] private GameObject attackAimCanvas;
|
||||||
@ -23,8 +22,6 @@ namespace Data
|
|||||||
|
|
||||||
public List<UnitInfo> Units => _units;
|
public List<UnitInfo> Units => _units;
|
||||||
|
|
||||||
public List<WariorInfo> Warior => _warior;
|
|
||||||
|
|
||||||
public BarCanvas PlayerBarCanvas => playerBarCanvas;
|
public BarCanvas PlayerBarCanvas => playerBarCanvas;
|
||||||
|
|
||||||
public BarCanvas BotBarCanvas => botBarCanvas;
|
public BarCanvas BotBarCanvas => botBarCanvas;
|
||||||
@ -44,15 +41,4 @@ namespace Data
|
|||||||
public int inventoryCapacity;
|
public int inventoryCapacity;
|
||||||
public Material InvisibleMaterial;
|
public Material InvisibleMaterial;
|
||||||
}
|
}
|
||||||
public partial struct WariorInfo
|
|
||||||
{
|
|
||||||
public HexCoordinates spawnPos;
|
|
||||||
public GameObject wariorPrefa;
|
|
||||||
public UnitColor color;
|
|
||||||
public int manaRegen;
|
|
||||||
public int maxMana;
|
|
||||||
public int maxHP;
|
|
||||||
public Material InvisibleMaterial;
|
|
||||||
internal int inventoryCapacity;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -10,14 +10,18 @@ namespace Data
|
|||||||
public class WariorsData : ScriptableObject
|
public class WariorsData : ScriptableObject
|
||||||
{
|
{
|
||||||
[SerializeField] private List<WariorInfo> _wariors;
|
[SerializeField] private List<WariorInfo> _wariors;
|
||||||
|
public List<WariorInfo> Wariors { get { return _wariors; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public partial struct WariorInfo
|
public partial struct WariorInfo
|
||||||
{
|
{
|
||||||
[SerializeField] private GameObject prefab;
|
public GameObject wariorPrefab;
|
||||||
[SerializeField] private WariorType Type;
|
[SerializeField] private WariorType Type;
|
||||||
[SerializeField, ShowIf("hasWeapon")] private Weapon _weapon;
|
[SerializeField, ShowIf("hasWeapon")] private Weapon _weapon;
|
||||||
|
public int maxHP;
|
||||||
|
public int manaRegen;
|
||||||
|
public int maxMana;
|
||||||
private bool hasWeapon => Type != WariorType.Defence;
|
private bool hasWeapon => Type != WariorType.Defence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ namespace HexFiled
|
|||||||
{
|
{
|
||||||
public static class HexManager
|
public static class HexManager
|
||||||
{
|
{
|
||||||
public static Dictionary<UnitColor, (HexCell cell, UnitBase unit)> UnitCurrentCell;
|
public static Dictionary<UnitColor, (HexCell cell,UnitBase unit)> UnitCurrentCell;
|
||||||
public static Dictionary<UnitColor, List<HexCell>> CellByColor;
|
public static Dictionary<UnitColor, List<HexCell>> CellByColor;
|
||||||
public static Dictionary<GameObject, AIBase> agents;
|
public static Dictionary<GameObject, AIBase> agents;
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ namespace Items
|
|||||||
var cell = HexManager.UnitCurrentCell[container.Unit.Color].cell.GetNeighbor(container.HexDirection);
|
var cell = HexManager.UnitCurrentCell[container.Unit.Color].cell.GetNeighbor(container.HexDirection);
|
||||||
container.OnItemUsed?.Invoke();
|
container.OnItemUsed?.Invoke();
|
||||||
|
|
||||||
container.Unit.UnitView.AnimActionDic[animName] = null;
|
container.Unit.BaseView.AnimActionDic[animName] = null;
|
||||||
|
|
||||||
container.OnItemUsed = null;
|
container.OnItemUsed = null;
|
||||||
if (cell == null)
|
if (cell == null)
|
||||||
@ -116,7 +116,7 @@ namespace Items
|
|||||||
container.Unit.Animator.SetTrigger(animName);
|
container.Unit.Animator.SetTrigger(animName);
|
||||||
container.DeAim();
|
container.DeAim();
|
||||||
container.Unit.SetCell(cell);
|
container.Unit.SetCell(cell);
|
||||||
container.Unit.UnitView.AnimActionDic[animName] += () => DoPaint(container);
|
container.Unit.BaseView.AnimActionDic[animName] += () => DoPaint(container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,11 +26,11 @@ namespace Items.ItemViews
|
|||||||
if (_item is Bonus { BonusType: BonusType.Heal } bonus)
|
if (_item is Bonus { BonusType: BonusType.Heal } bonus)
|
||||||
{
|
{
|
||||||
VFXController.Instance.PlayEffect(bonus.UsisngVFX, unit.Instance.transform);
|
VFXController.Instance.PlayEffect(bonus.UsisngVFX, unit.Instance.transform);
|
||||||
unit.UnitView.OnHit.Invoke(-bonus.Value);
|
unit.BaseView.OnHit.Invoke(-bonus.Value);
|
||||||
Despawn();
|
Despawn();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
transform.DOMove(unit.UnitView.transform.position + new Vector3(0,1,0), 0.1f).OnComplete(() =>
|
transform.DOMove(unit.BaseView.transform.position + new Vector3(0,1,0), 0.1f).OnComplete(() =>
|
||||||
{
|
{
|
||||||
ItemContainer itemContainer = new ItemContainer(Item, this, unit);
|
ItemContainer itemContainer = new ItemContainer(Item, this, unit);
|
||||||
unit.PickUpItem(itemContainer);
|
unit.PickUpItem(itemContainer);
|
||||||
|
@ -34,7 +34,7 @@ namespace Items
|
|||||||
|
|
||||||
container.AimInstance.SetActive(true);
|
container.AimInstance.SetActive(true);
|
||||||
container.AimInstance.transform.LookAt(
|
container.AimInstance.transform.LookAt(
|
||||||
new Vector3(direction.x, 0, direction.y) + container.Unit.UnitView.transform.position);
|
new Vector3(direction.x, 0, direction.y) + container.Unit.BaseView.transform.position);
|
||||||
container.Direction = direction;
|
container.Direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ namespace Chars
|
|||||||
_attackJoystick = joyView.AttackJoystick;
|
_attackJoystick = joyView.AttackJoystick;
|
||||||
_placeJoystick = joyView.PlaceJoystick;
|
_placeJoystick = joyView.PlaceJoystick;
|
||||||
_placeJoystick.gameObject.SetActive(false);
|
_placeJoystick.gameObject.SetActive(false);
|
||||||
_unitView = (UnitView) unit.UnitView;
|
_unitView = (UnitView) unit.BaseView;
|
||||||
|
|
||||||
_attackJoystick.OnTouchUp += DoAttack;
|
_attackJoystick.OnTouchUp += DoAttack;
|
||||||
_attackJoystick.OnDrug += AimCanvas;
|
_attackJoystick.OnDrug += AimCanvas;
|
||||||
|
@ -19,30 +19,30 @@ namespace Units
|
|||||||
{
|
{
|
||||||
public class Unit : UnitBase
|
public class Unit : UnitBase
|
||||||
{
|
{
|
||||||
private UnitInfo _data;
|
private UnitInfo _unitData;
|
||||||
public UnitInfo Data => _data;
|
public UnitInfo UnitData => _unitData;
|
||||||
public WariorInfo wariorInfo;
|
private WariorsData wariorData;
|
||||||
public WariorFactory wariorFactory;
|
public bool IsPlayer => _unitData.isPlayer;
|
||||||
public bool IsPlayer => _data.isPlayer;
|
|
||||||
public event Action<ItemContainer> OnItemPickUp;
|
public event Action<ItemContainer> OnItemPickUp;
|
||||||
public event Action<WariorInfo,UnitColor> OnShoot;
|
public event WariorFactory.SpawnWarior OnShoot;
|
||||||
|
private List<UnitBase> NotEnemy;
|
||||||
|
|
||||||
|
|
||||||
public Unit(UnitInfo data, Weapon weapon, HexGrid hexGrid)
|
public Unit(UnitInfo unitData, Weapon weapon, HexGrid hexGrid, Data.Data data)
|
||||||
{
|
{
|
||||||
Initialize(weapon, hexGrid);
|
Initialize(weapon, hexGrid);
|
||||||
_data = data;
|
_unitData = unitData;
|
||||||
Color = _data.color;
|
Color = _unitData.color;
|
||||||
maxHP = _data.maxHP;
|
maxHP = _unitData.maxHP;
|
||||||
maxMana = _data.maxMana;
|
maxMana = _unitData.maxMana;
|
||||||
InventoryCapacity = _data.inventoryCapacity;
|
InventoryCapacity = _unitData.inventoryCapacity;
|
||||||
|
wariorData = data.WariorsData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Retreet(HexDirection dir)
|
public override void Retreet(HexDirection dir)
|
||||||
{
|
{
|
||||||
if (!_isCapturing) return;
|
if (!_isCapturing) return;
|
||||||
var openList = _cell.GetListNeighbours().Where(x => x != null && x.Color == _data.color).ToList();
|
var openList = _cell.GetListNeighbours().Where(x => x != null && x.Color == _unitData.color).ToList();
|
||||||
if (!openList.Contains(_cell.GetNeighbor(dir)))
|
if (!openList.Contains(_cell.GetNeighbor(dir)))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -50,7 +50,7 @@ namespace Units
|
|||||||
|
|
||||||
IsBusy = false;
|
IsBusy = false;
|
||||||
IsHardToCapture = false;
|
IsHardToCapture = false;
|
||||||
UnitView.StopHardCapture();
|
BaseView.StopHardCapture();
|
||||||
Move(dir);
|
Move(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ namespace Units
|
|||||||
&& value.cell.Equals(_cell.GetNeighbor(direction)))) return;
|
&& value.cell.Equals(_cell.GetNeighbor(direction)))) return;
|
||||||
|
|
||||||
|
|
||||||
if (_cell.GetNeighbor(direction).Color == _data.color ||
|
if (_cell.GetNeighbor(direction).Color == _unitData.color ||
|
||||||
(_cell.GetNeighbor(direction).Color == _easyCaptureColor && _easyCaptureColor != UnitColor.Grey))
|
(_cell.GetNeighbor(direction).Color == _easyCaptureColor && _easyCaptureColor != UnitColor.Grey))
|
||||||
{
|
{
|
||||||
DoTransit(direction);
|
DoTransit(direction);
|
||||||
@ -85,9 +85,9 @@ namespace Units
|
|||||||
protected override void DoTransit(HexDirection direction)
|
protected override void DoTransit(HexDirection direction)
|
||||||
{
|
{
|
||||||
IsBusy = true;
|
IsBusy = true;
|
||||||
_isCapturing = _data.color != _cell.GetNeighbor(direction).Color;
|
_isCapturing = _unitData.color != _cell.GetNeighbor(direction).Color;
|
||||||
_cell = _cell.GetNeighbor(direction);
|
_cell = _cell.GetNeighbor(direction);
|
||||||
HexManager.UnitCurrentCell[_data.color] = (_cell, this);
|
HexManager.UnitCurrentCell[_unitData.color] = (_cell, this);
|
||||||
RotateUnit(new Vector2((_cell.transform.position - _instance.transform.position).normalized.x,
|
RotateUnit(new Vector2((_cell.transform.position - _instance.transform.position).normalized.x,
|
||||||
(_cell.transform.position - _instance.transform.position).normalized.z));
|
(_cell.transform.position - _instance.transform.position).normalized.z));
|
||||||
_animator.SetTrigger("Move");
|
_animator.SetTrigger("Move");
|
||||||
@ -130,13 +130,13 @@ namespace Units
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UnitView.RegenMana();
|
BaseView.RegenMana();
|
||||||
|
|
||||||
|
|
||||||
UpdateBarCanvas();
|
UpdateBarCanvas();
|
||||||
IsBusy = false;
|
IsBusy = false;
|
||||||
IsHardToCapture = false;
|
IsHardToCapture = false;
|
||||||
_cell.PaintHex(_data.color);
|
_cell.PaintHex(_unitData.color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Spawn(HexCoordinates hexCoordinates, HexCell spawnCell = null)
|
public override void Spawn(HexCoordinates hexCoordinates, HexCell spawnCell = null)
|
||||||
@ -145,28 +145,28 @@ namespace Units
|
|||||||
{
|
{
|
||||||
_cell = spawnCell != null ? spawnCell : _hexGrid.GetCellFromCoord(hexCoordinates);
|
_cell = spawnCell != null ? spawnCell : _hexGrid.GetCellFromCoord(hexCoordinates);
|
||||||
IsVisible = true;
|
IsVisible = true;
|
||||||
_cell.PaintHex(_data.color, true);
|
_cell.PaintHex(_unitData.color, true);
|
||||||
_cell.GetListNeighbours().ForEach(x => { x?.PaintHex(Color, true); });
|
_cell.GetListNeighbours().ForEach(x => { x?.PaintHex(Color, true); });
|
||||||
_inventory = new List<ItemContainer>();
|
_inventory = new List<ItemContainer>();
|
||||||
_inventoryDefence = new List<ItemContainer>();
|
_inventoryDefence = new List<ItemContainer>();
|
||||||
|
|
||||||
HexManager.UnitCurrentCell.Add(_data.color, (_cell, this));
|
HexManager.UnitCurrentCell.Add(_unitData.color,(_cell ,this));
|
||||||
|
|
||||||
_instance = Object.Instantiate(_data.unitPrefa, _cell.transform.parent);
|
_instance = Object.Instantiate(_unitData.unitPrefa, _cell.transform.parent);
|
||||||
|
|
||||||
_instance.transform.localPosition = _cell.transform.localPosition;
|
_instance.transform.localPosition = _cell.transform.localPosition;
|
||||||
|
|
||||||
IsAlive = true;
|
IsAlive = true;
|
||||||
_animator = _instance.GetComponent<Animator>();
|
_animator = _instance.GetComponent<Animator>();
|
||||||
UnitView = _instance.AddComponent<UnitView>();
|
BaseView = _instance.AddComponent<UnitView>();
|
||||||
|
|
||||||
|
|
||||||
UnitView.SetUp(_weapon, RegenMana, _data.manaRegen, CaptureHex,
|
BaseView.SetUp(_weapon, RegenMana, _unitData.manaRegen, CaptureHex,
|
||||||
this, _hexGrid.HardCaptureTime);
|
this, _hexGrid.HardCaptureTime);
|
||||||
SetAnimLength();
|
SetAnimLength();
|
||||||
MusicController.Instance.AddAudioSource(_instance);
|
MusicController.Instance.AddAudioSource(_instance);
|
||||||
_mana = _data.maxMana;
|
_mana = _unitData.maxMana;
|
||||||
_hp = _data.maxHP;
|
_hp = _unitData.maxHP;
|
||||||
SetUpActions();
|
SetUpActions();
|
||||||
_weapon.SetModifiedDamage(0);
|
_weapon.SetModifiedDamage(0);
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ namespace Units
|
|||||||
|
|
||||||
protected override void RegenMana()
|
protected override void RegenMana()
|
||||||
{
|
{
|
||||||
_mana += _data.manaRegen;
|
_mana += _unitData.manaRegen;
|
||||||
UpdateBarCanvas();
|
UpdateBarCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,14 +186,14 @@ namespace Units
|
|||||||
switch (item.Type)
|
switch (item.Type)
|
||||||
{
|
{
|
||||||
case ItemType.ATTACK:
|
case ItemType.ATTACK:
|
||||||
if (_inventory.Count < _data.inventoryCapacity / 2)
|
if (_inventory.Count < _unitData.inventoryCapacity / 2)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ItemType.DEFENCE:
|
case ItemType.DEFENCE:
|
||||||
if (_inventoryDefence.Count < _data.inventoryCapacity / 2)
|
if (_inventoryDefence.Count < _unitData.inventoryCapacity / 2)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ namespace Units
|
|||||||
switch (item.Item.Type)
|
switch (item.Item.Type)
|
||||||
{
|
{
|
||||||
case ItemType.ATTACK:
|
case ItemType.ATTACK:
|
||||||
if (_inventory.Count < _data.inventoryCapacity / 2)
|
if (_inventory.Count < _unitData.inventoryCapacity / 2)
|
||||||
{
|
{
|
||||||
_inventory.Add(item);
|
_inventory.Add(item);
|
||||||
_cell.Item = null;
|
_cell.Item = null;
|
||||||
@ -219,7 +219,7 @@ namespace Units
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case ItemType.DEFENCE:
|
case ItemType.DEFENCE:
|
||||||
if (_inventoryDefence.Count < _data.inventoryCapacity / 2)
|
if (_inventoryDefence.Count < _unitData.inventoryCapacity / 2)
|
||||||
{
|
{
|
||||||
_inventoryDefence.Add(item);
|
_inventoryDefence.Add(item);
|
||||||
_cell.Item = null;
|
_cell.Item = null;
|
||||||
@ -238,31 +238,31 @@ namespace Units
|
|||||||
Aim(_direction);
|
Aim(_direction);
|
||||||
|
|
||||||
_weapon.Fire(_instance.transform, _direction, this);
|
_weapon.Fire(_instance.transform, _direction, this);
|
||||||
if(IsPlayer)
|
if (IsPlayer)
|
||||||
OnShoot.Invoke(wariorInfo,_data.color);
|
OnShoot.Invoke(wariorData.Wariors[0], _unitData.color);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateBarCanvas()
|
protected override void UpdateBarCanvas()
|
||||||
{
|
{
|
||||||
if (_hp > _data.maxHP)
|
if (_hp > _unitData.maxHP)
|
||||||
_hp = _data.maxHP;
|
_hp = _unitData.maxHP;
|
||||||
if (_mana > _data.maxMana)
|
if (_mana > _unitData.maxMana)
|
||||||
_mana = _data.maxMana;
|
_mana = _unitData.maxMana;
|
||||||
|
|
||||||
float hp = _hp;
|
float hp = _hp;
|
||||||
float mana = _mana;
|
float mana = _mana;
|
||||||
float maxHp = _data.maxHP;
|
float maxHp = _unitData.maxHP;
|
||||||
float maxMana = _data.maxMana;
|
float maxMana = _unitData.maxMana;
|
||||||
BarCanvas.ManaBar.DOFillAmount(mana / maxMana, 0.5f).SetEase(Ease.InQuad);
|
BarCanvas.ManaBar.DOFillAmount(mana / maxMana, 0.5f).SetEase(Ease.InQuad);
|
||||||
BarCanvas.HealthBar.DOFillAmount(hp / maxHp, 0.5f).SetEase(Ease.InQuad);
|
BarCanvas.HealthBar.DOFillAmount(hp / maxHp, 0.5f).SetEase(Ease.InQuad);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Death()
|
public override void Death()
|
||||||
{
|
{
|
||||||
UnitView.OnStep -= MoveEnd;
|
BaseView.OnStep -= MoveEnd;
|
||||||
UnitView.OnAttackEnd -= AttackEnd;
|
BaseView.OnAttackEnd -= AttackEnd;
|
||||||
UnitView.OnAttack -= Attacking;
|
BaseView.OnAttack -= Attacking;
|
||||||
UnitView.OnHit -= Damage;
|
BaseView.OnHit -= Damage;
|
||||||
IsAlive = false;
|
IsAlive = false;
|
||||||
IsBusy = true;
|
IsBusy = true;
|
||||||
HexManager.UnitCurrentCell.Remove(Color);
|
HexManager.UnitCurrentCell.Remove(Color);
|
||||||
@ -285,7 +285,7 @@ namespace Units
|
|||||||
|
|
||||||
public override void StartAttack()
|
public override void StartAttack()
|
||||||
{
|
{
|
||||||
if (IsBusy || !UnitView.Shoot()) return;
|
if (IsBusy || !BaseView.Shoot()) return;
|
||||||
|
|
||||||
IsBusy = true;
|
IsBusy = true;
|
||||||
if (_direction.Equals(Vector2.zero))
|
if (_direction.Equals(Vector2.zero))
|
||||||
@ -293,7 +293,7 @@ namespace Units
|
|||||||
var enemy = AIManager.GetNearestUnit(_weapon.disnatce, this);
|
var enemy = AIManager.GetNearestUnit(_weapon.disnatce, this);
|
||||||
if (enemy == null)
|
if (enemy == null)
|
||||||
_direction =
|
_direction =
|
||||||
new Vector2(UnitView.transform.forward.x, UnitView.transform.forward.z);
|
new Vector2(BaseView.transform.forward.x, BaseView.transform.forward.z);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var dir = DirectionHelper.DirectionTo(_instance.transform.position,
|
var dir = DirectionHelper.DirectionTo(_instance.transform.position,
|
||||||
@ -310,12 +310,12 @@ namespace Units
|
|||||||
{
|
{
|
||||||
if (_cell.GetNeighbor(direction).Color != Color)
|
if (_cell.GetNeighbor(direction).Color != Color)
|
||||||
{
|
{
|
||||||
UnitView.AimCanvas.SetActive(false);
|
BaseView.AimCanvas.SetActive(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cell = _cell.GetNeighbor(direction);
|
var cell = _cell.GetNeighbor(direction);
|
||||||
UnitView.AimCanvas.transform.LookAt(cell.transform);
|
BaseView.AimCanvas.transform.LookAt(cell.transform);
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,9 +326,9 @@ namespace Units
|
|||||||
Death();
|
Death();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_hp - dmg > _data.maxHP)
|
if (_hp - dmg > _unitData.maxHP)
|
||||||
{
|
{
|
||||||
_hp = _data.maxHP;
|
_hp = _unitData.maxHP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_defenceBonus > 0)
|
if (_defenceBonus > 0)
|
||||||
|
@ -57,10 +57,10 @@ namespace Units
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public BarCanvas BarCanvas => UnitView.BarCanvas;
|
public BarCanvas BarCanvas => BaseView.BarCanvas;
|
||||||
public GameObject Instance => _instance;
|
public GameObject Instance => _instance;
|
||||||
public int Mana => _mana;
|
public int Mana => _mana;
|
||||||
public ViewBase UnitView { get; protected set; }
|
public ViewBase BaseView { get; protected set; }
|
||||||
|
|
||||||
public int Hp => _hp;
|
public int Hp => _hp;
|
||||||
public List<ItemContainer> Inventory => _inventory;
|
public List<ItemContainer> Inventory => _inventory;
|
||||||
@ -101,7 +101,7 @@ namespace Units
|
|||||||
case BonusType.Heal:
|
case BonusType.Heal:
|
||||||
break;
|
break;
|
||||||
case BonusType.Magnet:
|
case BonusType.Magnet:
|
||||||
var col = UnitView.gameObject.GetComponent<CapsuleCollider>();
|
var col = BaseView.gameObject.GetComponent<CapsuleCollider>();
|
||||||
var defRadius = col.radius;
|
var defRadius = col.radius;
|
||||||
col.radius = value * HexGrid.HexDistance;
|
col.radius = value * HexGrid.HexDistance;
|
||||||
TimerHelper.Instance.StartTimer(() => col.radius = defRadius, duration);
|
TimerHelper.Instance.StartTimer(() => col.radius = defRadius, duration);
|
||||||
@ -112,11 +112,11 @@ namespace Units
|
|||||||
break;
|
break;
|
||||||
case BonusType.Invisible:
|
case BonusType.Invisible:
|
||||||
IsVisible = false;
|
IsVisible = false;
|
||||||
UnitView.SetInvisible(IsVisible);
|
BaseView.SetInvisible(IsVisible);
|
||||||
TimerHelper.Instance.StartTimer(() =>
|
TimerHelper.Instance.StartTimer(() =>
|
||||||
{
|
{
|
||||||
IsVisible = true;
|
IsVisible = true;
|
||||||
UnitView.SetInvisible(IsVisible);
|
BaseView.SetInvisible(IsVisible);
|
||||||
}, duration);
|
}, duration);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -209,7 +209,7 @@ namespace Units
|
|||||||
|
|
||||||
if (IsHardToCapture)
|
if (IsHardToCapture)
|
||||||
{
|
{
|
||||||
UnitView.HardCaptureHex(_cell);
|
BaseView.HardCaptureHex(_cell);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -227,10 +227,10 @@ namespace Units
|
|||||||
|
|
||||||
protected void SetUpActions()
|
protected void SetUpActions()
|
||||||
{
|
{
|
||||||
UnitView.OnStep += MoveEnd;
|
BaseView.OnStep += MoveEnd;
|
||||||
UnitView.OnAttackEnd += AttackEnd;
|
BaseView.OnAttackEnd += AttackEnd;
|
||||||
UnitView.OnAttack += Attacking;
|
BaseView.OnAttack += Attacking;
|
||||||
UnitView.OnHit += Damage;
|
BaseView.OnHit += Damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void UpdateBarCanvas();
|
protected abstract void UpdateBarCanvas();
|
||||||
@ -242,7 +242,7 @@ namespace Units
|
|||||||
|
|
||||||
public void RotateUnit(Vector2 direction)
|
public void RotateUnit(Vector2 direction)
|
||||||
{
|
{
|
||||||
UnitView.transform.DOLookAt(new Vector3(direction.x, 0, direction.y) + UnitView.transform.position,
|
BaseView.transform.DOLookAt(new Vector3(direction.x, 0, direction.y) + BaseView.transform.position,
|
||||||
0.1f).onUpdate += () => BarCanvas.transform.LookAt(
|
0.1f).onUpdate += () => BarCanvas.transform.LookAt(
|
||||||
BarCanvas.transform.position + _camera.transform.rotation * Vector3.back,
|
BarCanvas.transform.position + _camera.transform.rotation * Vector3.back,
|
||||||
_camera.transform.rotation * Vector3.up);
|
_camera.transform.rotation * Vector3.up);
|
||||||
@ -250,8 +250,8 @@ namespace Units
|
|||||||
|
|
||||||
public void Aim(Vector2 direction)
|
public void Aim(Vector2 direction)
|
||||||
{
|
{
|
||||||
UnitView.AimCanvas.transform.LookAt(
|
BaseView.AimCanvas.transform.LookAt(
|
||||||
new Vector3(direction.x, 0, direction.y) + UnitView.transform.position);
|
new Vector3(direction.x, 0, direction.y) + BaseView.transform.position);
|
||||||
_direction = direction;
|
_direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ namespace Chars
|
|||||||
|
|
||||||
if (unitInfo.isPlayer)
|
if (unitInfo.isPlayer)
|
||||||
{
|
{
|
||||||
var player = new Unit(unitInfo, _chosenWeapon, _hexGrid);
|
var player = new Unit(unitInfo, _chosenWeapon, _hexGrid, _data);
|
||||||
PlayerControl playerControl = null;
|
PlayerControl playerControl = null;
|
||||||
|
|
||||||
CameraControl cameraControl =
|
CameraControl cameraControl =
|
||||||
@ -78,13 +78,13 @@ namespace Chars
|
|||||||
|
|
||||||
player.Spawn(spawnPos.coordinates, spawnPos);
|
player.Spawn(spawnPos.coordinates, spawnPos);
|
||||||
spawnPos.isSpawnPos = false;
|
spawnPos.isSpawnPos = false;
|
||||||
player.UnitView.SetBar(_data.UnitData.PlayerBarCanvas, _data.UnitData.AttackAimCanvas);
|
player.BaseView.SetBar(_data.UnitData.PlayerBarCanvas, _data.UnitData.AttackAimCanvas);
|
||||||
Player = player;
|
Player = player;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var enemy = new Unit(unitInfo,
|
var enemy = new Unit(unitInfo,
|
||||||
_data.WeaponsData.WeaponsList[Random.Range(0, _data.WeaponsData.WeaponsList.Count - 1)], _hexGrid);
|
_data.WeaponsData.WeaponsList[Random.Range(0, _data.WeaponsData.WeaponsList.Count - 1)], _hexGrid, _data);
|
||||||
|
|
||||||
if (unitInfo.isAI)
|
if (unitInfo.isAI)
|
||||||
{
|
{
|
||||||
@ -96,7 +96,7 @@ namespace Chars
|
|||||||
enemy.Spawn(spawnPos.coordinates, spawnPos);
|
enemy.Spawn(spawnPos.coordinates, spawnPos);
|
||||||
spawnPos.isSpawnPos = false;
|
spawnPos.isSpawnPos = false;
|
||||||
|
|
||||||
enemy.UnitView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas);
|
enemy.BaseView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,12 @@ namespace Units.Views
|
|||||||
|
|
||||||
protected override IEnumerator Regen()
|
protected override IEnumerator Regen()
|
||||||
{
|
{
|
||||||
if (_mana >= ((Unit)_unit).Data.maxMana)
|
if (_mana >= ((Unit)_unit).UnitData.maxMana)
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (_mana < ((Unit)_unit).Data.maxMana)
|
while (_mana < ((Unit)_unit).UnitData.maxMana)
|
||||||
{
|
{
|
||||||
yield return new WaitForSeconds(1f);
|
yield return new WaitForSeconds(1f);
|
||||||
_mana += _manaRegen;
|
_mana += _manaRegen;
|
||||||
|
@ -29,12 +29,12 @@ namespace Units.Views
|
|||||||
|
|
||||||
protected override IEnumerator Regen()
|
protected override IEnumerator Regen()
|
||||||
{
|
{
|
||||||
if (_mana >= ((Unit)_unit).Data.maxMana)
|
if (_mana >= ((Unit)_unit).UnitData.maxMana)
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (_mana < ((Unit)_unit).Data.maxMana)
|
while (_mana < ((Unit)_unit).UnitData.maxMana)
|
||||||
{
|
{
|
||||||
yield return new WaitForSeconds(1f);
|
yield return new WaitForSeconds(1f);
|
||||||
_mana += _manaRegen;
|
_mana += _manaRegen;
|
||||||
|
@ -21,99 +21,17 @@ namespace Units.Wariors.AbstractsBase
|
|||||||
{
|
{
|
||||||
Initialize(weapon, hexGrid);
|
Initialize(weapon, hexGrid);
|
||||||
_data = data;
|
_data = data;
|
||||||
_data.color = spawnerColor;
|
Color = spawnerColor;
|
||||||
Color = _data.color;
|
|
||||||
maxHP = _data.maxHP;
|
maxHP = _data.maxHP;
|
||||||
maxMana = _data.maxMana;
|
maxMana = _data.maxMana;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Retreet(HexDirection dir)
|
|
||||||
{
|
|
||||||
if (!_isCapturing) return;
|
|
||||||
var openList = _cell.GetListNeighbours().Where(x => x != null && x.Color == _data.color).ToList();
|
|
||||||
if (!openList.Contains(_cell.GetNeighbor(dir)))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
IsBusy = false;
|
|
||||||
IsHardToCapture = false;
|
|
||||||
UnitView.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 == _data.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)
|
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()
|
protected override void CaptureHex()
|
||||||
{
|
{
|
||||||
if (!_isInfiniteMana)
|
|
||||||
{
|
|
||||||
if (IsHardToCapture)
|
|
||||||
{
|
|
||||||
_mana -= _hexGrid.HexHardCaptureCost;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_mana -= _hexGrid.HexCaptureCost;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UnitView.RegenMana();
|
|
||||||
|
|
||||||
|
|
||||||
UpdateBarCanvas();
|
|
||||||
IsBusy = false;
|
|
||||||
IsHardToCapture = false;
|
|
||||||
_cell.PaintHex(_data.color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override void RegenMana()
|
protected override void RegenMana()
|
||||||
{
|
{
|
||||||
@ -121,49 +39,30 @@ namespace Units.Wariors.AbstractsBase
|
|||||||
UpdateBarCanvas();
|
UpdateBarCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanPickUpItem(Item item)
|
protected override void Attacking()
|
||||||
{
|
{
|
||||||
return false;
|
Aim(_direction);
|
||||||
|
|
||||||
|
_weapon.Fire(_instance.transform, _direction, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void PickUpItem(ItemContainer item)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void UpdateBarCanvas()
|
|
||||||
{
|
|
||||||
if (_hp > _data.maxHP)
|
|
||||||
_hp = _data.maxHP;
|
|
||||||
if (_mana > _data.maxMana)
|
|
||||||
_mana = _data.maxMana;
|
|
||||||
|
|
||||||
float hp = _hp;
|
|
||||||
float mana = _mana;
|
|
||||||
float maxHp = _data.maxHP;
|
|
||||||
float maxMana = _data.maxMana;
|
|
||||||
BarCanvas.ManaBar.DOFillAmount(mana / maxMana, 0.5f).SetEase(Ease.InQuad);
|
|
||||||
BarCanvas.HealthBar.DOFillAmount(hp / maxHp, 0.5f).SetEase(Ease.InQuad);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void StartAttack()
|
public override void StartAttack()
|
||||||
{
|
{
|
||||||
if (IsBusy || !UnitView.Shoot()) return;
|
if (IsBusy || !BaseView.Shoot()) return;
|
||||||
|
|
||||||
IsBusy = true;
|
IsBusy = true;
|
||||||
if (_direction.Equals(Vector2.zero))
|
if (_direction.Equals(Vector2.zero))
|
||||||
{
|
{
|
||||||
var enemy = AIManager.GetNearestUnit(_weapon.disnatce, this);
|
var enemy = AIManager.GetNearestUnit(_weapon.disnatce, this);
|
||||||
if (enemy == null)
|
if (enemy == null)
|
||||||
_direction =
|
_direction =
|
||||||
new Vector2(UnitView.transform.forward.x, UnitView.transform.forward.z);
|
new Vector2(BaseView.transform.forward.x, BaseView.transform.forward.z);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var dir = DirectionHelper.DirectionTo(_instance.transform.position,
|
var dir = DirectionHelper.DirectionTo(_instance.transform.position,
|
||||||
enemy.Instance.transform.position);
|
enemy.Instance.transform.position);
|
||||||
_direction = new Vector2(dir.x, dir.z);
|
_direction = new Vector2(dir.x, dir.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RotateUnit(_direction);
|
RotateUnit(_direction);
|
||||||
_animator.SetTrigger("Attack");
|
_animator.SetTrigger("Attack");
|
||||||
@ -171,7 +70,15 @@ namespace Units.Wariors.AbstractsBase
|
|||||||
|
|
||||||
public override HexCell PlaceItemAim(HexDirection direction)
|
public override HexCell PlaceItemAim(HexDirection direction)
|
||||||
{
|
{
|
||||||
return null;
|
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)
|
protected override void Damage(int dmg)
|
||||||
@ -181,9 +88,9 @@ namespace Units.Wariors.AbstractsBase
|
|||||||
Death();
|
Death();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_hp - dmg > _data.maxHP)
|
if (_hp - dmg > maxHP)
|
||||||
{
|
{
|
||||||
_hp = _data.maxHP;
|
_hp = maxHP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_defenceBonus > 0)
|
if (_defenceBonus > 0)
|
||||||
@ -194,8 +101,17 @@ namespace Units.Wariors.AbstractsBase
|
|||||||
|
|
||||||
_hp -= dmg;
|
_hp -= dmg;
|
||||||
|
|
||||||
UpdateBarCanvas();
|
UpdateBarCanvas();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override bool CanPickUpItem(Item item)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public override void PickUpItem(ItemContainer item)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
117
Assets/Scripts/Units/Wariors/AbstractsBase/Patrol.cs.bak
Normal file
117
Assets/Scripts/Units/Wariors/AbstractsBase/Patrol.cs.bak
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using AI;
|
||||||
|
using Data;
|
||||||
|
using DefaultNamespace;
|
||||||
|
using DG.Tweening;
|
||||||
|
using HexFiled;
|
||||||
|
using Items;
|
||||||
|
using UnityEngine;
|
||||||
|
using Weapons;
|
||||||
|
|
||||||
|
namespace Units.Wariors.AbstractsBase
|
||||||
|
{
|
||||||
|
public abstract class Patrol : UnitBase
|
||||||
|
{
|
||||||
|
protected WariorInfo _data;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void CaptureHex()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
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 > _unitData.maxHP)
|
||||||
|
{
|
||||||
|
_hp = _unitData.maxHP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_defenceBonus > 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_hp -= dmg;
|
||||||
|
|
||||||
|
UpdateBarCanvas();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override bool CanPickUpItem(Item item)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void PickUpItem(ItemContainer item)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 465e2f89096d0d445a3c7eed8acfd30b
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -1,4 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AI;
|
||||||
using Data;
|
using Data;
|
||||||
using DefaultNamespace;
|
using DefaultNamespace;
|
||||||
using DG.Tweening;
|
using DG.Tweening;
|
||||||
@ -13,17 +15,44 @@ namespace Units.Wariors
|
|||||||
{
|
{
|
||||||
public class Holem : Patrol
|
public class Holem : Patrol
|
||||||
{
|
{
|
||||||
public Holem(WariorInfo data, Weapon weapon, HexGrid hexGrid, UnitColor spawnerColor) : base(data, weapon,
|
public Holem(WariorInfo data, Weapon weapon, HexGrid hexGrid, UnitColor spawnerColor) : base(data, weapon, hexGrid, spawnerColor)
|
||||||
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)
|
protected override void DoTransit(HexDirection direction)
|
||||||
{
|
{
|
||||||
IsBusy = true;
|
IsBusy = true;
|
||||||
_isCapturing = _data.color != _cell.GetNeighbor(direction).Color;
|
_isCapturing = Color != _cell.GetNeighbor(direction).Color;
|
||||||
_cell = _cell.GetNeighbor(direction);
|
_cell = _cell.GetNeighbor(direction);
|
||||||
HexManager.UnitCurrentCell[_data.color] = (_cell, this);
|
HexManager.UnitCurrentCell[Color] = (_cell, this);
|
||||||
RotateUnit(new Vector2((_cell.transform.position - _instance.transform.position).normalized.x,
|
RotateUnit(new Vector2((_cell.transform.position - _instance.transform.position).normalized.x,
|
||||||
(_cell.transform.position - _instance.transform.position).normalized.z));
|
(_cell.transform.position - _instance.transform.position).normalized.z));
|
||||||
_animator.SetTrigger("Move");
|
_animator.SetTrigger("Move");
|
||||||
@ -31,32 +60,32 @@ namespace Units.Wariors
|
|||||||
_instance.transform.DOMove(_cell.transform.position, _animLength.Move);
|
_instance.transform.DOMove(_cell.transform.position, _animLength.Move);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public override void Spawn(HexCoordinates hexCoordinates, HexCell spawnCell = null)
|
public override void Spawn(HexCoordinates hexCoordinates, HexCell spawnCell = null)
|
||||||
{
|
{
|
||||||
if (!IsAlive)
|
if (!IsAlive)
|
||||||
{
|
{
|
||||||
_cell = spawnCell != null ? spawnCell : _hexGrid.GetCellFromCoord(hexCoordinates);
|
_cell = spawnCell != null ? spawnCell : _hexGrid.GetCellFromCoord(hexCoordinates);
|
||||||
IsVisible = true;
|
IsVisible = true;
|
||||||
_cell.PaintHex(_data.color, true);
|
|
||||||
_cell.GetListNeighbours().ForEach(x => { x?.PaintHex(Color, true); });
|
|
||||||
_inventory = new List<ItemContainer>();
|
_inventory = new List<ItemContainer>();
|
||||||
_inventoryDefence = new List<ItemContainer>();
|
_inventoryDefence = new List<ItemContainer>();
|
||||||
|
|
||||||
_instance = Object.Instantiate(_data.wariorPrefa, _cell.transform.parent);
|
_instance = Object.Instantiate(_data.wariorPrefab, _cell.transform.parent);
|
||||||
|
|
||||||
_instance.transform.localPosition = _cell.transform.localPosition;
|
_instance.transform.localPosition = _cell.transform.localPosition;
|
||||||
|
|
||||||
IsAlive = true;
|
IsAlive = true;
|
||||||
_animator = _instance.GetComponent<Animator>();
|
_animator = _instance.GetComponent<Animator>();
|
||||||
UnitView = _instance.AddComponent<UnitView>();
|
BaseView = _instance.AddComponent<WariorView>();
|
||||||
|
|
||||||
|
|
||||||
UnitView.SetUp(_weapon, RegenMana, _data.manaRegen, CaptureHex,
|
BaseView.SetUp(_weapon, RegenMana, _data.manaRegen, CaptureHex,
|
||||||
this, _hexGrid.HardCaptureTime);
|
this, _hexGrid.HardCaptureTime);
|
||||||
SetAnimLength();
|
SetAnimLength();
|
||||||
MusicController.Instance.AddAudioSource(_instance);
|
MusicController.Instance.AddAudioSource(_instance);
|
||||||
_mana = _data.maxMana;
|
_mana = maxMana;
|
||||||
_hp = _data.maxHP;
|
_hp = maxHP;
|
||||||
SetUpActions();
|
SetUpActions();
|
||||||
_weapon.SetModifiedDamage(0);
|
_weapon.SetModifiedDamage(0);
|
||||||
|
|
||||||
@ -65,12 +94,29 @@ namespace Units.Wariors
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
public override void Death()
|
||||||
{
|
{
|
||||||
UnitView.OnStep -= MoveEnd;
|
BaseView.OnStep -= MoveEnd;
|
||||||
UnitView.OnAttackEnd -= AttackEnd;
|
BaseView.OnAttackEnd -= AttackEnd;
|
||||||
UnitView.OnAttack -= Attacking;
|
BaseView.OnAttack -= Attacking;
|
||||||
UnitView.OnHit -= Damage;
|
BaseView.OnHit -= Damage;
|
||||||
IsAlive = false;
|
IsAlive = false;
|
||||||
IsBusy = true;
|
IsBusy = true;
|
||||||
_animator.SetTrigger("Death");
|
_animator.SetTrigger("Death");
|
||||||
@ -81,16 +127,11 @@ namespace Units.Wariors
|
|||||||
Object.Destroy(_instance);
|
Object.Destroy(_instance);
|
||||||
OnOnDeath(this);
|
OnOnDeath(this);
|
||||||
}, _animLength.Death);
|
}, _animLength.Death);
|
||||||
|
|
||||||
MusicController.Instance.AddAudioSource(vfx);
|
MusicController.Instance.AddAudioSource(vfx);
|
||||||
MusicController.Instance.PlayAudioClip(MusicController.Instance.MusicData.SfxMusic.Death, vfx);
|
MusicController.Instance.PlayAudioClip(MusicController.Instance.MusicData.SfxMusic.Death, vfx);
|
||||||
MusicController.Instance.RemoveAudioSource(_instance);
|
MusicController.Instance.RemoveAudioSource(_instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Attacking()
|
|
||||||
{
|
|
||||||
Aim(_direction);
|
|
||||||
|
|
||||||
_weapon.Fire(_instance.transform, _direction, this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
137
Assets/Scripts/Units/Wariors/Holem.cs.bak
Normal file
137
Assets/Scripts/Units/Wariors/Holem.cs.bak
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AI;
|
||||||
|
using Data;
|
||||||
|
using DefaultNamespace;
|
||||||
|
using DG.Tweening;
|
||||||
|
using HexFiled;
|
||||||
|
using Items;
|
||||||
|
using Units.Views;
|
||||||
|
using Units.Wariors.AbstractsBase;
|
||||||
|
using UnityEngine;
|
||||||
|
using Weapons;
|
||||||
|
|
||||||
|
namespace Units.Wariors
|
||||||
|
{
|
||||||
|
public class Holem : Patrol
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
7
Assets/Scripts/Units/Wariors/Holem.cs.bak.meta
Normal file
7
Assets/Scripts/Units/Wariors/Holem.cs.bak.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2f86704210acc6d428283f9fb6c23c7e
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -23,22 +23,25 @@ namespace Units.Wariors
|
|||||||
_controllers = controllers;
|
_controllers = controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public delegate UnitBase SpawnWarior(WariorInfo wariorInfo, UnitColor unitColor);
|
||||||
public void Spawn(WariorInfo wariorInfo , UnitColor unitColor)
|
public UnitBase Spawn(WariorInfo wariorInfo , UnitColor unitColor)
|
||||||
{
|
{
|
||||||
var spawnPos= HexManager.CellByColor[unitColor].Where(x => x != null).ToList()[
|
unitColor = UnitColor.Yellow;
|
||||||
Random.Range(0, HexManager.CellByColor[unitColor].Count - 1)];
|
var spawnPos =
|
||||||
|
HexManager.CellByColor[unitColor].Where(x => x != null).ToList()[
|
||||||
|
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 Holem(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);
|
||||||
patrol.OnDeath += x => { _controllers.Remove(agent); };
|
patrol.OnDeath += x => { _controllers.Remove(agent); };
|
||||||
|
|
||||||
patrol.Spawn(spawnPos.coordinates, spawnPos);
|
patrol.Spawn(spawnPos.coordinates, spawnPos);
|
||||||
spawnPos.isSpawnPos = false;
|
spawnPos.isSpawnPos = false;
|
||||||
|
|
||||||
patrol.UnitView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas);
|
patrol.BaseView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas);
|
||||||
|
return patrol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
47
Assets/Scripts/Units/Wariors/WariorFactory.cs.bak
Normal file
47
Assets/Scripts/Units/Wariors/WariorFactory.cs.bak
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using Controller;
|
||||||
|
using Data;
|
||||||
|
using DefaultNamespace.AI;
|
||||||
|
using GameUI;
|
||||||
|
using HexFiled;
|
||||||
|
using System.Linq;
|
||||||
|
using Units.Wariors.AbstractsBase;
|
||||||
|
using UnityEngine;
|
||||||
|
using Weapons;
|
||||||
|
|
||||||
|
namespace Units.Wariors
|
||||||
|
{
|
||||||
|
public class WariorFactory
|
||||||
|
{
|
||||||
|
private readonly HexGrid _hexGrid;
|
||||||
|
private readonly Controllers _controllers;
|
||||||
|
private readonly Data.Data _data;
|
||||||
|
|
||||||
|
public WariorFactory(HexGrid grid, Controllers controllers, Data.Data data)
|
||||||
|
{
|
||||||
|
_hexGrid = grid;
|
||||||
|
_data = data;
|
||||||
|
_controllers = controllers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate UnitBase SpawnWarior(WariorInfo wariorInfo, UnitColor unitColor);
|
||||||
|
public UnitBase Spawn(WariorInfo wariorInfo , UnitColor unitColor)
|
||||||
|
{
|
||||||
|
unitColor = UnitColor.Yellow;
|
||||||
|
var spawnPos =
|
||||||
|
HexManager.CellByColor[unitColor].Where(x => x != null).ToList()[
|
||||||
|
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);
|
||||||
|
|
||||||
|
AIPatrol agent = new AIPatrol (patrol);
|
||||||
|
patrol.OnSpawned += x => _controllers.Add(agent);
|
||||||
|
patrol.OnDeath += x => { _controllers.Remove(agent); };
|
||||||
|
|
||||||
|
patrol.Spawn(spawnPos.coordinates, spawnPos);
|
||||||
|
spawnPos.isSpawnPos = false;
|
||||||
|
|
||||||
|
patrol.BaseView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas);
|
||||||
|
return patrol;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
Assets/Scripts/Units/Wariors/WariorFactory.cs.bak.meta
Normal file
7
Assets/Scripts/Units/Wariors/WariorFactory.cs.bak.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1fb96c842d12c494f9e35bc9a5c93fdf
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user