找回密码
 点一下
查看: 3478|回复: 6

几个模板功能

[复制链接]
发表于 2009-2-1 16:19:35 | 显示全部楼层 |阅读模式
[jass]
//***************************************************************************************************
//*
//*  Nova Template
//*
//*  Requires:
//*      - A triggerer ability (has to be instant (non-target order) )
//*      - The Spell Templates System
//*      - CSSafety
//*      - This Trigger
//*
//*  Art:
//*      - The Triggerer Ability's Missile Art determines the missile
//*      - The Triggerer Ability's Special Art is spawned to the missile periodically
//*      - The Triggerer Ability's Target Art is used on targets when collision is greater than 0
//*                            And the second target art is its attachment point
//*
//***************************************************************************************************

//===================================================================================================
// Nova Template Setup
//
function NovaTemplateSetup takes nothing returns nothing
local integer D //An integer variable we use later to save the Damage Options so we give them to the templates
local integer s //An integer variable we use later to save the rawcodes of spells to save some time

//===================================================================================================
// Template Info:
//
// Template Name Id = "NovaSpellTemplate"
//
// integer "n"         is the number of missiles:
// real    "dur"       is the duration for the missiles
// real    "speed"     is the movement speed for the missiles (from 150 to 522, please)
// real    "scale"     is the scale for the missiles:
// real    "turnic"    is the angle incriment, changes the way the missiles spin. (0 makes them go straight)
// integer "abil"      is the ability added to the missiles.
// The ability added will match the level of the triggerer ability if possible
//
// real    "collision" Enables Bolt Collision, After this step many options are available :
// (next options only work if missiles have collision greater than 0)
//
// integer "DamageOptions" Caster System's Damage Options in saveable form, that determine which units to affect
//
// real    "dmg"           The Damage done to units hit by bolts
// real    "Pdmg"          The Periodic damage done to units
// real    "PDmgPeriod"    The Period for the periodic damage
// real    "PDmgDur"       The duration of the periodic damage
// integer "Spell"         The rawcode of the spell to cast
// integer "OrderId"       The Order Id of the spell to cast
// real    "RecDelay"      The Recycle Delay of the dummy caster that casts the Spell to cast
//
// integer "TargetLog"     Is 1 if it logs targets so it avoids to hit a unit more than once
//     

//===================================================================================================
// Nova template Defaults:
//
    call SetTemplateDefaultInt( "NovaSpellTemplate","n"      ,15)     //Default number of bolts=15
    call SetTemplateDefaultInt( "NovaSpellTemplate","abil"   ,'Aphx') //Default ability to add is Pheonix Morphing (Egg) let's call it the null ability
    call SetTemplateDefaultReal("NovaSpellTemplate","dur"    ,2)   //Default duration is 2
    call SetTemplateDefaultReal("NovaSpellTemplate","scale"  ,1)   //Default scale is 1
    call SetTemplateDefaultReal("NovaSpellTemplate","turninc",12)  //Default turning value is 12
    call SetTemplateDefaultReal("NovaSpellTemplate","speed"  ,522) //Default speed = 522 (max)

//===================================================================================================
// Incineration Nova ('A00C')
//
set s=SetSpellTemplate('A00C',"NovaSpellTemplate")
set D=0                                                //Incineration Nova Options :
set D=DamageTypes(ATTACK_TYPE_NORMAL,DAMAGE_TYPE_FIRE) //Spell fire damage
set D=D+DontDamageSelf()                               //Don't hurt self
set D=CreateDamageOptions(D)                           //Save the damage options

    call SetAbilityDataReal(s,"speed"    ,0,200 )  //200 of speed for all levels
    call SetAbilityDataReal(s,"dur"      ,0,0.5 )  // 0.5 seconds of duration for all levels
    call SetAbilityDataReal(s,"collision",0,55 )   // Always a collision of 55
    call SetAbilityDataInt( s,"TargetLog",0, 1 )   // Always log targets

    call SetAbilityDataReal(s,"dmg"      ,1,20)    //Level 1: 20 initial damage
    call SetAbilityDataReal(s,"dmg"      ,2,30)    //Level 2: 30 initial damage
    call SetAbilityDataReal(s,"dmg"      ,3,40)    //Level 3: 40 initial damage

    call SetAbilityDataReal(s,"Pdmg"     ,1,5)    //Level 1: 5 Periodic damage
    call SetAbilityDataReal(s,"Pdmg"     ,2,8)    //Level 2: 8 periodic damage
    call SetAbilityDataReal(s,"Pdmg"     ,3,11)   //Level 3: 11 Periodic damage

    call SetAbilityDataReal(s,"PdmgDur"  ,1,4)    //Level 1: Periodic damage lasts 4 seconds
    call SetAbilityDataReal(s,"PdmgDur"  ,2,6)    //Level 2: Periodic damage lasts 6 seconds
    call SetAbilityDataReal(s,"PdmgDur"  ,3,8)    //Level 3: Periodic damage lasts 8 seconds

   call SetAbilityDataInt( s,"damageoptions",0,D) //Using the damage options saved above


//===================================================================================================
// Poison Nova ('A003')
//
set s=SetSpellTemplate('A003',"NovaSpellTemplate")
    call SetAbilityDataInt( s, "abil", 0, 'A000' )  //Adds ability A000 for damage, it levels automatically
    call SetAbilityDataReal(s, "scale", 0, 2 )      //2 of bolt scale

//===================================================================================================
// Lightning Nova ('A007')
//
set s=SetSpellTemplate('A007',"NovaSpellTemplate")
    call SetAbilityDataInt( s, "abil", 0, 'A004' )  //Adds Ability A004 for damage
    call SetAbilityDataInt( s, "n", 0, 20 )         //20 bolts of lighting
    call SetAbilityDataReal(s, "dur", 1, 1 )        // Level 1 duration = 1
    call SetAbilityDataReal(s, "dur", 2, 2 )        // Level 2 duration = 2
    call SetAbilityDataReal(s, "dur", 3, 4 )        // Level 3 duration = 4
    call SetAbilityDataReal(s, "turninc", 0, 0 )    //Turn value of 0 (bolts won't turn)

//===================================================================================================
// Windstorm Caller ('A008')
//
// So, spell templates might be a life saver, I made a completelly
// Different Spell basing it from the Nova template
//
set s=SetSpellTemplate('A008',"NovaSpellTemplate")
    call SetAbilityDataInt( s, "abil", 0, 'A009' )  //Adds ability A009 (from tornado spin)
    call SetAbilityDataInt( s, "n", 0, 5 )          //Only 5 'bolts'
    call SetAbilityDataReal(s, "dur", 0, 5 )        //Lasts 5 seconds
    call SetAbilityDataReal(s, "turninc", 0, 20 )   //Turn value is 20
    call SetAbilityDataReal(s, "scale", 0, 0.5 )    //Scale is 0.5

//===================================================================================================
// Ability Preloading
//
// Next is unrelated to the templates system, just avoids the first time cast lag, here you
// should preload any ability used as auxiliar ability for the template, just to avoid first
// time cast lag.
//
    call PreloadAbility('A00E')
    call PreloadAbility('A000')
    call PreloadAbility('A004')
    call PreloadAbility('A009')

endfunction

