Compare commits

...

2 Commits

Author SHA1 Message Date
JiWoong Sul
306715ca26 feat(balance): 레벨 기반 장비 손실 확률 시스템
- 저레벨 사망 스파이럴 방지
- 장비 손실 확률 = (레벨 - 5) * 10%
  - Lv 1~5: 0% (절대 안전)
  - Lv 6: 10%
  - Lv 10: 50%
  - Lv 15+: 100%
- 디버그 로그 추가
2026-01-16 00:17:08 +09:00
JiWoong Sul
9e5472728f refactor(potion): 물약 자동 사용 조건 변경
- 임계치 기반 → 소모량 기반 조건 전환
- HP/MP 소모량 >= 물약 회복량일 때 사용
- emergencyHpThreshold, emergencyMpThreshold 상수 제거
- 우선순위 HP > MP 유지
2026-01-16 00:15:38 +09:00
3 changed files with 116 additions and 108 deletions

View File

@@ -265,9 +265,7 @@ class CombatTickService {
return null;
}
// 우선순위 1: HP 물약 (HP <= 30%)
final hpRatio = playerStats.hpCurrent / playerStats.hpMax;
if (hpRatio <= PotionService.emergencyHpThreshold) {
// 우선순위 1: HP 물약 (소모된 HP >= 물약 회복량)
final hpPotion = potionService.selectEmergencyHpPotion(
currentHp: playerStats.hpCurrent,
maxHp: playerStats.hpMax,
@@ -301,11 +299,8 @@ class CombatTickService {
);
}
}
}
// 우선순위 2: MP 물약 (MP <= 50%)
final mpRatio = playerStats.mpCurrent / playerStats.mpMax;
if (mpRatio <= PotionService.emergencyMpThreshold) {
// 우선순위 2: MP 물약 (소모된 MP >= 물약 회복량)
final mpPotion = potionService.selectEmergencyMpPotion(
currentMp: playerStats.mpCurrent,
maxMp: playerStats.mpMax,
@@ -339,7 +334,6 @@ class CombatTickService {
);
}
}
}
return null;
}

View File

@@ -13,12 +13,6 @@ class PotionService {
/// 글로벌 물약 쿨타임 (1배속 기준 3초)
static const int globalPotionCooldownMs = 3000;
/// 긴급 물약 사용 HP 임계치 (30%)
static const double emergencyHpThreshold = 0.30;
/// 긴급 물약 사용 MP 임계치 (50%)
static const double emergencyMpThreshold = 0.50;
// ============================================================================
// 물약 사용 가능 여부
// ============================================================================
@@ -104,7 +98,7 @@ class PotionService {
/// 긴급 HP 물약 선택
///
/// HP가 임계치 이하일 때 사용할 최적의 물약 선택
/// 소모된 HP >= 물약 회복량이면 사용할 최적의 물약 선택
/// [currentHp] 현재 HP
/// [maxHp] 최대 HP
/// [inventory] 물약 인벤토리
@@ -115,9 +109,8 @@ class PotionService {
required PotionInventory inventory,
required int playerLevel,
}) {
// 임계치 체크
final hpRatio = currentHp / maxHp;
if (hpRatio > emergencyHpThreshold) return null;
final hpLost = maxHp - currentHp;
if (hpLost <= 0) return null;
// 적정 티어 계산
final targetTier = PotionData.tierForLevel(playerLevel);
@@ -126,33 +119,38 @@ class PotionService {
for (var tier = targetTier; tier >= 1; tier--) {
final potion = PotionData.getHpPotionByTier(tier);
if (potion != null && inventory.hasPotion(potion.id)) {
final healAmount = potion.calculateHeal(maxHp);
if (hpLost >= healAmount) {
return potion;
}
}
}
// 적정 티어 이상도 검색
for (var tier = targetTier + 1; tier <= 5; tier++) {
final potion = PotionData.getHpPotionByTier(tier);
if (potion != null && inventory.hasPotion(potion.id)) {
final healAmount = potion.calculateHeal(maxHp);
if (hpLost >= healAmount) {
return potion;
}
}
}
return null;
}
/// 긴급 MP 물약 선택
///
/// MP가 임계치 이하일 때 사용할 최적의 물약 선택
/// 소모된 MP >= 물약 회복량이면 사용할 최적의 물약 선택
Potion? selectEmergencyMpPotion({
required int currentMp,
required int maxMp,
required PotionInventory inventory,
required int playerLevel,
}) {
// 임계치 체크
final mpRatio = currentMp / maxMp;
if (mpRatio > emergencyMpThreshold) return null;
final mpLost = maxMp - currentMp;
if (mpLost <= 0) return null;
// 적정 티어 계산
final targetTier = PotionData.tierForLevel(playerLevel);
@@ -161,17 +159,23 @@ class PotionService {
for (var tier = targetTier; tier >= 1; tier--) {
final potion = PotionData.getMpPotionByTier(tier);
if (potion != null && inventory.hasPotion(potion.id)) {
final healAmount = potion.calculateHeal(maxMp);
if (mpLost >= healAmount) {
return potion;
}
}
}
// 적정 티어 이상도 검색
for (var tier = targetTier + 1; tier <= 5; tier++) {
final potion = PotionData.getMpPotionByTier(tier);
if (potion != null && inventory.hasPotion(potion.id)) {
final healAmount = potion.calculateHeal(maxMp);
if (mpLost >= healAmount) {
return potion;
}
}
}
return null;
}

View File

@@ -974,20 +974,26 @@ class ProgressService {
ItemRarity? lostItemRarity;
if (!isBossDeath) {
// 레벨 기반 장비 손실 확률 계산
// Lv 1~5: 0%, Lv 6: 10%, Lv 10: 50%, Lv 15+: 100%
final level = state.traits.level;
final lossChancePercent = ((level - 5) * 10).clamp(0, 100);
final roll = state.rng.nextInt(100); // 0~99
final shouldLoseEquipment = roll < lossChancePercent;
// ignore: avoid_print
print('[Death] Lv$level lossChance=$lossChancePercent% roll=$roll '
'shouldLose=$shouldLoseEquipment');
if (shouldLoseEquipment) {
// 무기(슬롯 0)를 제외한 장착된 장비 중 1개를 제물로 삭제
final equippedNonWeaponSlots = <int>[];
for (var i = 1; i < Equipment.slotCount; i++) {
final item = state.equipment.getItemByIndex(i);
// 디버그: 장비 슬롯 상태 확인
// ignore: avoid_print
print('[Death] Slot $i: "${item.name}" isEmpty=${item.isEmpty}');
if (item.isNotEmpty) {
equippedNonWeaponSlots.add(i);
}
}
// 디버그: 장착된 슬롯 목록
// ignore: avoid_print
print('[Death] equippedNonWeaponSlots: $equippedNonWeaponSlots');
if (equippedNonWeaponSlots.isNotEmpty) {
lostCount = 1;
@@ -1008,6 +1014,10 @@ class ProgressService {
sacrificeIndex,
EquipmentItem.empty(lostItemSlot),
);
// ignore: avoid_print
print('[Death] Lost item: $lostItemName (slot: $lostItemSlot)');
}
}
}