Added soul plates, reflectors and messaging for pankration.
Showing
4 changed files
with
184 additions
and
23 deletions
... | @@ -247,26 +247,101 @@ def db_get_pankration_record(member_id): | ... | @@ -247,26 +247,101 @@ def db_get_pankration_record(member_id): |
247 | pan_record.close() | 247 | pan_record.close() |
248 | return dict_factory(c, result) | 248 | return dict_factory(c, result) |
249 | 249 | ||
250 | def db_add_monster(member_id, monster): | 250 | def db_add_soul_plate(member_id, soul_plate): |
251 | pan_record = db_get_pankration_record(member_id) | 251 | pan_record = db_get_pankration_record(member_id) |
252 | log("{}".format(member_id)) | 252 | log("{}".format(member_id)) |
253 | conn = sqlite3.connect('db.sqlite3') | 253 | conn = sqlite3.connect('db.sqlite3') |
254 | c = conn.cursor() | 254 | c = conn.cursor() |
255 | db_state = c.execute("SELECT monster_inventory FROM pankration WHERE member_id = ?;", (member_id,)).fetchone() | 255 | db_state = c.execute("SELECT soul_plates, member_id FROM pankration WHERE member_id = ?;", (member_id,)).fetchone() |
256 | if not db_state: | 256 | if not db_state: |
257 | c.execute("""INSERT INTO pankration(member_id, wins, losses, monster_inventory) | 257 | log("no record") |
258 | VALUES(?, ?, ?, ?);""", (member_id, 0, 0, pickle.dumps([monster]))) | 258 | c.execute("""INSERT INTO pankration(member_id, wins, losses, soul_plates) |
259 | VALUES(?, ?, ?, ?);""", (member_id, 0, 0, pickle.dumps([soul_plate]))) | ||
259 | conn.commit() | 260 | conn.commit() |
260 | else: | 261 | else: |
261 | log(db_state) | 262 | log(db_state) |
262 | inv = str(db_state[0]) | 263 | if db_state[0] and len(db_state[0]) > 0: |
263 | log(inv) | 264 | inv = str(db_state[0]) |
264 | monster_inventory = pickle.loads(inv) | 265 | soul_plates = pickle.loads(inv) |
265 | monster_inventory.append(monster) | 266 | else: |
266 | c.execute("""UPDATE pankration SET monster_inventory = ? | 267 | soul_plates = [] |
267 | WHERE member_id = ?;""", (pickle.dumps(monster_inventory), member_id)) | 268 | soul_plates.append(soul_plate) |
269 | c.execute("""UPDATE pankration SET soul_plates = ? | ||
270 | WHERE member_id = ?;""", (pickle.dumps(soul_plates), member_id)) | ||
271 | conn.commit() | ||
272 | |||
273 | def db_remove_soul_plate(member_id, idx): | ||
274 | pan_record = db_get_pankration_record(member_id) | ||
275 | log("{}".format(member_id)) | ||
276 | conn = sqlite3.connect('db.sqlite3') | ||
277 | c = conn.cursor() | ||
278 | db_state = c.execute("SELECT soul_plates, member_id FROM pankration WHERE member_id = ?;", (member_id,)).fetchone() | ||
279 | if not db_state: | ||
280 | log("Invalid remove request for reflector: {}".format(idx,)) | ||
281 | return False | ||
282 | else: | ||
283 | log(db_state) | ||
284 | if db_state[0] and len(db_state[0]) > 0: | ||
285 | inv = str(db_state[0]) | ||
286 | soul_plates = pickle.loads(inv) | ||
287 | else: | ||
288 | log("Invalid remove request for reflector: {}".format(idx,)) | ||
289 | return False | ||
290 | del soul_plates[idx] | ||
291 | c.execute("""UPDATE pankration SET soul_plates = ? | ||
292 | WHERE member_id = ?;""", (pickle.dumps(soul_plates), member_id)) | ||
293 | conn.commit() | ||
294 | |||
295 | def db_add_reflector(member_id, reflector): | ||
296 | pan_record = db_get_pankration_record(member_id) | ||
297 | log("{}".format(member_id)) | ||
298 | conn = sqlite3.connect('db.sqlite3') | ||
299 | c = conn.cursor() | ||
300 | db_state = c.execute("SELECT reflectors, member_id FROM pankration WHERE member_id = ?;", (member_id,)).fetchone() | ||
301 | if not db_state: | ||
302 | log("no record") | ||
303 | c.execute("""INSERT INTO pankration(member_id, wins, losses, reflectors) | ||
304 | VALUES(?, ?, ?, ?);""", (member_id, 0, 0, pickle.dumps([reflector]))) | ||
305 | conn.commit() | ||
306 | else: | ||
307 | log(db_state) | ||
308 | if db_state[0] and len(db_state[0]) > 0: | ||
309 | inv = str(db_state[0]) | ||
310 | reflectors = pickle.loads(inv) | ||
311 | else: | ||
312 | reflectors = [] | ||
313 | reflectors.append(reflector) | ||
314 | c.execute("""UPDATE pankration SET reflectors = ? | ||
315 | WHERE member_id = ?;""", (pickle.dumps(reflectors), member_id)) | ||
268 | conn.commit() | 316 | conn.commit() |
269 | 317 | ||
318 | def db_remove_reflector(member_id, idx): | ||
319 | pan_record = db_get_pankration_record(member_id) | ||
320 | log("{}".format(member_id)) | ||
321 | conn = sqlite3.connect('db.sqlite3') | ||
322 | c = conn.cursor() | ||
323 | db_state = c.execute("SELECT reflectors, member_id FROM pankration WHERE member_id = ?;", (member_id,)).fetchone() | ||
324 | if not db_state: | ||
325 | log("Invalid remove request for reflector: {}".format(idx,)) | ||
326 | return False | ||
327 | else: | ||
328 | log(db_state) | ||
329 | if db_state[0] and len(db_state[0]) > 0: | ||
330 | inv = str(db_state[0]) | ||
331 | reflectors = pickle.loads(inv) | ||
332 | else: | ||
333 | log("Invalid remove request for reflector: {}".format(idx,)) | ||
334 | return False | ||
335 | del reflectors[idx] | ||
336 | c.execute("""UPDATE pankration SET reflectors = ? | ||
337 | WHERE member_id = ?;""", (pickle.dumps(reflectors), member_id)) | ||
338 | conn.commit() | ||
339 | |||
340 | def db_convert_soul_plate_to_reflector(member_id, soul_plate, idx): | ||
341 | db_add_reflector(member_id, soul_plate) | ||
342 | db_remove_soul_plate(member_id, idx) | ||
343 | |||
344 | |||
270 | def db_get_member(discord_id=None, username=None): | 345 | def db_get_member(discord_id=None, username=None): |
271 | # Do a lookup by ID, if it's found but the name doesn't match then add a row to aliases with the previous name and change the member name | 346 | # Do a lookup by ID, if it's found but the name doesn't match then add a row to aliases with the previous name and change the member name |
272 | member_conn = sqlite3.connect('db.sqlite3') | 347 | member_conn = sqlite3.connect('db.sqlite3') | ... | ... |
No preview for this file type
... | @@ -85,7 +85,11 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help', | ... | @@ -85,7 +85,11 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help', |
85 | '!rigged': 'do_rigged', | 85 | '!rigged': 'do_rigged', |
86 | '!listzones': 'do_list_zones', | 86 | '!listzones': 'do_list_zones', |
87 | '!huntmonster': 'do_hunt_monster', | 87 | '!huntmonster': 'do_hunt_monster', |
88 | '!listmonster': 'do_list_monsters', | 88 | '!listferalskills': 'do_list_feral_skills', '!listferalskill': 'do_list_feral_skills', |
89 | '!listreflectors': 'do_list_reflectors', '!listreflector': 'do_list_reflectors', | ||
90 | '!listsoulplates': 'do_list_soul_plates', '!listsoulplate': 'do_list_soul_plates', | ||
91 | '!convertplate': 'do_convert_plate', '!convertsoulplate': 'do_convert_plate', | ||
92 | '!pankration': 'do_pankration', | ||
89 | } | 93 | } |
90 | 94 | ||
91 | 95 | ||
... | @@ -1015,34 +1019,116 @@ def do_rigged(client, message_parts, message): | ... | @@ -1015,34 +1019,116 @@ def do_rigged(client, message_parts, message): |
1015 | send_message(client, message.channel, ":musical_note: {} :musical_note:".format(random.choice(lines))) | 1019 | send_message(client, message.channel, ":musical_note: {} :musical_note:".format(random.choice(lines))) |
1016 | return | 1020 | return |
1017 | 1021 | ||
1018 | def do_list_monsters(client, message_parts, message): | 1022 | #### PANKRATION |
1023 | |||
1024 | |||
1025 | def do_pankration(client, message_parts, message): | ||
1026 | send_message(client, message.channel, """**NOTE! This is NOT implemented yet.. only partially** | ||
1027 | {} Available Commands: | ||
1028 | |||
1029 | *Hunting for Soul Plates:* | ||
1030 | **!listzones** - Returns a list of zones available for hunting and how many credits it costs to search in that zone. Depending on the weather and other factors some zones may not always be available. | ||
1031 | **!huntmonster <zone>** - An attempt will be made to search for a soul plate (monster) in the zone specified. Each search costs a certain amount of credits. Each zone has a different cost. | ||
1032 | |||
1033 | *Viewing Your Inventory:* | ||
1034 | **!listsoulplates** - Returns a list of all soul plates you have in your posession. | ||
1035 | **!listreflectors** - Returns a list of all reflectors you have in your posession (The available monsters you can fight with). | ||
1036 | **!listferalskills** - Returns a list of all feral skills you have in your inventory | ||
1037 | |||
1038 | *Editing Your Collections:* | ||
1039 | **!convertplate <plate number> <convert_to>** - From the list of soul plates you can choose to either convert the plate into a \"reflector\" or \"skill\". | ||
1040 | Ex: **!convertplate 1 reflector** | ||
1041 | **!convertplate 4 skill** | ||
1042 | **!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. | ||
1043 | |||
1044 | *Arena Battle:* | ||
1045 | **!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. | ||
1046 | **!registerbattle <reflector number> <player name>** - If you want to challenge a specific user to a battle just provide their user name. Have them do the same and your battle will start when the arena is available. | ||
1047 | |||
1048 | """.format(message.author.mention())) | ||
1049 | |||
1050 | def do_convert_plate(client, message_parts, message): | ||
1051 | member = data.db_get_member(message.author.id) | ||
1052 | |||
1053 | pankration_data = data.db_get_pankration_record(member['member_id']) | ||
1054 | if pankration_data and pankration_data['soul_plates']: | ||
1055 | log(message_parts) | ||
1056 | if len(message_parts) < 2: | ||
1057 | send_message(client, message.channel, 'You must provide at least 2 arguments for converting a plate. The plate number and the type of conversion. Please see !pankration for an example.') | ||
1058 | return | ||
1059 | |||
1060 | plate_num = message_parts[0] | ||
1061 | convert_to = message_parts[1] | ||
1062 | |||
1063 | soul_plates = pickle.loads(str(pankration_data['soul_plates'])) | ||
1064 | if not plate_num.isdigit() or int(plate_num) < 1 or int(plate_num) > len(soul_plates): | ||
1065 | send_message(client, message.channel, 'The requested plate is invalid. Please provide the number from !listsoulplates') | ||
1066 | return | ||
1067 | plate_num = int(plate_num) | ||
1068 | if convert_to == "reflector": | ||
1069 | # do reflector stuff | ||
1070 | data.db_convert_soul_plate_to_reflector(member['member_id'], soul_plates[plate_num], plate_num) | ||
1071 | pass | ||
1072 | elif convert_to == "skill": | ||
1073 | # do skill stuff | ||
1074 | pass | ||
1075 | else: | ||
1076 | send_message(client, message.channel, 'A plate can only be converted into a reflector or skill. Please see !pankration for an example.') | ||
1077 | return | ||
1078 | |||
1079 | #send_message(client, message.channel, "\n\n".join("{}. {}".format(idx+1, str(soul_plate)) for idx, soul_plate in enumerate(soul_plates))) | ||
1080 | else: | ||
1081 | send_message(client, message.channel, 'You have no soul plates to convert.') | ||
1082 | |||
1083 | def do_list_soul_plates(client, message_parts, message): | ||
1019 | member = data.db_get_member(message.author.id) | 1084 | member = data.db_get_member(message.author.id) |
1020 | log(member) | 1085 | |
1021 | monster_data = data.db_get_pankration_record(member['member_id']) | 1086 | pankration_data = data.db_get_pankration_record(member['member_id']) |
1022 | if monster_data: | 1087 | if pankration_data and pankration_data['soul_plates']: |
1023 | monsters = pickle.loads(str(monster_data['monster_inventory'])) | 1088 | soul_plates = pickle.loads(str(pankration_data['soul_plates'])) |
1024 | send_message(client, message.channel, "\n\n".join(str(monster) for monster in monsters)) | 1089 | send_message(client, message.channel, "\n\n".join("{}. {}".format(idx+1, str(soul_plate.get_soul_plate_description())) for idx, soul_plate in enumerate(soul_plates))) |
1025 | else: | 1090 | else: |
1026 | send_message(client, message.channel, 'You have no monsters.') | 1091 | send_message(client, message.channel, 'You have no soul plates.') |
1092 | |||
1093 | def do_list_reflectors(client, message_parts, message): | ||
1094 | member = data.db_get_member(message.author.id) | ||
1095 | |||
1096 | pankration_data = data.db_get_pankration_record(member['member_id']) | ||
1097 | if pankration_data and pankration_data['reflectors']: | ||
1098 | reflectors = pickle.loads(str(pankration_data['reflectors'])) | ||
1099 | send_message(client, message.channel, "\n\n".join("{}. {}".format(idx+1, str(reflector)) for idx, reflector in enumerate(reflectors))) | ||
1100 | else: | ||
1101 | send_message(client, message.channel, 'You have no reflectors.') | ||
1102 | |||
1103 | |||
1104 | def do_list_feral_skills(client, message_parts, message): | ||
1105 | member = data.db_get_member(message.author.id) | ||
1106 | |||
1107 | pankration_data = data.db_get_pankration_record(member['member_id']) | ||
1108 | if pankration_data and pankration_data['feral_skills']: | ||
1109 | feral_skills = pickle.loads(str(pankration_data['feral_skills'])) | ||
1110 | send_message(client, message.channel, "\n\n".join("{}. {}".format(idx+1, str(feral_skill)) for idx, feral_skill in enumerate(feral_skills))) | ||
1111 | else: | ||
1112 | send_message(client, message.channel, 'You have no feral skills.') | ||
1027 | 1113 | ||
1028 | def do_hunt_monster(client, message_parts, message): | 1114 | def do_hunt_monster(client, message_parts, message): |
1029 | p = Pankration() | 1115 | p = Pankration() |
1030 | hunt_response = p.hunt_monster(' '.join(message_parts)) | 1116 | hunt_response = p.hunt_monster(' '.join(message_parts)) |
1031 | str_out = hunt_response.message + "\n\n" | 1117 | str_out = hunt_response.message + "\n\n" |
1032 | if hunt_response.result == HuntResponse.SUCCESS: | 1118 | if hunt_response.result == HuntResponse.SUCCESS: |
1033 | monster = hunt_response.monster | 1119 | soul_plate = hunt_response.monster |
1034 | member = data.db_get_member(message.author.id) | 1120 | member = data.db_get_member(message.author.id) |
1035 | data.db_add_monster(member['member_id'], monster) | 1121 | data.db_add_soul_plate(member['member_id'], soul_plate) |
1036 | str_out += str(monster) | 1122 | str_out += str(soul_plate.get_soul_plate_description()) |
1037 | send_message(client, message.channel, str_out) | 1123 | send_message(client, message.channel, str_out) |
1038 | |||
1039 | return | ||
1040 | 1124 | ||
1041 | def do_list_zones(client, message_parts, message): | 1125 | def do_list_zones(client, message_parts, message): |
1042 | p = Pankration() | 1126 | p = Pankration() |
1043 | send_message(client, message.channel, ', '.join(p.list_zones())) | 1127 | send_message(client, message.channel, ', '.join(p.list_zones())) |
1044 | return | 1128 | return |
1045 | 1129 | ||
1130 | |||
1131 | ### END PANKRATION | ||
1046 | def start_timer(client): | 1132 | def start_timer(client): |
1047 | needs_loot = True | 1133 | needs_loot = True |
1048 | while not quitting: | 1134 | while not quitting: | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment