From ea19bb505d7df0cac6f221292975891e9be11a9d Mon Sep 17 00:00:00 2001 From: liutao <821580467@qq.com> Date: Wed, 16 Oct 2024 14:16:43 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=B8=8A=E9=98=B5=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E3=80=91=E4=BF=AE=E6=94=B9=E4=B8=8A=E9=98=B5=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Gameplay/Area/Ready/ReadyAreaManager.cs | 330 +++++++----------- .../Gameplay/Area/Ready/ReadyAreaPoint.cs | 1 - .../Gameplay/Buff/Impl/BuffChangeReadyArea.cs | 1 + .../Combat/ConditionCombatLeastOccupy.cs | 2 +- .../BlackArea/BlackAreaManagerImpl.cs | 2 +- 5 files changed, 127 insertions(+), 209 deletions(-) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Area/Ready/ReadyAreaManager.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Area/Ready/ReadyAreaManager.cs index cc58466e5e8..097085f116f 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Area/Ready/ReadyAreaManager.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Area/Ready/ReadyAreaManager.cs @@ -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 _mapReadyCellIndexs; - public List mapReadyCellIndexs => _mapReadyCellIndexs; - - private List _vehicleAroundCellIndexs; - private int _lastVehicleCellIndex; + private List _mapSavedReadyCellIndexs; + public List 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 _finalReadyCellIndexs; private Dictionary _readyAreaDict; private Stack _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(); _pointsStack = new Stack(); + _finalReadyCellIndexs = new List(); _InitReadyAreaFromLevel(); } public void Init() { EventManager.Instance.Register(EventManager.EventName.INFIGHT_CAPTURE_FINSIHED, _OnCaptureArea); + EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, _OnCellIndexChanged); } - + public void Dispose() { EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_CAPTURE_FINSIHED, _OnCaptureArea); + EventManager.Instance.Unregister(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(); + _mapSavedReadyCellIndexs = new List(); 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(); - } - 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() diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Area/Ready/ReadyAreaPoint.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Area/Ready/ReadyAreaPoint.cs index 768a91d7757..f550f372210 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Area/Ready/ReadyAreaPoint.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Area/Ready/ReadyAreaPoint.cs @@ -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; } } diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Buff/Impl/BuffChangeReadyArea.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Buff/Impl/BuffChangeReadyArea.cs index 4eb37afc60d..89b42240094 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Buff/Impl/BuffChangeReadyArea.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Buff/Impl/BuffChangeReadyArea.cs @@ -29,6 +29,7 @@ namespace Gameplay.Buff // 修改上阵区域 AreaManager.instance.readyAreaManager.isVehicleBuffActive = true; + AreaManager.instance.readyAreaManager.followVehicle = _vehicle; EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_READY, _OnUnitEnterBattle); } diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/Combat/ConditionCombatLeastOccupy.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/Combat/ConditionCombatLeastOccupy.cs index c1a44fe4835..53dc968b8bd 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/Combat/ConditionCombatLeastOccupy.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/Combat/ConditionCombatLeastOccupy.cs @@ -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 args) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/PostProcess/BlackArea/BlackAreaManagerImpl.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/PostProcess/BlackArea/BlackAreaManagerImpl.cs index 7ccd8d09c33..8b1a5d80613 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/PostProcess/BlackArea/BlackAreaManagerImpl.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/PostProcess/BlackArea/BlackAreaManagerImpl.cs @@ -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);