feat(death): 사망/부활 시스템 개선
- DeathInfo에 lostItem 필드 추가 (광고 부활 시 복구용) - 세이브 데이터 v4: MonetizationState 포함 - 사망 오버레이 UI 개선 - 부활 서비스 광고 연동
This commit is contained in:
@@ -240,6 +240,129 @@ class ResurrectionService {
|
||||
return state.inventory.gold >= cost;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 광고 부활 (HP 100% + 아이템 복구)
|
||||
// ============================================================================
|
||||
|
||||
/// 광고 부활 처리
|
||||
///
|
||||
/// 1. 상실한 아이템 복구 (있는 경우)
|
||||
/// 2. HP/MP 100% 회복
|
||||
/// 3. 사망 상태 해제
|
||||
/// 4. 안전 지역으로 이동 태스크 설정
|
||||
///
|
||||
/// Note: 10분 자동부활 버프는 GameSessionController에서 처리
|
||||
GameState processAdRevive(GameState state) {
|
||||
if (!state.isDead) return state;
|
||||
|
||||
var nextState = state;
|
||||
|
||||
// 1. 상실한 아이템 복구 (있는 경우)
|
||||
if (canRecoverLostItem(state)) {
|
||||
nextState = processItemRecovery(nextState);
|
||||
}
|
||||
|
||||
// 2. 전체 HP/MP 계산 (장비 + 종족 + 클래스 보너스 포함)
|
||||
final totalHpMax = _calculateTotalHpMax(nextState);
|
||||
final totalMpMax = _calculateTotalMpMax(nextState);
|
||||
|
||||
// HP/MP 100% 회복 (장비 구매 없이)
|
||||
nextState = nextState.copyWith(
|
||||
stats: nextState.stats.copyWith(
|
||||
hpCurrent: totalHpMax,
|
||||
mpCurrent: totalMpMax,
|
||||
),
|
||||
clearDeathInfo: true, // 사망 상태 해제
|
||||
);
|
||||
|
||||
// 스킬 쿨타임 초기화
|
||||
nextState = nextState.copyWith(
|
||||
skillSystem: SkillSystemState.empty().copyWith(
|
||||
elapsedMs: nextState.skillSystem.elapsedMs,
|
||||
),
|
||||
);
|
||||
|
||||
// 4. 부활 후 태스크 시퀀스 설정
|
||||
final resurrectionQueue = <QueueEntry>[
|
||||
QueueEntry(
|
||||
kind: QueueKind.task,
|
||||
durationMillis: 3000,
|
||||
caption: l10n.taskReturningToTown,
|
||||
taskType: TaskType.neutral,
|
||||
),
|
||||
QueueEntry(
|
||||
kind: QueueKind.task,
|
||||
durationMillis: 3000,
|
||||
caption: l10n.taskRestockingAtShop,
|
||||
taskType: TaskType.market,
|
||||
),
|
||||
QueueEntry(
|
||||
kind: QueueKind.task,
|
||||
durationMillis: 2000,
|
||||
caption: l10n.taskHeadingToHuntingGrounds,
|
||||
taskType: TaskType.neutral,
|
||||
),
|
||||
];
|
||||
|
||||
final firstTask = resurrectionQueue.removeAt(0);
|
||||
nextState = nextState.copyWith(
|
||||
queue: QueueState(entries: resurrectionQueue),
|
||||
progress: nextState.progress.copyWith(
|
||||
currentTask: TaskInfo(
|
||||
caption: firstTask.caption,
|
||||
type: firstTask.taskType,
|
||||
),
|
||||
task: ProgressBarState(position: 0, max: firstTask.durationMillis),
|
||||
currentCombat: null,
|
||||
),
|
||||
);
|
||||
|
||||
return nextState;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 아이템 복구 (Phase 5)
|
||||
// ============================================================================
|
||||
|
||||
/// 상실한 아이템 복구 가능 여부 확인
|
||||
///
|
||||
/// 사망 상태이고 상실한 아이템이 있을 때만 true
|
||||
bool canRecoverLostItem(GameState state) {
|
||||
if (!state.isDead) return false;
|
||||
if (state.deathInfo == null) return false;
|
||||
return state.deathInfo!.lostItem != null;
|
||||
}
|
||||
|
||||
/// 상실한 아이템 복구 처리
|
||||
///
|
||||
/// 광고 시청 후 호출되며 상실한 아이템을 장비에 복원합니다.
|
||||
/// Returns: 복구된 상태 (복구 불가 시 원본 상태 반환)
|
||||
GameState processItemRecovery(GameState state) {
|
||||
if (!canRecoverLostItem(state)) return state;
|
||||
|
||||
final deathInfo = state.deathInfo!;
|
||||
final lostItem = deathInfo.lostItem!;
|
||||
final lostSlot = deathInfo.lostItemSlot!;
|
||||
|
||||
// 해당 슬롯에 아이템 복원
|
||||
final slotIndex = lostSlot.index;
|
||||
final updatedEquipment = state.equipment.setItemByIndex(slotIndex, lostItem);
|
||||
|
||||
// DeathInfo에서 상실 아이템 정보 제거 (복구 완료)
|
||||
final updatedDeathInfo = deathInfo.copyWith(
|
||||
lostEquipmentCount: 0,
|
||||
lostItemName: null,
|
||||
lostItemSlot: null,
|
||||
lostItemRarity: null,
|
||||
lostItem: null,
|
||||
);
|
||||
|
||||
return state.copyWith(
|
||||
equipment: updatedEquipment,
|
||||
deathInfo: updatedDeathInfo,
|
||||
);
|
||||
}
|
||||
|
||||
/// 장비 보존 아이템 적용 (향후 확장용)
|
||||
///
|
||||
/// [protectedSlots] 보존할 슬롯 인덱스 목록
|
||||
|
||||
Reference in New Issue
Block a user