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=c2ab0ddceeca09caf2e0f4265461a026Mé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

[vJass] Buff

 
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Fonction Jass
Voir le sujet précédent :: Voir le sujet suivant  
Auteur Message
 Sapeur-Goblin
Floodeur prématuré


Inscrit le: 14 Oct 2009
Messages: 719
Sujets: 40
Spécialité en worldedit: Les bugs
Médailles: 1 (En savoir plus...)
Créateur d'unité (Quantité : 1)

MessagePosté le: 02/06/12 17:58    Sujet du message: [vJass] Buff Citer

Nom de la fonction : Buff
Créateur : Sapeur-Goblin
Fonctions requises : UnitIndexer et TimerUtils et optionnellement DamageEvent
Code :
Secret:

Jass:
library Buff /*
*************************************************************************************
*
*   Permet un développement rapide et efficace de buffs.
*
*************************************************************************************
*
*   */ uses /*
*
*       -   */ UnitIndexer /*
*       -   */ TimerUtils /*
*       -   */ optional DamageEvent /*
*
*************************************************************************************
*
*   La création de buff commence par la définition d'un type de buff, ce faisant
*   dans une structure à laquelle il faut implémenter le module BuffStruct, extendant
*   array de préférence pour éviter une surcharge de code inutile :
*
*   struct BuffTypeA extends array
*
*       implement BuffStruct
*
*   endstruct
*
*   Ensuite, il est possible de défnir les différentes configurations pour le type de
*   buff en incluant des membres statiques. Tous sont optionnels (la valeur indiquée
*   ci-dessous est la valeur par défaut) :
*       -   static boolean stackable = false
*               •   Lorsqu'un buff non stackable est appliqué à une unité bénéficiant
*                   déjà de ce type de buff, l'ancien buff est rafraîchi.
*               •   Voir la réponse d'événement onRefresh pour plus d'informations.
*       -   static boolean permanent = false
*               •   Les buffs permanents ne peuvent pas être dissipés.
*               •   Voir la section Dispel pour plus d'informations.
*       -   static integer dispellPriority = -1
*               •   Voir la section Dispel pour plus d'informations
*       -   static integer auraId = 0
*               •   Permet d'afficher le buff dans la barre d'état de l'unité.
*               •   Pour cela, créer un sort basé sur aura de lenteur, et réfler les
*                   cibles sur personnel.
*               •   Ajouter ensuite le buff conrrespondant.
*       -   static integer buffId = 0
*               •   Il s'agit du buff ajouté par l'aura de lenteur.
*       -   static integer alignment = BUFF_ALIGNMENT_NEUTRAL
*               •   Alignement du buff. Il en existe trois types :
*               •   BUFF_ALIGNMENT_POSITIVE
*               •   BUFF_ALIGNMENT_NEGATIVE
*               •   BUFF_ALIGNMENT_NEUTRAL
*       -   static boolean positiveBuffImmune = false
*               •   Immunise l'unité contre les buffs positifs.
*       -   static boolean negativeBuffImmune = false
*               •   Immunise l'unité contre les buffs négatifs.
*       -   static boolean neutralBuffImmune = false
*               •   Immunise l'unité contre les buffs neutres.
*       -   static boolean positiveDispelImmune = false
*               •   Immunise l'unité contre les dissipations de buffs positifs.
*       -   static boolean negativeDispelImmune = false
*               •   Immunise l'unité contre les dissipations de buffs négatifs.
*       -   static boolean neutralDispelImmune = false
*               •   Immunise l'unité contre les dissipations de buffs neutres.
*       -   static boolean keepAtDeath = false
*               •   L'unité garde le buff lorsquelle meurt.
*       -   static real period
*               •   Période pour les réponses d'événement périodiques.
*       -   static integer damagePriority = 0
*               •   Priorité de l'appel de la méthode onDamage.
*       -   static integer category = 0
*               •   A utiliser comme vous le souhaitez.
*
*   Une fois ces paramètres définis, il est possible d'ajouter des réponses d'événement.
*   Il existe huit réponses, toutes optionnelles :
*       -   static method onApply takes Buff this returns nothing
*               •   Appelée lors de l'application du buff.
*       -   static method onPeriodic takes Buff this returns nothing
*               •   Méthode appelée périodiquement.
*               •   Il est nécessaire d'ajouter un paramètre period.
*
*       -   static method onRefresh takes Buff this returns nothing
*               •   Appelée lorsque le buff est rafraîchi.
*               •   Pour accéder aux paramètres de l'ancien buff, utiliser :
*                       •   previousDuration
*                       •   previousCaster
*                       •   previousLevel
*
*       -   static method onDispel takes Buff this, unit dispeler, boolean b returns nothing
*               •   Appelée lorsqu'une tentative de dissipation du buff a lieu.
*               •   L'argument unité correspond à l'unité essayant de dissiper le buff.
*               •   L'argument boolean vaut true si la disspation a réussie (le buff sera alors
*                   détruit), false sinon.
*               •   Voir la sections Dispel pour plus d'informations.
*
*       -   static method onExpire takes Buff this returns nothing
*               •   Appelée lorsque le buff expire (la durée est nulle).
*               •   Il est possible de redéfinir la durée pour que le buff ne soit pas détruit.
*
*       -   static method onDeath takes Buff this returns nothing
*               •   Appelée lorsque le trajet du buff meurt.
*
*       -   static method onRemove takes Buff this returns nothing
*               •   Appelée lorsque le buff est détruit.
*               •   Redéfinir la durée ou le rafraîchir n'empêchera pas sa déstruction.
*
*       -   static method onDamage takes Buff this returns nothing
*               •   Appelée lorsque le trajet du buff subit des dégâts.
*               •   Ne peut être utilisé qu'avec la bibliothèque DamageEvent.
*
*   La structure possède aussi une méthode apply permettant d'appliquer le type de buff et
*   type, renvoyant le type de buff.
*
*************************************************************************************
*
*   struct Buff extends array
*
*       -   readonly unit caster (utiliser refresh pour modifier ce paramètre)
*       -   readonly unit target
*       -   readonly integer targetId
*       -   readonly real level (utiliser refresh pour modifier ce paramètre)
*       -   public real duration (method operator)
*       -   public real initialDuration (method operator)
*       -   static method apply takes BuffType buffType, unit caster, unit target, real level,
*           real duration returns thistype
*               •   Si la durée est nulle, le buff n'expirera jamais.
*       -   method destroy takes nothing returns nothing
*               •   Préferer utiliser les dissipations de buff que cette méthode.
*       -   method refresh takes unit caster, real level, real duration returns thistype
*               •   Rafraîchit le buff avec les nouveaux paramètres.
*               •   Un buff peut être rafraîchit même si l'unité est immunisée contre
*                   l'application du type de buff correspondant.
*       -   static method has takes unit target, BuffType buffType returns boolean
*       -   static method count takes unit target returns integer
*       -   static method countType takes unit target, BuffType buffType returns integer
*       -   static method countAlignment takes unit target, integer alignment returns integer
*       -   static method immune takes unit target, integer alignment returns boolean
*               -   Renvoie true si l'unité est immunisée aux buffs de l'alignement spécifié.
*       -   static method dispelImmune takes unit target, integer alignment returns boolean
*               -   Renvoie true si l'unité est immunisée aux dispels de l'alignement spécifié.
*
*
*************************************************************************************
*
*   Dispel
*   ------
*
*   -   method dispel takes unit dispeler, integer priority returns boolean
*           •   Le buff en question sera dissipé si la priorité du dispel est supérieure
*               strictement à la priorité de dissipation du buff.
*
*   -   static method dispelAlignment takes unit dispeler, unit target, integer priority, integer alignment returns integer
*           •   Applique une dissipation sur tous les buffs de l'alignement spécifié sur la cible.
*
*   -   static method dispelAll takes unit dispeler, unit target, integer priority returns integer
*           •   Applique une dissipation sur tous les buffs de la cible.
*
*   Les buffs permanents ne peuvent pas être dissipés, mais peuvent être détruits par l'intermédiaire de
*   la méthode destroy().
*
*   Manipuler les buffs d'une unité
*   -------------------------------
*
*   Les buffs d'une unité sont classés pour permettre des énumérations efficaces.
*   Chaque buff possède les membres next et prev, permettant d'accéder aux buffs
*   suivants et précédents :
*       A1 A2 A3 C1 C2    B1 B2 B3 D1 D2    E1 E2 E3 E4 E5
*       -------------- -> -------------- -> --------------
*       Buffs positifs    Buffs négatifs    Buffs neutres
*
*   Il existe trois manières d'accéder aux buffs d'une unité :
*       -   local Buff this = Buff[unit]
*               •   Renvoie le premier buff d'une unité.
*               •   loop
*                       exitwhen this == 0
*                       set this = this.next
*                   endloop
*       -   local Buff this = Buff[unit][type]
*               •   Renvoie le premier buff d'une unité du type spécifié.
*               •   loop
*                       exitwhen this.type != monType
*                       set this = this.next
*                   endloop
*       -   local Buff this = Buff[unit][alignment]
*               •   Renvoie le premier buff d'une unité de l'alignement spécifié.
*               •   loop
*                       exitwhen this.type.alignment != monAlignement
*                       set this = this.next
*                   endloop
*
*************************************************************************************/

