示例#1
0
def loadCharacters():

    print "--------------------------"
    print "--- LOADING CHARACTERS ---"
    print "--------------------------"
    tempChar = sql.getCharacters()
    for c in tempChar:
        character.characterStore[c["name"]] = character.Characters()
        character.characterStore[c["name"]].name = c["name"]
        character.characterStore[c["name"]].level = c["level"]
        character.characterStore[c["name"]].energy = c["energy"]
        character.characterStore[c["name"]].skillPoints = c["skillPoints"]
        character.characterStore[c["name"]].currentXP = c["currentXP"]
        character.characterStore[c["name"]].levelXP = c["levelXP"]
        character.characterStore[c["name"]].hp = c["hp"]
        character.characterStore[c["name"]].maxHP = c["maxHP"]
        character.characterStore[c["name"]].mana = c["mana"]
        character.characterStore[c["name"]].maxMana = c["maxMana"]
        character.characterStore[c["name"]].str = c["str"]
        character.characterStore[c["name"]].wis = c["wis"]
        character.characterStore[c["name"]].vit = c["vit"]
        character.characterStore[c["name"]].weapon = c["weapon"]
        character.characterStore[c["name"]].armor = c["armor"]
        character.characterStore[c["name"]].shield = c["shield"]
        character.characterStore[c["name"]].location = c["location"]
        character.characterStore[c["name"]].whisperMode = c["whisperMode"]
        character.characterStore[c["name"]].inventory = c["inventory"]
        character.characterStore[c["name"]].money = c["money"]
        character.characterStore[c["name"]].recalculateStats(item.itemStore)
        print character.characterStore[c["name"]].inventory
        print character.characterStore[c["name"]]
        print "--- Loaded Character: " + c["name"]
示例#2
0
    def test_set_blanks(self):
        guessedCharacters, defaultCharacters, blanks = [], [" ", "-", "\'", "\"", "!", ".", ","], 1
        testCharacterObject = characters.Characters(guessedCharacters, defaultCharacters, blanks)
        self.assertEqual(1, testCharacterObject.get_blanks())

        testCharacterObject.set_blanks(5)
        self.assertEqual(5, testCharacterObject.get_blanks())
示例#3
0
    def test_append_guessedCharacters(self):
        guessedCharacters, defaultCharacters, blanks = [], [" ", "-", "\'", "\"", "!", ".", ","], 1
        testCharacterObject = characters.Characters(guessedCharacters, defaultCharacters, blanks)

        guess = 'Q'
        testCharacterObject.append_guessedCharacters(guess)
        self.assertEqual(['Q'], testCharacterObject.get_guessedCharacters())
示例#4
0
    def test_str(self):
        guessedCharacters, defaultCharacters, blanks = [], [" ", "-", "\'", "\"", "!", ".", ","], 1
        testCharacterObject = characters.Characters(guessedCharacters, defaultCharacters, blanks)
        testCharacterObject.append_guessedCharacters('A')
        testCharacterObject.append_guessedCharacters('B')
        testCharacterObject.append_guessedCharacters('C')
        abc = 'A, B, C'

        self.assertEqual(abc, testCharacterObject.__str__())
示例#5
0
def createCharacterInformation():
    defaultCharacters = [
        " ", "-", "\'", "\"", "!", ".", ","
    ]  # Add special characters as needed to be revealed by default
    guessedCharacters = []  # User-guessed characters will append onto the list
    blanks = 1
    charInfo = characters.Characters(guessedCharacters, defaultCharacters,
                                     blanks)

    return charInfo
示例#6
0
def main():
    print "Connecting to Slack as SlackRPG"
    if slack_client.rtm_connect(with_team_state=False):
        print("Starter Bot connected and running!")
        # Read bot's user ID by calling Web API method `auth.test`
        starterbot_id = slack_client.api_call("auth.test")["user_id"]
        print "STARTER BOT ID: " + starterbot_id
        s = slack_client
        '''
        # Networking functions
        
        s.connect((cfg.HOST, cfg.PORT))
        s.send("PASS {}\r\n".format(cfg.PASS).encode("utf-8"))
        s.send("NICK {}\r\n".format(cfg.NICK).encode("utf-8"))
        s.send("JOIN #{}\r\n".format(cfg.CHAN[0]).encode("utf-8"))
        s.send("JOIN #{}\r\n".format(cfg.CHAN[1]).encode("utf-8"))
    
        # Decode chat message from IRC format.
        
        for i in cfg.CHAN:
            utils.chat(s, "The portals have opened to another land in the Slack realm! For more information, type @SlackRPG !help.", False, None, i)
        '''
        for channel in cfg.CHAN:
            utils.chat(s,
                       "The portals have opened to another land in the Twitch realm! For more information, type !help.",
                       False, None, channel)

        loadLocations()
        loadItems()
        loadCharacters()
        loadMonsters()

        # load up the oplist for admin commands
        thread.start_new_thread(utils.threadFillOpList, ())

        # start the thread to give energy every 60 seconds
        thread.start_new_thread(giveEnergy, (s,))

        # Start the autosaving thread to save characters to DB every 60 seconds
        thread.start_new_thread(sql.autosaveCharacters, (character.characterStore,))

        # Main logic loop
        while True:
            CHAT_MSG, chan, username = parse_bot_commands(slack_client.rtm_read())
            response = CHAT_MSG
            # Respond to ping request to stay alive on the server
            if response:
                # Here we process the different commands
                print "COMMAND WAS MESSAGE:" + CHAT_MSG + " CHANNEL:" + chan + " USER:"******"--- MESSAGE NOT STRIPPED: " + message
                print "--- MESSAGE NOT STRIPPED: " + message.strip()

                # splits the message so we can detect if there's a number to add for certain commands.
                message = message.split(" ")

                try:
                    char = character.characterStore[username]
                except:
                    pass

                if message[0].strip() == "!help":
                    utils.chat(s, "Hey <@" + username + ">!, some commands you can use are !joingame, !stats, !location [additional], !north, !south, !east, !west, !addstrength, !addwisdom, !addvitality, !hunt, !toggleWhisper, !rest, !inventory, !equipment, !equip [inventory slot number], !unequip [weapon/armor/shield]", True, username, chan)
                    # TODO: Flesh out the help command to take additional argument for per command usage.
                # this creates a new character for the account. Only one character is allowed per account.
                if message[0].strip() == "!joingame":
                        if username in character.characterStore:  # check and see if the character is already made
                            utils.chat(s, "<@" + username + ">, you already have a character!", True, username, chan)
                        else:
                            # create the character and add it to the DB
                            character.characterStore[username] = character.Characters()
                            if character.characterStore[username].createCharacter(username):
                                if sql.createCharacter(character.characterStore[username]):
                                    utils.chat(s, "<@" + username + ">, You've now created a character. Some commands you can use are !help ,!stats, !location, !north, !south, !east, !west", True, username, chan)
                                else:
                                    utils.chat(s, "<@" + username + ">, there was an error saving you to the database, please contact the channel admin or join the Discord for TC_RPG", True, username, chan)

                # Obviously shows the stats for the character. Twitch doesn't have linebreaks thanks to broke ass IRC code. So wall of text it is.
                if message[0].strip() == "!stats":
                    # We try this, if it throws an error, most likely they don't have a character. Need to clean this up a bit.
                    try:
                        print
                        utils.chat(s, "Hey <@" + username + ">. Your stats are:"\
                                     "\n• Level: " + str(character.characterStore[username].level) \
                                   + "\n• XP: " + str(character.characterStore[username].currentXP) + "/" + str(character.characterStore[username].levelXP) \
                                   + "\n• Health: " + str(character.characterStore[username].hp) + "/" + str(character.characterStore[username].maxHP) \
                                   + "\n• Mana: " + str(character.characterStore[username].mana) + "/" + str(character.characterStore[username].mana) \
                                   + "\n• Energy: " + str(character.characterStore[username].energy) \
                                   + "\n• Money: " + str(character.characterStore[username].money) \
                                   + "\n• Skill Points: " + str(character.characterStore[username].skillPoints) \
                                   + "\n• Location: " + str(location.locationStore[character.characterStore[username].location].name) \
                                   + ".", True, username, chan)
                        print character.characterStore[username].name
                    except:
                        utils.chat(s, "Hey " + username + ", you don't currently have a character registered. Type !joingame to have us create one for you!", True, username, chan)

                if message[0].strip() == "!south":
                    if location.locationStore[character.characterStore[username].location].south > 0:
                        character.characterStore[username].location = location.locationStore[character.characterStore[username].location].south
                        utils.chat(s, "<@" + username + "> decides to go to the south, now you're at " + location.locationStore[character.characterStore[username].location].name, True, username, chan)
                    else:
                        utils.chat(s, "<@" + username + "> looks to the south but there's no where to go!", True, username, chan)

                if message[0].strip() == "!north":
                    if location.locationStore[character.characterStore[username].location].north > 0:
                        character.characterStore[username].location = location.locationStore[character.characterStore[username].location].north
                        utils.chat(s, "You decide you want to head to the north, now you're at " + location.locationStore[character.characterStore[username].location].name, True, username, chan)
                    else:
                        utils.chat(s, "<@" + username + "> looks to the north but there's no where to go!", True, username, chan)

                if message[0].strip() == "!east":
                    if location.locationStore[character.characterStore[username].location].east > 0:
                        character.characterStore[username].location = location.locationStore[
                            character.characterStore[username].location].east
                        utils.chat(s, "You decide you want to head to the east, now you're at " + location.locationStore[character.characterStore[username].location].name, True, username, chan)
                    else:
                        utils.chat(s, "<@" + username + "> shifts their glance to the east, but there's no where to go!", True, username, chan)

                if message[0].strip() == "!west":
                    if location.locationStore[character.characterStore[username].location].west > 0:
                        character.characterStore[username].location = location.locationStore[
                            character.characterStore[username].location].west
                        utils.chat(s, "You decide you want to head to the west, now you're at " + location.locationStore[
                            character.characterStore[username].location].name, True, username, chan)
                    else:
                        utils.chat(s, "<@" + username + "> glances to the west, but there's no where to go!", True, username, chan)

                if message[0].strip() in ('!location', '!look'):
                    text = ""
                    if len(message) > 1:
                        print message
                        if message[1].strip() == "players":
                            playersAtLocation = sql.getPlayersAtLocation(character.characterStore[username].location)
                            print playersAtLocation
                            if len(playersAtLocation) > 1:
                                for p in playersAtLocation:
                                    text += "• <@" + p["name"] + "> \n "
                                utils.chat(s, "<@" + username + "> the current players in the same location are:\n " + text, True, username, chan)
                            else:
                                utils.chat(s, "<@" + username + "> you're all alone...", True, username, chan)
                        else:
                            utils.chat(s, "<@" + username + "> I didn't quite understand that.", True, username, chan)
                    else:
                        if location.locationStore[character.characterStore[username].location].location_id > 0:
                            utils.chat(s, "<@" + username + "> looks at their surroundings. " + location.locationStore[char.location].description, True, username, chan, image=location.locationStore[char.location].image)
                        else:
                            utils.chat(s, "<@" + username + "> stares into the nether, seeing nothing but darkness.", True, username, chan)

                # Players rest to heal in places without monsters
                if message[0].strip() == "!rest":
                    if location.locationStore[character.characterStore[username].location].hasMonsters:
                        utils.chat(s, "<@" + username + "> looks around but think it's not exactly the best idea to rest with monsters roaming around.", True, username, chan)
                    else:
                        utils.chat(s, "<@" + username + "> takes a break from the burden of adventuring and gains some health.", True, username, chan)
                        character.characterStore[username].hp += 20
                        if character.characterStore[username].hp > character.characterStore[username].maxHP:
                            character.characterStore[username].hp = character.characterStore[username].maxHP

                # Starts combat against creatures
                if message[0].strip() == "!hunt":
                    print character.characterStore[username].energy
                    char = character.characterStore[username]
                    if character.characterStore[username].energy > 3:
                        maxLevel = location.locationStore[character.characterStore[username].location].maxMonsterLevel
                        if maxLevel > 8:
                            minLevel = maxLevel-5
                        else:
                            minLevel = 1

                        if location.locationStore[character.characterStore[username].location].hasMonsters:
                            monsters = sql.getMonstersByLevel(minLevel, maxLevel)
                            if monsters:
                                print "Total Monsters" + str(len(monsters))
                                indexOfMonster = random.randint(0, len(monsters) - 1)
                                print "Index of Monster " + str(indexOfMonster)
                                monsterToFight = monsters[indexOfMonster]
                                print monsterToFight

                                if char.weapon == 0:
                                    weapon = 0
                                else:
                                    weapon = item.itemStore[char.weapon]

                                if char.armor == 0:
                                    armor = 0
                                else:
                                    armor = item.itemStore[char.armor]

                                if char.shield == 0:
                                    shield = 0
                                else:
                                    shield = item.itemStore[char.shield]

                                outcome = combat.fightMonster(s, monsterToFight, char, username, weapon, armor, shield, item.itemStore)
                                # print outcome
                                utils.chat(s, outcome, True, username, chan)
                                removeEnergy(1, username)
                        else:
                            utils.chat(s, "<@" + username + "> there doesn't seem to be anything here to kill.", True, username, chan)
                    else:
                        utils.chat(s, "<@" + username + "> tries to go and kill stuff, but takes a nap instead due to being completely out of of energy.", True, username, chan)

                # Adds strength using a skill point
                if message[0].strip() == "!addstrength":
                    if character.characterStore[username].skillPoints > 0:
                        try:
                            if len(message) > 1:
                                message_amount = int(message[1])

                                if message_amount <= character.characterStore[username].skillPoints:
                                    character.characterStore[username].skillPoints -= message_amount
                                    utils.chat(s, "<@" + username + "> just gained some strength to more easily defeat his foes.", True, username, chan)
                                else:
                                     utils.chat(s, "<@" + username + "> you don't have enough skillpoints!", True, username, chan)
                            else:
                                utils.chat(s, "<@" + username + "> looks like you wanted to add some strength, but wasn't quite sure how much. Please use !addstrength amount (ex: !addstrength 5).", True, username, chan)
                        except ValueError:
                            utils.chat(s, "<@" + username + "> you entered a wrong value, please make sure it's a number.", True, username, chan)
                    else:
                        utils.chat(s, "<@" + username + "> just tried to gain some strength, but failed miserably due to not having enough skill.", True, username, chan)

                if message[0].strip() == "!equipment":
                    command.showEquipment(s, username, character.characterStore[username], item.itemStore, chan)

                if message[0].strip() == "!weapon":
                    command.showWeapon(s, username, character.characterStore[username], item.itemStore, chan)

                if message[0].strip() == "!armor":
                    command.showArmor(s, username, character.characterStore[username], item.itemStore, chan)

                if message[0].strip() == "!shield":
                    command.showShield(s, username, character.characterStore[username], item.itemStore, chan)

                if message[0].strip() == "!inventory":
                    command.showInventory(s, username, character.characterStore[username], item.itemStore, chan)

                # Sells and item
                if message[0].strip() == "!sell":
                    print location.locationStore[char.location].hasMonsters
                    if location.locationStore[char.location].hasMonsters == 0:
                        try:
                            if len(message[1]) >= 1:
                                command.sellItem(s, username, character.characterStore[username], item.itemStore, int(message[1].strip()), chan)
                            else:
                                utils.chat(s, "<@" + username + "> we didn't quite catch what you wanted to sell. Use the item number in () when using !inventory to sell that item to the merchant.", char.whisperMode, username, chan)
                        except ValueError as e:
                            utils.chat(s, "<@" + username + "> you entered a wrong value, please make sure it's a number and that you actually, you know, have the item.", True, username, chan)
                            print e
                        except IndexError as e:
                            utils.chat(s,"<@" + username + "> you entered a wrong value, please make sure it's a number and that you actually, you know, have the item.",True, username, chan)
                    else:
                        utils.chat(s, "<@" + username + "> there isn't a merchant at this location.", True, username, chan)

                # Adds wisdom using a skill point
                if message[0].strip() == "!addwisdom":
                    print len(message)
                    try:
                        if character.characterStore[username].skillPoints > 0:
                            try:
                                if len(message) > 1:
                                    message_amount = int(message[1])

                                    if message_amount <= character.characterStore[username].skillPoints:
                                        character.characterStore[username].wis += 1
                                        character.characterStore[username].skillPoints -= 1
                                        utils.chat(s, "<@" + username + "> just got slightly less dumb and gained some hard earned wisdom.", True, username, chan)
                                    else:
                                        utils.chat(s, "<@" + username + "> you don't have enough skillpoints!", True, username, chan)
                                else:
                                    utils.chat(s, "<@" + username + "> you need to specify how many you wan to add!", True, username, chan)
                            finally:
                                pass
                        else:
                            utils.chat(s, "<@" + username + "> just tried to gain some wisdom, but his brain just couldn't handle it.", True, username, chan)
                    except ValueError:
                        utils.chat(s, "<@" + username + "> you entered a wrong value, please make sure it's a number.", True, username, chan)

                # Adds vitality using a skill point
                if message[0].strip() == "!addvitality":
                    try:
                        if character.characterStore[username].skillPoints > 0:
                                if len(message) > 1:
                                    message_amount = int(message[1])
                                    if message_amount <= character.characterStore[username].skillPoints:
                                        character.characterStore[username].vit += 1
                                        character.characterStore[username].skillPoints -= 1
                                        character.Characters.recalculateStats()
                                        utils.chat(s, "<@" + username + "> just gained some vitality to take some more hits like the mythical Rocky Balboa that he read about in some timetravel mages apartment.", True, username, chan)
                                    else:
                                        utils.chat(s, "<@" + username + "> you don't have enough skillpoints!", True, username, chan)
                                else:
                                    utils.chat(s, "<@" + username + "> you need to specify how many.", True, username, chan)
                        else:
                            utils.chat(s, "<@" + username + "> just tried to be more of a meat shield, but is just too scrawny and weak.", True, username, chan)
                    except ValueError:
                        utils.chat(s, "<@" + username + "> you entered a wrong value, please make sure it's a number.", True, username, chan)

                if message[0].strip() == "!unequip":
                    try:
                        if len(message) > 1:
                            if message[1].strip() == "weapon":
                                command.unequipWeapon(s, username, character.characterStore[username], chan)
                            elif message[1].strip() == "armor":
                                command.unequipArmor(s, username, character.characterStore[username], chan)
                            elif message[1].strip() == "shield":
                                command.unequipShield(s, username, character.characterStore[username], chan)
                            else:
                                utils.chat(s, "<@" + username + "> we didn't quite catch what you wanted to unequip. Did you want to !unequip your weapon, armor, or shield?", True, username, chan)
                        else:
                            utils.chat(s, "<@" + username + "> we didn't quite catch what you wanted to unequip. Did you want to !unequip your weapon, armor, or shield?", True, username, chan)
                    except ValueError:
                        utils.chat(s, "<@" + username + "> you entered a wrong value, please make sure it's a number.", True, username, chan)

                if message[0].strip() == "!equip":
                    try:
                        if len(message) > 1 and int(message[1]):
                            command.equipItem(s, username, character.characterStore[username], item.itemStore, int(message[1].strip()), chan)
                        else:
                            utils.chat(s, "<@" + username + "> we didn't quite catch what you wanted to equip. Use the item number in () when using !inventory to equip that item.", char.whisperMode, username, chan)
                    except ValueError:
                        utils.chat(s, "<@" + username + "> you entered a wrong value, please make sure it's a number.", True, username, chan)

                if message[0].strip() == "!reload":
                    try:
                        if len(message) > 1:
                            if message[1].strip() == "characters":
                                character.characterStore.clear()
                                loadCharacters()
                                utils.chat(s, "<@" + username + "> all characters have been reloaded.", False, username, chan)

                            if message[1].strip() == "items":
                                item.itemStore.clear()
                                loadItems()
                                utils.chat(s, "<@" + username + "> all items have been reloaded.", False, username, chan)

                            if message[1].strip() == "monsters":
                                monster.monsterStore.clear()
                                loadMonsters()
                                utils.chat(s, "<@" + username + "> all monsters have been reloaded.", False, username, chan)

                            if message[1].strip() == "locations":
                                location.locationStore.clear()
                                loadLocations()
                                utils.chat(s, "<@" + username + "> all locations have been reloaded.", False, username, chan)
                        else:
                            utils.chat(s, "<@" + username + "> we didn't quite catch what you wanted to reload master.", False, username, chan)
                    except ValueError:
                        utils.chat(s, "<@" + username + "> you entered a wrong value, please make sure it's either characters, locations, items, or monsters.", True, username, chan)
            sleep(0.5)
        utils.chat(s, "Bye everyone :)");
示例#7
0
 def test_create_Characters_Object(self):
     guessedCharacters, defaultCharacters, blanks = [], [" ", "-", "\'", "\"", "!", ".", ","], 1
     testCharacterObject = characters.Characters(guessedCharacters, defaultCharacters, blanks)
     self.assertEqual(guessedCharacters, testCharacterObject.guessedCharacters)
     self.assertCountEqual(defaultCharacters, testCharacterObject.defaultCharacters)
     self.assertEqual(blanks, testCharacterObject.blanks)