840d3f95 by Barry

Added a reset tickets, updated the bot and pankration.

1 parent 5489faaf
...@@ -68,6 +68,18 @@ def db_buy_ticket(member_id, amount): ...@@ -68,6 +68,18 @@ def db_buy_ticket(member_id, amount):
68 except Exception as e: 68 except Exception as e:
69 log(e) 69 log(e)
70 70
71 def db_reset_all_tickets(member_id):
72 log("Resetting Tickets - DB")
73 try:
74 conn = sqlite3.connect('db.sqlite3')
75 c = conn.cursor()
76 c.execute("""UPDATE members SET tickets = 0
77 WHERE member_id = ?;""", (member_id,))
78 conn.commit()
79 return True
80 except Exception as e:
81 log(e)
82
71 def db_update_credit(member_id, amount): 83 def db_update_credit(member_id, amount):
72 conn = sqlite3.connect('db.sqlite3') 84 conn = sqlite3.connect('db.sqlite3')
73 c = conn.cursor() 85 c = conn.cursor()
......
No preview for this file type
...@@ -62,6 +62,7 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help', ...@@ -62,6 +62,7 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help',
62 '!whoplayed': 'do_whoplayed', 62 '!whoplayed': 'do_whoplayed',
63 '!gimmecredits': 'do_gimmecredits', '!gimmecredit': 'do_gimmecredits', 63 '!gimmecredits': 'do_gimmecredits', '!gimmecredit': 'do_gimmecredits',
64 '!grantcredits': 'do_grantcredits', 64 '!grantcredits': 'do_grantcredits',
65 '!resetalltickets': 'do_resetalltickets',
65 '!ticketrank': 'do_ticketrank', 66 '!ticketrank': 'do_ticketrank',
66 '!startraffle': 'do_startraffle', 67 '!startraffle': 'do_startraffle',
67 '!raffle': 'do_raffle', 68 '!raffle': 'do_raffle',
...@@ -414,6 +415,19 @@ def do_gimmecredits(client, message_parts, message): ...@@ -414,6 +415,19 @@ def do_gimmecredits(client, message_parts, message):
414 send_message(client, message.author, "You already have credits. Stop begging.") 415 send_message(client, message.author, "You already have credits. Stop begging.")
415 return 416 return
416 417
418 def do_resetalltickets(client, message_parts, message, channel=None):
419 if not channel and message.author.id != '78767557628133376':
420 send_message(client, message.channel, "You are not Hellsbreath. Go away.")
421 return
422 members = data.db_get_all_members()
423 if len(members) < 0:
424 send_message(client, message.channel, "There was a problem looking up your information.")
425 else:
426 for member in members:
427 if member['tickets'] > 0:
428 data.db_reset_all_tickets(member['member_id'])
429 send_message(client, message.channel, "{} had {} tickets and was reset to 0.".format(member['member_name'], member['tickets']))
430 return
417 431
418 def do_grantcredits(client, message_parts, message, channel=None): 432 def do_grantcredits(client, message_parts, message, channel=None):
419 if not channel and message.author.id != '78767557628133376': 433 if not channel and message.author.id != '78767557628133376':
...@@ -1289,13 +1303,22 @@ def check_arena(): ...@@ -1289,13 +1303,22 @@ def check_arena():
1289 fighting = False 1303 fighting = False
1290 if action.attacker == monster: 1304 if action.attacker == monster:
1291 result, xp_msg = monster.add_xp(action.xp) 1305 result, xp_msg = monster.add_xp(action.xp)
1306 # give a small amount to the loser
1307 if result:
1308 out_str += xp_msg
1309 result, xp_msg = monster2.add_xp(5)
1292 if result: 1310 if result:
1293 out_str += xp_msg 1311 out_str += xp_msg
1294 winner = 1 1312 winner = 1
1295 monster.wins += 1 1313 monster.wins += 1
1296 monster2.losses += 1 1314 monster2.losses += 1
1297 else: 1315 else:
1316 # give a small amount to the loser
1298 result, xp_msg = monster2.add_xp(action.xp) 1317 result, xp_msg = monster2.add_xp(action.xp)
1318 # give a small amount to the loser
1319 if result:
1320 out_str += xp_msg
1321 result, xp_msg = monster.add_xp(5)
1299 if result: 1322 if result:
1300 out_str += xp_msg 1323 out_str += xp_msg
1301 winner = 2 1324 winner = 2
......
...@@ -212,7 +212,8 @@ class Spells: ...@@ -212,7 +212,8 @@ class Spells:
212 'magic_acc_stat': spell['magic_acc_stat'], 212 'magic_acc_stat': spell['magic_acc_stat'],
213 'base_damage': type_data[spell['damage_type']], 213 'base_damage': type_data[spell['damage_type']],
214 'multiplier': type_data['multiplier'], 214 'multiplier': type_data['multiplier'],
215 'mp_cost': spell['mp_cost'] 215 'mp_cost': spell['mp_cost'],
216 'damage_type': spell['damage_type']
216 } 217 }
217 return spell_data 218 return spell_data
218 219
...@@ -515,6 +516,8 @@ class Monster: ...@@ -515,6 +516,8 @@ class Monster:
515 def __init__(self, monster_type, family_name, family, base_hp, base_mp, level, weapon_base_damage, main_job, 516 def __init__(self, monster_type, family_name, family, base_hp, base_mp, level, weapon_base_damage, main_job,
516 support_job, innate_feral_skills, equipped_feral_skills, dicipline_level): 517 support_job, innate_feral_skills, equipped_feral_skills, dicipline_level):
517 self.custom_name = None 518 self.custom_name = None
519 self.status_effects = {}
520
518 self.monster_type = monster_type 521 self.monster_type = monster_type
519 self.family_name = family_name 522 self.family_name = family_name
520 self.family = family 523 self.family = family
...@@ -553,6 +556,7 @@ class Monster: ...@@ -553,6 +556,7 @@ class Monster:
553 self.mp = self.get_mp() 556 self.mp = self.get_mp()
554 self.wins = 0 557 self.wins = 0
555 self.losses = 0 558 self.losses = 0
559 self.battle_memory = []
556 560
557 def __str__(self): 561 def __str__(self):
558 try: 562 try:
...@@ -586,7 +590,7 @@ class Monster: ...@@ -586,7 +590,7 @@ class Monster:
586 590
587 def get_hp(self): 591 def get_hp(self):
588 #this is a bit dumb but it's close enough. 592 #this is a bit dumb but it's close enough.
589 return int((self.level * 20) + self.base_hp) 593 return self.get_status_effect('hp', int((self.level * 20) + self.base_hp))
590 594
591 def get_mp(self): 595 def get_mp(self):
592 #this is a bit dumb but it's close enough. 596 #this is a bit dumb but it's close enough.
...@@ -596,7 +600,7 @@ class Monster: ...@@ -596,7 +600,7 @@ class Monster:
596 600
597 main_mp = int((self.level * (self.base_mp + main_add_amount)) + self.base_mp) 601 main_mp = int((self.level * (self.base_mp + main_add_amount)) + self.base_mp)
598 sub_mp = int((self.level/2) * sub_add_amount) 602 sub_mp = int((self.level/2) * sub_add_amount)
599 return main_mp + sub_mp 603 return self.get_status_effect('mp', main_mp + sub_mp)
600 604
601 605
602 def get_fp(self): 606 def get_fp(self):
...@@ -637,45 +641,45 @@ class Monster: ...@@ -637,45 +641,45 @@ class Monster:
637 641
638 642
639 def get_dexterity(self): 643 def get_dexterity(self):
640 return int(round(max(self.base_dex, self.level * self.dex_per_level))) 644 return self.get_status_effect('dex', int(round(max(self.base_dex, self.level * self.dex_per_level))))
641 645
642 def get_accuracy(self): 646 def get_accuracy(self):
643 # We ignore magic / ranged / melee here and give everyone a good acc. This could be improved by doing a lookup for each type and based on the 647 # We ignore magic / ranged / melee here and give everyone a good acc. This could be improved by doing a lookup for each type and based on the
644 # type of monster (magic, range, or melee) then adjust the combat skill according to what type of attack is being performed. 648 # type of monster (magic, range, or melee) then adjust the combat skill according to what type of attack is being performed.
645 return int(math.floor(3*self.get_dexterity()/4) + self.get_combat_skill()) 649 return self.get_status_effect('acc', math.floor(3*self.get_dexterity()/4) + self.get_combat_skill())
646 650
647 def get_evasion(self): 651 def get_evasion(self):
648 job_eva = adjustments_by_job[self.main_job] 652 job_eva = adjustments_by_job[self.main_job]
649 base_eva = int(round(max(job_eva['base_eva'], self.level * job_eva['eva_per_level']))) 653 base_eva = int(round(max(job_eva['base_eva'], self.level * job_eva['eva_per_level'])))
650 654 return self.get_status_effect('eva', base_eva + int(self.get_agility() / 2))
651 return base_eva + int(self.get_agility() / 2)
652 655
653 def get_vitality(self): 656 def get_vitality(self):
654 return int(round(max(self.base_vit, self.level * self.vit_per_level))) 657 return self.get_status_effect('vit', int(round(max(self.base_vit, self.level * self.vit_per_level))))
655 658
656 def get_strength(self): 659 def get_strength(self):
657 return int(round(max(self.base_str, self.level * self.str_per_level))) 660 return self.get_status_effect('str', int(round(max(self.base_str, self.level * self.str_per_level))))
658 661
659 def get_agility(self): 662 def get_agility(self):
660 return int(round(max(self.base_agi, self.level * self.agi_per_level))) 663 return self.get_status_effect('agi', round(max(self.base_agi, self.level * self.agi_per_level)))
661 664
662 def get_mind(self): 665 def get_mind(self):
663 return int(round(max(self.base_mnd, self.level * self.mnd_per_level))) 666 return self.get_status_effect('mnd', int(round(max(self.base_mnd, self.level * self.mnd_per_level))))
664 667
665 def get_intelligence(self): 668 def get_intelligence(self):
666 return int(round(max(self.base_int, self.level * self.int_per_level))) 669 return self.get_status_effect('int', int(round(max(self.base_int, self.level * self.int_per_level))))
667 670
668 def get_charisma(self): 671 def get_charisma(self):
669 return int(round(max(self.base_chr, self.level * self.chr_per_level))) 672 return self.get_status_effect('cha', int(round(max(self.base_chr, self.level * self.chr_per_level))))
670 673
671 def get_base_defense(self): 674 def get_base_defense(self):
672 return (math.floor(self.get_vitality()/2) + 8 + self.level) 675 return self.get_status_effect('def', (math.floor(self.get_vitality()/2) + 8 + self.level))
673 676
674 def get_hp_percent(self): 677 def get_hp_percent(self):
675 return max(1, int(round((self.hp/self.get_hp())*100))) 678 return max(1, int(round((self.hp/self.get_hp())*100)))
676 679
677 def get_magic_evasion(self): 680 def get_magic_evasion(self, damage_type):
678 return max(1, int(1+round(self.level/4))) 681 # This handles spell types and elemental additions due to damage type
682 return self.get_status_effect(damage_type + '_resist', max(1, int(1+round(self.level/4))))
679 683
680 def get_hit_rate(self, enemy_eva, level_difference): 684 def get_hit_rate(self, enemy_eva, level_difference):
681 rate = 75 + math.floor(((self.get_accuracy() - enemy_eva)/2)) - (2*level_difference) 685 rate = 75 + math.floor(((self.get_accuracy() - enemy_eva)/2)) - (2*level_difference)
...@@ -699,7 +703,7 @@ class Monster: ...@@ -699,7 +703,7 @@ class Monster:
699 elif magic_acc_stat == 'agi': 703 elif magic_acc_stat == 'agi':
700 dSTAT = self.get_agility() - enemy.get_agility() 704 dSTAT = self.get_agility() - enemy.get_agility()
701 705
702 magic_hit_rate = 50 - 0.5 * (enemy.get_magic_evasion() - dSTAT) 706 magic_hit_rate = 50 - 0.5 * (enemy.get_magic_evasion(spell_data['damage_type']) - dSTAT)
703 707
704 if magic_hit_rate < 5: 708 if magic_hit_rate < 5:
705 magic_hit_rate = 5 709 magic_hit_rate = 5
...@@ -838,6 +842,47 @@ class Monster: ...@@ -838,6 +842,47 @@ class Monster:
838 842
839 return base_damage 843 return base_damage
840 844
845 # it is up to the rest of the system to understand how to read this data and act on it.
846 # Example Call: ('acc', '10', False, 30)
847 def set_status_effect(self, effect, amount, is_percent, expires_seconds):
848 self.status_effects[effect] = {'amount': amount, 'is_percent': is_percent, 'expires_seconds': expires_seconds}
849
850 def get_status_effect(self, effect, base_amount):
851
852 if effect in self.status_effects:
853 amount = self.status_effects[effect]['amount']
854 if self.status_effects[effect]['is_percent']:
855 return int(base_amount + base_amount * (amount/100))
856 else:
857 return int(base_amount + amount)
858 else:
859 return base_amount
860
861 # This is a list of all status effects that are available.
862 def get_status_effect_list(self):
863 return [
864 'acc',
865 'agi',
866 'cha',
867 'def',
868 'dex',
869 'eva',
870 'hp',
871 'int',
872 'mnd',
873 'mp',
874 'str',
875 'vit',
876 'fire_resist',
877 'water_resist',
878 'ice_resist',
879 'wind_resist',
880 'earth_resist',
881 'thunder_resist',
882 'light_resist',
883 'dark_resist'
884 ]
885
841 # Calculate the base damage against the provided defense 886 # Calculate the base damage against the provided defense
842 # attack_type can be 'ranged' or 'melee' 887 # attack_type can be 'ranged' or 'melee'
843 # TODO: Replace enemyvit with the actual enemy variable 888 # TODO: Replace enemyvit with the actual enemy variable
...@@ -855,6 +900,33 @@ class Monster: ...@@ -855,6 +900,33 @@ class Monster:
855 final_damage = int(bd * pDif) 900 final_damage = int(bd * pDif)
856 return final_damage 901 return final_damage
857 902
903 # Choose the best action for the monster
904 def get_best_action(self, monster):
905 # Step 0: Am I already casting a spell? Is it time to calc damage from that?
906
907 # Step 1: Is magic possible?
908 spell_list = Spells().get_spell_list(self.level, job=self.main_job, sub_job=self.sub_job)
909
910 # Step 2: Do i have a memory of this monster from past battles? Does it have any elemental weakness?
911
912 # Step 3: What status effects is the monster currently under? What are the effects(DOTS) we can apply?
913
914 # find out the avg damage from each type of attack and sort them
915
916 # find out if we need to do defensive actions given the amount of life left in the enemy vs how much damage it does.
917 # We should also store how hard the AI has hit previously and adjust accordingly (Store previous average damage per hit). IE project how much damage we will
918 # do vs how much they will do and choose an action
919
920 # Decide if we need to do healing as part of the defensive strategy.
921 # - This should be partially decided based on the class and the efficacy of healing
922 # - This should be comparied against shielding. Shielding is often based on a specific type of hit so remember the hits they have
923 # Taken on us in the past.
924
925 # Modify apply damage to pass what type of damage it was (magic, melee, or ranged)
926
927 # If we don't need defense (we thi)
928 pass
929
858 def attack(self, monster): 930 def attack(self, monster):
859 is_a_crit = False 931 is_a_crit = False
860 is_a_hit = False 932 is_a_hit = False
...@@ -862,6 +934,7 @@ class Monster: ...@@ -862,6 +934,7 @@ class Monster:
862 resisted = False 934 resisted = False
863 damage = 0 935 damage = 0
864 936
937 self.get_best_action(monster)
865 938
866 ###### 939 ######
867 # TODO: Build some type of AI / testing to find the most powerful attack and use that (magic, melee, or ranged) 940 # TODO: Build some type of AI / testing to find the most powerful attack and use that (magic, melee, or ranged)
...@@ -1077,6 +1150,7 @@ if __name__ == "__main__": ...@@ -1077,6 +1150,7 @@ if __name__ == "__main__":
1077 print(hunt_response.message) 1150 print(hunt_response.message)
1078 monster = hunt_response.monster 1151 monster = hunt_response.monster
1079 monster.set_monster_name('Kickass 1') 1152 monster.set_monster_name('Kickass 1')
1153 monster.set_status_effect('int', 100, False, None)
1080 print("The Soul Plate Shows: \n\n{}".format(monster)) 1154 print("The Soul Plate Shows: \n\n{}".format(monster))
1081 # print(monster.set_strategy(4, 3)) 1155 # print(monster.set_strategy(4, 3))
1082 # print(monster.set_strategy(1, 1)) 1156 # print(monster.set_strategy(1, 1))
......