DamageReductionTable 1.1c

Basically this system is used to set a unit's damage and spell reduction values and supports dynamic changing of a unit's reduction values.


And yeah, I know that its pretty simple...

I think this system is useful for custom damage systems and it also comes with a simple custom damage library as an example of how to use the system...


V1.1- added a new library which enables you to set the reduction values of items and automatically updates the unit's reduction values upon pick/drop/pawn of items.
V1.1b - placed the GetInstance method on top as per what Bribe said.
V1.1c - just some opt on the Get functions.


JASS:
//This is a custom Damage Reduction system that provides easy setting and changing of
//a unit's damage reduction and spell reduction by just using some function calls
//No object data needed to be created in the Object editor
//This system is useful for maps that will be having a custom damage system

//////////////////////////////////////////////////////////////////////////////
//--------------HOW TO USE--------------------------------------------------//
//--------------HOW TO INITIALIZE-------------------------------------------//
//First you need to initialize each unit that will use this system using    //
//                                                                          //
//DamageReduction.create(unit target, real damagered, real spellred)        //
//                                                                          //
//unit target = unit to be initialized                                      //
//                                                                          //
//real damagered = damage reduction value                                   //
//                                                                          //
//real spellred = spell reduction value                                     //
//                                                                          //
//-------------HOW TO GET VALUES--------------------------------------------//
//                                                                          //
//To get the value of spell or damage reduction just use these 2 functions: //
//                                                                          //
//DamageReduction.GetDamageReduction(unit u)                                //
//                                                                          //
//DamageReduction.GetSpellReduction(unit u)                                 //
//                                                                          //
//-------------HOW TO MODIFY VALUES IN-GAME---------------------------------//
//                                                                          //
//To modify values in-game just use these 2 functions:                      //
//                                                                          //
//DamageReduction.AddSpellReduction(unit target, real value, boolean add)   //
//                                                                          //
//DamageReduction.AddDamageReduction(unit target, real value, boolean add)  //
//                                                                          //
//unit target is the unit whose reduction value you want to change          //
//                                                                          //
//real value is the value of reduction to be used                           //
//                                                                          //
//boolean add if true will add real value to the current reduction          //
//                                                                          //
//while if false will set reduction to real value                           //
//                                                                          //
//NOTE: these two functions returns the new reduction values so if you need //
//to use those right away, you can directly use these function rather than  //
//using the Add function and then using the Get functions afterwards        //
//                                                                          //
//------------REMOVING INSTANCES--------------------------------------------//
//                                                                          //
//The system already checks every UPDATE_TIME interval for instances that   //
//                                                                          //
//are already unused due to the unit being dead and destroys that instance  //
//                                                                          //
//automatically.                                                            //
//                                                                          //
//You can destroy an instance directly by using                             //
//DamageReduction.Clear(unit u)                                             //
//////////////////////////////////////////////////////////////////////////////



library DamageReductionTable
//Version 1.1c
//By: Adiktuz
    
    globals
        private constant real UPDATE_TIME = 1.00
        //This is the timer interval between the system's check for dead units to remove their instances
        private integer array DRI
        private integer TOTAL = 0
        private timer DRT_TIMER = CreateTimer()
    endglobals
    
    struct DamageReduction
        real DAMAGE_REDUCTION
        real SPELL_REDUCTION
        unit u
        static thistype data
        
        //Used by the methods in this system to translate the unit parameter
        //into its struct instance
        static method GetInstance takes unit target returns thistype
            local integer i = 0
            loop
                exitwhen i == TOTAL
                set data = DRI[i]
                if target == data.u then
                    set i = TOTAL
                else
                    set i = i + 1
                    set data = 0
                endif
            endloop
            return data
        endmethod
        
        //Methods for Getting and setting reduction data
        static method GetDamageReduction takes unit u returns real
            return data.GetInstance(u).DAMAGE_REDUCTION
        endmethod
        
        static method GetSpellReduction takes unit u returns real
            return data.GetInstance(u).SPELL_REDUCTION
        endmethod
        
        static method AddSpellReduction takes unit target, real value ,boolean add returns real
            set data = DamageReduction.GetInstance(target)
            if add then
                set data.SPELL_REDUCTION = data.SPELL_REDUCTION + value
            else
                set data.SPELL_REDUCTION = value
            endif
            return data.SPELL_REDUCTION
        endmethod
        
        static method AddDamageReduction takes unit target, real value ,boolean add returns real
            set data = DamageReduction.GetInstance(target)
            if add then
                set data.DAMAGE_REDUCTION = data.DAMAGE_REDUCTION + value
            else
                set data.DAMAGE_REDUCTION = value
            endif
            return data.DAMAGE_REDUCTION
        endmethod
        
        
        
        //Method for clearing a unit's instance immediately
        static method Clear takes unit u returns nothing
            local integer i = 0
            set data = DamageReduction.GetInstance(u)
            loop
                exitwhen i == TOTAL
                if data == DRI[i] then
                    set TOTAL = TOTAL - 1
                    set DRI[i] = DRI[TOTAL]
                    set i = TOTAL
                    call data.destroy()
                else
                    set i = i + 1
                endif
            endloop
        endmethod
        
        //This method scans for instanced units that are already dead
        //and destroy's their instance
        static method update takes nothing returns nothing
            local integer i = 0
            loop
                exitwhen i == TOTAL
                set data = DRI[i]
                if data.u == null or GetWidgetLife(data.u) < .405 then
                    set TOTAL = TOTAL - 1
                    set DRI[i] = DRI[TOTAL]
                    set i = i - 1
                    call data.destroy()
                endif
                set i = i + 1
            endloop
            if TOTAL == 0 then
                call PauseTimer(DRT_TIMER)
            endif
        endmethod
        
        //This method is used to initialize each unit for the system
        static method create takes unit target, real damagered, real spellred returns thistype
            set data = DamageReduction.allocate()
            set data.DAMAGE_REDUCTION = damagered
            set data.SPELL_REDUCTION = spellred
            set data.u = target
            set DRI[TOTAL] = data
            if TOTAL == 0 then
                call TimerStart(DRT_TIMER, UPDATE_TIME, true, function DamageReduction.update)
            endif
            set TOTAL = TOTAL + 1
            return data
        endmethod
    endstruct
    
