找回密码
 点一下
查看: 2219|回复: 0

模拟ChainLightning的函数(学习用)

[复制链接]
发表于 2007-12-31 06:44:55 | 显示全部楼层 |阅读模式
如下。
基本思路是给Timer绑定一个单位组,并且在每次伤害的时候更新。
---------------------------------
[jass]function AddLightningBetweenUnitTimed_LoopAction takes nothing returns nothing
    local integer tmIndex = GetTimerIndex(GetExpiredTimer())
    local unit u1 = SYS_TimerData_U00[tmIndex]
    local unit u2 = SYS_TimerData_U01[tmIndex]
    local location p1
    local location p2
    local real timeLeft = SYS_TimerData_R00[tmIndex]
    local real inv = SYS_TimerData_R01[tmIndex]
    local real oX1 = SYS_TimerData_R02[tmIndex]
    local real oY1 = SYS_TimerData_R03[tmIndex]
    local real oZ1 = SYS_TimerData_R04[tmIndex]
    local real oX2 = SYS_TimerData_R05[tmIndex]
    local real oY2 = SYS_TimerData_R06[tmIndex]
    local real oZ2 = SYS_TimerData_R07[tmIndex]
    local lightning l = SYS_TimerData_Lighting[tmIndex]
    local real LightingAddTime = SYS_TimerData_LightingAddTime[tmIndex]
    set timeLeft = timeLeft - inv
    set SYS_TimerData_R00[tmIndex] = timeLeft
    if(timeLeft<=0.00)then
       call DestroyLightning(l)
       call ReleaseTimer(GetExpiredTimer())
    else
       if(GetUnitState(u1,UNIT_STATE_LIFE)>0.00)then
          set p1 = GetUnitLoc(u1)
          set p2 = GetUnitLoc(u2)
          set oX1 = GetLocationX(p1)
          set oY1 = GetLocationY(p1)
          set oZ1 = GetLocationZ(p1)
          call RemoveLocation(p1)
          set SYS_TimerData_R02[tmIndex] = oX1
          set SYS_TimerData_R03[tmIndex] = oY1
          set SYS_TimerData_R04[tmIndex] = oZ1
       endif
       if(GetUnitState(u2,UNIT_STATE_LIFE)>0.00)then
          set p2 = GetUnitLoc(u2)
          set oX2 = GetLocationX(p2)
          set oY2 = GetLocationY(p2)
          set oZ2 = GetLocationZ(p2)
          call RemoveLocation(p2)
          set SYS_TimerData_R05[tmIndex] = oX2
          set SYS_TimerData_R06[tmIndex] = oY2
          set SYS_TimerData_R07[tmIndex] = oZ2
       endif
       call MoveLightningEx(l,false,oX1,oY1,oZ1,oX2,oY2,oZ2)
    endif
    set u1 = null
    set u2 = null
    set p1 = null
    set p2 = null
    set l = null
endfunction

function AddLightningBetweenUnitTimed takes string codeName,unit u1,unit u2,real inv returns nothing
    local location p1 = GetUnitLoc(u1)
    local location p2 = GetUnitLoc(u2)
    local real oX1 = GetLocationX(p1)
    local real oY1 = GetLocationY(p1)
    local real oZ1 = GetLocationZ(p1)
    local real oX2 = GetLocationX(p2)
    local real oY2 = GetLocationY(p2)
    local real oZ2 = GetLocationZ(p2)
    local integer tmIndex = GetTimerIndex(GetTimer())
    local real LoopInv = 0.20
    local lightning l = AddLightningEx(codeName,false,oX1,oY1,oZ1,oX2,oY2,oZ2)
    call SetLightningColor(l,1.00,1.00,1.00,0.60)
    call RemoveLocation(p1)
    call RemoveLocation(p2)
    set SYS_TimerData_U00[tmIndex] = u1
    set SYS_TimerData_U01[tmIndex] = u2
    set SYS_TimerData_R00[tmIndex] = inv
    set SYS_TimerData_R01[tmIndex] = LoopInv
    set SYS_TimerData_R02[tmIndex] = oX1
    set SYS_TimerData_R03[tmIndex] = oY1
    set SYS_TimerData_R04[tmIndex] = oZ1
    set SYS_TimerData_R05[tmIndex] = oX2
    set SYS_TimerData_R06[tmIndex] = oY2
    set SYS_TimerData_R07[tmIndex] = oZ2
    set SYS_TimerData_Lighting[tmIndex] = l
    set SYS_TimerData_LightingAddTime[tmIndex] = GetSystemTime()
    call TimerStart(SYS_Timer[tmIndex],LoopInv,true,function AddLightningBetweenUnitTimed_LoopAction)
    set p1 = null
    set p2 = null
    set l = null
