Skip to content

Commit

Permalink
[lls] Move quest definitions to generic Container file, add TMission …
Browse files Browse the repository at this point in the history
…type

Fix ordering for Container sections, correct overload

break out remaining overload definitions
  • Loading branch information
claywar committed Sep 7, 2024
1 parent b3756be commit fcbcd10
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 25 deletions.
26 changes: 23 additions & 3 deletions scripts/globals/interaction/mission.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
-----------------------------------
require('scripts/globals/interaction/container')
-----------------------------------

---@see TInteractionContainer
---@class TMission : TInteractionContainer
---@field areaId integer
---@field missionId integer
Mission = setmetatable({ areaId = -1 }, { __index = Container })
Mission.__index = Mission

---@diagnostic disable-next-line: duplicate-set-field
Mission.__eq = function(m1, m2)
return m1.areaId == m2.areaId and m1.missionId == m2.missionId
end

---@type rewardParam
Mission.reward = {}

---@diagnostic disable-next-line: duplicate-set-field
---@type TMissionSection[]
Mission.sections = {}

---@nodiscard
---@param areaId integer
---@param missionId integer
---@return TMission
function Mission:new(areaId, missionId)
local obj = Container:new(Mission.getVarPrefix(areaId, missionId))
setmetatable(obj, self)
Expand All @@ -23,10 +32,17 @@ function Mission:new(areaId, missionId)
return obj
end

---@nodiscard
---@param areaId integer
---@param missionId integer
---@return string
function Mission.getVarPrefix(areaId, missionId)
return string.format('Mission[%d][%d]', areaId, missionId)
end

---@nodiscard
---@param player CBaseEntity
---@return table<integer>
function Mission:getCheckArgs(player)
return { player:getCurrentMission(self.areaId), player:getMissionStatus(self.areaId) }
end
Expand All @@ -35,10 +51,14 @@ end
-- Mission operations
-----------------------------------

---@param player CBaseEntity
---@return nil
function Mission:begin(player)
player:addMission(self.areaId, self.missionId)
end

---@param player CBaseEntity
---@return boolean
function Mission:complete(player)
local didComplete = npcUtil.completeMission(player, self.areaId, self.missionId, self.reward)
if didComplete then
Expand Down
6 changes: 4 additions & 2 deletions scripts/globals/interaction/quest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require('scripts/globals/interaction/container')
Quest = setmetatable({ areaId = 0 }, { __index = Container })
Quest.__index = Quest

---@diagnostic disable-next-line: duplicate-set-field
Quest.__eq = function(q1, q2)
return q1.areaId == q2.areaId and q1.questId == q2.questId
end
Expand All @@ -21,6 +20,7 @@ Quest.reward = {}
---@type TQuestSection[]
Quest.sections = {}

---@nodiscard
---@param areaId xi.questLog
---@param questId integer
---@return TQuest
Expand All @@ -32,15 +32,17 @@ function Quest:new(areaId, questId)
return obj
end

---@nodiscard
---@param areaId xi.questLog
---@param questId integer
---@return string
function Quest.getVarPrefix(areaId, questId)
return string.format('Quest[%d][%d]', areaId, questId)
end

---@nodiscard
---@param player CBaseEntity
---@return { [integer]: xi.questStatus }
---@return table<xi.questStatus>
function Quest:getCheckArgs(player)
return { player:getQuestStatus(self.areaId, self.questId) }
end
Expand Down
58 changes: 49 additions & 9 deletions scripts/specs/core/CBaseEntity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,14 @@ end
---@param arg1 number
---@param arg2 number
---@return nil
---@overload fun(arg0: table): nil
function CBaseEntity:lookAt(arg0, arg1, arg2)
end

---@param posTable table
---@return nil
function CBaseEntity:lookAt(posTable)
end

---@param PLuaBaseEntity CBaseEntity
---@param nonGlobal boolean?
---@return nil
Expand Down Expand Up @@ -492,11 +496,21 @@ end
---@param arg1 number
---@param arg2 number
---@return number
---@overload fun(arg0: table): number
---@overload fun(arg0: CBaseEntity): number
function CBaseEntity:checkDistance(arg0, arg1, arg2)
end

---@nodiscard
---@param posTable table
---@return number
function CBaseEntity:checkDistance(posTable)
end

---@nodiscard
---@param targetEntity CBaseEntity
---@return number
function CBaseEntity:checkDistance(targetEntity)
end

---@param milliseconds integer?
---@return nil
function CBaseEntity:wait(milliseconds)
Expand Down Expand Up @@ -620,10 +634,17 @@ end
---@param target CBaseEntity
---@param degrees integer?
---@return integer
---@overload fun(posX: number?, posY: number?, posZ: number?): integer
function CBaseEntity:getWorldAngle(target, degrees)
end

