57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using Framework;
|
|
using Gameplay.Area;
|
|
using Gameplay.Unit;
|
|
namespace Gameplay.Fight.Capture
|
|
{
|
|
public class CaptureInst
|
|
{
|
|
|
|
public int cellIndex;
|
|
|
|
public int checkDistance = 1;
|
|
public int maxCaptureProgress = 100;
|
|
|
|
public List<GameUnit> inAreaUnits;
|
|
|
|
public float captureProgress;
|
|
|
|
private bool _isCaptured;
|
|
|
|
public CaptureInst(int cellIndex)
|
|
{
|
|
this.cellIndex = cellIndex;
|
|
inAreaUnits = new List<GameUnit>();
|
|
captureProgress = 0f;
|
|
_isCaptured = false;
|
|
}
|
|
|
|
public void UpdateInAreaUnits(List<GameUnit> checkUnits)
|
|
{
|
|
if (_isCaptured) return;
|
|
inAreaUnits.Clear();
|
|
for (int i = 0; i < checkUnits.Count; i++)
|
|
{
|
|
var unit = checkUnits[i];
|
|
var unitCellIndex = unit.transData.cellIndex;
|
|
var distance = AreaManager.instance.GetDistance(unitCellIndex, checkDistance);
|
|
if (distance <= checkDistance)
|
|
{
|
|
inAreaUnits.Add(unit);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void LogicUpdate(float dt)
|
|
{
|
|
if (_isCaptured) return;
|
|
captureProgress += dt * inAreaUnits.Count;
|
|
if (captureProgress >= maxCaptureProgress)
|
|
{
|
|
_isCaptured = true;
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_CAPTURE_FINSIHED, this);
|
|
}
|
|
}
|
|
}
|
|
}
|