How to change an active ability into a passive ability?

So basically i want to make every single active ability in dota 2 into passive ability. For example, Juggernaut's blade fury can be proced by attacking units, lets say 25%chance to proc blade fury. So how should I code as i have completely no idea about it.

Comments

  • Well, the easiest way i see is to add modifier on hero, that will track attacks landed and roll percentage, and then, if chance proced, cast ability. But you will need unqiue modifier for each hero to set different chances and simulate different skills behaviors (for example, before casting Omni Slash, you need to set target for it manualy, since you made all your active abilities to passives and thus orders will not work)

    modifier_juggernaut_attack_roll = class({})
    
    -- hiding this modifier so we don't need to localize it
    function modifier_juggernaut_attack_roll:IsHidden( ... )
        return false
    end
    
    -- declaring function to track attacks
    function modifier_juggernaut_attack_roll:DeclareFunctions( ... )
        local funcs = {
            MODIFIER_EVENT_ON_ATTACK_LANDED,
        }
        return funcs
    end
    
    -- using this function to track attacks (this example is done for Blade Fury, other abilities are added in similar way)
    function modifier_juggernaut_attack_roll:OnAttackLanded(params)
        if params.attacker ~= self:GetParent() then return end
        local blade_fury_ability = params.attacker:GetAbilityByIndex(0) -- index is based by knowing ability position, wich is first, and it's index is 0
        local proc_chance = blade_fury_ability:GetSpecialValueFor("proc_chance") -- you will need to add another field in every ability kv with this or similar name to track
        if RollPercentage(proc_chance) then
            blade_fury_ability:OnSpellStart() -- casting ability
            blade_fury_ability:UseResources(true, true, true) -- spending it's resources, remove this line if not needed
        end
    end
    

    So, to summarize, you will need to edit evety ability kv to set it behavior to passive, and add new AbilitySpecial field with proc chance, and write modifier for each hero with their abilities tracked, and then apply modifiers on hero spawned in addon_game_mode