天工维度魔兽争霸开发者社区-全国最大的TJ集中营-原提百万联盟

标题: 【乐色】绿字属性 [打印本页]

作者: Rubbish    时间: 2022-2-7 20:49
标题: 【乐色】绿字属性
本帖最后由 Rubbish 于 2022-2-7 22:11 编辑

  1. llibrary UnitState initializer Main

  2.     //物编生成
  3.     <?
  4.         local cost = {
  5.             { 'AItg' , 'Stak' , '额外攻击' } ,
  6.             { 'AIsx' , 'Stas' , '额外攻速' } ,
  7.             { 'AId1' , 'Stdf' , '额外护甲' } ,
  8.             { 'AIl1' , 'Stlf' , '额外生命' } ,
  9.             { 'AImv' , 'Stmn' , '额外魔法' } ,
  10.             { 'Aamk' , 'Stag' , '额外敏捷' } ,
  11.             { 'Aamk' , 'Stst' , '额外力量' } ,
  12.             { 'Aamk' , 'Stin' , '额外智力' } ,
  13.             { 'ANre' , 'Strm' , '魔法恢复' } ,
  14.             { 'ACnr' , 'Strl' , '生命恢复' } ,
  15.         }

  16.         for _ , v in ipairs( cost ) do
  17.         local name = v[2]
  18.         local suff = v[3]
  19.         local old  = v[1]
  20.         local obj              = slk.ability[old]:new( name )
  21.             obj.name         = string.format( '[%s] 属性' , name )
  22.             obj.EditorSuffix = suff
  23.             obj.Buttonpos    = { 0 , 0 }
  24.             obj.UnButtonpos  = { 0 , 0 }
  25.             obj.hero         = 0
  26.             obj.item         = 0
  27.             obj.race         = 'orther'
  28.             obj.levels       = 2
  29.             obj.dataA        = { 0  , 0  }
  30.             if slk.ability[old].art ~= '' then
  31.                     obj.art          = ''
  32.             end
  33.             if old == 'ACnr' or old == 'ANre' then
  34.                     obj.dataB        = { 0  , 0 }
  35.                     obj.targs        = { "vulnerable,invulnerable,self"  , "vulnerable,invulnerable,self"  }
  36.                     obj.Area         = { 0  , 0 }
  37.             end
  38.             if old == 'Aamk' then
  39.                     obj.tip          = { '' , '' }
  40.                     obj.ubertip      = { '' , '' }
  41.                     obj.dataB        = { 0  , 0  }
  42.                     obj.dataC        = { 0  , 0  }
  43.                     obj.dataD        = { 1  , 1  }
  44.             end
  45.         end
  46.     ?>

  47.     globals
  48.         private integer   array AbilityId
  49.         private integer   array AbilityData
  50.         private hashtable       Ht          = InitHashtable( )
  51.         private trigger         Trigger     = CreateTrigger( )
  52.     endglobals

  53.     function GetHandleType takes handle h returns string
  54.         local  string func   = ""
  55.         local  string result = ""
  56.         set    func          = func + "(function ( handle )"                     + "\n"
  57.         set    func          = func + "local dbg      = require 'jass.debug'"    + "\n"
  58.         set    func          = func + "if handle == 0 or handle == nil then"     + "\n"
  59.         set    func          = func + "return ''"                                + "\n"
  60.         set    func          = func + "end"                                      + "\n"
  61.         set    func          = func + "local info = dbg.handledef(handle)"       + "\n"
  62.         set    func          = func + "if info and info.type then"               + "\n"
  63.         set    func          = func + "return info.type"                         + "\n"
  64.         set    func          = func + "end"                                      + "\n"
  65.         set    func          = func + "return ''"                                + "\n"
  66.         set    func          = func + "end)( " + I2S( GetHandleId( h ) ) + ")"   + "\n"
  67.         set    result        = EXExecuteScript( func )
  68.         return result
  69.     endfunction
  70.    
  71.     private function FlushUnitData takes unit whichUnit returns nothing
  72.         call FlushChildHashtable( Ht , GetHandleId( whichUnit ) )
  73.     endfunction

  74.     hook RemoveUnit FlushUnitData

  75.     private function UnitInitAbility takes unit whichUnit , integer whichSerial returns nothing
  76.         local ability thisAbility = null
  77.         if AbilityId[whichSerial] != 0 then
  78.             call UnitAddAbility( whichUnit , AbilityId[whichSerial] )
  79.             call UnitMakeAbilityPermanent( whichUnit , true , AbilityId[whichSerial] )
  80.             set  thisAbility = EXGetUnitAbility( whichUnit , AbilityId[whichSerial] )
  81.             call SetUnitAbilityLevel( whichUnit , AbilityId[whichSerial] , 2 )
  82.             call EXSetAbilityDataReal( thisAbility , 1 , AbilityData[whichSerial] , 0 )
  83.             call SetUnitAbilityLevel( whichUnit , AbilityId[whichSerial] , 1 )
  84.         endif
  85.         set thisAbility = null
  86.     endfunction

  87.     private function SetUnitAbility takes unit whichUnit , integer whichSerial , real value returns nothing
  88.         local ability thisAbility = null
  89.         if AbilityId[whichSerial] != 0 then
  90.             call UnitAddAbility( whichUnit , AbilityId[whichSerial] )
  91.             call UnitMakeAbilityPermanent( whichUnit , true , AbilityId[whichSerial] )
  92.             set  thisAbility = EXGetUnitAbility( whichUnit , AbilityId[whichSerial] )
  93.             call SetUnitAbilityLevel( whichUnit , AbilityId[whichSerial] , 2 )
  94.             call EXSetAbilityDataReal( thisAbility , 1 , AbilityData[whichSerial] , value )
  95.             call SetUnitAbilityLevel( whichUnit , AbilityId[whichSerial] , 1 )
  96.         endif
  97.         set thisAbility = null
  98.     endfunction

  99.     private function TriggerActions takes nothing returns boolean
  100.         local unit target = GetTriggerUnit( )
  101.         call BJDebugMsg( "死亡单位 ->" + GetUnitName( target ) )
  102.         if not IsUnitType( target , UNIT_TYPE_HERO ) then
  103.             call FlushUnitData( target )
  104.         endif
  105.         set target = null
  106.         return false
  107.     endfunction

  108.     private function Main takes nothing returns nothing
  109.         local integer index = 0
  110.         loop
  111.             exitwhen index > 15
  112.             call TriggerRegisterPlayerUnitEvent( Trigger , Player( index ) , EVENT_PLAYER_UNIT_DEATH , null )
  113.             call TriggerAddCondition( Trigger , Filter( function TriggerActions ) )
  114.             set index = index + 1
  115.         endloop
  116.         //生命恢复
  117.         set AbilityId[0x53] = 'Strl'
  118.         set AbilityData[0x53] = 0x6c
  119.         //魔法恢复
  120.         set AbilityId[0x54] = 'Strm'
  121.         set AbilityData[0x54] = 0x6c
  122.         //额外生命值
  123.         set AbilityId[0x71] = 'Stlf'
  124.         set AbilityData[0x71] = 0x6c
  125.         //额外魔法值
  126.         set AbilityId[0x73] = 'Stlm'
  127.         set AbilityData[0x73] = 0x6c
  128.         //额外攻击
  129.         set AbilityId[0x74] = 'Stak'
  130.         set AbilityData[0x74] = 0x6c
  131.         //额外护甲值
  132.         set AbilityId[0x75] = 'Stdf'
  133.         set AbilityData[0x75] = 0x6c
  134.         //额外攻击速度
  135.         set AbilityId[0x76] = 'Stas'
  136.         set AbilityData[0x76] = 0x6c
  137.         //额外力量
  138.         set AbilityId[0x81] = 'Stst'
  139.         set AbilityData[0x81] = 0x6e
  140.         //额外敏捷
  141.         set AbilityId[0x82] = 'Stst'
  142.         set AbilityData[0x82] = 0x6c
  143.         //额外力量
  144.         set AbilityId[0x83] = 'Stin'
  145.         set AbilityData[0x83] = 0x6d
  146.     endfunction

  147.     function EXGetUnitState takes unit whichUnit , unitstate whichUnitState returns real
  148.         local real    result = 0
  149.         local integer state  = GetHandleId( whichUnitState )
  150.         local real    attch  = 0
  151.         if AbilityId[state] != 0 then
  152.             if GetUnitAbilityLevel( whichUnit , AbilityId[state] ) > 0 then
  153.                 set result = LoadReal( Ht , GetHandleId( whichUnit ) , state )
  154.             endif
  155.         else
  156.             set result = GetUnitState( whichUnit , whichUnitState )
  157.             if state == 0x20 then
  158.                 set attch = LoadReal( Ht , GetHandleId( whichUnit ) , 0x75 )
  159.             elseif state == 0x51 then
  160.                 set attch = LoadReal( Ht , GetHandleId( whichUnit ) , 0x76 )
  161.             endif
  162.             set result = result - attch
  163.         endif
  164.         return result
  165.     endfunction

  166.     private struct TimerSetActions
  167.         private unit        target
  168.         private integer     state
  169.         private real        value
  170.         private timer       timer

  171.         private static constant hashtable ht = InitHashtable( )

  172.         method destroy takes nothing returns nothing
  173.             call DestroyTimer( .timer )
  174.             call RemoveSavedInteger( thistype.ht , GetHandleId( .target ) , .state )
  175.             call FlushChildHashtable( thistype.ht , GetHandleId( .timer ) )
  176.             set  .target = null
  177.             set  .state  = 0
  178.             set  .timer  = null
  179.             set  .value  = 0
  180.             call .deallocate( )
  181.         endmethod

  182.         static method TimerActions takes nothing returns nothing
  183.             local timer    Extime = GetExpiredTimer( )
  184.             local thistype this   = LoadInteger( thistype.ht , GetHandleId( Extime ) , <?=StringHash( 'UserData' )?> )
  185.             if UnitAlive( .target ) then
  186.                 call SetUnitAbility( .target , .state , .value )
  187.                 call .destroy( )
  188.             else
  189.                 if GetUnitName( .target ) == "" or GetHandleType( .target ) != "+w3u" then
  190.                     call .destroy( )
  191.                 endif
  192.             endif
  193.         endmethod

  194.         static method create takes unit whichUnit , integer state , real value returns thistype
  195.             local thistype this = 0
  196.             if Have( integer , thistype.ht , GetHandleId( whichUnit ) , state ) then
  197.                 set this = LoadInteger( thistype.ht , GetHandleId( whichUnit ) , state )
  198.             else
  199.                 set this             = thistype.allocate( )
  200.                 set .timer           = CreateTimer( )
  201.                 set .target          = whichUnit
  202.                 set .state           = state
  203.                 call SaveInteger( thistype.ht , GetHandleId( .timer )    , <?=StringHash( 'UserData' )?> , this )
  204.                 call SaveInteger( thistype.ht , GetHandleId( whichUnit ) , state , this )
  205.                 call TimerStart( .timer , 0.03 , true , function thistype.TimerActions )
  206.             endif
  207.             set .value = value
  208.             return this
  209.         endmethod

  210.     endstruct

  211.     function EXSetUnitState takes unit whichUnit , unitstate whichUnitState , real value returns nothing
  212.         local real        old   = 0
  213.         local integer     state = GetHandleId( whichUnitState )
  214.         local real        prof  = 0
  215.         local real        now   = 0
  216.         local real        max   = 0
  217.         if AbilityId[state] != 0 then
  218.             if GetUnitAbilityLevel( whichUnit , AbilityId[state] ) <= 0 then
  219.                 call UnitInitAbility( whichUnit , state )
  220.             endif
  221.             if not UnitAlive( whichUnit ) and ( state == 0x53 or state == 0x54 ) then
  222.                 call TimerSetActions.create( whichUnit , state , value )
  223.             else
  224.                 call SetUnitAbility( whichUnit , state , value )
  225.             endif
  226.             call SaveReal( Ht , GetHandleId( whichUnit ) , state , value )
  227.         else
  228.             if state == 0x01 or state == 0x02 then
  229.                 set now  = GetUnitState( whichUnit , ConvertUnitState( state - 1 ) )
  230.                 set max  = GetUnitState( whichUnit , ConvertUnitState( state ) )
  231.                 if max == 0 then
  232.                     set max = 1
  233.                 endif
  234.                 if now == 0 then
  235.                     set now = 1
  236.                 endif
  237.                 set prof = now / max
  238.             elseif state == 0x20 then
  239.                 call SetUnitAbility( whichUnit , 0x75 , 0 )
  240.             elseif state == 0x51 then
  241.                 call SetUnitAbility( whichUnit , 0x76 , 0 )
  242.             endif
  243.             call SetUnitState( whichUnit , whichUnitState , value )
  244.             if state == 0x01 or state == 0x02 then
  245.                 set max  = GetUnitState( whichUnit , ConvertUnitState( state ) )
  246.                 set now  = max * prof
  247.                 call SetUnitState( whichUnit , ConvertUnitState( state - 1 ) , now )
  248.             elseif state == 0x20 then
  249.                 call SetUnitAbility( whichUnit , 0x75 , LoadReal( Ht , GetHandleId( whichUnit ) , 0x75 ) )
  250.             elseif state == 0x51 then
  251.                 call SetUnitAbility( whichUnit , 0x76 , LoadReal( Ht , GetHandleId( whichUnit ) , 0x76 ) )
  252.             endif
  253.         endif
  254.     endfunction

  255.     function EXSetHeroStr takes unit whichUnit , integer newStr , boolean permanent returns nothing
  256.         if permanent then
  257.             call SetUnitAbility( whichUnit , 0x81 , I2R( newStr ) )
  258.         else
  259.             call SetHeroStr( whichUnit , newStr , true )
  260.         endif
  261.     endfunction

  262.     function EXSetHeroAgi takes unit whichUnit , integer newStr , boolean permanent returns nothing
  263.         if permanent then
  264.             call SetUnitAbility( whichUnit , 0x82 , I2R( newStr ) )
  265.         else
  266.             call SetHeroAgi( whichUnit , newStr , true )
  267.         endif
  268.     endfunction

  269.     function EXSetHeroInt takes unit whichUnit , integer newStr , boolean permanent returns nothing
  270.         if permanent then
  271.             call SetUnitAbility( whichUnit , 0x83 , I2R( newStr ) )
  272.         else
  273.             call SetHeroInt( whichUnit , newStr , true )
  274.         endif
  275.     endfunction

  276.     #define GetUnitState EXGetUnitState
  277.     #define SetUnitState EXSetUnitState
  278.     #define SetHeroStr   EXSetHeroStr
  279.     #define SetHeroAgi   EXSetHeroAgi
  280.     #define SetHeroInt   EXSetHeroInt
  281.    
  282. 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为白字


作者: 容夏至    时间: 2022-2-7 20:53
大佬,这是用在哪里的
作者: 安圣基    时间: 2022-2-8 15:36
能直接弄成演示图吗?




欢迎光临 天工维度魔兽争霸开发者社区-全国最大的TJ集中营-原提百万联盟 (http://bbs.mvprpg.com/) Powered by Discuz! X3.4