globals

    key BUFF_ALIGNMENT_POSITIVE
    key BUFF_ALIGNMENT_NEGATIVE
    key BUFF_ALIGNMENT_NEUTRAL

endglobals

globals

    private constant integer applyEvent = 0
    private constant integer refreshEvent = 1
    private constant integer dispelEvent = 2
    private constant integer removeEvent = 3
    private constant integer expireEvent = 4
    private constant integer deathEvent = 5

    private boolean eventBool
    private integer triggerBuff
    private boolexpr array buffEvent
    private integer eventType
    private trigger eventTrig = CreateTrigger()

endglobals

globals

    private real array buffTypePeriod
    private boolean array buffTypeStackable
    private integer array buffTypeAuraId
    private integer array buffTypeBuffId
    private integer array buffTypeAlignment
    private integer array buffTypeDispelPriority
    private boolean array buffTypePermanent
    private boolean array buffTypePositiveBuffImmune
    private boolean array buffTypeNegativeBuffImmune
    private boolean array buffTypeNeutralBuffImmune
    private boolean array buffTypePositiveDispelImmune
    private boolean array buffTypeNegativeDispelImmune
    private boolean array buffTypeNeutralDispelImmune
    private boolean array buffTypeKeepAtDeath
   
    private boolean array buffTypeHasApplyEvent
    private boolean array buffTypeHasDeathEvent
    private boolean array buffTypeHasRemoveEvent
    private boolean array buffTypeHasDispelEvent
    private boolean array buffTypeHasExpireEvent
    private boolean array buffTypeHasRefreshEvent
   
    private integer array buffTypeCategory
   
