84 lines
2.5 KiB
C#
84 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using Framework;
|
|
using Gameplay.Area;
|
|
using Gameplay.Unit;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
using Constants = Framework.Constants;
|
|
namespace Gameplay.Fight.Capture
|
|
{
|
|
public class CaptureInst
|
|
{
|
|
|
|
public int cellIndex;
|
|
|
|
public int checkDistance = 1;
|
|
public int maxCaptureProgress = 10;
|
|
|
|
public List<GameUnit> inAreaUnits;
|
|
|
|
public float captureProgress;
|
|
|
|
public bool isCaptured { get; private set; }
|
|
|
|
private GameObject _displayObj;
|
|
|
|
public CaptureInst(int cellIndex, int captureValue)
|
|
{
|
|
maxCaptureProgress = captureValue;
|
|
this.cellIndex = cellIndex;
|
|
inAreaUnits = new List<GameUnit>();
|
|
captureProgress = 0f;
|
|
isCaptured = false;
|
|
var sampleObj = AssetManager.Instance.GetPreLoadResult<GameObject>(Constants.CAPTURE_POINT_PATH);
|
|
_displayObj = Object.Instantiate(sampleObj);
|
|
var worldPos = AreaManager.instance.GetCellPosByIndex(cellIndex);
|
|
_displayObj.transform.position = worldPos;
|
|
}
|
|
|
|
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, cellIndex);
|
|
if (distance <= checkDistance)
|
|
{
|
|
inAreaUnits.Add(unit);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void LogicUpdate(float dt)
|
|
{
|
|
if (isCaptured) return;
|
|
if (inAreaUnits.Count > 0)
|
|
{
|
|
captureProgress += dt * inAreaUnits.Count;
|
|
if (captureProgress >= maxCaptureProgress)
|
|
{
|
|
isCaptured = true;
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_CAPTURE_FINSIHED, this);
|
|
}
|
|
else
|
|
{
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_CAPTURE_PROGRESS, this);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_displayObj != null)
|
|
{
|
|
_displayObj.Destroy();
|
|
_displayObj = null;
|
|
}
|
|
}
|
|
}
|
|
}
|