diff options
author | ubq323 <ubq323@ubq323.website> | 2023-08-26 08:22:06 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-08-26 08:22:06 +0100 |
commit | e95fc908f3952737e41efce88c83ce7414e130b0 (patch) | |
tree | 42795f0bd98a7e790005ac6d5f41a0f836e5e8ea /server/server.lua | |
parent | aace7b1f9c80f5cb4b155d8b2db51f355b6f81b2 (diff) |
add player inventories
Diffstat (limited to 'server/server.lua')
-rw-r--r-- | server/server.lua | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/server/server.lua b/server/server.lua index 8a725af..3ec467c 100644 --- a/server/server.lua +++ b/server/server.lua @@ -48,6 +48,9 @@ end local function chat_packet(fromplayer,msg) return json.encode{t="chat",from=fromplayer.id,msg=msg} end +local function inv_packet(inv) + return json.encode{t='inv',inv=inv} +end local map = MapS:make() @@ -128,8 +131,19 @@ local function handle_player_packet(player,ev) end elseif op == "settile" then local h = coords.Hex:make(j.q,j.r) - map:set_at(h,j.tile) - -- print(player.id,"settile",h,j.tile) + local old_tile = map:at(h) + local new_tile = j.tile + local inv = player.inv + + if old_tile == 0 then + inv[new_tile] = (inv[new_tile] or 0) - 1 + elseif new_tile == 0 then + inv[old_tile] = (inv[old_tile] or 0) + 1 + end + player.peer:send(inv_packet(inv)) + + map:set_at(h, new_tile) + for i,otherplayer in ipairs(playerlist) do if otherplayer ~= player then -- same packet structure s2c as c2s |