/*
	@PvE
*/
DROP TABLE IF EXISTS pve;
CREATE TABLE pve (
	`id` INTEGER PRIMARY KEY AUTOINCREMENT,
	`char_id` INTEGER NOT NULL,
	`char_hp` INTEGER NOT NULL,
	`char_m_hp` INTEGER NOT NULL,
	`char_mp` INTEGER NOT NULL,
	`char_m_mp` INTEGER NOT NULL,
	`char_pow` INTEGER NOT NULL, -- Power
	`char_acc` INTEGER NOT NULL, -- Accuracy
	`char_pen` INTEGER NOT NULL, -- Penetration
	`char_foc` INTEGER NOT NULL, -- Focus
	`char_tou` INTEGER NOT NULL, -- Toughness
	`char_arm` INTEGER NOT NULL, -- Armor
	`char_res` INTEGER NOT NULL, -- Resist
	`char_pre` INTEGER NOT NULL, -- Precision
	`char_fer` INTEGER NOT NULL, -- Ferocity
	`mob_id` INTEGER NOT NULL,
	`mob_level` INTEGER NOT NULL,
	`mob_rank` INTEGER NOT NULL,
	`mob_hp` INTEGER NOT NULL,
	`mob_m_hp` INTEGER NOT NULL,
	`mob_mp` INTEGER NOT NULL,
	`mob_m_mp` INTEGER NOT NULL,
	`mob_pow` INTEGER NOT NULL, -- Power
	`mob_acc` INTEGER NOT NULL, -- Accuracy
	`mob_pen` INTEGER NOT NULL, -- Penetration
	`mob_foc` INTEGER NOT NULL, -- Focus
	`mob_tou` INTEGER NOT NULL, -- Toughness
	`mob_arm` INTEGER NOT NULL, -- Armor
	`mob_res` INTEGER NOT NULL, -- Resist
	`mob_pre` INTEGER NOT NULL, -- Precision
	`mob_fer` INTEGER NOT NULL, -- Ferocity
	`first_turn` INTEGER NOT NULL,
	`turn` INTEGER NOT NULL default 1,
	`winner` INTEGER NOT NULL default 0,
	`can_flee` INTEGER NOT NULL default 1,
	`escaped` INTEGER NOT NULL default 0,
	`created` DATETIME DEFAULT CURRENT_TIMESTAMP,
	`updated` DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_pve_char_id ON pve (`char_id`);

DROP TABLE IF EXISTS pve_logs;
CREATE TABLE pve_logs (
	`id` INTEGER PRIMARY KEY AUTOINCREMENT,
	`fight_id` INTEGER NOT NULL,
	`info` TEXT NOT NULL
);
CREATE INDEX idx_pve_logs_fight_id ON pve_logs (`fight_id`);

/*
	@PvP
*/
DROP TABLE IF EXISTS pvp;
CREATE TABLE pvp (
	`id` INTEGER PRIMARY KEY AUTOINCREMENT,
	`char1_id` INTEGER NOT NULL,
	`char1_hp` INTEGER NOT NULL,
	`char1_max_hp` INTEGER NOT NULL,
	`char1_mp` INTEGER NOT NULL,
	`char1_max_mp` INTEGER NOT NULL,
	`char1_pow` INTEGER NOT NULL,  -- Power
	`char1_acc` INTEGER NOT NULL,  -- Accuracy
	`char1_pen` INTEGER NOT NULL,  -- Penetration
	`char1_foc` INTEGER NOT NULL,  -- Focus
	`char1_tou` INTEGER NOT NULL,  -- Toughness
	`char1_arm` INTEGER NOT NULL,  -- Armor
	`char1_res` INTEGER NOT NULL,  -- Resist
	`char1_pre` INTEGER NOT NULL,  -- Precision
	`char1_fer` INTEGER NOT NULL,  -- Ferocity
	`char2_id` INTEGER NOT NULL,
	`char2_hp` INTEGER NOT NULL,
	`char2_m_hp` INTEGER NOT NULL,
	`char2_mp` INTEGER NOT NULL,
	`char2_m_mp` INTEGER NOT NULL,
	`char2_pow` INTEGER NOT NULL,  -- Power
	`char2_acc` INTEGER NOT NULL,  -- Accuracy
	`char2_pen` INTEGER NOT NULL,  -- Penetration
	`char2_foc` INTEGER NOT NULL,  -- Focus
	`char2_tou` INTEGER NOT NULL,  -- Toughness
	`char2_arm` INTEGER NOT NULL,  -- Armor
	`char2_res` INTEGER NOT NULL,  -- Resist
	`char2_pre` INTEGER NOT NULL,  -- Precision
	`char2_fer` INTEGER NOT NULL,  -- Ferocity
	`first_turn` INTEGER NOT NULL,
	`turn` INTEGER NOT NULL default 1,
	`winner` INTEGER NOT NULL default 0,
	`created` DATETIME DEFAULT CURRENT_TIMESTAMP,
	`updated` DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_pvp_char1_id ON pvp (`char1_id`);
CREATE INDEX idx_pvp_char2_id ON pvp (`char2_id`);

CREATE TABLE pvp_logs (
	`id` INTEGER PRIMARY KEY AUTOINCREMENT,
	`fight_id` INTEGER NOT NULL,
	`info` TEXT NOT NULL
);
CREATE INDEX idx_pvp_logs_fight_id ON pvp_logs (`fight_id`);
