// Nicey weapon syntax, can't compile with those though... use the base words
weapondef{

WEAPON_CUSTOM value custom

: last-weapon custom 1- ;

: WEAPON_NEW
	custom WEAPON_COUNT >= if abort" TOO MANY WEAPONDEFS" then;
	custom ' custom ++
;

: lev> parse-line evaluate ;
: tev> token evaluate ;

// General
: select: lev> sel ;
: spriteid: lev> weapons_base_id + spriteid! ;
: name: parse-line name! ;
: tags: parse-line tags! ;

: custom: WEAPON_NEW sel name: ;

// Melee
( TODO:
	- swish sound/frequency
	- hit sound/frequency
	- event handlers for HITTING and such
)
: melee_start_angle: lev> melee_start_angle! ;
: melee_end_angle: lev> melee_end_angle! ;
: melee_windup_angle: lev> melee_windup_angle! ;
: melee_weapon_angle: lev> melee_weapon_angle! ;
: melee_shift.x: lev> melee_shift.x! ;
: melee_shift.y: lev> melee_shift.y! ;
: melee_off.x: lev> melee_off.x! ;
: melee_off.y: lev> melee_off.y! ;
: melee_reach: lev> melee_reach! ;
: melee_retract: lev> melee_retract! ;
: melee_range: lev> melee_range! ;
: melee_extra_hits: lev> melee_extra_hits! ;
: melee_extra_chance: lev> melee_extra_chance! ;
: melee_break_scale: lev> melee_break_scale! ;
: melee_aiming: lev> melee_aiming! ;
: melee_aiming_offset: lev> melee_aiming_offset! ;
: melee_thrown: lev> melee_thrown! ;
: melee_thrown_lob: lev> melee_thrown_lob! ;
: melee_thrown_speed: lev> melee_thrown_speed! ;
: melee_thrown_handler: lev> melee_thrown_handler! ;
: melee_fatigue_power_scale: lev> melee_fatigue_power_scale! ;
: melee_fatigue_knockback_scale: lev> melee_fatigue_knockback_scale! ;
: melee_fatigue_cooldown_scale: lev> melee_fatigue_cooldown_scale! ;
: melee_score_scale: lev> melee_score_scale! ;
: melee_pickup_scale: lev> melee_pickup_scale! ;
: thrown_lift: lev> thrown_lift! ;
: no_zombie_break: lev> no_zombie_break! ;
: wielder_handler: lev> wielder_handler! ;
: swoosh_particle1: lev> swoosh1id! ;
: swoosh_particle2: lev> swoosh2id! ;
: swoosh_range: lev> swoosh_range! ;
: swoosh_vel: lev> swoosh_vel! ;
: thrust_range: lev> thrust_range! ;
: swoosh_dist: lev> swoosh_dist! ;
: no_held_sprite: lev> no_held_sprite! ;
: default_only: lev> default_only! ;
: leaning: lev> leaning! ;
: skin_colour: lev> skin_colour! ;
: knockback: lev> knockback! ;
: power: lev> power! ; ( value from 0 to whatever... scaling factor for random damage roll )
: cooldown: lev> cooldown! ; ( in seconds, includes swing period )
: func: lev> weaponfunc! ;
: unbreakable: lev> unbreakable! ;

: burn_idle: lev> burn_idle! ;
: burn_active: lev> burn_active! ;

// Guns
: ammo_type: lev> ammo_type! ;
: shot_knockback: lev> shot_knockback! ;
: shot_power: lev> shot_power! ; ( for damage, as above )
: shoot_thru: lev> shoot_thru! ; ( scale for bullet continue after kill )
: reload: lev> reload! ; ( seconds )
: revolver: lev> revolver! ; ( takes number of bullets as param, spits out N casings after N shots )
: projectiles: lev> projectiles! ; ( mainly for shotgun )
: spread_factor: lev> spread_factor! ; ( trajectory variance )
: boom_factor: lev> boom_factor! ; ( SCREEN SHAKE and related FX )
: gun_angle: lev> gun_angle! ; ( idle holding angle )
: gun_muzzle_height: lev> gun_muzzle_height! ; ( vertical offset for the muzzle flash )
: cock_sound: lev> cock_sound! ;
: ammo_max: lev> ammo_max! ;
: stack_max: lev> stack_max! ;
: fuel_max: lev> fuel_max! ;
: gun_skill: lev> gun_skill! ;
: laser_type: lev> laser_type! ;
: auto_eject: lev> auto_eject! ;
: auto_eject: lev> auto_eject! ;
: lengthscale: lev>	length@ * length! ;
: targeting: lev> targeting! ;
: lock_drift: lev> lock_drift! ;
: skill_angle_range: lev> skill_angle_range! ; // 15 at default
: shoot_thru_scale: lev> skill_shoot_thru_scale! ; // 1 at default

// Untested yet, maybe not bother

: range_aim_scale: lev> range_aim_scale! ;
: range_cone: lev> range_cone! ;


// Special/misc
( TODO:
	- hit check rate
	- burn check rate
)
: special_knockback: lev> special_knockback! ;
: special_power: lev> special_power! ;
: fuel_type: lev> fuel_type! ;
: burn_scale: lev> burn_scale! ;

: lightcooldown 1.5 melee_fatigue_cooldown_scale! ;
: wepscorebonus 1.5 melee_score_scale! ;
: badmelee 0.1 melee_score_scale! ;

// Sprite offsets within sheet
0 constant GUNS1
16 constant MELEE1
32 constant MELEE2
48 constant MELEE3
64 constant MELEE4
80 constant MELEE5
}

