private void learn()
{
int iCount = 0;
try
{
while (true)
{
//int learning; // Use _ifLearning
using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
{
//learning = dbClient.getInt("SELECT learning FROM users WHERE name = '" + _Username + "'");
//if (learning == 0)
if (!_learning)
{
sendData("BK" + "You must wait 1 minute before learning again.");
learnLooper = null;
learnLooper.Abort(); // Aborting a thread like this is never a good idea imo, Let threads exit on their own.. in this case instead of using while (true) above why not use while (_learning) that way as soon as we stop learning the thread will exit quietly?
}
// Ugly ass hardcoding, I recommend caching locations like this on bootup or being a little more creative with your room manager hinthint
if (_roomID == 177 && (roomUser.Y == 12 && roomUser.X == 5) || (roomUser.Y == 12 && roomUser.X == 7) || (roomUser.Y == 12 && roomUser.X == 9) || (roomUser.Y == 12 && roomUser.X == 11) || (roomUser.Y == 9 && roomUser.X == 5) || (roomUser.Y == 9 && roomUser.X == 9) || (roomUser.Y == 9 && roomUser.X == 7) || (roomUser.Y == 9 && roomUser.X == 5))
{
// Replacing with _MyInt
//int myIntel;
// Replacing with _MyTime
//int myTime;
//refreshAppearance(false, false, true);
// Why is your intelligience not stored locally? You could save another SQL query by doing so..
//myIntel = dbClient.getInt("SELECT intel FROM users WHERE name = '" + _Username + "'");
//if (myIntel > 14)
if (_MyInt > 14)
{
sendData("BK" + "Sorry, your intelligence level cannot pass 15.");
learnLooper = null;
learnLooper.Abort();
}
int schoolTime = myIntel * 10;
// Again, replaced this with a local variable to save yet another SQL query
//myTime = dbClient.getInt("SELECT time_learn FROM users WHERE name = '" + _Username + "'");
//iCount = myTime;
iCount = _MyTime;
Room.sendWhisper(roomUser, _Username, "(Learning: " + iCount + "/" + schoolTime + " Minutes)");
iCount++;
// Finally, an SQL query that actually counts, bravo! If you wanted to be a resource nazi though you could put all your updates into one query and run them every minute instead.. just sayin'
dbClient.runQuery("UPDATE users SET time_learn = '" + iCount + "' WHERE name = '" + _Username + "'");
if (iCount > schoolTime)
{
Room.sendSaying(roomUser, "*feels smarter*");
// Have you actually tested the below line? Not sure but I would personally remove the quotations around 1, the 0 not so important, but why not
//dbClient.runQuery("UPDATE users SET time_learn = '0', intel = intel + '1' WHERE name = '" + _Username + "'");
dbClient.runQuery("UPDATE users SET time_learn = 0, intel = intel + 1 WHERE name = '" + _Username + "'");
iCount = 0;
}
}
else
{
//dbClient.runQuery("UPDATE users SET learning = '0' WHERE name = '" + _Username + "'");
_ifLearning = false;
dbClient.runQuery("UPDATE users SET learning = 0 WHERE name = '" + _Username + "'");
Room.sendSaying(roomUser, "*stops learning*");
learnLooper = null;
learnLooper.Abort();
}
Thread.Sleep(60000);
}
}
}
catch
{
// If you've got to this point then the thread is going to close itself after one line anyway so this abort is pointless
// Thread.CurrentThread.Abort();
workoutLooper = null;
}
}