33 lines
933 B
C#
33 lines
933 B
C#
using GeometryTD.DataTable;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
namespace GeometryTD.CustomComponent
|
|
{
|
|
internal sealed class EnemyDropResolver
|
|
{
|
|
public EnemyDropResolveResult Resolve(in EnemyDropResolveContext context)
|
|
{
|
|
DREnemy enemy = context.Enemy;
|
|
if (enemy == null)
|
|
{
|
|
return EnemyDropResolveResult.Empty;
|
|
}
|
|
|
|
int coin = Mathf.Max(0, enemy.DropCoin);
|
|
int gold = 0;
|
|
|
|
float dropRate = enemy.DropPercent > 1f
|
|
? Mathf.Clamp01(enemy.DropPercent * 0.01f)
|
|
: Mathf.Clamp01(enemy.DropPercent);
|
|
|
|
if (enemy.DropGold > 0 && dropRate > 0f && Random.value <= dropRate)
|
|
{
|
|
gold = Mathf.Max(0, enemy.DropGold);
|
|
}
|
|
|
|
return new EnemyDropResolveResult(coin, gold, shouldRollOutGameItem: true);
|
|
}
|
|
}
|
|
}
|