- Joined
- Dec 6, 2009
- Messages
- 168
Hi! I used BPower's http://www.hiveworkshop.com/forums/spells-569/simple-spell-collection-1-v1-0-0-0-a-245192/ as help to do my first vjass spell.
I made a simple Mind Crush spell. So here is what it does: It deals damage, reduces armor and attack damage.
I feel like there is alot of unnecessary code and checking since I will be using all of the systems like RegisterPlayerUnitEvent and DummyCaster, but I'm not sure what to delete..
I made a simple Mind Crush spell. So here is what it does: It deals damage, reduces armor and attack damage.
I feel like there is alot of unnecessary code and checking since I will be using all of the systems like RegisterPlayerUnitEvent and DummyCaster, but I'm not sure what to delete..
JASS:
scope MindCrush
globals
private constant integer AID = 'A00A'
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_MAGIC
private constant integer BUFF_CAST_ID = 'A00C'
private constant integer ORDER_ID = 852189
private constant integer BUFF_CAST_ID2 = 'A00B'
private constant integer ORDER_ID2 = 852149
endglobals
native UnitAlive takes unit id returns boolean
private constant function GetDamage takes integer shadowpower, integer spellpower returns real
return 100. + (1*shadowpower) + (0.5*spellpower)
endfunction
private module init
private static method onInit takes nothing returns nothing
static if LIBRARY_SpellEffectEvent then
call RegisterSpellEffectEvent(AID, function thistype.run)
else
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function thistype.check))
set t = null
endif
static if not LIBRARY_DummyCaster then
static if LIBRARY_UnitIndexer then
set UnitIndexer.enabled = false
set c = CreateUnit(NEUTRAL,DUMMY_CASTER,0,0,0)
set UnitIndexer.enabled = true
else
set c = CreateUnit(NEUTRAL,DUMMY_CASTER,0,0,0)
endif
call SetUnitPosition(c,2147483647,2147483647)
call UnitAddAbility(c, BUFF_CAST_ID)
endif
endmethod
endmodule
private struct Spell extends array
implement optional Alloc
unit caster
unit aim
real dmg
static if not LIBRARY_DummyCaster then
static unit c
endif
static if (not thistype.allocate.exists) then
static integer array rn
static integer ic = 0
endif
private static method applyDamage takes nothing returns nothing
local timer t = GetExpiredTimer()
local thistype this = GetTimerData(t)
if (UnitAlive(.aim)) then
call UnitDamageTarget(.caster, .aim, .dmg, false, false, ATTACK_TYPE, DAMAGE_TYPE, null)
endif
static if (thistype.deallocate.exists) then
call this.deallocate()
else
set rn[this] = rn[0]
set rn[0] = this
endif
set .caster = null
set .aim = null
endmethod
private static method run takes nothing returns boolean
local integer shadowpower
local integer spellpower
static if (thistype.allocate.exists) then
local thistype this = allocate()
else
local thistype this = rn[0]
if this == 0 then
set ic = ic + 1
set this = ic
else
set rn[0] = rn[this]
endif
endif
set .caster = GetTriggerUnit()
set .aim = GetSpellTargetUnit()
set spellpower = 10
set shadowpower = 10
set .dmg = GetDamage(shadowpower, spellpower)
static if DummyCaster.castTarget.exists then
call DummyCaster[BUFF_CAST_ID].castTarget(GetTriggerPlayer(), 1, ORDER_ID, .aim)
call DummyCaster[BUFF_CAST_ID2].castTarget(GetTriggerPlayer(), 1, ORDER_ID2, .aim)
else
call SetUnitOwner(c, GetTriggerPlayer(), false)
call IssueTargetOrderById(c, ORDER_ID, .aim)
call SetUnitOwner(c, NEUTRAL, false)
endif
call TimerStart(NewTimerEx(this), 0.00, false, function thistype.applyDamage)
return false
endmethod
static if not LIBRARY_SpellEffectEvent then
private static method check takes nothing returns boolean
if (GetSpellAbilityId() == AID) then
call thistype.run()
endif
return false
endmethod
endif
implement init
endstruct
endscope