Skip to content

Commit

Permalink
Merge pull request #6218 from LandSandBoat/lls/interaction-quest-format
Browse files Browse the repository at this point in the history
Modify Interaction to allow direct function definition for on/afterZone events
  • Loading branch information
claywar committed Sep 6, 2024
2 parents 148cf4e + dea7212 commit d79a273
Show file tree
Hide file tree
Showing 80 changed files with 650 additions and 917 deletions.
20 changes: 10 additions & 10 deletions scripts/globals/interaction/actions/action.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-----------------------------------
----- Action base class
-----------------------------------
---@class TInteractionAction
---@class TAction
Action = {}

---@enum Action.Priority
Expand Down Expand Up @@ -30,7 +30,7 @@ Action.Type =
}

---@param type Action.Type
---@return TInteractionAction
---@return TAction
function Action:new(type)
local obj = {}
setmetatable(obj, self)
Expand All @@ -48,54 +48,54 @@ function Action:perform(player, targetEntity)
end

---@param priorityArg Action.Priority|integer
---@return TInteractionAction
---@return TAction
function Action:setPriority(priorityArg)
self.priority = priorityArg
return self
end

---@return TInteractionAction
---@return TAction
function Action:progress()
-- Set highest priority for action
return self:setPriority(Action.Priority.Progress)
end

---@return TInteractionAction
---@return TAction
function Action:replaceDefault()
-- Always prefer this over falling back to default in lua file
return self:setPriority(Action.Priority.ReplaceDefault)
end

-- Perform the action as a Progress priority, and then default back to event
---@return TInteractionAction
---@return TAction
function Action:importantEvent()
self.priority = Action.Priority.Progress
self.secondaryPriority = Action.Priority.Event
return self
end

-- After the first time the action is performed, it will have a lower priority
---@return TInteractionAction
---@return TAction
function Action:importantOnce()
self.priority = Action.Priority.Event
self.secondaryPriority = Action.Priority.Default
return self
end

-- Only do this action once per zone, unless there's nothing else to do
---@return TInteractionAction
---@return TAction
function Action:oncePerZone()
self.secondaryPriority = Action.Priority.Ignore
return self
end

---@return TInteractionAction
---@return TAction
function Action:openDoor()
self.returnValue = -1
return self
end

---@return TInteractionAction
---@return TAction
function Action:open()
return self:openDoor()
end
4 changes: 2 additions & 2 deletions scripts/globals/interaction/actions/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-----------------------------------
require('scripts/globals/interaction/actions/action')

---@class TInteractionEvent : TInteractionAction
---@class TEvent : TAction
---@field id integer
---@field options integer[]|table[]
Event = Action:new(Action.Type.Event)
Expand Down Expand Up @@ -33,7 +33,7 @@ function Event:perform(player, targetEntity)
return self.returnValue
end

---@return TInteractionEvent
---@return TEvent
function Event:cutscene()
self.isCutscene = true
return self
Expand Down
4 changes: 2 additions & 2 deletions scripts/globals/interaction/actions/keyitem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
-----------------------------------
require('scripts/globals/interaction/actions/action')

---@class TInteractionKeyItem : TInteractionAction
---@class TKeyItem : TAction
---@field id integer
KeyItemAction = Action:new(Action.Type.KeyItem)

---@param keyItemId xi.keyItem
---@return TInteractionKeyItem
---@return TKeyItem
function KeyItemAction:new(keyItemId)
local obj = {}
setmetatable(obj, self)
Expand Down
2 changes: 1 addition & 1 deletion scripts/globals/interaction/actions/lambdaaction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-----------------------------------
require('scripts/globals/interaction/actions/action')

---@class TInteractionLambdaAction : TInteractionAction
---@class TLambdaAction : TAction
---@field actionFunc function
---@field priority Action.Priority|integer
LambdaAction = Action:new(Action.Type.LambdaAction)
Expand Down
4 changes: 2 additions & 2 deletions scripts/globals/interaction/actions/message.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-----------------------------------
require('scripts/globals/interaction/actions/action')

---@class TInteractionMessage: TInteractionAction
---@class TMessage: TAction
---@field messageType Message.type
---@field id integer
---@field npcId integer?
Expand All @@ -22,7 +22,7 @@ Message.Type =
---@param messageId integer
---@param messageType Message.type?
---@param ... integer?
---@return TInteractionMessage
---@return TMessage
function Message:new(messageId, messageType, ...)
local obj = {}
setmetatable(obj, self)
Expand Down
2 changes: 1 addition & 1 deletion scripts/globals/interaction/actions/noaction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-----------------------------------
require('scripts/globals/interaction/actions/action')

---@class TInteractionNoAction : TInteractionAction
---@class TNoAction : TAction
NoAction = Action:new(Action.Type.NoAction)

function NoAction:new(prio)
Expand Down
4 changes: 2 additions & 2 deletions scripts/globals/interaction/actions/sequence.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require('scripts/globals/interaction/actions/action')
require('scripts/globals/interaction/actions/message')

---@class TInteractionSequence : TInteractionAction
---@class TSequence : TAction
---@field __nextAction any
Sequence = Action:new(Action.Type.Sequence)

Expand All @@ -30,7 +30,7 @@ function Sequence:new(unparsedSequence)
local id = nil
for _, entry in ipairs(unparsedSequence) do
if entry.text then
---@type TInteractionMessage
---@type TMessage
local newLast = Message:new(entry.text)
last.__nextAction = newLast
last = newLast
Expand Down
26 changes: 13 additions & 13 deletions scripts/globals/interaction/container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,77 +38,77 @@ end

---@param eventid integer
---@param ... integer|table
---@return TInteractionEvent
---@return TEvent
function Container:event(eventid, ...)
return Event:new(eventid, ...)
end

