reworked the item deck for ease of use for the new shuffle algorithm

This commit is contained in:
duncathan 2019-03-11 06:12:11 -06:00
parent 80ffb75261
commit a47664f854
2 changed files with 41 additions and 26 deletions

View file

@ -135,32 +135,32 @@ local data = {
keySpot = { keySpot = {
requirements = {}, requirements = {},
map = "Weed", map = "Weed",
event = "#0000" event = "#0700"
}, },
jellyCapsule = { jellyCapsule = {
requirements = {}, requirements = {},
map = "Weed", map = "Weed",
event = "#0000" event = "#0701"
}, },
santa = { santa = {
requirements = {{"santaKey"}}, requirements = {{"santaKey"}},
map = "Santa", map = "Santa",
event = "#0000" event = "#0501"
}, },
charcoal = { charcoal = {
requirements = {{"santaKey", "juice"}}, requirements = {{"santaKey", "juice"}},
map = "Santa", map = "Santa",
event = "#0000" event = "#0302"
} }
chaco = { chaco = {
requirements = {{"santaKey"}, {"fireball"}}, requirements = {{"santaKey"}},
map = "Chako", map = "Chako",
event = "#6969" event = "#0211"
}, },
kulala = { kulala = {
requirements = {{"santaKey", "weaponBoss"}, {"fireball"}}, requirements = {{"santaKey", "weaponBoss"}},
map = "Weed", map = "Weed",
event = "0000" event = "0702"
} }
} }
}, },
@ -173,37 +173,37 @@ local data = {
kazuma1 = { kazuma1 = {
requirements = {}, requirements = {},
map = "Weed", map = "Weed",
event = "#0000" event = "#0800"
}, },
kazuma2 = { kazuma2 = {
requirements = {{"eventFans"}}, requirements = {{"eventFans"}},
map = "Weed", map = "Weed",
event = "#0000" event = "#0801"
}, },
execution = { execution = {
requirements = {{"weaponSN"}}, requirements = {{"weaponSN"}},
map = "WeedD", map = "WeedD",
event = "#0000" event = "#0305"
}, },
outsideHut = { outsideHut = {
requirements = {{"eventFans"}, {"flight"}}, requirements = {{"eventFans"}, {"flight"}},
map = "Weed", map = "Weed",
event = "#0000" event = "#0302"
}, },
hutChest = { hutChest = {
requirements = {{"eventFans"}, {"flight"}}, requirements = {{"eventFans"}, {"flight"}},
map = "WeedB", map = "WeedB",
event = "#0000" event = "#0300"
}, },
gumChest = { gumChest = {
requirements = {{"eventFans", "gumKey", "weaponBoss"}, {"flight", "gumKey", "weaponBoss"}}, requirements = {{"eventFans", "gumKey", "weaponBoss"}, {"flight", "gumKey", "weaponBoss"}},
map = "Frog", map = "Frog",
event = "#0000" event = "#0300"
}, },
malco = { malco = {
requirements = {{"eventFans", "juice", "charcoal", "gum"}}, requirements = {{"eventFans", "juice", "charcoal", "gum"}},
map = "Malco", map = "Malco",
event = "#0000" event = "#0350"
} }
}, },
events = { events = {

View file

@ -8,27 +8,31 @@ function C:new()
local item = _.clone(v) local item = _.clone(v)
table.insert(self._left, item) table.insert(self._left, item)
end end
self._placed = {}
end end
local function _filterAny(item) return true end local function _filterAny(item) return true end
local function _filterAnyExceptMissiles(item) return item.kind ~= "missiles" end
local function _filterWeapon(item) return item.kind == "weapon" end
function C:getAny() function C:getAny()
return self:_getItem(_filterAny) return self:_getItem(_filterAny)
end end
function C:getAnyExceptMissiles() function C:getAnyByAttribute(attribute)
return self:_getItem(_filterAnyExceptMissiles) function _filterAnyByAttribute(item, attribute)
for k, v in pairs(item.attributes) do
if v == attribute then return true
end
return false
end
return self:_getItem(_filterAnyByAttribute)
end end
function C:getByKey(key) function C:placeAny()
local filterByKey = function(item) return item.key == key end return self:place(self:getAny())
return self:_getItem(filterByKey)
end end
function C:getWeapon() function C:placeAnyByAttribute(attributes)
return self:_getItem(_filterWeapon) return self:place(self:getAnyByAttribute(attributes))
end end
function C:_getItem(filterFn) function C:_getItem(filterFn)
@ -46,9 +50,20 @@ function C:_getItem(filterFn)
-- Select an item. -- Select an item.
local selected = _.sample(applicable) local selected = _.sample(applicable)
local index = indexMap[selected] local index = indexMap[selected]
table.remove(self._left, index)
return selected return selected, index
end
function C:place(item, index)
table.remove(self._left, index)
table.insert(self._placed, item)
return item
end
function C:getPlacedItems(item)
local placed = {table.unpack(self._placed)} -- clone the table
if(item) then table.insert(placed, item) end
return placed
end end
return C return C