endfunction
//-----------------------
function Condition_ChainLight_Target takes nothing returns boolean
    if(GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE)<=0.00)then
        return false
    elseif(IsUnitType(GetFilterUnit(),UNIT_TYPE_MAGIC_IMMUNE))then
        return false
    elseif(IsGuard(GetFilterUnit()))then
        return false
    elseif(IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE))then
        return false
    elseif(IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL))then
        return false
    elseif(not(IsUnitEnemy(SYS_TempUnit[1433],GetOwningPlayer(GetFilterUnit()))))then
        return false
    elseif(IsUnitInGroup(GetFilterUnit(),SYS_TempGroup))then
        return false
    endif
    return true
endfunction

function Action_ChainLight_Target takes nothing returns nothing
    if(not(IsUnitInGroup(GetEnumUnit(),SYS_TempGroup)))then
       set SYS_TempInt[1433] = SYS_TempInt[1433] + 1
       set SYS_TempUnit[1433+SYS_TempInt[1433]] = GetEnumUnit()
    endif
endfunction

function ChainLight_LoopAction takes nothing returns nothing
    local item itm
    local integer tmIndex = GetTimerIndex(GetExpiredTimer())
    local unit su = SYS_TimerData_U00[tmIndex]
    local unit tu = SYS_TimerData_U01[tmIndex]
    local unit LastUnit = SYS_TimerData_U02[tmIndex]
    local integer DMin = SYS_TimerData_I00[tmIndex]
    local integer DMax = SYS_TimerData_I01[tmIndex]
    local integer CR_Cfg = SYS_TimerData_I02[tmIndex]
    local integer ManaCost = SYS_TimerData_I03[tmIndex]
    local integer MaxJumpTime = SYS_TimerData_I04[tmIndex]
    local integer JumpTime = SYS_TimerData_I05[tmIndex]
    local real value = SYS_TimerData_R00[tmIndex]
    local real inv = SYS_TimerData_R01[tmIndex]
    local real x = SYS_TimerData_R02[tmIndex]
    local real y = SYS_TimerData_R03[tmIndex]
    local real DecPercent = SYS_TimerData_R04[tmIndex]
    local real CI = SYS_TimerData_R05[tmIndex]
    local real CT_Cfg = SYS_TimerData_R06[tmIndex]
    local boolean CR_Add = SYS_TimerData_B00[tmIndex]
    local boolean CT_Add = SYS_TimerData_B01[tmIndex]
    local boolean DefendAble = SYS_TimerData_B02[tmIndex]
    local boolean ImageFirst = SYS_TimerData_B03[tmIndex]
    local group gp = SYS_TimerData_UnitGroup[tmIndex]
    local group gpTemp = CreateGroup()
    local boolexpr cond = Condition(function Condition_ChainLight_Target)
    local real tx
    local real ty
    local real r = 200.00
    local real rMax = 600.00
    local integer i = 1
    local real DecPercent_EX = 1.00
    loop
       exitwhen(i>JumpTime)
       set DecPercent_EX = DecPercent_EX*(1.00-DecPercent)
       set i = i + 1
    endloop
    set value = value*DecPercent_EX
    if(tu==null)then
       set SYS_TempGroup = gp
       set SYS_TempUnit[1433] = su
       loop
          exitwhen(tu!=null or r>rMax)
          call GroupEnumUnitsInRange(gpTemp,x,y,r,cond)
          set SYS_TempInt[1433] = 0
          call ForGroup(gpTemp,function Action_ChainLight_Target)
          if(SYS_TempInt[1433]>0)then
             set tu = SYS_TempUnit[1433+GetRandomInt(1,SYS_TempInt[1433])]
             call GroupAddUnit(gp,tu)
             set i = SYS_TempInt[1433]
             loop
                exitwhen(i<=0)
                set SYS_TempUnit[1433+i] = null
                set i = i - 1
             endloop
          endif
          call GroupClear(gpTemp)
          set r = r + 100.00
          set inv = inv + 0.02
       endloop
       set SYS_TempUnit[1433] = null
       set SYS_TempGroup = null
       set SYS_TempInt[1433] = 0
    endif
    if(tu!=null)then
       set tx = GetUnitX(tu)
       set ty = GetUnitY(tu)
       if(JumpTime>0 or ImageFirst)then
          call AddLightningBetweenUnitTimed("CLSB",LastUnit,tu,0.95)
          call DestroyEffect(AddSpecialEffectTarget("Abilities\\Weapons\\Bolt\\BoltImpact.mdl",tu,"origin"))
       endif
       call ResetDamageInfo()
       set value = SpellValueConfig(value,CI,CR_Cfg,CR_Add,CT_Cfg,CT_Add,su,tu,DefendAble,ManaCost)
       call DamageUnit_Spell(su,tu,DMin,DMax,value)
       set SYS_TimerData_U01[tmIndex] = null
       set SYS_TimerData_U02[tmIndex] = tu
       set SYS_TimerData_R02[tmIndex] = tx
       set SYS_TimerData_R03[tmIndex] = ty
    endif
    if(JumpTime>=MaxJumpTime or tu==null)then
       call DestroyGroup(gp)
       call ReleaseTimer(GetExpiredTimer())
    else
       set JumpTime = JumpTime + 1
       set SYS_TimerData_I05[tmIndex] = JumpTime
       call TimerStart(GetExpiredTimer(),inv,false,function ChainLight_LoopAction)
    endif
    call DestroyBoolExpr(cond)
    call DestroyGroup(gpTemp)
    set su = null
    set tu = null
    set LastUnit = null
    set gp = null
    set gpTemp = null
endfunction

function ChainLight_Start takes boolean ImageFirst,unit su,unit tu,real x,real y,real inv,integer MaxJumpUnit,real DecPercent,integer DMin,integer DMax,real Value,real CI,integer CR_Cfg,boolean CR_Add,real CT_Cfg,boolean CT_Add,boolean DefendAble,integer ManaCost returns nothing
    local timer tm = GetTimer()
    local integer tmIndex = GetTimerIndex(tm)
    local group gp = CreateGroup()
    local integer JumpTime = 0
    call GroupAddUnit(gp,tu)
    set SYS_TimerData_U00[tmIndex] = su
    set SYS_TimerData_U01[tmIndex] = tu
    set SYS_TimerData_U02[tmIndex] = su
    set SYS_TimerData_I00[tmIndex] = DMin
    set SYS_TimerData_I01[tmIndex] = DMax
    set SYS_TimerData_I02[tmIndex] = CR_Cfg
    set SYS_TimerData_I03[tmIndex] = ManaCost
    set SYS_TimerData_I04[tmIndex] = MaxJumpUnit
    set SYS_TimerData_I05[tmIndex] = JumpTime
    set SYS_TimerData_R00[tmIndex] = Value
    set SYS_TimerData_R01[tmIndex] = inv
    set SYS_TimerData_R02[tmIndex] = x
    set SYS_TimerData_R03[tmIndex] = y
    set SYS_TimerData_R04[tmIndex] = RConfig(DecPercent,0.00,1.00)
    set SYS_TimerData_R05[tmIndex] = CI
    set SYS_TimerData_R06[tmIndex] = CT_Cfg
    set SYS_TimerData_B00[tmIndex] = CR_Add
    set SYS_TimerData_B01[tmIndex] = CT_Add
    set SYS_TimerData_B02[tmIndex] = DefendAble
    set SYS_TimerData_B03[tmIndex] = ImageFirst
    set SYS_TimerData_UnitGroup[tmIndex] = gp
    call TimerStart(tm,0.1,false,function ChainLight_LoopAction)
    set tm = null
    set gp = null
endfunction[/jass]
您需要登录后才可以回帖 登录 | 点一下

本版积分规则

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

GMT+8, 2024-11-24 18:16 , Processed in 0.186636 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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