From e1cdfd20f92b2030bfe302184f61a72215c4acc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Sat, 20 Sep 2025 17:44:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=89=A9=E5=93=81=E7=B3=BB=E7=BB=9F):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=89=A9=E5=93=81=E6=94=B6=E9=9B=86=E5=92=8C?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E4=B8=8A=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在EntityBase.gd中添加物品数量上限检查,防止库存溢出 在ItemDropped.gd中增加收集条件,仅在库存未满时收集物品 --- scripts/Statemachine/EntityBase.gd | 2 +- scripts/Statemachine/ItemDropped.gd | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/Statemachine/EntityBase.gd b/scripts/Statemachine/EntityBase.gd index 0a84532..1dc4784 100644 --- a/scripts/Statemachine/EntityBase.gd +++ b/scripts/Statemachine/EntityBase.gd @@ -362,7 +362,7 @@ func useItem(items: Dictionary): return state func getItem(items: Dictionary): for item in items: - inventory[item] += items[item] + inventory[item] = clamp(inventory[item] + items[item], 0, inventoryMax[item]) func getTrackingAnchor() -> Vector2: return hurtbox.get_node("hitbox").global_position diff --git a/scripts/Statemachine/ItemDropped.gd b/scripts/Statemachine/ItemDropped.gd index 4f980d2..5640e03 100644 --- a/scripts/Statemachine/ItemDropped.gd +++ b/scripts/Statemachine/ItemDropped.gd @@ -35,8 +35,9 @@ func _physics_process(_delta): if targetPlayer.sprinting: apply_central_force((position - targetPlayer.texture.global_position).normalized() * targetPlayer.velocity.length() * 10) else: - targetPlayer.collectItem(item, stackCount) - collect() + if targetPlayer.inventoryMax[item] > targetPlayer.inventory[item]: + targetPlayer.collectItem(item, stackCount) + collect() func collect(): collecting = true