added enemy random spawn, added kill unit un cheat menu

This commit is contained in:
dushes 2022-03-15 16:31:57 +03:00
parent b1e00327d8
commit abaf11d237
2 changed files with 49 additions and 11 deletions

View File

@ -20,10 +20,10 @@ public class CheatMenu : MonoBehaviour
private GameObject _itemsPrefab; private GameObject _itemsPrefab;
private List<GameObject> _buttons; private List<GameObject> _buttons;
public void SetPlayerNData(Unit player, Data.Data data) public void SetPlayerNData(Data.Data data)
{ {
_buttons = new List<GameObject>(); _buttons = new List<GameObject>();
_player = player; _player = (Unit)(HexManager.UnitCurrentCell.FirstOrDefault(unit => ((Unit)unit.Value.unit).IsPlayer).Value.unit);
_itemsPrefab = new GameObject("CheatedItems"); _itemsPrefab = new GameObject("CheatedItems");
showButton.onClick.AddListener(() => scrollRect.SetActive(!scrollRect.activeSelf)); showButton.onClick.AddListener(() => scrollRect.SetActive(!scrollRect.activeSelf));
@ -56,11 +56,18 @@ public class CheatMenu : MonoBehaviour
_buttons.Add(playerGridGO); _buttons.Add(playerGridGO);
var playerGrid = playerGridGO.GetComponentInChildren<GridLayoutGroup>(); var playerGrid = playerGridGO.GetComponentInChildren<GridLayoutGroup>();
playerGridGO.GetComponentInChildren<TMP_Text>().text = "Player"; playerGridGO.GetComponentInChildren<TMP_Text>().text = "Player";
for (var i = 0; i < HexManager.UnitCurrentCell.Count; i++)
{
var unit = HexManager.UnitCurrentCell.ElementAt(i).Value.unit;
AddButton(() => AddButton(() =>
{ {
_player.UnitView.OnHit.Invoke(_player.Data.maxHP); unit.UnitView.OnHit.Invoke(unit.maxHP);
scrollRect.SetActive(false); scrollRect.SetActive(false);
}, "Kill Player", playerGrid.gameObject); }, $"Kill {unit.Color} unit", playerGrid.gameObject);
}
_buttons.Add(AddButton(() => scrollRect.SetActive(false), "CLOSE", grid).gameObject); _buttons.Add(AddButton(() => scrollRect.SetActive(false), "CLOSE", grid).gameObject);
} }
@ -79,4 +86,10 @@ public class CheatMenu : MonoBehaviour
scrollRect.SetActive(false); scrollRect.SetActive(false);
_buttons.ForEach(Destroy); _buttons.ForEach(Destroy);
} }
public void OnEnemyDeath()
{
_buttons.ForEach(Destroy);
AddAllButtons();
}
} }

View File

@ -1,8 +1,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using CamControl; using CamControl;
using Controller; using Controller;
using Data; using Data;
using DefaultNamespace;
using DefaultNamespace.AI; using DefaultNamespace.AI;
using GameUI; using GameUI;
using HexFiled; using HexFiled;
@ -35,6 +37,7 @@ namespace Chars
public void SpawnList(List<UnitInfo> units) public void SpawnList(List<UnitInfo> units)
{ {
units.ForEach(x => Spawn(x)); units.ForEach(x => Spawn(x));
_uiController.CheatMenu.SetPlayerNData(_data);
} }
public void Spawn(UnitInfo unitInfo, HexCell spawnHex = null) public void Spawn(UnitInfo unitInfo, HexCell spawnHex = null)
@ -68,7 +71,7 @@ namespace Chars
}; };
player.OnSpawned += unit => _uiController.CheatMenu.SetPlayerNData((Unit)unit, _data);
player.OnDeath += unit1 => _controllers.Remove(playerControl); player.OnDeath += unit1 => _controllers.Remove(playerControl);
player.OnDeath += u => playerControl.Dispose(); player.OnDeath += u => playerControl.Dispose();
player.OnSpawned += unit => cameraControl.InitCameraControl(unit.Instance); player.OnSpawned += unit => cameraControl.InitCameraControl(unit.Instance);
@ -86,6 +89,9 @@ namespace Chars
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);
enemy.OnDeath += unit => RandomSpawn(unitInfo);
if (unitInfo.isAI) if (unitInfo.isAI)
{ {
AIAgent agent = new AIAgent(enemy); AIAgent agent = new AIAgent(enemy);
@ -93,11 +99,30 @@ namespace Chars
enemy.OnDeath += x => { _controllers.Remove(agent); }; enemy.OnDeath += x => { _controllers.Remove(agent); };
} }
enemy.OnDeath += x => _uiController.CheatMenu.OnEnemyDeath();
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.UnitView.SetBar(_data.UnitData.BotBarCanvas, _data.UnitData.AttackAimCanvas);
} }
} }
private void RandomSpawn(UnitInfo info)
{
TimerHelper.Instance.StartTimer(() =>
{
var cellToSpawn = HexManager.CellByColor[UnitColor.Grey].Where(cell => cell != null &&
cell.GetListNeighbours().TrueForAll(neighbour => neighbour == null || neighbour.Color == UnitColor.Grey)).ToList();
if (cellToSpawn.Count == 0)
{
RandomSpawn(info);
return;
}
Spawn(info, cellToSpawn[Random.Range(0, cellToSpawn.Count - 1)]);
_uiController.CheatMenu.OnEnemyDeath();
}, 1f);
}
} }
} }