97 lines
2.7 KiB
C#
97 lines
2.7 KiB
C#
using System;
|
|
using GeometryTD.Definition;
|
|
using UnityEngine;
|
|
|
|
namespace GeometryTD.UI
|
|
{
|
|
public class CombatInfoFormUseCase : IUIUseCase
|
|
{
|
|
private Func<CombatInfoFormRawData> _modelProvider;
|
|
private Func<bool> _tryEndCombat;
|
|
private Func<bool> _tryDebugFail;
|
|
|
|
public CombatInfoFormRawData CreateInitialModel()
|
|
{
|
|
return BuildModel();
|
|
}
|
|
|
|
public CombatInfoFormRawData TryRefresh()
|
|
{
|
|
return BuildModel();
|
|
}
|
|
|
|
public void Configure(Func<CombatInfoFormRawData> modelProvider, Func<bool> tryEndCombat, Func<bool> tryDebugFail)
|
|
{
|
|
_modelProvider = modelProvider;
|
|
_tryEndCombat = tryEndCombat;
|
|
_tryDebugFail = tryDebugFail;
|
|
}
|
|
|
|
public bool TryEndCombat()
|
|
{
|
|
if (_tryEndCombat == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return _tryEndCombat.Invoke();
|
|
}
|
|
|
|
public bool TryDebugFail()
|
|
{
|
|
if (_tryDebugFail == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return _tryDebugFail.Invoke();
|
|
}
|
|
|
|
private CombatInfoFormRawData BuildModel()
|
|
{
|
|
return _modelProvider != null ? _modelProvider.Invoke() : null;
|
|
}
|
|
|
|
public static CombatInfoFormRawData BuildRawData(
|
|
LevelThemeType themeType,
|
|
int levelId,
|
|
int currentPhaseIndex,
|
|
int totalPhaseCount,
|
|
int coin,
|
|
int baseHp,
|
|
int baseHpMax,
|
|
bool canEnd)
|
|
{
|
|
return new CombatInfoFormRawData
|
|
{
|
|
LevelThemeType = themeType,
|
|
LevelId = levelId,
|
|
CurrentPhaseIndex = Mathf.Max(0, currentPhaseIndex),
|
|
TotalPhaseCount = Mathf.Max(0, totalPhaseCount),
|
|
Coin = Mathf.Max(0, coin),
|
|
BaseHp = Mathf.Max(0, baseHp),
|
|
BaseHpMax = Mathf.Max(0, baseHpMax),
|
|
EnemyHpRateMultiplier = ResolveEnemyHpRateMultiplier(currentPhaseIndex, totalPhaseCount),
|
|
CanPause = true,
|
|
CanEnd = canEnd
|
|
};
|
|
}
|
|
|
|
private static int ResolveEnemyHpRateMultiplier(int currentPhaseIndex, int totalPhaseCount)
|
|
{
|
|
if (currentPhaseIndex <= 0 || totalPhaseCount <= 0)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
int completedLoopCount = Mathf.Max(0, (currentPhaseIndex - 1) / totalPhaseCount);
|
|
if (completedLoopCount >= 30)
|
|
{
|
|
return int.MaxValue;
|
|
}
|
|
|
|
return 1 << completedLoopCount;
|
|
}
|
|
}
|
|
}
|