anchor.diff:  	desc = "Does not support Pinball."
   	icon_state = "arcade"
   	circuit = /obj/item/circuitboard/computer/arcade/battle
  +
   	var/enemy_name = "Space Villain"
  -	var/temp = "Winners don't use space drugs" //Temporary message, for attack messages, etc
  -	var/player_hp = 30 //Player health/attack points
  -	var/player_mp = 10
  -	var/enemy_hp = 45 //Enemy health/attack points
  -	var/enemy_mp = 20
  +	///Enemy health/attack points
  +	var/enemy_hp = 100
  +	var/enemy_mp = 40
  +	///Temporary message, for attack messages, etc
  +	var/temp = "<br><center><h3>Winners don't use space drugs<center><h3>"
  +	///the list of passive skill the enemy currently has. the actual passives are added in the enemy_setup() proc
  +	var/list/enemy_passive
  +	///if all the enemy's weakpoints have been triggered becomes TRUE
  +	var/finishing_move = FALSE
  +	///linked to passives, when it's equal or above the max_passive finishing move will become TRUE
  +	var/pissed_off = 0
  +	///the number of passives the enemy will start with
  +	var/max_passive = 3
  +	///weapon wielded by the enemy, the shotgun doesn't count.
  +	var/chosen_weapon
  +
  +	///Player health
  +	var/player_hp = 85
  +	///player magic points
  +	var/player_mp = 20
  +	///used to remember the last three move of the player before this turn.
  +	var/list/last_three_move
  +	///if the enemy or player died. restart the game when TRUE
   	var/gameover = FALSE
  -	var/blocked = FALSE //Player cannot attack/heal while set
  -	var/turtle = 0
  -	var/list/weapons = list()
  +	///the player cannot make any move while this is set to TRUE. should only TRUE during enemy turns.
  +	var/blocked = FALSE
  +	///used to clear the enemy_action proc timer when the game is restarted
  +	var/timer_id
  +	///weapon used by the enemy, pure fluff.for certain actions
  +	var/list/weapons
  +	///unique to the emag mode, acts as a time limit where the player dies when it reaches 0.
  +	var/bomb_cooldown = 19
  +
  +
  +///creates the enemy base stats for a new round along with the enemy passives
  +/obj/machinery/computer/arcade/battle/proc/enemy_setup(player_skill)
  +	player_hp = 85
  +	player_mp = 20
  +	enemy_hp = 100
  +	enemy_mp = 40
  +	gameover = FALSE
  +	blocked = FALSE
  +	finishing_move = FALSE
  +	pissed_off = 0
  +	last_three_move = null
  +
  +	enemy_passive = list("short_temper" = TRUE, "poisonous" = TRUE, "smart" = TRUE, "shotgun" = TRUE, "magical" = TRUE, "chonker" = TRUE)
  +	for(var/i = LAZYLEN(enemy_passive); i > max_passive; i--) //we'll remove passives from the list until we have the number of passive we want
  +		var/picked_passive = pick(enemy_passive)
  +		LAZYREMOVE(enemy_passive, picked_passive)
  +
  +	if(LAZYACCESS(enemy_passive, "chonker"))
  +		enemy_hp += 20
  +
  +	if(LAZYACCESS(enemy_passive, "shotgun"))
  +		chosen_weapon = "shotgun"
  +	else if(weapons)
  +		chosen_weapon = pick(weapons)
  +	else
  +		chosen_weapon = "null gun" //if the weapons list is somehow empty, shouldn't happen but runtimes are sneaky bastards.
  +
  +	if(player_skill)
  +		player_hp += player_skill * 2
  +
   
   /obj/machinery/computer/arcade/battle/Reset()
  +	max_passive = 3
   	var/name_action
   	var/name_part1
   	var/name_part2
  
