|
这看起来是相当笨,但目前是能想到的最有效的方法,通过普通伤害来计算防御
那么这个就是函数和演示了,因为普通攻击造成的伤害下限是1~,所以能通过计算来算出的防御值是受到检测伤害大小的限制的;另外,当前版本没有考虑负数护甲的计算和无敌时的情况~
[codes=jass]globals
constant real DefArmor = 0.06
constant real DetDamage =5.
constant attacktype DetAT=ATTACK_TYPE_CHAOS
real AttackTypeCorr=1.
timer AfterDetRev=null
real array DamageHeal
unit array DamageRecU
integer TimeupSeq=0
unit DamageSc=null
gamecache GeneralC=null
trigger DetTrg=null
endglobals
function msg takes string s returns nothing
call DisplayTimedTextFromPlayer(GetLocalPlayer(),0,0,10,s)
endfunction
function h2i takes handle h returns integer
return h
return 0
endfunction
function Healto takes nothing returns nothing
loop
exitwhen TimeupSeq==0
call SetUnitState(DamageRecU[TimeupSeq],UNIT_STATE_LIFE,GetUnitState(DamageRecU[TimeupSeq],UNIT_STATE_LIFE)+DamageHeal[TimeupSeq])
set DamageRecU[TimeupSeq]=null
set DamageHeal[TimeupSeq]=0
set TimeupSeq=TimeupSeq-1
endloop
call PauseTimer(GetExpiredTimer())
set TimeupSeq=0
endfunction
function RnC takes nothing returns nothing
if GetEventDamageSource() != DamageSc then
return
endif
call msg("dmg="+R2SW(GetEventDamage(),5,5))
call StoreReal(GeneralC,I2S(h2i(GetTriggerUnit())),"Def",(DetDamage-GetEventDamage())/(DefArmor*GetEventDamage()))
set TimeupSeq=TimeupSeq+1
set DamageHeal[TimeupSeq]=GetEventDamage()
set DamageRecU[TimeupSeq]=GetTriggerUnit()
call TimerStart(AfterDetRev,0.,false,function Healto)
endfunction
function RegDefenceDet takes unit u returns nothing
if GetStoredBoolean(GeneralC,I2S(h2i(u)),"reg")==false then
call StoreBoolean(GeneralC,I2S(h2i(u)),"reg",true)
call TriggerRegisterUnitEvent(DetTrg,u,EVENT_UNIT_DAMAGED)
endif
call UnitDamageTarget(DamageSc,u,DetDamage,false,false,DetAT,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
endfunction
//===========================================================================
function InitTrig_UnitDefAct takes nothing returns nothing
set DamageSc=CreateUnit(Player(15),'ewsp',0,0,0)
set GeneralC=InitGameCache("GetDef.w3v")
set AfterDetRev=CreateTimer()
set DetTrg=CreateTrigger()
call TriggerAddCondition(DetTrg,Condition(function RnC))
call ShowUnit(DamageSc,false)
call PauseUnit(DamageSc,true)
endfunction
[/codes] |
评分
-
查看全部评分
|