function init()
storage.complete = storage.complete or false
self.compassUpdate = config.getParameter("compassUpdate", 0.5)
self.descriptions = config.getParameter("descriptions")
self.scientistUid = config.getParameter("scientistUid")
self.techstationUid = config.getParameter("techstationUid")
self.findRange = config.getParameter("findRange")
self.exploreTime = config.getParameter("exploreTime")
storage.exploreTimer = storage.exploreTimer or 0
setPortraits()
storage.stage = storage.stage or 1
self.stages = {
explore,
findScientist
}
self.state = FSM:new()
self.state:set(self.stages[storage.stage])
end
function questInteract(entityId)
if self.onInteract then
return self.onInteract(entityId)
end
end
function questStart()
player.upgradeShip(config.getParameter("shipUpgrade"))
end
function update(dt)
self.state:update(dt)
if storage.complete then
quest.setCanTurnIn(true)
end
end
function explore()
quest.setObjectiveList({{self.descriptions.explore, false}})
-- Wait until the player is no longer on the ship
local findSci = util.uniqueEntityTracker(self.scientistUid, self.compassUpdate)
local buffer = 0
while storage.exploreTimer < self.exploreTime do
-- quest.setProgress(math.min(storage.exploreTimer / self.exploreTime, 1.0)) -- Debug
buffer = buffer + script.updateDt()
local sciPosition = findSci()
if sciPosition then
-- Mine is on this world, put buffer onto the exploration timer
storage.exploreTimer = storage.exploreTimer + buffer
buffer = 0
if world.magnitude(mcontroller.position(), sciPosition) < self.findRange then
self.state:set(mineFound)
coroutine.yield()
end
elseif sciPosition == nil then
-- Gate is not in this world, discard the buffer
buffer = 0
end
coroutine.yield()
end
storage.stage = 2
player.radioMessage("gaterepair-findGate")
util.wait(8)
self.state:set(self.stages[storage.stage])
end
function findSci()
quest.setProgress(nil)
quest.setObjectiveList({{self.descriptions.findScientist, false}})
-- Wait until the player is no longer on the ship
local findMine = util.uniqueEntityTracker(self.scientistUid, self.compassUpdate)
while true do
local result = findSci()
questutil.pointCompassAt(result)
if result and world.magnitude(mcontroller.position(), result) < self.findRange then
self.state:set(sciFound)
end
coroutine.yield()
end
self.state:set(self.stages[storage.stage])
end
function sciFound()
quest.setProgress(nil)
quest.setCompassDirection(nil)
player.radioMessage("gaterepair-gateFound1")
player.radioMessage("gaterepair-gateFound1b")
player.radioMessage("gaterepair-gateFound2")
quest.setCanTurnIn(true)
end
-- function collectRepairItem()
-- quest.setCompassDirection(nil)
--
-- while storage.stage == 2 do
-- quest.setObjectiveList({{self.descriptions.collectRepairItem, false}})
-- quest.setProgress(player.hasCountOfItem(self.gateRepairItem) / self.gateRepairCount)
-- if player.hasItem({name = self.gateRepairItem, count = self.gateRepairCount}) then
-- storage.stage = 3
-- end
-- coroutine.yield()
-- end
--
-- quest.setObjectiveList({})
--
-- self.state:set(self.stages[storage.stage])
-- end
--
-- function getBackShip()
-- quest.setCompassDirection(nil)
-- quest.setObjectiveList({{self.descriptions.getBackShip, false}})
--
-- if not storage.bookmarked then
-- player.addTeleportBookmark(config.getParameter("outpostBookmark"))
-- storage.bookmarked = true
-- end
--
-- while not storage.complete do
-- if player.worldId() == player.ownShipWorldId() then
-- storage.complete = true
-- end
-- coroutine.yield()
-- end
-- self.state:set(self.stages[storage.stage])
-- end
-- function repairGate()
-- quest.setCompassDirection(nil)
-- quest.setProgress(nil)
--
-- quest.setParameter("ancientgate", {type = "entity", uniqueId = self.gateUid})
-- quest.setIndicators({"ancientgate"})
--
-- quest.setObjectiveList({
-- {self.descriptions.repairGate, false}
-- })
--
-- local findGate = util.uniqueEntityTracker(self.gateUid, self.compassUpdate)
-- while storage.stage == 4 do
-- questutil.pointCompassAt(findGate())
--
-- -- Go back to last stage if player loses core fragments
-- if not player.hasItem({name = self.gateRepairItem, count = self.gateRepairCount}) then
-- storage.stage = 3
-- self.state:set(self.stages[storage.stage])
-- end
--
-- coroutine.yield()
-- end
--
-- self.onInteract = nil
-- self.state:set(self.stages[storage.stage])
-- end
--
-- function gateRepaired()
-- self.onInteract = nil
-- quest.setCompassDirection(nil)
-- quest.setProgress(nil)
-- quest.setIndicators({})
--
-- storage.stage = 5
--
-- player.radioMessage("gaterepair-gateOpened1")
-- player.radioMessage("gaterepair-gateOpened2")
--
-- self.state:set(self.stages[storage.stage])
-- end
--
-- function findEsther(dt)
-- quest.setCompassDirection(nil)
-- quest.setParameter("esther", {type = "entity", uniqueId = self.estherUid})
-- quest.setIndicators({"esther"})
-- quest.setObjectiveList({{self.descriptions.findEsther, false}})
--
-- local trackEsther = util.uniqueEntityTracker(self.estherUid, self.compassUpdate)
-- local trackGate = util.uniqueEntityTracker(self.gateUid, self.compassUpdate)
-- while true do
-- if not storage.complete then
-- local estherResult = trackEsther()
-- questutil.pointCompassAt(estherResult)
-- if estherResult then
-- if not storage.bookmarked then
-- player.addTeleportBookmark(config.getParameter("outpostBookmark"))
-- storage.bookmarked = true
-- end
-- if world.magnitude(estherResult, mcontroller.position()) < self.findRange then
-- player.playCinematic(config.getParameter("findEstherCinema"))
-- storage.complete = true
-- end
-- end
-- else
-- quest.setCanTurnIn(true)
-- quest.setIndicators({})
-- end
-- coroutine.yield()
-- end
-- self.state:set(self.stages[storage.stage])
-- end
function questComplete()
setPortraits()
questutil.questCompleteActions()
end