//===================================================================================================
// Nova template code:
//
function NovaTemplate_DoStuff takes unit u, unit t, integer s, integer l, real fc returns nothing
local real dmg=GetAbilityDataReal(s,l,"dmg")
local real dmgps=GetAbilityDataReal(s,l,"Pdmg")
local integer ab=GetAbilityDataInt(s,l,"Spell")
local string fx=GetAbilityEffectById(s,EFFECT_TYPE_TARGET,0)
    if (dmg!=0) then
        call UnitDamageTarget(u,t,dmg*fc,true,false,null,null,null)
    endif
    if (dmgps!=0) then
        call UnitDamageUnitTimed(u,dmgps*fc,GetAbilityDataReal(s,l,"PdmgPeriod"),GetAbilityDataReal(s,l,"PdmgDur"),t,fx,GetAbilityEffectById(s,EFFECT_TYPE_TARGET,1),null,null)
    elseif (fx!="") and (fx!=null) then
        call DestroyEffect( AddSpecialEffectTarget(fx,t,GetAbilityEffectById(s,EFFECT_TYPE_TARGET,1)  )  )
    endif
    if (ab!=0) then
        call CasterCastAbilityEx(GetOwningPlayer(u),GetUnitX(t),GetUnitY(t),0,ab,l,I2S(GetAbilityDataInt(s,l,"OrderId")),t,GetAbilityDataReal(s,l,"RecDelay") )
    endif
endfunction

function NovaTemplate_Collision takes nothing returns nothing
local trigger x=GetTriggeringTrigger()
local unit t=GetTriggerUnit()
local unit u=GetAttachedUnit(x,"u")
local integer s=GetAttachedInt(x,"s")
local integer l=GetAttachedInt(x,"l")

local real fc=0

local group g=GetAttachedGroup(x,"g")

    if ((g==null) or not(IsUnitInGroup(t,g)) ) then
        set fc=GetDamageFactorByOptions(u,t,   LoadDamageOptions(GetAbilityDataInt(s,l,"DamageOptions") ) )
    endif

    if (fc!=0) then
        if (g!=null) then
            call GroupAddUnit(g,t)
        endif
        call NovaTemplate_DoStuff(u,t,s,l,fc)
    endif

set g=null
set u=null
set x=null
set t=null
endfunction

function NovaTemplate_AI takes nothing returns nothing
local unit m=bj_lastCreatedUnit
local unit u=bj_meleeNearestMine
local integer l=R2I( udg_castervars[9] )
local integer s=udg_currentabi
local integer abi=GetAbilityDataInt(s,l,"abil")
local real inc=GetAbilityDataReal(s,l,"turninc")
local real dir=GetAbilityDataReal(s,l,"scale")
local real dirr

local trigger t=CreateTrigger()
local triggeraction ac=TriggerAddAction(t,function NovaTemplate_Collision)
local group g=null
local string fx=GetAbilityEffectById(s,EFFECT_TYPE_SPECIAL,0)

    set dirr=GetAbilityDataReal(s,l,"collision")
    if (dirr!=0) then
        call AttachInt(t,"s",s)
        call AttachInt(t,"l",l)
        call AttachObject(t,"u",u)
        if (GetAbilityDataInt(s,l,"TargetLog")==1) then
            set g=GetAttachedGroup(u,"Nova_"+I2S(s)+"_Group")
            if (g==null) then
                set g=NewGroup()
                call AttachObject(u,"Nova_"+I2S(s)+"_Group",g)
                call AttachObject(t,"g",g)
            else
                call AttachObject(t,"g",g)
                set g=null
            endif
        else
            call AttachObject(t,"g",null)
        endif
        call TriggerRegisterUnitInRange(t,m,dirr,null)

    endif

    call SetUnitScale( m, dir,dir,dir)
    set dir=udg_castervars[8]
    call SetUnitFlyHeight( m, 100,0)
    call SetUnitMoveSpeed( m, 300)
    loop
        set dirr=dir*bj_DEGTORAD
        call IssuePointOrder(m, "move", GetUnitX(m)+200*Cos(dirr), GetUnitY(m)+200*Sin(dirr) )
        exitwhen ((GetUnitAbilityLevel(m,abi)  == 0) or (GetUnitCurrentOrder(m)!=OrderId("move")))
        if ((fx!="") and (fx!=null)) then
            call DestroyEffect(AddSpecialEffectTarget(fx,m,"origin"))
        endif
        set dir=dir+inc
        call TriggerSleepAction(0)
    endloop
    call TriggerRemoveAction(t,ac)
    call DestroyTrigger(t)
    if (g!=null) then
        call AttachObject(u,"Nova_"+I2S(s)+"_Group",null)
        call ReleaseGroup(g)
       set g=null
    endif

set ac=null
set t=null
set m=null
set u=null
endfunction

function NovaSpellTemplate takes nothing returns nothing
local unit u=GetTriggerUnit()
local integer s=GetSpellAbilityId()
local integer l=GetUnitAbilityLevel( u,s)

local real speed=GetAbilityDataReal(s,l,"speed")
local real dur=GetAbilityDataReal(s,l,"dur")
local integer abil=GetAbilityDataInt(s,l,"abil")
local integer n=GetAbilityDataInt(s,l,"n")

    set udg_castervars[8]=0
    set udg_castervars[9]=l
    set bj_meleeNearestMine=u
    loop
        exitwhen udg_castervars[8]>=360
        set bj_lastCreatedUnit=CasterUseAbilityLevelStatic( GetOwningPlayer(u), GetAbilityEffectById(s,EFFECT_TYPE_MISSILE,0) , abil,l, dur, GetUnitX(u), GetUnitY(u) )
        call SetUnitMoveSpeed( bj_lastCreatedUnit, speed )
        set udg_currentabi=s
        call ExecuteFunc("NovaTemplate_AI")
        set udg_castervars[8]=udg_castervars[8]+360/n
    endloop

set u=null
endfunction

function InitTrig_Nova_Spells takes nothing returns nothing
    call ExecuteFunc("NovaTemplateSetup")
//Must use ExecuteFunc to prevent the Map init thread from getting too long and crash.
endfunction



[/jass]
发表于 2009-2-1 16:24:22 | 显示全部楼层

LZ不是人..
回复

使用道具 举报

发表于 2009-2-1 18:36:52 | 显示全部楼层
lz- -下次用如果可以的话中文写注释吧,郁闷死我了
回复

使用道具 举报

 楼主| 发表于 2009-3-3 21:37:17 | 显示全部楼层
RCCS v W

[jass]
constant function H2I takes handle h returns integer
    return h
    return 0
endfunction

constant function B2I takes boolean b returns integer
    if(b)then
        return 1
    endif
    return 0
endfunction

function GetItemSlot takes unit hero, item it returns integer
    local integer i=0
    loop
        exitwhen i==6
        if(UnitItemInSlot(hero,i)==it)then
            return i
        endif
        set i=i+1
    endloop
    return -1
endfunction
function SimError takes player ForPlayer, string msg returns nothing
    local sound error=CreateSoundFromLabel( "InterfaceError",false,false,false,10,10)
        if (GetLocalPlayer() == ForPlayer) then
            call ClearTextMessages()            
                call StartSound( error )
            call DisplayTimedTextToPlayer( ForPlayer, 0.52, -1.00, 2.00, "|cffffcc00"+msg+"|r" )
        endif
        call KillSoundWhenDone(error)
    set error=null
endfunction
function AbilityGetMaxLevel takes integer abil returns integer
    local unit hero
    local integer max=GetStoredInteger(objects(),I2S(abil),"m_maxlvl")
    if(abil==0)then
        return 0
    endif
    if(max==0)then
        set hero=CreateUnit(Player(15),'hfoo',0,0,0)
        call UnitAddAbility(hero,abil)
        call SetUnitAbilityLevel(hero,abil,100)
        set max=GetUnitAbilityLevel(hero,abil)
        call StoreInteger(objects(),I2S(abil),"m_maxlvl",max)
        call RemoveUnit(hero)
        set hero=null
    endif
    return max
