Posté le: 22/01/10 12:36 Sujet du message: Optimisation: attaques ioniques
Les unités équipées de "ion" (dégâts magique sous warcraft) et détectées par la présence d'une compétence infligent des effets de type "stun" etc de manière aléatoire (pourcentage de chance).
Du coup, le trigger se lance à chaque fois qu'une unité est attaquée.
Est-ce améliorable?
Secret:
Jass:
scope ionweapons initializer init
//=================================================
globals
private constant string FX = "war3mapImported\\fx_ion_squished.mdx"
private constant integer IONID1 = 'A00K'
private constant integer IONID2 = 'A01F'
private constant integer CHANCEBASE = 15
private constant integer CHANCECOEFF = 7
private constant integer RESEARCH = 'R007'
endglobals
//=================================================
private function Conditions takes nothing returns boolean
local integer i = GetRandomInt(0,100)
local integer chance = GetRandomInt(0,100)
local unit attacker = GetAttacker()
local unit target = GetTriggerUnit()
local player owner = GetOwningPlayer(attacker)
local integer chancereq = CHANCEBASE+CHANCECOEFF*GetPlayerTechCount(owner,RESEARCH,true)
local real x = GetUnitX(target)
local real y = GetUnitY(target)
local unit dummy = null
if GetUnitAbilityLevel(attacker,IONID1)>=1 or GetUnitAbilityLevel(attacker,IONID2)>=1then
if chance<=chancereq then
set dummy = CreateUnit(owner,'o00F',x,y,0.) //Ion Buff on target
call DestroyEffect(AddSpecialEffect(FX,x,y))
call UnitApplyTimedLife(dummy,'BTLF',1.)
call IssueTargetOrder(dummy,"acidbomb",target)
//Random Effect
if i <= 20 then//Reduced mana
call SetUnitState(target, UNIT_STATE_MANA, GetUnitState(target,UNIT_STATE_MANA)- GetRandomReal(50,GetUnitState(target,UNIT_STATE_MANA)) )
elseif i> 20 and i <= 50 then
set dummy = CreateUnit(owner,'o00D',x,y,0.)//Stun
call UnitApplyTimedLife(dummy,'BTLF',1.)
call IssueTargetOrder(dummy,"thunderbolt",target)
elseif i > 50 and i <= 80 then
set dummy = CreateUnit(owner,'o00D',x,y,0.) //Slow movement
call UnitApplyTimedLife(dummy,'BTLF',1.)
call IssueTargetOrder(dummy,"acidbomb",target)
elseif i > 80 and i <= 100 then
set dummy = CreateUnit(owner,'o00E',x,y,0.) //slow attack
call UnitApplyTimedLife(dummy,'BTLF',1.)
call IssueTargetOrder(dummy,"acidbomb",target)
endif
//Ion particle Fx
call IonAddFx(target)
endif
endif
set attacker = null
set owner = null
set target = null
set dummy = null
return false
endfunction
//=================================================
public function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition(t, Condition(function Conditions))
endfunction
//=================================================
endscope
Fonction IonAddFx: créé des effets quand il y a bien effets de type "ion"
Secret:
Jass:
library ionfxsys needs TimerUtils
//=================================================
globals
private constant real TIMEOUT = 0.25
private constant real AOE = 100.
endglobals
//=================================================
private struct str
unit ship
integer i
real x
real y
endstruct
//=================================================
private function CreateFx takes nothing returns nothing
local timer t = GetExpiredTimer()
local str dat = GetTimerData(t)
local real x = dat.x+GetRandomReal(-AOE,AOE)
local real y = dat.y+GetRandomReal(-AOE,AOE)
if dat.i < 10 and GetUnitState(dat.ship, UNIT_STATE_LIFE) > 0then
set dat.i = dat.i + 1
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Orc\\LightningShield\\LightningShieldBuff.mdl",x,y))
else
call ReleaseTimer(t)
call dat.destroy()
endif
endfunction
//=================================================
function IonAddFx takes unit whichUnit returns nothing
local timer t = NewTimer()
local str dat = str.create()
set dat.ship = whichUnit
set dat.x = GetUnitX(dat.ship)
set dat.y = GetUnitY(dat.ship)
set dat.i = 0
call SetTimerData(t, dat)
call TimerStart (t, TIMEOUT, true, function CreateFx )
endfunction
//=================================================
endlibrary
Inscrit le: 23 Aoû 2007 Messages: 7143 Sujets: 147 Spécialité en worldedit: le troll, le flood, la vulgarité, mon coeur balance Médailles: 2 (En savoir plus...)
Posté le: 15/03/10 21:30 Sujet du message:
Il est difficile de lier une attaque et le moment où celle ci fait des dégâts, en effet même "à la main" il est facile de se faire produire l'event "une unité est attaqué", tout en interrompant l'attaque, et même tu ne peux pas savoir quelle attaque aboutira avant une autre.
La voie des purs est de coder absolument tous les spells infligeant des dégâts, donc on sait quand une unité subit des dégâts d'un spell, et le reste c'est forcément d'une attaque. (et pour te faciliter la vie éventuellement utiliser un système de détection de dégâts).
PS : Même combat, fusion needed. _________________
private struct s_MineWall
unit caster
player owner
integer i
static method operator [] takes unit u returns thistype
return thistype(GetUnitId(u))
endmethod
method destroy takes nothing returns nothing
set .caster = null
set .owner = null
endmethod
endstruct
private function CreateFx takes nothing returns nothing
local timer t = GetExpiredTimer()
local s_Ion dat = GetTimerData(t)
local real x = dat.x+GetRandomReal(-FX_AOE,FX_AOE)
local real y = dat.y+GetRandomReal(-FX_AOE,FX_AOE)
if dat.i < FX_COUNT and GetUnitState(dat.ship, UNIT_STATE_LIFE) > 0then
set dat.i = dat.i + 1
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Orc\\LightningShield\\LightningShieldBuff.mdl",x,y))
else
call ReleaseTimer(t)
call dat.destroy()
endif
endfunction
private function IonAddFx takes unit whichUnit returns nothing
local timer t = NewTimer()
local s_Ion dat = s_Ion[whichUnit]
set dat.ship = whichUnit
set dat.x = GetUnitX(dat.ship)
set dat.y = GetUnitY(dat.ship)
set dat.i = 0
call SetTimerData(t, dat)
call TimerStart (t, FX_TIMEOUT, true, function CreateFx )
endfunction
private function MineWallSpawnMine takes nothing returns nothing
local timer t = GetExpiredTimer()
local s_MineWall dat = GetTimerData(t)
local real x = GetUnitX(dat.caster)
local real y = GetUnitY(dat.caster)
if dat.i < IMW_DUR and GetUnitState(dat.caster, UNIT_STATE_LIFE) > 0 then
set dat.i = dat.i + 1
call CreateUnit(dat.owner,MINE,x,y,0.)
else
call SetUnitPathing(dat.caster,true)
call ReleaseTimer(t)
call dat.destroy()
endif
endfunction
private function CastIonicMineWall takes nothing returns nothing
local timer t = NewTimer()
local s_MineWall dat = s_MineWall[SpellEvent.CastingUnit]
set dat.caster = SpellEvent.CastingUnit
set dat.i = 0
set dat.owner = GetOwningPlayer(dat.caster)
call SetUnitPathing(dat.caster,false)
call SetTimerData(t, dat)
call TimerStart (t,IMW_TIMEOUT,true, function MineWallSpawnMine)
endfunction
private function MineDeath takes unit mine returns nothing
local real x = GetUnitX(mine)
local real y = GetUnitY(mine)
local unit dummy = CreateUnit(GetOwningPlayer(mine),DUMMYID,x,y,0.)
call UnitApplyTimedLife(dummy,'BTLF',1.5)
call IssueImmediateOrder(dummy,"stomp")
call DestroyEffect(AddSpecialEffect(FX_MINE,x,y))
call IonAddFx(dummy)
set dummy = null
endfunction
private function CheckMineId takes nothing returns boolean
if GetUnitTypeId(GetTriggerUnit()) == MINE then
call MineDeath(GetTriggerUnit())
endif
return false
endfunction
private function IonDealAttack takes unit attacker, unit target returns nothing
local integer i = GetRandomInt(0,100)
local integer chance = GetRandomInt(0,100)
local player owner = GetOwningPlayer(attacker)
local integer chancereq = CHANCEBASE+CHANCECOEFF*GetPlayerTechCount(owner,RESEARCH,true)
local real x = GetUnitX(target)
local real y = GetUnitY(target)
local unit dummy = null
if chance<=chancereq then
set dummy = CreateUnit(owner,'o00F',x,y,0.) //Ion Buff on target
call DestroyEffect(AddSpecialEffect(FX,x,y))
call UnitApplyTimedLife(dummy,'BTLF',1.)
call IssueTargetOrder(dummy,"acidbomb",target)
//Random Effect
if i <= 20 then//Reduced mana
call SetUnitState(target, UNIT_STATE_MANA, GetUnitState(target,UNIT_STATE_MANA)- GetRandomReal(50,GetUnitState(target,UNIT_STATE_MANA)) )
elseif i> 20 and i <= 50 then
set dummy = CreateUnit(owner,'o00D',x,y,0.)//Stun
call UnitApplyTimedLife(dummy,'BTLF',1.)
call IssueTargetOrder(dummy,"thunderbolt",target)
elseif i > 50 and i <= 80 then
set dummy = CreateUnit(owner,'o00D',x,y,0.) //Slow movement
call UnitApplyTimedLife(dummy,'BTLF',1.)
call IssueTargetOrder(dummy,"acidbomb",target)
elseif i > 80 and i <= 100 then
set dummy = CreateUnit(owner,'o00E',x,y,0.) //slow attack
call UnitApplyTimedLife(dummy,'BTLF',1.)
call IssueTargetOrder(dummy,"acidbomb",target)
endif
//Ion particle Fx
call IonAddFx(target)
endif
set owner = null
set dummy = null
endfunction
private function IonCheckAttack takes nothing returns boolean
if GetUnitAbilityLevel(GetAttacker(),IONID1)>=1 or GetUnitAbilityLevel(GetAttacker(),IONID2)>=1then
call IonDealAttack(GetAttacker(),GetTriggerUnit())
endif
return false
endfunction
public function init takes nothing returns nothing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
call RegisterSpellFinishResponse(IMW_SPELL,CastIonicMineWall)
call TriggerRegisterAnyUnitEventBJ(t1, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition(t1, Condition(function CheckMineId))
call TriggerRegisterAnyUnitEventBJ(t2, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition(t2, Condition(function IonCheckAttack))
endfunction
Page 1 sur 1 La question posée dans ce topic a été résolue !
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