|
不久前老狼发了一篇关于SetUnitX/Y与SetUnitPosition之间效率的对比研究,简述之:SetUnitX/Y要比后者效率高20倍~
嗯,得知后我立即将原来用SetUnitPosition做的东西改成SetUnitX/Y,结果进去一看根本不动了,(原来作了个射箭的技能,箭由单位用timer控制位移),马上debug,首先是做SetUnitX/Y可靠性验证~打字、创造单位、缓存记录、用timer作SetUnitX/Y。。。很好,一切正常。然后回到我的技能,这回干脆些,直接让SetUnitX/Y回归到原点(0,0),测试一看,更纳闷了,箭还是不动。于是考虑可能是其他函数影响所致,于是开始逐行//屏蔽,所用变量尽可能替换为常数,直到~直到
[jass]function ArrowFlyingTime takes nothing returns nothing
local string key="AR"+I2S(h2i(GetExpiredTimer()))
local unit arrow=GetHandleUnitEx(key,"arrow")
call SetUnitX(arrow,GetUnitX(arrow)+30)
call SetUnitY(arrow,GetUnitY(arrow)+40)
//call SetUnitPosition(arrow,GetUnitX(arrow)+dis*Cos(angle),GetUnitY(arrow)+dis*Sin(angle))
endfunction[/jass]
实在不能减下去了,毛病依旧。在整个过程中随时将SetUnitPosition换回来,箭就能以正常轨迹运行。
于是我绝望的想到也许是物体属性的问题。。。(几乎不可能的),于是还原成默认模型。。。小精灵还是不动。。。随后我已经一度认为觉得魔兽灵异的阴影了。。准备放弃,忽然注意到了异象,原来小地图的阴影处被打出了条照亮的通路~于是马上
[jass]call debugmsg("X:"+R2S(GetUnitX(arrow))+" Y:"+R2S(GetUnitY(arrow)))[/jass]
果然得到单位的位置的确在变,但不会被显示出来。。。为什么原来的有显示呢?
居然是因为我将箭的基础移动速度设为0的缘故,在游戏中用SetUnitX就不能让它的图像移动了。。。(实际坐标还是动的)
完整的射箭过程:
[jass]function ArrowStunLast takes nothing returns nothing
local string key="AR"+I2S(h2i(GetExpiredTimer()))
local unit target=GetHandleUnitEx(key,"target")
if GetUnitAbilityLevel(target,'BPSE')>0 then
call UnitRemoveAbility(target,'BPSE')
endif
call FlushStoredMission(LocalVars(),key)
call DestroyGroup(GetHandleGroupEx(key,"filter"))
call DestroyTimer(GetExpiredTimer())
set target=null
endfunction
function ArrowTargetFilter takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(),Player(GetStoredInteger(LocalVars(),"AR"+I2S(h2i(GetExpiredTimer())),"id")))==true and IsUnitType(GetFilterUnit(),ConvertUnitType(2))==false and IsUnitType(GetFilterUnit(),ConvertUnitType(25))==false and GetUnitState(GetFilterUnit(),ConvertUnitState(0))>0
endfunction
function ArrowFlyingTime takes nothing returns nothing
local string key="AR"+I2S(h2i(GetExpiredTimer()))
local unit arrow=GetHandleUnitEx(key,"arrow")
local integer lv=GetStoredInteger(LocalVars(),key,"lv")
local integer flytime=GetStoredInteger(LocalVars(),key,"time")
local group g=GetHandleGroupEx(key,"filter")
local real angle=GetStoredReal(LocalVars(),key,"angle")
local real dis=lv*10+20
local location loc=Location(GetUnitX(arrow)+2*dis*Cos(angle),GetUnitY(arrow)+2*dis*Sin(angle))
local real flyheight=GetStoredReal(LocalVars(),key,"flyheight")-GetLocationZ(loc)
local unit stun=null
local unit target=null
call GroupEnumUnitsInRange(g,GetUnitX(arrow),GetUnitY(arrow),dis+20,Condition(function ArrowTargetFilter))
set target=FirstOfGroup(g)
if target != null then
if IsUnitType(target,ConvertUnitType(26)) then
call UnitDamageTarget(arrow,target,120*lv,true,true,ConvertAttackType(0),ConvertDamageType(5),ConvertWeaponType(0))
call KillUnit(arrow)
call FlushStoredMission(LocalVars(),key)
call DestroyTimer(GetExpiredTimer())
call DestroyGroup(g)
else
set stun=CreateUnit(GetOwningPlayer(arrow),'e00G',GetUnitX(arrow),GetUnitY(arrow),angle*bj_RADTODEG)
call UnitAddAbility(stun,'A04Z')
call UnitApplyTimedLife(stun,'B000',0.3)
if IssueTargetOrder(stun,"thunderbolt",target) then
call UnitDamageTarget(arrow,target,120*lv,true,true,ConvertAttackType(0),ConvertDamageType(5),ConvertWeaponType(0))
if GetUnitState(target,ConvertUnitState(0))>0 then
call StoreInteger(LocalVars(),key,"target",h2i(target))
if IsUnitType(target,ConvertUnitType(0))==true then
set dis=2
else
set dis=1
endif
call TimerStart(GetExpiredTimer(),(lv*10+20)*flytime/(dis*250),false,function ArrowStunLast)
else
call FlushStoredMission(LocalVars(),key)
call DestroyTimer(GetExpiredTimer())
call DestroyGroup(g)
endif
call KillUnit(arrow)
else
call UnitDamageTarget(arrow,target,60*lv,true,true,ConvertAttackType(0),ConvertDamageType(5),ConvertWeaponType(0))
endif
endif
elseif flytime > 33+lv or flyheight<0 then
call PauseTimer(GetExpiredTimer())
call FlushStoredMission(LocalVars(),key)
call DestroyTimer(GetExpiredTimer())
call DestroyGroup(g)
call KillUnit(arrow)
endif
call SetUnitX(arrow,GetUnitX(arrow)+dis*Cos(angle))
call SetUnitY(arrow,GetUnitY(arrow)+dis*Sin(angle))
call debugmsg("X:"+R2S(GetUnitX(arrow))+" Y:"+R2S(GetUnitY(arrow)))
//call SetUnitPosition(arrow,GetUnitX(arrow)+dis*Cos(angle),GetUnitY(arrow)+dis*Sin(angle))
call SetUnitFlyHeight(arrow,flyheight,0)
call StoreInteger(LocalVars(),key,"time",flytime+1)
call GroupClear(g)
call RemoveLocation(loc)
set arrow=null
set g=null
set target =null
set loc=null
endfunction
function ArrowSetoff takes nothing returns nothing
local location loc=GetSpellTargetLoc()
local real angle=Atan2(GetLocationY(loc) - GetUnitY(GetTriggerUnit()), GetLocationX(loc) - GetUnitX(GetTriggerUnit()))
local unit arrow=CreateUnit(GetTriggerPlayer(),'e00L',GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),angle*bj_RADTODEG)
local timer t=CreateTimer()
local string key="AR"+I2S(h2i(t))
local group g=CreateGroup()
local integer lv=GetUnitAbilityLevel(GetTriggerUnit(),GetSpellAbilityId())
call UnitApplyTimedLife(arrow,'B000',2)
call StoreReal(LocalVars(),key,"angle",angle)
call StoreInteger(LocalVars(),key,"arrow",h2i(arrow))
call StoreInteger(LocalVars(),key,"filter",h2i(g))
call StoreInteger(LocalVars(),key,"lv",lv)
call StoreInteger(LocalVars(),key,"id",GetPlayerId(GetTriggerPlayer()))
call FlushStoredInteger(LocalVars(),key,"time")
call TimerStart(t,0.04,true,function ArrowFlyingTime)
call RemoveLocation(loc)
set loc=GetUnitLoc(arrow)
call StoreReal(LocalVars(),key,"flyheight",GetLocationZ(loc)+100)
call RemoveLocation(loc)
set loc=null
set t=null
set g=null
set arrow=null
endfunction[/jass] |
评分
-
查看全部评分
|