async def study_cmd(msg): #check if player is in proper channel if msg.channel.id == gccfg.location_map.get("study-hall").channel_id: #add 1 lofi player = GCPlayer(msg.author.id) player.lofi += 1 player.persist()
async def learn_spell(msg): target_spell_name = msg.content.split(' ', 1)[1] if target_spell_name in gccfg.spell_map: spell = gccfg.spell_map[target_spell_name] player = GCPlayer(userid = msg.author.id) player.known_spells.append(spell.name) player.persist() response = "You have successfully learned {}".format(spell.name) else: response = "{} isn't a real spell dummy. Try {}{}".format(target_spell_name, gccfg.cmd_prefix, "listspells") await msg.channel.send('*{}:* {}'.format(msg.author.display_name, response))
async def work_cmd(msg): if msg.channel.id == gccfg.location_map.get("mall").channel_id: player = GCPlayer(msg.author.id) # make a random amount of money beween 1 and 5 pay = random.randrange(1, 5) # add pay to player's money total player.money += pay player.persist() response = "you work long and hard at the mall to earn some cash. you made " + str(pay) + " cash!" await sent_message(msg, response)
async def lookout_cmd(msg): user_data = GCPlayer(userid = msg.author.id) enemies = gcdb.findEnemies("location", user_data.location) response = "In " + user_data.location + " you see: \n" if enemies: for enemy_data in enemies: response += "\nA size {} {}. ID: {}".format(str(enemy_data["size"]), enemy_data["name"], enemy_data["id"]) await msg.channel.send('*' + str(msg.author.display_name) + ':* ' + response)
async def look_cmd(msg): response = None #get player location player = GCPlayer(msg.author.id) current_location = gccfg.location_map.get(player.location) if (current_location != None): response = current_location.look_txt else: response = "You are sitting in front of your parents' PC. There's a cup with some hot brew you made that you can't recall if it was tea or coffee, but it's gotten cold so who cares. You have bags under your eyes. You've been looking at this PC for way too long." await sent_message(msg, response)
async def known_spells(msg): # compile all user usable spell names player = GCPlayer(userid = msg.author.id) player_spells = [] for spell_name in player.known_spells: if spell_name in gccfg.spell_map: player_spells.append(gccfg.spell_map[spell_name]) # Build and send response response = "Currently known spells are: \n" for spell in player_spells: response += "\nName: {} | Cost: {}".format(spell.name, spell.cost) await msg.channel.send('*' + str(msg.author.display_name) + ':* ' + response)
async def fight(msg): target_id = int(msg.content.split(' ', 1)[1]) enemy_data = gcdb.getEnemyData(target_id) response = "" if enemy_data: enemy = GCEnemy(id = target_id) player = GCPlayer(userid = msg.author.id) if enemy.location != player.location: response = "That enemy is not present here." else: await gcfighting.initiate_combat(enemy, player, msg) return else: response = "No enemy with id {} exists".format(target_id) await msg.channel.send('*' + str(msg.author.display_name) + ':* ' + response)
async def transform_cmd(msg): # In the future I'll turn it into a tag, for now it is just hard to unlock flavor text player = GCPlayer(msg.author.id) currentLofi = player.lofi if currentLofi >= 1000000: response = "Epic orchestral music starts to sound. You summon the power of friendship and love and scream your magical girl name with all your soul. Your regular student clothes begin to disappear to reveal a super cute outfit without ever showing anything NSFW to the camera. People around you are hypnotized by this transformation, you notice that thanks to the 'Damns' and 'Holy f***s' they let out. You are a magical girl now, go kick some bad guy's ass!" elif currentLofi >= 100000: response = "you focus REALLY hard, and feel a breeze whip around you! ... but nothing really happened... so close..." elif currentLofi >= 10000: response = "you spin in place, really believing this time it will work!!! \n you fall over into your chair, having only **transformed** your hair into a big mess" elif currentLofi >= 1000: response = "you clasp your hands and look up to the sky, the moon reflected in your big eyes. you feel tingly!!! \n .... its just because you have been sitting too long..." elif currentLofi >= 100: response = "you grab your pen and poirouette around the room! you jump off your bed ready to take flight and- \n you fall onto the conveniently placed beanbag. nope, cant fly yet." else: response = "you spin around your room, your beautiful Guardian Garb flowing around you, those bad guys better watch out!!! \n... ok time to stop playing pretend and get out of this cheap cosplay gear." await sent_message(msg, response)
async def update_member_role(member): player_data = GCPlayer(member.id) roles_to_remove = [] for role in member.roles: if role.name != "@everyone": roles_to_remove.append(role) #print(roles_to_remove) await member.remove_roles(*roles_to_remove) roles_to_add = [] #get player location role location_role = gccfg.role_map.get(player_data.location) if location_role != None: roles_to_add.append(location_role) roles_to_add.append(gccfg.role_map.get("School Girl")) #print(roles_to_add) await member.add_roles(*roles_to_add)
async def goto_cmd(msg): # Setup necessary variables member = msg.author #The user player = GCPlayer(msg.author.id) desired_location = msg.content.split(' ', 1)[1] #the input with the command removed. Hopefully only the location name # check if desired location is a real location found_location = None for location in gccfg.location_map: location = gccfg.location_map[location] if location.is_alias(desired_location): found_location = location # location not found if found_location == None: response = "i dont know that location!" await sent_message(msg, response) # player already in location elif found_location.id == player.location: response = "You are already here" await sent_message(msg, response) # vaild desired location else: # Tell them they're moving response = 'You begin walking to ' + found_location.full_name + ". it will take 5 seconds" await sent_message(msg, response) #wait 5 seconds await asyncio.sleep(5) # change database location player = GCPlayer(msg.author.id) player.location = found_location.id player.persist() # update member roles await update_member_role(member)
async def initiate_combat(enemy, player, msg): # Check if there is already a fight happening in that district if player.location in gccfg.fights: existing = gccfg.fights[player.location] response = player.location + " was already being fought over!\n" if player.userid not in existing.player_ids: # Add player to fight if they werent already in it response += "\n but {} has now joined the battle!".format( msg.author.display_name) existing.player_ids.append(player.userid) existing.pts_remaining[player.userid] = gccfg.pts_per_round if enemy.id not in existing.enemy_ids: # Add target to fight if they were not already involved response += "\n but {} has now joined the battle!".format( enemy.name) existing.enemy_ids.append(enemy.id) # Send the response and cut the function, dont need to start a second loop await msg.channel.send('*' + str(msg.author.display_name) + ':* ' + response) return # Initialize the fight fight = fight_data(location=enemy.location, enemy_ids=[enemy.id], player_ids=[player.userid], pts_remaining={player.userid: gccfg.pts_per_round}) # Tell the user the fight started start_msg = "{} prepares to begin combat with {}! They have 30s to prepare attacks!".format( msg.author.display_name, enemy.name) await msg.channel.send('*' + str(msg.author.display_name) + ':* ' + start_msg) while (len(fight.enemy_ids) > 0 and len(fight.player_ids) > 0): await asyncio.sleep(30) # Separate player attacks by priority passives = [] actives = [] for spell in fight.player_queue: if spell.type in gccfg.passive_types: passives.append(spell) else: actives.append(spell) # Calculate first priority spells, pool all buffs defense_pool = 0 attack_pool = 0 healing_pool = 0 passives_response = "" for spell in passives: if spell.type == gccfg.spell_type_def_buff: defense_pool += spell.power if spell.type == gccfg.spell_type_atk_buff: attack_pool += spell.power if spell.type == gccfg.spell_type_heal_aoe: healing_pool += spell.power if spell.type == gccfg.spell_type_heal_target: if spell.target_id in fight.player_ids: # Grab player object from id and heal passives_response += "<@{}> is healed for {} lofi!\n".format( spell.target_id, spell.power) healed_target = GCPlayer(userid=spell.target_id) healed_target.lofi += spell.power healed_target.persist() # Distribute AOE healing heal_per_player = int(healing_pool / len(fight.player_ids)) if heal_per_player > 0: passives_response += "Everyone is healed for {} lofi!\n".format( heal_per_player) for healed_id in fight.player_ids: # Grab player object from id and heal healed = GCPlayer(userid=healed_id) healed.change_hp(heal_per_player, gccfg.damage_source_combat) # Build response for buffs if defense_pool > 0: passives_response += "Defense is buffed by {}%!\n".format( defense_pool * 10) if attack_pool > 0: passives_response += "Attacks are buffed by {}%!\n".format( attack_pool * 10) if passives_response != "": await msg.channel.send(passives_response) # Calculate secondary spells total_damage = 0 total_defense = 0 for spell in actives: if spell.type == gccfg.spell_type_damage: total_damage += spell.power if spell.type == gccfg.spell_type_defense: total_defense += spell.power # add 10% to damage per point in attack buffs if attack_pool != 0: attack_pool /= 10 attack_pool += 1 total_damage *= attack_pool # add 10% to defense per point in defense buffs if defense_pool != 0: defense_pool /= 10 defense_pool += 1 total_defense *= defense_pool # Apply damage to enemies damage_per_enemy = int(total_damage / len(fight.enemy_ids)) player_damage_msg = "The Magical Girls deal {} damage to every enemy in the fight!\n".format( str(damage_per_enemy)) targets = gcutility.copy_list(fight.enemy_ids) for hurt_id in targets: hurt = GCEnemy(id=hurt_id) hurt.changeHp(damage_per_enemy * -1) if hurt.hp <= 0: player_damage_msg += "\n{} has been slain by the magical girls and removed from the fight!".format( hurt.name) # potentially end the fight if no enemies are left if len(fight.enemy_ids) == 0: player_damage_msg += "\n\nThe last enemy in the fight has been slain! " if gcdb.findEnemies('location', fight.location): player_damage_msg += "{} is still not safe however...".format( fight.location) else: player_damage_msg += "{} is safe from the corruption!! For now...".format( fight.location) gccfg.fights.pop(fight.location) await msg.channel.send(player_damage_msg) return await msg.channel.send(player_damage_msg) # Decide enemy attacks after players attack to ensure # all targeted enemies get to fight back as long as # they survived. avg_size = 0 for monster_id in fight.enemy_ids: monster = GCEnemy(id=monster_id) avg_size += monster.size choice = random.randrange(0, len(monster.attacks)) fight.enemy_queue.append(gccfg.spell_map[monster.attacks[choice]]) # calculate avg size for damage multiplier avg_size /= len(fight.enemy_ids) # calculate total damage from enemies monster_damage = 0 for spell in fight.enemy_queue: monster_damage += spell.power * avg_size # Subtract player defense, minimum zero damage monster_damage -= total_defense if monster_damage <= 0: monster_damage = 0 # distribute monster damage monster_damage_per_player = int(monster_damage / len(fight.player_ids)) monster_damage_message = "The fighting monsters deal {} damage to each player!\n".format( str(monster_damage_per_player)) damaged_players = gcutility.copy_list(fight.player_ids) for fighter_id in damaged_players: fighter = GCPlayer(userid=fighter_id) fighter.change_hp(-1 * monster_damage_per_player, gccfg.damage_source_combat) if fighter.lofi <= 0: monster_damage_message += "\n<@{}> Has been critically wounded and removed from the fight!".format( fighter.userid) # potentially end the fight if no players are left if len(fight.player_ids) == 0: monster_damage_message += "\n\nThe last player has been slain! {} remains in darkness...".format( fight.location) gccfg.fights.pop(fight.location) await msg.channel.send(monster_damage_message) return await msg.channel.send(monster_damage_message) # Clear spell queues and inform players of new round fight.enemy_queue = [] fight.player_queue = [] for uid in fight.pts_remaining: fight.pts_remaining[uid] = gccfg.pts_per_round new_round_msg = "The players once again have 30s to prepare their spells..." await msg.channel.send(new_round_msg)
async def money_cmd(msg): player = GCPlayer(msg.author.id) response = "You have {} currency.".format(player.money) await sent_message(msg, response)
async def queue_spell(msg): # Parse target spell and get player target_spell_name = shlex.split(msg.content)[1] player = GCPlayer(userid = msg.author.id) # Ensure spell exists and is known if (target_spell_name in gccfg.spell_map and gccfg.spell_map[target_spell_name].name in player.known_spells): spell = gccfg.spell_map[target_spell_name].new_copy() # Check for fight and ensure player participation if player.location in gccfg.fights: fight = gccfg.fights[player.location] if player.userid in fight.player_ids: # TODO - add point system if player.lofi > spell.cost: if spell.cost <= fight.pts_remaining[player.userid]: response = "" # Parse target for targeted spells if spell.type == gccfg.spell_type_heal_target: mentions = msg.mentions if len(mentions) == 1: spell.target_id = mentions[0].id if spell.target_id not in fight.player_ids: response = "The target must be fighting with you!" if len(mentions) < 1: response = "You need to mention a target!" if len(mentions) > 1: response = "This spell can only target one player" if response != "": await msg.channel.send('*{}:* {}'.format(msg.author.display_name, response)) return player.lofi -= int(spell.cost) fight.pts_remaining[player.userid] -= int(spell.cost) fight.player_queue.append(spell) # Build list of enemy names for flavortext enemy_names = "" enemy_number = 0 for enemy_id in fight.enemy_ids: enemy_number += 1 enemy = GCEnemy(id = enemy_id) if enemy_number > 1 and enemy_number == len(fight.enemy_ids): enemy_names += ", and {} id: {}".format(enemy.name, enemy.id) elif enemy_number > 1: enemy_names += ", {} id: {}".format(enemy.name, enemy.id) else: enemy_names += "{} id: {}".format(enemy.name, enemy.id) response = "Successfully queued {} against {} for {} lofi".format(spell.name, enemy_names, spell.cost) player.persist() else: response = "You only have {} points remaining! that spell costs {}.".format(fight.pts_remaining[player.userid], spell.cost) else: response = "You only have {} lofi! You need {} to queue that.".format(player.lofi, spell.cost) else: response = "You are not participating in the present fight." else: response = "There are no fights to attack for here." else: response = "You don't know that spell." await msg.channel.send('*{}:* {}'.format(msg.author.display_name, response))
async def lofi_cmd(msg): player = GCPlayer(msg.author.id) response = "You have {} lofi.".format(player.lofi) await sent_message(msg, response)
async def test(msg): player = GCPlayer(userid = msg.author.id) player.lofi -= 1 player.money += 1 player.persist()
async def register_cmd(msg): if GCPlayer(userid=msg.author.id).new: await msg.channel.send('*' + str(msg.author.display_name) + ':* ' + 'You registered!') else: await msg.channel.send('*' + str(msg.author.display_name) + ':*' + ' you already registered')