From 9ea6fabbd10f8eb9a972aefde7be19bd8e3e9522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A6=E5=90=9B?= <73606411+setube@users.noreply.github.com> Date: Wed, 24 Dec 2025 02:51:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B5=84=E6=BA=90=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E5=85=BC=E5=AE=B9Partial=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将addResources和deductResources的参数类型由Resources调整为Partial,避免部分字段缺失时报错。同步修正任务奖励发放逻辑,提升资源操作的健壮性。 --- src/logic/campaignLogic.ts | 3 +-- src/logic/resourceLogic.ts | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/logic/campaignLogic.ts b/src/logic/campaignLogic.ts index 6aaac96..c2694aa 100644 --- a/src/logic/campaignLogic.ts +++ b/src/logic/campaignLogic.ts @@ -13,7 +13,6 @@ import { type QuestNotification, type CampaignQuestConfig, type NPC, - type Resources, RelationStatus, type BuildingType, type TechnologyType, @@ -357,7 +356,7 @@ export const claimQuestRewards = ( const currentPlanet = player.planets[0] // 默认发放到第一个星球 if (rewards.resources && currentPlanet) { - resourceLogic.addResources(currentPlanet.resources, rewards.resources as Resources) + resourceLogic.addResources(currentPlanet.resources, rewards.resources) } if (rewards.darkMatter && currentPlanet) { diff --git a/src/logic/resourceLogic.ts b/src/logic/resourceLogic.ts index 22b8b33..749a9be 100644 --- a/src/logic/resourceLogic.ts +++ b/src/logic/resourceLogic.ts @@ -256,21 +256,21 @@ export const checkResourcesAvailable = (currentResources: Resources, cost: Resou /** * 扣除资源 */ -export const deductResources = (currentResources: Resources, cost: Resources): void => { - currentResources.metal -= cost.metal - currentResources.crystal -= cost.crystal - currentResources.deuterium -= cost.deuterium - currentResources.darkMatter -= cost.darkMatter +export const deductResources = (currentResources: Resources, cost: Partial): void => { + currentResources.metal -= cost.metal || 0 + currentResources.crystal -= cost.crystal || 0 + currentResources.deuterium -= cost.deuterium || 0 + currentResources.darkMatter -= cost.darkMatter || 0 } /** * 添加资源 */ -export const addResources = (currentResources: Resources, amount: Resources): void => { - currentResources.metal += amount.metal - currentResources.crystal += amount.crystal - currentResources.deuterium += amount.deuterium - currentResources.darkMatter += amount.darkMatter +export const addResources = (currentResources: Resources, amount: Partial): void => { + currentResources.metal += amount.metal || 0 + currentResources.crystal += amount.crystal || 0 + currentResources.deuterium += amount.deuterium || 0 + currentResources.darkMatter += amount.darkMatter || 0 } /**