Fixed spell support and made 2 spells: hold_monster and magic_missile
When you define spells you don't use defineSpell but createSpell function.
Code: Select all
createSpell(
{
name = "hold_monster",
uiName = "Hold monster",
skill = "spellcraft",
level = 0,
runes = "AC",
manaCost = 15,
}
)
createSpell(
{
name = "magic_missile",
uiName = "Magic missile",
skill = "fire_magic",
level = 0,
runes = "AD",
manaCost = 15,
}
)
Difference to defineSpell is that you don't define onCast-hook because hooks are defined in script entities.
Here is the fw_spells script entity
Code: Select all
activeSpells = {}
immunityList = {}
immunityList.hold_monster = {
skeleton_archer=true,
skeleton_warrior=true
}
function activate()
addSpell('hold_monster',holdMonster)
addSpell('magic_missile',magicMissile)
end
function addSpell(spellName,hookFunction)
fw.addHooks(spellName,'fw_spells',{
onCast = hookFunction
}
)
end
function magicMissile(champ, x, y, direction, skill)
local dx,dy = getForward(party.facing)
playSoundAt("fireball_launch",party.level,party.x,party.y)
shootProjectile('magic_missile', party.level, party.x+dx, party.y+dy, direction, 14, 0, 0, 0, 0, 0, skill*5, nil, true)
end
function shootSpell(fx,dir,speed)
local timer = spawn('timer',party.level,0,0,0)
end
function holdMonster(champ, x, y, direction, skill)
local holdMonster = function() return false end
local monster = help.nextEntityAheadOf(party,3,'monster')
if not monster then return false end
if immunityList.hold_monster[monster.name] then return false end
local timerId = createSpellTimer(monster,10+skill,'holdMonsterDestructor')
playSoundAt("frostbolt_launch",party.level,party.x,party.y)
fw.debugPrint(monster.id..' held')
--dynamically add hooks which prevents monster to attack or move
-- use spellId as hook-id so the hook can be removed on destructor
fw.addHooks(monster.id,timerId,{
onMove = holdMonster,
onAttack = holdMonster,
onRangedAttack = holdMonster,
onTurn = holdMonster
},
1)
return true
end
function holdMonsterDestructor(timer)
fw.removeHooks(activeSpells[timer.id],timer.id)
fw.debugPrint(activeSpells[timer.id]..' unheld')
timer:deactivate()
timer:destroy()
end
-- creates a spell timer
-- entity = affected entity,
-- time = how many seconds spells effect lasts
-- destructorName = name of the function which is called when the effect of the spell is worn out.
-- returns id of timer
function createSpellTimer(entity,time,destructorName)
local timer = spawn('timer',party.level,0,0,0)
timer:setTimerInterval(time)
-- store entity.id to table indexed by timer.id so we can access it in spell-destructor
activeSpells[timer.id] = entity.id
timer:addConnector('activate','fw_spells',destructorName)
timer:activate()
return timer.id
end
Hold monster was surprisingly tough one to code, but i'm pretty happy with it now. Without my hook-framework it would have been much harder to implement. Magic missile was trivial and it can be done without this framework.
Here is item definition and particleSystems for magic missile.
Code: Select all
defineObject{
name = "magic_missile",
class = "Item",
uiName = "Magic missile",
model = "assets/models/items/quarrel.fbx", --assets/models/items/arrow.fbx
--ammoType = "arrow",
gfxIndex = 109,
attackPower = 1,
impactSound = "fireball_hit",
particleEffect = "magic_missile",
stackable = false,
sharpProjectile = false,
projectileRotationY = 90,
weight = 0.1,
}
defineParticleSystem{
name = "magic_missile",
emitters = {
-- flames
{
emissionRate = 50,
emissionTime = 0,
maxParticles = 50,
boxMin = {-0.0, -0.0, 0.0},
boxMax = { 0.0, 0.0, -0.0},
sprayAngle = {0,360},
velocity = {0.3, 0.3},
texture = "assets/textures/particles/torch_flame.tga",
frameRate = 35,
frameSize = 64,
frameCount = 16,
lifetime = {0.8, 0.8},
colorAnimation = true,
color0 = {1, 1, 1},
opacity = 1,
fadeIn = 0.15,
fadeOut = 0.3,
size = {0.125, 0.25},
gravity = {0,0,0},
airResistance = 1,
rotationSpeed = 1,
blendMode = "Additive",
objectSpace = true,
},
-- glow
{
spawnBurst = true,
emissionRate = 1,
emissionTime = 0,
maxParticles = 1,
boxMin = {0,0,-0.1},
boxMax = {0,0,-0.1},
sprayAngle = {0,30},
velocity = {0,0},
texture = "assets/textures/particles/glow.tga",
lifetime = {1000000, 1000000},
colorAnimation = false,
color0 = {1, 1, 1},
opacity = 1,
fadeIn = 0.1,
fadeOut = 0.1,
size = {0.8, 0.8},
gravity = {0,0,0},
airResistance = 1,
rotationSpeed = 2,
blendMode = "Additive",
objectSpace = true,
}
}
}
You can try it in action by downloading my demo dungeon from google drive
https://docs.google.com/open?id=0B7cR7s ... UN4SGZGNEk