positive.code: 	enemy_name = ("The " + name_part1 + " " + name_part2)
  	name = (name_action + " " + enemy_name)
  
  /obj/machinery/computer/arcade/battle/ui_interact(mob/user)
  	. = ..()
  	var/dat = "<a href='byond://?src=[REF(src)];close=1'>Close</a>"
  	dat += "<center><h4>[enemy_name]</h4></center>"
  
  	dat += "<br><center><h3>[temp]</h3></center>"
  	dat += "<br><center>Health: [player_hp] | Magic: [player_mp] | Enemy Health: [enemy_hp]</center>"
  
  	if (gameover)
  		dat += "<center><b><a href='byond://?src=[REF(src)];newgame=1'>New Game</a>"
  	else
  		dat += "<center><b><a href='byond://?src=[REF(src)];attack=1'>Attack</a> | "
  		dat += "<a href='byond://?src=[REF(src)];heal=1'>Heal</a> | "
  		dat += "<a href='byond://?src=[REF(src)];charge=1'>Recharge Power</a>"
  
  	dat += "</b></center>"
  	var/datum/browser/popup = new(user, "arcade", "Space Villain 2000")
  	popup.set_content(dat)
  	popup.set_title_image(user.browse_rsc_icon(icon, icon_state))
  	popup.open()
  
  /obj/machinery/computer/arcade/battle/Topic(href, href_list)
  	if(..())
  		return
  
  	if (!blocked && !gameover)
  		var/gamerSkillLevel = usr.mind?.get_skill_level(/datum/skill/gaming)
  		var/gamerSkill = usr.mind?.get_skill_modifier(/datum/skill/gaming, SKILL_RANDS_MODIFIER)
  		if (href_list["attack"])
  			blocked = TRUE
  			var/attackamt = rand(2,6) + rand(0, gamerSkill)
  			var/weapon = pick(weapons)
  			temp = "You attack with a [weapon] for [attackamt] damage!"
  			playsound(loc, 'sound/arcade/hit.ogg', 50, TRUE, extrarange = -3, falloff = 10)
  			updateUsrDialog()
  			if(turtle > 0)
  				turtle--
  
  			sleep(10)
  			enemy_hp -= attackamt
  			arcade_action(usr)
  
  		else if (href_list["heal"])
  			blocked = TRUE
  			var/maxPointCost = 3
  			if(gamerSkillLevel >= SKILL_LEVEL_JOURNEYMAN)
  				maxPointCost = 2
  			var/pointamt = rand(1, maxPointCost)
  			var/healamt = rand(6,8) + rand(0, gamerSkill)
  			temp = "You use [pointamt] magic to heal for [healamt] damage!"
  			playsound(loc, 'sound/arcade/heal.ogg', 50, TRUE, extrarange = -3, falloff = 10)
  			updateUsrDialog()
  			turtle++
  
  			sleep(10)
  			player_mp -= pointamt
  			player_hp += healamt
  			blocked = TRUE
  			updateUsrDialog()
  			arcade_action(usr)
  
  		else if (href_list["charge"])
  			blocked = TRUE
  			var/chargeamt = rand(4,7) + rand(0, gamerSkill)
  			temp = "You regain [chargeamt] points."
  			playsound(loc, 'sound/arcade/mana.ogg', 50, TRUE, extrarange = -3, falloff = 10)
  			player_mp += chargeamt
  			if(turtle > 0)
  				turtle--
  
  			updateUsrDialog()
  			sleep(10)
  			arcade_action(usr)
  
  	if (href_list["close"])
  		usr.unset_machine()
  		usr << browse(null, "window=arcade")
  
  	else if (href_list["newgame"]) //Reset everything
  		temp = "New Round"
  		player_hp = 30
  		player_mp = 10
  		enemy_hp = 45
  		enemy_mp = 20
  		gameover = FALSE
  		turtle = 0
  
  		if(obj_flags & EMAGGED)
  			Reset()
  			obj_flags &= ~EMAGGED
  
  	add_fingerprint(usr)
  	updateUsrDialog()
  	return
  
  /obj/machinery/computer/arcade/battle/proc/arcade_action(mob/user)
  	var/xp_gained = 0
  	if ((enemy_mp <= 0) || (enemy_hp <= 0))
  		if(!gameover)
  			gameover = TRUE
  			temp = "[enemy_name] has fallen! Rejoice!"
  			playsound(loc, 'sound/arcade/win.ogg', 50, TRUE, extrarange = -3, falloff = 10)
  
  			if(obj_flags & EMAGGED)
  
negative.code: 				xp_gained += 50
  			SSblackbox.record_feedback("nested tally", "arcade_results", 1, list("win", (obj_flags & EMAGGED ? "emagged":"normal")))
  
  	else if(player_hp <= 0)
  		if(timer_id)
  			deltimer(timer_id)
  			timer_id = null
  		gameover = TRUE
  		temp = "<br><center><h3>You have been crushed! GAME OVER<center><h3>"
  		playsound(loc, 'sound/arcade/lose.ogg', 50, TRUE, extrarange = -3, falloff = 10)
  		xp_gained += 10//pity points
  		if(obj_flags & EMAGGED)
  			user.gib()
  		SSblackbox.record_feedback("nested tally", "arcade_results", 1, list("loss", "hp", (obj_flags & EMAGGED ? "emagged":"normal")))
  		user?.mind?.adjust_experience(/datum/skill/gaming, xp_gained+1)//always gain at least 1 point of XP
  
  
  ///used to check if the last three move of the player are the one we want in the right order and if the passive's weakpoint has been triggered yet
  /obj/machinery/computer/arcade/battle/proc/weakpoint_check(passive,first_move,second_move,third_move)
  	if(LAZYLEN(last_three_move) < 3)
  		return FALSE
  
  	if(last_three_move[1] == first_move && last_three_move[2] == second_move && last_three_move[3] == third_move && LAZYACCESS(enemy_passive, passive))
  		LAZYREMOVE(enemy_passive, passive)
  		pissed_off++
  		return TRUE
  	else
  		return FALSE
  
  
  /obj/machinery/computer/arcade/battle/Destroy()
  	enemy_passive = null
  	weapons = null
  	last_three_move = null
  	return ..() //well boys we did it, lists are no more
  
  
  /obj/machinery/computer/arcade/battle/emag_act(mob/user)
  	if(obj_flags & EMAGGED)
  		return
  
  	to_chat(user, "<span class='warning'>A mesmerizing Rhumba beat starts playing from the arcade machine's speakers!</span>")
  	temp = "<br><center><h2>If you die in the game, you die for real!<center><h2>"
  	max_passive = 6
  	bomb_cooldown = 18
  	var/gamerSkill = usr.mind?.get_skill_level(/datum/skill/gaming)
  	enemy_setup(gamerSkill)
  	enemy_hp += 100 //extra HP just to make cuban pete even more bullshit
  	player_hp += 30 //the player will also get a few extra HP in order to have a fucking chance
  
  	screen_setup(user)
  	gameover = FALSE
  
  	obj_flags |= EMAGGED
  
  	enemy_name = "Cuban Pete"
  	name = "Outbomb Cuban Pete"
  
  	updateUsrDialog()
  
  
  // *** THE ORION TRAIL ** //
  