Updated lots of things
This commit is contained in:
@@ -228,14 +228,10 @@ function StartGameQuest()
|
||||
quest.activate = function(this)
|
||||
print('activate...')
|
||||
local mc_is_free = function()
|
||||
this.boat_id = ecs_vehicle_set("boat", 0, 0, -10, 1.75)
|
||||
this.npc_id = ecs_npc_set("normal-female.glb", 0, 2, -10, 1.75)
|
||||
this.boat = true
|
||||
-- ecs_set_slot(this.boat_id, this.npc_id, "captain_seat")
|
||||
-- ecs_character_physics_control(this.npc_id, false)
|
||||
local ent = ecs_get_player_entity()
|
||||
ecs_character_params_set(ent, "gravity", true)
|
||||
ecs_character_params_set(ent, "buoyancy", true)
|
||||
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)
|
||||
@@ -249,6 +245,43 @@ function StartGameQuest()
|
||||
end
|
||||
return quest
|
||||
end
|
||||
function BoatControlQuest()
|
||||
-- Parse a book from the Ink file.
|
||||
local book = narrator.parse_file('stories.boat_control')
|
||||
local quest = Quest('boat control', book)
|
||||
quest.base = {}
|
||||
quest.base.activate = quest.activate
|
||||
quest.base.complete = quest.complete
|
||||
quest.boat = false
|
||||
quest.activate = function(this)
|
||||
print('activate...')
|
||||
local ent = ecs_get_player_entity()
|
||||
ecs_set_slot(this.boat.boat_id, ent, "seat1")
|
||||
-- ecs_character_set_actuator(ent, "sitting")
|
||||
ecs_character("set-actuator", ent, "idle")
|
||||
local boat_activated = function()
|
||||
-- local ent = ecs_get_player_entity()
|
||||
-- ecs_character_set_actuator(ent, "idle")
|
||||
-- ecs_character_physics_control(ent, false)
|
||||
-- ecs_character_params_set(ent, "gravity", false)
|
||||
-- ecs_character_params_set(ent, "buoyancy", false)
|
||||
end
|
||||
this.story:bind('boat_activated', boat_activated)
|
||||
this.base.activate(this)
|
||||
end
|
||||
quest.complete = function(this)
|
||||
this.base.complete(this)
|
||||
this.active = false
|
||||
local ent = ecs_get_player_entity()
|
||||
ecs_set_slot(this.boat.boat_id, this.boat.passengers[1], "seat0")
|
||||
ecs_character("set-actuator", ent, "sitting")
|
||||
ecs_set_slot(this.boat.boat_id, ent, "seat1")
|
||||
ecs_character("set-actuator", ent, "sitting")
|
||||
ecs_set_slot(this.boat.boat_id, ent, "captain_seat")
|
||||
ecs_character("set-actuator", ent, "sitting")
|
||||
end
|
||||
return quest
|
||||
end
|
||||
function create_actuator()
|
||||
return {
|
||||
is_complete = false,
|
||||
@@ -257,8 +290,8 @@ function create_actuator()
|
||||
end,
|
||||
finish = function(this)
|
||||
this.is_complete = true
|
||||
ecs_character_set_actuator(this.entity, "")
|
||||
ecs_character_physics_control(this.entity, true)
|
||||
ecs_character("set-actuator", this.entity, "")
|
||||
ecs_character("physics-control", this.entity, true)
|
||||
print("COMPLETE")
|
||||
end,
|
||||
forward = function(this)
|
||||
@@ -268,7 +301,7 @@ function create_actuator()
|
||||
end,
|
||||
animation = function(this, animation)
|
||||
print("ANIMATION: ", animation)
|
||||
ecs_character_set_actuator(this.entity, animation)
|
||||
ecs_character("set-actuator", this.entity, animation)
|
||||
end,
|
||||
event = function(this, event, trigger_entity, what_entity)
|
||||
print("actuator events: ", event)
|
||||
@@ -301,13 +334,14 @@ quests = {}
|
||||
local actuator = nil
|
||||
function check_actuator_event(event, trigger_entity, what_entity)
|
||||
print("check_actuator_event: ", event)
|
||||
--[[
|
||||
if event == "actuator_enter" then
|
||||
if not ecs_character_is_player(what_entity) then
|
||||
if not ecs_character("is-player", what_entity) then
|
||||
return
|
||||
end
|
||||
ecs_character_physics_control(what_entity, false)
|
||||
ecs_character("physics-control", what_entity, false)
|
||||
local animation = ecs_trigger_get_animation(trigger_entity)
|
||||
ecs_character_set_actuator(what_entity, animation)
|
||||
ecs_character("set-actuator", what_entity, animation)
|
||||
ecs_trigger_set_position(trigger_entity, what_entity)
|
||||
local ent = ecs_get_entity(what_entity)
|
||||
if (ent.is_character()) then
|
||||
@@ -323,8 +357,8 @@ function check_actuator_event(event, trigger_entity, what_entity)
|
||||
actuator.forward = function(this)
|
||||
this:animation("swimming-edge-climb")
|
||||
local ent = ecs_get_player_entity()
|
||||
ecs_character_params_set(ent, "gravity", true)
|
||||
ecs_character_params_set(ent, "buoyancy", true)
|
||||
ecs_character("params-set", ent, "gravity", true)
|
||||
ecs_character("params-set", ent, "buoyancy", true)
|
||||
end
|
||||
actuator.base_event = actuator.event
|
||||
actuator.finish_events = {"animation:swimming-edge-climb:end"}
|
||||
@@ -335,8 +369,9 @@ function check_actuator_event(event, trigger_entity, what_entity)
|
||||
end
|
||||
return false
|
||||
end
|
||||
elseif event == "character_enter" then
|
||||
if not ecs_character_is_player(trigger_entity) then
|
||||
]]--
|
||||
if event == "character_enter" then
|
||||
if not ecs_character("is-player", trigger_entity) then
|
||||
return
|
||||
end
|
||||
actuator = create_actuator()
|
||||
@@ -372,8 +407,162 @@ function check_actuator_event(event, trigger_entity, what_entity)
|
||||
end
|
||||
end
|
||||
-- ecs_set_debug_drawing(true)
|
||||
|
||||
local vehicles = {}
|
||||
local player_vehicles = {}
|
||||
local actuators = {}
|
||||
|
||||
function create_boat()
|
||||
local boat = {}
|
||||
boat.boat_id = ecs_vehicle_set("boat", 0, 0, -10, 1.75)
|
||||
local npc_id = ecs_npc_set("normal-female.glb", 0, 2, -10, 1.75)
|
||||
boat.passengers = {npc_id}
|
||||
ecs_character("physics-control", npc_id, false)
|
||||
ecs_character("params-set", npc_id, "gravity", false)
|
||||
ecs_character("params-set", npc_id, "buoyancy", false)
|
||||
ecs_set_slot(boat.boat_id, npc_id, "captain_seat")
|
||||
ecs_character("set-actuator", npc_id, "sitting")
|
||||
-- ecs_set_animation_state(npc_id, "main", "actuator", true)
|
||||
-- ecs_set_animation_state(npc_id, "actuator-state", "sitting", true)
|
||||
boat.event = function(this, event, event_data)
|
||||
print("boat: ", event)
|
||||
if event == "boat_control_enter" then
|
||||
local quest = BoatControlQuest()
|
||||
quest.boat = this
|
||||
quests[quest.name] = quest
|
||||
quest:activate()
|
||||
return true
|
||||
end
|
||||
if event == "boat_control_exit" then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
return boat
|
||||
end
|
||||
function create_actuator2(ent)
|
||||
print("create actuator")
|
||||
local act = {
|
||||
id = ent,
|
||||
activated = false,
|
||||
contained = {},
|
||||
enter = function(this, what)
|
||||
print(this.id, "visited by", what)
|
||||
if not ecs_character("is-player", what) then
|
||||
-- actuators are only for players
|
||||
return
|
||||
end
|
||||
ecs_character("physics-control", what, false)
|
||||
local animation = ecs_trigger_get_animation(this.id)
|
||||
print(animation)
|
||||
ecs_character("set-actuator", what, animation)
|
||||
ecs_trigger_set_position(this.id, what)
|
||||
local ent = ecs_get_entity(what)
|
||||
if (ent.is_character()) then
|
||||
print("character")
|
||||
end
|
||||
if (ent.is_player()) then
|
||||
print("player")
|
||||
end
|
||||
table.insert(this.contained, what)
|
||||
this.activated = true
|
||||
end,
|
||||
exit = function(this, what)
|
||||
print(this.id, "left by", what)
|
||||
if this.contained[1] ~= what then
|
||||
crash()
|
||||
end
|
||||
ecs_character("set-actuator", this.contained[1], "")
|
||||
ecs_character("physics-control", this.contained[1], true)
|
||||
this.activated = false
|
||||
print("COMPLETE")
|
||||
end,
|
||||
event = function(this, event, trigger, what)
|
||||
if this.activated then
|
||||
print("!!!", event)
|
||||
if event == "actuator_forward" then
|
||||
this:animation("swimming-edge-climb")
|
||||
local ent = this.contained[1]
|
||||
ecs_character("params-set", ent, "gravity", true)
|
||||
ecs_character("params-set", ent, "buoyancy", true)
|
||||
return true
|
||||
elseif event == "actuator_backward" then
|
||||
return true
|
||||
elseif event == "animation:swimming-edge-climb:end" then
|
||||
this:exit(this.contained[1])
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
return false
|
||||
end,
|
||||
animation = function(this, animation)
|
||||
if this.activated then
|
||||
print("ANIMATION: ", animation)
|
||||
local ent = this.contained[1]
|
||||
ecs_character("set-actuator", ent, animation)
|
||||
end
|
||||
end,
|
||||
}
|
||||
return act
|
||||
end
|
||||
|
||||
function endswith(s, suffix)
|
||||
return string.sub(s, -#suffix) == suffix
|
||||
end
|
||||
|
||||
function startswith(s, prefix)
|
||||
return string.sub(s, 1, #prefix) == prefix
|
||||
end
|
||||
|
||||
|
||||
setup_handler(function(event, trigger_entity, what_entity)
|
||||
print(event)
|
||||
local event_handled = false
|
||||
if startswith(event, "actuator_") and event ~= "actuator_created" then
|
||||
for i, act in ipairs(actuators) do
|
||||
if act.id == trigger_entity then
|
||||
if event == "actuator_enter" then
|
||||
if not act.activated then
|
||||
act:enter(what_entity)
|
||||
event_handled = true
|
||||
break
|
||||
end
|
||||
elseif event == "actuator_exit" then
|
||||
if act.activated then
|
||||
act:exit(what_entity)
|
||||
event_handled = true
|
||||
break
|
||||
end
|
||||
else
|
||||
if act.activated then
|
||||
if act:event(event, trigger_entity, what_entity) then
|
||||
event_handled = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
event_handled = true
|
||||
end
|
||||
end
|
||||
elseif startswith(event, "animation:") and endswith(event, ":end") then
|
||||
for i, act in ipairs(actuators) do
|
||||
if act.activated then
|
||||
if act:event(event, trigger_entity, what_entity) then
|
||||
event_handled = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if event_handled then
|
||||
return
|
||||
end
|
||||
if event == "actuator_enter" or event == "actuator_exit" or event == "actuator_forward" then
|
||||
print("bad event:", event, trigger_entity, what_entity)
|
||||
crash()
|
||||
end
|
||||
|
||||
for k, v in pairs(quests) do
|
||||
if v.active then
|
||||
local event_data = {}
|
||||
@@ -382,6 +571,20 @@ setup_handler(function(event, trigger_entity, what_entity)
|
||||
v:event(event, event_data)
|
||||
end
|
||||
end
|
||||
for i, vehicle in ipairs(vehicles) do
|
||||
print(i, vehicle)
|
||||
if vehicle.event then
|
||||
local event_data = {}
|
||||
event_data.trigger_entity = trigger_entity
|
||||
event_data.object_entity = what_entity
|
||||
if vehicle:event(event, event_data) then
|
||||
event_handled = true
|
||||
end
|
||||
end
|
||||
end
|
||||
if event_handled then
|
||||
return
|
||||
end
|
||||
if event == "startup" then
|
||||
main_menu()
|
||||
elseif event == "narration_progress" then
|
||||
@@ -391,14 +594,22 @@ setup_handler(function(event, trigger_entity, what_entity)
|
||||
print("answered:", answer)
|
||||
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)
|
||||
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)
|
||||
elseif event == "actuator_created" then
|
||||
print(trigger_entity)
|
||||
local act = create_actuator2(trigger_entity)
|
||||
table.insert(actuators, act)
|
||||
--[[
|
||||
else
|
||||
if not actuator then
|
||||
check_actuator_event(event, trigger_entity, what_entity)
|
||||
@@ -412,5 +623,6 @@ setup_handler(function(event, trigger_entity, what_entity)
|
||||
actuator = nil
|
||||
end
|
||||
end
|
||||
--]]
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user