endglobals

struct BuffType extends array

    method operator stackable takes nothing returns boolean
        return buffTypeStackable[this]
    endmethod

    method operator period takes nothing returns real
        return buffTypePeriod[this]
    endmethod

    method operator auraId takes nothing returns integer
        return buffTypeAuraId[this]
    endmethod
   
    method operator buffId takes nothing returns integer
        return buffTypeBuffId[this]
    endmethod

    method operator alignment takes nothing returns integer
        return buffTypeAlignment[this]
    endmethod

    method operator dispelPriority takes nothing returns integer
        return buffTypeDispelPriority[this]
    endmethod

    method operator permanent takes nothing returns boolean
        return buffTypePermanent[this]
    endmethod

    method operator positiveBuffImmune takes nothing returns boolean
        return buffTypePositiveBuffImmune[this]
    endmethod

    method operator negativeBuffImmune takes nothing returns boolean
        return buffTypeNegativeBuffImmune[this]
    endmethod

    method operator neutralBuffImmune takes nothing returns boolean
        return buffTypeNeutralBuffImmune[this]
    endmethod

    method operator positiveDispelImmune takes nothing returns boolean
        return buffTypePositiveDispelImmune[this]
    endmethod

    method operator negativeDispelImmune takes nothing returns boolean
        return buffTypeNegativeDispelImmune[this]
    endmethod

    method operator neutralDispelImmune takes nothing returns boolean
        return buffTypeNeutralDispelImmune[this]
    endmethod

    method operator keepAtDeath takes nothing returns boolean
        return buffTypeKeepAtDeath[this]
    endmethod

    method operator hasApplyEvent takes nothing returns boolean
        return buffTypeHasApplyEvent[this]
    endmethod
   
    method operator hasDeathEvent takes nothing returns boolean
        return buffTypeHasDeathEvent[this]
    endmethod

    method operator hasRemoveEvent takes nothing returns boolean
        return buffTypeHasRemoveEvent[this]
    endmethod
   
    method operator hasDispelEvent takes nothing returns boolean
        return buffTypeHasDispelEvent[this]
    endmethod
   
    method operator hasExpireEvent takes nothing returns boolean
        return buffTypeHasExpireEvent[this]
    endmethod

    method operator hasRefreshEvent takes nothing returns boolean
        return buffTypeHasRefreshEvent[this]
    endmethod

    method operator category takes nothing returns integer
        return buffTypeCategory[this]
    endmethod

endstruct

globals
    // Periodic timer for onPeriodic method.
    private timer array periodicTim

endglobals

private module Init

    private static method onInit takes nothing returns nothing
        local trigger death = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(death, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddCondition(death, Filter(function thistype.onDeath))
        call UnitIndexer.DEINDEX.register(Filter(function thistype.onDeindex))
    endmethod

endmodule

struct Buff extends array

    readonly static real previousLevel = 0
    readonly static unit previousCaster = null
    readonly static real previousDuration = 0

    private static integer array buffCount
    private static thistype array firstBuff

    private static hashtable table = InitHashtable()
    private static integer instanceCount = 0
   
    private thistype recycle
    readonly thistype prev
    readonly thistype next

    readonly real level
    readonly unit caster

    readonly integer targetId
    readonly BuffType buffType
   
    private timer tim

    method operator target takes nothing returns unit
        return GetUnitById(targetId)
    endmethod

    method operator initialDuration takes nothing returns real
        return TimerGetTimeout(tim)
    endmethod

    method operator duration takes nothing returns real
        return TimerGetRemaining(tim)
    endmethod

    method operator duration= takes real dur returns nothing
        if (dur > 0) then
            if (tim == null) then
                set tim = NewTimerEx(this)
            endif
            call TimerStart(tim, dur, false, function thistype.expire)
        else
            if (tim != null) then
                call ReleaseTimer(tim)
                set tim = null
            endif
        endif
    endmethod

    static method has takes unit targ, integer id returns boolean
        return HaveSavedInteger(table, GetUnitUserData(targ), id)
    endmethod

    static method count takes unit target returns integer
        return buffCount[GetUnitUserData(target)]
    endmethod

    static method countType takes unit target, integer id returns integer
        return LoadInteger(table, GetUnitUserData(target), -id)
    endmethod

    static method countAlignment takes unit target, integer align returns integer
        return LoadInteger(table, GetUnitUserData(target), -align)
    endmethod

    static method operator [] takes unit targ returns thistype
        return firstBuff[GetUnitUserData(targ)]
    endmethod

    method operator [] takes integer id returns thistype
        return LoadInteger(table, GetUnitUserData(target), id)
    endmethod

    static method immune takes unit targ, integer align returns boolean
        return LoadInteger(table, -GetUnitUserData(targ), align) > 0
    endmethod
   
    static method immuneById takes integer targetId, integer align returns boolean
        return LoadInteger(table, -targetId, align) > 0
    endmethod

    static method dispelImmune takes unit targ, integer align returns boolean
        return LoadInteger(table, -GetUnitUserData(targ), -align) > 0
    endmethod

    static method dispelImmuneById takes integer targetId, integer align returns boolean
        return LoadInteger(table, -targetId, -align) > 0
    endmethod

    // Methods for more readability
    //******************************************************************************************
   
    private static method increaseImmuneCount takes integer targetId, integer alignment returns nothing
        call SaveInteger(table, -targetId, alignment, LoadInteger(table, -targetId, alignment) + 1)
    endmethod
   
    private static method decreaseImmuneCount takes integer targetId, integer alignment returns nothing
        call SaveInteger(table, -targetId, alignment, LoadInteger(table, -targetId, alignment) - 1)
    endmethod

    private static method increaseDispelImmuneCount takes integer targetId, integer alignment returns nothing
        call SaveInteger(table, -targetId, -alignment, LoadInteger(table, -targetId, -alignment) + 1)
    endmethod
   
    private static method decreaseDispelImmuneCount takes integer targetId, integer alignment returns nothing
        call SaveInteger(table, -targetId, -alignment, LoadInteger(table, -targetId, -alignment) - 1)
    endmethod
   
    private static method increaseCount takes integer targetId, integer id returns nothing
        call SaveInteger(table, targetId, -id, LoadInteger(table, targetId, -id) + 1)
    endmethod
   
    private static method decreaseCount takes integer targetId, integer id returns nothing
        call SaveInteger(table, targetId, -id, LoadInteger(table, targetId, -id) - 1)
    endmethod

    private static method first takes integer targetId, integer id returns thistype
        return LoadInteger(table, targetId, id)
    endmethod

    private static method setFirst takes integer targetId, integer id, integer this returns nothing
        call SaveInteger(table, targetId, id, this)
    endmethod

    private static method removeCount takes integer targetId, integer id returns nothing
        call RemoveSavedInteger(table, targetId, -id)
    endmethod

    private static method removeFirst takes integer targetId, integer id returns nothing
        call RemoveSavedInteger(table, targetId, id)
    endmethod

    //********************************************************************************************

    private method fireEvent takes integer whichEvent returns nothing
        set eventType = whichEvent
        set triggerBuff = this
        call TriggerClearConditions(eventTrig)
        call TriggerAddCondition(eventTrig, buffEvent[buffType])
        call TriggerEvaluate(eventTrig)
    endmethod

    method destroy takes nothing returns nothing
        local thistype previous = first(targetId, buffType)

        if (buffType.hasRemoveEvent) then
            call fireEvent(removeEvent)
        endif

        set buffCount[targetId] = buffCount[targetId] - 1
        call decreaseCount(targetId, buffType)
        call decreaseCount(targetId, buffType.alignment)

        if (buffType.positiveBuffImmune) then
            call decreaseImmuneCount(targetId, BUFF_ALIGNMENT_POSITIVE)
        endif
        if (buffType.negativeBuffImmune) then
            call decreaseImmuneCount(targetId, BUFF_ALIGNMENT_NEGATIVE)
        endif
        if (buffType.neutralBuffImmune) then
            call decreaseImmuneCount(targetId, BUFF_ALIGNMENT_NEUTRAL)
        endif
        if (buffType.positiveDispelImmune) then
            call decreaseDispelImmuneCount(targetId, BUFF_ALIGNMENT_POSITIVE)
        endif
        if (buffType.negativeDispelImmune) then
            call decreaseDispelImmuneCount(targetId, BUFF_ALIGNMENT_NEGATIVE)
        endif
        if (buffType.neutralDispelImmune) then
            call decreaseDispelImmuneCount(targetId, BUFF_ALIGNMENT_NEUTRAL)
        endif

        if (this == previous) then
            if (buffType != next.buffType) then
                call removeFirst(targetId, buffType)
                call removeCount(targetId, buffType)
                call UnitRemoveAbility(target, buffType.auraId)
                call UnitRemoveAbility(target, buffType.buffId)
            else
                call setFirst(targetId, buffType, next)
            endif
            set previous = first(targetId, buffType.alignment)
            if (this == previous) then
                if (buffType.alignment != next.buffType.alignment) then
                    call removeFirst(targetId, buffType.alignment)
                    call removeCount(targetId, buffType.alignment)
                else
                    call setFirst(targetId, buffType.alignment, next)
                endif
            endif
        endif
        if (prev == 0) then
            set firstBuff[targetId] = next
        else
            set prev.next = next
        endif
        set next.prev = prev     

        set caster = null
        call ReleaseTimer(tim)
        set tim = null
        call ReleaseTimer(periodicTim[this])
        set periodicTim[this] = null

        set recycle = thistype(0).recycle
        set thistype(0).recycle = this
    endmethod

    method dispel takes unit cast, integer priority returns boolean
        set eventBool = priority > buffType.dispelPriority and not buffType.permanent and not dispelImmuneById(targetId, buffType.alignment)
        if (buffType.hasDispelEvent) then
            set thistype(0).caster = cast
            call fireEvent(dispelEvent)
        endif
        if (eventBool) then
            call destroy()
        endif
        return eventBool
    endmethod

    static method dispelAlignment takes unit cast, unit targ, integer priority, integer align returns integer
        local thistype this = thistype[targ][align]
        local integer c = 0
        loop
            exitwhen (buffType.alignment != align)
            set eventBool = priority > buffType.dispelPriority and not buffType.permanent and not dispelImmuneById(targetId, align)
            if (buffType.hasDispelEvent) then
                set thistype(0).caster = cast
                call fireEvent(dispelEvent)
            endif
            if (eventBool) then
                set c = c + 1
                call destroy()
            endif
            set this = next
        endloop
        return c
    endmethod

    static method dispelAll takes unit cast, unit targ, integer priority returns integer
        return dispelAlignment(cast, targ, priority, BUFF_ALIGNMENT_POSITIVE) + /*
        */     dispelAlignment(cast, targ, priority, BUFF_ALIGNMENT_NEGATIVE) + /*
        */     dispelAlignment(cast, targ, priority, BUFF_ALIGNMENT_NEUTRAL)
    endmethod

    private static method expire takes nothing returns nothing
        local thistype this = GetTimerData(GetExpiredTimer())
        if (buffType.hasExpireEvent) then
            call fireEvent(expireEvent)
        endif
        if (tim != null and duration == 0) then
            call destroy()
        endif
    endmethod

    method refresh takes unit cast, real lev, real dur returns thistype
        local real plev = previousLevel
        local real pdur = previousDuration
        local unit pcas = previousCaster
        set previousLevel = level
        set previousDuration = duration
        set previousCaster = caster
        set caster = cast
        set level = lev
        set duration = dur
        if (buffType.hasRefreshEvent) then
            call fireEvent(refreshEvent)
        endif
        set previousLevel = plev
        set previousDuration = pdur
        set previousCaster = pcas
        return this
    endmethod

    static method apply takes BuffType buffType, unit cast, unit targ, real lev, real duration returns thistype
        local thistype this
        local thistype previous
        local thistype align
        local integer targId = GetUnitUserData(targ)
        if (targId == 0 or immuneById(targId, buffType.alignment)) then
            return 0
        endif
        set previous = LoadInteger(table, targId, buffType)
        if (not buffType.stackable and previous != 0) then
            return previous.refresh(cast, lev, duration)
        else
            if (thistype(0).recycle != 0) then
                set this = thistype(0).recycle
                set thistype(0).recycle = recycle
            else
                set instanceCount = instanceCount + 1
                set this = instanceCount
            endif       
           
            set align = first(targId, buffType.alignment)
            if (previous == 0) then
                if (align == 0) then
                    set previous = firstBuff[targId]
                else
                    set previous = align
                endif
                call UnitAddAbility(targ, buffType.auraId)
                call SetUnitAbilityLevel(targ, buffType.auraId, R2I(lev))
                call UnitMakeAbilityPermanent(targ, true, buffType.auraId)
            endif

            if (previous == firstBuff[targId]) then
                set firstBuff[targId] = this
                call setFirst(targId, buffType.alignment, this)
            elseif (previous == align) then
                call setFirst(targId, buffType.alignment, this)
            endif

            call setFirst(targId, buffType, this)
           
            set prev = previous.prev
            set next = previous
            set prev.next = this
            set next.prev = this           

            call increaseCount(targId, buffType)
            call increaseCount(targId, buffType.alignment)
            set buffCount[targId] = buffCount[targId] + 1

            if (buffType.positiveBuffImmune) then
                call increaseImmuneCount(targId, BUFF_ALIGNMENT_POSITIVE)
            endif
            if (buffType.negativeBuffImmune) then
                call increaseImmuneCount(targId, BUFF_ALIGNMENT_NEGATIVE)
            endif
            if (buffType.neutralBuffImmune) then
                call increaseImmuneCount(targId, BUFF_ALIGNMENT_NEUTRAL)
            endif
            if (buffType.positiveDispelImmune) then
                call increaseDispelImmuneCount(targId, BUFF_ALIGNMENT_POSITIVE)
            endif
            if (buffType.negativeDispelImmune) then
                call increaseDispelImmuneCount(targId, BUFF_ALIGNMENT_NEGATIVE)
            endif
            if (buffType.neutralDispelImmune) then
                call increaseDispelImmuneCount(targId, BUFF_ALIGNMENT_NEUTRAL)
            endif
   
            set caster = cast
            set targetId = targId
            set level = lev
            set buffType = buffType
            if (duration > 0) then
                set tim = NewTimerEx(this)
                call TimerStart(tim, duration, false, function thistype.expire)
            endif

            if (buffType.hasApplyEvent) then
                call fireEvent(applyEvent)
            endif

        endif
        return this
    endmethod

    private static method onDeath takes nothing returns boolean
        local thistype this = firstBuff[GetUnitUserData(GetDyingUnit())]
        loop
            exitwhen (this == 0)
            if (buffType.hasDeathEvent) then
                call fireEvent(deathEvent)
            endif
            if (not buffType.keepAtDeath) then
                call destroy()
            endif
            set this = next
        endloop
        return false
    endmethod

    private static method onDeindex takes nothing returns boolean
        local integer unitId = GetIndexedUnitId()
        local thistype this = firstBuff[unitId]
        loop
            exitwhen (this == 0)
            if (buffType.hasRemoveEvent) then
                call fireEvent(removeEvent)
            endif
            if (next == 0) then
                set recycle = thistype(0).recycle
            else
                set recycle = next
            endif
            set caster = null
            call ReleaseTimer(tim)
            set tim = null
            call ReleaseTimer(periodicTim[this])
            set periodicTim[this] = null
            set this = next
        endloop
        set this = firstBuff[unitId]
        set firstBuff[unitId] = 0
        set buffCount[unitId] = 0
        call FlushChildHashtable(table, unitId)
        call FlushChildHashtable(table, -unitId)
        set thistype(0).recycle = this
        return false
    endmethod

    implement Init

endstruct

private struct DefaultValues extends array

    static boolean stackable = false
    static boolean permanent = false
    static integer dispelPriority = -1
    static integer auraId = 0
    static integer buffId = 0
    static integer alignment = BUFF_ALIGNMENT_NEUTRAL
    static boolean positiveBuffImmune = false
    static boolean negativeBuffImmune = false
    static boolean neutralBuffImmune = false
    static boolean positiveDispelImmune = false
    static boolean negativeDispelImmune = false
    static boolean neutralDispelImmune = false
    static boolean keepAtDeath = false
   
    static integer category = 0
   
    static if (LIBRARY_DamageEvent) then
        static integer damagePriority = 0
    endif

endstruct

module BuffStruct

    private static delegate DefaultValues default

    static if (LIBRARY_DamageEvent and thistype.onDamage.exists) then
        private static method damageCall takes nothing returns boolean
            static if (thistype.damageFilter.exists) then
                local Buff this
                if (damageFilter()) then
                    set this = Buff[DamageEvent.target][typeid]
                    loop
                        exitwhen (this == 0)
                        call onDamage(this)
                        set this = this.next
                    endloop
                endif
            else
                local Buff this = Buff[DamageEvent.target][typeid]
                loop
                    exitwhen (this == 0)
                    call onDamage(this)
                    set this = this.next
                endloop
            endif
            return false
        endmethod
    endif

    static if (thistype.onPeriodic.exists) then
        private static method periodicCall takes nothing returns nothing
            call onPeriodic(GetTimerData(GetExpiredTimer()))
        endmethod
    endif

    private static method onEvent takes nothing returns boolean
        if (eventType == applyEvent) then
            static if thistype.onPeriodic.exists then
                set periodicTim[triggerBuff] = NewTimerEx(triggerBuff)
                call TimerStart(periodicTim[triggerBuff], buffType.period, true, function thistype.periodicCall)
            endif
            static if thistype.onApply.exists then
                call onApply(triggerBuff)
            endif
            static if (thistype.onDispel.exists) then
                //! novjass
                elseif (eventType == dispelEvent) then
                //! endnovjass
                    call onDispel(triggerBuff, Buff(0).caster, eventBool)
            endif
            static if (thistype.onRefresh.exists) then
                //! novjass
                elseif (eventType == refreshEvent) then
                //! endnovjass
                    call onRefresh(triggerBuff)
            endif
            static if (thistype.onRemove.exists) then
                //! novjass
                elseif (eventType == removeEvent) then
                //! endnovjass
                    call onRemove(triggerBuff)
            endif
            static if thistype.onExpire.exists then
                //! novjass
                elseif (eventType == expireEvent) then
                //! endnovjass
                    call onExpire(triggerBuff)
            endif
            static if (thistype.onDeath.exists) then
                //! novjass
                elseif (eventType == deathEvent) then
                //! endnovjass
                    call onDeath(triggerBuff)
            endif
        endif
        return false
    endmethod

    private static method onInit takes nothing returns nothing
        set buffEvent[typeid] = Filter(function thistype.onEvent)
        set buffTypeStackable[typeid] = stackable
        static if thistype.onPeriodic.exists then
            set buffTypePeriod[typeid] = period
        endif
        set buffTypeAuraId[typeid] = auraId
        set buffTypeBuffId[typeid] = buffId
        set buffTypeAlignment[typeid] = alignment
        set buffTypeDispelPriority[typeid] = dispelPriority
        set buffTypePermanent[typeid] = permanent
        set buffTypePositiveBuffImmune[typeid] = positiveBuffImmune
        set buffTypeNegativeBuffImmune[typeid] = negativeBuffImmune
        set buffTypeNeutralBuffImmune[typeid] = neutralBuffImmune
        set buffTypePositiveDispelImmune[typeid] = positiveDispelImmune
        set buffTypeNegativeDispelImmune[typeid] = negativeDispelImmune
        set buffTypeNeutralDispelImmune[typeid] = neutralDispelImmune
        set buffTypeKeepAtDeath[typeid] = keepAtDeath
        set buffTypeCategory[typeid] = category
        static if (LIBRARY_DamageEvent and thistype.onDamage.exists) then
            call DamageEvent.ANY.register(Filter(function thistype.damageCall), damagePriority)
        endif
        static if (thistype.onApply.exists) then
            set buffTypeHasApplyEvent[typeid] = true
        elseif (thistype.onPeriodic.exists) then
            set buffTypeHasApplyEvent[typeid] = true
        endif
        static if (thistype.onRefresh.exists) then
            set buffTypeHasRefreshEvent[typeid] = true
        endif
        static if (thistype.onRemove.exists) then
            set buffTypeHasRemoveEvent[typeid] = true
        endif
        static if (thistype.onExpire.exists) then
            set buffTypeHasExpireEvent[typeid] = true
        endif
        static if (thistype.onDeath.exists) then
            set buffTypeHasDeathEvent[typeid] = true
        endif
        static if (thistype.onDispel.exists) then
            set buffTypeHasDispelEvent[typeid] = true
        endif
    endmethod

    static method apply takes unit caster, unit target, real level, real duration returns Buff
        return Buff.apply(typeid, caster, target, level, duration)
    endmethod

    static method operator buffType takes nothing returns buffType
        return typeid
    endmethod

    static method operator previousCaster takes nothing returns unit
        return Buff.previousCaster
    endmethod
   
    static method operator previousDuration takes nothing returns real
        return Buff.previousDuration
    endmethod
   
    static method operator previousLevel takes nothing returns real
        return Buff.previousLevel
    endmethod

endmodule

endlibrary


Utilisation : Voir le code.
Copyright : Libre
Remarques : Aucune
_________________
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
 Sapeur-Goblin
Floodeur prématuré


Inscrit le: 14 Oct 2009
Messages: 719
Sujets: 40
Spécialité en worldedit: Les bugs
Médailles: 1 (En savoir plus...)
Créateur d'unité (Quantité : 1)

MessagePosté le: 15/04/13 10:47    Sujet du message: Citer

Mise à jour majeure du système.
On peut faire des trucs vraiment pas mal maintenant Smile.

Il y aura sûrement une prochaine mise à jour, Nestharus modifiant ses lib' de détection de dégâts actuellement.
_________________
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
 florianlenecro
Floodeur prématuré


Inscrit le: 12 Nov 2009
Messages: 711
Sujets: 50
Spécialité en worldedit: Vétéran


MessagePosté le: 09/08/14 20:10    Sujet du message: Citer

J'ai un problème lors de son installation :
1. DEINDEX is not a member of UnitIndexer
Jass:
module Buff_Init
     private static method onInit takes nothing returns nothing
         local trigger death = CreateTrigger( )
        call TriggerRegisterAnyUnitEventBJ(death, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddCondition(death, Filter(function thistype.onDeath))
        call UnitIndexer.DEINDEX.register(Filter(function thistype.onDeindex))
    endmethod

2. ( From this instance)
Jass:
implement Buff__Init

_________________
C'est en forgeant que l'on devient forgeron
"Le feu ne peut tuer le dragon"
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
 Sapeur-Goblin
Floodeur prématuré


Inscrit le: 14 Oct 2009
Messages: 719
Sujets: 40
Spécialité en worldedit: Les bugs
Médailles: 1 (En savoir plus...)
Créateur d'unité (Quantité : 1)

MessagePosté le: 09/08/14 22:00    Sujet du message: Citer

Tu utilises le UnitIndexer de Nestharus?

Sinon je ne peux pas garantir que cette lib' n'a aucun bug et qu'elle fonctionne totalement correctement.
(Je sais que l'affichage des icônes dans la barre d'état des unités ne se fait pas...)
_________________
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
 florianlenecro
Floodeur prématuré


Inscrit le: 12 Nov 2009
Messages: 711
Sujets: 50
Spécialité en worldedit: Vétéran


MessagePosté le: 06/11/14 20:57    Sujet du message: Citer

Ton lien d'UnitIndexer ne donne plus la lib.

Juste comme ça, comment ça fonctionne pour faire afficher un buff? Les buffs ajoutés par trigger, on doit faire nous même les effets je suppose nan?
_________________
C'est en forgeant que l'on devient forgeron
"Le feu ne peut tuer le dragon"
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
 Sapeur-Goblin
Floodeur prématuré


Inscrit le: 14 Oct 2009
Messages: 719
Sujets: 40
Spécialité en worldedit: Les bugs
Médailles: 1 (En savoir plus...)
Créateur d'unité (Quantité : 1)

MessagePosté le: 15/11/14 19:45    Sujet du message: Citer

Hmm oui Nestharus a rage quit et détruit toutes ses ressources.
Mais tu peux quand même le trouver .

Sinon, oui cette lib' est faite pour des buffs 100% par déclencheurs (il y a un certain nombre d'events qui sont inclus dans la lib pour tout simplifier. Du tout tu construits juste ton buff et pas toute l’indexation et les trucs chiants qu'il y a derrière). L'éditeur d'objets est juste utilisé pour les animations/icônes dans la barre d'état.

Et pour faire afficher un buff tu as un problème? Il me semble qu'il y avait un problème avec cette fonctionnalité, je me souviens plus exactement.

Edit: Je viens de me rendre compte que Nes a changé ses libs depuis le temps. Il a ajouté des fonctionnalités et de la documentation, mais il y a beaucoup plus de dépendances (7 requirements pour UnitIndexer --'). Du coup je vais peut-être poster une map exemple avec les anciens systèmes.
_________________
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
 florianlenecro
Floodeur prématuré


Inscrit le: 12 Nov 2009
Messages: 711
Sujets: 50
Spécialité en worldedit: Vétéran


MessagePosté le: 16/11/14 23:15    Sujet du message: Citer

Pas forcèment le fonctionnement de ta lib, je voudrais juste savoir pour comprendre comment c'est réalisé, la manière pour faire afficher un buff par trigger.
_________________
C'est en forgeant que l'on devient forgeron
"Le feu ne peut tuer le dragon"
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
Montrer les messages depuis:   
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Fonction Jass Toutes les heures sont au format GMT + 1 Heure
Page 1 sur 1

 
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