endfunction

function Vector_size takes string vector returns integer
    return GetStoredInteger(objects(),vector,"m_size")
endfunction

function Vector_getElem takes string vector,integer index returns integer
    return GetStoredInteger(objects(),vector,"m_a"+I2S(index))
endfunction

function Vector_setElem takes string vector,integer index, integer data returns boolean
    if(index<0 or index>=Vector_size(vector))then
        return false
    endif
    call StoreInteger(objects(),vector,"m_a"+I2S(index),data)
    return true
endfunction

function Vector_addElem takes string vector, integer data returns boolean
    local gamecache gc=objects()
    local integer size=Vector_size(vector)
    call StoreInteger(gc,vector,"m_a"+I2S(size),data)
    call StoreInteger(gc,vector,"m_size",size+1)
    return true
endfunction

function Vector_removeElem takes string vector, integer index returns integer
    local integer size=Vector_size(vector)-1
    local gamecache gc=objects()
    local integer val=GetStoredInteger(gc,vector,"m_a"+I2S(index))
    local integer i=index
    if(index<=size and index>=0)then
        loop
            exitwhen i==size
            call StoreInteger(gc,vector,"m_a"+I2S(i),GetStoredInteger(gc,vector,"m_a"+I2S(i+1)))
            set i=i+1
        endloop
        call StoreInteger(gc,vector,"m_size",size)
        call StoreInteger(gc,vector,"m_a"+I2S(size),0) //reset it to zero
    endif
    set gc=null
    return val
endfunction

function Vector_swapElems takes string vector, integer x,integer y returns nothing
    local integer i=Vector_getElem(vector,x)
    call Vector_setElem(vector,x,Vector_getElem(vector,y))
    call Vector_setElem(vector,y,i)
endfunction

function GetUniqueId takes nothing returns integer
    local gamecache gc=null
    local integer last=0
    local integer size=Vector_size("0")
    set gc=objects()
    if(size!=0)then
        return Vector_removeElem("0",size-1)
    endif
    set last=GetStoredInteger(gc,"index","index")+1
    call StoreInteger(gc,"Index","index",last)
    set gc=null
    return last
endfunction

function DestroyObject takes string object returns nothing
    call FlushStoredMission(objects(),object)
endfunction

function RecycleObject takes string object returns nothing
    if(object=="0")then
        return
    endif
    call Vector_addElem("0",S2I(object)) //recycle object type.
    call DestroyObject(object)
endfunction

function CreateVector takes nothing returns string
    return I2S(GetUniqueId())
endfunction
//==================================================================
function Node_setData takes string node,integer data returns nothing
    local gamecache gc=objects()
    call StoreInteger(gc,node,"M_data",data)
    set gc=null
endfunction

function Node_setNext takes string node,string next returns nothing
    local gamecache gc=objects()
    call StoreString(gc,node,"m_next",next)
    set gc=null
endfunction

function Node_setPred takes string node,string pred returns nothing
    local gamecache gc=objects()
    call StoreString(gc,node,"m_pred",pred)
    set gc=null
endfunction

function Node_getData takes string node returns integer
    local gamecache gc=objects()
    local integer data=GetStoredInteger(gc,node,"m_data")
    set gc=null
    return data
endfunction

function Node_getNext takes string node returns string
    local gamecache gc=objects()
    local string next=GetStoredString(gc,node,"m_next")
    set gc=null
    return next
endfunction
   
function Node_getPred takes string node returns string
    local gamecache gc=objects()
    local string pred=GetStoredString(gc,node,"m_pred")
    set gc=null
    return pred
endfunction


function CreateNode takes integer data,string next,string pred returns string
    local string this=I2S(GetUniqueId())
    local gamecache gc=objects()
    call StoreInteger(gc,this,"m_data",data)
    if (next=="this")then
        set next=this
    endif
    call StoreString(gc,this,"m_next",next)
    if(pred=="this")then
        set pred=this
    endif
    call StoreString(gc,this,"m_pred",pred)
    set gc=null
    return this
endfunction

function Queue_getTail takes string q returns string
    local gamecache gc=objects()
    local string t=GetStoredString(gc,q,"m_tail")
    set gc=null
    return t
endfunction
function Queue_getLength takes string q returns integer
    local gamecache gc=objects()
    local integer l=GetStoredInteger(gc,q,"m_length")
    set gc=null
    return l
endfunction
function Queue_getSize takes string q returns integer
    local gamecache gc=objects()
    local integer s=GetStoredInteger(gc,q,"m_size")
    set gc=null
    return s
endfunction


//Will only return the falling off tail's data field.
function Queue_Enqueue takes string q,integer data returns integer
    local gamecache gc=objects()
    local string tail=Queue_getTail(q)
    local string head=null
    local string pred=null
    local string new=null
    local integer size=Queue_getSize(q)
    local integer length=Queue_getLength(q)
    local integer ret=0
    if(tail==null)then //0 element q
        set new=CreateNode(data,"this","this")
        call StoreString(gc,q,"m_tail",new)
        call StoreInteger(gc,q,"m_size",1)
    elseif(size!=length)then
        set head=Node_getNext(tail)
        set new=CreateNode(data,head,tail)
        call Node_setNext(tail,new)
        call Node_setPred(head,new)
        call StoreInteger(gc,q,"m_size",size+1)
    else
        set head=Node_getNext(tail)
        set pred=Node_getPred(tail)
        set new=CreateNode(data,head,pred)
        call Node_setPred(head,new)
        call Node_setNext(pred,new)
        call StoreString(gc,q,"m_tail",pred)
        set ret=Node_getData(tail)
        call RecycleObject(tail)
    endif
    return ret
endfunction

function Queue_Dequeue takes string q returns integer
    local gamecache gc=objects()
    local string tail=Queue_getTail(q)
    local string head=null
    local string pred=null
    local integer ret
    if(tail==null)then
        set ret=-1
    elseif(Queue_getSize(q)==1)then //this queue has one elem
        call StoreInteger(gc,q,"m_size",0)
        set ret=Node_getData(tail)
        call RecycleObject(tail)
        call StoreString(gc,q,"m_tail",null)
    else
        set head=Node_getNext(tail)
        set pred=Node_getPred(tail)
        call StoreInteger(gc,q,"m_size",Queue_getSize(q)-1)
        set ret=Node_getData(tail)
        call Node_setNext(pred,head)
        call Node_setPred(head,pred)
        call RecycleObject(tail)
        call StoreString(gc,q,"m_tail",pred)
    endif
    return ret
endfunction
//length must be at least two.
function CreateQueue takes integer length returns string
    local string this=I2S(GetUniqueId())
    local gamecache gc=objects()
    call StoreInteger(gc,this,"m_length",length)
    call StoreInteger(gc,this,"m_size",0)
    set gc=null
    return this
endfunction
//==============================================================
function IV_capacity takes string iv returns integer
    return GetStoredInteger(objects(),iv,"m_capacity")
endfunction

function IV_getItem takes string iv,integer ix returns item
    return Vector_getElem(iv,ix)
    return null
endfunction

function IV_setItem takes string iv,integer ix,item it returns nothing
    call Vector_setElem(iv,ix,H2I(it))
endfunction

function IV_getIndexOfItem takes string iv,item it returns integer
    local integer i=0
    local integer end=Vector_size(iv)
    local integer target=H2I(it)
    loop
        exitwhen i==end
        if(Vector_getElem(iv,i)==target)then
            return i
        endif
        set i=i+1
    endloop
    return -1
endfunction