---@param eventid integer
---@param ... integer|table
---@return TInteractionEvent
---@return TEvent
function Container:cutscene(eventid, ...)
return Event:new(eventid, ...):cutscene()
end

---@param eventid integer
---@param ... integer|table
---@return TInteractionEvent
---@return TEvent
function Container:progressEvent(eventid, ...)
return Event:new(eventid, ...):progress()
end

---@param eventid integer
---@param ... integer|table
---@return TInteractionEvent
---@return TEvent
function Container:priorityEvent(eventid, ...)
return Event:new(eventid, ...):progress()
end

---@param eventid integer
---@param ... integer|table
---@return TInteractionEvent
---@return TEvent
function Container:progressCutscene(eventid, ...)
return Event:new(eventid, ...):cutscene():progress()
end

---@param eventid integer
---@param ... integer|table
---@return TInteractionEvent
---@return TEvent
function Container:replaceEvent(eventid, ...)
return Event:new(eventid, ...):replaceDefault()
end

---@param keyItemId xi.keyItem
---@return TInteractionKeyItem
---@return TKeyItem
function Container:keyItem(keyItemId)
return KeyItemAction:new(keyItemId)
end

---@param messageId integer
---@param messageType integer?
---@param ... integer?
---@return TInteractionMessage
---@return TMessage
function Container:message(messageId, messageType, ...)
return Message:new(messageId, messageType, ...)
end

---@param messageId integer
---@param ... integer?
---@return TInteractionMessage
---@return TMessage
function Container:messageText(messageId, ...)
return Message:new(messageId, Message.Type.Text, ...)
end

---@param messageId integer
---@param ... integer?
---@return TInteractionMessage
---@return TMessage
function Container:messageSpecial(messageId, ...)
return Message:new(messageId, Message.Type.Special, ...)
end

---@param messageId integer
---@param ... integer?
---@return TInteractionMessage
---@return TMessage
function Container:messageName(messageId, ...)
return Message:new(messageId, Message.Type.Name, ...)
end
Expand All @@ -119,7 +119,7 @@ function Container:replaceMessage(messageId, messageType, ...)
return Message:new(messageId, messageType, ...):replaceDefault()
end

---@return TInteractionSequence|TInteractionMessage?
---@return TSequence|TMessage?
function Container:sequence(...)
if type(...) == 'number' then
return Message:new(...)
Expand All @@ -128,7 +128,7 @@ function Container:sequence(...)
end
end

---@return TInteractionNoAction
---@return TNoAction
function Container:noAction(...)
return NoAction:new(...)
end
Expand Down
20 changes: 20 additions & 0 deletions scripts/globals/interaction/interaction_lookup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ local function addHandlers(secondLevel, lookupSecondLevel, checkFunc, container)

-- Loop through the given second level table, and add them to lookup as needed
for secondLevelKey, thirdLevel in pairs(secondLevel) do
-- The following keys are restricted in CI to function definitions, but to preserve
-- backwards-compatibility and ease of use in this system, wrap them in tables if
-- encountered.
local wrappedDefinitions =
{
'onZoneIn',
'onZoneOut',
'afterZoneIn',
}

for _, keyName in ipairs(wrappedDefinitions) do
if
secondLevelKey == keyName and
type(thirdLevel) == 'function'
then
thirdLevel = { thirdLevel }
end
end

lookupSecondLevel[secondLevelKey] = lookupSecondLevel[secondLevelKey] or {}

-- If only given a function or an action definition as third level, that will default to be an onTrigger handler
Expand Down Expand Up @@ -196,6 +215,7 @@ function InteractionLookup:addContainer(container, validZoneTable)
for zoneId, secondLevel in pairs(section) do
if zoneId ~= 'check' and (validZoneTable == nil or validZoneTable[zoneId]) then
self.data[zoneId] = self.data[zoneId] or {}

addHandlers(secondLevel, self.data[zoneId], checkFunc, container)
end
end
Expand Down
2 changes: 1 addition & 1 deletion scripts/globals/interaction/quest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end
---@type rewardParam
Quest.reward = {}

---@type TQuestSectionList
---@type TQuestSection[]
Quest.sections = {}

---@param areaId xi.questLog
Expand Down
9 changes: 3 additions & 6 deletions scripts/missions/acp/01_A_Crystalline_Prophecy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ mission.sections =

[xi.zone.LOWER_JEUNO] =
{
onZoneIn =
{
function(player, prevZone)
return 10094
end,
},
onZoneIn = function(player, prevZone)
return 10094
end,

onEventUpdate =
{
Expand Down
9 changes: 3 additions & 6 deletions scripts/missions/amk/12_Joy_Summoned_to_a_Fabulous_Fete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ mission.sections =

[xi.zone.CASTLE_ZVAHL_BAILEYS] =
{
onZoneIn =
{
function(player, prevZone)
return 88
end
},
onZoneIn = function(player, prevZone)
return 88
end,

onEventFinish =
{
Expand Down
19 changes: 8 additions & 11 deletions scripts/missions/asa/01_A_Shantotto_Ascension.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ mission.sections =

[xi.zone.WINDURST_WALLS] =
{
onZoneIn =
{
function(player, prevZone)
if
prevZone == xi.zone.WINDURST_WATERS or
prevZone == xi.zone.WINDURST_WOODS
then
return 510
end
end,
},
onZoneIn = function(player, prevZone)
if
prevZone == xi.zone.WINDURST_WATERS or
prevZone == xi.zone.WINDURST_WOODS
then
return 510
end
end,

onEventFinish =
{
Expand Down
Loading

0 comments on commit d79a273

Please sign in to comment.