Working on quests - tried to simplify stuff as much as possible, and put it in one script per quest. And it works well! Here's an example of quest state:
InHouseState.entityStates = {
luna = function(e, quest)
setActionListOnInteraction(e, beforeKill, quest)
end
}
InHouseState.sceneEnter = {
luna_house_basement = function(quest)
saveManager:setQuestData(QUEST_TAG, "went_to_basement", true)
spawnByTag("basement_slime") -- spawn a boss
end
}
InHouseState.sceneExit = {
luna_house_basement = function(quest)
despawnByTag("basement_slime") -- despawn a boss
end
}
entityStates is used to describe what function should be called on an entity when it appears on scene. In this case, when "luna" appears on the scene, she gets a new interaction function which will launch a specific cutscene.
sceneEnter/
sceneExit are used to describe what happens when you enter/exit the scene in the specific quest state. In this case, it's used to spawn a boss in "luna_house_basement" until you kill it (and then the quest state changes and different script plays each time you enter the basement)
Here's what's good about this mechanism - entities and scenes don't know anything about quests - quest itself does the things when it's in corresponding state, so I can easily add more and more logic to them without touching scene/NPC script - it's all encapsulated into quest script!
Another thing I've added in an event logger. It allows me to subscribe to events of needed type and then inspect the data in each event. Very useful for debugging!
Here it is in action:
https://gfycat.com/sardonicmenacinggrackle