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] 보존할 슬롯 인덱스 목록
|
||||
|
||||
@@ -133,6 +133,7 @@ class DeathInfo {
|
||||
this.lostItemName,
|
||||
this.lostItemSlot,
|
||||
this.lostItemRarity,
|
||||
this.lostItem,
|
||||
this.lastCombatEvents = const [],
|
||||
});
|
||||
|
||||
@@ -154,6 +155,9 @@ class DeathInfo {
|
||||
/// 제물로 바친 아이템 희귀도 (null이면 없음)
|
||||
final ItemRarity? lostItemRarity;
|
||||
|
||||
/// 상실한 장비 전체 정보 (광고 부활 시 복구용)
|
||||
final EquipmentItem? lostItem;
|
||||
|
||||
/// 사망 시점 골드
|
||||
final int goldAtDeath;
|
||||
|
||||
@@ -173,6 +177,7 @@ class DeathInfo {
|
||||
String? lostItemName,
|
||||
EquipmentSlot? lostItemSlot,
|
||||
ItemRarity? lostItemRarity,
|
||||
EquipmentItem? lostItem,
|
||||
int? goldAtDeath,
|
||||
int? levelAtDeath,
|
||||
int? timestamp,
|
||||
@@ -185,6 +190,7 @@ class DeathInfo {
|
||||
lostItemName: lostItemName ?? this.lostItemName,
|
||||
lostItemSlot: lostItemSlot ?? this.lostItemSlot,
|
||||
lostItemRarity: lostItemRarity ?? this.lostItemRarity,
|
||||
lostItem: lostItem ?? this.lostItem,
|
||||
goldAtDeath: goldAtDeath ?? this.goldAtDeath,
|
||||
levelAtDeath: levelAtDeath ?? this.levelAtDeath,
|
||||
timestamp: timestamp ?? this.timestamp,
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:collection';
|
||||
|
||||
import 'package:asciineverdie/src/core/model/equipment_item.dart';
|
||||
import 'package:asciineverdie/src/core/model/equipment_slot.dart';
|
||||
import 'package:asciineverdie/src/core/model/monetization_state.dart';
|
||||
import 'package:asciineverdie/src/core/model/monster_grade.dart';
|
||||
import 'package:asciineverdie/src/core/util/deterministic_random.dart';
|
||||
import 'package:asciineverdie/src/core/model/game_state.dart';
|
||||
@@ -9,7 +10,8 @@ import 'package:asciineverdie/src/core/model/game_state.dart';
|
||||
/// 세이브 파일 버전
|
||||
/// - v2: 장비 이름만 저장 (레거시)
|
||||
/// - v3: 장비 전체 정보 저장 (level, rarity, stats 포함)
|
||||
const int kSaveVersion = 3;
|
||||
/// - v4: MonetizationState 추가, DeathInfo.lostItem 추가
|
||||
const int kSaveVersion = 4;
|
||||
|
||||
class GameSave {
|
||||
GameSave({
|
||||
@@ -23,9 +25,14 @@ class GameSave {
|
||||
required this.progress,
|
||||
required this.queue,
|
||||
this.cheatsEnabled = false,
|
||||
this.monetization,
|
||||
});
|
||||
|
||||
factory GameSave.fromState(GameState state, {bool cheatsEnabled = false}) {
|
||||
factory GameSave.fromState(
|
||||
GameState state, {
|
||||
bool cheatsEnabled = false,
|
||||
MonetizationState? monetization,
|
||||
}) {
|
||||
return GameSave(
|
||||
version: kSaveVersion,
|
||||
rngState: state.rng.state,
|
||||
@@ -37,6 +44,7 @@ class GameSave {
|
||||
progress: state.progress,
|
||||
queue: state.queue,
|
||||
cheatsEnabled: cheatsEnabled,
|
||||
monetization: monetization,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,6 +59,9 @@ class GameSave {
|
||||
final QueueState queue;
|
||||
final bool cheatsEnabled;
|
||||
|
||||
/// 수익화 시스템 상태 (v4+)
|
||||
final MonetizationState? monetization;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'version': version,
|
||||
@@ -132,6 +143,7 @@ class GameSave {
|
||||
},
|
||||
)
|
||||
.toList(),
|
||||
if (monetization != null) 'monetization': monetization!.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -244,6 +256,9 @@ class GameSave {
|
||||
}),
|
||||
),
|
||||
),
|
||||
monetization: _monetizationFromJson(
|
||||
json['monetization'] as Map<String, dynamic>?,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -355,3 +370,12 @@ Equipment _equipmentFromJson(Map<String, dynamic> json, int version) {
|
||||
bestIndex: json['bestIndex'] as int? ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
/// MonetizationState 역직렬화 (v4+ 마이그레이션)
|
||||
///
|
||||
/// - v3 이하: null (기본값 사용)
|
||||
/// - v4 이상: 저장된 상태 로드
|
||||
MonetizationState? _monetizationFromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return null;
|
||||
return MonetizationState.fromJson(json);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:asciineverdie/src/core/model/game_state.dart';
|
||||
import 'package:asciineverdie/src/core/model/monetization_state.dart';
|
||||
import 'package:asciineverdie/src/core/model/save_data.dart';
|
||||
import 'package:asciineverdie/src/core/storage/save_repository.dart';
|
||||
import 'package:asciineverdie/src/core/storage/save_service.dart'
|
||||
@@ -13,23 +14,36 @@ class SaveManager {
|
||||
|
||||
/// Save current game state to disk. [fileName] may be absolute or relative.
|
||||
/// Returns outcome with error on failure.
|
||||
///
|
||||
/// [monetization] 저장 시 lastPlayTime을 현재 시간으로 자동 업데이트
|
||||
Future<SaveOutcome> saveState(
|
||||
GameState state, {
|
||||
String? fileName,
|
||||
bool cheatsEnabled = false,
|
||||
MonetizationState? monetization,
|
||||
}) {
|
||||
final save = GameSave.fromState(state, cheatsEnabled: cheatsEnabled);
|
||||
// lastPlayTime을 현재 시간으로 업데이트
|
||||
final updatedMonetization = (monetization ?? MonetizationState.initial())
|
||||
.copyWith(lastPlayTime: DateTime.now());
|
||||
|
||||
final save = GameSave.fromState(
|
||||
state,
|
||||
cheatsEnabled: cheatsEnabled,
|
||||
monetization: updatedMonetization,
|
||||
);
|
||||
return _repo.save(save, fileName ?? defaultFileName);
|
||||
}
|
||||
|
||||
/// Load game state from disk. [fileName] may be absolute (e.g., file picker).
|
||||
/// Returns outcome + optional state + cheatsEnabled flag.
|
||||
Future<(SaveOutcome, GameState?, bool)> loadState({String? fileName}) async {
|
||||
/// Returns outcome + optional state + cheatsEnabled flag + monetization state.
|
||||
Future<(SaveOutcome, GameState?, bool, MonetizationState?)> loadState({
|
||||
String? fileName,
|
||||
}) async {
|
||||
final (outcome, save) = await _repo.load(fileName ?? defaultFileName);
|
||||
if (!outcome.success || save == null) {
|
||||
return (outcome, null, false);
|
||||
return (outcome, null, false, null);
|
||||
}
|
||||
return (outcome, save.toState(), save.cheatsEnabled);
|
||||
return (outcome, save.toState(), save.cheatsEnabled, save.monetization);
|
||||
}
|
||||
|
||||
/// 저장 파일 목록 조회
|
||||
|
||||
Reference in New Issue
Block a user