|
本帖最后由 Simonade 于 2013-7-19 15:07 编辑
//这个hashtable专门用于这两个物品(技能),没有其他技能或程序的绑定数据
//=============================================================================
globals
hashtable h=InitHashtable()
endglobals
//=============================================================================以下是攻击者死亡后排泄攻击者身上的数据(摧毁创建的对象后)
function AttackerDeath takes nothing returns nothing //其实是想防止吸血鬼祭品光环给攻击者添加的带buff空法球技能因攻击者死亡而泄露
local unit u=GetTriggerUnit() //不知道用不用排泄给单位添加的技能,但还是用了。。。
call UnitRemoveAbility(u,'A005')
call DestroyTrigger(LoadTriggerHandle(h,GetHandleId(u),10))
set u=null
endfunction
//=============================================================================以下区域是黯灭技能
function bAA takes nothing returns nothing //效果持续时间的计时器到期时如果目标没死的话就恢复减少的护甲,删除对该目标的受伤害触发
local timer t=GetExpiredTimer() //清空整个事件中给单位绑定的数据
local unit u=LoadUnitHandle(h,GetHandleId(t),0)
local integer bn=LoadInteger(h,GetHandleId(u),2)
local real armor
set armor=GetUnitState(u,ConvertUnitState(0x20))
call SetUnitState(u,ConvertUnitState(0x20),armor+5.0*bn)
call UnitRemoveAbility(u,'A002')
call DestroyTrigger(LoadTriggerHandle(h,GetHandleId(u),1))
call PauseTimer(LoadTimerHandle(h,GetHandleId(u),1))
call DestroyTimer(LoadTimerHandle(h,GetHandleId(u),1))
call FlushChildHashtable(h,GetHandleId(u))
call DestroyTimer(t)
call FlushChildHashtable(h,GetHandleId(t)) call BJDebugMsg("特殊效果到期作用目标"+GetUnitName(u)+"脱离战斗")
set t=null
set u=null
endfunction
function RefreshTimer takes unit u returns timer // 刷新用于记录减甲持续时间的计时器
call UnitRemoveAbility(u,'A002')
call PauseTimer(LoadTimerHandle(h,GetHandleId(u),3))
call DestroyTimer(LoadTimerHandle(h,GetHandleId(u),3))
return CreateTimer()
endfunction
//==============================================================================以下是Skills函数区域
function Skills takes nothing returns nothing
local unit u=GetTriggerUnit()
local unit a=GetEventDamageSource()
local boolean bA=LoadBoolean(h,GetHandleId(u),11)
local boolean bB=LoadBoolean(h,GetHandleId(u),12)
local timer t
local integer bn=LoadInteger(h,GetHandleId(u),2)
local real armor
if GetTriggerEventId()==EVENT_UNIT_DEATH then
//call BJDebugMsg(GetUnitName(u)+"死亡时被攻击命中次数"+I2S(bn))
call DestroyTrigger(LoadTriggerHandle(h,GetHandleId(u),10))
call PauseTimer(LoadTimerHandle(h,GetHandleId(u),1))
call DestroyTimer(LoadTimerHandle(h,GetHandleId(u),1))
call FlushChildHashtable(h,GetHandleId(u))
set u=null
set a=null
return
elseif GetUnitAbilityLevel(u,'B002')>0 then//用同一个buff判定攻击命中
call UnitRemoveAbility(u,'B002')
if ((bA==true) and (GetUnitAbilityLevel(a,'A003')>0)) then //【黯灭】
call UnitAddAbility(u,'A002')
set bn=bn+1
call BJDebugMsg("被减甲次数"+I2S(bn))
set armor=GetUnitState(u,ConvertUnitState(0x20))
call SetUnitState(u,ConvertUnitState(0x20),armor-5.0)
set t=RefreshTimer(u) //【每次符合条件的伤害事件】会刷新减甲效果持续时间
call SaveInteger(h,GetHandleId(u),2,bn)
call SaveTimerHandle(h,GetHandleId(u),3,t)
call SaveUnitHandle(h,GetHandleId(t),0,u)
call TimerStart(t,4.5,false,function bAA)
elseif bB==true and GetUnitAbilityLevel(a,'B003')>0 and not IsUnitType(a,UNIT_TYPE_DEAD)then //【吸血鬼祭品光环】
if GetUnitAbilityLevel(a,'A005')>0 then
call UnitRemoveAbility(a,'A005')
endif
call SetUnitState(a,UNIT_STATE_LIFE,GetUnitState(a,UNIT_STATE_LIFE)+GetEventDamage()*0.25)
endif
endif
set u=null
set a=null
set t=null
endfunction
//=======================================================================以下区域是排泄单位动态注册的trigger和有关单位身上绑定数据(摧毁了创建的对象后)
function InitAll takes nothing returns nothing // 这个就是针对攻击没有命中的情况,进行数据清空
local timer Init=GetExpiredTimer()
local unit u1=LoadUnitHandle(h,GetHandleId(Init),0) //由于偷懒,即使在命中的情况下也没有立刻暂停可摧毁这个清空装置
local unit u2=LoadUnitHandle(h,GetHandleId(Init),1) // 干脆就等这个初始化计时器到期了不论怎么样都一起清空好了。。。
call UnitRemoveAbility(u2,'A005') //当然,每个技能中创建的对象必须在相应技能完成时摧毁。。。
call BJDebugMsg("攻击"+GetUnitName(u1)+"长时间未命中脱离战斗")
call DestroyTrigger(LoadTriggerHandle(h,GetHandleId(u1),10))
call DestroyTrigger(LoadTriggerHandle(h,GetHandleId(u2),10))
call DestroyTimer(Init)
call FlushChildHashtable(h,GetHandleId(u1))
call FlushChildHashtable(h,GetHandleId(u2))
call FlushChildHashtable(h,GetHandleId(Init))
set Init=null
set u1=null
set u2=null
endfunction
function RefreshInit takes unit u returns timer
call PauseTimer(LoadTimerHandle(h,GetHandleId(u),1))
call DestroyTimer(LoadTimerHandle(h,GetHandleId(u),1))
return CreateTimer()
endfunction
//============================================================================以下是动态注册受伤害等事件区域
function RegisterTargetDamaged takes nothing returns nothing
local unit u1=GetTriggerUnit()
local unit u2=GetAttacker()
local trigger tA
local trigger tB
local timer Init
local integer n=LoadInteger(h,GetHandleId(u1),0)
//=======================================以下区域是判断要运行技能区
local boolean bA //物品技能:黯灭(每次【攻击命中】使【目标降低五点护甲持续4.5秒】,连续的攻击会使【效果叠加】并【刷新持续时间】)
local boolean bB //物品技能:吸血鬼祭品(光环技能:使光环作用下的友军增加15点护甲,每次攻击吸血25%【远程近程都是25%的吸血效果】)
if GetUnitAbilityLevel(u2,'A003')>0 then
set bA=true //判断是否装备了黯灭
elseif GetUnitAbilityLevel(u2,'B003')>0 then
set bB=true //判断是否装备了吸血鬼祭品
elseif bA==true or bB==true then
//=======================================以下区域是动态注册区【计数n是防止反复注册机制】
set Init=RefreshInit(u1)
call SaveTimerHandle(h,GetHandleId(u1),1,Init)
call SaveUnitHandle(h,GetHandleId(Init),0,u1)
call SaveUnitHandle(h,GetHandleId(Init),1,u2)
call TimerStart(Init,10.0,false,function InitAll)
if n<1 then
call BJDebugMsg(GetUnitName(u1)+"进入战斗")
set n=n+1
call SaveInteger(h,GetHandleId(u1),0,n)
set tA=CreateTrigger()
call SaveTriggerHandle(h,GetHandleId(u1),10,tA)
call TriggerRegisterUnitEvent(tA,u1,EVENT_UNIT_DEATH)
call TriggerRegisterUnitEvent(tA,u1,EVENT_UNIT_DAMAGED) //注册被攻击单位死亡&受伤害事件
set tB=CreateTrigger()
call SaveTriggerHandle(h,GetHandleId(u2),10,tB)
call TriggerRegisterUnitEvent(tB,u2,EVENT_UNIT_DEATH) //注册攻击者死亡事件
endif
//=======================================以下区域是开始运行已判断的技能区
if bA==true then
call SaveBoolean(h,GetHandleId(u1),11,bA) //装备了黯灭就绑定bA到【被攻击单位】身上
elseif bB==true then
if GetUnitAbilityLevel(u2,'A003')<1 then //如果攻击者没装备黯灭(就是说攻击者没有带指定buff的法球技能)
call UnitAddAbility(u2,'A005') //就给攻击者添加带指定buff的空法球技能
endif
call SaveBoolean(h,GetHandleId(u1),12,bB) //装备了祭品就绑定bB到【被攻击单位】身上
call TriggerAddAction(tB,function AttackerDeath)
endif
call TriggerAddAction(tA,function Skills) //执行被攻击单位受伤害后的函数【Skills】
endif
set u1=null
set u2=null
set tA=null
set tB=null
set Init=null
endfunction
//===========================================================================
function InitTrig_System takes nothing returns nothing
local trigger t= CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_ATTACKED) //初始注册被攻击事件
call TriggerAddAction(t,function RegisterTargetDamaged) //动态注册受伤害事件
set t=null
endfunction
自认为这是效率最高,并且100%捕捉攻击命中的方法
但还是有大神说我这个方法很渣。。。所以目前“我不断的寻找,完美的法案你在哪里。。。”。。。额昨天发的图,减甲恢复时候读取hashtable的绑定的减甲次数读取错了地址(应该是 local integer bn=LoadInteger(h,GetHandleId(u),2))。。。这个上面的代码没错
这个附件已经在刚才更新了
抱歉,昨天是我太不严谨了。。。
|
-
-
-
多人无bug,复原完美,运行流畅
-
-
好大的坑.w3x
2.49 MB, 下载次数: 55
|