<commit_before>if duel_cooldown == nil then
	duel_cooldown = {}
end

function duelchar_callback(event, origin, params)
	local args = str_split_max(params[2], " ", 3)
	if #args ~= 3 then
		irc_msg(params[1], "Usage: !duelchar <class> <specialty> <character title>")
		return
	end

	if params[1] == get_config("bot:nick") then
		params[1] = origin
	end
	
	local class = args[1]:upper()
	local spec  = args[2]:upper()
	local title = cleanSpace(args[3])

	local stats = sql_query_fetch("SELECT `ac`,`attack`,`damage`,`hp` FROM `duelclasses` WHERE `class`='" .. sql_escape(class) .. "'")
	if stats == nil or #stats == 0 then
		irc_msg(params[1], "The class you selected is not valid")
		return
	end
	stats = stats[1]

	if spec == "ARMOR" then
		stats.ac = stats.ac + 3
	elseif spec == "ATTACK" then
		stats.attack = stats.attack + 3
	elseif spec == "DAMAGE" then
		stats.damage = stats.damage + 3
	else
		irc_msg(params[1], "The specialty you selected is not valid")
		return
	end

	sql_fquery("DELETE FROM `duelchars` WHERE `nick`='"..sql_escape(origin).."'")
	sql_fquery("DELETE FROM `duelstats` WHERE `player1`='"..sql_escape(origin).."' OR `player2`='"..sql_escape(origin).."'")

	class = class:lower()

	sql_fquery(
		"INSERT INTO `duelchars` (`nick`,`title`,`armor`,`attack`,`damage`,`level`,`xp`,`hp`,`class`) VALUES " ..
		"('"..sql_escape(origin).."', '"..sql_escape(title).."', '"..stats.ac.."', '"..stats.attack.."', '"..stats.damage.."', '1', '0', '"..stats.hp.."', '"..sql_escape(class).."')"
	)

	irc_msg(params[1], "Welcome, "..origin..", "..title.."! Your stats are: "..stats.ac.." ARMOR / "..stats.attack.." ATTACK / "..stats.damage.." DAMAGE / "..stats.hp .." HEALTH")

end
register_command("duelchar", "duelchar_callback")

function duelhelp_callback(event, origin, params)
	local class_t   = sql_query_fetch("SELECT `class`,`ac`,`attack`,`damage`,`hp` FROM `duelclasses`")

	irc_msg(origin, "== CREATING A CHARACTER ==")
	irc_msg(origin, "To duel, you must make a character with the !duelchar command.")
	irc_msg(origin, "You use it to select a class, a specialty, and a title for your character.")
	irc_msg(origin, "Each class comes with base ARMOR, ATTACK, and DAMAGE stats, as well as an amount of HEALTH points (HP).")
	irc_msg(origin, "Your specialty allows you to increase one of these stats by +3.")
	irc_msg(origin, "Your title is displayed after your nick, e.g. if you enter 'the Wise' you will be called '"..origin..", the Wise'.")
	irc_msg(origin, "The character creation syntax is: !duelchar <class> <specialty> <character title>")
	irc_msg(origin, "The classes you can choose are: ")
	for i,c in pairs(class_t) do
		irc_msg(origin, "  - " .. c.class .. " (" .. c.ac .. " ARMOR / " .. c.attack .. " ATTACK / " .. c.damage .. " DAMAGE / " .. c.hp .. " HEALTH) ")
	end
	irc_msg(origin, "The specialties you can choose are: ARMOR ATTACK DAMAGE")
	irc_msg(origin, " ")

	irc_msg(origin, "== DUELING ==")
	irc_msg(origin, "You may only duel someone who has also made a character.")
	irc_msg(origin, "To do so, simply use the command !duel <nick>")
	irc_msg(origin, "The outcome of the battle is decided by random chance combined with the players' stats.")
	irc_msg(origin, "A turn-by-turn description of the battle will be shown in "..get_config("bot:duelchan")..", but the outcome will also displayed in the channel the battle was initiated in.")
	irc_msg(origin, "The characters will fight to the death and the winner will gain +1 XP. However, no XP is awarded for defeating an opponent more than 3 levels below you. XP is also capped at 2 times the XP to level up.")
	irc_msg(origin, "Both characters will be restored to full HEALTH after the fight.")
	irc_msg(origin, " ")

	irc_msg(origin, "== LEVELING UP ==")
	irc_msg(origin, "When your XP reaches 10 + (LEVEL - 1) * 2 you may level up.")
	irc_msg(origin, "Leveling up allows you to increase one of your stats by +1.")
	irc_msg(origin, "To do so, use !duellevel <stat> (the stats are the same as those you can choose as specialties.)")
	irc_msg(origin, "You can check your level progress by performing !duellevel without a stat as an argument.")	
	irc_msg(origin, " ")
end
register_command("duelhelp", "duelhelp_callback")

function duel_callback(event, origin, params)
	local p1_nick = origin
	local p2_nick = cleanSpace(params[2])

	if p1_nick == p2_nick then
		irc_msg(params[1], origin.." : you cannot duel yourself!")
		return
	end

	if duel_cooldown[origin] ~= nil and duel_cooldown[origin] > os.time() - 60 then
		irc_msg(params[1], origin.. " : you must wait " .. (60 - (os.time() - duel_cooldown[origin])) .. " seconds to duel again.")
		return
	end

	local p1_stats = sql_query_fetch("SELECT `armor`,`attack`,`damage`,`level`,`xp`,`hp`,`title`,`class` FROM `duelchars` WHERE `nick`='"..sql_escape(p1_nick).."'")
	local p2_stats = sql_query_fetch("SELECT `armor`,`attack`,`damage`,`level`,`xp`,`hp`,`title`,`class` FROM `duelchars` WHERE `nick`='"..sql_escape(p2_nick).."'")

	if p1_stats == nil or #p1_stats == 0 then
		irc_msg(params[1], origin.. ": you must create a character! Try using !duelhelp.")
		return
	end

	if p2_stats == nil or #p2_stats == 0 then
		irc_msg(params[1], origin.." : you cannot duel "..params[2].." because they do not have a character!")
		return
	end
<commit_msg>add information about combat system to !duelhelp<commit_after>if duel_cooldown == nil then
	duel_cooldown = {}
end

function duelchar_callback(event, origin, params)
	local args = str_split_max(params[2], " ", 3)
	if #args ~= 3 then
		irc_msg(params[1], "Usage: !duelchar <class> <specialty> <character title>")
		return
	end

	if params[1] == get_config("bot:nick") then
		params[1] = origin
	end
	
	local class = args[1]:upper()
	local spec  = args[2]:upper()
	local title = cleanSpace(args[3])

	local stats = sql_query_fetch("SELECT `ac`,`attack`,`damage`,`hp` FROM `duelclasses` WHERE `class`='" .. sql_escape(class) .. "'")
	if stats == nil or #stats == 0 then
		irc_msg(params[1], "The class you selected is not valid")
		return
	end
	stats = stats[1]

	if spec == "ARMOR" then
		stats.ac = stats.ac + 3
	elseif spec == "ATTACK" then
		stats.attack = stats.attack + 3
	elseif spec == "DAMAGE" then
		stats.damage = stats.damage + 3
	else
		irc_msg(params[1], "The specialty you selected is not valid")
		return
	end

	sql_fquery("DELETE FROM `duelchars` WHERE `nick`='"..sql_escape(origin).."'")
	sql_fquery("DELETE FROM `duelstats` WHERE `player1`='"..sql_escape(origin).."' OR `player2`='"..sql_escape(origin).."'")

	class = class:lower()

	sql_fquery(
		"INSERT INTO `duelchars` (`nick`,`title`,`armor`,`attack`,`damage`,`level`,`xp`,`hp`,`class`) VALUES " ..
		"('"..sql_escape(origin).."', '"..sql_escape(title).."', '"..stats.ac.."', '"..stats.attack.."', '"..stats.damage.."', '1', '0', '"..stats.hp.."', '"..sql_escape(class).."')"
	)

	irc_msg(params[1], "Welcome, "..origin..", "..title.."! Your stats are: "..stats.ac.." ARMOR / "..stats.attack.." ATTACK / "..stats.damage.." DAMAGE / "..stats.hp .." HEALTH")

end
register_command("duelchar", "duelchar_callback")

