New game works almost as intended, quest system
This commit is contained in:
@@ -219,30 +219,99 @@ function Quest(name, book)
|
||||
return quest
|
||||
end
|
||||
function StartGameQuest()
|
||||
local quest = {}
|
||||
-- Parse a book from the Ink file.
|
||||
local book = narrator.parse_file('stories.initiation')
|
||||
local quest = Quest('start game', book)
|
||||
quest.base = {}
|
||||
quest.base.activate = quest.activate
|
||||
quest.base.complete = quest.complete
|
||||
quest.boat = false
|
||||
quest.activate = function(this)
|
||||
print('activate...')
|
||||
local mc_is_free = function()
|
||||
this.boat = true
|
||||
local ent = ecs_get_player_entity()
|
||||
ecs_character("params-set", ent, "gravity", true)
|
||||
ecs_character("params-set", ent, "buoyancy", true)
|
||||
end
|
||||
this.story:bind('mc_is_free', mc_is_free)
|
||||
this.base.activate(this)
|
||||
local book = narrator.parse_file('stories.initiation')
|
||||
local story = narrator.init_story(book)
|
||||
this._add_narration({
|
||||
book = book,
|
||||
story = story,
|
||||
activate = function(this)
|
||||
local mc_is_free = function()
|
||||
this.boat = true
|
||||
local ent = ecs_get_player_entity()
|
||||
ecs_character("params-set", ent, "gravity", true)
|
||||
ecs_character("params-set", ent, "buoyancy", true)
|
||||
end
|
||||
this.story:bind('mc_is_free', mc_is_free)
|
||||
this.story:begin()
|
||||
this:narration_update()
|
||||
end,
|
||||
event = function(this, event)
|
||||
if event == "narration_progress" then
|
||||
this:narration_update()
|
||||
end
|
||||
if event == "narration_answered" then
|
||||
local answer = this._get_narration_answer()
|
||||
this.story:choose(answer)
|
||||
this:narration_update()
|
||||
end
|
||||
end,
|
||||
finish = function(this)
|
||||
end,
|
||||
narration_update = function(this)
|
||||
local ret = ""
|
||||
local choices = {}
|
||||
local have_choice = false
|
||||
local have_paragraph = false
|
||||
print("narration_update")
|
||||
if this.story:can_continue() then
|
||||
print("CAN continue")
|
||||
have_paragraph = true
|
||||
local paragraph = this.story:continue(1)
|
||||
print(dump(paragraph))
|
||||
local text = paragraph.text
|
||||
if paragraph.tags then
|
||||
-- text = text .. ' #' .. table.concat(paragraph.tags, ' #')
|
||||
for i, tag in ipairs(paragraph.tags) do
|
||||
if tag == 'discard' then
|
||||
text = ''
|
||||
elseif tag == 'crash' then
|
||||
print(text)
|
||||
crash()
|
||||
end
|
||||
this:handle_tag(tag)
|
||||
end
|
||||
end
|
||||
ret = text
|
||||
if this.story:can_choose() then
|
||||
have_choice = true
|
||||
local ch = this.story:get_choices()
|
||||
for i, choice in ipairs(ch) do
|
||||
table.insert(choices, choice.text)
|
||||
print(i, dump(choice))
|
||||
end
|
||||
if #choices == 1 and choices[1] == "Ascend" then
|
||||
this.story:choose(1)
|
||||
choices = {}
|
||||
end
|
||||
if #choices == 1 and choices[1] == "Continue" then
|
||||
this.story:choose(1)
|
||||
choices = {}
|
||||
end
|
||||
end
|
||||
else
|
||||
print("can NOT continue")
|
||||
end
|
||||
print(ret)
|
||||
if (#choices > 0) then
|
||||
print("choices!!!")
|
||||
this._narration(ret, choices)
|
||||
else
|
||||
this._narration(ret, {})
|
||||
end
|
||||
if not have_choice and not have_paragraph then
|
||||
this._finish()
|
||||
end
|
||||
end,
|
||||
handle_tag = function(this, tag)
|
||||
print("tag: " .. tag)
|
||||
end,
|
||||
})
|
||||
end
|
||||
quest.complete = function(this)
|
||||
this.base.complete(this)
|
||||
this.active = false
|
||||
if not this.boat then
|
||||
ecs_save_object_debug(boat, 'boat.scene')
|
||||
end
|
||||
quest.finish = function(this)
|
||||
end
|
||||
return quest
|
||||
end
|
||||
@@ -616,25 +685,27 @@ setup_handler(function(event, trigger_entity, what_entity)
|
||||
return
|
||||
end
|
||||
if event == "startup" then
|
||||
main_menu()
|
||||
--
|
||||
elseif event == "narration_progress" then
|
||||
print("narration progress!")
|
||||
elseif event == "narration_answered" then
|
||||
local answer = narration_get_answer()
|
||||
print("answered:", answer)
|
||||
elseif event == "spawn_player" then
|
||||
elseif event == "new_game" then
|
||||
local ent = ecs_get_player_entity()
|
||||
ecs_character("params-set", ent, "gravity", true)
|
||||
ecs_character("params-set", ent, "buoyancy", false)
|
||||
local quest = StartGameQuest()
|
||||
quests[quest.name] = quest
|
||||
for k, v in pairs(quests) do
|
||||
print(k, v.active)
|
||||
end
|
||||
quest:activate()
|
||||
local start_boat = create_boat()
|
||||
table.insert(vehicles, start_boat)
|
||||
table.insert(player_vehicles, start_boat)
|
||||
local quest = StartGameQuest()
|
||||
add_quest("main", quest)
|
||||
-- quests[quest.name] = quest
|
||||
-- for k, v in pairs(quests) do
|
||||
-- print(k, v.active)
|
||||
-- end
|
||||
-- quest:activate()
|
||||
elseif event == "actuator_created" then
|
||||
print(trigger_entity)
|
||||
local act = create_actuator2(trigger_entity)
|
||||
@@ -829,3 +900,5 @@ setup_action_handler("talk", function(town, index, word)
|
||||
end)
|
||||
]]--
|
||||
|
||||
main_menu()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user