Added the start of weapon skills calc and lots of little fixes.
Showing
4 changed files
with
63 additions
and
19 deletions
... | @@ -339,6 +339,14 @@ def db_remove_soul_plate(member_id, idx): | ... | @@ -339,6 +339,14 @@ def db_remove_soul_plate(member_id, idx): |
339 | conn.commit() | 339 | conn.commit() |
340 | return True | 340 | return True |
341 | 341 | ||
342 | def db_update_pankration_record(member_id, column_name, value): | ||
343 | conn = sqlite3.connect('db.sqlite3') | ||
344 | c = conn.cursor() | ||
345 | c.execute("""UPDATE pankration SET """ + column_name + """ = ? | ||
346 | WHERE member_id = ?;""", (value, member_id)) | ||
347 | conn.commit() | ||
348 | conn.close() | ||
349 | |||
342 | def db_add_reflector(member_id, reflector): | 350 | def db_add_reflector(member_id, reflector): |
343 | pan_record = db_get_pankration_record(member_id) | 351 | pan_record = db_get_pankration_record(member_id) |
344 | log("{}".format(member_id)) | 352 | log("{}".format(member_id)) |
... | @@ -394,15 +402,22 @@ def db_convert_soul_plate_to_reflector(member_id, soul_plate, idx): | ... | @@ -394,15 +402,22 @@ def db_convert_soul_plate_to_reflector(member_id, soul_plate, idx): |
394 | return True | 402 | return True |
395 | 403 | ||
396 | 404 | ||
397 | def db_register_battle(member_id, reflector, idx, target_member=None): | 405 | def db_register_battle(member_id, reflector, idx, target_member_id=None): |
398 | pan_record = db_get_pankration_record(member_id) | 406 | pan_record = db_get_pankration_record(member_id) |
399 | conn = sqlite3.connect('db.sqlite3') | 407 | conn = sqlite3.connect('db.sqlite3') |
400 | c = conn.cursor() | 408 | c = conn.cursor() |
401 | db_state = c.execute("SELECT battle_id, reflector_primary member_id FROM pankration_arena WHERE battle_status = 'waiting';").fetchall() | 409 | if target_member_id: |
410 | db_state = c.execute("SELECT battle_id, reflector_primary FROM pankration_arena WHERE battle_status = 'waiting' AND direct_challenge = ?;", (member_id,)).fetchall() | ||
411 | else: | ||
412 | db_state = c.execute("SELECT battle_id, reflector_primary FROM pankration_arena WHERE battle_status = 'waiting' AND direct_challenge = 0;").fetchall() | ||
402 | if not db_state: | 413 | if not db_state: |
403 | log("No battles available: {}".format(idx,)) | 414 | log("No battles available: {}".format(idx,)) |
404 | c.execute("""INSERT INTO pankration_arena(primary_member_id, reflector_primary) | 415 | if target_member_id: |
405 | VALUES(?, ?);""", (member_id, pickle.dumps(reflector))) | 416 | c.execute("""INSERT INTO pankration_arena(primary_member_id, reflector_primary, direct_challenge) |
417 | VALUES(?, ?, ?);""", (member_id, pickle.dumps(reflector), target_member_id)) | ||
418 | else: | ||
419 | c.execute("""INSERT INTO pankration_arena(primary_member_id, reflector_primary) | ||
420 | VALUES(?, ?);""", (member_id, pickle.dumps(reflector))) | ||
406 | conn.commit() | 421 | conn.commit() |
407 | conn.close() | 422 | conn.close() |
408 | db_remove_reflector(member_id, idx) | 423 | db_remove_reflector(member_id, idx) |
... | @@ -440,16 +455,17 @@ def db_complete_battle(battle_id, primary_member_id, primary_reflector, secondar | ... | @@ -440,16 +455,17 @@ def db_complete_battle(battle_id, primary_member_id, primary_reflector, secondar |
440 | else: | 455 | else: |
441 | c.execute("""UPDATE pankration SET reflectors = ?, losses = losses + 1 | 456 | c.execute("""UPDATE pankration SET reflectors = ?, losses = losses + 1 |
442 | WHERE member_id = ?;""", (pickle.dumps(reflectors), primary_member_id)) | 457 | WHERE member_id = ?;""", (pickle.dumps(reflectors), primary_member_id)) |
458 | conn.commit() | ||
443 | 459 | ||
444 | reflectors = pickle.loads(str(db_get_pankration_record(secondary_member_id)['reflectors'])) | 460 | reflectors2 = pickle.loads(str(db_get_pankration_record(secondary_member_id)['reflectors'])) |
445 | reflectors.append(secondary_reflector) | 461 | reflectors2.append(secondary_reflector) |
446 | log('Completing battle - secondary') | 462 | log('Completing battle - secondary') |
447 | if winner == 2: | 463 | if winner == 2: |
448 | c.execute("""UPDATE pankration SET reflectors = ?, wins = wins + 1 | 464 | c.execute("""UPDATE pankration SET reflectors = ?, wins = wins + 1 |
449 | WHERE member_id = ?;""", (pickle.dumps(reflectors), secondary_member_id)) | 465 | WHERE member_id = ?;""", (pickle.dumps(reflectors2), secondary_member_id)) |
450 | else: | 466 | else: |
451 | c.execute("""UPDATE pankration SET reflectors = ?, losses = losses + 1 | 467 | c.execute("""UPDATE pankration SET reflectors = ?, losses = losses + 1 |
452 | WHERE member_id = ?;""", (pickle.dumps(reflectors), secondary_member_id)) | 468 | WHERE member_id = ?;""", (pickle.dumps(reflectors2), secondary_member_id)) |
453 | conn.commit() | 469 | conn.commit() |
454 | conn.close() | 470 | conn.close() |
455 | log('Completing battle - done') | 471 | log('Completing battle - done') | ... | ... |
No preview for this file type
... | @@ -93,6 +93,7 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help', | ... | @@ -93,6 +93,7 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help', |
93 | '!convertplate': 'do_convert_plate', '!convertsoulplate': 'do_convert_plate', | 93 | '!convertplate': 'do_convert_plate', '!convertsoulplate': 'do_convert_plate', |
94 | '!assignskill': 'do_assign_skill', | 94 | '!assignskill': 'do_assign_skill', |
95 | '!registerbattle': 'do_register_battle', | 95 | '!registerbattle': 'do_register_battle', |
96 | '!setreflectorname': 'do_set_reflector_name', | ||
96 | '!pankration': 'do_pankration', | 97 | '!pankration': 'do_pankration', |
97 | } | 98 | } |
98 | 99 | ||
... | @@ -1041,6 +1042,7 @@ def do_pankration(client, message_parts, message): | ... | @@ -1041,6 +1042,7 @@ def do_pankration(client, message_parts, message): |
1041 | Ex: **!convertplate 1 reflector** | 1042 | Ex: **!convertplate 1 reflector** |
1042 | **!convertplate 4 skill** | 1043 | **!convertplate 4 skill** |
1043 | **!assignskill <reflector number> <skill num>** - Assigns a skill to a reflector. Each skill is worth a certain amount of feral points, each monster has a maximum of feral points available. | 1044 | **!assignskill <reflector number> <skill num>** - Assigns a skill to a reflector. Each skill is worth a certain amount of feral points, each monster has a maximum of feral points available. |
1045 | **!setreflectorname <reflector number> <name>** - This will rename a monster in your collection to a custom name. | ||
1044 | 1046 | ||
1045 | *Arena Battle:* | 1047 | *Arena Battle:* |
1046 | **!registerbattle <reflector number>** - Adds your reflector to the queue in the arena. When the arena is available your monster will be paired with either another players monster or a similarly matched arena monster. | 1048 | **!registerbattle <reflector number>** - Adds your reflector to the queue in the arena. When the arena is available your monster will be paired with either another players monster or a similarly matched arena monster. |
... | @@ -1048,6 +1050,28 @@ def do_pankration(client, message_parts, message): | ... | @@ -1048,6 +1050,28 @@ def do_pankration(client, message_parts, message): |
1048 | 1050 | ||
1049 | """.format(message.author.mention())) | 1051 | """.format(message.author.mention())) |
1050 | 1052 | ||
1053 | def do_set_reflector_name(client, message_parts, message): | ||
1054 | member = data.db_get_member(message.author.id) | ||
1055 | |||
1056 | if len(message_parts) < 2: | ||
1057 | send_message(client, message.channel, 'You must provide the reflector number and the new name.') | ||
1058 | return | ||
1059 | |||
1060 | reflector_num = message_parts[0] | ||
1061 | new_name = ' '.join(message_parts[1:]) | ||
1062 | pankration_data = data.db_get_pankration_record(member['member_id']) | ||
1063 | if pankration_data and pankration_data['reflectors']: | ||
1064 | reflectors = pickle.loads(str(pankration_data['reflectors'])) | ||
1065 | |||
1066 | if not reflector_num.isdigit() or int(reflector_num) < 1 or int(reflector_num) > len(reflectors): | ||
1067 | send_message(client, message.channel, 'The requested reflector is invalid. Please provide the number from !listreflectors') | ||
1068 | return | ||
1069 | reflector_num = int(reflector_num) - 1 | ||
1070 | reflectors[reflector_num].set_monster_name(new_name) | ||
1071 | data.db_update_pankration_record(member['member_id'], 'reflectors', pickle.dumps(reflectors)) | ||
1072 | send_message(client, message.channel, 'The reflector (monster) name has been updated.') | ||
1073 | else: | ||
1074 | send_message(client, message.channel, 'Unable to find the reflector data.') | ||
1051 | 1075 | ||
1052 | def do_register_battle(client, message_parts, message): | 1076 | def do_register_battle(client, message_parts, message): |
1053 | member = data.db_get_member(message.author.id) | 1077 | member = data.db_get_member(message.author.id) |
... | @@ -1067,13 +1091,17 @@ def do_register_battle(client, message_parts, message): | ... | @@ -1067,13 +1091,17 @@ def do_register_battle(client, message_parts, message): |
1067 | reflector_num = int(reflector_num) - 1 | 1091 | reflector_num = int(reflector_num) - 1 |
1068 | 1092 | ||
1069 | if len(message_parts) > 1: | 1093 | if len(message_parts) > 1: |
1070 | user = ' '.join(message_parts[1:]) | 1094 | username = ' '.join(message_parts[1:]) |
1071 | 1095 | ||
1072 | data.db_register_battle(member['member_id'], reflectors[reflector_num], reflector_num, user) | 1096 | target_member = data.db_get_member(username=username) |
1073 | send_message(client, message.channel, "Your *{} level {}* has been registered for battle with {}. The battle will begin when the arena is availble with the next challenger".format(reflectors[reflector_num].monster_type, reflectors[reflector_num].level, user)) | 1097 | if target_member and 'member_id' in target_member: |
1098 | data.db_register_battle(member['member_id'], reflectors[reflector_num], reflector_num, target_member['member_id']) | ||
1099 | send_message(client, message.channel, "Your *{} level {}* has been registered for battle with {}. The battle will begin when the arena is availble with the next challenger".format(reflectors[reflector_num].get_monster_name(), reflectors[reflector_num].level, username)) | ||
1100 | else: | ||
1101 | send_message(client, message.channel, "There was a problem looking up that user.") | ||
1074 | else: | 1102 | else: |
1075 | data.db_register_battle(member['member_id'], reflectors[reflector_num], reflector_num) | 1103 | data.db_register_battle(member['member_id'], reflectors[reflector_num], reflector_num) |
1076 | send_message(client, message.channel, "Your *{} level {}* has been registered for battle. The battle will begin when the arena is availble with the next challenger".format(reflectors[reflector_num].monster_type, reflectors[reflector_num].level)) | 1104 | send_message(client, message.channel, "Your *{} level {}* has been registered for battle. The battle will begin when the arena is availble with the next challenger".format(reflectors[reflector_num].get_monster_name(), reflectors[reflector_num].level)) |
1077 | else: | 1105 | else: |
1078 | send_message(client, message.channel, 'You have no available reflectors. You can get reflectors by converting soul plates with !convertplate') | 1106 | send_message(client, message.channel, 'You have no available reflectors. You can get reflectors by converting soul plates with !convertplate') |
1079 | return | 1107 | return |
... | @@ -1221,15 +1249,15 @@ def check_arena(): | ... | @@ -1221,15 +1249,15 @@ def check_arena(): |
1221 | 1249 | ||
1222 | send_message(client, arena_channel, "Ladies and gentlemen!\nFor our next match...") | 1250 | send_message(client, arena_channel, "Ladies and gentlemen!\nFor our next match...") |
1223 | time.sleep(5) | 1251 | time.sleep(5) |
1224 | send_message(client, arena_channel, "In the red corner we have...\n **{}**!".format(monster.monster_type)) | 1252 | send_message(client, arena_channel, "In the red corner we have...\n **{}**!".format(monster.get_monster_name())) |
1225 | time.sleep(5) | 1253 | time.sleep(5) |
1226 | send_message(client, arena_channel, "Hmmm... This monster seems {} and {}.".format(monster.get_current_posture()["name"], monster.get_current_attitude()["name"])) | 1254 | send_message(client, arena_channel, "Hmmm... This monster seems {} and {}.".format(monster.get_current_posture()["name"], monster.get_current_attitude()["name"])) |
1227 | time.sleep(5) | 1255 | time.sleep(5) |
1228 | send_message(client, arena_channel, "And in the blue corner is...\n **{}**!".format(monster2.monster_type)) | 1256 | send_message(client, arena_channel, "And in the blue corner is...\n **{}**!".format(monster2.get_monster_name())) |
1229 | time.sleep(5) | 1257 | time.sleep(5) |
1230 | send_message(client, arena_channel, "Hmmm... This monster seems {} and {}.".format(monster2.get_current_posture()["name"], monster2.get_current_attitude()["name"])) | 1258 | send_message(client, arena_channel, "Hmmm... This monster seems {} and {}.".format(monster2.get_current_posture()["name"], monster2.get_current_attitude()["name"])) |
1231 | time.sleep(5) | 1259 | time.sleep(5) |
1232 | send_message(client, arena_channel, "Alright, Pankration fans, the match is about to begin!\n *Chaaaaaarge!*".format(monster2.monster_type)) | 1260 | send_message(client, arena_channel, "Alright, Pankration fans, the match is about to begin!\n *Chaaaaaarge!*".format(monster2.get_monster_name())) |
1233 | time.sleep(5) | 1261 | time.sleep(5) |
1234 | data.db_start_battle(battle['battle_id']) | 1262 | data.db_start_battle(battle['battle_id']) |
1235 | 1263 | ||
... | @@ -1244,12 +1272,12 @@ def check_arena(): | ... | @@ -1244,12 +1272,12 @@ def check_arena(): |
1244 | out_str = "" | 1272 | out_str = "" |
1245 | for action in actions: | 1273 | for action in actions: |
1246 | if isinstance(action, MissAction): | 1274 | if isinstance(action, MissAction): |
1247 | out_str += "{} {} {}.\n".format(action.attacker.monster_type, action.message, action.target.monster_type) | 1275 | out_str += "{} {} {}.\n".format(action.attacker.get_monster_name(), action.message, action.target.get_monster_name()) |
1248 | if isinstance(action, AttackAction): | 1276 | if isinstance(action, AttackAction): |
1249 | out_str += "{} {} {} for {}.\n".format(action.attacker.monster_type, action.message, action.target.monster_type, int(action.damage)) | 1277 | out_str += "{} {} {} for {}.\n".format(action.attacker.get_monster_name(), action.message, action.target.get_monster_name(), int(action.damage)) |
1250 | if isinstance(action, DefeatAction): | 1278 | if isinstance(action, DefeatAction): |
1251 | 1279 | ||
1252 | out_str += "\n\n**{}** {}. {} gains {} xp.\n\n".format(action.target.monster_type, action.message, action.attacker.monster_type, action.xp) | 1280 | out_str += "\n\n**{}** {}. {} gains {} xp.\n\n".format(action.target.get_monster_name(), action.message, action.attacker.get_monster_name(), action.xp) |
1253 | fighting = False | 1281 | fighting = False |
1254 | if action.attacker == monster: | 1282 | if action.attacker == monster: |
1255 | result, xp_msg = monster.add_xp(action.xp) | 1283 | result, xp_msg = monster.add_xp(action.xp) |
... | @@ -1266,7 +1294,7 @@ def check_arena(): | ... | @@ -1266,7 +1294,7 @@ def check_arena(): |
1266 | monster2.wins += 1 | 1294 | monster2.wins += 1 |
1267 | monster.losses += 1 | 1295 | monster.losses += 1 |
1268 | break | 1296 | break |
1269 | out_str += "\n{} {}% - {} {}%\n".format(monster.monster_type, monster.get_hp_percent(), monster2.monster_type, monster2.get_hp_percent()) | 1297 | out_str += "\n{} {}% - {} {}%\n".format(monster.get_monster_name(), monster.get_hp_percent(), monster2.get_monster_name(), monster2.get_hp_percent()) |
1270 | log(out_str) | 1298 | log(out_str) |
1271 | send_message(client, arena_channel, byteify(out_str)) | 1299 | send_message(client, arena_channel, byteify(out_str)) |
1272 | # Heal the monsters before they are returned to the player inventory | 1300 | # Heal the monsters before they are returned to the player inventory | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment