Snippet DbMod-alpha

weaaddar

New Member
Reaction score
6
Edit updated:: Now its configurable. You can now modify the levels of each sub property, the abilityId and the button positions. I don't know if Lua has a string format like C does, if it does I'll make the tooltip configurable.

Here is a resource that is used to manipulate drunken brawler and set different levels of evasion, critical hit rate and the crit hit damage multiplier.

The whole thing generates an ability and is fairly easy to configure with some minor textmacro abuse.

I realize that there is some belief that using text macros should be discouraged, but since there isn't an easy way to generate 100 level abilities in the worldeditor, this macro abuse is probably the best way.

I don't know lua, so I have no idea how to do proper string formatting (for now just straight concat). if someone can share how, I'll allow configuration of the tooltip for the ability.


(Note the current example code creates a 100 level ability, with
evasion (5 levels): 0,0.07,0.14,0.21,0.28
DamageMultiplier(4 levels): 1.5,2.0,2.5,3.0
Critical Hit rate(5 levels): 0,10,15,20,25)

It is in Vjass now.
Zinc and external blocks don't mix for some reason.
JASS:
library DBMod
    struct DBMod
    //! externalblock extension=lua ObjectMerger $FILENAME$
    /*****************************************************************
     *                       DBMod  -- Alpha                               
     *****************************************************************
        DBMod is a framework to manipulate the ability Drunken Brawler
        and allow it to be modified in runtime. It turns the ability
        into 3 extra properties for a unit,allowing the modification 
        of the evasion, damage multiplier and critical hit rate at run
        time. 
        Static properties and methods::
        -------------------------------
        thistype operator[unit u]
            Get the DBMod for this unit. A Dbmod holds the data stored
            for this unit, and allows application of different levels of
            evasion, dmg multiple, crit hit rate. 
            Note: On first retrieval the DBMod ability is added at level 1.
            
        setBonuses(unit u,integer evs,integer dmg,integer crt)
            Sets the evasion at evs,damage multiplier at dmg,crit hit rate at crt
            for unit u.
        
        Instance properties::
        ---------------------
        integer EvsRateLevel
            gets or sets the evasion rate level for this unit.*
        
        integer DmgMultLevel
            gets or sets the damage multiplier level for this unit.*
        
        integer CrtRateLevel
            gets or sets the critical hit rate for this unit.*
        
        * While you can set these values to anything you like, the abilities
        only function between 0 and MaxLevel for the ability.
    Configuration macros
        StartDBModConfig takes AbilityId,posX,posY
            configures the ability. Choose the abilityId, and its position on the Command
        ConfigEvsRate takes Rates,lvl
        ConfigDmgMult takes Rates,lvl
        ConfigCrtRate takes Rates,lvl
            configures the levels. Rates is a comma delimited list of values. Lvl
            is the number of levels
    EndDBModConfig()
            finishes the configuration. Must be called.
        *****************************************************************/
        //! runtextmacro StartDBModConfig("WAFP","0","0")
            //! runtextmacro ConfigEvsRate("0,0.07,0.14,0.21,0.28","5")
            //! runtextmacro ConfigDmgMult("1.5,2.0,2.5,3.0","4")
            //! runtextmacro ConfigCrtRate("0,10,15,20,25","5")
        //! runtextmacro EndDBModConfig()
        static constant integer EVS = 0
        static constant integer DMG = 1
        static constant integer CRT = 2
        private static integer array MaxLevels
        private unit m_unit
        private integer m_evs
        private integer m_dmg
        private integer m_crt
        private static hashtable Table = InitHashtable()
        static method GetMaxLevel takes integer dbType returns integer
            return MaxLevels[dbType]
        endmethod
        private static method GetSafeVal takes integer dbtype,integer val returns integer
            if(val <= 0)then
                return 0
            elseif(val >= GetMaxLevel(dbtype)-1)then
                return GetMaxLevel(dbtype)-1
            endif
            return val
        endmethod
        private method setBonus takes nothing returns nothing
            local integer level = 1 + GetSafeVal(CRT,m_crt)+ GetMaxLevel(CRT)*GetSafeVal(DMG,m_dmg)+(GetMaxLevel(CRT)*GetMaxLevel(DMG))*GetSafeVal(EVS,m_evs)
            debug call BJDebugMsg(I2S(level))
            call UnitRemoveAbility(m_unit,DBMOD_ABIL )
            call UnitAddAbility(m_unit,DBMOD_ABIL)
            call SetUnitAbilityLevel(m_unit,DBMOD_ABIL,level)
        endmethod
        
        static method create takes unit u returns thistype
            local thistype ret = thistype.allocate()
            set ret.m_unit = u
            call SaveInteger(Table,GetHandleId(ret.m_unit),0,ret)
            set ret.m_evs = 0
            set ret.m_dmg = 0
            set ret.m_crt = 0
            call ret.setBonus()
            return ret
        endmethod
        
                
        static method operator[] takes unit u returns thistype
            local thistype data = LoadInteger(Table,GetHandleId(u),0)
            if(data > 0)then
                return data
            endif
            return thistype.create(u)
        endmethod
        
        static method setBonuses takes unit u,integer evs,integer dmg,integer crt returns nothing
            local thistype data = DBMod<u>
            set data.m_evs = evs
            set data.m_dmg = dmg
            set data.m_crt = crt
            call data.setBonus()
        endmethod
        
        method operator EvsRateLevel takes nothing returns integer
            return m_evs
        endmethod
        
        method operator DmgMultLevel takes nothing returns integer
            return m_dmg
        endmethod
        
        method operator CrtRateLevel takes nothing returns integer
            return m_crt
        endmethod
        
        method operator EvsRateLevel= takes integer value returns nothing
            set m_evs = value
            call setBonus()
        endmethod 
        
        method operator DmgMultLevel= takes integer value returns nothing
            set m_dmg = value
            call setBonus()
        endmethod
        
        method operator CrtRateLevel= takes integer value returns nothing
            set m_crt = value
            call setBonus()
        endmethod
    endstruct
endlibrary
//! endexternalblock

//! textmacro StartDBModConfig takes abilityId,posX,posY
    //! i local level = 0
    //! i local ability = &quot;$abilityId$&quot;
    //! i setobjecttype(&quot;abilities&quot;)
    //! i createobject(&quot;ANdb&quot;,ability)
    //! i makechange(current,&quot;abpx&quot;,$posX$)
    //! i makechange(current,&quot;abpy&quot;,$posY$)
            static constant integer DBMOD_ABIL = &#039;$abilityId$&#039;
        static method onInit takes nothing returns nothing
//! endtextmacro
//! textmacro ConfigEvsRate takes rates,lvl
            set MaxLevels[EVS] = $lvl$
            
    // Ocr4
    //! i local evsrate = {$rates$} 
    //! i local maxevslvl = #evsrate
//! endtextmacro

//! textmacro ConfigDmgMult takes rates,lvl
            set MaxLevels[DMG] = $lvl$
    // Ocr2
    //! i local dmgmult = {$rates$}
    //! i local maxdmglvl = #dmgmult
//! endtextmacro
//! textmacro ConfigCrtRate takes rates,lvl
            set MaxLevels[CRT] = $lvl$
    // Ocr1
    //! i local crtrate = {$rates$}
    //! i local maxcrtlvl = #crtrate
//! endtextmacro

//! textmacro EndDBModConfig
            endmethod
    //! i makechange(current,&quot;alev&quot;,maxevslvl*maxdmglvl*maxcrtlvl)
    //! i for i = 1,maxevslvl do
        //! i for j = 1,maxdmglvl do
            //! i for k = 1,maxcrtlvl do
                //! i level = 1+(i-1)*(maxcrtlvl*maxdmglvl)+(j-1)*maxcrtlvl+(k-1)
                //! i makechange(current,&quot;Ocr4&quot;,level,evsrate<i>)
                //! i makechange(current,&quot;Ocr2&quot;,level,dmgmult[j])
                //! i makechange(current,&quot;Ocr1&quot;,level,crtrate[k])
                //! i makechange(current,&quot;atp1&quot;,level,&quot;---Combat Profeciencies---&quot;)
                //! i makechange(current,&quot;aub1&quot;,level,&quot;Evasion Rate: |cffffcc00&lt;&quot;.. ability..&quot;,DataD&quot;.. level ..&quot;,%&gt;% |n|rCritical Hit Multiplier: |cffffcc00&lt;&quot;..ability..&quot;,DataB&quot;.. level ..&quot;,%&gt;%|r|nCritical Hit Rate: |cffffcc00&lt;&quot;..ability..&quot;,DataA&quot;.. level ..&quot;&gt;% |r&quot;)
            //! i end            
        //! i end
    //! i end
//! endtextmacro
</i></u>



Finally, here is a simple test library to show how one might use the library.
JASS:
//! zinc
library test requires DBMod
{
    unit u;
    function onInit()
    {
        integer i;
        u = CreateUnit(Player(0),&#039;Hpal&#039;,0,0,0);
        i = DBMod<u>;
    }
    public function Trig_textMessage_Actions()
    {
         DBMod<u>.EvsRateLevel = S2I(SubString(GetEventPlayerChatString(),0,1));
        DBMod<u>.DmgMultLevel = S2I(SubString(GetEventPlayerChatString(),1,2));
        DBMod<u>.CrtRateLevel = S2I(SubString(GetEventPlayerChatString(),2,3));
    }
}
//! endzinc
//===========================================================================
function InitTrig_textMessage takes nothing returns nothing
    set gg_trg_textMessage = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_textMessage, Player(0), &quot;&quot;, false )
    call TriggerAddAction( gg_trg_textMessage, function Trig_textMessage_Actions )
endfunction
</u></u></u></u>

 

the Immortal

I know, I know...
Reaction score
51
Ynow, reminds me of the time when I was writing WoW addons. Never knew ObjMerger supports LUA, and even when J4L abused it that good in his Inv system didn't look much into it.

And although I find it really.. well, sloppy (read below) it perfectly 'explains' how to use LUA in conj with ObjMerger. And that's win. =P

About the snippet - if one would really use it, (with much more levels as well, I suppose) it'd be just better to use 3 different abilities each giving the different bonuses instead of this.
3 abilities x N levels vs. 1 ability with N^3 levels
No need to say the 2nd would be much more optimized. Even thou it'd probably require 2 more spellbooks.
 

weaaddar

New Member
Reaction score
6
Well, I've updated and made it configurable now. I still don't know lua at all. And I had to switch to Vjass as Zinc and external block don't work together. That idea won't really work that great as then you can't see how much you have (without some other mechanism), and then its per player rather then per unit.

Plus Damage multiplier and crit hit rate are intrinsically tied.

Beside, with OM its stupid easy to generate the ability (which is the best part really), and it doesn't seem to add much to load time.

Its annoying but there doesn't seem to be a mechanism to send data from Lua to Jass. The only thing you can do is have a text macro generate some stuff that can be done at compile time for lua, and at runtime in an OnInit trigger for jass. Which is a shame, as it could've been neat to use lua to do compile time evaluations and code generation.
 

Jesus4Lyf

Good Idea™
Reaction score
397
I don't know lua, so I have no idea how to do proper string formatting (for now just straight concat). if someone can share how, I'll allow configuration of the tooltip for the ability.
No offense, but that's weak.
I didn't know a scrap of LUA before I wrote ItemStruct.
And you can rip string concatenation out of it. It's:
JASS:
//! i myString=&quot;dog&quot;
//! i myString=myString..myString

".." seems to be concatenate.

Edit:
This leaks - it uses hashtables and never flushes the value when the unit leaves the game. I suggest you use AIDS - which is more efficient and user friendly for cleanup functionality.
 

weaaddar

New Member
Reaction score
6
Yeah, I got the concat operator from googling. But I need something like a string format so that you can send it in a text macro what you want as, text macros don't allow escaping characters.
i.e.
[ljass]//! runtextmacro SetToolTip("Here is a tooltip mentioning something"..dataA$.."more text") [/ljass] won't work

As for the autoindexing complaint, while technically valid is a very minor issue. If you really are hellbent on applying dbmod to 8000+ units, then adding an aids/autoindex/pui is certainly a possibility. I'll probably make an optional autoindex version, as the hashtable version is easiest and the leak is one ht index, and array locations. Its not leaking like a sieve.
 

weaaddar

New Member
Reaction score
6
Less icon space on the command card? Hey it was a great Idea in 2005 when I first made this resource :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top