Skip to content

Commit 46f85ee

Browse files
added put and remove actions
1 parent 1599ba2 commit 46f85ee

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

data/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local config = {};
22

33
config.title = "brutopolis";
4-
config.version = "0.0.5";
4+
config.version = "0.0.5a";
55

66
config.mapSize = {x = 32, y = 32};
77
config.minRoomSize = {x = 5, y = 5};

main.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,22 @@ br.pick = function(direction)
206206
world.passTurn();
207207
end
208208

209+
br.put = function(itemid, containerid, other)
210+
if containerid == "in" or containerid == "inside" then
211+
containerid = other;
212+
end
213+
player.plan("put", {itemid, containerid});
214+
world.passTurn();
215+
end
216+
217+
br.remove = function(itemid, containerid, other)
218+
if containerid == "from" then
219+
containerid = other;
220+
end
221+
player.plan("remove", {itemid, containerid});
222+
world.passTurn();
223+
end
224+
209225
br.items = function()
210226
for x = 1, #br.player.items do
211227
local text = x .. ". ";
@@ -228,8 +244,10 @@ br.items = function()
228244
text = text .. txt:sub(1, -3);
229245
else
230246
for k,v in pairs(content) do
231-
text = text .. v .. " " .. k .. "s";
247+
text = text .. v .. " " .. k .. "s, ";
232248
end
249+
--remove the last , and space
250+
text = text:sub(1, -3);
233251
end
234252
else
235253
text = text .. br.player.items[x].name;

types/Creature.lua

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,58 @@ local creaturePick = function(creature, world, direction)
404404
end
405405
end
406406

407+
local creaturePut = function(creature, world, itemid, containerid)
408+
local container = creature.items[containerid];
409+
local item = creature.items[itemid];
410+
if container and item then
411+
if container.maxStorage <= 0 then
412+
print(creature.name .. " can't put " .. item.name .. " in " .. container.name .. " because it's not a container");
413+
elseif container.liquidContainer then
414+
if not item.liquid then
415+
print(creature.name .. " can't put " .. item.name .. " in " .. container.name .. " because it's not a liquid");
416+
elseif #container.items >= container.maxStorage then
417+
print(creature.name .. " can't put " .. item.name .. " in " .. container.name .. " because it's full");
418+
else
419+
local _item = table.remove(creature.items, itemid);
420+
table.insert(container.items, _item);
421+
print(creature.name .. " put " .. _item.name .. " in " .. container.name);
422+
end
423+
elseif #container.items >= container.maxStorage then
424+
print(creature.name .. " can't put " .. item.name .. " in " .. container.name .. " because it's full");
425+
elseif item.maxStorage > 0 then
426+
if item.liquidContainer then
427+
if #item.items > 0 then
428+
local _item = table.remove(creature.items, itemid);
429+
table.insert(container.items, _item);
430+
print(creature.name .. " put " .. _item.name .. " in " .. container.name);
431+
end
432+
else
433+
print(creature.name .. " can't put a container(" .. item.name .. ") in antoher container(" .. container.name .. ")");
434+
end
435+
else
436+
local _item = table.remove(creature.items, itemid);
437+
table.insert(container.items, _item);
438+
print(creature.name .. " put " .. _item.name .. " in " .. container.name);
439+
end
440+
end
441+
end
442+
443+
local creatureRemove = function(creature, world, itemid, containerid)
444+
local container = creature.items[containerid];
445+
local item = container.items[itemid];
446+
if container and item then
447+
if container.maxStorage <= 0 then
448+
print(creature.name .. " can't remove " .. item.name .. " from " .. container.name .. " because it's not a container");
449+
elseif #container.items <= 0 then
450+
print(creature.name .. " can't remove " .. item.name .. " from " .. container.name .. " because it's empty");
451+
else
452+
local _item = table.remove(container.items, itemid);
453+
table.insert(creature.items, _item);
454+
print(creature.name .. " removed " .. _item.name .. " from " .. container.name);
455+
end
456+
end
457+
end
458+
407459
local function Creature(name)
408460
local self = {};
409461

@@ -426,7 +478,9 @@ local function Creature(name)
426478
poo = creaturePoo,
427479
sleep = creatureSleep,
428480
drop = creatureDrop,
429-
pick = creaturePick
481+
pick = creaturePick,
482+
put = creaturePut,
483+
remove = creatureRemove
430484
};
431485

432486
self.plan = function(action, args, index)

0 commit comments

Comments
 (0)