peterburg/custom_parser.lua

148 lines
3.1 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Здесь мы настраиваем парсер.
mp.msg.SCENE = "{#Me} {#plural/находишься,находитесь} {#if_has/#here,supporter,на,в} {#here/пр,2}.";
function split(s, sep)
if sep == nil then
sep = ","
end
local t={}
for str in string.gmatch(s, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
local function istable(t) return type(t) == 'table' end
-- "Ты/вы" в разных падежах: им, род, дат, вин, твор, пред.
function mp.shortcut.you(case)
if case == nil then
case = 'им'
end
if case == 'им' then
if pl.plural then
return 'вы'
end
return 'ты'
end
if case == 'род' then
if pl.plural then
return 'вас'
end
return 'тебя'
end
if case == 'дат' then
if pl.plural then
return 'вам'
end
return 'тебе'
end
if case == 'вин' then
if pl.plural then
return 'вас'
end
return 'тебя'
end
if case == 'твор' then
if pl.plural then
return 'вами'
end
return 'тобой'
end
if case == 'пред' then
if pl.plural then
return 'вас'
end
return 'тебе'
end
end
function mp.shortcut.plural(options)
if not istable(options) then
options = split(options)
end
if pl.plural then
return options[2]
end
return options[1]
end
-- {#g/singlefem,singlemasc,singleother,plural}
function mp.shortcut.g(options)
if not istable(options) then
options = split(options)
end
if #options == 2 then
return mp.shortcut.plural(options)
end
if pl.plural then
return options[4]
end
if pl.pronouns == 'fem' then
return options[1]
end
if pl.pronouns == 'masc' then
return options[2]
end
if pl.pronouns == 'other' then
return options[3]
end
return options[1]
end
game:dict {
["Димидий/мр,C,но,ед"] = {
"Димидий/им",
"Димидий/вн",
"Димидия/рд",
"Димидию/дт",
"Димидием/тв",
"Димидии/пр",
}
}
function game:before_Any(ev, w)
if ev == "Ask" or ev == "Say" or ev == "Tell" or ev == "AskFor" or ev == "AskTo" then
p [[Попробуйте просто поговорить.]];
return
end
return false
end
function mp:pre_input(str)
local a = std.split(str)
if #a <= 1 or #a > 3 then
return str
end
if a[1] == 'в' or a[1] == 'на' or a[1] == 'во' or
a[1] == "к" or a[1] == 'ко' then
return "идти "..str
end
return str
end
Distance = Class {
before_Default = function(s, ev)
if ev == "Exam" or ev == "Look" or ev == "Search" then
return false
end
p ("Но ", s:noun(), " очень далеко.");
end;
}:attr 'scenery'
Furniture = Class {
['before_Push,Pull,Transfer,Take'] = [[Пусть лучше
{#if_hint/#first,plural,стоят,стоит} там, где
{#if_hint/#first,plural,стоят,стоит}.]];
}:attr 'static'
Prop = Class {
before_Default = function(s, ev)
p ("Тебе нет дела до ", s:noun 'рд', ".")
end;
}:attr 'scenery'