endlibrary

Keywords:
damage, armor, spell, damage reduction, vjass, jass, systems, custom, structs
Contents

DamageReductionTable (Map)

Reviews
20:26, 3rd Nov 2010 The_Reborn_Devil: Pretty simple, but neat. Status: Approved Rating: Useful

Moderator

M

Moderator

20:26, 3rd Nov 2010
The_Reborn_Devil:

Pretty simple, but neat.


Status: Approved
Rating: Useful
 
Level 15
Joined
Jul 6, 2009
Messages
889
Ow. My eyes pain reading that code header. Also I think this should be in (v)JASS Submissions.

You could also directly return things;

JASS:
        static method GetDamageReduction takes unit u returns real
            set data = DamageReduction.GetInstance(u)
            return data.DAMAGE_REDUCTION
        endmethod

-->

JASS:
        static constant method GetDamageReduction takes unit u returns real
            return DamageReduction.GetInstance(u).DAMAGE_REDUCTION
        endmethod

And what of armor values?
 
Ow. My eyes pain reading that code header. Also I think this should be in (v)JASS Submissions.

You could also directly return things;

JASS:
        static method GetDamageReduction takes unit u returns real
            set data = DamageReduction.GetInstance(u)
            return data.DAMAGE_REDUCTION
        endmethod

-->

JASS:
        static constant method GetDamageReduction takes unit u returns real
            return DamageReduction.GetInstance(u).DAMAGE_REDUCTION
        endmethod

And what of armor values?

oh... didnt know that... ^^... gonna change it maybe tomorrow after I go home...

well, if you use this system, you need to set them yourself...

for armor bonuses it could be easy if you're using an equipment system
(already found a workaround when using The_Watcher's equip system...), and for the normal one, you might need to make something which will store every item-types armor bonus value....

about the JASS submission section... hmmm... I guess so... ^^
 
So if I use this, and give a unit 100% reduction for damage & spells, then it would basically take 0 damage from everything?

Also
JASS:
DamageReduction.Clear(unit u)

Removes the Reductions from the unit, right?

yup, if you set damage to be Damage*(100%-reduction%)... ^_^

it would totaly depend on how you will use it, you can also do 1 damage reduction per reduction value (Damage - reduction)

But you should make all damages custom... ^_^

and yes, it would remove the reduction effect from the unit.

EDIT: I might add an additional option that will enable you to initialize the armor value of items so that if a unit gets an item, the armor value will automatically be updated.
 
Level 13
Joined
Mar 13, 2010
Messages
1,211
This system could be very useful, in fact I'll even need it for my own map if you don't mind. Another masterpiece Adiktuz :thumbs_up:
 
Level 22
Joined
Feb 3, 2009
Messages
3,292
+ useless
165490-albums3158-picture37396.jpg

Please don't be a troll, if you really need to, there is a Troll Warlord in DotA to play with.

could you say why?

I'm aware that this system is not useful for Advanced Users, because this system is not made for Advanced users who can code awesome systems, this is for those you wants simple things.

I think it's an obvious troll :thumbs_down:
 
Level 13
Joined
Mar 13, 2010
Messages
1,211
I'm aware that this system is not useful for Advanced Users, because this system is not made for Advanced users who can code awesome systems, this is for those you wants simple things.

And simple systems are what helps us map makers, who can't make our own systems, a lot. What would the spell section be without simple things ;)
 
The method "GetInstance" is compiled wrong in vJass. Instead of top-sort, which would be logical, vJass turns this into a function interface and therefore uses trigger evaluations instead of simple call/return. Move GetInstance to above the methods which call it in order to avoid this.

done! thanks! :goblin_good_job:
 
Level 1
Joined
Jan 4, 2011
Messages
1
165490-albums3158-picture37396.jpg

Please don't be a troll, if you really need to, there is a Troll Warlord in DotA to play with.

Sorry for being offtopic but this made me laugh hard!

As for the system, I think it's great for people who try to learn JASS amongst acctually using this system in their humble maps. People like myself. Thank you for posting this!
 
Top