Enhance tactical sortie preparation
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import Phaser from 'phaser';
|
||||
import { soundDirector } from '../audio/SoundDirector';
|
||||
import { equipmentExpToNext, equipmentSlotLabels, equipmentSlots, getItem, type EquipmentSlot } from '../data/battleItems';
|
||||
import { getUnitClass } from '../data/battleRules';
|
||||
import { defaultBattleScenario } from '../data/battles';
|
||||
import { getUnitClass, terrainRules, type TerrainType } from '../data/battleRules';
|
||||
import { defaultBattleScenario, getBattleScenario, type BattleScenarioDefinition } from '../data/battles';
|
||||
import { getSortieFlow } from '../data/campaignFlow';
|
||||
import { firstBattleBonds, firstBattleUnits, xuzhouRecruitBonds, xuzhouRecruitUnits, type PortraitKey, type UnitData } from '../data/scenario';
|
||||
import {
|
||||
@@ -64,6 +64,13 @@ type SortieChecklistItem = {
|
||||
detail: string;
|
||||
};
|
||||
|
||||
type SortieUnitTacticalSummary = {
|
||||
statLine: string;
|
||||
equipmentLine: string;
|
||||
bondLine: string;
|
||||
terrainLine: string;
|
||||
};
|
||||
|
||||
const portraitKeys: Record<PortraitKey, string> = {
|
||||
liuBei: 'portrait-liu-bei',
|
||||
guanYu: 'portrait-guan-yu',
|
||||
@@ -1159,8 +1166,8 @@ export class CampScene extends Phaser.Scene {
|
||||
this.selectedSortieUnitIds = this.normalizedSortieUnitIds(this.campaign.selectedSortieUnitIds);
|
||||
|
||||
const depth = 40;
|
||||
const width = 900;
|
||||
const height = 560;
|
||||
const width = 1160;
|
||||
const height = 660;
|
||||
const x = Math.floor((this.scale.width - width) / 2);
|
||||
const y = Math.floor((this.scale.height - height) / 2);
|
||||
|
||||
@@ -1181,10 +1188,10 @@ export class CampScene extends Phaser.Scene {
|
||||
);
|
||||
subtitle.setDepth(depth + 2);
|
||||
|
||||
this.renderSortieBriefing(x + 34, y + 112, 396, 152, depth + 2);
|
||||
this.renderSortieChecklist(x + 462, y + 112, 404, 170, depth + 2);
|
||||
this.renderSortieUnitSummary(x + 34, y + 292, 832, 176, depth + 2);
|
||||
this.renderSortieRewardHint(x + 34, y + 480, 548, 52, depth + 2);
|
||||
this.renderSortieBriefing(x + 34, y + 112, 520, 178, depth + 2);
|
||||
this.renderSortieChecklist(x + 576, y + 112, 550, 178, depth + 2);
|
||||
this.renderSortieUnitSummary(x + 34, y + 310, 1092, 252, depth + 2);
|
||||
this.renderSortieRewardHint(x + 34, y + 576, 696, 52, depth + 2);
|
||||
|
||||
this.addSortieButton('군영으로', x + width - 298, y + height - 44, 124, () => {
|
||||
soundDirector.playSelect();
|
||||
@@ -1239,8 +1246,8 @@ export class CampScene extends Phaser.Scene {
|
||||
bg.setStrokeStyle(1, palette.blue, 0.48);
|
||||
const allies = this.sortieAllies();
|
||||
const selectedCount = this.selectedSortieUnitIds.length;
|
||||
const rowGap = allies.length > 4 ? 24 : 30;
|
||||
const rowHeight = allies.length > 4 ? 22 : 26;
|
||||
const rowGap = allies.length > 4 ? 32 : 36;
|
||||
const rowHeight = allies.length > 4 ? 31 : 32;
|
||||
this.trackSortie(
|
||||
this.add.text(x + 18, y + 14, `출전 무장 선택 ${selectedCount}/${Math.min(maxSortieUnits, allies.length)}`, this.textStyle(18, '#f2e3bf', true))
|
||||
).setDepth(depth + 1);
|
||||
@@ -1250,6 +1257,7 @@ export class CampScene extends Phaser.Scene {
|
||||
const rowY = y + 48 + index * rowGap;
|
||||
const selected = this.isSortieSelected(unit.id);
|
||||
const required = requiredSortieUnitIds.has(unit.id);
|
||||
const summary = this.sortieUnitTacticalSummary(unit);
|
||||
const row = this.trackSortie(this.add.rectangle(x + 18, rowY - 5, width - 36, rowHeight, selected ? 0x172a22 : 0x151b24, selected ? 0.96 : 0.82));
|
||||
row.setOrigin(0);
|
||||
row.setDepth(depth + 1);
|
||||
@@ -1260,20 +1268,123 @@ export class CampScene extends Phaser.Scene {
|
||||
const marker = selected ? '출전' : '대기';
|
||||
this.trackSortie(this.add.text(x + 30, rowY, required ? '필수' : marker, this.textStyle(12, required ? '#ffdf7b' : selected ? '#a8ffd0' : '#9fb0bf', true))).setDepth(depth + 2);
|
||||
this.trackSortie(this.add.text(x + 84, rowY, `${unit.name} Lv ${unit.level}`, this.textStyle(14, selected ? '#f2e3bf' : '#87919c', true))).setDepth(depth + 2);
|
||||
this.trackSortie(this.add.text(x + 198, rowY, unit.className, this.textStyle(13, selected ? '#d4dce6' : '#77818c', true))).setDepth(depth + 2);
|
||||
this.trackSortie(this.add.text(x + 310, rowY, `병력 ${unit.hp}/${unit.maxHp}`, this.textStyle(13, selected ? '#d4dce6' : '#77818c', true))).setDepth(depth + 2);
|
||||
this.drawSortieBar(x + 414, rowY + 6, 102, 7, unit.hp / unit.maxHp, selected ? palette.green : 0x53606c, depth + 2);
|
||||
this.trackSortie(this.add.text(x + 218, rowY, `${unit.className} · ${getUnitClass(unit.classKey).role}`, this.textStyle(12, selected ? '#d4dce6' : '#77818c', true))).setDepth(depth + 2);
|
||||
this.trackSortie(this.add.text(x + 462, rowY, `병력 ${unit.hp}/${unit.maxHp}`, this.textStyle(12, selected ? '#d4dce6' : '#77818c', true))).setDepth(depth + 2);
|
||||
this.drawSortieBar(x + 554, rowY + 6, 86, 7, unit.hp / unit.maxHp, selected ? palette.green : 0x53606c, depth + 2);
|
||||
this.trackSortie(this.add.text(x + 666, rowY, summary.terrainLine, this.textStyle(11, selected ? '#d8b15f' : '#77818c', true))).setDepth(depth + 2);
|
||||
|
||||
const equipment = equipmentSlots
|
||||
.map((slot) => {
|
||||
const state = unit.equipment[slot];
|
||||
return `${equipmentSlotLabels[slot]} Lv${state.level}`;
|
||||
})
|
||||
.join(' ');
|
||||
this.trackSortie(this.add.text(x + 542, rowY, equipment, this.textStyle(12, selected ? '#d4dce6' : '#77818c'))).setDepth(depth + 2);
|
||||
this.renderSortieEquipmentIcons(unit, x + 84, rowY + 19, selected, depth + 2);
|
||||
this.trackSortie(this.add.text(x + 162, rowY + 18, summary.equipmentLine, this.textStyle(11, selected ? '#c8d2dd' : '#68727e'))).setDepth(depth + 2);
|
||||
this.trackSortie(this.add.text(x + 522, rowY + 18, summary.statLine, this.textStyle(11, selected ? '#c8d2dd' : '#68727e'))).setDepth(depth + 2);
|
||||
this.trackSortie(this.add.text(x + 760, rowY + 18, summary.bondLine, this.textStyle(11, selected ? '#a8ffd0' : '#68727e', selected))).setDepth(depth + 2);
|
||||
});
|
||||
}
|
||||
|
||||
private renderSortieEquipmentIcons(unit: UnitData, x: number, y: number, selected: boolean, depth: number) {
|
||||
equipmentSlots.forEach((slot, index) => {
|
||||
const state = unit.equipment[slot];
|
||||
const item = getItem(state.itemId);
|
||||
const iconFrame = this.trackSortie(this.add.rectangle(x + index * 23, y, 18, 18, selected && item.rank === 'treasure' ? 0x2c2630 : 0x0a1017, 0.92));
|
||||
iconFrame.setStrokeStyle(1, item.rank === 'treasure' ? palette.gold : 0x53606c, selected ? 0.62 : 0.34);
|
||||
iconFrame.setDepth(depth);
|
||||
const icon = this.trackSortie(this.add.image(x + index * 23, y, `item-${item.id}`));
|
||||
icon.setDisplaySize(14, 14);
|
||||
icon.setAlpha(selected ? 1 : 0.52);
|
||||
icon.setDepth(depth + 1);
|
||||
});
|
||||
}
|
||||
|
||||
private sortieUnitTacticalSummary(unit: UnitData): SortieUnitTacticalSummary {
|
||||
return {
|
||||
statLine: `무 ${unit.stats.might} 지 ${unit.stats.intelligence} 통 ${unit.stats.leadership} 민 ${unit.stats.agility} 운 ${unit.stats.luck}`,
|
||||
equipmentLine: this.sortieEquipmentLine(unit),
|
||||
bondLine: this.sortieBondLine(unit),
|
||||
terrainLine: this.sortieTerrainLine(unit)
|
||||
};
|
||||
}
|
||||
|
||||
private sortieEquipmentLine(unit: UnitData) {
|
||||
return equipmentSlots
|
||||
.map((slot) => {
|
||||
const state = unit.equipment[slot];
|
||||
const item = getItem(state.itemId);
|
||||
return `${item.name} Lv${state.level}`;
|
||||
})
|
||||
.join(' · ');
|
||||
}
|
||||
|
||||
private sortieBondLine(unit: UnitData) {
|
||||
const selected = new Set(this.selectedSortieUnitIds);
|
||||
const activeBonds = this.currentBonds()
|
||||
.filter((bond) => bond.unitIds.includes(unit.id))
|
||||
.map((bond) => {
|
||||
const partnerId = bond.unitIds.find((unitId) => unitId !== unit.id) ?? bond.unitIds[0];
|
||||
return {
|
||||
bond,
|
||||
partnerId,
|
||||
partnerName: this.unitName(partnerId),
|
||||
partnerSelected: selected.has(partnerId)
|
||||
};
|
||||
})
|
||||
.sort((a, b) => Number(b.partnerSelected) - Number(a.partnerSelected) || b.bond.level - a.bond.level || b.bond.exp - a.bond.exp);
|
||||
|
||||
const deployedBond = activeBonds.find((entry) => entry.partnerSelected);
|
||||
if (deployedBond) {
|
||||
return `공명 ${deployedBond.partnerName} Lv${deployedBond.bond.level}`;
|
||||
}
|
||||
|
||||
const strongestBond = activeBonds[0];
|
||||
if (strongestBond) {
|
||||
return `대기 공명 ${strongestBond.partnerName} Lv${strongestBond.bond.level}`;
|
||||
}
|
||||
|
||||
return '공명 관계 없음';
|
||||
}
|
||||
|
||||
private sortieTerrainLine(unit: UnitData) {
|
||||
const scenario = this.nextSortieScenario();
|
||||
if (!scenario) {
|
||||
return `${getUnitClass(unit.classKey).role}`;
|
||||
}
|
||||
|
||||
const terrainCounts = this.passableTerrainCounts(scenario);
|
||||
const unitClass = getUnitClass(unit.classKey);
|
||||
const entries = Object.entries(terrainCounts) as [TerrainType, number][];
|
||||
const total = entries.reduce((sum, [, count]) => sum + count, 0);
|
||||
if (total <= 0) {
|
||||
return `${unitClass.role}`;
|
||||
}
|
||||
|
||||
const weightedScore =
|
||||
entries.reduce((sum, [terrain, count]) => sum + (unitClass.terrainRatings[terrain] ?? 0) * count, 0) / total;
|
||||
const grade = weightedScore >= 110 ? '최적' : weightedScore >= 102 ? '유리' : weightedScore >= 95 ? '보통' : '주의';
|
||||
const bestTerrains = entries
|
||||
.sort((a, b) => (unitClass.terrainRatings[b[0]] ?? 0) - (unitClass.terrainRatings[a[0]] ?? 0) || b[1] - a[1])
|
||||
.slice(0, 2)
|
||||
.map(([terrain]) => terrainRules[terrain].label)
|
||||
.join('/');
|
||||
|
||||
return `지형 ${grade}${bestTerrains ? ` · ${bestTerrains}` : ''}`;
|
||||
}
|
||||
|
||||
private passableTerrainCounts(scenario: BattleScenarioDefinition) {
|
||||
const counts = {} as Record<TerrainType, number>;
|
||||
scenario.map.terrain.forEach((row) => {
|
||||
row.forEach((terrain) => {
|
||||
if (terrainRules[terrain].passable === false) {
|
||||
return;
|
||||
}
|
||||
counts[terrain] = (counts[terrain] ?? 0) + 1;
|
||||
});
|
||||
});
|
||||
return counts;
|
||||
}
|
||||
|
||||
private nextSortieScenario() {
|
||||
const nextBattleId = getSortieFlow(this.campaign?.latestBattleId).nextBattleId;
|
||||
return nextBattleId ? getBattleScenario(nextBattleId) : undefined;
|
||||
}
|
||||
|
||||
private renderSortieRewardHint(x: number, y: number, width: number, height: number, depth: number) {
|
||||
const bg = this.trackSortie(this.add.rectangle(x, y, width, height, 0x151f2a, 0.9));
|
||||
bg.setOrigin(0);
|
||||
@@ -2143,6 +2254,20 @@ export class CampScene extends Phaser.Scene {
|
||||
selectedUnitId: this.selectedUnitId,
|
||||
selectedDialogueId: this.selectedDialogueId,
|
||||
selectedSortieUnitIds: [...this.selectedSortieUnitIds],
|
||||
sortieRoster: this.sortieAllies().map((unit) => {
|
||||
const summary = this.sortieUnitTacticalSummary(unit);
|
||||
return {
|
||||
id: unit.id,
|
||||
name: unit.name,
|
||||
selected: this.isSortieSelected(unit.id),
|
||||
className: unit.className,
|
||||
classRole: getUnitClass(unit.classKey).role,
|
||||
statLine: summary.statLine,
|
||||
equipmentLine: summary.equipmentLine,
|
||||
bondLine: summary.bondLine,
|
||||
terrainLine: summary.terrainLine
|
||||
};
|
||||
}),
|
||||
campBattleId: this.currentCampBattleId(),
|
||||
campTitle: this.currentCampTitle(),
|
||||
availableDialogueIds: this.availableCampDialogues().map((dialogue) => dialogue.id),
|
||||
|
||||
Reference in New Issue
Block a user