function IV_addItem takes string iv,item it returns boolean
    if(IV_capacity(iv)==0)then
        return Vector_addElem(iv,H2I(it))
    elseif(IV_capacity(iv)==Vector_size(iv))then
        return false
    else
        return Vector_addElem(iv,H2I(it))
    endif
endfunction

function IV_removeItemByIx takes string iv,integer ix returns item
    return Vector_removeElem(iv,ix)
    return null
endfunction

function IV_removeItem takes string iv,item toRemove returns boolean
    return IV_removeItemByIx(iv,IV_getIndexOfItem(iv,toRemove))!=null
endfunction

function PrintIV takes string iv returns nothing
    local integer i=0
    local integer size=Vector_size(iv)
    loop
        exitwhen i==size
        call BJDebugMsg(GetItemName(IV_getItem(iv,i)))
        set i=i+1
    endloop
endfunction

function CreateIV takes integer capacity returns string
    local string this=CreateVector()
    call StoreInteger(objects(),this,"m_capacity",capacity)
    return this
endfunction
//=========================================================================
function Hero_getState takes unit hero returns integer
    return GetStoredInteger(objects(),I2S(H2I(hero)),"m_state")
endfunction

function Hero_setState takes unit hero,integer state returns nothing
    call StoreInteger(objects(),I2S(H2I(hero)),"m_state",state)
endfunction

function Hero_getNext takes unit hero returns item
    return GetStoredInteger(objects(),I2S(H2I(hero)),"m_next")
    return null
endfunction

function Hero_getCancel takes unit hero returns item
    return GetStoredInteger(objects(),I2S(H2I(hero)),"m_cancel")
    return null
endfunction

function Hero_BlankIV takes unit hero returns string
    return GetStoredString(objects(),I2S(H2I(hero)),"m_biv")
endfunction

function Hero_IV takes unit hero returns string
    return GetStoredString(objects(),I2S(H2I(hero)),"m_iv")
endfunction

function Hero_getFree takes unit hero returns integer
    return GetStoredInteger(objects(),I2S(H2I(hero)),"m_free")
endfunction

function Hero_setFree takes unit hero,integer free returns nothing
    call StoreInteger(objects(),I2S(H2I(hero)),"M_free",free)
endfunction

function Hero_addToIV takes unit hero,item toAdd returns boolean
    local string iv=Hero_IV(hero)
    local integer i=0
    local integer free=Hero_getFree(hero)
    if(free==0)then
        return false
    else
        loop
            exitwhen i==6
            if(IV_getItem(iv,i)==null)then
                call UnitRemoveItem(hero,toAdd)
                call SetItemVisible(toAdd,false)
                call IV_setItem(iv,i,toAdd)
                call Hero_setFree(hero,free-1)
                set i=5
            endif
            set i=i+1
        endloop
    return true
    endif
endfunction
   
function Hero_removeBlanks takes unit hero returns nothing
    local integer i=0
    local integer state=Hero_getState(hero)
    local item temp=null
    call Hero_setState(hero,74)
    loop
        exitwhen i==6
        set temp=UnitItemInSlot(hero,i)
        if(GetItemTypeId(temp)==IDBlank())then
            call UnitRemoveItem(hero,temp)
            call SetItemVisible(temp,false)
        endif
        set i=i+1
    endloop
    call Hero_setState(hero,state)
    set temp=null
endfunction

function Hero_clearInv takes unit hero returns nothing
    local integer i=0
    local integer state=Hero_getState(hero)
    call Hero_setState(hero,74) //prevents drop from firing.
    loop
        exitwhen i==6
        call SetItemVisible(UnitRemoveItemFromSlot(hero,i),false)
        set i=i+1
    endloop
    call Hero_setState(hero,state)
endfunction

function Hero_swapInv takes unit hero returns nothing
    local integer i=0
    local item toIV=null
    local item toH=null
    local string hiv=Hero_IV(hero)
    local string biv=Hero_BlankIV(hero)
    local integer state=Hero_getState(hero)
    local integer free=0
    call Hero_setState(hero,74) //prevents drop from firing.
    call StoreInteger(objects(),I2S(H2I(hero)),"m_used",UnitInventoryCount(hero))
    loop
        exitwhen i==6
        set toIV=UnitRemoveItemFromSlot(hero,i)
        if(toIV==null)then
            set free=free+1
        endif
        set toH=IV_getItem(hiv,i)
        if(toH==null)then
            set toH=IV_getItem(biv,i)
        endif
        call SetItemVisible(toIV,false)
        call SetItemVisible(toH,true)
        call IV_setItem(hiv,i,toIV)
        call UnitAddItem(hero,toH)
        set i=i+1
    endloop
    set i=0
    call Hero_setFree(hero,free)
    call Hero_removeBlanks(hero)
    call Hero_setState(hero,state)
    set toIV=null
    set toH=null
endfunction

//assumes passed an empty INVed hero
// Returns the current Page indexed.
function Hero_nextPage takes unit hero,string iv,integer page,boolean droppable returns integer
    local integer i=0
    local integer limit=Vector_size(iv)
    local item temp=null
    set page=page+1
    if( ((page-1)*4)>=limit)then
        set page=1
    endif
    loop
        exitwhen i==4
        set temp=IV_getItem(iv,(page-1)*4+i)
        if(temp==null)then
            set temp=IV_getItem(Hero_BlankIV(hero),i )
        endif
        call SetItemVisible(temp,true)
        call UnitAddItem(hero,temp)
        set i=i+1
    endloop
    set temp=Hero_getNext(hero)
    call SetItemVisible(temp,true)
    call SetItemCharges(temp,page)
    call UnitAddItem(hero,temp)
    set temp=Hero_getCancel(hero)
    call UnitAddItem(hero,temp)
    call SetItemVisible(temp,true)
    call SetItemDroppable(temp,droppable)
    return page
endfunction
//===========================================================================
// Constructor:
// ===========
// There is only one constructor for hero.
// CreateHero(unit hero) turns the unit in to a Hero object. It also creates
// the internal iv and explicitly sets it size to 6.
//===========================================================================
function CreateHero takes unit hero returns unit
    local gamecache gc=objects()
    local string this=I2S(H2I(hero))
    local string iv=CreateIV(6)
    local string biv=CreateIV(6)
    local integer i=0
    local item temp=null
    call StoreString(gc,this,"m_IV",iv)
    call StoreString(gc,this,"m_BIV",biv)
    loop
        exitwhen i==6
        set temp=CreateItem(IDBlank(),0,0)
        call IV_addItem(biv,temp)
        call SetItemVisible(temp,false)
        set i=i+1
    endloop
    set temp=CreateItem(IDCancel(),0,0)
    call SetItemVisible(temp,false)
    call StoreInteger(gc,this,"m_cancel",H2I(temp))
   
    set temp=CreateItem(IDNext(),0,0)
    call SetItemVisible(temp,false)
    call StoreInteger(gc,this,"m_next",H2I(temp))
   
    call StoreInteger(gc,iv,"m_size",6)
    set gc=null
    set temp=null
    return hero
endfunction

function T_getHero takes timer t returns unit
    return GetStoredInteger(objects(),I2S(H2I(t)),"m_hero")
    return null
endfunction

function T_getItem takes timer t returns item
    return GetStoredInteger(objects(),I2S(H2I(t)),"m_item")
    return null
endfunction

function T_getItem2 takes timer t returns item
    return GetStoredInteger(objects(),I2S(H2I(t)),"m_item2")
    return null
endfunction

function reAdd_child takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local unit hero=T_getHero(t)
    local item bag=T_getItem(t)
    call UnitAddItem(hero,bag)
    call FlushStoredMission(objects(),I2S(H2I(t)))
    call DestroyTimer(t)
    set t=null
    set hero=null
    set bag=null
