function GetHeroIllusionId takes integer UnitTypeId returns integer
if UnitTypeId=='Hro0' then//0
return 'Oro0'
elseif UnitTypeId=='Hro1' then//1
return 'Oro1'
elseif UnitTypeId=='Hro2' then//2
return 'Oro2'
elseif UnitTypeId=='Hro3' then//3
return 'Oro3'
elseif UnitTypeId=='Hro4' then//4
return 'Oro4'
elseif UnitTypeId=='Hro5' then//5
return 'Oro5'
elseif UnitTypeId=='Hro6' then//6
return 'Oro6'
elseif UnitTypeId=='Hro7' then//7
return 'Oro7'
elseif UnitTypeId=='Hro8' then//8
return 'Oro8'
elseif UnitTypeId=='Hro9' then//9
return 'Oro9'
elseif UnitTypeId=='Ero2' then//10
return 'Uro2'
elseif UnitTypeId=='Er51' then//11
return 'Ur51'
elseif UnitTypeId=='Er52' then//12
return 'Ur52'
elseif UnitTypeId=='Er53' then//13
return 'Ur53'
elseif UnitTypeId=='Ero9' then//14
return 'Uro9'
endif
return 0
endfunction
function Item_Copy_AtoB_Illusion takes unit ua,unit u_Target returns nothing
local integer i = 0
local item it_Origin = null
local item it_Target = null
local integer it_Origin_Type = 0
local integer it_Origin_Charges = 0
loop
exitwhen i > 5
set it_Origin = UnitItemInSlot(ua,i)//源头单位此格物品
set it_Origin_Type = GetItemTypeId(it_Origin)//源头单位此格物品类型
set it_Origin_Charges = GetItemCharges(it_Origin)//源头此格物品次数
set it_Target = UnitItemInSlot(u_Target,i)//目标此格物品
call RemoveItem(it_Target)//目标此格物品清空
call UnitAddItemToSlotById(u_Target,it_Origin_Type,i)
set it_Target = UnitItemInSlot(u_Target,i)//目标此格物品
call SetItemCharges(it_Target,it_Origin_Charges)
call SetItemDropOnDeath(it_Target,false)
set i = i + 1
endloop
set it_Origin = null
set it_Target = null
endfunction
function CreateIllusion_Hero takes player p,unit ut,real x,real y,real f returns unit
//1,等级和经验
local integer Lv=GetHeroLevel(ut)
local integer XP=GetHeroXP(ut)
//2属性
local integer Str=GetHeroStr(ut,false)
local integer Agi=GetHeroAgi(ut,false)
local integer Int=GetHeroInt(ut,false)
//3血蓝量
local real Life=GetUnitState(ut,UNIT_STATE_LIFE)
local real Mana=GetUnitState(ut,UNIT_STATE_MANA)
local integer UnitTypeId=GetHeroIllusionId(GetUnitTypeId(ut))
local unit Illusion=CreateUnit(p,UnitTypeId,x,y,f)
//1等级和经验
call SetHeroXP(Illusion,XP,false)
//2属性
call SetHeroStr(Illusion,Int,false)
call SetHeroAgi(Illusion,Agi,false)
call SetHeroInt(Illusion,Str,false)
//3血蓝量
call SetUnitState(Illusion,UNIT_STATE_LIFE,Life)//11
call SetUnitState(Illusion,UNIT_STATE_MANA,Mana)//12
//4
call SuspendHeroXP(Illusion,true)//暂停经验获取
call SetUnitUseFood(Illusion,false)//禁止人口占用
call UnitAddAbility(Illusion,'Silu')
call UnitMakeAbilityPermanent(Illusion,true,'Silu')
call Item_Copy_AtoB_Illusion(ut,Illusion)
call SetUnitAbilityLevel(Illusion,'Aien',2)//-----Here is the POINT,MUST set the itemslot(ability) has two level, Level 1 is allowed to get item and Level 2 is not.
set UnitForReturn=Illusion
set Illusion=null
return UnitForReturn
endfunction
function CreateIllusion_Unit takes player p,unit ut,real x,real y,real f returns unit
//1血蓝量
local real Life=GetUnitState(ut,UNIT_STATE_LIFE)
local real Mana=GetUnitState(ut,UNIT_STATE_MANA)
local integer UnitTypeId=GetUnitTypeId(ut)
local unit Illusion=CreateUnit(p,UnitTypeId,x,y,f)
//3血蓝量
call SetUnitState(Illusion,UNIT_STATE_LIFE,Life)//11
call SetUnitState(Illusion,UNIT_STATE_MANA,Mana)//12
//4
call SetUnitUseFood(Illusion,false)//禁止人口占用
call UnitAddAbility(Illusion,'Silu')
call UnitMakeAbilityPermanent(Illusion,true,'Silu')
set UnitForReturn=Illusion
set Illusion=null
return UnitForReturn
endfunction
function CreateIllusion takes player p,unit ut,real x,real y,real f returns unit
if IsUnitType(ut,UNIT_TYPE_HERO)==true then
return CreateIllusion_Hero(p,ut,x,y,f)
endif
return CreateIllusion_Unit(p,ut,x,y,f)
endfunction
function IllusionDeath takes unit Illusion returns nothing
call DeleteUnitsItemAll(Illusion)
call RemoveUnit(Illusion)
endfunction