- Joined
- Sep 30, 2009
- Messages
- 698
Here is a simple but very interesting and quite new system by me. The description should answer all questions.
Feel free to write what you think about the system. What should be added, improved...
Feel free to write what you think about the system. What should be added, improved...
JASS:
library SpellExperience requires optional AutoIndex
//############################### CREDITS ###############################//
//##
//## Idea & System: Axarion
//## AutoIndex: grim001
//##
//############################### DESCRIPTION ###############################//
//##
//## This small library allows you to aquire a totally new way of
//## spell-leveling. Instead of letting the player choose a spell
//## which spell should increase after a hero gains a level, spells
//## acquire experience for being cast, damaging enemies or whatever
//## you want.
//##
//############################### HOW TO USE ###############################//
//##
//## To use this system you need to extend SpellExp. In your struct you
//## have to call the textmacro SpellExpConstructor. You can add all of
//## the methods listed in the interface below. You should not add your own
//## create method since its done via the textmacro. To add exp to a spell
//## you first need to call:
//##
//## Yourstruct.create(unit, integer)
//##
//## Then whenever you want you can use the method below to get an instance:
//##
//## YourStruct.get(unit u, integer spellid)
//##
//## Finally you can change the experience just by:
//##
//## set InstanceName.spellExp = newValue
//##
//## The method expNeeded is used to check if the spell has enough experience.
//## You dont need to level up manualy just set the exp to .expNeeded() to
//## increase the spells level by 1.
//##
//############################################################################//
globals
// feel free to use your own hashtable here, if you aren't
// using the units handle and the spells rawcode as keys already.
private hashtable h = InitHashtable()
endglobals
//############################### END OF USER AREA ########################//
private interface SpellExpEvents
method onSpellLevelUp takes nothing returns nothing defaults nothing
method onSpellExpGain takes nothing returns nothing defaults nothing
method onSpellInit takes nothing returns nothing defaults nothing
method expNeeded takes nothing returns real defaults 200.
endinterface
struct SpellExp extends SpellExpEvents
integer spellId2 = 0
integer spellLevel = 1
integer maxLevel = 3
unit spellUnit = null
real spellExp2 = 0
//########################### START OF OPERATORS #############################//
method operator spellId takes nothing returns integer
return .spellId2
endmethod
method operator spellId= takes integer id returns nothing
call RemoveSavedInteger(h, GetHandleId(.spellUnit), .spellId2)
set .spellId2 = id
call SaveInteger(h, GetHandleId(.spellUnit), .spellId, this)
endmethod
method operator spellExp takes nothing returns real
return .spellExp2
endmethod
method operator spellExp= takes real exp returns nothing
if .spellLevel < .maxLevel and .spellExp + exp > 0 then
set .spellExp2 = exp
if .spellExp2 >= .expNeeded() then
set .spellExp2 = .spellExp2 -.expNeeded()
call .levelUp()
endif
call .onSpellExpGain()
endif
endmethod
//########################### END OF OPERATORS #############################//
method levelUp takes nothing returns nothing
if .spellLevel < .maxLevel then
set .spellLevel = .spellLevel + 1
call .onSpellLevelUp()
call SetUnitAbilityLevel(.spellUnit, .spellId, .spellLevel)
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\Levelup\\LevelupCaster.mdl", .spellUnit, "origin"))
endif
endmethod
static method get takes unit u, integer id returns thistype
return LoadInteger(h, GetHandleId(u), id)
endmethod
static method create takes unit u, integer id returns thistype
local thistype this = thistype.allocate()
set .spellUnit = u
set .spellId = id
return this
endmethod
endstruct
//! textmacro SpellExpConstructor
static method create takes unit u, integer id returns thistype
local thistype this = thistype.allocate(u, id)
set .spellUnit = u
set .spellId = id
call .onSpellInit()
set me = u
return this
endmethod
implement optional AutoDestroy
//! endtextmacro
endlibrary
Attachments
Last edited: