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.
Finally, here is a simple test library to show how one might use the library.
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 = "$abilityId$"
//! i setobjecttype("abilities")
//! i createobject("ANdb",ability)
//! i makechange(current,"abpx",$posX$)
//! i makechange(current,"abpy",$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,"alev",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,"Ocr4",level,evsrate<i>)
//! i makechange(current,"Ocr2",level,dmgmult[j])
//! i makechange(current,"Ocr1",level,crtrate[k])
//! i makechange(current,"atp1",level,"---Combat Profeciencies---")
//! i makechange(current,"aub1",level,"Evasion Rate: |cffffcc00<".. ability..",DataD".. level ..",%>% |n|rCritical Hit Multiplier: |cffffcc00<"..ability..",DataB".. level ..",%>%|r|nCritical Hit Rate: |cffffcc00<"..ability..",DataA".. level ..">% |r")
//! 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;Hpal039;,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), "", false )
call TriggerAddAction( gg_trg_textMessage, function Trig_textMessage_Actions )
endfunction
</u></u></u></u>