// Weapon defs
weapondef{

select: WEAPON_PUNCH
	// TODO:
	spriteid: 0
	cooldown: 0
	melee_extra_hits: 0
	swoosh_particle2: 6
	swoosh_vel: 1
	skin_colour: 1

select: WEAPON_NEW
	name: Claw
	spriteid: 0
	cooldown: 0
	melee_extra_hits: 0
	swoosh_particle2: 0x 40
	no_held_sprite: 1

select: WEAPON_NEW
	name: Karate
	spriteid: 0
	power: 0.75
	knockback: 1
	leaning: -2
	thrust_range: 4
	cooldown: 0
	melee_extra_hits: 1
	swoosh_particle1: 0x 41
	swoosh_particle2: 0x 42
	swoosh_range: 0
	no_held_sprite: 1
	melee_range: 10
	swoosh_vel: 0.25

select: WEAPON_NEW
	name: Boxing
	spriteid: 0
	power: 1
	knockback: 0.5
//	thrust_range: 3
	thrust_range: 3
	cooldown: 0
	swoosh_particle1: 0x 43
	swoosh_particle2: 0x 44
	swoosh_range: 45
	no_held_sprite: 1
	melee_range: 10
	swoosh_vel: 0.5
	skin_colour: 1

select: WEAPON_NEW
	name: Kung Fu
	spriteid: 0
	power: 1
	knockback: 0.75
	cooldown: 0
	melee_extra_hits: 1
	swoosh_particle1: 0x 47
	swoosh_particle2: 0x 48
	swoosh_range: 0
	thrust_range: 3
	no_held_sprite: 1
	melee_range: 10
	swoosh_vel: 0.5
	skin_colour: 1
	
select: WEAPON_NEW
	name: Sumo
	spriteid: 0
	power: 0.75
	knockback: 2
	cooldown: 0
	melee_extra_hits: 2
	melee_extra_chance: 0.5
	swoosh_particle1: 0x 4c
	swoosh_particle2: 0x 4d
	swoosh_range: 0
	thrust_range: 3
	no_held_sprite: 1
	melee_range: 10
	swoosh_vel: 0.5
	skin_colour: 1

// Some predefs still needed because of special functions
// TODO: fix somehow, perhaps with parameterization
// - torch type
// - chainsaw type
// - ??? type etc.

select: WEAPON_NEW
	name: Blowtorch
	spriteid: MELEE1 0x 10 +
	fuel_type: LOOT_GAS
	power: 0.4
	knockback: 0.25
	cooldown: 0.55
	func: WEAPON_FUNC_BLOWTORCH
	burn_scale: 0.25
	melee_break_scale: 0.10
	burn_active: 20 // formerly 30 or 12
	burn_idle: 120

select: WEAPON_NEW
	name: Chainsaw
	spriteid: MELEE1 0x 5 +
	fuel_type: LOOT_GAS
	power: 0.5
	special_power: 1.2
	special_knockback: 0.25
	knockback: 1
	cooldown: 1.25
	melee_start_angle: -85
	melee_windup_angle: -180
	melee_end_angle: 90
	func: WEAPON_FUNC_CHAINSAW
	melee_break_scale: 0.10
	burn_active: 40
	burn_idle: 160

// CUSTOM WEAPONS
select: WEAPON_NEW
	name: Baseball bat
	spriteid: MELEE1 4 +
	knockback: 2				// knockback impulse scale
	power: 1					// damage power scale - damage is calculated as a random number between 1 and 5, scaled by POWER
	cooldown: 0.75				// in seconds
	melee_break_scale: 0.02 	// 2%

select: WEAPON_NEW
	name: Nail board
	spriteid: MELEE1 3 +
	power: 1.3
	knockback: 3
	cooldown: 1.5
	melee_shift.x: -3
	melee_start_angle: 75
	melee_reach: 5
	melee_break_scale: 0.05 	// 5%
	melee_extra_hits: 2
	lightcooldown

select: WEAPON_NEW
	spriteid: MELEE1 1 +
	name: Wrench
	power: 1.3
	knockback: 1
	cooldown: 1.00
	melee_shift.x: -3
	melee_reach: 5
	melee_break_scale: 0
	
select: WEAPON_NEW
	name: Sledgehammer
	spriteid: MELEE1 2 +
	power: 1.5
	knockback: 3
	cooldown: 1.2
	melee_shift.x: -3
	melee_start_angle: 60
	melee_reach: 5
	melee_break_scale: 0
	melee_extra_hits: 1
	melee_extra_chance: 0.6
	
select: WEAPON_NEW
	name: Kitchen knife
	spriteid: MELEE1 9 +
	power: 0.75
	knockback: 0.25
	melee_start_angle: 90
	melee_windup_angle: 120
	melee_end_angle: -120
	melee_weapon_angle: -120
	melee_reach: 10
//	melee_shift.x: 3
//	melee_shift.y: 3
	melee_off.x: 4
	melee_off.y: 1
	melee_break_scale: 0.01  // 1%
	lightcooldown

select: WEAPON_NEW
	name: Meat cleaver
	spriteid: MELEE1 
	power: 0.75
	knockback: 0.25
	melee_break_scale: 0.0025
	melee_extra_hits: 1
	lightcooldown

select: WEAPON_NEW
	name: Spatula
	spriteid: MELEE1 11 +
	power: 0
	knockback: 0.1
	melee_break_scale: 0.25
	melee_end_angle: -120
	no_zombie_break: 1 // NO BREAKS WHEN SLAPPING ZOMBIES WITH A SPATULA
	melee_pickup_scale: 0.1

select: WEAPON_NEW
	name: Hatchet
	spriteid: MELEE1 10 +
	power: 1.25
	knockback: 0.5
	cooldown: 0.75
	melee_break_scale: 0
	melee_reach: 5
	melee_extra_hits: 1
	melee_extra_chance: 0.1

	
// Before was estimating 2 clips for each gun, now more like 6

select: WEAPON_NEW
	name: Cowboy rifle
	spriteid: GUNS1 10 +
	gun_muzzle_height: 2
	ammo_type: LOOT_RIFLE_SHELL
	cock_sound: 2
	boom_factor: 2
	shot_power: 3
	cooldown: 1
	reload: 1
	power: 0.40
	knockback: 1
	func: WEAPON_FUNC_SHOOT
	melee_windup_angle: 0
	melee_end_angle: 225
	melee_reach: -16
	shoot_thru: 0.2
	shot_knockback: 1.5
	ammo_max: 50
	melee_break_scale: 0.02
	melee_range: -5
	skill_angle_range: 20
	badmelee

select: WEAPON_NEW
	name: Hunting rifle
	spriteid: GUNS1 1 +
	gun_muzzle_height: 2
	ammo_type: LOOT_RIFLE_SHELL
	cock_sound: 2
	boom_factor: 3
	shot_power: 4
	cooldown: 1
	reload: 1.3
	power: 0.40
	knockback: 1
//	projectiles: 1
	func: WEAPON_FUNC_SHOOT
	melee_windup_angle: 0
	melee_end_angle: 225
	melee_reach: -16
// melee_range ???
	shoot_thru: 0.3
	shot_knockback: 2
	ammo_max: 50
	melee_break_scale: 0.02
	melee_range: -5
	skill_angle_range: 22
	badmelee

// Knockback is PER BULLET
select: WEAPON_NEW
	name: Shotgun
	spriteid: GUNS1 2 +
	gun_muzzle_height: 3
	ammo_type: LOOT_SHOTGUN_SHELL
	cock_sound: 2
	boom_factor: 3
	shot_power: 0.5
	spread_factor: 4
	cooldown: 0.75
	reload: 1
	power: 0.40
	knockback: 1
	projectiles: 5
	func: WEAPON_FUNC_SHOOT
	lengthscale: 0.5
	melee_windup_angle: 0
	melee_end_angle: 225
	melee_reach: -16
	shoot_thru: 0.1
	shot_knockback: 1.5
	ammo_max: 40
	melee_break_scale: 0
	skill_angle_range: 25
	
select: WEAPON_NEW
	name: Autoshotgun
	spriteid: GUNS1 9 +
	gun_muzzle_height: 3
	ammo_type: LOOT_SHOTGUN_SHELL
	cock_sound: 2
	boom_factor: 3
	shot_power: 0.5
	spread_factor: 4
	cooldown: 0.75
	reload: 0.4
	power: 0.40
	knockback: 1
	projectiles: 5
	func: WEAPON_FUNC_SHOOT
	lengthscale: 0.5
	melee_windup_angle: 0
	melee_end_angle: 225
	melee_reach: -16
	shoot_thru: 0.1
	shot_knockback: 1.5
	auto_eject: 1
	ammo_max: 80
	melee_break_scale: 0.02
	skill_angle_range: 25
	badmelee
	
select: WEAPON_NEW
	name: Slug Shotgun
	spriteid: GUNS1 13 +
	gun_muzzle_height: 3
	ammo_type: LOOT_SHOTGUN_SHELL
	cock_sound: 2
	boom_factor: 4
	shot_power: 5
	spread_factor: 1
	cooldown: 0.75
	reload: 1.5
	power: 0.40
	knockback: 1
	func: WEAPON_FUNC_SHOOT
	lengthscale: 0.5
	melee_windup_angle: 0
	melee_end_angle: 225
	melee_reach: -16
	shoot_thru: 0.30
	shot_knockback: 3
	ammo_max: 40
	melee_break_scale: 0.02
	skill_angle_range: 25
	badmelee
	
select: WEAPON_NEW
	name: BIG DAWG
	spriteid: GUNS1 8 +
	gun_muzzle_height: 3
	ammo_type: LOOT_SHOTGUN_SHELL
	cock_sound: 2
	boom_factor: 4
	shot_power: 0.7
	spread_factor: 5
	cooldown: 0.75
	reload: 1.4
	power: 0.40
	knockback: 1
	projectiles: 7
	func: WEAPON_FUNC_SHOOT
	lengthscale: 0.5
	melee_windup_angle: 0
	melee_end_angle: 225
	melee_reach: -16
	shoot_thru: 0.1
	shot_knockback: 4
	ammo_max: 40
	melee_break_scale: 0
	skill_angle_range: 30
	
select: WEAPON_NEW
	name: Dolt 45
	spriteid: GUNS1 3 +
	gun_muzzle_height: 3
	cock_sound: 1
	ammo_type: LOOT_BULLET	
	boom_factor: 1.5
	spread_factor: 1
	shot_power: 2.5
	reload: 1
	cooldown: 0.5
	power: 0.40
	knockback: 0.5
	shoot_thru: 0.15
	shot_knockback: 1
	func: WEAPON_FUNC_SHOOT
	revolver: 6
	ammo_max: 60
	melee_break_scale: 0
	skill_angle_range: 20


select: WEAPON_NEW
	name: Pistol
	spriteid: GUNS1 4 +
	gun_muzzle_height: 3
	ammo_type: LOOT_BULLET
	spread_factor: 0
	shot_power: 1.5
	power: 0.40
	knockback: 0.5
	lengthscale: 0.5
	shoot_thru: 0.1
	shot_knockback: 1
	ammo_max: 90
	func: WEAPON_FUNC_SHOOT
	auto_eject: 1
	melee_break_scale: 0

select: WEAPON_NEW
	name: Snubnose
	spriteid: GUNS1 6 +
	gun_muzzle_height: 3
	ammo_type: LOOT_BULLET
	spread_factor: 2
	reload: 0.7
	power: 0.40
	knockback: 0.5
	shot_knockback: 1.5
	shot_power: 2
	lengthscale: 0.5
	shoot_thru: 0.1
	func: WEAPON_FUNC_SHOOT
	revolver: 6
	ammo_max: 60
	skill_angle_range: 20
	shoot_thru_scale: 0.5
	melee_break_scale: 0

select: WEAPON_NEW
	name: Uzi
	spriteid: GUNS1 5 +
	gun_muzzle_height: 2
	ammo_type: LOOT_BULLET
	boom_factor: 0.75
	spread_factor: 3
	shot_power: 1.2
	reload: 0.125
	cooldown: 0.75
	power: 0.40
	knockback: 0.25
	shoot_thru: 0.1
	shot_knockback: 1.5
	ammo_max: 160
	func: WEAPON_FUNC_SHOOT
	skill_angle_range: 25
	shoot_thru_scale: 0.5
	badmelee

select: WEAPON_NEW
	name: AK47
	spriteid: GUNS1 7 +
	gun_muzzle_height: 2
	ammo_type: LOOT_RIFLE_SHELL
	boom_factor: 2
	spread_factor: 2
	shot_power: 2.5
	reload: 0.20 // maybe try 0.3 or 0.25
	cooldown: 0.75
	power: 0.40
	knockback: 1
	melee_windup_angle: 0
	melee_end_angle: 225
	melee_reach: -16
	shoot_thru: 0.1
	shot_knockback: 2
	ammo_max: 150
	func: WEAPON_FUNC_SHOOT
	skill_angle_range: 22
	shoot_thru_scale: 0.5
	melee_break_scale: 0

select: WEAPON_NEW
	name: Cane
	spriteid: MELEE3
	knockback: 1
	power: 1
	cooldown: 0.85
	melee_break_scale: 0.02
	lightcooldown
	
select: WEAPON_NEW
	name: Frying Pan
	spriteid: MELEE3 1 +
	knockback: 1
	power: 1
	cooldown: 0.9
	
select: WEAPON_NEW
	name: Otaku katana
	spriteid: MELEE1 12 +
	melee_start_angle: -45
	melee_end_angle: -135
	melee_shift.x: -3
	melee_reach: -7
	knockback: 0.25
	power: 2
	cooldown: 0.6
	melee_break_scale: 0.05 	// 5%
	melee_extra_hits: 2
	melee_extra_chance: 0.6
	lightcooldown

select: WEAPON_NEW
	name: Piece of wood
	spriteid: MELEE1 0x e +
	knockback: 1
	power: 0.75
	cooldown: 0.5
	melee_break_scale: 0.1
	2 melee_off.y!
	-2 melee_off.x!
	melee_reach: 8
	melee_pickup_scale: 0.1

select: WEAPON_NEW
	name: Crowbar
	spriteid: MELEE1 0x f +
	knockback: 2
	power: 1.5
	cooldown: 1.1
	melee_break_scale: 0

select: WEAPON_NEW
	name: Nightstick
	spriteid: MELEE1 0x d +
	knockback: 1.5
	power: 0.8
	cooldown: 0.65
	melee_break_scale: 0
	wepscorebonus

select: WEAPON_NEW
	name: Cricket bat
	spriteid: MELEE1 0x 12 +
	knockback: 2.2
	power: 1.1
	cooldown: 0.7
	melee_break_scale: 0.01
	lightcooldown

select: WEAPON_NEW
	name: Aluminum bat
	spriteid: MELEE1 0x 14 +
	knockback: 2
	power: 1
	cooldown: 0.75
	melee_break_scale: 0
	wepscorebonus

select: WEAPON_NEW
	name: Femur
	spriteid: MELEE1 0x 13 +
	knockback: 1
	power: 0.75
	cooldown: 0.5
	melee_break_scale: 0.05
	melee_pickup_scale: 0.1

select: WEAPON_NEW
	name: Golf Club
	spriteid: MELEE2 5 +
	knockback: 2
	power: 0.5
	cooldown: 0.55
	melee_break_scale: 0.02
	lightcooldown
	
select: WEAPON_NEW
	name: Medieval Axe
	spriteid: MELEE2 6 +
	knockback: 2
	power: 3
	cooldown: 1.75
	melee_break_scale: 0
	melee_extra_hits: 2
	wepscorebonus
	
custom: Strong Katana
	tags: truekatana
	spriteid: MELEE1 12 +
	melee_start_angle: -45
	melee_end_angle: -135
	melee_shift.x: -3
	melee_reach: -7
	knockback: 0.25
	power: 2
	cooldown: 0.8
	melee_break_scale: 0
	melee_extra_hits: 2
	melee_extra_chance: 0.6
	lightcooldown
	wepscorebonus
	
select: WEAPON_NEW
	name: Knight Sword
	spriteid: MELEE2 8 +
	knockback: 1.5
	power: 2.5
	cooldown: 1.3
	melee_break_scale: 0
	melee_extra_hits: 1
	wepscorebonus
	
select: WEAPON_NEW
	name: Claymore
	spriteid: MELEE2 9 +
	knockback: 3
	power: 3.5
	cooldown: 1.6
	melee_break_scale: 0
	melee_extra_hits: 3
	melee_extra_chance: 0.6
	-2 melee_off.y!
	3 melee_off.x!
	melee_reach: 6
	melee_range: 9
	wepscorebonus
	
select: WEAPON_NEW
	name: Fire Axe
	spriteid: MELEE2 0x a +
	knockback: 2
	power: 2
	cooldown: 1.2
	melee_break_scale: 0
	melee_extra_hits: 1
	melee_extra_chance: 0.5

select: WEAPON_NEW
	name: Umbrella
	spriteid: MELEE2 0x e +
	knockback: 1.5
	power: 0.5
	cooldown: 0.7
	melee_break_scale: 0.02
	melee_extra_hits: 1
	lightcooldown
	
select: WEAPON_NEW
	name: Beach Umbrella
	spriteid: MELEE2 0x b +
	knockback: 2
	power: 0.75
	cooldown: 0.9
	melee_shift.x: -3
	melee_start_angle: 60
	melee_reach: 5
	melee_break_scale: 0.02
	melee_extra_hits: 2
	wepscorebonus
	
select: WEAPON_NEW
	name: Hockey Stick
	spriteid: MELEE2 0x c +
	knockback: 2
	power: 0.75
	cooldown: 0.65
	melee_reach: 5
	melee_break_scale: 0.02
	lightcooldown

select: WEAPON_NEW
	name: Xtreme Hockey Stick
	spriteid: MELEE2 0x d +
	knockback: 4
	power:  1
	cooldown: 0.65
	melee_break_scale: 0
	melee_extra_hits: 1
	melee_extra_chance: 0.3
	lightcooldown
	wepscorebonus
	
select: WEAPON_NEW
	name: Mountie Hockey Stick
	spriteid: MELEE2 0x d +
	knockback: 8 // 4
	power: 1
	cooldown: 0.65
	melee_break_scale: 0
	melee_extra_hits: 4
	melee_extra_chance: 0.7
	lightcooldown

select: WEAPON_NEW
	name: Cardboard Tube
	spriteid: MELEE2 0x f +
	knockback: 8
	power: 0
	cooldown: 0.5
	melee_break_scale: 0.05
	melee_extra_hits: 1
	lightcooldown
	wepscorebonus
	
select: WEAPON_NEW
	name: Pitchfork
	spriteid: MELEE3 2 +
	knockback: 1
	power: 1.5
	cooldown: 1.2
	melee_break_scale: 0.001
	melee_break_scale: 0
	melee_extra_hits: 2
	
	melee_start_angle: 0
	melee_windup_angle: 0
	melee_end_angle: melee_start_angle@
	melee_aiming: 1
	melee_reach: 20
	melee_retract: 0.75
	melee_range: 8
	melee_aiming_offset: 4
	swoosh_particle1: 0x 45
	swoosh_particle2: 0x 46
	swoosh_range: 0
	thrust_range: 8
	swoosh_vel: 1

	leaning: 0
	
select: WEAPON_NEW
	name: Shovel
	spriteid: MELEE3 3 +
	knockback: 2
	power: 1.5
	cooldown: 1.3
	melee_break_scale: 0.001
	melee_extra_hits: 2
	melee_extra_chance: 0.5
	
select: WEAPON_NEW
	name: Tree Branch
	spriteid: MELEE3 4 +
	knockback: 0.5
	power: 0.5
	cooldown: 0.5
	melee_break_scale: 0.05
	
select: WEAPON_NEW
	name: Metal Pipe
	spriteid: MELEE3 5 +
	power: 2
	knockback: 2
	cooldown: 1.35
	melee_start_angle: 60
	melee_reach: 5
	melee_break_scale: 0
	
select: WEAPON_NEW
	name: Rusty Machete
	tags: machete1
	spriteid: MELEE3 6 +
	knockback: 1
	power: 1.5
	cooldown: 0.86
	melee_break_scale: 0.005
	melee_extra_hits: 1
	melee_extra_chance: 0.2
	lightcooldown
	
select: WEAPON_NEW
	name: Sturdy Machete
	tags: machete2
	spriteid: MELEE3 7 +
	knockback: 1
	power: 2
	cooldown: 0.86
	melee_break_scale: 0
	melee_extra_hits: 1
	melee_extra_chance: 0.2
	lightcooldown
	wepscorebonus
	
select: WEAPON_NEW
	name: Parking Meter
	spriteid: MELEE3 8 +
	power: 2
	knockback: 2
	cooldown: 1.55
	melee_shift.x: 1
	melee_start_angle: 60
	melee_reach: 7
	melee_break_scale: 0
	melee_extra_hits: 4
	melee_extra_chance: 0.3
	
select: WEAPON_NEW
	name: Lovely Wand
	spriteid: MELEE3 9 +
	knockback: 1.5
	power: 0.5
	cooldown: 0.5
	melee_break_scale: 0
	melee_aiming: 0
	lightcooldown
	
mission{

		thing-event: lovebeam-glow
			eventid THING_EVENT_TIMER <> if exit then

			1 me .timer! 

			particle{ new me .pos pos! }
//				me .spriteid@ particle{ spriteid! }
				me .spriteid@ particle{ particles32_base_id 9 + spriteid! }
				me .angle@ particle{ 180 + angle! }
				me .flip@ particle{ not flipx! }
				particle{
					5 ticks!
					0.25 clr.g!
					0.5 clr.b!
					madticks 30 * sin 0.4 * 0.4 + clr.r!
					madticks 60 * sin 0.3 * 0.7 + scale!
					0.95 grow!
					5 fade_out!

					pcopy glowy 15 ticks! ticks@ fade_out!
					0.9 grow!
					madticks 180 + 30 * sin 0.5 * 0.5 + scale!
					madticks 180 + 30 * sin 0.4 * 0.4 + clr.r!
					madticks 180 + 60 * sin 0.3 * 0.7 + scale!
					}
		;

		: lovebeam locals( b )

			10 3 * me .action_cooldown!
			
			blast -> b
			8 <- b .hitcheck.rad!
			45 <- b .anim.counter!
			me .pos3 <- b .pos.z! <- b .pos.y! <- b .pos.x! 

//			particles32_base_id 9 + <- b .spriteid!
			0 <- b .spriteid!

			3 <- b .hitcheck.knockback!
			1 <- b .hitcheck.power!
			me .flip@ <- b .flip!
			
			1 <- b .anim.extra!

			mission{ ' lovebeam-glow <- b .events! }
			
			1 <- b .timer!

			me .aim_angle@ anglexy 3 xymul <- b .vel.y! <- b .vel.x!
			// Tried removing below line to make the heart always in the right angle, but it would just get changed by the bounce anyway
			me .aim_angle@ <- b .angle!

			sfx{ noise 1 fx .pitch!
				1000 fx .freq!
				50 fx .freq2!
				50 fx .a! 
				50 fx .d! 
				0.25 fx .s!
				550 fx .r! 
				0.5 fx .q!
				1000 fx .filt!
				0.75 1 frnd fx .pitch!
				0.5 fx .scale!
				}
			me .adjust-vol
		;

		: lovewand-commands
			me .action_cooldown@ if exit then
			me .isattack? not if exit then
			me .carryid@ if exit then
			me #character .specialtype@ 65 = 10 %chance and if
				0 me #character .health! me .pos 6 xypowboom
			then
			lovebeam
		;

thing-event: lovewand-events
	eventid THING_EVENT_SWING = if
		lovewand-commands
	then
;
}
		
	wielder_handler: last
	
select: WEAPON_NEW
	name: Rapier
	spriteid: MELEE3 0x a +
	knockback: 0
	power: 1.6
	cooldown: 0.15
	melee_break_scale: 0
	melee_start_angle: 0
	melee_windup_angle: 0
	melee_end_angle: melee_start_angle@
	melee_aiming: 1
	melee_reach: 20
	melee_retract: 0.75
	melee_range: 8
	melee_aiming_offset: 4
	swoosh_particle1: 0x 45
	swoosh_particle2: 0x 46
	swoosh_range: 0
	thrust_range: 8
	swoosh_vel: 1

	leaning: 0
	lightcooldown

select: WEAPON_NEW
	name: Toy Hammer
	spriteid: MELEE3 0x b +
	knockback: 5
	power: 0
	cooldown: 0.9
	melee_break_scale: 0

select: WEAPON_NEW
	name: Gauntlet
	spriteid: MELEE3 0x c +
	knockback: 2
	power: 1
	cooldown: 0.8
	melee_break_scale: 0	
//	melee_weapon_angle: -55
	melee_windup_angle: -200
	melee_start_angle: -160
	melee_end_angle: 0
	melee_weapon_angle: 90
	melee_shift.x: -2
	melee_reach: 15	
	
select: WEAPON_NEW
	name: Punchquest Gauntlet
	spriteid: MELEE3 0x c +
	knockback: 2
	power: 1
	cooldown: 0.6
	melee_break_scale: 0	
//	melee_weapon_angle: -55
	melee_windup_angle: -200
	melee_start_angle: -160
	melee_end_angle: 0
	melee_weapon_angle: 90
	melee_shift.x: -2
	melee_reach: 15

select: WEAPON_NEW
	name: Boxing Glove
	spriteid: MELEE3 0x d +
	knockback: 1.5
	power: 0.75
	cooldown: 0.5
	melee_break_scale: 0
	melee_shift.x: 1
	melee_shift.y: -1
	melee_start_angle: 65
	melee_end_angle: -120
	melee_weapon_angle: -90
	melee_reach: 10
	leaning: 2

select: WEAPON_NEW
	name: Uppercut
	spriteid: MELEE3 0x d +
	knockback: 3
	power: 1
	cooldown: 1.3
	melee_break_scale: 0
	melee_windup_angle: -270
	melee_start_angle: -160
	melee_end_angle: -45
	melee_weapon_angle: 90
	melee_shift.y: 0
	melee_reach: 15
	melee_extra_hits: 1
	leaning: -1

select: WEAPON_NEW
	name: Morning Star
	spriteid: MELEE3 0x 10 +
	knockback: 3
	power: 2.5
	melee_shift.x: 2
	melee_shift.y: -2
	cooldown: 1.5
	melee_break_scale: 0
	melee_start_angle: 120
	melee_end_angle: -240
	melee_reach: 20
	melee_range: 10
	melee_extra_hits: 4
	melee_extra_chance: 0.5
//	melee_extra_chance: 1 // for testing

select: WEAPON_NEW
	name: Pool1
	spriteid: MELEE3 0x e +
	knockback: 0.5
	power: 0
	cooldown: 0.8
	melee_break_scale: 0
	
select: WEAPON_NEW
	name: Pool2
	spriteid: MELEE3 0x f +
	knockback: 0.5
	power: 0
	cooldown: 0.8
	melee_break_scale: 0

// Special char weapons
	
select: WEAPON_NEW
	name: Debutante Umbrella
	spriteid: MELEE2 0x e +
	knockback: 1.5
	power: 0.8
	cooldown: 0.7
	melee_break_scale: 0
	melee_extra_hits: 1
	lightcooldown

select: WEAPON_NEW
	name: Mason Machete
	spriteid: MELEE4 4 + 
	power: 2
	cooldown: 0.86
	knockback: 0.35
	melee_break_scale: 0
	melee_extra_hits: 3
	melee_extra_chance: 0.3
	lightcooldown

select: WEAPON_NEW
	name: Rambeux Knife
	spriteid: MELEE4 3 +
	power: 1.2
	melee_extra_hits: 1
	knockback: 0.25
	melee_start_angle: 90
	melee_windup_angle: 120
	melee_end_angle: -120
	melee_weapon_angle: -120
	melee_reach: 10
	melee_off.x: 4
	melee_off.y: 1
	melee_break_scale: 0
	lightcooldown

select: WEAPON_NEW
	name: Minigun
	spriteid: GUNS1 0x b +
	gun_muzzle_height: 2
	ammo_type: LOOT_RIFLE_SHELL
	boom_factor: 3
	spread_factor: 5
	shot_power: 2.5
	reload: 0.1
	cooldown: 1.5
	power: 0.5
	knockback: 2
	melee_start_angle: -100
	melee_windup_angle: -190
	melee_end_angle: 90
	melee_reach: 0
	shoot_thru: 0.2
	shot_knockback: 4
	ammo_max: 400
	func: WEAPON_FUNC_SHOOT
	melee_break_scale: 0

select: WEAPON_NEW
	name: Ridiculous Pistol
	spriteid: GUNS1 4 +
	gun_muzzle_height: 3
	ammo_type: LOOT_BULLET
	boom_factor: 10
	spread_factor: 0
	shot_power: 1
	power: 0.40
	reload: 0.55
	knockback: 0.5
	lengthscale: 0.5
	shoot_thru: 0.1
	shot_knockback: 1
	ammo_max: 100
	func: WEAPON_FUNC_SHOOT
	auto_eject: 1
	melee_break_scale: 0
	
select: WEAPON_NEW
	name: Vlambeer Shotgun
	spriteid: GUNS1 2 +
	gun_muzzle_height: 3
	ammo_type: LOOT_SHOTGUN_SHELL
	cock_sound: 2
	boom_factor: 10
	shot_power: 0.5
	spread_factor: 4
	cooldown: 0.75
	reload: 0.35
	power: 0.40
	knockback: 1
	projectiles: 6
	func: WEAPON_FUNC_SHOOT
	lengthscale: 0.5
	melee_windup_angle: 0
	melee_end_angle: 225
	melee_reach: -16
	shoot_thru: 0.1
	shot_knockback: 1
	ammo_max: 50
	melee_break_scale: 0
	
select: WEAPON_NEW
	name: Ninja katana
	spriteid: MELEE1 12 +
	melee_start_angle: -45
	melee_end_angle: -135
	melee_shift.x: -3
	melee_reach: -7
	knockback: 0.25
	power: 2
	cooldown: 0.6
	melee_break_scale: 0
	melee_extra_hits: 2
	melee_extra_chance: 0.6
	lightcooldown	

mission{

		: ticksin madticks 30 * + sin 0.5 * 0.5 + ;

		thing-event: linkbolt-glow
			eventid THING_EVENT_FREE = if then
			eventid THING_EVENT_TIMER <> if exit then

			1 me .timer! 

			particle{
				new me .pos pos! 

				particles_base_id
				me .anim.info@ WEAPON_HERO = if 0x 4b else 0x 4a then
				+ spriteid! 
			}

			me .angle@ particle{ angle! }
			me .flip@ particle{ not flipx! }
			particle{
				2 ticks!
				0 ticksin dup * dup * clr.r!
				120 ticksin dup * dup * clr.g!
				240 ticksin dup * dup * clr.b!
				ticks@ fade_out!

				pcopy glowy 5 ticks! ticks@ fade_out!

				0 180 + ticksin dup * dup * clr.r!
				120 180 + ticksin dup * dup * clr.g!
				240 180 + ticksin dup * dup * clr.b!

				1.1 grow!
				}
		;

		: linkbolt locals( b )

			60 me .action_cooldown!

			blast -> b
			8 <- b .hitcheck.rad!
			45 <- b .anim.counter!
			me .pos3 <- b .pos.z! <- b .pos.y! <- b .pos.x! 

			me .wielded <- b .anim.info!

			3 <- b .hitcheck.knockback!
			1 <- b .hitcheck.power!
			me .flip@ <- b .flip!

			me .aim_angle@ anglexy 8 xymul
				<- b .pos.y@ + <- b .pos.y!
				<- b .pos.x@ + <- b .pos.x!

			0 <- b .anim.extra!

			mission{ ' linkbolt-glow <- b .events! }
			
			1 <- b .timer!

			me .aim_angle@ anglexy 3 xymul <- b .vel.y! <- b .vel.x!
			me .aim_angle@ <- b .angle!

			sfx{ zelda }
			me .adjust-vol
		;

		: linkbolt-commands
			me .character@ .health@ STAT_VITALITY me .character@ .stat@ < if exit then
			me .action_cooldown@ if exit then
			me .isattack? not if exit then
			me .carryid@ if exit then
			linkbolt
		;


thing-event: linksword-events
	eventid THING_EVENT_SWING = if
		linkbolt-commands
	then
;
}

custom: Take This
	tags: woodsword
	spriteid: MELEE4 1+
	knockback: 1
	power: 0.75
	cooldown: 0.5
	melee_break_scale: 0
	melee_start_angle: 0
	melee_windup_angle: 0
	melee_end_angle: melee_start_angle@
	melee_aiming: 1
	melee_reach: 10
	melee_retract: 0.75
	melee_range: 4
	melee_aiming_offset: 4
	swoosh_particle1: 0x 45
	swoosh_particle2: 0x 46
	swoosh_range: 0
	thrust_range: 8
	leaning: 0


custom: White Sword
	tags: whitesword
	spriteid: MELEE4 2 +
	knockback: 2
	power: 1
	cooldown: 0.5
	melee_break_scale: 0
	melee_start_angle: 0
	melee_windup_angle: 0
	melee_end_angle: melee_start_angle@
	melee_aiming: 1
	melee_reach: 10
	melee_retract: 0.75
	melee_range: 4
	melee_aiming_offset: 4
	swoosh_particle1: 0x 45
	swoosh_particle2: 0x 46
	swoosh_range: 0
	thrust_range: 8
	leaning: 0
	wielder_handler: last

custom: M#ster Sword
	tags: hero
	spriteid: MELEE2 7 +
	knockback: 1
	power: 1.5
	cooldown: 0.5
	melee_break_scale: 0
	melee_extra_hits: 1
	wielder_handler: last

custom: Grenade
	spriteid: GUNS1 15 +
	power: 0
	melee_thrown: 1
	melee_thrown_lob: 2
	stack_max: 5

mission{

thing-event: grenade-events
	eventid THING_EVENT_THROW = if
		120 me .timer! 1 me .mass!
		15 me .hitpoints!
		1 me .lob_mode!
		0.1 me .mass!
		1 me .no_hit!
		90 me .flipx * me .rot!
		then

	eventid THING_EVENT_BOUNCE = if
		me .angle@ me .rot@ + me .angle!
	then

	eventid THING_EVENT_TIMER = if
		me .pos 5 xypowboom
		me silentkillit
		then
;

	melee_thrown_handler: last
}

custom: Pipe bomb
	tags: pipebomb
	spriteid: GUNS1 14 +
	power: 0
	melee_thrown: 1
	melee_thrown_lob: 2
	stack_max: 5

mission{

: flipx 2 * 1 - ;
: .flipx .flip@ flipx ;

210 constant PIPETIME

: fusescale me .anim.counter@ PIPETIME / ;

: pipefuse
	me .pos3 particle{ new pos3! 4 ticks! spriteid@ 0x 1 + spriteid! }
	me .angle@ 90 me .flip@ flipx * - anglexy 7 4 fusescale * + xymul

	particle{ pos@ xyadd pos! } flameflicker

	rnd5050 if sfx{ noise 50 fx .a! 5 fx .d! 0.75 1 frnd 20 * fx .pitch! 0.1 fx .scale! 1500 fx .filt_high! }
		me .pos xy-vol 
	then
;

thing-event: pipe-events
	eventid THING_EVENT_THROW = if
		PIPETIME me .anim.counter! 1 me .timer!
		-15 me .flipx * me .rot!
		15 me .hitpoints!
		1 me .lob_mode!
		0.1 me .mass!
		1 me .no_hit!
	then

	eventid THING_EVENT_BOUNCE = if
		me .rot@ -0.5 * me .rot!
	then

	eventid THING_EVENT_TIMER = if
		me .anim.counter@ if
			1 me .timer!
			pipefuse
			me .angle@ me .rot@ + me .angle!

			me .rot@ abs 5 < if
				0 me .rot!
				0 me .angle!
			then

			exit
		then

		me .pos 2 xypowboom sfx{ 6 fx .pitch@ * fx .pitch! }
		me silentkillit
	then
;

	melee_thrown_handler: last
}

custom: Lnk Bomb
	tags: lnkbomb
	spriteid: MELEE5 1 +
	melee_thrown: 1
	melee_thrown_lob: 1
	stack_max: 3

mission{

thing-event: lnkbomb-events
	eventid THING_EVENT_THROW = if
		PIPETIME me .anim.counter! 1 me .timer!
		-15 me .flipx * me .rot!
		15 me .hitpoints!
	then

	eventid THING_EVENT_BOUNCE = if
		me .rot@ -0.5 * me .rot!
	then

	eventid THING_EVENT_TIMER = if
		me .anim.counter@ if
			1 me .timer!
			pipefuse
			me .angle@ me .rot@ + me .angle!

			me .rot@ abs 5 < if
				0 me .rot!
				0 me .angle!
			then

			exit
		then

		me .pos 1 xypowboom sfx{ 6 fx .pitch@ * fx .pitch! }
		me silentkillit
	then
;

	melee_thrown_handler: last
}

custom: Bottle
	spriteid: MELEE4 5 +
	melee_thrown: 1
//	melee_thrown_lob: 1
	melee_thrown_speed: 2
	stack_max: 6

mission{
thing-event: bottle-events
	eventid THING_EVENT_THROW = if
		1 me .timer!
		12 me .rad.z!
		-20 me .flipx * me .rot!
	then

	eventid THING_EVENT_BREAK = if
		5 me .smashybits
		sfx{ glass me .adjust-vol } // noise 0.2 fx .s! 250 fx .r! 8 fx .pitch! me .adjust-vol 
	then

	eventid THING_EVENT_TIMER = if
		1 me .timer!
		me .angle@ me .rot@ + me .angle!
	then

	eventid THING_EVENT_BOUNCE = eventid THING_EVENT_WALL = or if
		me .timer@ if
			me .smack me killit
		then
	then
}
;

	melee_thrown_handler: last

custom: Kunai
	spriteid: MELEE4 0x 7 +
	power: 1
	knockback: 0.25
	cooldown: 0.5
	melee_break_scale: 0

	melee_start_angle: -250
	melee_windup_angle: -280
	melee_end_angle: 120 360 +

	melee_shift.x: -8
	melee_shift.y: 2

	// Because ninja
	melee_extra_hits: 3
//	melee_extra_chance: 0.6 // BECAUSE NINJA I SAID

	leaning: -2

mission{
	thing-event: kunai-events
		eventid THING_EVENT_SWING = if
			sfx{ ringmod me .adjust-vol 30 fx .delay! 25 fx .d! 3.75 4.25 frnd fx .pitch!
			fx .freq@ 1.2 * fx .freq2! 0.1 fx .s! 250 fx .r! fx .scale@ 0.5 * fx .scale! }
		then
	;
}

	wielder_handler: last


custom: Shuriken
	spriteid: MELEE4 6 +
	cooldown: 0.2
	melee_thrown: 1
	melee_thrown_speed: 3
	melee_thrown_lob: 0.5
	thrown_lift: 0.75
	melee_shift.y: 0
	melee_shift.x: 1
	stack_max: 12

mission{
thing-event: shuriken-events
	eventid THING_EVENT_THROW = if
		1 me .timer!
		16 me .rad.z!
		-27 me .flipx * me .rot!
	then

	eventid THING_EVENT_TIMER = if
		me .anim.info@ 0= if 1 me .timer! then
		me .angle@ 2 * abs 360 %
		me .angle@ me .rot@ + me .angle!
		me .angle@ 2 * abs 360 % - 180 > if
		sfx{ noise 0.25 fx .scale! me .adjust-vol 25 fx .a! 5 fx .d! 0.9 1.1 frnd 5 * fx .pitch! 1000 fx .filt_high! }
		then
	then

	eventid THING_EVENT_BOUNCE = if
		1 me .anim.info!
//		sfx{ ringmod me .adjust-vol 37 fx .d! 5.5 6.5 frnd 1.25 * fx .pitch! 0 fx .r! }
	then

	eventid THING_EVENT_WALL = me .anim.info@ 0= and if
		sfx{ ringmod me .adjust-vol 75 fx .d! 5.5 6.5 frnd fx .pitch! 150 fx .r! }
	then
;
}
	melee_thrown_handler: last

custom: Smoke Bomb
	tags: smokebomb
	spriteid: MELEE4 8 +
	melee_thrown: 1
	melee_thrown_speed: 0
	melee_thrown_lob: 2
	melee_start_angle: -90
	melee_end_angle: -90
	melee_windup_angle: -90
	melee_shift.y: 0
	melee_shift.x: -1
	stack_max: 5

mission{

: smokepoof 1 5 for
	me .pos3
		particle{
			new pos3!
			particles32_base_id 3 + spriteid!
			-1 *
			0.25 1 frnd over * 8 * pos.x@ + pos.x!
			-1 1 frnd 8 * pos.y@ + pos.y!
			-0.25 -0.5 frnd vel.z!
			0.99 grow!
			0.9 1.1 frnd scale!
			5 fade_in!
			15 fade_out!
			90 0 15 rnd + ticks!
			0.5 clr.r!
			0.25 0.35 frnd clr.g!
			1 clr.b!
			0.25 -0.25 frnd vel.x!
			i 2 * wait!
	next

	// White flash
	pcopy 2 scale! 0 vel.z! 1 clr.r! 1 clr.g! 1 clr.b! 0.75 grow! glowy
	15 ticks!
	particles32_base_id 1+ spriteid!

	// SMOKE POOF SOUND
	sfx{ thump 0.2 fx .s! 500 fx .r! 100 fx .filt! 0.9 fx .q! me .adjust-vol }

	}
;

: .smokepoof thing# to me# smokepoof ;

: ninjaport locals( them )
	me .throwerid@ #thing -> them
	<- them .aim_angle@ anglexy 64 xymul
	<- them .pos.y@ + <- them .pos.y!
	<- them .pos.x@ + <- them .pos.x!
	15 <- them .fade!
	15 <- them .cooldown!
;

thing-event: smokebomb-events
	eventid THING_EVENT_THROW = if
		me .vel.x@ 0.1 * me .vel.x!
		me .vel.y@ 0.1 * me .vel.y!
		me .pos.y@ 1+ me .pos.y!
		0 me .flip!
		10 me .hitpoints!
		1 me .nocollide!
		1 me .no_hit!
	then

	eventid THING_EVENT_BUMP = eventid THING_EVENT_BOUNCE = or if
		smokepoof
		ninjaport
		me silentkillit
	then
;
}
	melee_thrown_handler: last


custom: Wooden Boomerang
	tags: woodboom
	spriteid: MELEE4 10 +
	power: 0.5
	knockback: 3
	cooldown: 0.5
	melee_thrown: 1
	melee_thrown_speed: 1.75
	melee_thrown_lob: 0.1
	melee_start_angle: 90
	melee_weapon_angle: 0
	thrown_lift: 1
	melee_shift.y: 0
	melee_shift.x: 0
	melee_off.x: 0
	melee_off.y: 0
	stack_max: 2
	melee_break_scale: 0

mission{

: seekthrower locals( them diffx diffy )
	me .throwerid@ not if exit then
	me .throwerid@ #thing -> them

	<- them .mapid@ me .mapid@ <> if exit then
	<- them .pos me .pos xysub -> diffy -> diffx
	<- diffx <- diffy xymag 12 < if 0 <- them .cooldown@ max me <- them .take <- them .cooldown! then
	me .invincible_counter@ if exit then

	<- diffx <- diffy xynorm 0.15 xymul
	me .vel 0.95 xymul xyadd me .vel!
;

thing-event: boom-events
	eventid THING_EVENT_THROW = if
		1 me .timer!
		16 me .rad.z!
		-27 me .flipx * me .rot!
		50 me .hitpoints!
		30 me .anim.counter!
	then

	eventid THING_EVENT_TIMER = if
		me .anim.info@ 0= if 1 me .timer! then
		me .angle@ abs 360 %
		me .angle@ me .rot@ + me .angle!
		me .angle@ abs 360 % - 180 > if
		sfx{ noise 0.25 fx .scale! me .adjust-vol 25 fx .a! 5 fx .d! 0.9 1.1 frnd 5 * fx .pitch! 1000 fx .filt_high! } // FFFFT
		then
		me .anim.substate@ me .anim.counter@ 0= or if seekthrower exit then
	then

	eventid THING_EVENT_WALL = eventid THING_EVENT_BUMP = or if
		1 me .anim.substate@ 1+ me .anim.substate!

		me .invincible_counter@ 0= if
			15 me .invincible_counter!
			me .vel xynorm 2 xymul me .vel! // BOUNCE from wall/object
		else then;

		me .spriteid@ weapons_base_id MELEE4 + 10 + = if
			sfx{ ruffle me .adjust-vol 75 fx .d! 0.35 0.6 frnd fx .pitch! 0 fx .duty! 10 fx .freq2! }
		else
			sfx{ ringmod me .adjust-vol 100 fx .d! 0.75 1.25 frnd 1.5 * fx .pitch! }
			sfx{ ruffle me .adjust-vol 50 fx .d! 0.35 0.6 frnd 2 * fx .pitch! 0 fx .duty! 10 fx .freq2! }
		then
	then

	eventid THING_EVENT_BOUNCE = eventid THING_EVENT_LAND = or if
		1 me .anim.info!
	then

	eventid THING_EVENT_WALL = me .anim.info@ 0= and if
		me .smack
	then
;
}

	melee_thrown_handler: last
//	wielder_handler:


custom: Metal Boomerang
	tags: metalboom
	spriteid: MELEE4 11 +
	power: 0.5
	unbreakable: 1
	knockback: 3
	cooldown: 0.5
	melee_thrown: 1
	melee_thrown_speed: 2.5
	melee_thrown_lob: 0.1
	melee_start_angle: 90
	melee_weapon_angle: 0
	thrown_lift: 1
	melee_shift.y: 0
	melee_shift.x: 0
	melee_off.x: 0
	melee_off.y: 0
	stack_max: 2
	melee_break_scale: 0
	melee_thrown_handler: last

custom: Wind Shuriken
	tags: windstar
	spriteid: MELEE4 12 +
	power: 1
	knockback: 3
	cooldown: 1
	unbreakable: 1
	melee_thrown: 1
	melee_thrown_speed: 2
	melee_thrown_lob: 0.1
	melee_start_angle: 90
	melee_weapon_angle: 0
	thrown_lift: 1
	melee_shift.y: 0
	melee_shift.x: 0
	melee_off.x: 0
	melee_off.y: 0
	stack_max: 2
	melee_break_scale: 0
	melee_thrown_handler: last

mission{

: msparks locals( angle )
	0 360 frnd -> angle
	particle{
	5 for 
		particleme
			<- angle anglexy vel!
			15 ticks! 5 fade_out!
			spriteid@ 0x f + spriteid!
			0.5 1 frnd clr.g!
			clr.g@ 0.5 * clr.r!
			3 scale!
			0.9 grow!
			1 clr.b!
			glowy
			<- angle 52 92 rnd + -> angle
	next

	pcopy 0 0 vel!
	particles_base_id 4 + spriteid!
	0.75 grow!
	0 angle!
	}
;

// TODO: throwing and special returning action

0 value the-mjolnir

: mjteleport locals( thing ) -> thing
	<- thing .mapid@ the-mjolnir .mapid!
	the-mjolnir .scatter
;

: .get-mjolnir locals( thing ) -> thing
	<- thing .character@ .weapona@ WEAPON_MJOLNIR = if then;
	<- thing .character@ .weaponb@ WEAPON_MJOLNIR = if then;
	mission{ the-mjolnir if
		the-mjolnir .itemtype@ WEAPON_MJOLNIR <> if then;

		the-mjolnir .mapid@ <- thing .mapid@ <> if
			<- thing mjteleport
			2 rumble
			sfx{ rumble 1 fx .scale! the-mjolnir .adjust-vol fx .q@ 0.5 * fx .q! }
		else
			sfx{ fm the-mjolnir .adjust-vol 0.225 0.275 frnd 0.75 * fx .pitch! 15 fx .freq! fx .d@ fx .a! 10 fx .d! }
		then

		-1 the-mjolnir .pos.z!
		1 the-mjolnir .timer!
		1 the-mjolnir .anim.substate!
		0 the-mjolnir .anim.info!
		0 the-mjolnir .anim.counter!
		0 the-mjolnir .layer!
		1 the-mjolnir .weapon_no_hit_human!
		<- thing .id@ the-mjolnir .throwerid!

		msparks
	then
	}
;

thing-event: mjolnir-events
	eventid THING_EVENT_THROW = if
		1 me .timer!
		16 me .rad.z!
		5 me .rad.x!
		30 me .anim.counter!
		30 me .anim.counter!
		1 me .weapon_no_hit_human!
	then;

	eventid THING_EVENT_TIMER = if
		me .anim.info@ 0= if 1 me .timer! then
		me .vel xyangle 90 me .flipx * + me .angle!
		me .anim.substate@ me .anim.counter@ 0= or if
			seekthrower
			me .throwerid@ 0= if exit then
			me .throwerid@ #thing .mapid@ me .mapid@ = if
				me .pos.z@ -5 > if -5 me .pos.z! then
			me .anim.substate@ 1+ me .anim.substate!
		then

		me .anim.substate@ 1 = if
//			sfx{ fm me .adjust-vol 0.225 0.275 frnd 0.75 * fx .pitch! 15 fx .freq! fx .d@ fx .a! 10 fx .d! }
			me .anim.substate@ 1+ me .anim.substate!
		then

		then
	then;

	eventid THING_EVENT_WALL = eventid THING_EVENT_BUMP = or if
		1 me .anim.substate@ 1+ me .anim.substate!

		me .invincible_counter@ 0= if
			15 me .invincible_counter!
			me .vel xynorm 2 xymul me .vel! // BOUNCE from wall/object
		then

		sfx{ ringmod me .adjust-vol 250 fx .d! 0.75 1 frnd 0.5 * fx .pitch! 30 fx .i! 800 fx .j! }
		sfx{ ruffle me .adjust-vol 50 fx .d! 0.35 0.6 frnd 1 * fx .pitch! 0 fx .duty! 10 fx .freq2! }
		sfx{ rumble 1 fx .scale! me .adjust-vol fx .q@ 0.5 * fx .q! }
		2 rumble msparks
	then

	eventid THING_EVENT_WALL = me .anim.info@ 0= and if
//		msparks
	then;

	eventid THING_EVENT_BOUNCE = eventid THING_EVENT_LAND = or if
		1 me .anim.info!
		me to the-mjolnir
		-90 me .angle!
		1 me .flip!
		-2 me .pos.y@ + me .pos.y!
		0 me .timer!
	then;

	eventid THING_EVENT_NEW = if
		0 to the-mjolnir
	then;

	eventid THING_EVENT_FREE = if
		sfx{ fm 1 fx .delay! 0.5 fx .scale! me .adjust-vol 0.225 0.275 frnd 3 * fx .pitch! 1 fx .duty! 15 fx .freq! 125 fx .a! 10 fx .d! }
		me .throwerid@ if 5 me .throwerid@ #thing .shudder! then
	then;

;

: nearest-hittable-dist? locals( self dist2 )
	-> self
	dup * -> dist2
	<- self .nearest_enemy_dist2@ <- dist2 < if 1 then;
	<- self .nearest_interact_dist2@ <- dist2 > if 0 then;
	<- self .nearest_interact_id@ me .nearest_pickup_id@ = if 0 then;
	<- self .nearest_interact_id@ #thing .typeid@ THING_HUMAN = if 0 then;
	2
;

// TODO: Make a big enum for these somewhere
7 constant VALKYRIE

thing-event: mjol-wield
	eventid THING_EVENT_DID_HIT = if
		sfx{ ringmod me .adjust-vol 250 fx .d!
		0.75 1 frnd 0.5 * fx .pitch! 30 fx .i! 800 fx .j! }
	then

//	eventid THING_EVENT_WIELD = if sfx{ ringmod me .adjust-vol 100 fx .d! 0.75 1 frnd 0.75 * fx .pitch! 30 fx .i! 800 fx .j! } then;

	eventid THING_EVENT_WIELD = if
		me .character@ .specialtype@ VALKYRIE <> if
			BAMP
			sfx{ rumble 2 fx .scale! me .adjust-vol fx .q@ 0.5 * fx .q! }
			2 rumble
			BLINKY "NOT WORTHY" $cat me .report
			me .drop
			-90 lt .angle!
			-2 lt .pos.y@ + lt .pos.y!
			1 lt .flip!
			15 me .shudder!
		then;
	then
		

	eventid THING_EVENT_SWING = if
		24 me nearest-hittable-dist? not if
			0 me .cooldown! 0 me .cooldown_set!
			0 me .anim.weapon_counter! me .forcethrow
			sfx{ fm me .adjust-vol 0.225 0.275 frnd fx .pitch! 15 fx .freq! }
		then
	then
;

custom: Mjollin'er
	tags: mjolnir
	unbreakable: 1
	spriteid: MELEE4 9 +
	power: 3
	knockback: 3
	cooldown: 1.0 // Formerly 0.75
	melee_start_angle: 45
	melee_windup_angle: 135
	melee_end_angle: -260
	melee_break_scale: 0
	melee_reach: 10
	melee_extra_hits: 3
	melee_extra_chance: 0.1
	melee_thrown: 0
	thrown_lift: 0.99
	melee_thrown_lob: 0.1
	melee_thrown_speed: 2
	melee_thrown_handler: ' mjolnir-events
	wielder_handler: ' mjol-wield

}


: .final-aim-angle dup .swing_angle@ swap .angle@ + ;

mission{
	: flamershot locals( thing )
		spawn lt -> thing
		me .pos <- thing .pos!
		1 <- thing .nocollide!
		100 <- thing .flammability!
		0 <- thing .spriteid!
		me .swing_angle@ anglexy 24 xymul <- thing .pos xyadd <- thing .pos!
		me .swing_angle@ anglexy 3 xymul <- thing .vel!
		me .id@ <- thing .throwerid!
		-0.5 <- thing .vel.z!
		<- thing .gravity@ 0.5 * <- thing .gravity!
		8 <- thing .rad.x!
		16 <- thing .rad.z!
		' flamebitz <- thing .events!
		1 <- thing .timer!
		60 <- thing .anim.counter!

		sfx{
			noise me .adjust-vol 100 fx .a! 0.5 0.75 frnd fx .pitch!
			50 500 frnd fx .filt!
			0 0.5 fx .q!
		}

		me .useanammo // Active burn for flamethrower
	;

	: lighterfx
		me .final-aim-angle me .flipx -5 * + anglexy 20 xymul me .pos xyadd 
		particle{ new pos! 6 ticks! 
		pos@ -1 1 frnd -1 1 frnd xyadd pos!
		0.75 1 frnd -1 * vel.z! 0.8 grow!
		particles_base_id 1+ spriteid!
		glowy
		1 clr.r!
		0.25 0.8 frnd dup * dup * clr.g!
		0 clr.b!
		}

		me .pos.z@ particle{ pos.z! }
	;

	: flamerfx
		me .final-aim-angle anglexy 20 xymul me .pos xyadd 
		particle{ new pos! 3 ticks! 
		me .swing_angle@ anglexy 2 xymul vel!

		pos@ -1 1 frnd -1 1 frnd xyadd pos!
		0.8 grow!
		particles_base_id 4 + spriteid!
		glowy
		1 clr.r!
		0.25 0.8 frnd dup * dup * clr.g!
		0 clr.b!
		}

		me .pos.z@ particle{ pos.z! }
	;

	thing-event: flamethrower-events
		eventid THING_EVENT_TIMER = if
			2 me .timer!
			me .ammocount 0= if exit then
			me .actioncmd@ 1 & not if lighterfx else flamerfx then
			gameticks 127 & 0= if me .useanammo then // Idle burn for flamethrower
		then;
		eventid THING_EVENT_WIELD = if 1 me .timer! then;
		eventid THING_EVENT_SHOOT = if flamershot then;
	;
}

custom: Flamethrower
	tags: flamethrower
	spriteid: GUNS1 12 +
	gun_muzzle_height: 2
	ammo_type: LOOT_GAS
	reload: 0.05
	power: 0.5
	cooldown: 1
	melee_start_angle: -100
	melee_windup_angle: -190
	melee_end_angle: 90
	melee_reach: 0
	targeting: 0
	lock_drift: 0.01
	func: WEAPON_FUNC_CUSTOM_AIMING
	ammo_max: 200
	wielder_handler: last


custom: Molotov
	spriteid: MELEE5 0x 9 +
	power: 0
	melee_thrown: 1
	melee_thrown_lob: 2
	stack_max: 5

mission{


thing-event: molotov-events
	eventid THING_EVENT_THROW = if
		1 me .mass!
		1 me .hitpoints!
		-15 me .flipx * me .rot!
		1 me .timer!
		-15 me .flipx * me .rot!
	then;

	eventid THING_EVENT_TIMER = if
		1 me .timer!
		pipefuse
		me .angle@ me .rot@ + me .angle!
	then;

	eventid THING_EVENT_BREAK = if
		me .timer@ if 
			5 me .smashybits
			3 for me flamesplash next
			sfx{ glass me .adjust-vol } // noise 0.2 fx .s! 250 fx .r! 8 fx .pitch! me .adjust-vol }
		then
	then

	eventid THING_EVENT_BOUNCE = eventid THING_EVENT_WALL = or if
		me .timer@ if 
			me .smack me killit
		then
	then

;

	melee_thrown_handler: last
}

custom: Zombie Leg
	tags: zombleg
	spriteid: MELEE4 0x d +
	knockback: 1
	power: 0.5
	cooldown: 0.75
	melee_break_scale: 0.05 

custom: Spine
	tags: spine
	spriteid: MELEE4 0x e +
	knockback: 1
	power: 0.5
	cooldown: 0.75
	melee_break_scale: 0.1 

custom: Spine w/ Skull Accessory
	tags: spineskull
	spriteid: MELEE4 0x f +
	knockback: 1
	power: 1
	cooldown: 0.75
	melee_break_scale: 0.05

custom: Re-bar
	tags: rebar
	spriteid: MELEE4 0x 13 +
	knockback: 1
	power: 0.5
	cooldown: 0.5
	melee_break_scale: 0.0025 
	melee_aiming: 1
	melee_start_angle: -15
	melee_windup_angle: 15
	melee_end_angle: melee_start_angle@
	melee_aiming_offset: -1
	melee_reach: 15
	melee_retract: 0.75
	melee_range: 5
	swoosh_particle1: 0x 56
	swoosh_particle2: 0x 56
	swoosh_range: 0
	swoosh_vel: 3
	leaning: 0

custom: Devil Fork
	tags: devilfork
	spriteid: MELEE4 0x 12 +
	knockback: 1
	power: 2
	cooldown: 0.75
	melee_break_scale: 0
	melee_extra_hits: 2
	melee_extra_chance: 0.5

	melee_start_angle: 0
	melee_windup_angle: 0
	melee_end_angle: melee_start_angle@
	melee_aiming: 1
	melee_reach: 20
	melee_retract: 0.75
	melee_range: 8
	melee_aiming_offset: 0
	swoosh_particle1: 0x 45
	swoosh_particle2: 0x 46
	swoosh_range: 0
	thrust_range: 8
	swoosh_vel: 1
	leaning: 0
	
select: WEAPON_NEW
	name: Broom
	spriteid: MELEE5 0x 11 +
	knockback: 1
	power: 0.2
	cooldown: 0.6
	melee_break_scale: 0.02
	melee_extra_hits: 2
	lightcooldown
	
select: WEAPON_NEW
	name: Mop
	spriteid: MELEE5 0x 12 +
	knockback: 1.5
	power: 0.6
	cooldown: 0.8
	melee_break_scale: 0.02
	melee_extra_hits: 1
	lightcooldown
	
select: WEAPON_NEW
	name: UltraMop
	spriteid: MELEE5 0x 12 +
	knockback: 1.5
	power: 1.2
	cooldown: 0.8
	melee_break_scale: 0
	melee_extra_hits: 1
	lightcooldown
	
custom: Fishing Pole
	tags: fishing
	spriteid: MELEE4 0x 17 +
	knockback: 1
	power: 0.5
	cooldown: 0.5 
	melee_break_scale: 0.1
	lightcooldown

custom: Electric Guitar
	tags: guitar
	spriteid: MELEE4 0x 18 +	
	melee_shift.x: 1
	melee_start_angle: 60
	melee_reach: 7
	knockback: 1.5
	power: 1.5
	cooldown: 0.86
	melee_break_scale: 0

custom: Moose Antlers
	name: antlers
	spriteid: 0
	power: 2.5
	knockback: 4
	leaning: -2.5
	cooldown: 1.5
	melee_extra_hits: 1
	swoosh_particle1: 3
	swoosh_particle2: 3
	swoosh_particle1: 5
	swoosh_particle2: 5
	no_held_sprite: 1
	swoosh_range: -90
	melee_range: 24
	thrust_range: 5
	swoosh_dist: 10
	swoosh_vel: 0.5
	melee_start_angle: 90

custom: Ray Gun
	name: RayGun
	spriteid: MELEE5 0x a +
	gun_muzzle_height: 5
	ammo_type: LOOT_GAS
	spread_factor: 0
	reload: 0.7
	laser_type: 1
	power: 0.40
	knockback: 0.5
	shot_knockback: 1.5
	shot_power: 2
	lengthscale: 0.5
	shoot_thru: 0.15
	func: WEAPON_FUNC_SHOOT
	boom_factor: 2
	ammo_max: 60
	skill_angle_range: 10

custom: 2x4
	name: 2x4
	spriteid: MELEE5 0x b +
	knockback: 1.5
	power: 1
	cooldown: 1
	melee_break_scale: 0.05
	melee_extra_hits: 1

custom: Pokin'
	name: pokin
	spriteid: 0
	power: 0
	knockback: 5
	thrust_range: 3
	cooldown: 0
	swoosh_particle1: 0x 47
	swoosh_particle2: 0x 49
	swoosh_range: 0
	no_held_sprite: 1
	melee_range: 10
	swoosh_vel: 0.5
	skin_colour: 1
	lightcooldown

mission{
thing-event: raygun-events
	eventid THING_EVENT_SHOOT = if
		sfx{ fm_sweep 3500 2 fx .a! fx .ramp_start! 150 fx .ramp_end! 100 fx .freq! 0 fx .duty2! 0 fx .duty!
			350 fx .d!
			0.9 1.2 frnd fx .pitch!
			0.65 fx .scale!
			me .adjust-vol }
	then
;
}

	wielder_handler: last

custom: EHZER beam
	name: ehzerbeam
	spriteid: 0
	melee_aiming: 1
	cooldown: 0
	melee_break_scale: 0
	no_held_sprite: 1
	melee_range: 60
}
// End of defs
