|
| 1 | +--------------------------- |
| 2 | +-- Condition checking whether the player has a specific main job. |
| 3 | +-- @class module |
| 4 | +-- @name PartyHasMainJobCondition |
| 5 | +local serializer_util = require('cylibs/util/serializer_util') |
| 6 | +local party_util = require('cylibs/util/party_util') |
| 7 | + |
| 8 | +local Condition = require('cylibs/conditions/condition') |
| 9 | +local MultiPickerConfigItem = require('ui/settings/editors/config/MultiPickerConfigItem') |
| 10 | +local PartyHasMainJobCondition = setmetatable({}, { __index = Condition }) |
| 11 | +PartyHasMainJobCondition.__index = PartyHasMainJobCondition |
| 12 | +PartyHasMainJobCondition.__type = "PartyHasMainJobCondition" |
| 13 | +PartyHasMainJobCondition.__class = "PartyHasMainJobCondition" |
| 14 | + |
| 15 | +function PartyHasMainJobCondition.new(job_name_shorts) |
| 16 | + local self = setmetatable(Condition.new(), PartyHasMainJobCondition) |
| 17 | + -- self.job_name_short = job_name_short or res.jobs[windower.ffxi.get_player().main_job_id].ens |
| 18 | + self.job_name_shorts = job_name_shorts or job_util.all_jobs() |
| 19 | + return self |
| 20 | +end |
| 21 | + |
| 22 | +function PartyHasMainJobCondition:is_satisfied(target_index) |
| 23 | + local party = player.party |
| 24 | + if party then |
| 25 | + for party_member in party:get_party_members(true):it() do |
| 26 | + if party_member:get_main_job_short() == self.job_name_shorts then |
| 27 | + return true |
| 28 | + end |
| 29 | + end |
| 30 | + end |
| 31 | + return false |
| 32 | +end |
| 33 | + |
| 34 | +function PartyHasMainJobCondition:get_config_items() |
| 35 | + local all_job_name_shorts = L{} |
| 36 | + for i = 1, 22 do |
| 37 | + all_job_name_shorts:append(res.jobs[i].ens) |
| 38 | + end |
| 39 | + local jobPickerConfigItem = MultiPickerConfigItem.new('job_name_shorts', self.job_name_shorts, all_job_name_shorts, function(job_names) |
| 40 | + return localization_util.commas(job_names:map(function(job_name_short) return i18n.resource('jobs', 'ens', job_name_short) end), 'or') |
| 41 | + end, "Target's Job") |
| 42 | + jobPickerConfigItem:setPickerTitle("Jobs") |
| 43 | + jobPickerConfigItem:setPickerDescription("Choose one or more jobs.") |
| 44 | + jobPickerConfigItem:setPickerTextFormat(function(job_name_short) |
| 45 | + return i18n.resource('jobs', 'ens', job_name_short) |
| 46 | + end) |
| 47 | + return L{ |
| 48 | + jobPickerConfigItem |
| 49 | + } |
| 50 | +end |
| 51 | + |
| 52 | +function PartyHasMainJobCondition:tostring() |
| 53 | + if self.job_name_shorts:equals(job_util.all_jobs()) then |
| 54 | + return "Party has any main job" |
| 55 | + else |
| 56 | + if self.job_name_shorts:length() > 15 then |
| 57 | + local excluded_job_name_shorts = list.diff(self.job_name_shorts, job_util.all_jobs()) |
| 58 | + return "Party has any main job except "..localization_util.commas(excluded_job_name_shorts:map(function(job_name_short) |
| 59 | + return i18n.resource('jobs', 'ens', job_name_short) |
| 60 | + end), 'or') |
| 61 | + end |
| 62 | + return "Party has main job "..localization_util.commas(self.job_name_shorts:map(function(job_name_short) |
| 63 | + return i18n.resource('jobs', 'ens', job_name_short) |
| 64 | + end), 'or') |
| 65 | + end |
| 66 | +end |
| 67 | + |
| 68 | +function PartyHasMainJobCondition.description() |
| 69 | + return "Party has any main job of X." |
| 70 | +end |
| 71 | + |
| 72 | +function PartyHasMainJobCondition.valid_targets() |
| 73 | + return S{ Condition.TargetType.Ally, Condition.TargetType.Self } |
| 74 | +end |
| 75 | + |
| 76 | +function PartyHasMainJobCondition:serialize() |
| 77 | + return "PartyHasMainJobCondition.new(" .. serializer_util.serialize_args(self.job_name_shorts) .. ")" |
| 78 | +end |
| 79 | + |
| 80 | +return PartyHasMainJobCondition |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
0 commit comments