function duelhelp_callback(event, origin, params)
	local class_t   = sql_query_fetch("SELECT `class`,`ac`,`attack`,`damage`,`hp` FROM `duelclasses`")

	irc_msg(origin, "== CREATING A CHARACTER ==")
	irc_msg(origin, "To duel, you must make a character with the !duelchar command.")
	irc_msg(origin, "You use it to select a class, a specialty, and a title for your character.")
	irc_msg(origin, "Each class comes with base ARMOR, ATTACK, and DAMAGE stats, as well as an amount of HEALTH points (HP).")
	irc_msg(origin, "Your specialty allows you to increase one of these stats by +3.")
	irc_msg(origin, "Your title is displayed after your nick, e.g. if you enter 'the Wise' you will be called '"..origin..", the Wise'.")
	irc_msg(origin, "The character creation syntax is: !duelchar <class> <specialty> <character title>")
	irc_msg(origin, "The classes you can choose are: ")
	for i,c in pairs(class_t) do
		irc_msg(origin, "  - " .. c.class .. " (" .. c.ac .. " ARMOR / " .. c.attack .. " ATTACK / " .. c.damage .. " DAMAGE / " .. c.hp .. " HEALTH) ")
	end
	irc_msg(origin, "The specialties you can choose are: ARMOR ATTACK DAMAGE")
	irc_msg(origin, " ")

	irc_msg(origin, "== DUELING ==")
	irc_msg(origin, "You may only duel someone who has also made a character.")
	irc_msg(origin, "To do so, simply use the command !duel <nick>")
	irc_msg(origin, "The outcome of the battle is decided by random chance combined with the players' stats.")
	irc_msg(origin, "A turn-by-turn description of the battle will be shown in "..get_config("bot:duelchan")..", but the outcome will also displayed in the channel the battle was initiated in.")
	irc_msg(origin, "The characters will fight to the death and the winner will gain +1 XP. However, no XP is awarded for defeating an opponent more than 3 levels below you. XP is also capped at 2 times the XP to level up.")
	irc_msg(origin, "Both characters will be restored to full HEALTH after the fight.")
	irc_msg(origin, " ")

	irc_msg(origin, "== LEVELING UP ==")
	irc_msg(origin, "When your XP reaches 10 + (LEVEL - 1) * 2 you may level up.")
	irc_msg(origin, "Leveling up allows you to increase one of your stats by +1.")
	irc_msg(origin, "To do so, use !duellevel <stat> (the stats are the same as those you can choose as specialties.)")
	irc_msg(origin, "You can check your level progress by performing !duellevel without a stat as an argument.")	
	irc_msg(origin, " ")

	irc_msg(origin, "== COMBAT SYSTEM ==")
	irc_msg(origin, "Whoever issues the !duel command is considered the attacker, and their opponent is the defender.")
	irc_msg(origin, "The attacker always gets the first swing, but the defender has an opportunity to attack one more time after being reduced to 0 HP.")
	irc_msg(origin, "Combat uses D&D-ish rules, where an attack hits if your d20 roll plus your ATTACK stat beats your opponent's ARMOR rating.")
	irc_msg(origin, "If the attack hits, you do damage equal to d10 plus your DAMAGE stat, and this damage is deducted from your opponent's HEALTH.")
	irc_msg(origin, "A natural 20 on the attack roll is a critical hit, ignoring the ARMOR rating and dealing 10 + DAMAGE with a extra +1 crit bonus.")
	irc_msg(origin, "A duel is over when a player goes below 0 HP (and after the defender takes their last attack, if necessary).")
	irc_msg(origin, "Since it is possible for both players to go below 0 HP, the player with the highest HP after the duel is considered the winner.")
	irc_msg(origin, "Rarely, both players will end up with the same negative HP value, and thus the duel will end in a draw.")
	irc_msg(origin, " ")
end
register_command("duelhelp", "duelhelp_callback")

function duel_callback(event, origin, params)
	local p1_nick = origin
	local p2_nick = cleanSpace(params[2])

	if p1_nick == p2_nick then
		irc_msg(params[1], origin.." : you cannot duel yourself!")
		return
	end

	if duel_cooldown[origin] ~= nil and duel_cooldown[origin] > os.time() - 60 then
		irc_msg(params[1], origin.. " : you must wait " .. (60 - (os.time() - duel_cooldown[origin])) .. " seconds to duel again.")
		return
	end

	local p1_stats = sql_query_fetch("SELECT `armor`,`attack`,`damage`,`level`,`xp`,`hp`,`title`,`class` FROM `duelchars` WHERE `nick`='"..sql_escape(p1_nick).."'")
	local p2_stats = sql_query_fetch("SELECT `armor`,`attack`,`damage`,`level`,`xp`,`hp`,`title`,`class` FROM `duelchars` WHERE `nick`='"..sql_escape(p2_nick).."'")

	if p1_stats == nil or #p1_stats == 0 then
		irc_msg(params[1], origin.. ": you must create a character! Try using !duelhelp.")
		return
	end

	if p2_stats == nil or #p2_stats == 0 then
		irc_msg(params[1], origin.." : you cannot duel "..params[2].." because they do not have a character!")
		return
	end

{'fraction_non_alphanumeric': 0.15414683888511216, 'fraction_numerical': 0.010197144799456152, 'mean_word_length': 4.351978171896317, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3543226', 'n_tokens_mistral': 4291, 'n_tokens_neox': 3906, 'n_words': 1359}