140 lines
5.0 KiB
C#
140 lines
5.0 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Gameplay.Character;
|
|
using Gameplay.Common;
|
|
|
|
namespace Gameplay.Level
|
|
{
|
|
public partial class Level
|
|
{
|
|
private int _currentStageIndex = 0;
|
|
|
|
public int GetCurrentStageIndex()
|
|
{
|
|
return _currentStageIndex;
|
|
}
|
|
|
|
public static bool IsEnemy(GameUnit character1, GameUnit character2)
|
|
{
|
|
return IsEnemy(character1.commonData.troopId, character2.commonData.troopId);
|
|
}
|
|
|
|
public static bool IsEnemy(int troop1, int troop2)
|
|
{
|
|
return troop1 != troop2;
|
|
}
|
|
|
|
|
|
|
|
public bool CheckIsFail(out LevelData.FailCondition condition)
|
|
{
|
|
if (_levelData != null && _currentStageIndex >= 0 && _currentStageIndex < _levelData.stages.Count)
|
|
{
|
|
var stage = _levelData.stages[_currentStageIndex];
|
|
|
|
for (int i = 0; i < stage.failConditions.Count; i++)
|
|
{
|
|
if (stage.failConditions[i].failType == LevelData.FailCondition.FailType.AllDead)
|
|
{
|
|
if (IsAllDead(ETroopsId.Self))
|
|
{
|
|
condition = stage.failConditions[i];
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
condition = default;
|
|
return false;
|
|
}
|
|
|
|
|
|
private bool IsAllDead(int troopId)
|
|
{
|
|
return _characterManager.FindOne(c => c.troopId == troopId && !c.statusData.isDead) == null;
|
|
}
|
|
|
|
public bool CheckIsSuccess(out LevelData.Goal goal)
|
|
{
|
|
if (_levelData != null && _currentStageIndex >= 0 && _currentStageIndex < _levelData.stages.Count)
|
|
{
|
|
var stage = _levelData.stages[_currentStageIndex];
|
|
|
|
if (stage.goal.goalType == LevelData.Goal.GoalType.Occupy)
|
|
{
|
|
var position = stage.goal.position;
|
|
var character = _characterManager.FindOne(character =>
|
|
character.transData.cellIndex == _map.BlockPosition2TGSCellIndex(position)
|
|
&& character.troopId == ETroopsId.Self);
|
|
if (character != null)
|
|
{
|
|
goal = stage.goal;
|
|
return true;
|
|
}
|
|
}
|
|
else if (stage.goal.goalType == LevelData.Goal.GoalType.FallBack)
|
|
{
|
|
var position = stage.goal.position;
|
|
var characterYes = _characterManager.FindOne(character =>
|
|
character.transData.cellIndex == _map.BlockPosition2TGSCellIndex(position)
|
|
&& character.troopId == ETroopsId.Self);
|
|
var characterNo = _characterManager.FindOne(character =>
|
|
character.transData.cellIndex != _map.BlockPosition2TGSCellIndex(position)
|
|
&& character.troopId == ETroopsId.Self);
|
|
|
|
if (characterYes != null && characterNo == null)
|
|
{
|
|
goal = stage.goal;
|
|
return true;
|
|
}
|
|
}
|
|
else if (stage.goal.goalType == LevelData.Goal.GoalType.KillAll)
|
|
{
|
|
var character = _characterManager.FindOne(character =>
|
|
character.troopId is ETroopsId.Enemy1 or ETroopsId.Enemy2
|
|
&& !character.statusData.isDead);
|
|
if (character == null)
|
|
{
|
|
goal = stage.goal;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
goal = default;
|
|
return false;
|
|
}
|
|
|
|
public void CurrentStageSuccess()
|
|
{
|
|
if (_levelData != null && _currentStageIndex >= 0 && _currentStageIndex < _levelData.stages.Count)
|
|
{
|
|
var stage = _levelData.stages[_currentStageIndex];
|
|
OnStageSuccess(stage.goal);
|
|
}
|
|
}
|
|
|
|
public async void AllStageSuccess()
|
|
{
|
|
while (_levelData != null && _currentStageIndex >= 0 && _currentStageIndex < _levelData.stages.Count)
|
|
{
|
|
var stage = _levelData.stages[_currentStageIndex];
|
|
await OnStageSuccess(stage.goal);
|
|
await UniTask.NextFrame();
|
|
}
|
|
}
|
|
|
|
public void LevelFail()
|
|
{
|
|
if (_levelData != null && _currentStageIndex >= 0 && _currentStageIndex < _levelData.stages.Count)
|
|
{
|
|
var stage = _levelData.stages[_currentStageIndex];
|
|
|
|
for (int i = 0; i < stage.failConditions.Count; i++)
|
|
{
|
|
var failCondition = stage.failConditions[i];
|
|
OnLevelFail(failCondition);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |