fix(server): frisch gekaufte Flaschen sind nicht mehr leer
Lint / Lint Resource (push) Has been cancelled

Eine Flasche ohne gesetzte Metadata - aus dem Shop, per AddItem oder per
Admin-Befehl - wurde in getTankList als 0 gelesen. Anlegen scheiterte damit an
"Diese Tauchflasche ist leer!", man haette also erst eine Kartusche verbrauchen
muessen, um ueberhaupt tauchen zu koennen.

Dazu waren sich die beiden Codepfade uneinig: syncTank hat denselben Fall auf
capacity zurueckfallen lassen, also als voll behandelt.

Beide gehen jetzt ueber readOxygen(), gesteuert von shared.newTanksFull
(default true = neue Flasche ist voll).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-11 00:31:37 +02:00
co-authored by Claude Opus 5
parent c264872007
commit 3ab70d44ef
3 changed files with 27 additions and 3 deletions
+17 -3
View File
@@ -5,6 +5,21 @@ local shared = require 'config.shared'
--- niemand verbrauchen.
local lastSync = {}
--- Restluft eines Slots. Ohne gesetzte Metadata (frisch aus dem Shop, per AddItem
--- oder Admin-Befehl) entscheidet newTanksFull, ob die Flasche voll oder leer ist.
--- Muss überall dieselbe Antwort geben, sonst hält die eine Stelle die Flasche für
--- leer und die andere für voll.
--- @return number
local function readOxygen(slot, tankConfig)
local stored = tonumber(slot.metadata and slot.metadata.oxygen)
if not stored then
return shared.newTanksFull and tankConfig.capacity or 0
end
return math.max(0, math.min(stored, tankConfig.capacity))
end
--- @param source number
--- @param slotId number
--- @return table? slot, table? tankConfig
@@ -60,13 +75,12 @@ local function getTankList(source)
if slots then
for j = 1, #slots do
local slot = slots[j]
local oxygen = tonumber(slot.metadata and slot.metadata.oxygen) or 0
tanks[#tanks + 1] = {
slot = slot.slot,
name = name,
label = (exports.ox_inventory:Items(name) or {}).label or name,
oxygen = math.max(0, math.min(oxygen, tankConfig.capacity)),
oxygen = readOxygen(slot, tankConfig),
capacity = tankConfig.capacity,
pressure = tankConfig.pressure
}
@@ -87,7 +101,7 @@ local function syncTank(source, slotId, oxygen)
if not slot then return end
local current = tonumber(slot.metadata and slot.metadata.oxygen) or tankConfig.capacity
local current = readOxygen(slot, tankConfig)
local now = os.time()
local elapsed = lastSync[source] and (now - lastSync[source]) or shared.syncIntervalSeconds