找回密码
 点一下
查看: 3476|回复: 1

得到单位防御值

[复制链接]
发表于 2008-5-24 20:41:32 | 显示全部楼层 |阅读模式
这看起来是相当笨,但目前是能想到的最有效的方法,通过普通伤害来计算防御

那么这个就是函数和演示了,因为普通攻击造成的伤害下限是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]

unit defence.w3x

10 KB, 下载次数: 57

评分

参与人数 1威望 +6 收起 理由
喀尔硫司之瞳 + 6 终于又有了。。。

查看全部评分

发表于 2008-5-24 21:00:50 | 显示全部楼层
貌似单位多的话比较麻烦额
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-12-22 16:05 , Processed in 0.197311 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表