yatta-invisible-market.lua
local items = {
["scope"] = {
vnum = 36651,
cost = 5,
slot = 1,
previewMsg = "Ah, the scope eh? Perfect for a sniper! That'll be 5 coins."
},
["superconductor"] = {vnum = 36652, cost = 5, slot = 1,
previewMsg = "You some sorta engineer? No matter. My contact tells me that Relby makes the best. A bargain at 5 coins."},
["battery"] = {vnum = 36653, cost = 5, slot = 2,
previewMsg = "Yeah, I get it. Everyone needs batteries. This power pack is something else though. But it's all yours for 5 coins."},
["crystal"] = {vnum = 36654, cost = 5, slot = 2,
previewMsg = "Crystal... yeah... I got some. Just uh.. don't ask where it came from. That'll be 10 coins."},
["sweetblossom"] = {vnum = 36657, count = 10, cost = 5, slot = 3, buyName = "Ten vials of sweetblossom",
previewMsg = "Suhweeeeeeet blossom. That's the stuff. Hit a little harder, feel a little stronger? Give ya 10 vials for 5 coins."},
["gunship blueprints"] = {vnum = 32018, cost = 250, slot = 4, buyName = "One set of gunship blueprints",
previewMsg = "You ain't seen nothing 'til you seen these babies bust out their payload! Gunship blueprint'll be 250 coins."},
}
local function stockCheck(self, ch, keyword)
if not LOTJ.getGlobalVar("im.stock", ""):find("<"..keyword..">") then
self:sayTo(ch, "Hah! Nice try, but I'm sold outta that fer now. Check back next week.")
return false
end
return true
end
self:onGive(function(self, obj, ch)
if obj:getVNum() ~= 36641 then
self:sayTo(ch, "What's this, hmm? I don't want your junk!")
self:drop(obj)
return
end
ch:setVar("im.coinBalance", ch:getVar("im.coinBalance", 0)+1)
self:emote("&cflicks the coin with a long fingernail and listens to it. She says, \"Yeah, that's a real one. "..
"I have you down for "..ch:getVar("im.coinBalance").." of these.\"")
obj:toRoom(4)
end)
for keyword, item in pairs(items) do
self:onSpeech(keyword, function(self, ch, fullText)
if fullText ~= keyword then return end
if not stockCheck(self, ch, keyword) then return end
self:sayTo(ch, item.previewMsg)
ch:echoAt("&z[&WI&wnvisible Market&z] To purchase this item, give all of the required coins to Yatta then '&ksay confirm "..keyword.."&k'.")
end)
self:onSpeech("confirm "..keyword, function(self, ch, fullText)
if fullText ~= "confirm "..keyword then return end if not stockCheck(self, ch, keyword) then return end
local coinBalance = ch:getVar("im.coinBalance", 0)
if coinBalance < item.cost then
self:emote("&ccounts the coins in her palm with a dissatisfied grunt, \"Whatcha tryin' to pull here? That ain't enough coins!\"")
return
end
local buyName = item.buyName or "One "..keyword
self:emote("&cgrins greedily, quickly closing her fingers around the coins, \""..buyName..", comin' right up!\"")
local obj = nil
local count = item.count or 1
for i=1,count do
obj = Object.invoke(item.vnum)
obj:toChar(ch)
end
ch:setVar("im.coinBalance", coinBalance - item.cost)
if count == 1 then
self:echo("{1} &cdisappears into the vault and returns, sans coins but with {2}&c, which she hands over to {3}.", self, obj, ch)
else
self:echo("{1} &cdisappears into the vault and returns, sans coins but with "..count.." of {2}&c, which she hands over to {3}.", self, obj, ch)
end
self:emote("&creturns her attention to the room and hollers, \"Next!\"")
end)
end
local function secondsUntilNextSundayMidnight()
local expTime = LOTJ.time()
while LOTJ.date("*t", expTime).wday > 1 do
expTime = expTime + (24*60*60) end
local expDate = LOTJ.date("*t", expTime)
expTime = LOTJ.time({year=expDate.year, month=expDate.month, day=expDate.day, hour = 0})
return expTime - LOTJ.time()
end
self:onRandom(100, function(self)
if LOTJ.getGlobalVar("im.stockTimer") then return end
local stockString = ""
for slot = 1, 4 do
local slotOptions = {}
for keyword, item in pairs(items) do
if item.slot == slot then table.insert(slotOptions, keyword) end
end
if slot > 1 then stockString = stockString.." " end
stockString = stockString.."<"..slotOptions[math.random(#slotOptions)]..">"
end
self:force("immchat This week's Invisible Market stock is: "..stockString)
LOTJ.setGlobalVar("im.stock", stockString)
LOTJ.setGlobalVar("im.stockTimer", true, secondsUntilNextSundayMidnight())
end)