- Joined
- Feb 22, 2006
- Messages
- 960
Here is the new System I worked on. It's called CombopointListener look into the script header for more information.
Requires:
Credits:
Requires:
Credits:
Vexorian for JassHelper/Table 2.0/BoolexprUtils
Deadon for help with methods reworking
PurplePoot who reminded me to use a generic trigger
aznricepuff for general and upcoming help
JASS:
//****************************************************************************************************
//* CombopointListener v0.6a By xD.Schurke
//* ---------------------------------------
//*
//* Requires:
//* *At least JassHelper v0.9.Z.5
//* *Table 3.0
//*
//* Credits:
//* *Vexorian for JassHelper,Table
//* *Deaod for helping with some stuff
//* *PurplePoot who reminded me to use a generic trigger
//* *aznricepuff
//*
//* Changelog:
//* *Removed BoolexprUtils
//* *Added an auto-reset via timer
//* *Added new method (autoReset(boolean))
//* *resetCPOnTargetSwitch is now a method and also was renamed (resetOnSwitch(boolean))
//* *Cleaned code (removed most operator overloading and simply renamed the variables)
//*
//* Changelog for 0.6a:
//* *Renamed globals for a better legibility
//* *Fixed a small issue with the intern variable dataNum
//* *Fixed a small issue with the stackRemove method which could cause some problems
//*
//*
//* CombopointListener Doc:
//* ---------------------------------------
//*
//* The following Doc lists up all Methods/Members which can be influenced by the user.
//*
//*
//* Methods of CombopointListener:
//*
//* create (unit u)
//* Alocates a unique Instance for the unit
//*
//* resetCombopoints()
//* Sets the combopoints to 0
//*
//* newSpellData (integer rawCode, integer combpointsperspell)
//* Registers a spell and sets the combopoints gained per spell
//*
//* autoReset (boolean b)
//* If true the combopoints reset each autoResetTime-Interval to 0
//* By default it's false
//*
//* resetOnSwitch (boolean b)
//* If true the combopoints reset on each target switch
//* By default it's true
//*
//* destroy()
//* Recycles the ID and resets all members of the instance
//*
//*
//* Members of CombopointListener:
//*
//* integer maxCombopoints
//* Represents the maxCombopoints which can gained by the unit
//* Standard for this member is 5.
//*
//* integer combopoints
//* The current number of combopoints
//*
//* real autoResetTime
//* Used for reseting combopoints if autoReset is true
//* By default each 90 seconds
//*
//*
//* Outstanding Constants:
//*
//* integer StandardMaxCP = 5
//*
//* real StandardInterval = 0.03125
//*
//* Outstanding Functions:
//*
//* CombopointListener GetCombopointListener(unit u)
//* Returns the CombopointListener instance for this unit
//*
//* ---------------------------------------
//*
//* This small system simulates a combopoint system equal to the one in Worlf of Warcraft.
//* It works all for its own, that means you only have to register an unit and spells for this unit
//* and the system will register the combopoints. The only thing the user have to do is for abilities
//* which should remove combopoints or are based on the number of Combopoints.
//*
//****************************************************************************************************
library CombopointListener requires Table
globals
private constant integer STANDARD_MAX_CP = 5
private constant real STANDARD_INTERVAL = 0.03125
endglobals
struct CombopointListener
public integer maxCombopoints = STANDARD_MAX_CP
public real autoResetTime = 90.0
private integer cp = 0
private boolean autoR = false
private boolean onSwitch = true
private unit listenUnit = null
private unit curTarget = null
private real time = 0.0
private integer dataNum = 0
private static integer size = 0
private static thistype array data
private static timer tim
readonly static HandleTable regTable = 0
method operator combopoints= takes integer i returns nothing
debug if i > this.maxCombopoints or i < 0 then
debug call BJDebugMsg("Warning: This number isn't supported by the system!")
return
debug endif
debug set this.cp = i
endmethod
method operator combopoints takes nothing returns integer
return this.cp
endmethod
method resetCombopoints takes nothing returns nothing
set this.cp = 0
endmethod
method newSpellData takes integer rawCode, integer cpps returns nothing
set Table[I2S(GetHandleId(this.listenUnit))][rawCode] = cpps
endmethod
static method autoResetCallback takes nothing returns nothing
local integer i = 0
local thistype this
loop
exitwhen i >= thistype.size
set this = thistype.data[i]
set this.time = this.time + STANDARD_INTERVAL
if this.time >= this.autoResetTime then
call this.resetCombopoints()
set this.time = 0.0
endif
endloop
if this.size == 0 then
call PauseTimer(this.tim)
endif
endmethod
method autoReset takes boolean b returns nothing
if b then
if this.size == 0 then
call TimerStart(this.tim,STANDARD_INTERVAL,true,function thistype.autoResetCallback)
endif
set this.dataNum = this.size
set this.data[this.size] = this
set this.size = this.size + 1
set this.autoR = true
elseif this.size > 0 and this.autoR then
call this.stackRemove()
set this.autoR = false
endif
endmethod
private method stackRemove takes nothing returns nothing
if this.size > 1 then
set this.size = this.size - 1
set this.data[this.dataNum] = this.data[this.size]
set this.data[this.size] = 0
set this.data[this.dataNum].dataNum = this.dataNum
else
set this.size = this.size - 1
set this.data[this.size] = 0
endif
if this.size == 0 then
call PauseTimer(this.tim)
endif
endmethod
private static method condition takes nothing returns boolean
local unit u = GetTriggerUnit()
local thistype this = thistype.regTable[u]
local boolean b = false
if this != 0 or this != null then
set b = Table[I2S(GetHandleId(u))].exists(GetSpellAbilityId())
endif
set u = null
return b
endmethod
private static method action takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit tar = GetSpellTargetUnit()
local thistype this = thistype.regTable[u]
if this.onSwitch and tar != this.curTarget then
call this.resetCombopoints()
set this.curTarget = tar
endif
set this.cp = this.cp + Table[I2S(GetHandleId(u))][GetSpellAbilityId()]
if this.cp > this.maxCombopoints then
set this.cp = this.maxCombopoints
endif
set this.time = 0.0
set u = null
set tar = null
endmethod
static method create takes unit u returns thistype
local thistype this = thistype.allocate()
set this.listenUnit = u
set thistype.regTable[u] = this
return this
endmethod
private method onDestroy takes nothing returns nothing
if this.autoR then
call this.stackRemove()
endif
call this.regTable.flush(this.listenUnit)
call Table.flush2D(I2S(GetHandleId(this.listenUnit)))
set this.listenUnit = null
set this.curTarget = null
endmethod
private static method onInit takes nothing returns nothing
local trigger int = CreateTrigger()
local integer i = 0
loop
call TriggerRegisterPlayerUnitEvent(int,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
set i = i + 1
exitwhen i >= bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition(int,Condition(function thistype.condition))
call TriggerAddAction(int,function thistype.action)
set thistype.regTable = HandleTable.create()
set thistype.tim = CreateTimer()
set int = null
endmethod
endstruct
function GetCombopointListener takes unit u returns CombopointListener
debug if u == null then
debug call BJDebugMsg("Warning: Attempted to get an instance for a null unit!")
debug return 0
debug elseif CombopointListener.regTable.exists(u) != true then
debug call BJDebugMsg("Warning: There is no instance registered for this unit!")
debug return 0
debug endif
return CombopointListener.regTable[u]
endfunction
endlibrary
Changelog
v0.6a
- Renamed globals for a better legibility
- Fixed a small issue with the intern variable dataNum
- Fixed a small issue with the stackRemove method which could cause some problems
v0.6
- Removed BoolexprUtils
- Added an auto-reset via timer
- Added new method (autoReset(boolean))
- resetCPOnTargetSwitch is now a method and also was renamed (resetOnSwitch(boolean))
- Cleaned code (removed most operator overloading and simply renamed the variables)
v0.5b
- Added compatibility for patch 1.24
- Removed return bug
v0.5
- Added more safety for changing current combopoints
- The way how newSpellData workes was changed, it uses now 2D Tables. Now there should be fewer Tables created unfortunately I now have to use the H2I bug, with 1.24 I will update how this works.
v0.4
- Fixed a bug that created a warcraft3 Critical Error when units, which are not registered, cast a spell
v0.3
- Created a constant integer which defines the standard maxCP
- regTable is now a readonly static member of CombopointListener
- There is only one Table left for combopoints (spellData)
- Reworked condition and action methods
v0.2
- Changed the way the trigger is created
- Changed regTable to HandleTable and removed the H2I function
v0.1
- Release
Attachments
Last edited: