mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
fix: 资源操作兼容Partial类型
将addResources和deductResources的参数类型由Resources调整为Partial<Resources>,避免部分字段缺失时报错。同步修正任务奖励发放逻辑,提升资源操作的健壮性。
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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<Resources>): 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<Resources>): void => {
|
||||
currentResources.metal += amount.metal || 0
|
||||
currentResources.crystal += amount.crystal || 0
|
||||
currentResources.deuterium += amount.deuterium || 0
|
||||
currentResources.darkMatter += amount.darkMatter || 0
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user