some more witch spike notes

trunk
vilmibm 2022-12-16 16:49:17 -08:00
parent fe1139bf60
commit 76382a2b36
2 changed files with 114 additions and 15 deletions

View File

@ -65,7 +65,6 @@ func _main() (err error) {
grpcServer.Serve(l)
return nil
}
type gameWorldServer struct {

View File

@ -1,11 +1,22 @@
-- This file contains some drafts on how a WITCH API could look in Lua.
-- Assumed in-scope functions:
-- has(data)
-- tells the server what data this object has. If this object is live (ie,
-- in world) when opened for editing this invocation will match the current
-- state of the data in the database. Anything can go in here and all keys
-- are optional.
-- allows(permissions)
-- tells the server what this object's permissions are. the permissions are
-- read, write, carry, and execute. permissions can have value of either
-- "owner" or "world". if unspecified, a permission is set to "owner".
-- hears(pattern, callback)
-- registers a callback called when an object in the same room as this one
-- SAYs something that matches pattern
-- sees(pattern, callback)
-- registers a callback called when an object in the same room as this one
-- EMOTEs something that matches pattern
-- provides(verb_pattern, callback)
-- registers a callback called when an object in the same room as this one runs "/verb_pattern"
-- says(message)
-- issues a SAY to the server that other objects in the same room will overhear
-- does(message)
@ -13,12 +24,47 @@
-- room.says(message)
-- tells the server to have the room "say" something. this is useful when an
-- object wants something said in the third person.
-- random(min, max)
-- returns a random integer between min and max. This is provided so callers
-- do not have to worry about seeding randomness themselves.
-- create(name, code)
-- returns a new object with the given name and Lua code. owner and permissions are transferred from calling object
-- drop(object)
-- drop an object on the ground of the current room
-- tell_sender(msg)
-- issues a WHISPER to whoever triggered a callback
-- teleport_sender(room_id)
-- teleports whoever triggered a callback to the specified room
-- move_sender(direction)
-- teleports whoever triggered a callback in the specified direction
--
-- Callbacks are passed "args," a table which contains the utterance that
-- triggered the handler. this table can be accessed in a few ways:
--
-- args.get("thing")
-- returns whatever string occupied a placeholder called $thing. for example, in this provides:
--
-- provides("give $thing", function(args) end)
--
-- args.get("thing") has whatever space delimited value came after "give".
--
-- args.contains("some substring")
-- returns true if "some substring" is found when all of the args are joined
-- together in one string
--
-- Example 1: the nervous pasta
has = {
has({
name = "spaghetti",
description = "a plate of spaghetti covered in a fresh pomodoro sauce"
}
})
allows({
read = "world",
write = "owner"
carry = "owner",
execute = "world",
})
hears("*eat*", function(msg)
does("quivers nervously")
@ -28,18 +74,50 @@ sees("*slurp*", function(emote)
does("inches away from " + sender.get("name"))
end)
-- Example 1a: the nervous pasta written pedantically
-- This example just demonstrates the syntactic sugar of "hears" and "sees"
has({
name = "spaghetti",
description = "a plate of spaghetti covered in a fresh pomodoro sauce"
})
allows({
read = "world",
write = "owner"
carry = "owner",
execute = "world",
})
provides("say", function(args)
if args.contain("eat") then
does("quivers nervously")
end
end)
provides("emote", function(args)
if args.contain("slurp") then
does("inches away from " + sender.get("name"))
end
end)
-- Example 2: the slot machine
has = {
has({
name = "slot machine",
description = "a vintage 1960s slot machine from Las Vegas"
}
})
allows({
read = "world",
write = "owner"
carry = "owner",
execute = "world",
})
provides("pull $this", function(args)
math.randomseed(os.time())
says("KA CHANK")
one = math.random(0, 9)
two = math.random(0, 9)
three = math.random(0,9)
one = random(0, 9)
two = random(0, 9)
three = random(0, 9)
say("you got" + string.format("%d %d %d", one, two, three))
end)
@ -50,12 +128,34 @@ provides("whack $this", function(args)
end)
-- Example 3: vending machine
has = {
has({
name = "vending machine",
description = "looks like the kind of thing you'd see in Tokyo"
}
description = "looks like the kind of thing you'd see in Tokyo",
money = 0
})
provides("give $this $money", function(args)
amount = args.get("money")
-- TODO
allows({
read = "world",
write = "owner"
carry = "owner",
execute = "world",
})
provides("give $this $money $unit", function(args)
amount = tonumber(args.get("money")) or 0
unit = args.get("unit")
if unit != "yen" then
say("i only take yen sorry")
return
end
set("money", get("money") + amount)
if get("money") > 100 then
room.says("the " + get("name") + " clatters a bit then drops a pocari sweat on the floor")
set("money", 0)
bottle = create("a bottle of pocari sweat", "")
drop(bottle)
else
say("i need more money")
end
end)