#!/usr/bin/perl -w

# round_reset.pl
# (c) 2022, CWZ, LLC

# Reset the whole round to blank

use strict;
use lib '.';
use CWZ;

Exec: {
	# Reset all Accounts to null gang and invalidate Sessions
   qDb_do("DELETE from Session");
	 qDb_do("UPDATE Account SET sess = null");

	# Erase Alliances
	qDb_do("DELETE FROM Alliance");
  qDb_do("DELETE FROM Alliance_Invite");
  qDb_do("DELETE FROM Alliance_Rank");

	# Erase Squad related data
	qDb_do("DELETE FROM Squad");
  qDb_do("DELETE FROM Squadlog");
   qDb_do("DELETE FROM Squad_Holding");
   qDb_do("DELETE FROM Squad_Invite");
   qDb_do("DELETE FROM Squad_Rank");

	# Erase Toon related data
	qDb_do("DELETE FROM Player");
	qDb_do("DELETE FROM Player_Crypto");
  qDb_do("DELETE FROM Boosts");
  qDb_do("DELETE FROM Crypto_Reel WHERE id NOT IN (SELECT id FROM ( SELECT id FROM Crypto_Reel ORDER BY id DESC LIMIT 10) AS subquery)");


	# Delete console, chat, and message content
	qDb_do("DELETE FROM Console");
	qDb_do("DELETE FROM Chat");
  qDb_do("DELETE FROM Messaging");
   wConsoleLog("[Crypto Warz] System: Welcome to Crypto Warz!");

	# Delete attacks
	qDb_do("DELETE FROM Attack_Log");
my $query_vals = "";
  foreach ( 1..25 ) {
    my $pid = 1 . ($_ < 10 ? "0$_" : $_);
    my $charnm = "Vonsmasherson" . ($_ < 10 ? "0$_" : $_);
    $query_vals .= "(1, $pid, 1,
                $_, '$charnm', NULL,
                1,
                $_, $_,
                2000, 0, 0,
                0, 0,
                0, 0, 0,
                (RAND() * 40) + 10, (RAND() * 40) + 10, (RAND() * 20) + 10, (RAND() * 20) + 10, (RAND() * 20) + 10, (RAND() * 20) + 10, (RAND() * 20) + 10, (RAND() * 20) + 10, 'Investor',
                0, 0, 0, 0, 0, 0,
                5000, 4000, 3000, 0,
                0, 0, 0,
                0, 0, 0,
                0, '', 0,
                0, '', 0,
                0, '', 0,
                '', 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0,
                0, 1),\n";
  }
  $query_vals =~ s/,+$//;
  # Booooooom
  qDb_do("INSERT INTO Player VALUES $query_vals");
  qDb_do("INSERT INTO Squad VALUES (1, 0, 'SirDiamondHands', 101, NULL, '', '', '', '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)");
  qDb_do("INSERT INTO Squad_Holding VALUES (1, 3, 0, 0)");
  qDb_do("INSERT INTO Squad_Holding VALUES (1, 1, ?, 50), (1, 2, ?, 25)", $_, $_) foreach ( 1..9 );
  qDb_do("INSERT INTO Squad_Rank VALUES(1, 0, (SELECT COUNT(sid) FROM Squad), 0, 0, 0, 0, 0)");
  qDb_do("UPDATE Account SET sess = CONCAT('created:', NOW()) WHERE id = 1;");

	# Clear TwelveLog entries
	#qDb_do("DELETE FROM TwelveLog");

}