endfunction

function reAddItem takes unit hero,item it returns nothing
    local timer t=CreateTimer()
    local gamecache gc=objects()
    call StoreInteger(objects(),I2S(H2I(t)),"m_hero",H2I(hero))
    call StoreInteger(objects(),I2S(H2I(t)),"m_item",H2I(it))
    call TimerStart(t,0,false,function reAdd_child)
    set t=null
    set gc=null
endfunction

function Tro_Child takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local unit hero=T_getHero(t)
    call IssueImmediateOrder(hero,"replenishon")
    call IssueImmediateOrder(hero,"replenishlifeoff")
    call DestroyObject(I2S(H2I(t)))
    call DestroyTimer(t)
    set t=null
    set hero=null
endfunction

function TRO takes unit hero returns nothing
    local timer t=CreateTimer()
    call StoreInteger(objects(),I2S(H2I(t)),"m_hero",H2I(hero))
    call TimerStart(t,0,false,function Tro_Child)
endfunction


function GetItemCostById_Hero takes nothing returns unit
    return GetStoredInteger(objects(),"rccs","m_hero")
    return null
endfunction

function GetItemCostById_Shop takes nothing returns unit
    return GetStoredInteger(objects(),"rccs","m_shop")
    return null
endfunction


function GetItemCostById takes integer id,boolean whichtype,integer charges returns integer
    local unit h
    local unit s
    local player p
    local gamecache gc=objects()
    local string t=I2S(id)
    local integer gold=GetStoredInteger(gc,t,"m_gold")
    local integer lumber=GetStoredInteger(gc,t,"m_lumber")
    local integer def=GetStoredInteger(gc,t,"m_def")
    local item it=null
    if(not (gold==0 and lumber==0))then
        set gc=null
        if(def==0 or charges==0)then
            set charges=1
            set def=charges
        endif
        return charges/def*( B2I(whichtype)*gold+B2I(not whichtype)*lumber)
    endif
    set h=GetItemCostById_Hero()
    set s=GetItemCostById_Shop()
    set p=GetItemCostById_DummyPlayer()
    call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,50000)
    call SetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER,50000)
    call AddItemToStock(s,id,1,1)
    call IssueTargetOrder(s,"neutralinteract",h)
    call IssueNeutralImmediateOrderById(p,s,id)
    set it= UnitRemoveItemFromSlot(h,0)
    set def=GetItemCharges(it)
    call StoreInteger(gc,t,"m_def",def)
    call RemoveItemFromStock(s,id)
    call RemoveItem(it)
    set gold=50000-GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)
    set lumber=50000-GetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER)
    call StoreInteger(gc,t,"m_gold",gold)
    call StoreInteger(gc,t,"m_lumber",lumber)

    set h=null
    set s=null
    set gc=null
    set p=null
    set it=null
    if(def==0 or charges==0)then
        set charges=1
        set def=charges
    endif
    return charges/def*(B2I(whichtype)*gold+B2I(not whichtype)*lumber)
endfunction

function Bounty takes player whichplayer, integer bounty, real x, real y returns nothing
    local texttag t=CreateTextTag()
    local string s="+"
    local sound error=CreateSound( "Abilities\\\\Spells\\\\Items\\\\ResourceItems\\\\ReceiveGold.wav", false, true, true, 10, 10, "SpellsEAX" )
    if bounty<0 then
        set s=""
    endif
    call SetTextTagText(t,s+I2S(bounty),0.025)
    call SetTextTagPos(t,x,y, 0.00)
    call SetTextTagColor(t,255,220,0,255)
    call SetTextTagVelocity(t,0,0.03)
    if (GetLocalPlayer()==whichplayer) then
        call SetTextTagVisibility(t,true)
        call SetSoundPosition(error,x,y,0)
        call SetSoundVolume(error,127)        
        call StartSound( error )
        set s="UI\\\\Feedback\\\\GoldCredit\\\\GoldCredit.mdl"

    else
        call SetTextTagVisibility(t,false)
        set s=""
    endif
    call KillSoundWhenDone(error)
    call DestroyEffect(AddSpecialEffect(s,x,y))
    call SetTextTagFadepoint(t,2)
    call SetTextTagLifespan(t,3)
    call SetTextTagPermanent(t,false)
  set error=null
set t=null
endfunction


function InitTrig_RCCS_v_W takes nothing returns nothing
    local unit h=CreateUnit(GetItemCostById_DummyPlayer(),GetItemCostById_BuyerTypeId(),0,0,0)
    local unit s=CreateUnit(GetItemCostById_DummyPlayer(),GetItemCostById_ShopTypeId(),0,0,0)
    local gamecache gc=objects()
    local rect r=GetWorldBounds()
    call SetUnitX(h,GetRectMaxX(r)-10)
    call SetUnitX(s,GetRectMaxX(r))
    call SetUnitY(h,GetRectMaxY(r)-10)
    call SetUnitY(s,GetRectMaxY(r))
    call StoreInteger(gc,"rccs","m_hero",H2I(h))
    call StoreInteger(gc,"rccs","m_shop",H2I(s))
    call UnitAddAbility(s,'Asid')
    call UnitAddAbility(s,'Aneu')
    call UnitAddAbility(s,'Apit')
    call UnitAddAbility(s,'Avul')
    call UnitRemoveAbility(s,'Awan')
    call UnitAddAbility(s,'Aloc')
    call RemoveRect(r)
    set h=null
    set s=null
    set gc=null
    set r=null
endfunction
[/jass]
回复

使用道具 举报

 楼主| 发表于 2009-3-3 21:41:33 | 显示全部楼层
Bag core system
[jass]
function BT_getCap takes integer itemtypeid returns integer
    return GetStoredInteger(objects(),I2S(itemtypeid),"m_cap")
endfunction

function BT_getCReq takes integer itemtypeid returns boolexpr
    return GetStoredInteger(objects(),I2S(itemtypeid),"m_creq")
    return null
endfunction

function IsItemIDBT takes integer itemtypeid returns boolean
    return BT_getCap(itemtypeid)>0
endfunction

function IsItemBT takes item it returns boolean
    return IsItemIDBT(GetItemTypeId(it))
endfunction

//===========================================================================
// Constructor:
// ===========
// CreateBT(int itemtypeid,int capacity)--
// Turns the itemtypeid into a BT. And stores the capacity on it.
//===========================================================================
function CreateBT takes integer itemtypeid,integer capacity,boolexpr creq returns integer
    local string this=I2S(itemtypeid)
    local gamecache gc=objects()
    call StoreInteger(gc,this,"m_cap",capacity)
    call StoreInteger(gc,this,"m_creq",H2I(creq) )
    set gc=null
    return itemtypeid
endfunction

function BT_Bag takes nothing returns item
    return GetStoredInteger(objects(),I2S(H2I(GetTriggeringTrigger()) ),"m_bag")
    return null
endfunction

function BT_Item takes nothing returns item
    return GetStoredInteger(objects(),I2S(H2I(GetTriggeringTrigger())),"m_item")
    return null
endfunction

function BT_Hero takes nothing returns unit
    return GetStoredInteger(objects(),I2S(H2I(GetTriggeringTrigger())),"m_hero")
    return null
endfunction

function Hero_getBag takes unit hero returns item
    return GetStoredInteger(objects(),I2S(H2I(hero)),"m_bag")
    return null
endfunction

function Hero_setBag takes unit hero,item bag returns nothing
    call StoreInteger(objects(),I2S(H2I(hero)),"m_bag",H2I(bag))
endfunction

