Page 1 of 1

Magical Melee weapon code

Posted: Sun Dec 04, 2016 9:40 pm
by LordGarth
Here is code for magical melee weapons. It will do physical and magic damage both.
Fireburst can be change to what ever spell.

GfxIndex and Gfx Atlas will have to be changed to your own.

Party will not be awareded exp though if monster is killed by the spell effect on the melee weapon.



defineObject{
name = "fflail",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/flail.fbx",
},
{
class = "Item",
uiName = "Fire Knight Flail",
gfxIndex = 34,
gfxAtlas = "mod_assets/textures/ikons2.tga",
gfxIndexPowerAttack = 423,
impactSound = "impact_blunt",
weight = 6.5,
traits = { "heavy_weapon", "mace" },
},
{
class = "MeleeAttack",
attackPower = 52,
pierce = 10,
accuracy = 10,
cooldown = 5,
swipe = "vertical",
attackSound = "swipe_heavy",
reachWeapon = true,
requirements = { "heavy_weapons", 2 },
powerAttackTemplate = "stun",
onAttack = function(self)

local obj = spawn("fireburst")

end,
},
},
tags = { "weapon" },
}

Re: Magical Melee weapon code

Posted: Mon Dec 05, 2016 12:02 am
by Isaac
An alternative onAttack() that grants XP for monsters killed by the spell; that also checks for walls, and for closed doors.
Casting against walls and closed doors now targets the party's cell (as per the game's default). The wall check also prevents casting the spell outside of the map.

Code: Select all

onAttack = function(self, champion, slot, chainIndex)
	local dX,dY = getForward(party.facing) --Directional offsets
	local tile = {party.x+dX, party.y+dY, party.elevation}
	local doorCheck = true 
	local doorFound = false
	if party.map:isWall(unpack(tile)) then
		dX,dY = 0,0 --Targets Party's cell if cast on a wall
		doorCheck = false	
	end
	if doorCheck then
		for obj in party.map:entitiesAt(unpack(tile)) do
			if obj.door and obj.facing == (party.facing+2)%4 and obj.door:isClosed() then
				dX,dY = 0,0 --Targets Party's cell if cast on a wall
				doorFound = true
				break
			end 
		end
		if not doorFound then
			tile[1], tile[2] = party.x, party.y
			for obj in party.map:entitiesAt(unpack(tile)) do
				if obj.door and obj.facing == party.facing and obj.door:isClosed() then
					dX,dY = 0,0 --Targets Party's cell if cast on a wall
					break
				end 
			end
		end
	end
	spawn("fireburst", party.level, party.x+dX, party.y+dY, party.facing, party.elevation).tiledamager:setCastByChampion(champion:getOrdinal())
end,

Re: Magical Melee weapon code

Posted: Mon Dec 05, 2016 3:42 am
by LordGarth
will try that code

thankyou

Re: Magical Melee weapon code

Posted: Mon Dec 05, 2016 6:19 am
by Isaac
After playtesting a bit, I thought I should include a version that doesn't target the party when striking doors and walls... The fireburst effect is not a secondary [deliberate] attack like the spell, or as with the fire_blade. This version simply omits the fireburst effect from the attack if the player strikes at a door, or a wall.

Code: Select all

onAttack = function(self, champion)
	local dX,dY = getForward(party.facing) --Directional offsets
	local tile = {party.x+dX, party.y+dY, party.elevation}
	local doorCheck = true 
	local doorFound = false
	if party.map:isWall(unpack(tile)) then
		return	
	end
		for obj in party.map:entitiesAt(unpack(tile)) do
			if obj.door and obj.facing == (party.facing+2)%4 and obj.door:isClosed() then
				return
			end 
		end
		if not doorFound then
			tile[1], tile[2] = party.x, party.y
			for obj in party.map:entitiesAt(unpack(tile)) do
				if obj.door and obj.facing == party.facing and obj.door:isClosed() then
					return
				end 
			end
		end
	spawn("fireburst", party.level, party.x+dX, party.y+dY, party.facing, party.elevation).tiledamager:setCastByChampion(champion:getOrdinal())
end,