• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Damage Formula in JASS Spells

Status
Not open for further replies.
I want to make a damage formula as:

CONST FACTOR + (LEVEL FACTOR * AbilityLevel) + (PREV LEVEL FACTOR * PrevLevelDamage)

The CONST FACTOR and LEVEL FACTOR * AbilityLevel was easy to make but the problem is with the PREV LEVEL FACTOR * PrevLevelDamage

Here is a part of the script:

JASS:
scope AoETemplate initializer Init
    private keyword Data
 
    globals
        // Constants
        private constant real TIMER_INTERVAL = 0.015
        private constant real DIST = 16.00
        private constant real NOVA_RADIUS = 512.00 // radius of the Nova
        private constant integer NOVA_SIZE = 36 // number of the Nova Units
        private constant real dA = 360/NOVA_SIZE
        private constant integer UNIT_ID = 'e001' // rawcode of the Nova Unit
        private constant integer ABIL_ID = 'A001' // rawcode of the Dummy Spell
        private constant attacktype ATKTYPE = ATTACK_TYPE_MAGIC
        private constant damagetype DMGTYPE = DAMAGE_TYPE_FIRE
        private constant real AB_CONST_FACTOR = 50.00
        private constant real AB_LEVEL_FACTOR = 50.00
        private constant real AB_PREV_LVL_FACTOR = 1
        // Variables
        private timer tm = CreateTimer()
        private Data array temp_dat
        private integer index = 0
        private Data iFilter // Filter Data
        private boolexpr fFilter // Filter function
        private group TempGroup = CreateGroup()
    endglobals
    private struct Data
        unit Caster
        unit array Nova[NOVA_SIZE]
        real expand
        real Cx
        real Cy
        player Owner
        group dGroup = CreateGroup() // Damaged Units Group
        real dmg
        real prev
 
        static method Damage takes integer AbiLevel returns real
            local real damage = AB_CONST_FACTOR + AB_LEVEL_FACTOR * AbiLevel //+ AB_PREV_LVL_FACTOR * prev
        return damage
        endmethod
 
        // ...
        //rest of the script
        // ...
 
        static method create takes unit caster returns Data
            local thistype dat = thistype.allocate()
            local integer i = 0
            local real A = 0.00
            set dat.Caster = caster
            set dat.Owner = GetOwningPlayer(dat.Caster)
            set dat.Cx = GetUnitX(dat.Caster)
            set dat.Cy = GetUnitY(dat.Caster)
            set dat.dmg = Data.Damage(GetUnitAbilityLevel(dat.Caster,ABIL_ID))
 
        // ...
        // To the end of the script
        // ...

This is the same script that good :thumbs_up: Element of Water fixed it to me, I just wanted to add a damage function but I was stuck by that problem.
 
Assuming factor is not constant (either that the prev level factor is different from the current level factor, or that the factor is a formula). If it is, there's a better way:

JASS:
constant function Factor takes integer lv returns real
    return someFormula
endfunction

constant function GetDamage takes integer lv returns real
    if lv > 1 then
        return const+lv*Factor(lv)+GetDamage(lv-1)*Factor(lv-1)
    endif
    return const+lv*Factor(lv)
endfunction
 
Try this function. Don't ask how it works, I don't really know either. I just know that it kinda does work.

JASS:
function GetDamage takes integer level returns real
    local real prevDamage
    if level == 1 then
        set prevDamage = 0
    else
        set prevDamage = GetDamage.evaluate(level - 1)
    endif
    
    return CONST_FACTOR + (LEVEL_FACTOR * level) + (PREV_LEVEL_FACTOR * prevDamage)
endfunction
 
Try this function. Don't ask how it works, I don't really know either. I just know that it kinda does work.

JASS:
function GetDamage takes integer level returns real
    local real prevDamage
    if level == 1 then
        set prevDamage = 0
    else
        set prevDamage = GetDamage.evaluate(level - 1)
    endif
 
    return CONST_FACTOR + (LEVEL_FACTOR * level) + (PREV_LEVEL_FACTOR * prevDamage)
endfunction
.evaluate don't work inside static members.

<< ADDED >>

OK, EOW no need to answer. I just made a function outside the struct as you mentioned and it worked.

It seems that .evaluate runs a function and ignores anything inside it; it looks only for the arguments and the return value or so it seems to me.
 
Last edited:
Status
Not open for further replies.
Back
Top