function Hero_evaluateCreq takes unit hero, item bag,item it returns boolean
    local gamecache gc=objects()
    local trigger t=CreateTrigger()
    local boolean b
    local triggercondition tc
    set tc=TriggerAddCondition(t,BT_getCReq( GetItemTypeId(bag) ) )
    call StoreInteger(gc,I2S(H2I(t)),"m_hero",H2I(hero))
    call StoreInteger(gc,I2S(H2I(t)),"m_bag",H2I(bag))
    call StoreInteger(gc,I2S(H2I(t)),"m_item",H2I(it))
    set b=TriggerEvaluate(t)
    call DestroyObject(I2S(H2I(t)))
    call TriggerRemoveCondition(t,tc)
    call DestroyTrigger(t)
    return b
endfunction


//==========================
function Bag_IV takes item bag returns string
    return GetStoredString(objects(),I2S(H2I(bag)),"m_iv")
endfunction

function Bag_getPage takes item bag returns integer
    return GetStoredInteger(objects(),I2S(H2I(bag)),"m_page")
endfunction

function Bag_setPage takes item bag,integer newval returns nothing
    call StoreInteger(objects(),I2S(H2I(bag)),"m_page",newval)
endfunction

function Bag_getHero takes item bag returns unit
    return     GetStoredInteger(objects(),I2S(H2I(bag)),"m_hero")
    return null
endfunction

function Bag_setHero takes item bag, unit hero returns nothing
    call StoreInteger(objects(),I2S(H2I(bag)),"m_hero",H2I(hero))
endfunction

//===========================================================================
// Methods:
// =======
// bool addItem(item toAdd)--Tries to m_IV.addItem(toAdd).if it can't,
// it readdItem(toAdd) the item to m_hero's inventory and returns false.
// else it removes the item from  m_hero's inventory, hides toAdd and increases
// the charge on bag.

// bool removeItem(item toRemove)--tries to m_IV.removeItem(toRemove).
// If it does it decrements the bag's charge. It returns the output of
// m_Iv.removeItem(toRemove)

// void nextPage(item bag)--displays the next page of m_IV. It first finds out
// if the page+1 is greater then the number of page's present in the iv, if
// this is the case, it resets page to 1. It then invokes Hero_clearInv(m_hero)
// and for loops and prints the four items found in the page. Any null
// is replaced with an IDBlank() item. It then adds m_next and m_cancel to the
// hero's inventory. All the while in state 74, when it completes it sets
// the hero's state to -2.
//===========================================================================
function Bag_addItem takes item bag,item toAdd returns boolean
    local unit hero=Bag_getHero(bag)
    local string biv=Bag_IV(bag)
    local boolean werkd=IV_addItem(biv,toAdd)
    local integer state=Hero_getState(hero)
    call Hero_setState(hero,74) //prevents drop from firing.
    if(werkd)then
        call UnitRemoveItem(hero,toAdd)
        call SetItemVisible(toAdd,false)
        call SetItemCharges(bag,GetItemCharges(bag)-1)
    endif
    call Hero_setState(hero,state)
    return werkd
endfunction

function Bag_removeItem takes item bag,item toRemove returns boolean
    local boolean b=IV_removeItem(Bag_IV(bag),toRemove)
    local unit hero=Bag_getHero(bag)
    if(b)then
        //call SetItemVisible(toRemove,true)
        call SetItemCharges(bag,GetItemCharges(bag)+1)
    endif
    return b
endfunction

//===========================================================================
// Constructors:
// ============
// CreateBag(item bag,int capacity,unit hero)--
// Makes the bag into a Bag object, call createIV(capacity) and stores
// the output in m_Iv. stores the hero object, and creates the m_next
// m_cancel item.
//
// CreateBagByBT(item bag,unit hero)--
// Uses the bt defined by GetItemTypeId(bag) and uses it to find the
// capacity value to pass to the above constructor.
//===========================================================================
function CreateBag takes item bag, integer capacity,unit hero returns item
    local string this=I2S(H2I(bag))
    local gamecache gc=objects()
    call StoreString(gc,this,"m_IV",CreateIV(capacity))
    call SetItemCharges(bag,capacity)
    call StoreInteger(gc,this,"m_page",0)
    call StoreInteger(gc,this,"m_hero",H2I(hero))
    return bag
endfunction

function CreateBagByBT takes item bag,unit hero returns item
    return CreateBag(bag,BT_getCap(GetItemTypeId(bag)),hero)
endfunction


//===========================================================================
function InitTrig_Bag takes nothing returns nothing
endfunction

[/jass]
回复

使用道具 举报

 楼主| 发表于 2009-3-3 21:45:45 | 显示全部楼层
pick bag
[jass]
function Trig_Bag_Pick_Up_Actions takes nothing returns nothing
    local unit hero=GetManipulatingUnit()
    local item bag=GetManipulatedItem()
    if(IsItemIDBT(GetItemTypeId(bag)))then
        if(Hero_IV(hero)==null)then  
            if(IsUnitHidden(hero) or Pitem_getPuaId(bag)==null)then
                set hero=null
                set bag=null
                return
            else
                call UnitRemoveItem(hero,bag)
                call SimError(GetOwningPlayer(hero),"You need to be a hero to use this item")
                set hero=null
                set bag=null
                return
            endif
        endif
        call SetItemInvulnerable(bag,true)
        if(Bag_IV(bag)==null)then
            call CreateBagByBT(bag,hero)
        else
            call Bag_setHero(bag,hero)
        endif            
    endif
    set hero=null
    set bag=null
endfunction

//===========================================================================
function InitTrig_Bag_Pick_Up takes nothing returns nothing
    set gg_trg_Bag_Pick_Up = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Bag_Pick_Up, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Bag_Pick_Up, function Trig_Bag_Pick_Up_Actions )
endfunction

[/jass]

bag use
[jass]
function Trig_Bag_Use_Actions takes nothing returns nothing
    local unit hero=GetManipulatingUnit()
    local item clicked=GetManipulatedItem()
    local item bag=Hero_getBag(hero)
    if(Hero_IV(hero)==null)then
        set hero=null
        set clicked=null
        set bag=null
        return
    endif
    if(Hero_getState(hero)==0)then
        if(IsItemBT(clicked))then
            call Hero_swapInv(hero)
            call Hero_setState(hero,74)
            call Hero_setBag(hero,clicked)
            call Bag_setPage(clicked,Hero_nextPage(hero,Bag_IV(clicked),Bag_getPage(clicked),false))
            call SetItemCharges(UnitItemInSlot(hero,5),Hero_getFree(hero) )
            call SetItemCharges(clicked,IV_capacity(Bag_IV(clicked))-Vector_size(Bag_IV(clicked)) )
            call Hero_setState(hero,-2)
        endif
    elseif(Hero_getState(hero)==-2)then
        if(clicked==Hero_getCancel(hero))then
            call Hero_setState(hero,74)
            call Bag_setPage(bag,0)
            call Hero_clearInv(hero)
            call Hero_swapInv(hero)
            call Hero_setState(hero,0)
        elseif(clicked==Hero_getNext(hero))then
            call Hero_setState(hero,74)
            call Hero_clearInv(hero)
            call Bag_setPage(bag,Hero_nextPage(hero,Bag_IV(bag),Bag_getPage(bag),false))
            call Hero_setState(hero,-2)
        elseif(IsItemBT(clicked))then
            call SimError(GetOwningPlayer(hero),"You cannot use a container inside a container")
            call SetItemCharges(clicked,IV_capacity(Bag_IV(clicked))-Vector_size(Bag_IV(clicked)) )               
        endif
    endif
    set hero=null
    set clicked=null
    set bag=null