---@nodiscard
---@param posX number
---@param posY number
---@param posZ number
---@return integer
function CBaseEntity:getWorldAngle(posX, posY, posZ)
end

---@nodiscard
---@param target CBaseEntity
---@return integer
Expand Down Expand Up @@ -772,10 +793,14 @@ end
---@param rot integer?
---@param zoneId integer?
---@return nil
---@overload fun(arg0: table): nil
function CBaseEntity:setPos(x, y, z, rot, zoneId)
end

---@param posTable table
---@return nil
function CBaseEntity:setPos(posTable)
end

---@return nil
function CBaseEntity:warp()
end
Expand Down Expand Up @@ -933,10 +958,15 @@ end
---@param arg2 integer
---@param arg3 integer
---@return nil
---@overload fun(itemID: integer, rawPrice: number): nil
function CBaseEntity:addShopItem(itemID, rawPrice, arg2, arg3)
end

---@param itemID integer
---@param rawPrice number
---@return nil
function CBaseEntity:addShopItem(itemID, rawPrice)
end

---@nodiscard
---@param guildID integer
---@return table
Expand Down Expand Up @@ -2681,10 +2711,14 @@ end
---@param subPower integer?
---@param tier integer?
---@return boolean
---@overload fun(effectID: CStatusEffect): boolean
function CBaseEntity:addStatusEffect(effectID, power, tick, duration, subType, subPower, tier)
end

---@param effect CStatusEffect
---@return boolean
function CBaseEntity:addStatusEffect(effect)
end

-- NOTE: Currently this function allows for an optional last parameter at any position. This is represented
-- in currently-used overloads, but should be standardized in the future and just pass 0-values.
---@param effectID integer
Expand Down Expand Up @@ -3711,10 +3745,13 @@ end
---@param skillID integer
---@param PLuaBaseEntity CBaseEntity?
---@return nil
---@overload fun(): nil
function CBaseEntity:useMobAbility(skillID, PLuaBaseEntity)
end

---@return nil
function CBaseEntity:useMobAbility()
end

---@nodiscard
---@param skillID integer
---@return number
Expand All @@ -3728,10 +3765,13 @@ end

---@param PLuaBaseEntity CBaseEntity
---@return nil
---@overload fun(): nil
function CBaseEntity:drawIn(PLuaBaseEntity)
end

---@return nil
function CBaseEntity:drawIn()
end

---@param level integer
---@return nil
function CBaseEntity:weaknessTrigger(level)
Expand Down
22 changes: 11 additions & 11 deletions scripts/specs/types/Quest.lua → scripts/specs/types/Container.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
-- Supporting Class Definitions for Interaction Quests. TQuest definition
-- is contained within scripts/globals/interaction/quest.lua

-- Interaction Container definitions
---@meta

-- Definitions for quest.sections{}
---@class TQuestSection
---@field check fun(player: CBaseEntity, status: xi.questStatus, vars: { [string]: integer }): boolean
---@field [xi.zone] ZoneSection

-- TODO: Below here, we can most likely be generic and reuse these definitions for Hidden Quests, Missions,
-- and perhaps Battlefields as well
---@class ZoneSection
---@field onZoneIn? fun(player: CBaseEntity, prevZone: xi.zone): integer|table<integer>?
---@field onZoneOut? onZoneHandler
---@field afterZoneIn? onZoneHandler
---@field [string]? EntitySection|TAction|fun(player: CBaseEntity, npc: CBaseEntity): TAction?
---@field onEventUpdate? onEventHandler
---@field onEventFinish? onEventHandler
---@field onTriggerAreaEnter? onTriggerAreaHandler
---@field onTriggerAreaLeave? onTriggerAreaHandler
---@field [string]? EntitySection|TAction|fun(player: CBaseEntity, npc: CBaseEntity): TAction?

---@alias onZoneHandler fun(player: CBaseEntity): TAction?

Expand All @@ -32,3 +23,12 @@

---@class onEventHandler
---@field [integer] fun(player: CBaseEntity, csid: integer, option: integer, npc: CBaseEntity)

-- Quest and Mission sections vary slightly based on their check function (below):
---@class TQuestSection
---@field check fun(player: CBaseEntity, status: xi.questStatus, vars: { [string]: integer }): boolean
---@field [xi.zone] ZoneSection

---@class TMissionSection
---@field check fun(player: CBaseEntity, currentMission: integer, missionStatus: integer, vars: { [string]: integer }): boolean
---@field [xi.zone] ZoneSection

0 comments on commit fcbcd10

Please sign in to comment.