马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 Rubbish 于 2022-2-7 22:11 编辑
-
- llibrary UnitState initializer Main
-
- //物编生成
- <?
- local cost = {
- { 'AItg' , 'Stak' , '额外攻击' } ,
- { 'AIsx' , 'Stas' , '额外攻速' } ,
- { 'AId1' , 'Stdf' , '额外护甲' } ,
- { 'AIl1' , 'Stlf' , '额外生命' } ,
- { 'AImv' , 'Stmn' , '额外魔法' } ,
- { 'Aamk' , 'Stag' , '额外敏捷' } ,
- { 'Aamk' , 'Stst' , '额外力量' } ,
- { 'Aamk' , 'Stin' , '额外智力' } ,
- { 'ANre' , 'Strm' , '魔法恢复' } ,
- { 'ACnr' , 'Strl' , '生命恢复' } ,
- }
-
- for _ , v in ipairs( cost ) do
- local name = v[2]
- local suff = v[3]
- local old = v[1]
- local obj = slk.ability[old]:new( name )
- obj.name = string.format( '[%s] 属性' , name )
- obj.EditorSuffix = suff
- obj.Buttonpos = { 0 , 0 }
- obj.UnButtonpos = { 0 , 0 }
- obj.hero = 0
- obj.item = 0
- obj.race = 'orther'
- obj.levels = 2
- obj.dataA = { 0 , 0 }
- if slk.ability[old].art ~= '' then
- obj.art = ''
- end
- if old == 'ACnr' or old == 'ANre' then
- obj.dataB = { 0 , 0 }
- obj.targs = { "vulnerable,invulnerable,self" , "vulnerable,invulnerable,self" }
- obj.Area = { 0 , 0 }
- end
- if old == 'Aamk' then
- obj.tip = { '' , '' }
- obj.ubertip = { '' , '' }
- obj.dataB = { 0 , 0 }
- obj.dataC = { 0 , 0 }
- obj.dataD = { 1 , 1 }
- end
- end
- ?>
-
- globals
- private integer array AbilityId
- private integer array AbilityData
- private hashtable Ht = InitHashtable( )
- private trigger Trigger = CreateTrigger( )
- endglobals
-
- function GetHandleType takes handle h returns string
- local string func = ""
- local string result = ""
- set func = func + "(function ( handle )" + "\n"
- set func = func + "local dbg = require 'jass.debug'" + "\n"
- set func = func + "if handle == 0 or handle == nil then" + "\n"
- set func = func + "return ''" + "\n"
- set func = func + "end" + "\n"
- set func = func + "local info = dbg.handledef(handle)" + "\n"
- set func = func + "if info and info.type then" + "\n"
- set func = func + "return info.type" + "\n"
- set func = func + "end" + "\n"
- set func = func + "return ''" + "\n"
- set func = func + "end)( " + I2S( GetHandleId( h ) ) + ")" + "\n"
- set result = EXExecuteScript( func )
- return result
- endfunction
-
- private function FlushUnitData takes unit whichUnit returns nothing
- call FlushChildHashtable( Ht , GetHandleId( whichUnit ) )
- endfunction
-
- hook RemoveUnit FlushUnitData
-
- private function UnitInitAbility takes unit whichUnit , integer whichSerial returns nothing
- local ability thisAbility = null
- if AbilityId[whichSerial] != 0 then
- call UnitAddAbility( whichUnit , AbilityId[whichSerial] )
- call UnitMakeAbilityPermanent( whichUnit , true , AbilityId[whichSerial] )
- set thisAbility = EXGetUnitAbility( whichUnit , AbilityId[whichSerial] )
- call SetUnitAbilityLevel( whichUnit , AbilityId[whichSerial] , 2 )
- call EXSetAbilityDataReal( thisAbility , 1 , AbilityData[whichSerial] , 0 )
- call SetUnitAbilityLevel( whichUnit , AbilityId[whichSerial] , 1 )
- endif
- set thisAbility = null
- endfunction
-
- private function SetUnitAbility takes unit whichUnit , integer whichSerial , real value returns nothing
- local ability thisAbility = null
- if AbilityId[whichSerial] != 0 then
- call UnitAddAbility( whichUnit , AbilityId[whichSerial] )
- call UnitMakeAbilityPermanent( whichUnit , true , AbilityId[whichSerial] )
- set thisAbility = EXGetUnitAbility( whichUnit , AbilityId[whichSerial] )
- call SetUnitAbilityLevel( whichUnit , AbilityId[whichSerial] , 2 )
- call EXSetAbilityDataReal( thisAbility , 1 , AbilityData[whichSerial] , value )
- call SetUnitAbilityLevel( whichUnit , AbilityId[whichSerial] , 1 )
- endif
- set thisAbility = null
- endfunction
-
- private function TriggerActions takes nothing returns boolean
- local unit target = GetTriggerUnit( )
- call BJDebugMsg( "死亡单位 ->" + GetUnitName( target ) )
- if not IsUnitType( target , UNIT_TYPE_HERO ) then
- call FlushUnitData( target )
- endif
- set target = null
- return false
- endfunction
-
- private function Main takes nothing returns nothing
- local integer index = 0
- loop
- exitwhen index > 15
- call TriggerRegisterPlayerUnitEvent( Trigger , Player( index ) , EVENT_PLAYER_UNIT_DEATH , null )
- call TriggerAddCondition( Trigger , Filter( function TriggerActions ) )
- set index = index + 1
- endloop
- //生命恢复
- set AbilityId[0x53] = 'Strl'
- set AbilityData[0x53] = 0x6c
- //魔法恢复
- set AbilityId[0x54] = 'Strm'
- set AbilityData[0x54] = 0x6c
- //额外生命值
- set AbilityId[0x71] = 'Stlf'
- set AbilityData[0x71] = 0x6c
- //额外魔法值
- set AbilityId[0x73] = 'Stlm'
- set AbilityData[0x73] = 0x6c
- //额外攻击
- set AbilityId[0x74] = 'Stak'
- set AbilityData[0x74] = 0x6c
- //额外护甲值
- set AbilityId[0x75] = 'Stdf'
- set AbilityData[0x75] = 0x6c
- //额外攻击速度
- set AbilityId[0x76] = 'Stas'
- set AbilityData[0x76] = 0x6c
- //额外力量
- set AbilityId[0x81] = 'Stst'
- set AbilityData[0x81] = 0x6e
- //额外敏捷
- set AbilityId[0x82] = 'Stst'
- set AbilityData[0x82] = 0x6c
- //额外力量
- set AbilityId[0x83] = 'Stin'
- set AbilityData[0x83] = 0x6d
- endfunction
-
- function EXGetUnitState takes unit whichUnit , unitstate whichUnitState returns real
- local real result = 0
- local integer state = GetHandleId( whichUnitState )
- local real attch = 0
- if AbilityId[state] != 0 then
- if GetUnitAbilityLevel( whichUnit , AbilityId[state] ) > 0 then
- set result = LoadReal( Ht , GetHandleId( whichUnit ) , state )
- endif
- else
- set result = GetUnitState( whichUnit , whichUnitState )
- if state == 0x20 then
- set attch = LoadReal( Ht , GetHandleId( whichUnit ) , 0x75 )
- elseif state == 0x51 then
- set attch = LoadReal( Ht , GetHandleId( whichUnit ) , 0x76 )
- endif
- set result = result - attch
- endif
- return result
- endfunction
-
- private struct TimerSetActions
- private unit target
- private integer state
- private real value
- private timer timer
-
- private static constant hashtable ht = InitHashtable( )
-
- method destroy takes nothing returns nothing
- call DestroyTimer( .timer )
- call RemoveSavedInteger( thistype.ht , GetHandleId( .target ) , .state )
- call FlushChildHashtable( thistype.ht , GetHandleId( .timer ) )
- set .target = null
- set .state = 0
- set .timer = null
- set .value = 0
- call .deallocate( )
- endmethod
-
- static method TimerActions takes nothing returns nothing
- local timer Extime = GetExpiredTimer( )
- local thistype this = LoadInteger( thistype.ht , GetHandleId( Extime ) , <?=StringHash( 'UserData' )?> )
- if UnitAlive( .target ) then
- call SetUnitAbility( .target , .state , .value )
- call .destroy( )
- else
- if GetUnitName( .target ) == "" or GetHandleType( .target ) != "+w3u" then
- call .destroy( )
- endif
- endif
- endmethod
-
- static method create takes unit whichUnit , integer state , real value returns thistype
- local thistype this = 0
- if Have( integer , thistype.ht , GetHandleId( whichUnit ) , state ) then
- set this = LoadInteger( thistype.ht , GetHandleId( whichUnit ) , state )
- else
- set this = thistype.allocate( )
- set .timer = CreateTimer( )
- set .target = whichUnit
- set .state = state
- call SaveInteger( thistype.ht , GetHandleId( .timer ) , <?=StringHash( 'UserData' )?> , this )
- call SaveInteger( thistype.ht , GetHandleId( whichUnit ) , state , this )
- call TimerStart( .timer , 0.03 , true , function thistype.TimerActions )
- endif
- set .value = value
- return this
- endmethod
-
- endstruct
-
- function EXSetUnitState takes unit whichUnit , unitstate whichUnitState , real value returns nothing
- local real old = 0
- local integer state = GetHandleId( whichUnitState )
- local real prof = 0
- local real now = 0
- local real max = 0
- if AbilityId[state] != 0 then
- if GetUnitAbilityLevel( whichUnit , AbilityId[state] ) <= 0 then
- call UnitInitAbility( whichUnit , state )
- endif
- if not UnitAlive( whichUnit ) and ( state == 0x53 or state == 0x54 ) then
- call TimerSetActions.create( whichUnit , state , value )
- else
- call SetUnitAbility( whichUnit , state , value )
- endif
- call SaveReal( Ht , GetHandleId( whichUnit ) , state , value )
- else
- if state == 0x01 or state == 0x02 then
- set now = GetUnitState( whichUnit , ConvertUnitState( state - 1 ) )
- set max = GetUnitState( whichUnit , ConvertUnitState( state ) )
- if max == 0 then
- set max = 1
- endif
- if now == 0 then
- set now = 1
- endif
- set prof = now / max
- elseif state == 0x20 then
- call SetUnitAbility( whichUnit , 0x75 , 0 )
- elseif state == 0x51 then
- call SetUnitAbility( whichUnit , 0x76 , 0 )
- endif
- call SetUnitState( whichUnit , whichUnitState , value )
- if state == 0x01 or state == 0x02 then
- set max = GetUnitState( whichUnit , ConvertUnitState( state ) )
- set now = max * prof
- call SetUnitState( whichUnit , ConvertUnitState( state - 1 ) , now )
- elseif state == 0x20 then
- call SetUnitAbility( whichUnit , 0x75 , LoadReal( Ht , GetHandleId( whichUnit ) , 0x75 ) )
- elseif state == 0x51 then
- call SetUnitAbility( whichUnit , 0x76 , LoadReal( Ht , GetHandleId( whichUnit ) , 0x76 ) )
- endif
- endif
- endfunction
-
- function EXSetHeroStr takes unit whichUnit , integer newStr , boolean permanent returns nothing
- if permanent then
- call SetUnitAbility( whichUnit , 0x81 , I2R( newStr ) )
- else
- call SetHeroStr( whichUnit , newStr , true )
- endif
- endfunction
-
- function EXSetHeroAgi takes unit whichUnit , integer newStr , boolean permanent returns nothing
- if permanent then
- call SetUnitAbility( whichUnit , 0x82 , I2R( newStr ) )
- else
- call SetHeroAgi( whichUnit , newStr , true )
- endif
- endfunction
-
- function EXSetHeroInt takes unit whichUnit , integer newStr , boolean permanent returns nothing
- if permanent then
- call SetUnitAbility( whichUnit , 0x83 , I2R( newStr ) )
- else
- call SetHeroInt( whichUnit , newStr , true )
- endif
- endfunction
-
- #define GetUnitState EXGetUnitState
- #define SetUnitState EXSetUnitState
- #define SetHeroStr EXSetHeroStr
- #define SetHeroAgi EXSetHeroAgi
- #define SetHeroInt EXSetHeroInt
-
- endlibrary
复制代码
上方是代码
使用方式
call SetUnitState( whichUnit , ConvertUnitState(Serial) , value ) //设置单位的属性 这个函数会自动被更改为EXSetUnitState
call SetUnitState( whichUnit , ConvertUnitState(Serial) ) //获取单位的属性 这个函数会自动被更改为EXSetUnitState
//whichUnit 为单位
//Serial 为以下值:
// 0x53:生命回复
// 0x54:魔法回复
// 0x71:额外生命
// 0x73:额外魔法值
// 0x74:额外攻击
// 0x75:额外护甲
// 0x76:额外攻速
//value 为设置值
call SetHeroStr( whichUnit , value , bool ) //函数制动替换为 EXSetHeroStr
call SetHeroAgi( whichUnit , value , bool ) //函数制动替换为 EXSetHeroAgi
call SetHeroInt( whichUnit , value , bool ) //函数制动替换为 EXSetHeroInt
//whichUnit 为单位
//value 为设置值
//bool 为是否为绿字,true为绿字,false为白字
|