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

View File

@ -1,8 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CamControl;
using Controller;
using Data;
using DefaultNamespace;
using DefaultNamespace.AI;
using GameUI;
using HexFiled;
@ -35,6 +37,7 @@ namespace Chars
public void SpawnList(List<UnitInfo> units)
{
units.ForEach(x => Spawn(x));
_uiController.CheatMenu.SetPlayerNData(_data);
}
public void Spawn(UnitInfo unitInfo, HexCell spawnHex = null)
@ -66,16 +69,16 @@ namespace Chars
_uiController.PlayerInventoryView);
_controllers.Add(playerControl);
};
player.OnSpawned += unit => _uiController.CheatMenu.SetPlayerNData((Unit)unit, _data);
player.OnDeath += unit1 => _controllers.Remove(playerControl);
player.OnDeath += u => playerControl.Dispose();
player.OnSpawned += unit => cameraControl.InitCameraControl(unit.Instance);
player.OnDeath += unit => _uiController.CheatMenu.OnPlayerDeath();
player.OnDeath += p => _uiController.AdsMob.ShowCanvas(unitInfo, this);
player.Spawn(spawnPos.coordinates, spawnPos);
spawnPos.isSpawnPos = false;
player.UnitView.SetBar(_data.UnitData.PlayerBarCanvas, _data.UnitData.AttackAimCanvas);
@ -86,6 +89,9 @@ namespace Chars
var enemy = new Unit(unitInfo,
_data.WeaponsData.WeaponsList[Random.Range(0, _data.WeaponsData.WeaponsList.Count - 1)], _hexGrid);
enemy.OnDeath += unit => RandomSpawn(unitInfo);
if (unitInfo.isAI)
{
AIAgent agent = new AIAgent(enemy);
@ -93,11 +99,30 @@ namespace Chars
enemy.OnDeath += x => { _controllers.Remove(agent); };
}
enemy.OnDeath += x => _uiController.CheatMenu.OnEnemyDeath();
enemy.Spawn(spawnPos.coordinates, spawnPos);
spawnPos.isSpawnPos = false;
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);
}
}
}