fix: 资源操作兼容Partial类型

将addResources和deductResources的参数类型由Resources调整为Partial<Resources>,避免部分字段缺失时报错。同步修正任务奖励发放逻辑,提升资源操作的健壮性。
This commit is contained in:
谦君
2025-12-24 02:51:27 +08:00
parent 5a06022798
commit 9ea6fabbd1
2 changed files with 11 additions and 12 deletions

View File

@@ -13,7 +13,6 @@ import {
type QuestNotification, type QuestNotification,
type CampaignQuestConfig, type CampaignQuestConfig,
type NPC, type NPC,
type Resources,
RelationStatus, RelationStatus,
type BuildingType, type BuildingType,
type TechnologyType, type TechnologyType,
@@ -357,7 +356,7 @@ export const claimQuestRewards = (
const currentPlanet = player.planets[0] // 默认发放到第一个星球 const currentPlanet = player.planets[0] // 默认发放到第一个星球
if (rewards.resources && currentPlanet) { if (rewards.resources && currentPlanet) {
resourceLogic.addResources(currentPlanet.resources, rewards.resources as Resources) resourceLogic.addResources(currentPlanet.resources, rewards.resources)
} }
if (rewards.darkMatter && currentPlanet) { if (rewards.darkMatter && currentPlanet) {

View File

@@ -256,21 +256,21 @@ export const checkResourcesAvailable = (currentResources: Resources, cost: Resou
/** /**
* 扣除资源 * 扣除资源
*/ */
export const deductResources = (currentResources: Resources, cost: Resources): void => { export const deductResources = (currentResources: Resources, cost: Partial<Resources>): void => {
currentResources.metal -= cost.metal currentResources.metal -= cost.metal || 0
currentResources.crystal -= cost.crystal currentResources.crystal -= cost.crystal || 0
currentResources.deuterium -= cost.deuterium currentResources.deuterium -= cost.deuterium || 0
currentResources.darkMatter -= cost.darkMatter currentResources.darkMatter -= cost.darkMatter || 0
} }
/** /**
* 添加资源 * 添加资源
*/ */
export const addResources = (currentResources: Resources, amount: Resources): void => { export const addResources = (currentResources: Resources, amount: Partial<Resources>): void => {
currentResources.metal += amount.metal currentResources.metal += amount.metal || 0
currentResources.crystal += amount.crystal currentResources.crystal += amount.crystal || 0
currentResources.deuterium += amount.deuterium currentResources.deuterium += amount.deuterium || 0
currentResources.darkMatter += amount.darkMatter currentResources.darkMatter += amount.darkMatter || 0
} }
/** /**