endfunction
//===========================================================================
function InitTrig_Bag_Use takes nothing returns nothing
    set gg_trg_Bag_Use = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Bag_Use, EVENT_PLAYER_UNIT_USE_ITEM )
    call TriggerAddAction( gg_trg_Bag_Use, function Trig_Bag_Use_Actions )
endfunction

[/jass]

Bag order
[jass]
function Trig_Bag_Order_Actions takes nothing returns nothing
    local unit hero=GetOrderedUnit()
    local integer order=GetIssuedOrderId()
    local item dragged=GetOrderTargetItem()
    local integer dropslot=order-852002
    local item drop=UnitItemInSlot(hero,dropslot)
    local item bag=Hero_getBag(hero)
    local integer dragslot=GetItemSlot(hero,dragged)
    if(Hero_IV(hero)==null or (order<852002 or order>852007))then
        set hero=null
        set dragged=null
        set drop=null
        set bag=null
    endif
    if(Hero_getState(hero)==0 and dragged!=drop)then
        if(IsItemBT(drop) and not Bag_addItem(drop,dragged))then
            call Hero_setState(hero,74)
            call SimError(GetOwningPlayer(hero),"This container is full")
            call UnitRemoveItem(hero,dragged)
            call reAddItem(hero,dragged)
            call Hero_setState(hero,0)
        endif
    elseif(Hero_getState(hero)==-2)then
        if(IsItemBT(drop) and drop!=dragged)then
            call Hero_setState(hero,74)
            if(not Bag_addItem(drop,dragged))then
                call SimError(GetOwningPlayer(hero),"This container is full")
                call UnitRemoveItem(hero,dragged)
                call reAddItem(hero,dragged)
            else
                call Bag_removeItem(bag,dragged)
                call Hero_clearInv(hero)
                call Bag_setPage(bag,Hero_nextPage(hero,Bag_IV(bag),Bag_getPage(bag)-1,false))
            endif
            call Hero_setState(hero,-2)
        elseif(drop==dragged)then
            call Hero_setState(hero,74)
            if(not Hero_addToIV(hero,dragged))then
                call SimError(GetOwningPlayer(hero),"You have no more room in your inventory")
                call UnitRemoveItem(hero,dragged)
                call reAddItem(hero,dragged)
            else
                call Bag_removeItem(bag,dragged)
                call Hero_clearInv(hero)
                call Bag_setPage(bag,Hero_nextPage(hero,Bag_IV(bag),Bag_getPage(bag)-1,false))
                call SetItemCharges(UnitItemInSlot(hero,5),Hero_getFree(hero) )
            endif
            call Hero_setState(hero,-2)
        else
            call Vector_swapElems(Bag_IV(bag),4*(Bag_getPage(bag)-1)+dropslot,4*(Bag_getPage(bag)-1)+dragslot)
        endif
    endif
    set hero=null
    set dragged=null
    set drop=null
    set bag=null
endfunction
//===========================================================================
function InitTrig_Bag_Order takes nothing returns nothing
    set gg_trg_Bag_Order = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Bag_Order, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerAddAction( gg_trg_Bag_Order, function Trig_Bag_Order_Actions )
endfunction

[/jass]

bag drop
[jass]
function PaD_child takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local item bag=T_getItem(t)
    local unit hero=Bag_getHero(bag)
    call Hero_clearInv(hero)
    call Hero_setState(hero,74)
    call Bag_setPage(bag,Hero_nextPage(hero,Bag_IV(bag),Bag_getPage(bag)-1,false))
    call Hero_setState(hero,-2)
    call DestroyObject(I2S(H2I(t)))
    call DestroyTimer(t)
    set t=null
    set hero=null
    set bag=null
endfunction


function PageAfterDelay takes item bag returns nothing
    local timer t=CreateTimer()
    call StoreInteger(objects(),I2S(H2I(t)),"m_item",H2I(bag))
    call TimerStart(t,0,false,function PaD_child)
    set t=null
endfunction

function Trig_Bag_Drop_Actions takes nothing returns nothing
    local unit hero=GetManipulatingUnit()
    local item dropped=GetManipulatedItem()
    local item bag=Hero_getBag(hero)
    if(Hero_IV(hero)==null or Hero_getState(hero)==74)then
        return
    endif
    if(Hero_getState(hero)==-2)then
        call Bag_removeItem(bag,dropped)
        call PageAfterDelay(bag)
    endif
endfunction

//===========================================================================
function InitTrig_Bag_Drop takes nothing returns nothing
    set gg_trg_Bag_Drop = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Bag_Drop, EVENT_PLAYER_UNIT_DROP_ITEM )
    call TriggerAddAction( gg_trg_Bag_Drop, function Trig_Bag_Drop_Actions )
endfunction

[/jass]
回复

使用道具 举报

 楼主| 发表于 2009-3-5 21:04:41 | 显示全部楼层
AttributionSys
[jass]
library AttributeSystem initializer Init needs LastOrder

//***************************************************************************
//*                                                                         *
//* Attribute System v5               by: emjlr3                            *
//* &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;               **URL in the works                    *
//* Requires:                                                               *
//* &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;                                                               *
//*                                                                         *
//* - A vJASS Preprocessor                                                  *
//* - LastOrder library by RisingDusk                                       *
//* - The custom items and abilities found in this map                      *
//* - Updated globals in the configuration section                          *
//*                                                                         *
//***************************************************************************

// Configuration Section:
globals
    // Attribute(Attribute System) ability rawcode
    private constant integer Abil = 'A001'
    // Blank item rawcode
    private constant integer Blank = 'I000'
    // Cancel item rawcode
    private constant integer Cancel = 'I001'
    // Number of Stat Points Remaining item rawcode
    private constant integer At = 'I005'
    // Increment Strength item rawcode
    private constant integer Str = 'I004'
    // Increment Agility item rawcode
    private constant integer Agi = 'I002'
    // Increment Intelligence item rawcode
    private constant integer Int = 'I003'

    // Max handles in your map, each 8191 interval decreases speed :(
    private constant integer Max_Handles = 50000
endglobals

//**Do not touch past here unless you pain for death!!**\\\\
private keyword Data
globals
    private trigger Level = CreateTrigger()
    private trigger Inven = CreateTrigger()
    private trigger Att = CreateTrigger()

    private group Enabled = CreateGroup()
    private timer Timer = CreateTimer()
    private unit Hero = null
    private Data array D[Max_Handles]
endglobals
private struct Data
    item array it[6]
    integer points_per_level
    integer last_level
    integer points = 0
    boolean on = false
endstruct

//-- Utilities
// Return bug, data storage
private function H2I takes handle h returns integer
    return h
    return 0
endfunction
private function GetUnitData takes unit u returns Data
    return D[H2I(u)-0x100000]
endfunction
private function SetUnitData takes unit u, Data d returns nothing
    set D[H2I(u)-0x100000] = d
endfunction

// Swap the inventory
private function SwapInv takes unit u returns nothing
    local Data d = GetUnitData(u)
    local integer i
    local item it
   
    if not d.on then
        set i = 0
    else
        set i = 5
    endif

    loop
        set it = UnitRemoveItemFromSlot(u,i)
  
        if d.it!=null then
            call SetItemVisible(d.it,true)
            call SetItemInvulnerable(d.it,false)
            if GetItemTypeId(d.it)==At then // Points remaining item, update charges
                call SetItemCharges(d.it,d.points)
            endif
            call UnitAddItem(u,d.it)
        endif
  
        if it!=null then
            call SetItemVisible(it,false)
            call SetItemInvulnerable(it,true)
        endif
        set d.it = it
        
        if d.on then
            exitwhen i==0
            set i = i - 1
        else
            exitwhen i==5
            set i = i + 1
        endif
    endloop
    set d.on = not d.on  // Swap between in and out of point inventory

    set it = null
