Repository navigation
feat: 新增插件 HerbBloom / BottleRefund / NurseHeal;TerraNews 草药提醒 - #1215
Conversation
There was a problem hiding this comment.
你好——我发现了 8 个问题
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/NurseHeal/PaymentService.cs" line_range="82-87" />
<code_context>
+ var filled = new List<int>();
+ if (!AllocateChange(change, free, filled))
+ {
+ foreach (Snapshot s in snapshot)
+ {
+ s.Item.type = s.Type;
+ s.Item.stack = s.Stack;
+ s.Item.prefix = s.Prefix;
+ }
+ return DeductResult.Fail("背包无法容纳找零(空间不足),本次未扣费");
+ }
</code_context>
<issue_to_address>
**Rejected treatment creates coins**
When change needs more slots than are available, after allocation has filled at least one originally empty slot, `AllocateChange` writes partial change before returning false, but the failure branch restores only the original coin snapshots. The new stacks remain alongside the restored balance, so the player keeps extra coins after treatment is refused.
Clear every partially filled originally empty slot during rollback, or calculate the required slots before mutating the inventory.
Also at `src/NurseHeal/PaymentService.cs:121-122`.
</issue_to_address>
### Comment 2
<location path="src/BottleRefund/BottleRefundPlugin.cs" line_range="51-53" />
<code_context>
+
+ private static string ConfigPath => Path.Combine(TShock.SavePath, "BottleRefund.json");
+
+ // 网络槽位:0..TrashItem-1 为主背包/钱币/弹药区;TrashItem 为垃圾桶;≥Bank1_0 为各类银行。
+ // 只跟踪主背包区,垃圾桶与银行整体排除。
+ private static readonly int SlotRange = PlayerItemSlotID.TrashItem;
+
+ private volatile BottleRefundConfig? _config;
</code_context>
<issue_to_address>
**Storage moves earn refunds**
When a player moves a one-count potion from the tracked inventory into a bank or the trash, `OnPlayerSlot` ignores destination slots at or beyond `TrashItem`, so `Settle` sees the unmatched inventory decrease as drinking a potion and grants a bottle.
Track bank and trash destination changes, or otherwise exclude storage moves from drink detection.
Also at `src/BottleRefund/BottleRefundPlugin.cs:173-174`, `src/BottleRefund/BottleRefundPlugin.cs:418-419`.
</issue_to_address>
### Comment 3
<location path="src/BottleRefund/BottleRefundPlugin.cs" line_range="164-192" />
<code_context>
+ private void OnPlayerSlot(object? sender, GetDataHandlers.PlayerSlotEventArgs e)
</code_context>
<issue_to_address>
**Forged inventory deltas grant free items**
When a non-SSC player can submit accepted `PlayerSlot` updates for a potion slot, `OnPlayerSlot` records client-reported stack changes as inventory deltas, and `Settle` counts an unmatched one-item decrease as a drink before `GiveItem` issues the configured refund. A player can submit a valid potion stack increase followed by a one-item decrease, earning refunds without consuming potions.
Base refunds on a server-authoritative potion-consumption signal, or otherwise verify the slot change against server-owned inventory state before treating it as a drink.
Also at `src/BottleRefund/BottleRefundPlugin.cs:418-419`, `src/BottleRefund/BottleRefundPlugin.cs:445`.
</issue_to_address>
### Comment 4
<location path="src/NurseHeal/PaymentService.cs" line_range="18" />
<code_context>
+{
+ private sealed record CoinSlot(Item Item, int SlotId);
+
+ private const int CoinStackMax = 999; // 原版钱币堆叠上限(旧版误用 100,白白多占 10 倍槽位)
+
+ private static readonly int[] CoinIds = { 71, 72, 73, 74 };
</code_context>
<issue_to_address>
**Change uses undersized coin stacks**
When the change fits within the coin item's actual stack limit but requires multiple stacks of 999, `AllocateChange` limits coin stacks to 999 instead of using the coin item's stack limit, so it requires extra slots and rejects a treatment the inventory could hold.
Use each coin item's actual `maxStack` when splitting change.
Also at `src/NurseHeal/PaymentService.cs:119`.
</issue_to_address>
### Comment 5
<location path="src/BottleRefund/BottleRefundPlugin.cs" line_range="228-235" />
<code_context>
+ long key = ((long)e.ID << 8) | (byte)e.Slot;
+ lock (_lock)
+ {
+ _chestMirror.TryGetValue(key, out var old);
+ _chestMirror[key] = (e.Type, e.Stacks);
+ var ledger = GetLedger(plr.Index, Now);
+ if (old.Type == e.Type)
+ {
+ int delta = e.Stacks - old.Stack;
+ if (delta > 0 && _potionSet.Contains(e.Type))
+ AddEntry(ledger, ledger.ChestIncreases, Now, e.Type, delta);
+ }
+ else if (e.Type > 0 && e.Stacks > 0 && _potionSet.Contains(e.Type))
</code_context>
<issue_to_address>
**Chest changes hide consumed potions**
When the first observed change to a pre-filled potion chest slot is a deposit or partial withdrawal, and the player drinks the same potion before settlement, `_chestMirror` has no baseline for the slot, so the first update can be recorded as an increase equal to the resulting stack. `Settle` can match that phantom increase to the drink and withhold the refund.
Establish the chest slot's current stack as a baseline before recording subsequent deposit deltas.
</issue_to_address>
### Comment 6
<location path="src/BottleRefund/BottleRefundPlugin.cs" line_range="481" />
<code_context>
+ for (int i = 0; i < incs.Count; i++)
+ {
+ var e = incs[i];
+ if (!e.Used && e.Amount == dec.Amount && e.Time >= dec.Time - 0.5)
+ {
+ e.Used = true;
</code_context>
<issue_to_address>
**Later pickups suppress refunds**
When a player gains an equal-sized stack of the same potion after drinking and before settlement, `TryMatchExact` matches an increase occurring after a decrease, so it classifies the drink as a move and the player receives no refund.
Restrict move matching to inventory changes that can represent the other side of the same move, rather than matching later gains.
</issue_to_address>
### Comment 7
<location path="src/HerbBloom/HerbBloomPlugin.cs" line_range="216" />
<code_context>
+ ushort type = tile.type;
+ if (type == TileMature || (scanImmature && type == TileImmature))
+ {
+ _pending.Enqueue(new PendingChange { X = (short)x, Y = (short)y, ExpectedType = type });
+ found++;
+ }
</code_context>
<issue_to_address>
**Overlapping scans accelerate growth**
When active players' scan areas overlap around immature herbs, `ScanCycle` queues the same herb from each overlapping area, and `Pump` rolls the growth chance for every queued copy. The herb therefore matures faster than its configured per-scan probability.
Deduplicate pending herb coordinates before queuing or processing growth rolls.
Also at `src/HerbBloom/HerbBloomPlugin.cs:176`, `src/HerbBloom/HerbBloomPlugin.cs:307`.
</issue_to_address>
### Comment 8
<location path="src/BottleRefund/BottleRefundConfig.cs" line_range="86-89" />
<code_context>
+
+ public void Sanitize()
+ {
+ RefundChance = Math.Max(0.0, Math.Min(1.0, RefundChance));
+ RefundCountPerDrink = Math.Max(0, Math.Min(999, RefundCountPerDrink));
+ RefundItemId = Math.Max(1, Math.Min(10000, RefundItemId));
+ SettlementDelaySeconds = Math.Max(1.0, Math.Min(300.0, SettlementDelaySeconds));
+ LedgerLimit = Math.Max(10, Math.Min(100000, LedgerLimit));
+ if (Blacklist == null)
</code_context>
<issue_to_address>
**NaN values evade config bounds**
When a configuration file contains a NaN floating-point value accepted by Json.NET, `Math.Min`/`Math.Max` leave `NaN` unchanged. In BottleRefund, a NaN settlement delay makes the readiness comparison false, so ledgers never settle and refunds are eventually dropped; in HerbBloom, a NaN growth chance makes both rejection comparisons false, so every scanned immature herb matures.
Reject or replace non-finite floating-point settings before applying the bounds.
Also at `src/HerbBloom/HerbBloomConfig.cs:98-99`.
</issue_to_address>Original comment in English
Hey - I've found 8 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/NurseHeal/PaymentService.cs" line_range="82-87" />
<code_context>
+ var filled = new List<int>();
+ if (!AllocateChange(change, free, filled))
+ {
+ foreach (Snapshot s in snapshot)
+ {
+ s.Item.type = s.Type;
+ s.Item.stack = s.Stack;
+ s.Item.prefix = s.Prefix;
+ }
+ return DeductResult.Fail("背包无法容纳找零(空间不足),本次未扣费");
+ }
</code_context>
<issue_to_address>
**Rejected treatment creates coins**
When change needs more slots than are available, after allocation has filled at least one originally empty slot, `AllocateChange` writes partial change before returning false, but the failure branch restores only the original coin snapshots. The new stacks remain alongside the restored balance, so the player keeps extra coins after treatment is refused.
Clear every partially filled originally empty slot during rollback, or calculate the required slots before mutating the inventory.
Also at `src/NurseHeal/PaymentService.cs:121-122`.
</issue_to_address>
### Comment 2
<location path="src/BottleRefund/BottleRefundPlugin.cs" line_range="51-53" />
<code_context>
+
+ private static string ConfigPath => Path.Combine(TShock.SavePath, "BottleRefund.json");
+
+ // 网络槽位:0..TrashItem-1 为主背包/钱币/弹药区;TrashItem 为垃圾桶;≥Bank1_0 为各类银行。
+ // 只跟踪主背包区,垃圾桶与银行整体排除。
+ private static readonly int SlotRange = PlayerItemSlotID.TrashItem;
+
+ private volatile BottleRefundConfig? _config;
</code_context>
<issue_to_address>
**Storage moves earn refunds**
When a player moves a one-count potion from the tracked inventory into a bank or the trash, `OnPlayerSlot` ignores destination slots at or beyond `TrashItem`, so `Settle` sees the unmatched inventory decrease as drinking a potion and grants a bottle.
Track bank and trash destination changes, or otherwise exclude storage moves from drink detection.
Also at `src/BottleRefund/BottleRefundPlugin.cs:173-174`, `src/BottleRefund/BottleRefundPlugin.cs:418-419`.
</issue_to_address>
### Comment 3
<location path="src/BottleRefund/BottleRefundPlugin.cs" line_range="164-192" />
<code_context>
+ private void OnPlayerSlot(object? sender, GetDataHandlers.PlayerSlotEventArgs e)
</code_context>
<issue_to_address>
**Forged inventory deltas grant free items**
When a non-SSC player can submit accepted `PlayerSlot` updates for a potion slot, `OnPlayerSlot` records client-reported stack changes as inventory deltas, and `Settle` counts an unmatched one-item decrease as a drink before `GiveItem` issues the configured refund. A player can submit a valid potion stack increase followed by a one-item decrease, earning refunds without consuming potions.
Base refunds on a server-authoritative potion-consumption signal, or otherwise verify the slot change against server-owned inventory state before treating it as a drink.
Also at `src/BottleRefund/BottleRefundPlugin.cs:418-419`, `src/BottleRefund/BottleRefundPlugin.cs:445`.
</issue_to_address>
### Comment 4
<location path="src/NurseHeal/PaymentService.cs" line_range="18" />
<code_context>
+{
+ private sealed record CoinSlot(Item Item, int SlotId);
+
+ private const int CoinStackMax = 999; // 原版钱币堆叠上限(旧版误用 100,白白多占 10 倍槽位)
+
+ private static readonly int[] CoinIds = { 71, 72, 73, 74 };
</code_context>
<issue_to_address>
**Change uses undersized coin stacks**
When the change fits within the coin item's actual stack limit but requires multiple stacks of 999, `AllocateChange` limits coin stacks to 999 instead of using the coin item's stack limit, so it requires extra slots and rejects a treatment the inventory could hold.
Use each coin item's actual `maxStack` when splitting change.
Also at `src/NurseHeal/PaymentService.cs:119`.
</issue_to_address>
### Comment 5
<location path="src/BottleRefund/BottleRefundPlugin.cs" line_range="228-235" />
<code_context>
+ long key = ((long)e.ID << 8) | (byte)e.Slot;
+ lock (_lock)
+ {
+ _chestMirror.TryGetValue(key, out var old);
+ _chestMirror[key] = (e.Type, e.Stacks);
+ var ledger = GetLedger(plr.Index, Now);
+ if (old.Type == e.Type)
+ {
+ int delta = e.Stacks - old.Stack;
+ if (delta > 0 && _potionSet.Contains(e.Type))
+ AddEntry(ledger, ledger.ChestIncreases, Now, e.Type, delta);
+ }
+ else if (e.Type > 0 && e.Stacks > 0 && _potionSet.Contains(e.Type))
</code_context>
<issue_to_address>
**Chest changes hide consumed potions**
When the first observed change to a pre-filled potion chest slot is a deposit or partial withdrawal, and the player drinks the same potion before settlement, `_chestMirror` has no baseline for the slot, so the first update can be recorded as an increase equal to the resulting stack. `Settle` can match that phantom increase to the drink and withhold the refund.
Establish the chest slot's current stack as a baseline before recording subsequent deposit deltas.
</issue_to_address>
### Comment 6
<location path="src/BottleRefund/BottleRefundPlugin.cs" line_range="481" />
<code_context>
+ for (int i = 0; i < incs.Count; i++)
+ {
+ var e = incs[i];
+ if (!e.Used && e.Amount == dec.Amount && e.Time >= dec.Time - 0.5)
+ {
+ e.Used = true;
</code_context>
<issue_to_address>
**Later pickups suppress refunds**
When a player gains an equal-sized stack of the same potion after drinking and before settlement, `TryMatchExact` matches an increase occurring after a decrease, so it classifies the drink as a move and the player receives no refund.
Restrict move matching to inventory changes that can represent the other side of the same move, rather than matching later gains.
</issue_to_address>
### Comment 7
<location path="src/HerbBloom/HerbBloomPlugin.cs" line_range="216" />
<code_context>
+ ushort type = tile.type;
+ if (type == TileMature || (scanImmature && type == TileImmature))
+ {
+ _pending.Enqueue(new PendingChange { X = (short)x, Y = (short)y, ExpectedType = type });
+ found++;
+ }
</code_context>
<issue_to_address>
**Overlapping scans accelerate growth**
When active players' scan areas overlap around immature herbs, `ScanCycle` queues the same herb from each overlapping area, and `Pump` rolls the growth chance for every queued copy. The herb therefore matures faster than its configured per-scan probability.
Deduplicate pending herb coordinates before queuing or processing growth rolls.
Also at `src/HerbBloom/HerbBloomPlugin.cs:176`, `src/HerbBloom/HerbBloomPlugin.cs:307`.
</issue_to_address>
### Comment 8
<location path="src/BottleRefund/BottleRefundConfig.cs" line_range="86-89" />
<code_context>
+
+ public void Sanitize()
+ {
+ RefundChance = Math.Max(0.0, Math.Min(1.0, RefundChance));
+ RefundCountPerDrink = Math.Max(0, Math.Min(999, RefundCountPerDrink));
+ RefundItemId = Math.Max(1, Math.Min(10000, RefundItemId));
+ SettlementDelaySeconds = Math.Max(1.0, Math.Min(300.0, SettlementDelaySeconds));
+ LedgerLimit = Math.Max(10, Math.Min(100000, LedgerLimit));
+ if (Blacklist == null)
</code_context>
<issue_to_address>
**NaN values evade config bounds**
When a configuration file contains a NaN floating-point value accepted by Json.NET, `Math.Min`/`Math.Max` leave `NaN` unchanged. In BottleRefund, a NaN settlement delay makes the readiness comparison false, so ledgers never settle and refunds are eventually dropped; in HerbBloom, a NaN growth chance makes both rejection comparisons false, so every scanned immature herb matures.
Reject or replace non-finite floating-point settings before applying the bounds.
Also at `src/HerbBloom/HerbBloomConfig.cs:98-99`.
</issue_to_address>| foreach (Snapshot s in snapshot) | ||
| { | ||
| s.Item.type = s.Type; | ||
| s.Item.stack = s.Stack; | ||
| s.Item.prefix = s.Prefix; | ||
| } |
There was a problem hiding this comment.
🔴 严重 · 拒绝治疗后仍会产生金币
当找零所需的槽位多于可用槽位时,如果分配过程已经填充了至少一个原本为空的槽位,AllocateChange 会在返回 false 前写入部分找零;但失败分支只会恢复原有金币快照。新金币堆会与恢复后的余额同时保留,因此玩家在治疗被拒绝后仍会得到额外金币。
回滚时清空所有被部分填充的原本空槽位,或者在修改物品栏之前先计算所需槽位。
另见 src/NurseHeal/PaymentService.cs:121-122。
供 AI 代理使用的提示
在 `src/NurseHeal/PaymentService.cs` 第 82-87 行:
**拒绝治疗后仍会产生金币**
当找零所需的槽位多于可用槽位时,如果分配过程已经填充了至少一个原本为空的槽位,`AllocateChange` 会在返回 false 前写入部分找零;但失败分支只会恢复原有金币快照。新金币堆会与恢复后的余额同时保留,因此玩家在治疗被拒绝后仍会得到额外金币。
回滚时清空所有被部分填充的原本空槽位,或者在修改物品栏之前先计算所需槽位。
另见 `src/NurseHeal/PaymentService.cs:121-122`。Original comment in English
🔴 Critical · Rejected treatment creates coins
When change needs more slots than are available, after allocation has filled at least one originally empty slot, AllocateChange writes partial change before returning false, but the failure branch restores only the original coin snapshots. The new stacks remain alongside the restored balance, so the player keeps extra coins after treatment is refused.
Clear every partially filled originally empty slot during rollback, or calculate the required slots before mutating the inventory.
Also at src/NurseHeal/PaymentService.cs:121-122.
Prompt for AI agents
In `src/NurseHeal/PaymentService.cs` at lines 82-87:
**Rejected treatment creates coins**
When change needs more slots than are available, after allocation has filled at least one originally empty slot, `AllocateChange` writes partial change before returning false, but the failure branch restores only the original coin snapshots. The new stacks remain alongside the restored balance, so the player keeps extra coins after treatment is refused.
Clear every partially filled originally empty slot during rollback, or calculate the required slots before mutating the inventory.
Also at `src/NurseHeal/PaymentService.cs:121-122`.| // 网络槽位:0..TrashItem-1 为主背包/钱币/弹药区;TrashItem 为垃圾桶;≥Bank1_0 为各类银行。 | ||
| // 只跟踪主背包区,垃圾桶与银行整体排除。 | ||
| private static readonly int SlotRange = PlayerItemSlotID.TrashItem; |
There was a problem hiding this comment.
🟠 高 · 存储物品也会获得退款
当玩家将一瓶数量为 1 的药水从受跟踪的物品栏移入银行或垃圾栏时,OnPlayerSlot 会忽略索引大于或等于 TrashItem 的目标槽位,因此 Settle 会把未匹配的物品栏数量减少视为喝掉了药水,并发放一瓶药水。
跟踪银行和垃圾栏中的目标槽位变更,或以其他方式排除存储移动,不将其判定为饮用。
另见 src/BottleRefund/BottleRefundPlugin.cs:173-174、src/BottleRefund/BottleRefundPlugin.cs:418-419。
供 AI 代理使用的提示
在 `src/BottleRefund/BottleRefundPlugin.cs` 第 51-53 行:
**存储物品也会获得退款**
当玩家将一瓶数量为 1 的药水从受跟踪的物品栏移入银行或垃圾栏时,`OnPlayerSlot` 会忽略索引大于或等于 `TrashItem` 的目标槽位,因此 `Settle` 会把未匹配的物品栏数量减少视为喝掉了药水,并发放一瓶药水。
跟踪银行和垃圾栏中的目标槽位变更,或以其他方式排除存储移动,不将其判定为饮用。
另见 `src/BottleRefund/BottleRefundPlugin.cs:173-174`、`src/BottleRefund/BottleRefundPlugin.cs:418-419`。Original comment in English
🟠 High · Storage moves earn refunds
When a player moves a one-count potion from the tracked inventory into a bank or the trash, OnPlayerSlot ignores destination slots at or beyond TrashItem, so Settle sees the unmatched inventory decrease as drinking a potion and grants a bottle.
Track bank and trash destination changes, or otherwise exclude storage moves from drink detection.
Also at src/BottleRefund/BottleRefundPlugin.cs:173-174, src/BottleRefund/BottleRefundPlugin.cs:418-419.
Prompt for AI agents
In `src/BottleRefund/BottleRefundPlugin.cs` at lines 51-53:
**Storage moves earn refunds**
When a player moves a one-count potion from the tracked inventory into a bank or the trash, `OnPlayerSlot` ignores destination slots at or beyond `TrashItem`, so `Settle` sees the unmatched inventory decrease as drinking a potion and grants a bottle.
Track bank and trash destination changes, or otherwise exclude storage moves from drink detection.
Also at `src/BottleRefund/BottleRefundPlugin.cs:173-174`, `src/BottleRefund/BottleRefundPlugin.cs:418-419`.| private void OnPlayerSlot(object? sender, GetDataHandlers.PlayerSlotEventArgs e) | ||
| { | ||
| var cfg = _config; | ||
| if (cfg == null || !cfg.Enabled) | ||
| return; | ||
| var plr = e.Player; | ||
| if (plr == null || e.PlayerId != plr.Index || plr.IgnoreSSCPackets) | ||
| return; | ||
| int slot = e.Slot; | ||
| if (slot < 0 || slot >= SlotRange) | ||
| return; | ||
|
|
||
| lock (_lock) | ||
| { | ||
| var st = GetMirror(plr.Index); | ||
| int oldType = st.Type[slot]; | ||
| int oldStack = st.Stack[slot]; | ||
| st.Type[slot] = (short)e.Type; | ||
| st.Stack[slot] = (short)e.Stack; | ||
| double t = Now; | ||
| var ledger = GetLedger(plr.Index, t); | ||
|
|
||
| if (oldType == e.Type) | ||
| { | ||
| int delta = e.Stack - oldStack; | ||
| if (delta == 0) | ||
| return; | ||
| if (_potionSet.Contains(e.Type)) | ||
| AddEntry(ledger, delta < 0 ? ledger.Decreases : ledger.Increases, t, e.Type, Math.Abs(delta)); |
There was a problem hiding this comment.
🟡 中 · 伪造物品栏变化可免费获得物品
如果非 SSC 玩家可以提交被接受的药水槽 PlayerSlot 更新,OnPlayerSlot 就会将客户端报告的堆叠变化记录为物品栏变化;随后 Settle 会把未匹配的单件减少计为饮用,再由 GiveItem 发放配置的退款。玩家可以先提交有效的药水堆叠增加,再提交单件减少,从而不消耗药水也能获得退款。
应基于服务器权威的药水消耗信号发放退款;或者在将槽位变化视为饮用之前,根据服务器持有的物品栏状态进行核验。
另见 src/BottleRefund/BottleRefundPlugin.cs:418-419、src/BottleRefund/BottleRefundPlugin.cs:445。
供 AI 代理使用的提示
在 `src/BottleRefund/BottleRefundPlugin.cs` 第 164-192 行:
**伪造物品栏变化可免费获得物品**
如果非 SSC 玩家可以提交被接受的药水槽 `PlayerSlot` 更新,`OnPlayerSlot` 就会将客户端报告的堆叠变化记录为物品栏变化;随后 `Settle` 会把未匹配的单件减少计为饮用,再由 `GiveItem` 发放配置的退款。玩家可以先提交有效的药水堆叠增加,再提交单件减少,从而不消耗药水也能获得退款。
应基于服务器权威的药水消耗信号发放退款;或者在将槽位变化视为饮用之前,根据服务器持有的物品栏状态进行核验。
另见 `src/BottleRefund/BottleRefundPlugin.cs:418-419`、`src/BottleRefund/BottleRefundPlugin.cs:445`。Original comment in English
🟡 Medium · Forged inventory deltas grant free items
When a non-SSC player can submit accepted PlayerSlot updates for a potion slot, OnPlayerSlot records client-reported stack changes as inventory deltas, and Settle counts an unmatched one-item decrease as a drink before GiveItem issues the configured refund. A player can submit a valid potion stack increase followed by a one-item decrease, earning refunds without consuming potions.
Base refunds on a server-authoritative potion-consumption signal, or otherwise verify the slot change against server-owned inventory state before treating it as a drink.
Also at src/BottleRefund/BottleRefundPlugin.cs:418-419, src/BottleRefund/BottleRefundPlugin.cs:445.
Prompt for AI agents
In `src/BottleRefund/BottleRefundPlugin.cs` at lines 164-192:
**Forged inventory deltas grant free items**
When a non-SSC player can submit accepted `PlayerSlot` updates for a potion slot, `OnPlayerSlot` records client-reported stack changes as inventory deltas, and `Settle` counts an unmatched one-item decrease as a drink before `GiveItem` issues the configured refund. A player can submit a valid potion stack increase followed by a one-item decrease, earning refunds without consuming potions.
Base refunds on a server-authoritative potion-consumption signal, or otherwise verify the slot change against server-owned inventory state before treating it as a drink.
Also at `src/BottleRefund/BottleRefundPlugin.cs:418-419`, `src/BottleRefund/BottleRefundPlugin.cs:445`.| { | ||
| private sealed record CoinSlot(Item Item, int SlotId); | ||
|
|
||
| private const int CoinStackMax = 999; // 原版钱币堆叠上限(旧版误用 100,白白多占 10 倍槽位) |
There was a problem hiding this comment.
🟡 中 · 找零使用了容量过小的金币堆
当找零总量没有超过金币物品的实际堆叠上限,但需要拆分成多个 999 枚的金币堆时,AllocateChange 会将金币堆限制为 999 枚,而不是使用金币物品的堆叠上限,因此需要更多槽位,并拒绝本可放入物品栏的治疗。
拆分找零时使用每种金币物品的实际 maxStack。
另见 src/NurseHeal/PaymentService.cs:119。
供 AI 代理使用的提示
在 `src/NurseHeal/PaymentService.cs` 第 18 行:
**找零使用了容量过小的金币堆**
当找零总量没有超过金币物品的实际堆叠上限,但需要拆分成多个 999 枚的金币堆时,`AllocateChange` 会将金币堆限制为 999 枚,而不是使用金币物品的堆叠上限,因此需要更多槽位,并拒绝本可放入物品栏的治疗。
拆分找零时使用每种金币物品的实际 `maxStack`。
另见 `src/NurseHeal/PaymentService.cs:119`。Original comment in English
🟡 Medium · Change uses undersized coin stacks
When the change fits within the coin item's actual stack limit but requires multiple stacks of 999, AllocateChange limits coin stacks to 999 instead of using the coin item's stack limit, so it requires extra slots and rejects a treatment the inventory could hold.
Use each coin item's actual maxStack when splitting change.
Also at src/NurseHeal/PaymentService.cs:119.
Prompt for AI agents
In `src/NurseHeal/PaymentService.cs` at line 18:
**Change uses undersized coin stacks**
When the change fits within the coin item's actual stack limit but requires multiple stacks of 999, `AllocateChange` limits coin stacks to 999 instead of using the coin item's stack limit, so it requires extra slots and rejects a treatment the inventory could hold.
Use each coin item's actual `maxStack` when splitting change.
Also at `src/NurseHeal/PaymentService.cs:119`.| _chestMirror.TryGetValue(key, out var old); | ||
| _chestMirror[key] = (e.Type, e.Stacks); | ||
| var ledger = GetLedger(plr.Index, Now); | ||
| if (old.Type == e.Type) | ||
| { | ||
| int delta = e.Stacks - old.Stack; | ||
| if (delta > 0 && _potionSet.Contains(e.Type)) | ||
| AddEntry(ledger, ledger.ChestIncreases, Now, e.Type, delta); |
There was a problem hiding this comment.
🟡 中 · 箱子变化会掩盖已饮用的药水
如果预先装有药水的箱子槽位首次观察到的变化是存入物品或部分取出,并且玩家在结算前喝下了同一种药水,_chestMirror 就没有该槽位的基准值,因此首次更新可能会被记录为增加了相当于最终堆叠数量的数量。Settle 可能会将这次虚假的增加与饮用操作匹配,从而不发放退款。
在记录后续存入变化之前,先将箱子槽位当前的堆叠数量设为基准值。
供 AI 代理使用的提示
在 `src/BottleRefund/BottleRefundPlugin.cs` 第 228-235 行:
**箱子变化会掩盖已饮用的药水**
如果预先装有药水的箱子槽位首次观察到的变化是存入物品或部分取出,并且玩家在结算前喝下了同一种药水,`_chestMirror` 就没有该槽位的基准值,因此首次更新可能会被记录为增加了相当于最终堆叠数量的数量。`Settle` 可能会将这次虚假的增加与饮用操作匹配,从而不发放退款。
在记录后续存入变化之前,先将箱子槽位当前的堆叠数量设为基准值。Original comment in English
🟡 Medium · Chest changes hide consumed potions
When the first observed change to a pre-filled potion chest slot is a deposit or partial withdrawal, and the player drinks the same potion before settlement, _chestMirror has no baseline for the slot, so the first update can be recorded as an increase equal to the resulting stack. Settle can match that phantom increase to the drink and withhold the refund.
Establish the chest slot's current stack as a baseline before recording subsequent deposit deltas.
Prompt for AI agents
In `src/BottleRefund/BottleRefundPlugin.cs` at lines 228-235:
**Chest changes hide consumed potions**
When the first observed change to a pre-filled potion chest slot is a deposit or partial withdrawal, and the player drinks the same potion before settlement, `_chestMirror` has no baseline for the slot, so the first update can be recorded as an increase equal to the resulting stack. `Settle` can match that phantom increase to the drink and withhold the refund.
Establish the chest slot's current stack as a baseline before recording subsequent deposit deltas.| for (int i = 0; i < incs.Count; i++) | ||
| { | ||
| var e = incs[i]; | ||
| if (!e.Used && e.Amount == dec.Amount && e.Time >= dec.Time - 0.5) |
There was a problem hiding this comment.
🟡 中 · 后续拾取会导致退款被抑制
如果玩家喝药后、结算前拾取了数量相同的同种药水堆叠,TryMatchExact 会将减少之后发生的增加匹配起来,因此会把饮用判定为物品移动,玩家也就收不到退款。
仅将移动匹配限制在可能代表同一次移动另一端的物品栏变化中,不要匹配之后发生的拾取。
供 AI 代理使用的提示
在 `src/BottleRefund/BottleRefundPlugin.cs` 第 481 行:
**后续拾取会导致退款被抑制**
如果玩家喝药后、结算前拾取了数量相同的同种药水堆叠,`TryMatchExact` 会将减少之后发生的增加匹配起来,因此会把饮用判定为物品移动,玩家也就收不到退款。
仅将移动匹配限制在可能代表同一次移动另一端的物品栏变化中,不要匹配之后发生的拾取。Original comment in English
🟡 Medium · Later pickups suppress refunds
When a player gains an equal-sized stack of the same potion after drinking and before settlement, TryMatchExact matches an increase occurring after a decrease, so it classifies the drink as a move and the player receives no refund.
Restrict move matching to inventory changes that can represent the other side of the same move, rather than matching later gains.
Prompt for AI agents
In `src/BottleRefund/BottleRefundPlugin.cs` at line 481:
**Later pickups suppress refunds**
When a player gains an equal-sized stack of the same potion after drinking and before settlement, `TryMatchExact` matches an increase occurring after a decrease, so it classifies the drink as a move and the player receives no refund.
Restrict move matching to inventory changes that can represent the other side of the same move, rather than matching later gains.| ushort type = tile.type; | ||
| if (type == TileMature || (scanImmature && type == TileImmature)) | ||
| { | ||
| _pending.Enqueue(new PendingChange { X = (short)x, Y = (short)y, ExpectedType = type }); |
There was a problem hiding this comment.
🟡 中 · 重叠扫描会加快生长
当活跃玩家的扫描区域在未成熟的草药附近重叠时,ScanCycle 会从每个重叠区域都将同一株草药加入队列,而 Pump 会对队列中的每个副本都进行一次生长概率判定。因此,草药成熟的速度会快于配置的单次扫描概率所预期的速度。
在将待处理的草药坐标加入队列或进行生长概率判定之前,先对其去重。
另见 src/HerbBloom/HerbBloomPlugin.cs:176、src/HerbBloom/HerbBloomPlugin.cs:307。
供 AI 代理使用的提示
在 `src/HerbBloom/HerbBloomPlugin.cs` 第 216 行:
**重叠扫描会加快生长**
当活跃玩家的扫描区域在未成熟的草药附近重叠时,`ScanCycle` 会从每个重叠区域都将同一株草药加入队列,而 `Pump` 会对队列中的每个副本都进行一次生长概率判定。因此,草药成熟的速度会快于配置的单次扫描概率所预期的速度。
在将待处理的草药坐标加入队列或进行生长概率判定之前,先对其去重。
另见 `src/HerbBloom/HerbBloomPlugin.cs:176`、`src/HerbBloom/HerbBloomPlugin.cs:307`。Original comment in English
🟡 Medium · Overlapping scans accelerate growth
When active players' scan areas overlap around immature herbs, ScanCycle queues the same herb from each overlapping area, and Pump rolls the growth chance for every queued copy. The herb therefore matures faster than its configured per-scan probability.
Deduplicate pending herb coordinates before queuing or processing growth rolls.
Also at src/HerbBloom/HerbBloomPlugin.cs:176, src/HerbBloom/HerbBloomPlugin.cs:307.
Prompt for AI agents
In `src/HerbBloom/HerbBloomPlugin.cs` at line 216:
**Overlapping scans accelerate growth**
When active players' scan areas overlap around immature herbs, `ScanCycle` queues the same herb from each overlapping area, and `Pump` rolls the growth chance for every queued copy. The herb therefore matures faster than its configured per-scan probability.
Deduplicate pending herb coordinates before queuing or processing growth rolls.
Also at `src/HerbBloom/HerbBloomPlugin.cs:176`, `src/HerbBloom/HerbBloomPlugin.cs:307`.| RefundChance = Math.Max(0.0, Math.Min(1.0, RefundChance)); | ||
| RefundCountPerDrink = Math.Max(0, Math.Min(999, RefundCountPerDrink)); | ||
| RefundItemId = Math.Max(1, Math.Min(10000, RefundItemId)); | ||
| SettlementDelaySeconds = Math.Max(1.0, Math.Min(300.0, SettlementDelaySeconds)); |
There was a problem hiding this comment.
🟡 中 · NaN 值可绕过配置边界限制
当配置文件包含 Json.NET 接受的 NaN 浮点值时,Math.Min/Math.Max 会让 NaN 保持不变。在 BottleRefund 中,NaN 结算延迟会导致就绪状态比较结果为 false,因此账本永远不会结算,退款最终会被丢弃;在 HerbBloom 中,NaN 生长概率会使两项拒绝比较都返回 false,因此每株被扫描到的未成熟草药都会成熟。
在应用边界限制之前,拒绝或替换非有限浮点设置。
另见 src/HerbBloom/HerbBloomConfig.cs:98-99。
供 AI 代理使用的提示
在 `src/BottleRefund/BottleRefundConfig.cs` 第 86-89 行:
**NaN 值可绕过配置边界限制**
当配置文件包含 Json.NET 接受的 NaN 浮点值时,`Math.Min`/`Math.Max` 会让 `NaN` 保持不变。在 BottleRefund 中,NaN 结算延迟会导致就绪状态比较结果为 false,因此账本永远不会结算,退款最终会被丢弃;在 HerbBloom 中,NaN 生长概率会使两项拒绝比较都返回 false,因此每株被扫描到的未成熟草药都会成熟。
在应用边界限制之前,拒绝或替换非有限浮点设置。
另见 `src/HerbBloom/HerbBloomConfig.cs:98-99`。Original comment in English
🟡 Medium · NaN values evade config bounds
When a configuration file contains a NaN floating-point value accepted by Json.NET, Math.Min/Math.Max leave NaN unchanged. In BottleRefund, a NaN settlement delay makes the readiness comparison false, so ledgers never settle and refunds are eventually dropped; in HerbBloom, a NaN growth chance makes both rejection comparisons false, so every scanned immature herb matures.
Reject or replace non-finite floating-point settings before applying the bounds.
Also at src/HerbBloom/HerbBloomConfig.cs:98-99.
Prompt for AI agents
In `src/BottleRefund/BottleRefundConfig.cs` at lines 86-89:
**NaN values evade config bounds**
When a configuration file contains a NaN floating-point value accepted by Json.NET, `Math.Min`/`Math.Max` leave `NaN` unchanged. In BottleRefund, a NaN settlement delay makes the readiness comparison false, so ledgers never settle and refunds are eventually dropped; in HerbBloom, a NaN growth chance makes both rejection comparisons false, so every scanned immature herb matures.
Reject or replace non-finite floating-point settings before applying the bounds.
Also at `src/HerbBloom/HerbBloomConfig.cs:98-99`.
新增 3 个自研插件 + 2 个更新(TShock 6.2.1 · Terraria 1.4.5.8,作者:不是现在):
新增
更新
全部在本仓库模板(TShock 6.2.1)下编译通过(0 警告 0 错误),配置驱动、无游戏内指令。
Sourcery 摘要
新增三个可配置的游戏玩法插件,并扩展 TerraNews,加入草药采收通知,同时统一插件元数据。
新功能:
改进:
构建:
文档:
Original summary in English
Summary by Sourcery
Add three configurable gameplay plugins and expand TerraNews with herb harvest notifications while standardizing plugin metadata.
New Features:
Enhancements:
Build:
Documentation: