Browse Source

Game expansion

tBKwtWS 7 years ago
parent
commit
a6b68f3148
4 changed files with 48 additions and 22 deletions
  1. 3 3
      irc/bot.py
  2. 14 8
      irc/commands/common.py
  3. 30 10
      irc/commands/games.py
  4. 1 1
      irc/commands/public.py

+ 3 - 3
irc/bot.py

@@ -144,8 +144,6 @@ class PyRot(irc.bot.SingleServerIRCBot):
             if event.source.nick == "NickServ":
                 if event.arguments[0].startswith("This nickname is registered"):
                     connection.privmsg("NickServ", "identify " + connection.nickname + " " + self.password) # Identify with NickServ.
-                    Inform.notice_owners(self, connection, red + connection.get_nickname() + reset + " is registered with NickServ.")
-                    return
                 if event.arguments[0] == "You are already identified.":
                     return
             elif event.source.nick == "ChanServ":
@@ -156,10 +154,12 @@ class PyRot(irc.bot.SingleServerIRCBot):
                 if event.arguments[0] == "Password authentication required for that command.":  # Not authenticated with NisckServ.
                     Inform.notice_owners(self, connection, "Not authenticated with NickServ. See " + blue + self.helpchar + "recovernick " + reset + "and " + blue + self.helpchar + "registernick" + reset + ".")
                     return
-                if event.arguments[0].startswith("You have been unbanned from ") or event.arguments[0].endswith(" autokick list is empty.") or event.arguments[0].startswith("You are already in "):
+                if event.arguments[0].startswith("You have been unbanned from ") or event.arguments[0].endswith(" autokick list is empty.") or event.arguments[0].startswith("You are already in ") or event.arguments[0] == "Syntax: UNBAN channel [nick]" or event.arguments[0] == "/msg ChanServ HELP UNBAN for more information":
                     return
                 if event.arguments[0].startswith("Channel ") and event.arguments[0].endswith(" has no key."):
                     return
+            elif event.source.nick == "Global":
+                return
             Inform.notice_owners(self, connection, "Notice from " + red + red + event.source.nick + grey + ": " + reset + event.arguments[0])
         except:
             pass

+ 14 - 8
irc/commands/common.py

@@ -155,13 +155,14 @@ class GameHelpers():
             notices += int(record[6])
             notices_words += int(record[7])
             notices_characters += int(record[8])
-        userrecord = self.db.one("SELECT xp_spent, level, coin, coin_given coin_spent FROM users WHERE LOWER(name)=%s AND network='" + self.network + "'", (user, ))
+        userrecord = self.db.one("SELECT xp_spent, level, coin, coin_given, coin_spent, ap_spent FROM users WHERE LOWER(name)=%s AND network='" + self.network + "'", (user, ))
         xp_spent = userrecord[0]
         level = userrecord[1]
         coin = userrecord[2]
         coin_given = userrecord[3]
         coin_spent = userrecord[4]
-        total_xp = ((level + joins + (given * received) + messages + (messages_words / 4) + (messages_characters / 10) + ((actions + (actions_words / 4) + (actions_characters / 10)) * 2) + ((notices + (notices_words / 4) + (notices_characters / 10)) / 2)) / 120) - (level * 5) + (coin_spent / (level + 1))
+        ap_spent = userrecord[5]
+        total_xp = ((level + joins + (given * received) + messages + (messages_words / 4) + (messages_characters / 10) + ((actions + (actions_words / 4) + (actions_characters / 10)) * 2) + ((notices + (notices_words / 4) + (notices_characters / 10)) / 2)) / 120) - (level * 5) + float(coin_spent) + float(ap_spent / 4)
         xp = total_xp - xp_spent
         total_messages = messages + actions + notices
         total_words = messages_words + actions_words + notices_words
@@ -187,24 +188,29 @@ class GameHelpers():
         karma = float(joinkarma) + float(chatkarma) - float(kickkarma) + float(xpkarma) - float(coinkarma)
         print("karma: " + str(joinkarma) + " + "+ str(chatkarma) + " - " + str(kickkarma) + " + " + str(xpkarma) + " - " + str(coinkarma) + " = " + str(karma))
         
-        return level, xp, userrecord[0], karma, coin
+        return level, xp, userrecord[0], karma, coin, coin_spent, coin_given, ap_spent
     
     def list_top_players(self, sort):
         result = self.db.all("SELECT name, level, xp_spent, coin FROM users WHERE network=%s ORDER BY " + sort + " DESC LIMIT 3 ", (self.network, ))
         if sort == "level":
             column = 1
-            threshold = 1
+            threshold = 0
         if sort == "xp_spent":
             column = 2
-            threshold = 1
+            threshold = 0
         if sort == "coin":
             column = 3
             threshold = 10
         message = ""
         for record in result:
-            if not record[column] < threshold:
-                level, xp, xpspent, karma, coin = GameHelpers.get_info(self, record[0])
-                message += red + str(record[0]) + reset + " [L " + green + str(level) + reset + ", X " + grey + str(xpspent) + "/" + green + str(int(xp)) + reset + ", C " + green + str(coin) + reset + ", K " + green + str(round(karma, 2)) + reset + "], "
+            if not record[column] <= threshold:
+                level, xp, xpspent, karma, coin, coinspent, coingiven, apspent = GameHelpers.get_info(self, record[0])
+                if sort == "level":
+                    message += red + str(record[0]) + reset + " [" + blue + "L " + green + str(level) + reset + ", X " + grey + str(xpspent) + "/" + green + str(int(xp)) + reset + ", A " + str(int(xp - float(apspent))) + ", C " + green + str(coin) + reset + ", K " + green + str(round(karma, 2)) + reset + "], "
+                if sort == "xp_spent":
+                    message += red + str(record[0]) + reset + " [L " + green + str(level) + reset + ", " + blue + "X " + grey + str(xpspent) + "/" + green + str(int(xp)) + reset + ", A " + str(int(xp - float(apspent))) + ", C " + green + str(coin) + reset + ", K " + green + str(round(karma, 2)) + reset + "], "
+                if sort == "coin":
+                    message += red + str(record[0]) + reset + " [L " + green + str(level) + reset + ", X " + grey + str(xpspent) + "/" + green + str(int(xp)) + reset + ", " + reset + "A " + str(int(xp - float(apspent))) + ", " + blue + "C " + green + str(coin) + reset + ", K " + green + str(round(karma, 2)) + reset + "], "
         return message[:-2]
 
 class StatisticsHelpers():

+ 30 - 10
irc/commands/games.py

@@ -30,7 +30,7 @@ def do_command(self, connection, event):
     if command == "cmd" or command == "cmds" or command == "commands":
         if cmdtype == "cmd":
             connection.privmsg(replyto, grey + "Games: " + CH.ccc(self, "8ball") + CH.ccc(self, "dice") + CH.ccc(self, "player") + CH.ccc(self, "players") + CH.ccc(self, "levelup") + CH.ccc(self, "givecoin")[:-2] + ".")
-            connection.privmsg(replyto, grey + "Game help: " + blue + self.helpchar + "xp" + reset + ".")
+            connection.privmsg(replyto, grey + "Game help: " + blue + self.helpchar + "level" + grey + ", " + blue + self.helpchar + "xp" + grey + ", " + blue + self.helpchar + "ap" + grey + ", " + blue + self.helpchar + "coin" + grey + ", " + blue + self.helpchar + "karma" + grey + ".")
     
     elif command.split()[0] == "8ball":
         if cmdtype == "help":    #Display help text.
@@ -161,8 +161,8 @@ def do_command(self, connection, event):
                 connection.privmsg(replyto, "Too many arguments, For help type " + blue + self.helpchar + "players " + reset + ".")
                 return
              
-            level, xp, xpspent, karma, coin = GameHelpers.get_info(self, user)
-            connection.privmsg(replyto, message + "Level: " + str(level) + grey + ", " + reset + "XP: " + str(xp) + grey + ", " + reset + "coin: " + str(coin) + grey + ", " + reset + "karma: " + str(karma))
+            level, xp, xpspent, karma, coin, coinspent, coingiven, apspent = GameHelpers.get_info(self, user)
+            connection.privmsg(replyto, message + "Level: " + str(level) + grey + ", " + reset + "XP: " + grey + str(xpspent) + "/" + reset + str(round(xp, 4)) + grey + ", " + reset + "AP: " + str(int(xp - float(apspent))) + grey + ", " + reset + "coin: " + str(coin) + grey + "[S " + str(coinspent) + ", G " + str(coingiven) + "], " + reset + "karma: " + str(round(karma, 4)))
     
     elif command.split()[0] == "levelup":
         if cmdtype == "help":    #Display help text.
@@ -170,7 +170,7 @@ def do_command(self, connection, event):
         elif cmdtype == "cmd":
             
             user = event.source.nick.lower()
-            level, xp, xpspent, karma, coin = GameHelpers.get_info(self, user)
+            level, xp, xpspent, karma, coin, coinspent, coingiven, apspent = GameHelpers.get_info(self, user)
             if len(command.split()) == 1:
                 print("XP < 10: " + str(xp < 10))
                 if xp < 10:
@@ -210,24 +210,32 @@ def do_command(self, connection, event):
             elif command.split()[1] == event.source.nick.lower():
                 connection.privmsg(replyto, "You already have your own coin. For help type " + blue + self.helpchar + "givecoin" + reset + ".")
                 return
-            level, xp, xpspent, karma, coin = GameHelpers.get_info(self, event.source.nick)
+                
+            level, xp, xpspent, karma, coin, coinspent, coingiven, apspent = GameHelpers.get_info(self, event.source.nick)
+            receivingrecord = self.db.one("SELECT level, away FROM users WHERE LOWER(name)=%s AND network=%s", (command.split()[1], self.network, ))
             if level < 1:
                 connection.privmsg(replyto, "You need to " + blue + self.cmdchar + "levelup " + reset + "to be able to give coin.")
                 return
             elif coin < 1:
                 connection.privmsg(replyto, "You have no coin to give.")
                 return
-            elif not self.db.one("SELECT id FROM users WHERE LOWER(name)=%s AND network=%s", (command.split()[1], self.network, )):
+            elif receivingrecord:
                 connection.action(replyto, "does not know of any \"" + red + trigger.split()[1] + reset + "\".")
                 return
-            elif not self.db.one("SELECT id FROM users WHERE LOWER(name)=%s AND network=%s AND LEVEL>0", (command.split()[1], self.network, )):
+            elif receivingrecord[0] == 0:
                 connection.privmsg(replyto, red + trigger.split()[1] + reset + " is not playing the game.")
                 return
+            elif receivingrecord[1] == True:
+                connection.privmsg(replyto, red + trigger.split()[1] + reset + "is not here right now.")
+                return
+            elif apspent >= xp:
+                connection.privmsg(replyto, "You have no action points, go use IRC some more...")
+                return
             if len(command.split()) == 2:
-                self.db.run("UPDATE users SET coin=coin-1, coin_given=coin_given+1 WHERE name=%s AND network=%s", (event.source.nick, self.network, ))
+                self.db.run("UPDATE users SET coin=coin-1, coin_spent=coin_spent+1, coin_given=coin_given+1 ap_spent=ap_spent+1 WHERE name=%s AND network=%s", (event.source.nick, self.network, ))
                 self.db.run("UPDATE users SET coin=coin+1 WHERE LOWER(name)=%s AND network=%s", (command.split()[1], self.network, ))
             elif len(command.split()) == 3:
-                self.db.run("UPDATE users SET coin=coin-%s, coin_given=coin_given+%s WHERE name=%s AND network=%s", (command.split()[2], command.split()[2], event.source.nick, self.network, ))
+                self.db.run("UPDATE users SET coin=coin-%s, coin_spent=coint_spent+%s coin_given=coin_given+%s ap_spent=ap_spent+%s WHERE name=%s AND network=%s", (command.split()[2], command.split()[2], command.split()[2], command.split()[2], event.source.nick, self.network, ))
                 self.db.run("UPDATE users SET coin=coin+%s WHERE LOWER(name)=%s AND network=%s", (command.split()[2], command.split()[1], self.network))
     
     elif command.split()[0] == "players":
@@ -247,9 +255,21 @@ def do_command(self, connection, event):
             if not toplevel and not topxp and not topcoin:
                 connection.privmsg(replyto, "Nobody is playing the game.")
     
+    elif command.split()[0] == "level":
+        if cmdtype == "help":    #Display help text.
+            connection.privmsg(replyto, "For 10 XP you can use !levelup to gain a level. As your level increases, things become more difficult, while more capabilities and options are unlocked.")
     elif command.split()[0] == "xp":
         if cmdtype == "help":    #Display help text.
-            connection.privmsg(replyto, "XP is earned by using IRC and playing the game. XP is onlt recorded in channels where the bot is present. Ask any operator in " + red + self.homechannel + reset + " to have the bot join a channel.")
+            connection.privmsg(replyto, "XP is earned by using IRC and playing the game, in channels with " + red + connection.get_nickname() + reset + ". Ask any operator in " + red + self.homechannel + reset + " to add a channel. XP is used to level up, advance classes, as a limit and as a multiplier. Once XP is expended it keeps counting towards your total.")
+    elif command.split()[0] == "ap":
+        if cmdtype == "help":    #Display help text.
+            connection.privmsg(replyto, "XP is earned by using IRC and playing the game in channels with " + red + connection.get_nickname() + reset + ". Ask any operator in " + red + self.homechannel + reset + " to add a channel. AP is expended for every action you take in the game.")
+    elif command.split()[0] == "coin":
+        if cmdtype == "help":    #Display help text.
+            connection.privmsg(replyto, "Coin is earned when certain events occur, for instance when a player expands XP. Coin is used to buy items and classes. To give a player coin use " + blue + self.cmdchar + "givecoin" + reset + ". Coin affects karma.")
+    elif command.split()[0] == "karma":
+        if cmdtype == "help":    #Display help text.
+            connection.privmsg(replyto, "Karma is a secret formula, based upon on yuor IRC events and how you play the game. It does not increase like XP. Some events, skills and items are karma based.")
     
 #    elif command.split()[0] == "classup":
 #        if cmdtype == "help":    #Display help text.

+ 1 - 1
irc/commands/public.py

@@ -130,7 +130,7 @@ def do_command(self, connection, event):
         if cmdtype == "help":    #Display help text.
             if len(command.split()) is not 1:
                 return
-            connection.privmsg(replyto, "Sets you away, optionally with reason. Affects the !seen command.")
+            connection.privmsg(replyto, "Sets you away, optionally with reason. This affects the !seen command and the game.")
             connection.privmsg(replyto, grey + "Usage: " + blue + "!away " + reset + italic + "reason")
             
         elif cmdtype == "cmd":