endfunction
// Returns what slot the item is in
private function GetItemSlot takes unit hero, item it returns integer
    local integer i = 0
   
    loop
        exitwhen i==6
        if UnitItemInSlot(hero,i)==it then
            return i
        endif
        set i = i + 1
    endloop
   
    return -1
endfunction

//-- Trigger functions
// Universal condition checker
private function Conditions takes nothing returns boolean
    return IsUnitInGroup(GetTriggerUnit(),Enabled)
endfunction
// When the hero levels up
private function Level_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer points
    local Data d = GetUnitData(u)
    local boolean b = not IsLastOrderFinished(u)
   
    set points = ((GetHeroLevel(u)-d.last_level)*d.points_per_level)+d.points
    set d.last_level = GetHeroLevel(u)
    if GetUnitAbilityLevel(u,Abil)<1 and not d.on then // No stat points previously
        call UnitAddAbility(u,Abil)
        call UnitMakeAbilityPermanent(u,true,Abil)
    endif
    if d.on then // In point inventory
        call SetItemCharges(UnitItemInSlot(u,1),points)
    endif
    set d.points = points
    call IssueImmediateOrder(u,"replenishon")
    if b then // If the heroes last order was not complete, re-order it
        call IssueSecondLastOrder(u)
    endif

    set u = null
endfunction

// Unit issued order to view inventory, or player tries to stop our blinking
private function Blink takes nothing returns nothing
    call IssueImmediateOrder(Hero,"replenishon")
    call IssueImmediateOrder(Hero,"replenishlifeoff")
    call PauseTimer(Timer)
endfunction
private function Inven_Actions takes nothing returns nothing
    local unit hero = GetTriggerUnit()
    local integer order = GetIssuedOrderId()
   
    if order==OrderId("replenish") then // Go to selection items
        call UnitRemoveAbility(hero,Abil)
        call SwapInv(hero)
    elseif order==OrderId("replenishoff") then // Player tries to stop blinking
        set Hero = hero
        call TimerStart(Timer,0.0,false,function Blink)
    endif
   
    set hero = null
endfunction

// Correct path based on the selected item
private function Att_Actions takes nothing returns nothing
    local unit hero = GetManipulatingUnit()
    local item used = GetManipulatedItem()
    local Data d = GetUnitData(hero)
    local integer array temp
   
    if not d.on then // Not in point inventory, some in game item was used
        set hero = null
        set used = null
        return
    endif

    set temp[0] = GetItemSlot(hero,used)
    set temp[1] = d.points-1
    if temp[0]!=5 then // Not cancel
        call ModifyHeroStat( temp[0]/2,hero,bj_MODIFYMETHOD_ADD,1)
        set d.points = temp[1]
        if temp[1]<=0 then // No more points left
            call SwapInv(hero)
        else
            call SetItemCharges(UnitItemInSlot(hero,1),temp[1]) // Positive points remaining
        endif
    else // Cancel
        call SwapInv(hero)
        call UnitAddAbility(hero,Abil)
        call UnitMakeAbilityPermanent(hero,true,Abil)
        call IssueImmediateOrder(hero,"replenishon") // Re-add and flash points indicator
    endif
   
    set hero = null
    set used = null
endfunction

//-- User functions
// Change stat gain for given hero
public function UpdatePointsGain takes unit u, integer i returns nothing
    local Data d = GetUnitData(u)

    if i<=0 then
        set i = 1
    endif
    set d.points_per_level = i
endfunction
// Change current points for given hero
public function SetCurrentPoints takes unit u, integer i returns nothing
    local Data d = GetUnitData(u)

    if i<0 then
        set i = 0
    endif
    set d.points = i
    if d.on then
        call SetItemCharges(UnitItemInSlot(u,1),d.points)
    endif
    if i==0 then
        call SwapInv(u)
    endif
endfunction
// Disable the system for the given hero
public function UnRegister takes unit u returns boolean
    local Data d
    local integer i = 0

    // Not enabled or dead check
    if not IsUnitInGroup(u,Enabled) then
        call BJDebugMsg("AttributeSystem_UnRegister Error: "+GetUnitName(u)+" has not previously been registered.")
        return false
    elseif GetWidgetLife(u)<.405 then
        call BJDebugMsg("AttributeSystem_UnRegister Error: "+GetUnitName(u)+" is currently dead and cannot be unregistered.")
        return false
    endif

    set d = GetUnitData(u)
    if d.on then
        call SwapInv(u)
    endif
    loop
        exitwhen i>5
        call SetItemInvulnerable(d.it,false)
        call SetWidgetLife(d.it,0.)
        set i = i + 1
    endloop
    call UnitRemoveAbility(u,Abil)
    call d.destroy()
    call SetUnitData(u,0)
    call GroupRemoveUnit(Enabled,u)

    return true
endfunction
// Enable the system for the given hero
public function Register takes unit u, integer i returns boolean
    local Data d

    // Already enabled check
    if IsUnitInGroup(u,Enabled) then
        call BJDebugMsg("AttributeSystem_Register Error: "+GetUnitName(u)+" has already been registered.")
        return false
    endif
    call GroupAddUnit(Enabled,u)

    // Setup items and struct
    set d = Data.create()
    if i<=0 then
        set i = 1
    endif
    set d.points_per_level = i
    set d.last_level = GetHeroLevel(u)
    set d.it[0] = CreateItem(Str,0,0)
    call SetItemVisible(d.it[0],false)   
    call SetItemInvulnerable(d.it[0],true)
    set d.it[1] = CreateItem(At,0,0)
    call SetItemVisible(d.it[1],false)  
    call SetItemInvulnerable(d.it[1],true)
    set d.it[2] = CreateItem(Agi,0,0)
    call SetItemVisible(d.it[2],false)  
    call SetItemInvulnerable(d.it[2],true)
    set d.it[3] = CreateItem(Blank,0,0)
    call SetItemVisible(d.it[3],false)   
    call SetItemInvulnerable(d.it[3],true)
    set d.it[4] = CreateItem(Int,0,0)
    call SetItemVisible(d.it[4],false)  
    call SetItemInvulnerable(d.it[4],true)
    set d.it[5] = CreateItem(Cancel,0,0)
    call SetItemVisible(d.it[5],false)
    call SetItemDroppable(d.it[5],false)
    call SetItemInvulnerable(d.it[5],true)
    // Store struct to unit
    call SetUnitData(u,d)

    return true
endfunction

//===========================================================================
private function Init takes nothing returns nothing   
    call TriggerAddAction( Level, function Level_Actions )
    call TriggerAddCondition(Level,Condition(function Conditions))
    call TriggerRegisterAnyUnitEventBJ( Level, EVENT_PLAYER_HERO_LEVEL )   
    call TriggerAddAction( Inven, function Inven_Actions )
    call TriggerAddCondition(Inven,Condition(function Conditions))
    call TriggerRegisterAnyUnitEventBJ( Inven, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerRegisterAnyUnitEventBJ( Inven, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerRegisterAnyUnitEventBJ( Inven, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )  
    call TriggerAddAction( Att, function Att_Actions )
    call TriggerAddCondition(Att,Condition(function Conditions))
    call TriggerRegisterAnyUnitEventBJ( Att, EVENT_PLAYER_UNIT_USE_ITEM )
endfunction  

endlibrary
[/jass]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

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

GMT+8, 2024-11-24 17:33 , Processed in 0.059452 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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