Skip to content

Commit 1599ba2

Browse files
added pick and drop
1 parent a8ba703 commit 1599ba2

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
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.4";
4+
config.version = "0.0.5";
55

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

data/items.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ items.bottle = function(position,content)-- 2.5 liters
5353
return self;
5454
end
5555

56+
items.smallbox = function(position, content)
57+
local self = Item("smallbox", "container", position);
58+
self.creator = "unknown";
59+
self.maxStorage = 12;
60+
self.items = content or {};
61+
return self;
62+
end
63+
5664
items.corn = function(position)
5765
local self = Item("corn", "food", position);
5866
self.creator = "god";

main.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ end
180180

181181
br.player = player;
182182
br.getitem(player, "bottle", "water");
183-
for x = 1, 10 do
184-
br.getitem(player, "bread");
185-
end
183+
br.getitem(player, "smallbox", "bread")
186184

187185
br.inventory = br.player.items;
188186

@@ -194,6 +192,20 @@ br.skills = function()
194192
br.help(br.player.skills);
195193
end
196194

195+
br.drop = function(itemid)
196+
if itemid == nil then
197+
print("drop <itemid>");
198+
return;
199+
end
200+
player.plan("drop", {itemid});
201+
world.passTurn();
202+
end
203+
204+
br.pick = function(direction)
205+
player.plan("pick", {direction});
206+
world.passTurn();
207+
end
208+
197209
br.items = function()
198210
for x = 1, #br.player.items do
199211
local text = x .. ". ";
@@ -213,7 +225,7 @@ br.items = function()
213225
txt = txt .. v*100 .. "ml of " .. k .. ", ";
214226
end
215227
--remove the last , and space
216-
text = text .. txt:sub(1, -3) .. "\n";
228+
text = text .. txt:sub(1, -3);
217229
else
218230
for k,v in pairs(content) do
219231
text = text .. v .. " " .. k .. "s";

types/Creature.lua

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,43 @@ local creatureSleep = function(creature, world)
365365
end
366366
end
367367
creature.needs.current.sleep = creature.needs.current.sleep + 10;
368+
end
369+
370+
local creatureDrop = function(creature, world, itemid)
371+
local item;
372+
if creature.items[itemid] then
373+
item = table.remove(creature.items, itemid);
374+
item.position["global"] = br.utils.table.clone(creature.position["global"]);
375+
item.position["local"] = br.utils.table.clone(creature.position["local"]);
376+
table.insert(world.map[creature.position["global"].x][creature.position["global"].y].items, item);
377+
print(creature.name .. " dropped " .. item.name);
378+
end
379+
end
380+
381+
local creaturePick = function(creature, world, direction)
382+
local room = world.map[creature.position["global"].x][creature.position["global"].y];
368383

384+
if direction == "up" then
385+
direction = {x = 0, y = -1};
386+
elseif direction == "down" then
387+
direction = {x = 0, y = 1};
388+
elseif direction == "left" then
389+
direction = {x = -1, y = 0};
390+
elseif direction == "right" then
391+
direction = {x = 1, y = 0};
392+
else
393+
direction = {x = 0, y = 0};
394+
end
395+
396+
for k,v in pairs(room.items) do
397+
if v.position["local"].x == creature.position["local"].x + direction.x and v.position["local"].y == creature.position["local"].y + direction.y then
398+
local item = table.remove(room.items, k);
399+
item.position = creature.position;
400+
table.insert(creature.items, v);
401+
print(creature.name .. " picked " .. item.name);
402+
break;
403+
end
404+
end
369405
end
370406

371407
local function Creature(name)
@@ -388,7 +424,9 @@ local function Creature(name)
388424
consume = creatureConsume,
389425
pee = creaturePee,
390426
poo = creaturePoo,
391-
sleep = creatureSleep
427+
sleep = creatureSleep,
428+
drop = creatureDrop,
429+
pick = creaturePick
392430
};
393431

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

0 commit comments

Comments
 (0)