Randomizer largely works! Just need to fill in item database now, mostly.

This commit is contained in:
shru 2018-12-14 23:22:03 -05:00
parent 5fffdcc659
commit dec51b6b33
3 changed files with 188 additions and 52 deletions

View file

@ -1,48 +1,145 @@
return {
-- Weapons
-- wXXX = {
-- name = "",
-- map = "",
-- getText = "",
-- command = "",
-- displayCmd = "",
-- kind = "weapon",
-- },
wBubbler = {
name = "Bubbler",
map = "Comu",
getText = "Got the =Bubbler=!",
command = "<AM+0007:0100",
displayCmd = "<GIT0007",
function weapon(t)
assert(t.name and t.map and t.id and t.ammo)
return {
name = t.name,
map = t.map,
getText = ("Got the =%s=!<WAI0160<NOD"):format(t.name),
command = ("<AM+00%s:%s"):format(t.id, t.ammo),
displayCmd = ("<GIT00%s"):format(t.id),
music = "<CMU0010",
kind = "weapon",
},
wPolar = {
}
end
function lifeCapsule(t)
assert(t.hp and t.map)
return {
name = ("Life Capsule (+%d)"):format(t.hp),
map = t.map,
getText = {
("Got a =Life Capsule=!<WAI0160<NOD\n\r Max health increased by %d!"):format(t.hp),
"Got a =Life Capsule=!<WAI0160<NOD", -- erase the extra wait for most things.
},
command = ("<ML+000%d"):format(t.hp),
displayCmd = "<GIT1006",
music = "<CMU0016",
erase = ("Max health increased by %d!<NOD"):format(t.hp),
}
end
return {
-------------------
-- WEAPONS --
-------------------
wPolarStar = weapon({
name = "Polar Star",
map = "Pole",
getText = "Got the =Polar Star=!",
command = "<AM+0002:0000",
displayCmd = "<GIT0002",
kind = "weapon",
},
-- Items
id = "02",
ammo = "0000",
}),
wBubbler = weapon({
name = "Bubbler",
map = "Comu",
id = "07",
ammo = "0100",
}),
-------------------
-- LIFE CAPSULES --
-------------------
lFirstCave = lifeCapsule({
hp = 3,
map = "Cave",
}),
lYamashitaFarm = lifeCapsule({
hp = 3,
map = "Plant",
}),
lEggCorridorA = lifeCapsule({
hp = 3,
map = "Eggs",
}),
-- !!!! Can't randomize this one until I do some label-aware shit !!!!
-- Egg Corridor: Go through Cthulhu's Abode and out the top door. +4 HP.
-- lEggCorridorB = lifeCapsule({
-- hp = 4,
-- map = "Plant",
-- }),
-- Bushlands: Just past where you found Santa's Key, go east to a set of two
-- horizontal rows of star blocks, jump on them and to the left. +5 HP.
-- Bushlands: In the Execution Chamber, the tall building with the skull on it
-- to the right of Kazuma's shack. +5 HP.
-- Sand Zone: East of Curly's House and past the Sun Stones, it's in the top of
-- the first thick pillar made up of star blocks. Try not to blow up all the star
-- blocks when fighting the Polishes to create a path and reach it. +5 HP.
-- Sand Zone: At the end of the hidden path behind a pawpad block on the far
-- right wall between the Sun Stones and Jenka's house, behind a line of star
-- blocks. Found next to a chest containing one of Jenka's dogs. +5 HP.
-- Labyrinth: Nestled next to the left wall of the first room of the labyrinth
-- when you're sent there, a ways up into the room. +5 HP.
-- Plantation: Sitting on a platform hanging from the far upper-left ceiling.
-- +4 HP.
-- Plantation: Talk to the puppy that appears on the left platform just under
-- the red skull signs on the top right section of the Plantation after Momorin's
-- finished the rocket. +5 HP.
-- Sanctuary: Bonus life capsule. Found in plain sight as you make your
-- initial descent. +5 HP.
-----------
-- ITEMS --
-----------
iPanties = {
name = "Curly's Panties",
map = "CurlyS",
getText = "Found =Curly's Underwear=.",
-- getText = "Found =Curly's Panties=.", -- Grrr
getText = {
"Found =Curly's Panties=.",
"Found =Curly's Underwear=.",
},
command = "<IT+0035",
displayCmd = "<GIT1035",
kind = "item",
},
}
-- #0200
-- <KEY<FLJ1640:0201<FL+1640<SOU0022<CNP0200:0021:0000
-- <MSGOpened the chest.<NOD<GIT0002<AM+0002:0000<CLR
-- <CMU0010Got the =Polar Star=!<WAI0160<NOD<GIT0000<CLO<RMU
-- <MSG
-- From somewhere, a transmission...<FAO0004<NOD<TRA0018:0501:0002:0000
--[[
-- #0420
-- <KEY<DNP0420<MSG<GIT1035<IT+0035
-- Found Curly's Panties.<NOD<END
<KEY<FLJ1640:0201<FL+1640<SOU0022<CNP0200:0021:0000
<MSGOpened the chest.<NOD<GIT0002<AM+0002:0000<CLR
<CMU0010Got the =Polar Star=!<WAI0160<NOD<GIT0000<CLO<RMU
#0301
<KEY<GIT1008<MSGDo you want to use the
=Jellyfish Juice=?<YNJ0000<CLO<GIT0000
<IT-0008<ANP0300:0010:0000<WAI0030<FLJ0442:0302<FL+0442
<MSGYou find something in the
ashes...<NOD<CLR<GIT0007<AM+0007:0100
<CMU0010Got the =Bubbler=!<WAI0160<NOD<CLO<RMU<DNP0300<END
<PRI<SOU0022<DNP0400<CMU0016
<MSG<GIT1006Got a =Life Capsule=!<WAI0160<NOD<RMU<ML+0003
Max health increased by 3!<NOD<END
#0400
<PRI<FL+0101<SOU0022<DNP0400<CMU0016
<MSG<GIT1006Got a =Life Capsule=!<WAI0160<NOD<RMU<ML+0003
Max health increased by 3!<NOD<END
<KEY<DNP0420<MSG<GIT1035<IT+0035
Found Curly's Panties.<NOD<END
-- TODO:
#0401
<PRI<FL+0102<SOU0022<DNP0401<CLR<CMU0016
<MSG<GIT1006Got a =Life Capsule=!<WAI0160<NOD<RMU<ML+0004
Max health increased by 4!<NOD<END
]]

View file

@ -6,7 +6,7 @@ Serpent = require 'lib.serpent'
lf = love.filesystem
local LOG_LEVEL = 4
local LOG_LEVEL = 3
local function _log(level, prefix, text, ...)
if LOG_LEVEL >= level then
print(prefix .. text, ...)

View file

@ -36,11 +36,61 @@ function C:hasUnreplacedItems()
return #self._unreplaced >= 1
end
local function _stringReplace(text, needle, replacement)
function C:replaceItem(replacement)
assert(self:hasUnreplacedItems())
local original = table.remove(self._unreplaced)
local template = "[%s] %s -> %s"
logNotice(template:format(self._mapName, original.name, replacement.name))
-- Erase first, in case replace attribute would place some text that would match here...
if original.erase then
local erases = original.erase
if type(erases) == 'string' then
erases = {erases}
end
for _, erase in ipairs(erases) do
self._text = self:_stringReplace(self._text, erase, '')
end
end
self:_replaceAttribute(original, replacement, 'command')
self:_replaceAttribute(original, replacement, 'getText')
self:_replaceAttribute(original, replacement, 'displayCmd')
self:_replaceAttribute(original, replacement, 'music')
end
function C:_replaceAttribute(original, replacement, attribute)
local originalTexts = original[attribute]
if originalTexts == nil then
return
elseif type(originalTexts) == 'string' then
originalTexts = {originalTexts}
end
local replaceText = replacement[attribute] or ''
if type(replaceText) == 'table' then
replaceText = replaceText[1]
end
-- Loop through each possible original value until we successfully replace one.
for _, originalText in ipairs(originalTexts) do
local changed
self._text, changed = self:_stringReplace(self._text, originalText, replaceText)
if changed then
return
end
end
local template = 'Unable to replace original "%s" for %s.'
logWarning(template:format(attribute, original.name))
end
function C:_stringReplace(text, needle, replacement)
local i = text:find(needle, 1, true)
if i == nil then
logWarning(('Unable to replace "%s" with "%s"'):format(needle, replacement))
return text
-- logWarning(('Unable to replace "%s" with "%s"'):format(needle, replacement))
return text, false
end
local len = needle:len()
local j = i + len - 1
@ -48,18 +98,7 @@ local function _stringReplace(text, needle, replacement)
assert((j % 1 == 0), tostring(j))
local a = text:sub(1, i - 1)
local b = text:sub(j + 1)
return a .. replacement .. b
end
function C:replaceItem(replacement)
assert(self:hasUnreplacedItems())
local original = table.remove(self._unreplaced)
self._text = _stringReplace(self._text, original.command, replacement.command)
self._text = _stringReplace(self._text, original.getText, replacement.getText)
self._text = _stringReplace(self._text, original.displayCmd, replacement.displayCmd)
local template = "[%s] %s -> %s"
logNotice(template:format(self._mapName, original.name, replacement.name))
return a .. replacement .. b, true
end
function C:writeTo(path)