Worldedit
  Worldedit
Le site sur l'éditeur de warcraft 3 !
 
  FAQFAQ   RechercherRechercher   Liste des MembresListe des Membres    Groupes d'utilisateursGroupes d'utilisateurs   medals.php?sid=c35a542b56c4c5c73dc4c8a8534563f0Médailles   S'enregistrerS'enregistrer 
 ProfilProfil   Se connecter pour vérifier ses messages privésSe connecter pour vérifier ses messages privés   ConnexionConnexion 
  FAQFAQ World Editor   UploadUploader une map ou une image    UploadAjouter sa map à l'annuaire   UploadConsulter l'annuaire

Library: SpellEvent

 
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Aide sur les déclencheurs
Voir le sujet précédent :: Voir le sujet suivant  
Auteur Message
 jk2pach
Invité








MessagePosté le: 18/03/10 19:04    Sujet du message: Library: SpellEvent Citer

Nécessite:

AutoIndex
UnitListModule

Jass:
library SpellEvent requires AutoIndex,UnitListModule

private function interface FunctionInterface takes nothing returns nothing

globals
    private keyword s_spell
    s_spell SpellEvent = 0
    key SPELL_CHANNEL
    key SPELL_CAST
    key SPELL_EFFECT
    key SPELL_FINISH // if the unit had succesfully finished the spell
    key SPELL_ENDCAST // if the unit abort the spell before the end
endglobals

globals
    private hashtable HashT
    private timer Tim
    private integer Index = 0
    private FunctionInterface Func = 0
    private s_spell array S
endglobals

private module m_init
    static method onInit takes nothing returns nothing
        local trigger trig
        //! runtextmacro t_CreateSpellsTriggers("OnChannel","CHANNEL")
        //! runtextmacro t_CreateSpellsTriggers("OnCast","CAST")
        //! runtextmacro t_CreateSpellsTriggers("OnEffect","EFFECT")
        //! runtextmacro t_CreateSpellsTriggers("OnFinish","FINISH")
        //! runtextmacro t_CreateSpellsTriggers("OnEndCast","ENDCAST")
        set Tim = CreateTimer()
        set HashT = InitHashtable()
    endmethod
endmodule

function RegisterSpellEvent takes integer whichEvent, integer whichSpell, FunctionInterface whichFunc returns nothing
    call SaveInteger(HashT,whichEvent,whichSpell,integer(whichFunc))
endfunction
   
function RegisterSpellChannelResponse takes integer spellId, FunctionInterface whichFunc returns nothing
    call SaveInteger(HashT,SPELL_CHANNEL,spellId,integer(whichFunc))
endfunction

function RegisterSpellCastResponse takes integer spellId, FunctionInterface whichFunc returns nothing
    call SaveInteger(HashT,SPELL_CAST,spellId,integer(whichFunc))
endfunction

function RegisterSpellEffectResponse takes integer spellId, FunctionInterface whichFunc returns nothing
    call SaveInteger(HashT,SPELL_EFFECT,spellId,integer(whichFunc))
endfunction

function RegisterSpellFinishResponse takes integer spellId, FunctionInterface whichFunc returns nothing
    call SaveInteger(HashT,SPELL_FINISH,spellId,integer(whichFunc))
endfunction

function RegisterSpellEndCastResponse takes integer spellId, FunctionInterface whichFunc returns nothing
    call SaveInteger(HashT,SPELL_ENDCAST,spellId,integer(whichFunc))
endfunction

