Skip to content

Commit

Permalink
Potions and general fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hekili committed Sep 22, 2024
1 parent 7cdc2db commit 5c61d30
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 93 deletions.
224 changes: 149 additions & 75 deletions Classes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -594,20 +594,22 @@ local HekiliSpecMixin = {
end
end,



RegisterPotion = function( self, potion, data )
self.potions[ potion ] = data

data.key = potion

if data.copy then
if type( data.copy ) == "table" then
for _, key in ipairs( data.copy ) do
if data.items then
if type( data.items ) == "table" then
for _, key in ipairs( data.items ) do
self.potions[ key ] = data
CommitKey( key )
end
else
self.potions[ data.copy ] = data
CommitKey( data.copy )
self.potions[ data.items ] = data
CommitKey( data.items )
end
end

Expand Down Expand Up @@ -2318,11 +2320,22 @@ all:RegisterAuras( {
},
} )


do
-- Dragonflight Potions
-- There are multiple items for each potion, and there are also Toxic potions that people may not want to use.
local df_potions = {
local exp_potions = {
{
name = "tempered_potion",
items = { 212971, 212970, 212969, 212265, 212264, 212263 }
},
{
name = "potion_of_unwavering_focus",
items = { 212965, 212964, 212963, 212259, 212258, 212257 }
},
{
name = "frontline_potion",
items = { 212968, 212967, 212966, 212262, 212261, 212260 }
},
{
name = "elemental_potion_of_ultimate_power",
items = { 191914, 191913, 191912, 191383, 191382, 191381 }
Expand All @@ -2331,35 +2344,104 @@ do
name = "elemental_potion_of_power",
items = { 191907, 191906, 191905, 191389, 191388, 191387 }
},

}

all:RegisterAuras( {
elemental_potion_of_ultimate_power = {
id = 371028,
duration = 30,
max_stack = 1
},
elemental_potion_of_power = {
id = 371024,
duration = 30,
max_stack = 1
},
potion = {
alias = { "elemental_potion_of_ultimate_power", "elemental_potion_of_power" },
aliasMode = "first",
aliasType = "buff",
duration = 30
}
} )
local first_potion, first_potion_key
local potion_items = {}

local function getValidPotion()
for _, potion in ipairs( df_potions ) do
all:RegisterHook( "reset_precast", function ()
wipe( potion_items )
for _, potion in ipairs( exp_potions ) do
for _, item in ipairs( potion.items ) do
if GetItemCount( item, false ) > 0 then return item, potion.name end
if GetItemCount( item, false ) > 0 then
potion_items[ potion.name ] = item
break
end
end
end
end
end )

all:RegisterAura( "potion", {
alias = {},
aliasMode = "first",
aliasType = "buff",
duration = 30
} )

local GetItemInfo = C_Item.GetItemInfo

for _, potion in ipairs( exp_potions ) do
local potionItem = Item:CreateFromItemID( potion.items[ #potion.items ] )

potionItem:ContinueOnItemLoad( function()
all:RegisterAbility( potion.name, {
name = potionItem:GetItemName(),
listName = potionItem:GetItemLink(),
cast = 0,
cooldown = 300,
gcd = "off",

startsCombat = false,
toggle = "potions",

item = function ()
return potion_items[ potion.name ] or potion.items[ #potion.items ]
end,
items = potion.items,
bagItem = true,
texture = potionItem:GetItemIcon(),

handler = function ()
applyBuff( potion.name )
end,
} )

class.potions[ potion.name ] = {
name = potionItem:GetItemName(),
link = potionItem:GetItemLink(),
item = potion.items[ #potion.items ]
}

class.potionList[ potion.name ] = "|T" .. potionItem:GetItemIcon() .. ":0|t |cff00ccff[" .. potionItem:GetItemName() .. "]|r"

for i, item in ipairs( potion.items ) do
if not first_potion then
first_potion_key = potion.name
first_potion = item
end

local each_potion = Item:CreateFromItemID( item )

if not each_potion:IsItemEmpty() then
each_potion:ContinueOnItemLoad( function()
local _, spell = GetItemSpell( item )

if not spell then Hekili:Error( "No spell found for item %d.", item ) return false end

if not all.auras[ potion.name ] then
all:RegisterAura( potion.name, {
id = spell,
duration = 30,
max_stack = 1,
copy = { spell }
} )

class.auras[ spell ] = all.auras[ potion.name ]
else
insert( all.auras[ potion.name ].copy, spell )
all.auras[ spell ] = all.auras[ potion.name ]
class.auras[ spell ] = all.auras[ potion.name ]
end

return true
end )
else
Hekili:Error( "Item %d is empty.", item )
end
end
end )
end

all:RegisterAbility( "potion", {
name = "Potion",
Expand All @@ -2371,41 +2453,35 @@ do
startsCombat = false,
toggle = "potions",

item = function ()
return getValidPotion()
consumable = function() return state.args.potion or settings.potion or first_potion_key or "elemental_potion_of_power" end,
item = function()
if state.args.potion and class.abilities[ state.args.potion ] then return class.abilities[ state.args.potion ].item end
if settings.potion and class.abilities[ settings.potion ] then return class.abilities[ settings.potion ].item end
if first_potion and class.abilities[ first_potion ] then return class.abilities[ first_potion ].item end
return class.abilities.elemental_potion_of_power.item
end,
bagItem = true,

timeToReady = function ()
local item = getValidPotion()

if item then
local start, dur = GetItemCooldown( item )
return max( 0, start + dur - query_time )
end

return 3600
end,

handler = function ()
local item, effect = getValidPotion()
local use = all.abilities.potion
use = use and use.consumable

if item and effect then
applyBuff( effect )
if use ~= "global_cooldown" then
class.abilities[ use ].handler()
setCooldown( use, action[ use ].cooldown )
end
end,

usable = function ()
if getValidPotion() ~= nil then return true end
return false, "no valid potions found in inventory"
return potion_items[ all.abilities.potion.item ], "no valid potions found in inventory"
end,

copy = "potion_default"
} )
end





local gotn_classes = {
WARRIOR = 28880,
MONK = 121093,
Expand Down Expand Up @@ -2761,12 +2837,8 @@ all:RegisterAbilities( {
},

healthstone = {
name = function () return ( GetItemInfo( 5512 ) ) or "Healthstone" end,
listName = function ()
local _, link, _, _, _, _, _, _, _, tex = GetItemInfo( 5512 )
if link and tex then return "|T" .. tex .. ":0|t " .. link end
return "|cff00ccff[Healthstone]|r"
end,
name = "Healthstone",
listName = "|T538745:0|t |cff00ccff[Healthstone]|r",
cast = 0,
cooldown = function () return time > 0 and 3600 or 60 end,
gcd = "off",
Expand Down Expand Up @@ -6023,30 +6095,26 @@ end


ns.addHook = function( hook, func )
class.hooks[ hook ] = func
insert( class.hooks[ hook ], func )
end


do
local inProgress = {}

ns.callHook = function( hook, ... )
if class.hooks[ hook ] and not inProgress[ hook ] then
local a1, a2, a3, a4, a5

inProgress[ hook ] = true
for _, hook in ipairs( class.hooks[ hook ] ) do
a1, a2, a3, a4, a5 = hook ( ... )
end
inProgress[ hook ] = nil
if not class.hooks[ hook ] or inProgress[ hook ] then return ... end
local a1, a2, a3, a4, a5 = ...

if a1 ~= nil then
return a1, a2, a3, a4, a5
else
return ...
end
inProgress[ hook ] = true
for _, h in ipairs( class.hooks[ hook ] ) do
a1, a2, a3, a4, a5 = h( a1, a2, a3, a4, a5 )
end
inProgress[ hook ] = nil

if ( a1 ~= nil or a2 ~= nil or a3 ~= nil or a4 ~= nil or a5 ~= nil ) then
return a1, a2, a3, a4, a5
end
return ...
end
end
Expand Down Expand Up @@ -6279,6 +6347,7 @@ function Hekili:SpecializationChanged()

wipe( class.auras )
wipe( class.abilities )
wipe( class.hooks )
wipe( class.talents )
wipe( class.pvptalents )
wipe( class.powers )
Expand Down Expand Up @@ -6392,14 +6461,18 @@ function Hekili:SpecializationChanged()
class.pvptalents[ talent ] = id
end

class.hooks = spec.hooks or {}
--[[ for name, func in pairs( spec.hooks ) do
class.hooks[ name ] = func
end ]]

class.variables = spec.variables

class.potionList.default = "|cFFFFD100Default|r"
class.potionList.default = "|T967533:0|t |cFFFFD100Default|r"
end

if specID == currentID or specID == 0 then
for event, hooks in pairs( spec.hooks ) do
for _, hook in ipairs( hooks ) do
class.hooks[ event ] = class.hooks[ event ] or {}
insert( class.hooks[ event ], hook )
end
end
end

for res, model in pairs( spec.resources ) do
Expand All @@ -6408,6 +6481,7 @@ function Hekili:SpecializationChanged()
state[ res ] = model.state
end
end

if rawget( state, "runes" ) then state.rune = state.runes end

for k, v in pairs( spec.auras ) do
Expand Down
16 changes: 13 additions & 3 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,16 @@ function Hekili:GetPredictionFromAPL( dispName, packName, listName, slot, action
end
elseif action == "main_hand" and class.abilities[ action ].key ~= action and not Hekili:IsItemScripted( action, true ) then
action = class.abilities[ action ].key
ability = class.abilities[ action ]
state.this_action = action
entryReplaced = true
elseif action == "potion" then
local usePotion = entry.potion or spec.potion
if not usePotion or not class.abilities[ usePotion ] then usePotion = class.specs[ specID ].options.potion end
if not usePotion or not class.abilities[ usePotion ] then usePotion = "elemental_potion_of_power" end

action = class.abilities[ usePotion ] and class.abilities[ usePotion ].key or "elemental_potion_of_power"
ability = class.abilities[ action ]
state.this_action = action
entryReplaced = true
end
Expand Down Expand Up @@ -1097,7 +1107,7 @@ function Hekili:GetPredictionFromAPL( dispName, packName, listName, slot, action
Timer:Track("Post Recheck")

if aScriptPass then
if action == "potion" then
--[[ if action == "potion" then
local item = class.abilities.potion.item
slot.scriptType = "simc"
Expand Down Expand Up @@ -1130,9 +1140,9 @@ function Hekili:GetPredictionFromAPL( dispName, packName, listName, slot, action
-- slot.indicator = ( entry.Indicator and entry.Indicator ~= "none" ) and entry.Indicator
state.selection_time = state.delay
state.selected_action = rAction
state.selected_action = rAction ]]

elseif action == "wait" then
if action == "wait" then
local sec = state.args.sec or 0.5

if sec <= 0 then
Expand Down
Loading

0 comments on commit 5c61d30

Please sign in to comment.