This commit is contained in:
2026-04-28 19:36:39 +08:00
parent a9febe7678
commit f0471a4f8d
206 changed files with 18456 additions and 10133 deletions

View File

@@ -10,11 +10,7 @@
import {
applyQuestProgressFromSceneReached,
} from '../../data/questFlow';
import {
buildInitialNpcState,
getPreferredGiftItemId,
MAX_COMPANIONS,
} from '../../data/npcInteractions';
import { MAX_COMPANIONS } from '../../data/npcInteractions';
import { incrementGameRuntimeStats } from '../../data/runtimeStats';
import { ensureSceneEncounterPreview } from '../../data/sceneEncounterPreviews';
import { getScenePresetById } from '../../data/scenePresets';
@@ -53,11 +49,10 @@ export function getNpcEncounterKey(encounter: Encounter) {
return encounter.id ?? encounter.npcName;
}
function getResolvedNpcState(state: GameState, encounter: Encounter) {
return (
state.npcStates[getNpcEncounterKey(encounter)] ??
buildInitialNpcState(encounter, state.worldType)
);
function findPreferredTradeItemId(
items: Array<{ itemId: string; canSubmit: boolean }>,
) {
return items.find(item => item.canSubmit)?.itemId ?? items[0]?.itemId ?? null;
}
export function resolveNpcInteractionDecision(
@@ -73,29 +68,29 @@ export function resolveNpcInteractionDecision(
}
const encounter = state.currentEncounter;
const npcState = getResolvedNpcState(state, encounter);
switch (option.functionId) {
case NPC_TRADE_FUNCTION.id:
return {
kind: 'trade_modal',
modal: buildNpcTradeModalState(
state,
encounter,
option.actionText,
npcState.inventory,
findPreferredTradeItemId(
state.runtimeNpcInteraction?.trade.buyItems ?? [],
),
findPreferredTradeItemId(
state.runtimeNpcInteraction?.trade.sellItems ?? [],
),
),
};
case NPC_GIFT_FUNCTION.id:
{
const selectedGiftItemId = getPreferredGiftItemId(
state.playerInventory,
encounter,
{
worldType: state.worldType,
customWorldProfile: state.customWorldProfile,
},
);
const selectedGiftItemId =
state.runtimeNpcInteraction?.gift.items.find(item => item.canSubmit)
?.itemId ??
state.runtimeNpcInteraction?.gift.items[0]?.itemId ??
null;
if (!selectedGiftItemId) {
return { kind: 'none' };
}
@@ -103,7 +98,6 @@ export function resolveNpcInteractionDecision(
return {
kind: 'gift_modal',
modal: buildNpcGiftModalState(
state,
encounter,
option.actionText,
selectedGiftItemId,