Stackables
Reported by Mikael Lind | November 13th, 2008 @ 04:00 PM
local clone_ignore = {
env = true,
first_inv = true,
last_inv = true,
next_inv = true,
prev_inv = true,
}
function clone(self)
local result = getmetatable(self):new()
for key, value in pairs(self) do
if not clone_ignore[key] then
result[key] = value
end
end
return result
end
function Thing:split(count)
if count >= 1 and count < self.count then
local result = self:clone()
result.count = count
self.count = self.count - count
return result
else
return self
end
end
function Thing:can_join(other)
if not self.stackable or getmetatable(self) ~= getmetatable(other) then
return false
end
for key, value in pairs(self) do
if key ~= "count" and self[key] ~= other[key] then
return false
end
end
for key, value in pairs(other) do
if key ~= "count" and self[key] ~= other[key] then
return false
end
end
return true
end
function Thing:join(other)
if self:can_join(other) then
self.count = self.count + other.count
other.count = 0
return self
else
return other
end
end
No comments found
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Moonshine is a roguelike computer game written in Lua.