|
总算换了种模板类型来做~~(*^__^*) 嘻嘻……
一个添加技能组合型Buff的万能模板……
(PS:还兼职了被动技能O(∩_∩)O哈哈~)
适用类型:基本所有Buff/Debuff/被动技能都能适用~~
代码:
[codes=jass]globals
gamecache BuffGroup_GC = null
//游戏缓存
integer BuffGroup_Data_Int = 0
real BuffGroup_Data_Real = 0.0
boolean BuffGroup_Data_Bool = false
string BuffGroup_Data_Str = null
integer BuffGroup_Ab_num = 0
group BuffGroup_TheGroup = null
timer BuffGroup_TheTimer = null
//对code-action的辅助参数。
//---------------------------------------
integer array BuffGroup_ab_id
integer array BuffGroup_ab_lv
boolean array BuffGroup_IsMagicBook
boolean array BuffGroup_DontNeedAddAndRemove
integer BuffGroup_ab_num = 0
//对BuffGroupAbility的技能参数
//BuffGroup_ab_num=这个Buff包含技能的个数
//BuffGroup_ab_id[N]=这个Buff的第N-1个技能的ID(在物体编辑器里按Ctrl+D可见)
//BuffGroup_ab_lv[N]=这个Buff的第N-1个技能的等级
//BuffGroup_IsMagicBook[N]=这个Buff的第N-1个技能是否为包含被动技能的魔法书类型的技能
//(这种魔法书一般需要禁止玩家使用,所以要设置)
//BuffGroup_DontNeedAddAndRemove[N]=这个Buff的第N-1个技能是否为被魔法书隐藏的技能
//(如果是则模板不使用UnitAdd/RemoveAbility)
//---------------------------------------
integer BuffGroup__ab_id = 0
integer BuffGroup__ab_lv = 0
//内部
endglobals
//Copy这个
function BuffGroupInit takes nothing returns nothing
call FlushGameCache(InitGameCache( "BuffGroup.w3v" ))
set BuffGroup_GC = InitGameCache( "BuffGroup.w3v" )
endfunction
//你把BuffGroup_GC设置成你的GameCache(推荐)或者这样都可以(但你要保证BuffGroup_GC不为空)
function H2I takes handle h returns integer
return h
return 0
endfunction
function I2G takes integer i returns group
return i
return null
endfunction
function C2I takes code c returns integer
return c
return 0
endfunction
function I2C takes integer i returns code
return i
return null
endfunction
function BuffGroup_AddAbility takes nothing returns nothing
local unit u = GetEnumUnit()
call UnitAddAbility( u, BuffGroup__ab_id )
call SetUnitAbilityLevel( u, BuffGroup__ab_id, BuffGroup__ab_lv )
call UnitMakeAbilityPermanent( u, true, BuffGroup__ab_id )
set u = null
endfunction
function BuffGroup_RemoveAbility takes nothing returns nothing
local unit u = GetEnumUnit()
call UnitRemoveAbility( u, BuffGroup__ab_id )
set u = null
endfunction
function BuffGroup_End takes nothing returns nothing
local timer ti = GetExpiredTimer()
local string ti_s = I2S(H2I( ti ))
local group g = I2G( GetStoredInteger( BuffGroup_GC, ti_s, "group" ) )
local boolean destroy = GetStoredBoolean( BuffGroup_GC, ti_s, "destroy" )
local integer ab_num = GetStoredInteger( BuffGroup_GC, ti_s, "ab_num" )
local code action = I2C( GetStoredInteger( BuffGroup_GC, ti_s, "action" ) )
local integer i = 0
if action != null then
set BuffGroup_Data_Int = GetStoredInteger( BuffGroup_GC, ti_s, "help" )
set BuffGroup_Data_Real = GetStoredReal( BuffGroup_GC, ti_s, "help" )
set BuffGroup_Data_Bool = GetStoredBoolean( BuffGroup_GC, ti_s, "help" )
set BuffGroup_Data_Str = GetStoredString( BuffGroup_GC, ti_s, "help" )
set BuffGroup_Ab_num = ab_num
set BuffGroup_TheGroup = g
set BuffGroup_TheTimer = ti
call ForGroup( g, action )
call StoreInteger( BuffGroup_GC, ti_s, "group", H2I( BuffGroup_TheGroup ) )
call StoreInteger( BuffGroup_GC, ti_s, "ab_num", BuffGroup_Ab_num )
set BuffGroup_Data_Int = 0
set BuffGroup_Data_Real = 0.0
set BuffGroup_Data_Bool = false
set BuffGroup_Data_Str = null
set BuffGroup_Ab_num = 0
set BuffGroup_TheGroup = null
set BuffGroup_TheTimer = null
endif
loop
exitwhen i >= ab_num
set BuffGroup__ab_id = GetStoredInteger( BuffGroup_GC, ti_s, "ab_id" + I2S( i ) )
set BuffGroup__ab_lv = GetStoredInteger( BuffGroup_GC, ti_s, "ab_lv" + I2S( i ) )
if not GetStoredBoolean( BuffGroup_GC, ti_s, "need" + I2S( i ) ) then
call ForGroup( g, function BuffGroup_RemoveAbility )
endif
set i = i + 1
endloop
if destroy then
call PauseTimer( ti )
call DestroyTimer( ti )
call DestroyGroup( g )
call FlushStoredMission( BuffGroup_GC, ti_s )
endif
set action = null
set g = null
set ti_s = null
set ti = null
endfunction
function BuffGroupAbility takes timer TheTimer, group g, player p, real time, boolean destroy, code action_before_buffremove returns nothing
local timer ti = null
local string ti_s = null
local integer i = 0
if time > 0.0 then
if TheTimer == null then
set ti = CreateTimer()
else
set ti = TheTimer
endif
set ti_s = I2S(H2I( ti ))
call StoreInteger( BuffGroup_GC, ti_s, "help", BuffGroup_Data_Int )
call StoreReal( BuffGroup_GC, ti_s, "help", BuffGroup_Data_Real )
call StoreBoolean( BuffGroup_GC, ti_s, "help", BuffGroup_Data_Bool )
call StoreString( BuffGroup_GC, ti_s, "help", BuffGroup_Data_Str )
call StoreInteger( BuffGroup_GC, ti_s, "group", H2I( g ) )
call StoreInteger( BuffGroup_GC, ti_s, "ab_num", BuffGroup_ab_num )
call StoreBoolean( BuffGroup_GC, ti_s, "destroy", destroy )
call StoreInteger( BuffGroup_GC, ti_s, "action", C2I( action_before_buffremove ) )
endif
loop
exitwhen i >= BuffGroup_ab_num
if time > 0.0 then
call StoreInteger( BuffGroup_GC, ti_s, "ab_id" + I2S( i ), BuffGroup_ab_id[ i ] )
call StoreInteger( BuffGroup_GC, ti_s, "ab_lv" + I2S( i ), BuffGroup_ab_lv[ i ] )
call StoreBoolean( BuffGroup_GC, ti_s, "need" + I2S( i ), BuffGroup_DontNeedAddAndRemove[ i ] )
endif
if BuffGroup_IsMagicBook[ i ] then
call SetPlayerAbilityAvailable( p, BuffGroup_ab_id[ i ], false )
endif
if not BuffGroup_DontNeedAddAndRemove[ i ] then
set BuffGroup__ab_id = BuffGroup_ab_id[ i ]
set BuffGroup__ab_lv = BuffGroup_ab_lv[ i ]
call ForGroup( g, function BuffGroup_AddAbility )
set BuffGroup__ab_id = 0
set BuffGroup__ab_lv = 0
endif
set i = i + 1
endloop
call TimerStart( ti, time, false, function BuffGroup_End )
set ti_s = null
set ti = null
endfunction[/codes]
参数说明:
timer TheTimer 用来计时的Timer(如果为null则函数自动创建一个)
group g 添加Buff的单位组
player p 需要禁用的特殊的(一般来说是隐藏被动技能的)魔法书对这个玩家会禁用
real time Buff的限制时间(如果<=0.0,那么会被认为是一个被动技能,不会对单位组删除技能)
boolean destroy Buff的限制时间到后,是否删除Group和Timer并清除Timer的缓存
code action_before_buffremove Buff的限制时间到后,对Group执行的函数。
Globals中变量的参数说明:
integer array BuffGroup_ab_id
integer array BuffGroup_ab_lv
boolean array BuffGroup_IsMagicBook
boolean array BuffGroup_DontNeedAddAndRemove
integer BuffGroup_ab_num = 0
对BuffGroupAbility的技能参数
BuffGroup_ab_num=这个Buff包含技能的个数
BuffGroup_ab_id[N]=这个Buff的第N-1个技能的ID(在物体编辑器里按Ctrl+D可见)
BuffGroup_ab_lv[N]=这个Buff的第N-1个技能的等级
BuffGroup_IsMagicBook[N]=这个Buff的第N-1个技能是否为包含被动技能的魔法书类型的技能
(这种魔法书一般需要禁止玩家使用,所以要设置禁用)
BuffGroup_DontNeedAddAndRemove[N]=这个Buff的第N-1个技能是否为被魔法书隐藏的技能
(如果是则模板不使用UnitAdd/RemoveAbility)
特殊说明(可以说是指导):
你现在可以先创建一个自己的TheTimer,然后用ReturnBug+GameCache为它存储自定义的值了,在code执行时,你可以从BuffGroup_TheTimer获得你的TheTimer,最后……这些存储的数据你就可以读取了!也就是说,你现在可以有无数个自定义值了!这是在code的参数方面的一大进步!!纪念一下!!
有些危险,但一个很好的东东:
在<GameCache>, <Timer Handle String>的目录(GameCache中)下,
你可以改动/引用这些string key中的值:
integer(group) "group" : 你可以在RemoveUnitAbility之前改变被Buff了的单位组(H2I)
boolean "destroy" : 你可以在RemoveUnitAbility之前改变是否删除Group和Timer并清除Timer的缓存
integer "ab_num" : 你可以在RemoveUnitAbility之前改变这个Buff包含技能的个数(只是认为而已,真正技能的个数不是这个)
integer(code) "action" : 你可以在RemoveUnitAbility之前改变code
integer "ab_id" + I2S(N) : 你可以在RemoveUnitAbility之前改变第N+1个技能的ID。
integer "ab_lv" + I2S(N) : 你可以在RemoveUnitAbility之前改变第N+1个技能的LV。
integer "need" + I2S(N) : 你可以在RemoveUnitAbility之前改变第N+1个技能是否为被魔法书隐藏的技能。
action_before_buffremove这个code的特殊参数说明:
GetEnumUnit()获得被Buff了的单位。
你可以在调用BuffGroupAbility之前设置这四个全局变量:
[codes=jass] integer BuffGroup_Data_Int = 0
real BuffGroup_Data_Real = 0.0
boolean BuffGroup_Data_Bool = false
string BuffGroup_Data_Str = null[/codes]
然后,当这个action执行时,这四个全局变量储存的值就是你赋给他们的值(如果没赋值则是默认的0/0.0/false/null)。
注意!当运行完BuffGroupAbility后,这四个全局变量就会被自动清空。
另外三个参数:
BuffGroup_Ab_num = 这个Buff包含技能的个数
BuffGroup_TheGroup = 这个被Buff了的单位组
BuffGroup_TheTimer = 用来计时的Timer
希望大家多多支持我~~有Bug一定要回帖/发短消息给我这个帐号~~ |
评分
-
查看全部评分
|