commit ea6361d6e63bc4a6d9f19e319b2bb2770627e78b
parent cbcb29d3cd7c621114d4befe6ad27b7d57cd776d
Author: Juan F. Meleiro <juan@juanmeleiro.mat.br>
Date: Mon, 27 Jan 2025 10:54:08 -0300
Improve devalueing logic
Diffstat:
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/absurdor b/absurdor
@@ -42,8 +42,6 @@ commands.devalue = commands.record:command("devalue", "Devalue the Veblen")
commands.devalue:argument("who", "Name of the player")
commands.devalue:argument("when", "When the devalueing took place")
:convert(maildate)
-commands.devalue:argument("value", "The new value")
- :convert(tonumber)
commands.devalue:option("-m", "Message ID where devalue happened"):target("where")
local args = parser:parse()
@@ -105,9 +103,13 @@ if args.command == "report" then
veblen.cost = e.payed + 1
veblen.namewidth = math.max(veblen.namewidth, string.len(e.who))
elseif e.what == "devalue" then
- die(e.value ~= math.ceil(veblen.cost/2), string.format("Recorded devalueing of the Veblen to an incorrect value (from %d to %d)", veblen.cost, e.value))
+ local val = math.ceil(veblen.cost/2)
table.insert(veblen.history, {when = e.when, what = "devalue", value = e.value})
veblen.cost = e.value
+ elseif e.what == "report" then
+ veblen.cost = e.cost or veblen.cost
+ end
+
local news = {}
for i,e in ipairs(log) do
if e.when > last then
diff --git a/lib/record.lua b/lib/record.lua
@@ -22,13 +22,22 @@ record.transfer = function(f, args, log)
end
record.devalue = function(f, args, log)
- f:write(string.format("%s devalued the Veblen to %d spendies.\n", args.who, args.value))
+ local val = 1
+ local max = 0
+ for _,e in ipairs(log) do
+ if e.what == "report" and e.when > max then
+ max = e.when
+ val = e.cost
+ end
+ end
+
+ f:write(string.format("%s devalued the Veblen to %d spendies.\n", args.who, math.ceil(val/2)))
table.insert(log, {
when = args.when,
what = "devalue",
who = args.who,
where = args.where,
- value = args.value
+ value = math.ceil(val/2)
})
end