- Progress Quest 6.4 Flutter 포팅 프로젝트 - 게임 루프, 상태 관리, UI 구현 - 캐릭터 생성, 인벤토리, 장비, 주문 시스템 - 시장/판매/구매 메커니즘
246 lines
8.0 KiB
Dart
246 lines
8.0 KiB
Dart
import 'package:askiineverdie/src/core/model/equipment_slot.dart';
|
|
import 'package:askiineverdie/src/core/model/game_state.dart';
|
|
import 'package:askiineverdie/src/core/model/pq_config.dart';
|
|
import 'package:askiineverdie/src/core/util/deterministic_random.dart';
|
|
import 'package:askiineverdie/src/core/util/pq_logic.dart' as pq_logic;
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
const config = PqConfig();
|
|
|
|
test('levelUpTime grows with level and matches expected seconds', () {
|
|
expect(pq_logic.levelUpTime(1), 1269);
|
|
expect(pq_logic.levelUpTime(10), 1443);
|
|
});
|
|
|
|
test('roughTime formats seconds into human-readable strings', () {
|
|
// < 120초: seconds
|
|
expect(pq_logic.roughTime(60), '60 seconds');
|
|
expect(pq_logic.roughTime(119), '119 seconds');
|
|
|
|
// 120초 ~ 2시간: minutes
|
|
expect(pq_logic.roughTime(120), '2 minutes');
|
|
expect(pq_logic.roughTime(3600), '60 minutes');
|
|
expect(pq_logic.roughTime(7199), '119 minutes');
|
|
|
|
// 2시간 ~ 48시간: hours
|
|
expect(pq_logic.roughTime(7200), '2 hours');
|
|
expect(pq_logic.roughTime(86400), '24 hours');
|
|
expect(pq_logic.roughTime(172799), '47 hours');
|
|
|
|
// 48시간 이상: days
|
|
expect(pq_logic.roughTime(172800), '2 days');
|
|
expect(pq_logic.roughTime(604800), '7 days');
|
|
});
|
|
|
|
test('generateName produces deterministic names per seed', () {
|
|
expect(pq_logic.generateName(DeterministicRandom(123)), 'Grunax');
|
|
expect(pq_logic.generateName(DeterministicRandom(42)), 'Bregpran');
|
|
});
|
|
|
|
test('indefinite/definite/pluralize honor English rules', () {
|
|
expect(pq_logic.indefinite('apple', 1), 'an apple');
|
|
expect(pq_logic.indefinite('orc', 3), '3 orcs');
|
|
expect(pq_logic.definite('goblin', 2), 'the goblins');
|
|
expect(pq_logic.pluralize('baby'), 'babies');
|
|
});
|
|
|
|
test('item and reward helpers are deterministic with seed', () {
|
|
expect(pq_logic.boringItem(config, DeterministicRandom(12)), 'egg');
|
|
expect(
|
|
pq_logic.interestingItem(config, DeterministicRandom(12)),
|
|
'Golden Ornament',
|
|
);
|
|
expect(
|
|
pq_logic.specialItem(config, DeterministicRandom(12)),
|
|
'Golden Ornament of Efficiency',
|
|
);
|
|
// 원본 Main.pas:770-774 RandomLow 방식으로 수정됨
|
|
expect(
|
|
pq_logic.winSpell(config, DeterministicRandom(22), 7, 4),
|
|
'Slime Finger|II',
|
|
);
|
|
expect(
|
|
pq_logic.winEquip(
|
|
config,
|
|
DeterministicRandom(12),
|
|
5,
|
|
EquipmentSlot.weapon,
|
|
),
|
|
'Baselard',
|
|
);
|
|
expect(
|
|
pq_logic.winEquip(
|
|
config,
|
|
DeterministicRandom(15),
|
|
2,
|
|
EquipmentSlot.armor,
|
|
),
|
|
'-2 Canvas',
|
|
);
|
|
expect(
|
|
pq_logic.winItem(config, DeterministicRandom(10), 3),
|
|
'Golden Hymnal of Cruelty',
|
|
);
|
|
expect(pq_logic.winItem(config, DeterministicRandom(10), 1000), isEmpty);
|
|
});
|
|
|
|
test('monsterTask picks level-appropriate monsters with modifiers', () {
|
|
expect(
|
|
pq_logic.monsterTask(config, DeterministicRandom(99), 5, null, null),
|
|
'an underage Rakshasa',
|
|
);
|
|
expect(
|
|
pq_logic.monsterTask(config, DeterministicRandom(7), 10, null, null),
|
|
'a greater Sphinx',
|
|
);
|
|
expect(
|
|
pq_logic.monsterTask(config, DeterministicRandom(5), 6, 'Goblin|3', 3),
|
|
'a Barbed Devil',
|
|
);
|
|
});
|
|
|
|
test('completeQuest and completeAct return deterministic results', () {
|
|
final quest = pq_logic.completeQuest(config, DeterministicRandom(33), 4);
|
|
expect(quest.caption, 'Deliver this chicken');
|
|
expect(quest.reward, pq_logic.RewardKind.item);
|
|
expect(quest.monsterName, isNull);
|
|
|
|
final act2 = pq_logic.completeAct(2);
|
|
expect(act2.actTitle, 'Act II');
|
|
expect(act2.plotBarMaxSeconds, 39600);
|
|
expect(act2.rewards, contains(pq_logic.RewardKind.item));
|
|
expect(act2.rewards, isNot(contains(pq_logic.RewardKind.equip)));
|
|
|
|
final act3 = pq_logic.completeAct(3);
|
|
expect(
|
|
act3.rewards,
|
|
containsAll(<pq_logic.RewardKind>{
|
|
pq_logic.RewardKind.item,
|
|
pq_logic.RewardKind.equip,
|
|
}),
|
|
);
|
|
});
|
|
|
|
test('dequeue starts next task and drains queue', () {
|
|
const progress = ProgressState(
|
|
task: ProgressBarState(position: 100, max: 100),
|
|
quest: ProgressBarState(position: 0, max: 10),
|
|
plot: ProgressBarState(position: 0, max: 10),
|
|
exp: ProgressBarState(position: 0, max: 10),
|
|
encumbrance: ProgressBarState(position: 0, max: 1),
|
|
currentTask: TaskInfo(caption: 'Idle', type: TaskType.neutral),
|
|
plotStageCount: 1,
|
|
questCount: 0,
|
|
);
|
|
final queue = QueueState(
|
|
entries: const [
|
|
QueueEntry(
|
|
kind: QueueKind.task,
|
|
durationMillis: 120,
|
|
caption: 'Fight',
|
|
taskType: TaskType.kill,
|
|
),
|
|
QueueEntry(
|
|
kind: QueueKind.plot,
|
|
durationMillis: 80,
|
|
caption: 'Plot',
|
|
taskType: TaskType.plot,
|
|
),
|
|
],
|
|
);
|
|
|
|
final result = pq_logic.dequeue(progress, queue);
|
|
expect(result, isNotNull);
|
|
expect(result!.caption, 'Fight...');
|
|
expect(result.taskType, TaskType.kill);
|
|
expect(result.kind, QueueKind.task);
|
|
expect(result.progress.task.position, 0);
|
|
expect(result.progress.task.max, 120);
|
|
expect(result.queue.entries.length, 1);
|
|
expect(result.queue.entries.first.kind, QueueKind.plot);
|
|
});
|
|
|
|
test('impressiveGuy generates deterministic NPC titles', () {
|
|
// case 0: "the King of the Elves" 형태
|
|
final guy1 = pq_logic.impressiveGuy(config, DeterministicRandom(42));
|
|
expect(guy1, contains('of the'));
|
|
|
|
// case 1: "King Vrognak of Zoxzik" 형태
|
|
final guy2 = pq_logic.impressiveGuy(config, DeterministicRandom(7));
|
|
expect(guy2, contains(' of '));
|
|
|
|
// 결정적(deterministic) 결과 확인
|
|
expect(
|
|
pq_logic.impressiveGuy(config, DeterministicRandom(100)),
|
|
pq_logic.impressiveGuy(config, DeterministicRandom(100)),
|
|
);
|
|
});
|
|
|
|
test('namedMonster generates named monster with level matching', () {
|
|
final monster = pq_logic.namedMonster(config, DeterministicRandom(42), 10);
|
|
// "GeneratedName the MonsterType" 형태
|
|
expect(monster, contains(' the '));
|
|
|
|
// 결정적(deterministic) 결과 확인
|
|
expect(
|
|
pq_logic.namedMonster(config, DeterministicRandom(50), 5),
|
|
pq_logic.namedMonster(config, DeterministicRandom(50), 5),
|
|
);
|
|
});
|
|
|
|
test('interplotCinematic generates queue entries with plot ending', () {
|
|
final entries = pq_logic.interplotCinematic(
|
|
config,
|
|
DeterministicRandom(42),
|
|
10,
|
|
3,
|
|
);
|
|
|
|
// 최소 1개 이상의 엔트리 생성
|
|
expect(entries, isNotEmpty);
|
|
|
|
// 마지막은 항상 plot 타입의 'Loading'
|
|
expect(entries.last.kind, QueueKind.plot);
|
|
expect(entries.last.caption, 'Loading');
|
|
expect(entries.last.durationMillis, 2000);
|
|
|
|
// 나머지는 task 타입
|
|
for (var i = 0; i < entries.length - 1; i++) {
|
|
expect(entries[i].kind, QueueKind.task);
|
|
}
|
|
});
|
|
|
|
test('interplotCinematic has three distinct scenarios', () {
|
|
// 여러 시드를 테스트해서 3가지 시나리오가 모두 나오는지 확인
|
|
final scenariosFound = <String>{};
|
|
|
|
for (var seed = 0; seed < 100; seed++) {
|
|
final entries = pq_logic.interplotCinematic(
|
|
config,
|
|
DeterministicRandom(seed),
|
|
5,
|
|
1,
|
|
);
|
|
|
|
final firstCaption = entries.first.caption;
|
|
if (firstCaption.contains('oasis')) {
|
|
scenariosFound.add('oasis');
|
|
// 오아시스 시나리오: 4개 task + 1개 plot = 5개
|
|
expect(entries.length, 5);
|
|
} else if (firstCaption.contains('quarry')) {
|
|
scenariosFound.add('combat');
|
|
// 전투 시나리오: 가변 길이 (combatRounds에 따라)
|
|
expect(entries.length, greaterThanOrEqualTo(5));
|
|
} else if (firstCaption.contains('sweet relief')) {
|
|
scenariosFound.add('betrayal');
|
|
// 배신 시나리오: 6개 task + 1개 plot = 7개
|
|
expect(entries.length, 7);
|
|
}
|
|
}
|
|
|
|
// 3가지 시나리오가 모두 발견되어야 함
|
|
expect(scenariosFound, containsAll(['oasis', 'combat', 'betrayal']));
|
|
});
|
|
}
|