【上阵区域】修改上阵区域动态更新逻辑
parent
1b3ab7fa62
commit
ea19bb505d
|
|
@ -2,14 +2,14 @@
|
|||
using System.Collections.Generic;
|
||||
using AOT.PostProcess.BlackArea;
|
||||
using Framework;
|
||||
using Gameplay.Character;
|
||||
using Gameplay.Fight.Capture;
|
||||
using Gameplay.Level;
|
||||
using Gameplay.Unit;
|
||||
using Gameplay.Unit.Data;
|
||||
using Gameplay.Utils;
|
||||
using Gameplay.Vehicle.Impl;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Gameplay.Area.Ready
|
||||
{
|
||||
public class ReadyAreaManager
|
||||
|
|
@ -19,23 +19,27 @@ namespace Gameplay.Area.Ready
|
|||
|
||||
private EReadyAreaStatus _areaStatus;
|
||||
|
||||
private List<int> _mapReadyCellIndexs;
|
||||
public List<int> mapReadyCellIndexs => _mapReadyCellIndexs;
|
||||
|
||||
private List<int> _vehicleAroundCellIndexs;
|
||||
private int _lastVehicleCellIndex;
|
||||
private List<int> _mapSavedReadyCellIndexs;
|
||||
public List<int> mapSavedReadyCellIndexs => _mapSavedReadyCellIndexs;
|
||||
|
||||
public bool isShow { get; private set; }
|
||||
|
||||
private NormalVehicle _followVehicle { get; set; }
|
||||
public NormalVehicle followVehicle { get; set; }
|
||||
|
||||
public bool isVehicleBuffActive;
|
||||
private bool _lastVehicleBuffActive;
|
||||
public bool isVehicleBuffActive
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
private List<int> _finalReadyCellIndexs;
|
||||
|
||||
private Dictionary<int, ReadyAreaPoint> _readyAreaDict;
|
||||
private Stack<ReadyAreaPoint> _pointsStack;
|
||||
public GameObject rootObj;
|
||||
|
||||
|
||||
private bool _needUpdate;
|
||||
|
||||
public ReadyAreaManager(Map map)
|
||||
{
|
||||
rootObj = new GameObject("[ReadyArea]");
|
||||
|
|
@ -43,22 +47,40 @@ namespace Gameplay.Area.Ready
|
|||
isShow = false;
|
||||
_readyAreaDict = new Dictionary<int, ReadyAreaPoint>();
|
||||
_pointsStack = new Stack<ReadyAreaPoint>();
|
||||
_finalReadyCellIndexs = new List<int>();
|
||||
_InitReadyAreaFromLevel();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
EventManager.Instance.Register<CaptureInst>(EventManager.EventName.INFIGHT_CAPTURE_FINSIHED, _OnCaptureArea);
|
||||
EventManager.Instance.Register<GameUnit>(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, _OnCellIndexChanged);
|
||||
}
|
||||
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
EventManager.Instance.Unregister<CaptureInst>(EventManager.EventName.INFIGHT_CAPTURE_FINSIHED, _OnCaptureArea);
|
||||
EventManager.Instance.Unregister<GameUnit>(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, _OnCellIndexChanged);
|
||||
|
||||
_HideAll();
|
||||
|
||||
_pointsStack.Clear();
|
||||
|
||||
if (rootObj != null)
|
||||
{
|
||||
Object.Destroy(rootObj);
|
||||
rootObj = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void _OnCellIndexChanged(GameUnit unit)
|
||||
{
|
||||
_needUpdate = true;
|
||||
}
|
||||
|
||||
private void _InitReadyAreaFromLevel()
|
||||
{
|
||||
_mapReadyCellIndexs = new List<int>();
|
||||
_mapSavedReadyCellIndexs = new List<int>();
|
||||
var levelData = LevelManager.Instance.CurrentLevel.GetLevelData();
|
||||
var areaId = levelData.preparingRegionId;
|
||||
var area = _map.MapData.GetRegion(areaId);
|
||||
|
|
@ -70,51 +92,22 @@ namespace Gameplay.Area.Ready
|
|||
var cellIndexs = area.positions;
|
||||
foreach (var cellIndex in cellIndexs)
|
||||
{
|
||||
if (_mapReadyCellIndexs.Contains(cellIndex))
|
||||
if (_mapSavedReadyCellIndexs.Contains(cellIndex))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
_mapReadyCellIndexs.Add(cellIndex);
|
||||
_mapSavedReadyCellIndexs.Add(cellIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void _OnCaptureArea(CaptureInst inst)
|
||||
{
|
||||
if (_mapReadyCellIndexs.Contains(inst.cellIndex))
|
||||
if (_mapSavedReadyCellIndexs.Contains(inst.cellIndex))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapReadyCellIndexs.Add(inst.cellIndex);
|
||||
}
|
||||
|
||||
private void _UpdateWithVehicle()
|
||||
{
|
||||
// 需要更新载具周边区域
|
||||
if (_followVehicle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var currentVehicleCellIndex = _followVehicle.transData.cellIndex;
|
||||
if (currentVehicleCellIndex == _lastVehicleCellIndex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_lastVehicleCellIndex = currentVehicleCellIndex;
|
||||
for (int i = 0; i < _vehicleAroundCellIndexs.Count; i++)
|
||||
{
|
||||
var oldIndex = _vehicleAroundCellIndexs[i];
|
||||
if (_areaStatus == EReadyAreaStatus.Both)
|
||||
{
|
||||
if (_mapReadyCellIndexs.Contains(oldIndex))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
_SetPointHide(oldIndex);
|
||||
}
|
||||
|
||||
_GetPosFromVehicle();
|
||||
_SetPointsShow(_vehicleAroundCellIndexs);
|
||||
_mapSavedReadyCellIndexs.Add(inst.cellIndex);
|
||||
_needUpdate = true;
|
||||
}
|
||||
|
||||
private ReadyAreaPoint _GetOrCreate()
|
||||
|
|
@ -179,82 +172,64 @@ namespace Gameplay.Area.Ready
|
|||
|
||||
private void _GetPosFromVehicle()
|
||||
{
|
||||
if (_vehicleAroundCellIndexs == null)
|
||||
{
|
||||
_vehicleAroundCellIndexs = new List<int>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_vehicleAroundCellIndexs.Clear();
|
||||
}
|
||||
var totalAround = AreaManager.instance.GetCellIndexsAround(_lastVehicleCellIndex,
|
||||
_followVehicle.aroundReadyRange, false);
|
||||
var map = LevelManager.Instance.CurrentLevel.Map;
|
||||
for (int i = 0; i < totalAround.Count; i++)
|
||||
{
|
||||
var newIndex = totalAround[i];
|
||||
if (map.GetRuntimeBlockProperty(newIndex, out var runtimeBlockProperty))
|
||||
{
|
||||
if (runtimeBlockProperty.isEmptyBlock)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!runtimeBlockProperty.selectable)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (runtimeBlockProperty.banAttack)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var hasMoveUnit = AreaManager.instance.CheckContainsMoveUnit(newIndex);
|
||||
if (hasMoveUnit)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
_vehicleAroundCellIndexs.Add(newIndex);
|
||||
}
|
||||
}
|
||||
var vehicleCellIndex = followVehicle.transData.cellIndex;
|
||||
var totalAround = AreaManager.instance.GetCellIndexsAround(vehicleCellIndex,
|
||||
followVehicle.aroundReadyRange, false);
|
||||
_finalReadyCellIndexs.AddRange(totalAround);
|
||||
}
|
||||
|
||||
private void _UpdateOnlyMap()
|
||||
private void _GetPosFromMapSavedReady()
|
||||
{
|
||||
if (isVehicleBuffActive)
|
||||
_finalReadyCellIndexs.AddRange(_mapSavedReadyCellIndexs);
|
||||
}
|
||||
|
||||
private bool _CheckCanUp(int cellIndex)
|
||||
{
|
||||
if (cellIndex == -1) return false;
|
||||
if (_map.GetRuntimeBlockProperty(cellIndex, out var runtimeBlockProperty))
|
||||
{
|
||||
_UpdateWithVehicle();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_lastVehicleBuffActive != isVehicleBuffActive)
|
||||
if (runtimeBlockProperty.isEmptyBlock)
|
||||
{
|
||||
_lastVehicleBuffActive = isVehicleBuffActive;
|
||||
// 移除载具区域显示
|
||||
for (int i = 0; i < _vehicleAroundCellIndexs.Count; i++)
|
||||
{
|
||||
var oldIndex = _vehicleAroundCellIndexs[i];
|
||||
if (_mapReadyCellIndexs.Contains(oldIndex))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
_SetPointHide(oldIndex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!runtimeBlockProperty.selectable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (runtimeBlockProperty.banAttack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var hasMoveUnit = AreaManager.instance.CheckContainsMoveUnit(cellIndex);
|
||||
if (hasMoveUnit)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void _RemoveNotMatch()
|
||||
{
|
||||
for (int i = 0; i < _finalReadyCellIndexs.Count; i++)
|
||||
{
|
||||
var newIndex = _finalReadyCellIndexs[i];
|
||||
if (!_CheckCanUp(newIndex))
|
||||
{
|
||||
_finalReadyCellIndexs.RemoveAt(i--);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void LogicUpdate(float dt)
|
||||
{
|
||||
if (!isShow) return;
|
||||
switch (_areaStatus)
|
||||
|
||||
if (_needUpdate)
|
||||
{
|
||||
case EReadyAreaStatus.FromMap:
|
||||
_UpdateOnlyMap();
|
||||
break;
|
||||
case EReadyAreaStatus.Both:
|
||||
case EReadyAreaStatus.AroundVehicle:
|
||||
_UpdateWithVehicle();
|
||||
break;
|
||||
_UpdateArea();
|
||||
_needUpdate = false;
|
||||
}
|
||||
|
||||
_AutoLightUpReadyArea();
|
||||
|
|
@ -271,85 +246,23 @@ namespace Gameplay.Area.Ready
|
|||
|
||||
private void _AutoLightUpReadyArea()
|
||||
{
|
||||
switch (_areaStatus)
|
||||
{
|
||||
case EReadyAreaStatus.FromMap:
|
||||
_LightUpList(_mapReadyCellIndexs);
|
||||
if (isVehicleBuffActive)
|
||||
{
|
||||
_LightUpList(_vehicleAroundCellIndexs);
|
||||
}
|
||||
break;
|
||||
case EReadyAreaStatus.AroundVehicle:
|
||||
if (_followVehicle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_LightUpList(_vehicleAroundCellIndexs);
|
||||
break;
|
||||
case EReadyAreaStatus.Both:
|
||||
_LightUpList(_mapReadyCellIndexs);
|
||||
if (_followVehicle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_LightUpList(_vehicleAroundCellIndexs);
|
||||
break;
|
||||
}
|
||||
_LightUpList(_finalReadyCellIndexs);
|
||||
}
|
||||
|
||||
public bool CheckIsInReadyArea(int cellIndex)
|
||||
{
|
||||
switch (_areaStatus)
|
||||
{
|
||||
case EReadyAreaStatus.FromMap:
|
||||
if (_mapReadyCellIndexs.Contains(cellIndex))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (isVehicleBuffActive)
|
||||
{
|
||||
if (_vehicleAroundCellIndexs.Contains(cellIndex))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EReadyAreaStatus.AroundVehicle:
|
||||
if (_followVehicle == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_vehicleAroundCellIndexs.Contains(cellIndex))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case EReadyAreaStatus.Both:
|
||||
if (_mapReadyCellIndexs.Contains(cellIndex))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (_followVehicle == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_vehicleAroundCellIndexs.Contains(cellIndex))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
return _finalReadyCellIndexs.Contains(cellIndex);
|
||||
}
|
||||
|
||||
public void ShowReadyArea(EReadyAreaStatus showStatus = EReadyAreaStatus.FromMap, GameUnit unit = null)
|
||||
public void ShowReadyArea(EReadyAreaStatus showStatus = EReadyAreaStatus.FromMap,
|
||||
GameUnit unit = null)
|
||||
{
|
||||
if (isShow)
|
||||
{
|
||||
if (_areaStatus == showStatus)
|
||||
{
|
||||
// 重复的调用
|
||||
_needUpdate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -359,40 +272,46 @@ namespace Gameplay.Area.Ready
|
|||
}
|
||||
isShow = true;
|
||||
_areaStatus = showStatus;
|
||||
switch (_areaStatus)
|
||||
{
|
||||
case EReadyAreaStatus.FromMap:
|
||||
_SetPointsShow(_mapReadyCellIndexs);
|
||||
if (isVehicleBuffActive)
|
||||
{
|
||||
_lastVehicleBuffActive = true;
|
||||
_GetCurrentVehicle();
|
||||
_SetPointsShow(_vehicleAroundCellIndexs);
|
||||
}
|
||||
_lastVehicleBuffActive = false;
|
||||
break;
|
||||
case EReadyAreaStatus.AroundVehicle:
|
||||
_SetCurrentVehicle(unit);
|
||||
_GetCurrentVehicle();
|
||||
_SetPointsShow(_vehicleAroundCellIndexs);
|
||||
break;
|
||||
case EReadyAreaStatus.Both:
|
||||
_SetPointsShow(_mapReadyCellIndexs);
|
||||
_SetCurrentVehicle(unit);
|
||||
_GetCurrentVehicle();
|
||||
_SetPointsShow(_vehicleAroundCellIndexs);
|
||||
break;
|
||||
}
|
||||
_SetCurrentVehicle(unit);
|
||||
_UpdateArea();
|
||||
_SetPointsShow(_finalReadyCellIndexs);
|
||||
}
|
||||
|
||||
private void _GetCurrentVehicle()
|
||||
private void _UpdateArea()
|
||||
{
|
||||
_lastVehicleCellIndex = _followVehicle.transData.cellIndex;
|
||||
_GetPosFromVehicle();
|
||||
_finalReadyCellIndexs.Clear();
|
||||
if (!LevelManager.Instance.CurrentLevel.isInBattle)
|
||||
{
|
||||
// 不在战斗中,直接显示地图上的准备区域
|
||||
_GetPosFromMapSavedReady();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (_areaStatus)
|
||||
{
|
||||
case EReadyAreaStatus.Both:
|
||||
_GetPosFromVehicle();
|
||||
_GetPosFromMapSavedReady();
|
||||
break;
|
||||
case EReadyAreaStatus.AroundVehicle:
|
||||
_GetPosFromVehicle();
|
||||
break;
|
||||
case EReadyAreaStatus.FromMap:
|
||||
_GetPosFromMapSavedReady();
|
||||
if (isVehicleBuffActive)
|
||||
{
|
||||
_GetPosFromVehicle();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
_RemoveNotMatch();
|
||||
}
|
||||
|
||||
|
||||
private void _SetCurrentVehicle(GameUnit downUnit)
|
||||
{
|
||||
if (downUnit == null) return;
|
||||
if (downUnit.gameunitType != EGameUnitType.Character)
|
||||
{
|
||||
throw new Exception("不是角色1");
|
||||
|
|
@ -402,8 +321,7 @@ namespace Gameplay.Area.Ready
|
|||
{
|
||||
throw new Exception("不是角色2");
|
||||
}
|
||||
_followVehicle = character.runtimeData.belongVehicle;
|
||||
_lastVehicleCellIndex = -1;
|
||||
followVehicle = character.runtimeData.belongVehicle;
|
||||
}
|
||||
|
||||
public void HideReadyArea()
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ namespace Gameplay.Area.Ready
|
|||
noticeObj.SetActive(true);
|
||||
}
|
||||
var worldPos = AreaManager.instance.GetCellPosByIndex(cellIndex);
|
||||
worldPos.y = 0.1f;
|
||||
noticeObj.transform.position = worldPos;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ namespace Gameplay.Buff
|
|||
|
||||
// 修改上阵区域
|
||||
AreaManager.instance.readyAreaManager.isVehicleBuffActive = true;
|
||||
AreaManager.instance.readyAreaManager.followVehicle = _vehicle;
|
||||
|
||||
EventManager.Instance.Register<GameUnit>(EventManager.EventName.INFIGHT_UNIT_READY, _OnUnitEnterBattle);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class ConditionCombatLeastOccupy : ICondition
|
|||
|
||||
int target = (int)args[0];
|
||||
|
||||
return AreaManager.instance.readyAreaManager.mapReadyCellIndexs.Count > target;
|
||||
return AreaManager.instance.readyAreaManager.mapSavedReadyCellIndexs.Count > target;
|
||||
}
|
||||
|
||||
public string[] GetArgLocalizations(List<float> args)
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ namespace Gameplay.PostProcess.BlackArea
|
|||
public void AutoLightUpReadyArea()
|
||||
{
|
||||
if (!enableBlackArea) return;
|
||||
var readyArea = AreaManager.instance.readyAreaManager.mapReadyCellIndexs;
|
||||
var readyArea = AreaManager.instance.readyAreaManager.mapSavedReadyCellIndexs;
|
||||
for (int i = 0; i < readyArea.Count; i++)
|
||||
{
|
||||
LightUpCell(readyArea[i], 0.1f);
|
||||
|
|
|
|||
Loading…
Reference in New Issue