Hi MasterJoe, I've got two solutions for you!
First of all, just a few things that aren't quite right with your understanding of how defineSpell works.
1. Your function definition for onCast is wrong, it should read... onCast = function(caster, x, y, direction, skill). You can't pick and choose the parameters that get passed, the given 5 parameters will always get passed - you just get to decide what name your code will use for them. As such, what you think is skill in your function is actually just using the first two parameters that are passed and calling them 'caster' and 'skill', although as you will notice above - the second parameter is the x coordinate of the party. This is probably what is causing the problem with it only sometimes working.
2. By defining your own fireburst spell, you are completely overriding the original fireburst spell description. This means that the original spell is essentially hidden away and cannot be accessed any more. However, the fireburst effect appears to still work if you call 'spawn("fireburst", level, x, y, facing)' in code - so I imagine that the spell definitions are different to the 'object' that is a fireburst in the game world.
3. onCast can only ever return true or false. True means the spell worked and false means it didn't. However, these return values have little effect on what happens next (apart from whether the mana cost of the spell should be deducted).
So, with this knowledge, we can build a simple version of your spell that will simply summon the original fireburst effect in front of the party and a more advanced version where you can emulate the fireburst effect but using your own damageTile call to actually define how much damage is caused by the spell. You probably want the second, but I include both for information.
Solution A - Spawn original FireBurst effect, but with custom mana cost.
Code: Select all
defineSpell{
name = "fireburst",
uiName = "Fireburst",
skill = "fire_magic",
level = 2,
runes = "B",
manaCost = 0,
onCast = function(caster, x, y, direction, skill)
local castingCost = 15 + math.ceil(skill / 2);
if ( caster:getStat("energy") < castingCost ) then
hudPrint(caster:getName() .. " doesn't have enough energy to cast this spell.");
return false;
end
local dx, dy = getForward(party.facing);
local targetX = party.x + dx;
local targetY = party.y + dy;
if ( isWall(party.level, targetX, targetY) ) then
targetX = party.x;
targetY = party.y;
end
caster:modifyStat("energy", -castingCost);
spawn("fireburst", party.level, targetX, targetY, party.facing);
end
}
Solution B - Fake the fireburst effect by creating the particle system and dealing damage yourself. The best thing about this is that you can determine how much damage is dealt. The bad thing is that it's a bit more complicated.
Code: Select all
defineSpell{
name = "fireburst",
uiName = "Fireburst",
skill = "fire_magic",
level = 2,
runes = "B",
manaCost = 0,
onCast = function(caster, x, y, direction, skill)
local castingCost = 15 + math.ceil(skill / 2);
local spellPower = 15 + math.ceil(skill / 2);
print(castingCost, spellPower);
if ( caster:getStat("energy") < castingCost ) then
hudPrint(caster:getName() .. " doesn't have enough energy to cast this spell.");
return false;
end
local dx, dy = getForward(party.facing);
local targetX = party.x + dx;
local targetY = party.y + dy;
local damageBitRecoil = 1;
local damageBitChamp = {};
damageBitChamp[1] = 4;
damageBitChamp[2] = 8;
damageBitChamp[3] = 16;
damageBitChamp[4] = 32;
local damageFlags = damageBitRecoil + damageBitChamp[caster:getOrdinal()];
if ( isWall(party.level, targetX, targetY) ) then
targetX = party.x;
targetY = party.y;
end
caster:modifyStat("energy", -castingCost);
spawn("fx", party.level, targetX, targetY, party.facing):setParticleSystem("fireburst"):translate(0, 1.5, 0);
damageTile(party.level, targetX, targetY, party.facing, damageFlags, "fire", spellPower);
end
}
Both of these spells currently suffer from a problem that they will work through a closed door. ie. Casting this on a closed door will still cause it to damage the other side. I'll leave it to you to fix that bug. It will likely require you to iterate through the entities in your space and the target space and look for a door entity that's in the way. If you get stuck with this, let me know - but I'll leave it with you for now!