Mana Transfer System

Weyrling

New Member
Reaction score
25
I'm creating a mana-transfer system for my new game, but I'm not sure how to get it to work properly. I'm using a struct that will be able to send and receive 2 transfers, but I'm not sure how to apply the mana function to each rune, since they're structs with a unit variable inside them, rather than actually units.
Any help would be appreciated, if you need any clarification or my code please inform me.
 

Weyrling

New Member
Reaction score
25
JASS:
library Runes
globals
    constant integer nill = 0
endglobals
struct Rune
    readonly unit u
    readonly location p
    readonly Rune src1
    readonly Rune dst1
    readonly lightning beam1
    readonly Rune src2
    readonly Rune dst2
    readonly lightning beam2
    public static method create takes unit u returns Rune
        local Rune r
        local location Loc = GetUnitLoc(u)
        set r.p = Loc
        call RemoveLocation(Loc)
        set r.u = u
        return r
    endmethod
    public static method makebeam takes Rune src, Rune dst returns nothing
        if (src.dst1 == null) then
            set src.dst1 = dst
        elseif (src.dst2 == null) then
            set src.dst2 = dst
        else
            return
            call DisplayTextToPlayer(GetOwningPlayer(src.u),0,0,"|cffff0000Source Node cannot withstand another connection")
        endif
        if (dst.src1 == null) then
            set dst.src1 = src
        elseif (dst.src2 == null) then
            set dst.src2 = src
        else
            return
            call DisplayTextToPlayer(GetOwningPlayer(src.u),0,0,"|cffff0000Destination Node cannot withstand another connection")
        endif
        if (src.beam1 == null) then
            set src.beam1 = AddLightningLoc("HWSB",src.p,dst.p)
        elseif (src.beam2 == null) then
            set src.beam2 = AddLightningLoc("HWSB",src.p,dst.p)
        else
            call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,&quot;The Rune Transfer system has failed, email <a href="mailto:[email protected]">Weyriing@hotmail.com</a> with the replay&quot;)
        endif
    endmethod
    public method destroybeam takes Rune src, Rune dst returns nothing
        if (src.dst1 == dst) then
            call DestroyLightning(src.beam1)
            set src.dst1 = nill
        elseif (src.dst2 == dst) then
            call DestroyLightning(src.beam2)
            set src.dst2 = nill
        else
            call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,&quot;The Source Node is not transfering to that Node&quot;)
        endif
        if (dst.src1 == src) then
            set dst.src1 = nill
        elseif (dst.src2 == src) then
            set dst.src2 = nill
        else
            call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,&quot;The Designated Node is not being sent to by the Source Node&quot;)
        endif
    endmethod
    public static method destroyrune takes Rune r returns nothing
        set r.u = null
        call RemoveLocation(r.p)
        call r.destroybeam(r.src1,r)
        call r.destroybeam(r.src2,r)
        call r.destroybeam(r,r.dst1)
        call r.destroybeam(r,r.dst2)
        set r.src1 = nill
        set r.src2 = nill
        set r.dst1 = nill
        set r.dst2 = nill
        return
    endmethod
endstruct
endlibrary


What I need to figure out is how to transfer mana along the beams from src to dst from every Rune.
 

Cohadar

master of fugue
Reaction score
209
From jasshelper.html (can be found inside NewGenPack\jasshelper directory)

All struct members are public by default, so the public keyword is not necessary, on the other hand you must specify private. Something to point out is the existance of the readonly keyword, it allows code outside the struct to read the variable but not to assign it. It is a nonstandard at the moment, so you shouldn't use it on public releases.
 

Cohadar

master of fugue
Reaction score
209
I'm creating a mana-transfer system for my new game, but I'm not sure how to get it to work properly. I'm using a struct that will be able to send and receive 2 transfers, but I'm not sure how to apply the mana function to each rune, since they're structs with a unit variable inside them, rather than actually units.
Any help would be appreciated, if you need any clarification or my code please inform me.

Why 2 transfers? That is totally wrong organization.
What is a rune?

Anyways this sounds like a problem for collections.
Check this.
 

Weyrling

New Member
Reaction score
25
Since I am evidently out of my depth here, I"ll just say what I need to do:
I have an ability, when I use it, I want it to create a lightning effect between the casting unit and the targeted unit. When the targeted unit's mana is below maximum, it should take mana from the casting unit.
I have a second ability that should remove the lightning effect and stop transfering mana.
Everything that I have created in an attempt to do this has failed completely.
The units that will be doing this are the runes.
I looked at the collections system but I don't understand how it works.
I apologize for lacking the knowledge to do it myself, but I'd appreciate if somebody could give me some code, or at-least link me to a properly defined function/syntax list.
 

Cohadar

master of fugue
Reaction score
209
Ok let me explain to you how to do this:
First you need a struct:
JASS:

private struct TransferPair
    unit rune
    unit target
    lightning fx
endstruct


Then you need array and a counter:
JASS:

globals
    private Transfers array
    private integer N = 0
endglobals


When a rune casts first spell on a target unit you create a TransferPair and add it to the array and increase the counter:
JASS:

//===========================================================================
private function Connect takes nothing returns nothing
    local TransferPair tp = TransferPair.create()
    set tp.rune = GetTriggerUnit()
    set tp.target = GetSpellTargetUnit()
    set Transfers[N] = tp
    set N = N + 1
endfunction


Disconnecting transfer: (3 cases)
1: Casting disconnect spell
JASS:

//===========================================================================
private function Disconnect takes nothing returns nothing
    local integer i
    local unit rune = GetTriggerUnit()
    local unit target target = GetSpellTargetUnit()

    set i = N - 1
    loop
        exitwhen i&lt;0
        if (Transfers<i>.rune == rune) and (Transfers<i>.target == target) then
            // remove the pair from array
            call Transfers<i>.destroy()
            set N = N - 1
            set Transfers<i> = Transfers[N]
            exitwhen true // break the loop
        endif
        set i = i - 1
    endloop
endfunction
</i></i></i></i>


2: target dies:
JASS:

//===========================================================================
private function DisconnectTarget takes nothing returns nothing
    local integer i
    local unit target = GetTriggerUnit() // dying unit

    set i = N - 1
    loop
        exitwhen i&lt;0
        if (Transfers<i>.target == target) then
            // remove all pairs with target
            call Transfers<i>.destroy()
            set N = N - 1
            set Transfers<i> = Transfers[N]
            // exitwhen true // break the loop
        endif
        set i = i - 1
    endloop
endfunction
</i></i></i>


3: rune dies:
JASS:

//===========================================================================
private function DisconnectRune takes nothing returns nothing
    local integer i
    local unit rune = GetTriggerUnit() // dying unit

    set i = N - 1
    loop
        exitwhen i&lt;0
        if (Transfers<i>.rune == rune) then
            // remove the pairs with rune
            call Transfers<i>.destroy()
            set N = N - 1
            set Transfers<i> = Transfers[N]
            //exitwhen true // break the loop
        endif
        set i = i - 1
    endloop
endfunction
</i></i></i>


As for the handling of lightnings, you do that in a periodic timer
JASS:

//===========================================================================
private function Periodic takes nothing returns nothing
    set i = N - 1
    loop
        exitwhen i&lt;0
        // Set the position of lightning Transfers<i>.fx from rune to target
        set i = i - 1
    endloop
endfunction
</i>


That's it, have fun.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top