private struct s_spell
   
    integer AbilityId = 0
    unit CastingUnit = null
    unit TargetUnit = null
    item TargetItem = null
    destructable TargetDestructable = null
    real TargetX = 0.
    real TargetY = 0.
    boolean IsTargetPoint = false
    boolean IsTargetUnit = false
    boolean IsTargetItem = false
    boolean IsTargetDestructable = false
    boolean IsNoTarget = false
    integer TargetUnitTypeId = 0
    integer TargetDestructableTypeId = 0
    integer TargetItemTypeId = 0
    boolean CastFinished = false
   
    private method destroy takes nothing returns nothing
        call .unitListRemove.evaluate()
        set .CastFinished = false
    endmethod
   
    implement UnitList
   
    private static method create takes nothing returns thistype
        local thistype this = .allocate()
       
        set .CastingUnit = GetSpellAbilityUnit()
        set .TargetUnit = GetSpellTargetUnit()
        set .AbilityId = GetSpellAbilityId()
       
        if .TargetUnit != null then
            set .IsTargetUnit = true
            set .TargetUnitTypeId = GetUnitTypeId(.TargetUnit)
            set .TargetX = GetUnitX(.TargetUnit)
            set .TargetY = GetUnitY(.TargetUnit)
           
        else
            set .TargetDestructable = GetSpellTargetDestructable()
               
            if .TargetDestructable != null then
                set .IsTargetDestructable = true
                set .TargetDestructableTypeId = GetDestructableTypeId(.TargetDestructable)
                set .TargetX = GetDestructableX(.TargetDestructable)
                set .TargetY = GetDestructableY(.TargetDestructable)
            else
                set .TargetItem = GetSpellTargetItem()
               
                if .TargetItem != null then
                    set .IsTargetItem = true
                    set .TargetItemTypeId = GetItemTypeId(.TargetItem)
                    set .TargetX = GetItemX(.TargetItem)
                    set .TargetY = GetItemY(.TargetItem)
                else
                    set .IsNoTarget = true
                    set .TargetX = GetSpellTargetX()
                    set .TargetY = GetSpellTargetY()
                endif
               
            endif
           
        endif

        call .unitListAdd(.CastingUnit)
        return this
    endmethod
   
    private static method DestroyInstances takes nothing returns nothing
        loop
        exitwhen Index == 0
            set Index = Index-1
            call S[Index].destroy()
        endloop
    endmethod
   
    private static method OnChannel takes nothing returns boolean
        set SpellEvent = s_spell.create()
        //! runtextmacro t_FindSpellFunctionInterface("CHANNEL")
        return false
    endmethod
   
    private static method OnCast takes nothing returns boolean
        //! runtextmacro t_FindWhichSpell()
        //! runtextmacro t_FindSpellFunctionInterface("CAST")
        return false
    endmethod
   
    private static method OnEffect takes nothing returns boolean
        //! runtextmacro t_FindWhichSpell()
        //! runtextmacro t_FindSpellFunctionInterface("EFFECT")
        return false
    endmethod

    private static method OnFinish takes nothing returns boolean
        //! runtextmacro t_FindWhichSpell()
        set SpellEvent.CastFinished = true
        //! runtextmacro t_FindSpellFunctionInterface("FINISH")
        return false
    endmethod

    private static method OnEndCast takes nothing returns boolean
        //! runtextmacro t_FindWhichSpell()
        //! runtextmacro t_FindSpellFunctionInterface("ENDCAST")
        set S[Index] = SpellEvent
        set Index = Index+1
        call TimerStart(Tim,0.,false,function thistype.DestroyInstances)
        return false
    endmethod
   
    implement m_init
endstruct

//! textmacro t_FindWhichSpell
    set SpellEvent = s_spell.unitFirst(GetSpellAbilityUnit())
    loop
    exitwhen SpellEvent.AbilityId == GetSpellAbilityId()
        set SpellEvent = SpellEvent.unitNext
    endloop
//! endtextmacro

//! textmacro t_CreateSpellsTriggers takes NAME , EVENT
    set trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_$EVENT$)
    call TriggerAddCondition(trig,function s_spell.$NAME$)
//! endtextmacro

//! textmacro t_FindSpellFunctionInterface takes EVENT
    set Func = FunctionInterface(LoadInteger(HashT,SPELL_$EVENT$,SpellEvent.AbilityId))
    if Func != 0 then
        call Func.execute()
    endif
//! endtextmacro

endlibrary

_________________
Revenir en haut
Montrer les messages depuis:   
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Aide sur les déclencheurs Toutes les heures sont au format GMT + 1 Heure
Page 1 sur 1
La question posée dans ce topic a été résolue !

 
Sauter vers:  
Vous ne pouvez pas poster de nouveaux sujets dans ce forum
Vous ne pouvez pas répondre aux sujets dans ce forum
Vous ne pouvez pas éditer vos messages dans ce forum
Vous ne pouvez pas supprimer vos messages dans ce forum
Vous ne pouvez pas voter dans les sondages de ce forum


Powered by phpBB © 2001, 2005 phpBB Group
Traduction par : phpBB-fr.com