Changes for pankration
Showing
4 changed files
with
203 additions
and
44 deletions
... | @@ -157,6 +157,46 @@ def db_get_messages(): | ... | @@ -157,6 +157,46 @@ def db_get_messages(): |
157 | msg_conn.close() | 157 | msg_conn.close() |
158 | return db_messages | 158 | return db_messages |
159 | 159 | ||
160 | def db_add_joke(joke): | ||
161 | conn = sqlite3.connect('db.sqlite3') | ||
162 | c = conn.cursor() | ||
163 | c.execute("INSERT INTO jokes (joke) VALUES (?)", (joke,)) | ||
164 | conn.commit() | ||
165 | conn.close() | ||
166 | |||
167 | def db_get_fortune(): | ||
168 | try: | ||
169 | conn = sqlite3.connect('db.sqlite3') | ||
170 | c = conn.cursor() | ||
171 | # TODO: Move this shit to data | ||
172 | return c.execute("SELECT fortune FROM fortunes ORDER BY RANDOM() LIMIT 1;").fetchone()[0] | ||
173 | finally: | ||
174 | conn.close() | ||
175 | |||
176 | def db_get_joke(): | ||
177 | try: | ||
178 | conn = sqlite3.connect('db.sqlite3') | ||
179 | c = conn.cursor() | ||
180 | return c.execute("SELECT joke FROM jokes ORDER BY RANDOM() LIMIT 1;").fetchone()[0] | ||
181 | finally: | ||
182 | conn.close() | ||
183 | |||
184 | def db_add_fortune(fortune, date_added): | ||
185 | conn = sqlite3.connect('db.sqlite3') | ||
186 | c = conn.cursor() | ||
187 | c.execute("INSERT INTO fortunes (fortune, date_added) VALUES (?, ?)", (fortune, date_added)) | ||
188 | conn.commit() | ||
189 | conn.close() | ||
190 | |||
191 | def db_get_fortune(): | ||
192 | try: | ||
193 | conn = sqlite3.connect('db.sqlite3') | ||
194 | c = conn.cursor() | ||
195 | # TODO: Move this shit to data | ||
196 | return c.execute("SELECT fortune FROM fortunes ORDER BY RANDOM() LIMIT 1;").fetchone()[0] | ||
197 | finally: | ||
198 | conn.close() | ||
199 | |||
160 | def db_get_whoplayed(game_name): | 200 | def db_get_whoplayed(game_name): |
161 | conn = sqlite3.connect('db.sqlite3') | 201 | conn = sqlite3.connect('db.sqlite3') |
162 | c = conn.cursor() | 202 | c = conn.cursor() |
... | @@ -272,25 +312,32 @@ def db_add_soul_plate(member_id, soul_plate): | ... | @@ -272,25 +312,32 @@ def db_add_soul_plate(member_id, soul_plate): |
272 | 312 | ||
273 | def db_remove_soul_plate(member_id, idx): | 313 | def db_remove_soul_plate(member_id, idx): |
274 | pan_record = db_get_pankration_record(member_id) | 314 | pan_record = db_get_pankration_record(member_id) |
275 | log("{}".format(member_id)) | 315 | log("Removing Soul Plate: {}".format(member_id)) |
276 | conn = sqlite3.connect('db.sqlite3') | 316 | conn = sqlite3.connect('db.sqlite3') |
277 | c = conn.cursor() | 317 | c = conn.cursor() |
278 | db_state = c.execute("SELECT soul_plates, member_id FROM pankration WHERE member_id = ?;", (member_id,)).fetchone() | 318 | db_state = c.execute("SELECT soul_plates, member_id FROM pankration WHERE member_id = ?;", (member_id,)).fetchone() |
279 | if not db_state: | 319 | if not db_state: |
280 | log("Invalid remove request for reflector: {}".format(idx,)) | 320 | log("Invalid remove request for reflector: {}".format(idx,)) |
281 | return False | 321 | return False |
282 | else: | 322 | else: |
283 | log(db_state) | ||
284 | if db_state[0] and len(db_state[0]) > 0: | 323 | if db_state[0] and len(db_state[0]) > 0: |
285 | inv = str(db_state[0]) | 324 | try: |
286 | soul_plates = pickle.loads(inv) | 325 | log("\nFirst: {}\n\n".format(db_state[0])) |
326 | inv = str(db_state[0]) | ||
327 | soul_plates = pickle.loads(inv) | ||
328 | log("\n\nPlates: \n{}".format(soul_plates)) | ||
329 | except Exception as e: | ||
330 | log("Failed! {}".format(e)) | ||
331 | |||
287 | else: | 332 | else: |
288 | log("Invalid remove request for reflector: {}".format(idx,)) | 333 | log("Invalid remove request for reflector: {}".format(idx,)) |
289 | return False | 334 | return False |
335 | log("\n\nPlates: \n{}".format(soul_plates)) | ||
290 | del soul_plates[idx] | 336 | del soul_plates[idx] |
291 | c.execute("""UPDATE pankration SET soul_plates = ? | 337 | c.execute("""UPDATE pankration SET soul_plates = ? |
292 | WHERE member_id = ?;""", (pickle.dumps(soul_plates), member_id)) | 338 | WHERE member_id = ?;""", (pickle.dumps(soul_plates), member_id)) |
293 | conn.commit() | 339 | conn.commit() |
340 | return True | ||
294 | 341 | ||
295 | def db_add_reflector(member_id, reflector): | 342 | def db_add_reflector(member_id, reflector): |
296 | pan_record = db_get_pankration_record(member_id) | 343 | pan_record = db_get_pankration_record(member_id) |
... | @@ -304,7 +351,7 @@ def db_add_reflector(member_id, reflector): | ... | @@ -304,7 +351,7 @@ def db_add_reflector(member_id, reflector): |
304 | VALUES(?, ?, ?, ?);""", (member_id, 0, 0, pickle.dumps([reflector]))) | 351 | VALUES(?, ?, ?, ?);""", (member_id, 0, 0, pickle.dumps([reflector]))) |
305 | conn.commit() | 352 | conn.commit() |
306 | else: | 353 | else: |
307 | log(db_state) | 354 | #log(db_state) |
308 | if db_state[0] and len(db_state[0]) > 0: | 355 | if db_state[0] and len(db_state[0]) > 0: |
309 | inv = str(db_state[0]) | 356 | inv = str(db_state[0]) |
310 | reflectors = pickle.loads(inv) | 357 | reflectors = pickle.loads(inv) |
... | @@ -314,6 +361,7 @@ def db_add_reflector(member_id, reflector): | ... | @@ -314,6 +361,7 @@ def db_add_reflector(member_id, reflector): |
314 | c.execute("""UPDATE pankration SET reflectors = ? | 361 | c.execute("""UPDATE pankration SET reflectors = ? |
315 | WHERE member_id = ?;""", (pickle.dumps(reflectors), member_id)) | 362 | WHERE member_id = ?;""", (pickle.dumps(reflectors), member_id)) |
316 | conn.commit() | 363 | conn.commit() |
364 | return True | ||
317 | 365 | ||
318 | def db_remove_reflector(member_id, idx): | 366 | def db_remove_reflector(member_id, idx): |
319 | pan_record = db_get_pankration_record(member_id) | 367 | pan_record = db_get_pankration_record(member_id) |
... | @@ -372,9 +420,39 @@ def db_register_battle(member_id, reflector, idx, target_member=None): | ... | @@ -372,9 +420,39 @@ def db_register_battle(member_id, reflector, idx, target_member=None): |
372 | db_remove_reflector(member_id, idx) | 420 | db_remove_reflector(member_id, idx) |
373 | return | 421 | return |
374 | 422 | ||
423 | |||
375 | def db_complete_battle(battle_id, primary_member_id, primary_reflector, secondary_member_id, | 424 | def db_complete_battle(battle_id, primary_member_id, primary_reflector, secondary_member_id, |
376 | secondary_reflector): | 425 | secondary_reflector, winner): |
377 | pass | 426 | log('Completing battle') |
427 | conn = sqlite3.connect('db.sqlite3') | ||
428 | c = conn.cursor() | ||
429 | c.execute("""UPDATE pankration_arena SET battle_status = 'finished', battle_end = ? | ||
430 | WHERE battle_id = ?;""", (datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S'), battle_id)) | ||
431 | conn.commit() | ||
432 | log('Completing battle - finished') | ||
433 | # TODO: Settle any wagers | ||
434 | reflectors = pickle.loads(str(db_get_pankration_record(primary_member_id)['reflectors'])) | ||
435 | reflectors.append(primary_reflector) | ||
436 | log('Completing battle - Primary') | ||
437 | if winner == 1: | ||
438 | c.execute("""UPDATE pankration SET reflectors = ?, wins = wins + 1 | ||
439 | WHERE member_id = ?;""", (pickle.dumps(reflectors), primary_member_id)) | ||
440 | else: | ||
441 | c.execute("""UPDATE pankration SET reflectors = ?, losses = losses + 1 | ||
442 | WHERE member_id = ?;""", (pickle.dumps(reflectors), primary_member_id)) | ||
443 | |||
444 | reflectors = pickle.loads(str(db_get_pankration_record(secondary_member_id)['reflectors'])) | ||
445 | reflectors.append(secondary_reflector) | ||
446 | log('Completing battle - secondary') | ||
447 | if winner == 2: | ||
448 | c.execute("""UPDATE pankration SET reflectors = ?, wins = wins + 1 | ||
449 | WHERE member_id = ?;""", (pickle.dumps(reflectors), secondary_member_id)) | ||
450 | else: | ||
451 | c.execute("""UPDATE pankration SET reflectors = ?, losses = losses + 1 | ||
452 | WHERE member_id = ?;""", (pickle.dumps(reflectors), secondary_member_id)) | ||
453 | conn.commit() | ||
454 | conn.close() | ||
455 | log('Completing battle - done') | ||
378 | 456 | ||
379 | 457 | ||
380 | def db_start_battle(battle_id): | 458 | def db_start_battle(battle_id): |
... | @@ -393,7 +471,7 @@ def db_get_battle_queue(): | ... | @@ -393,7 +471,7 @@ def db_get_battle_queue(): |
393 | results = [] | 471 | results = [] |
394 | for row in result: | 472 | for row in result: |
395 | results.append(dict_factory(c, row)) | 473 | results.append(dict_factory(c, row)) |
396 | 474 | ||
397 | return results | 475 | return results |
398 | 476 | ||
399 | 477 | ... | ... |
No preview for this file type
... | @@ -580,10 +580,8 @@ def do_buyticket(client, message_parts, message): | ... | @@ -580,10 +580,8 @@ def do_buyticket(client, message_parts, message): |
580 | member = data.db_get_member(message.author.id) | 580 | member = data.db_get_member(message.author.id) |
581 | log("Member: {}".format(member,)) | 581 | log("Member: {}".format(member,)) |
582 | if not member: | 582 | if not member: |
583 | log("there") | ||
584 | send_message(client, message.author, "There was a problem looking up your information.") | 583 | send_message(client, message.author, "There was a problem looking up your information.") |
585 | else: | 584 | else: |
586 | log("here") | ||
587 | log("Buying Ticket for: {}".format(byteify(member['member_name']))) | 585 | log("Buying Ticket for: {}".format(byteify(member['member_name']))) |
588 | result, response = data.db_buy_ticket(member['member_id'], 1) | 586 | result, response = data.db_buy_ticket(member['member_id'], 1) |
589 | log("Buy Result: {} - {}".format(result, response)) | 587 | log("Buy Result: {} - {}".format(result, response)) |
... | @@ -601,7 +599,11 @@ def do_balance(client, message_parts, message): | ... | @@ -601,7 +599,11 @@ def do_balance(client, message_parts, message): |
601 | if not member: | 599 | if not member: |
602 | send_message(client, message.author, "There was a problem looking up your information.") | 600 | send_message(client, message.author, "There was a problem looking up your information.") |
603 | else: | 601 | else: |
604 | send_message(client, message.author, "Credits: {}\nTickets: {}".format(member['credits'], member['tickets'])) | 602 | pankration_data = data.db_get_pankration_record(member['member_id']) |
603 | if pankration_data and 'wins' in pankration_data: | ||
604 | send_message(client, message.author, "Credits: {}\nTickets: {}\nPankration Wins: {}\nPankration Losses: {}".format(member['credits'], member['tickets'], pankration_data['wins'], pankration_data['losses'])) | ||
605 | else: | ||
606 | send_message(client, message.author, "Credits: {}\nTickets: {}".format(member['credits'], member['tickets'])) | ||
605 | return | 607 | return |
606 | 608 | ||
607 | 609 | ||
... | @@ -897,14 +899,12 @@ def do_msg(client, message_parts, message): | ... | @@ -897,14 +899,12 @@ def do_msg(client, message_parts, message): |
897 | 899 | ||
898 | def do_addfortune(client, message_parts, message): | 900 | def do_addfortune(client, message_parts, message): |
899 | try: | 901 | try: |
900 | fortune = message.content[9:] | 902 | fortune = message.content[11:] |
901 | if 'aa737a5846' in fortune: | 903 | if 'aa737a5846' in fortune: |
902 | send_message(client, message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention())) | 904 | send_message(client, message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention())) |
903 | return | 905 | return |
904 | date_added = datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S') | 906 | date_added = datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S') |
905 | c = conn.cursor() | 907 | data.db_add_fortune(fortune, date_added) |
906 | c.execute("INSERT INTO fortunes (fortune, date_added) VALUES (?, ?)", (fortune, date_added)) | ||
907 | conn.commit() | ||
908 | log("Added fortune") | 908 | log("Added fortune") |
909 | except Exception as e: | 909 | except Exception as e: |
910 | log(e.message) | 910 | log(e.message) |
... | @@ -917,9 +917,7 @@ def do_addfortune(client, message_parts, message): | ... | @@ -917,9 +917,7 @@ def do_addfortune(client, message_parts, message): |
917 | def do_fortune(client, message_parts, message): | 917 | def do_fortune(client, message_parts, message): |
918 | fortune = None | 918 | fortune = None |
919 | try: | 919 | try: |
920 | c = conn.cursor() | 920 | fortune = data.db_get_fortune() |
921 | # TODO: Move this shit to data | ||
922 | fortune = c.execute("SELECT fortune FROM fortunes ORDER BY RANDOM() LIMIT 1;").fetchone()[0] | ||
923 | log(fortune) | 921 | log(fortune) |
924 | except Exception as e: | 922 | except Exception as e: |
925 | log(e) | 923 | log(e) |
... | @@ -963,13 +961,11 @@ def do_question(client, message_parts, message): | ... | @@ -963,13 +961,11 @@ def do_question(client, message_parts, message): |
963 | 961 | ||
964 | def do_addjoke(client, message_parts, message): | 962 | def do_addjoke(client, message_parts, message): |
965 | try: | 963 | try: |
966 | joke = message.content[9:] | 964 | joke = message.content[8:] |
967 | if 'aa737a5846' in joke: | 965 | if 'aa737a5846' in joke: |
968 | send_message(client, message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention())) | 966 | send_message(client, message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention())) |
969 | return | 967 | return |
970 | c = conn.cursor() | 968 | data.db_add_joke(joke) |
971 | c.execute("INSERT INTO jokes (joke) VALUES (?)", (joke,)) | ||
972 | conn.commit() | ||
973 | log("Added joke") | 969 | log("Added joke") |
974 | except Exception as e: | 970 | except Exception as e: |
975 | log(e.message) | 971 | log(e.message) |
... | @@ -982,8 +978,7 @@ def do_addjoke(client, message_parts, message): | ... | @@ -982,8 +978,7 @@ def do_addjoke(client, message_parts, message): |
982 | def do_joke(client, message_parts, message): | 978 | def do_joke(client, message_parts, message): |
983 | joke = None | 979 | joke = None |
984 | try: | 980 | try: |
985 | c = conn.cursor() | 981 | joke = data.db_get_joke() |
986 | joke = c.execute("SELECT joke FROM jokes ORDER BY RANDOM() LIMIT 1;").fetchone()[0] | ||
987 | log(joke) | 982 | log(joke) |
988 | except Exception as e: | 983 | except Exception as e: |
989 | log(e) | 984 | log(e) |
... | @@ -1129,9 +1124,12 @@ def do_list_soul_plates(client, message_parts, message): | ... | @@ -1129,9 +1124,12 @@ def do_list_soul_plates(client, message_parts, message): |
1129 | member = data.db_get_member(message.author.id) | 1124 | member = data.db_get_member(message.author.id) |
1130 | 1125 | ||
1131 | pankration_data = data.db_get_pankration_record(member['member_id']) | 1126 | pankration_data = data.db_get_pankration_record(member['member_id']) |
1132 | if pankration_data and pankration_data['soul_plates']: | 1127 | if pankration_data and 'soul_plates' in pankration_data: |
1133 | soul_plates = pickle.loads(str(pankration_data['soul_plates'])) | 1128 | soul_plates = pickle.loads(str(pankration_data['soul_plates'])) |
1134 | 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))) | 1129 | if len(soul_plates) > 0: |
1130 | 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))) | ||
1131 | else: | ||
1132 | send_message(client, message.channel, 'You have no soul plates.') | ||
1135 | else: | 1133 | else: |
1136 | send_message(client, message.channel, 'You have no soul plates.') | 1134 | send_message(client, message.channel, 'You have no soul plates.') |
1137 | 1135 | ||
... | @@ -1142,7 +1140,10 @@ def do_list_reflectors(client, message_parts, message): | ... | @@ -1142,7 +1140,10 @@ def do_list_reflectors(client, message_parts, message): |
1142 | pankration_data = data.db_get_pankration_record(member['member_id']) | 1140 | pankration_data = data.db_get_pankration_record(member['member_id']) |
1143 | if pankration_data and pankration_data['reflectors']: | 1141 | if pankration_data and pankration_data['reflectors']: |
1144 | reflectors = pickle.loads(str(pankration_data['reflectors'])) | 1142 | reflectors = pickle.loads(str(pankration_data['reflectors'])) |
1145 | send_message(client, message.channel, "\n\n".join("{}. {}".format(idx+1, str(reflector)) for idx, reflector in enumerate(reflectors))) | 1143 | if len(reflectors) > 0: |
1144 | send_message(client, message.channel, "\n\n".join("{}. {}".format(idx+1, str(reflector)) for idx, reflector in enumerate(reflectors))) | ||
1145 | else: | ||
1146 | send_message(client, message.channel, 'You have no reflectors.') | ||
1146 | else: | 1147 | else: |
1147 | send_message(client, message.channel, 'You have no reflectors.') | 1148 | send_message(client, message.channel, 'You have no reflectors.') |
1148 | 1149 | ||
... | @@ -1160,6 +1161,22 @@ def do_list_feral_skills(client, message_parts, message): | ... | @@ -1160,6 +1161,22 @@ def do_list_feral_skills(client, message_parts, message): |
1160 | 1161 | ||
1161 | def do_hunt_monster(client, message_parts, message): | 1162 | def do_hunt_monster(client, message_parts, message): |
1162 | p = Pankration() | 1163 | p = Pankration() |
1164 | zone = ' '.join(message_parts) | ||
1165 | cost = p.get_zone_cost(zone) | ||
1166 | if cost == False: | ||
1167 | send_message(client, message.channel, 'The zone was not found.') | ||
1168 | return | ||
1169 | else: | ||
1170 | member = data.db_get_member(message.author.id) | ||
1171 | if not member: | ||
1172 | send_message(client, message.author, "There was a problem looking up your information.") | ||
1173 | return | ||
1174 | result, error_message = data.db_update_credit(member['member_id'], -cost) | ||
1175 | if not result: | ||
1176 | send_message(client, message.author, error_message) | ||
1177 | return | ||
1178 | send_message(client, message.channel, 'Soul Plate purchased for {} credits\n Hunting in {}'.format(cost, zone)) | ||
1179 | time.sleep(3) | ||
1163 | hunt_response = p.hunt_monster(' '.join(message_parts)) | 1180 | hunt_response = p.hunt_monster(' '.join(message_parts)) |
1164 | str_out = hunt_response.message + "\n\n" | 1181 | str_out = hunt_response.message + "\n\n" |
1165 | if hunt_response.result == HuntResponse.SUCCESS: | 1182 | if hunt_response.result == HuntResponse.SUCCESS: |
... | @@ -1172,7 +1189,13 @@ def do_hunt_monster(client, message_parts, message): | ... | @@ -1172,7 +1189,13 @@ def do_hunt_monster(client, message_parts, message): |
1172 | 1189 | ||
1173 | def do_list_zones(client, message_parts, message): | 1190 | def do_list_zones(client, message_parts, message): |
1174 | p = Pankration() | 1191 | p = Pankration() |
1175 | send_message(client, message.channel, ', '.join(p.list_zones())) | 1192 | zones = p.list_zones() |
1193 | # out_str = "" | ||
1194 | # for zone_name, zone in zones.iteritems(): | ||
1195 | # out_str += "{} - {}\n".format(zones[idx]['cost'], idx) | ||
1196 | # send_message(client, message.channel, out_str) | ||
1197 | out_str = 'Credit Cost - Zone Name\n--------------------------------\n' + '\n'.join(["{} - {}".format(zone['cost'], zone_name.title()) for zone_name, zone in zones.iteritems()]) | ||
1198 | send_message(client, message.channel, out_str) | ||
1176 | return | 1199 | return |
1177 | 1200 | ||
1178 | 1201 | ||
... | @@ -1214,6 +1237,7 @@ def check_arena(): | ... | @@ -1214,6 +1237,7 @@ def check_arena(): |
1214 | 1237 | ||
1215 | battle_arena = p.start_battle(monster, monster2, "not used") | 1238 | battle_arena = p.start_battle(monster, monster2, "not used") |
1216 | fighting = True | 1239 | fighting = True |
1240 | winner = 1 | ||
1217 | while fighting: | 1241 | while fighting: |
1218 | actions = battle_arena.step() | 1242 | actions = battle_arena.step() |
1219 | time.sleep(4) | 1243 | time.sleep(4) |
... | @@ -1224,15 +1248,34 @@ def check_arena(): | ... | @@ -1224,15 +1248,34 @@ def check_arena(): |
1224 | if isinstance(action, AttackAction): | 1248 | if isinstance(action, AttackAction): |
1225 | out_str += "{} {} {} for {}.\n".format(action.attacker.monster_type, action.message, action.target.monster_type, int(action.damage)) | 1249 | out_str += "{} {} {} for {}.\n".format(action.attacker.monster_type, action.message, action.target.monster_type, int(action.damage)) |
1226 | if isinstance(action, DefeatAction): | 1250 | if isinstance(action, DefeatAction): |
1251 | |||
1227 | out_str += "\n\n**{}** {}. {} gains {} xp.\n\n".format(action.target.monster_type, action.message, action.attacker.monster_type, action.xp) | 1252 | out_str += "\n\n**{}** {}. {} gains {} xp.\n\n".format(action.target.monster_type, action.message, action.attacker.monster_type, action.xp) |
1228 | fighting = False | 1253 | fighting = False |
1254 | if action.attacker == monster: | ||
1255 | result, xp_msg = monster.add_xp(action.xp) | ||
1256 | if result: | ||
1257 | out_str += xp_msg | ||
1258 | winner = 1 | ||
1259 | monster.wins += 1 | ||
1260 | monster2.losses += 1 | ||
1261 | else: | ||
1262 | result, xp_msg = monster2.add_xp(action.xp) | ||
1263 | if result: | ||
1264 | out_str += xp_msg | ||
1265 | winner = 2 | ||
1266 | monster2.wins += 1 | ||
1267 | monster.losses += 1 | ||
1229 | break | 1268 | break |
1230 | out_str += "\n{} {}% - {} {}%\n".format(monster.monster_type, monster.get_hp_percent(), monster2.monster_type, monster2.get_hp_percent()) | 1269 | out_str += "\n{} {}% - {} {}%\n".format(monster.monster_type, monster.get_hp_percent(), monster2.monster_type, monster2.get_hp_percent()) |
1231 | log(out_str) | 1270 | log(out_str) |
1232 | send_message(client, arena_channel, byteify(out_str)) | 1271 | send_message(client, arena_channel, byteify(out_str)) |
1272 | # Heal the monsters before they are returned to the player inventory | ||
1273 | monster.hp = monster.get_hp() | ||
1274 | monster2.hp = monster2.get_hp() | ||
1275 | data.db_complete_battle(battle['battle_id'], battle['primary_member_id'], monster, battle['secondary_member_id'], monster2, winner) | ||
1276 | |||
1233 | #wait after each match before starting a new fight. | 1277 | #wait after each match before starting a new fight. |
1234 | time.sleep(30) | 1278 | time.sleep(30) |
1235 | |||
1236 | except Exception as e: | 1279 | except Exception as e: |
1237 | log("{} - {}".format(format_exception(e), e.message)) | 1280 | log("{} - {}".format(format_exception(e), e.message)) |
1238 | finally: | 1281 | finally: | ... | ... |
... | @@ -2,6 +2,14 @@ import random | ... | @@ -2,6 +2,14 @@ import random |
2 | import time | 2 | import time |
3 | import pickle | 3 | import pickle |
4 | import math | 4 | import math |
5 | import collections | ||
6 | import logging | ||
7 | |||
8 | def log(message): | ||
9 | try: | ||
10 | logging.warning("{} - {}".format(datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S'), message)) | ||
11 | except: | ||
12 | pass | ||
5 | 13 | ||
6 | FIND_PERCENTAGE = 100 | 14 | FIND_PERCENTAGE = 100 |
7 | SKILL_PERCENT = 80 | 15 | SKILL_PERCENT = 80 |
... | @@ -218,21 +226,41 @@ Families = { | ... | @@ -218,21 +226,41 @@ Families = { |
218 | 226 | ||
219 | Monsters = { | 227 | Monsters = { |
220 | 'Mechanical Menace': { | 228 | 'Mechanical Menace': { |
221 | 'initial_level': 9, | ||
222 | 'family': 'acrolith', | 229 | 'family': 'acrolith', |
223 | 'zone': 'Abyssea - Uleguerand', | 230 | 'zone': ['abyssea - uleguerand'], |
224 | 'hp': 20, | 231 | 'hp': 20, |
225 | 'weapon_base_damage': 14 | 232 | 'weapon_base_damage': 14 |
226 | }, | 233 | }, |
227 | 'Floating Eye': { | 234 | 'Floating Eye': { |
228 | 'initial_level': 10, | ||
229 | 'family': 'ahriman', | 235 | 'family': 'ahriman', |
230 | 'zone': 'Ranguemont Pass', | 236 | 'zone': ['ranguemont pass'], |
237 | 'hp': 15, | ||
238 | 'weapon_base_damage': 15 | ||
239 | }, | ||
240 | 'Bat Eye': { | ||
241 | 'family': 'ahriman', | ||
242 | 'zone': ['ranguemont pass', 'beaucedine glacier'], | ||
243 | 'hp': 15, | ||
244 | 'weapon_base_damage': 15 | ||
245 | }, | ||
246 | 'Evil Eye': { | ||
247 | 'family': 'ahriman', | ||
248 | 'zone': ['castle zvahl baileys', 'castle zvahl keep', 'xarcabard'], | ||
231 | 'hp': 15, | 249 | 'hp': 15, |
232 | 'weapon_base_damage': 15 | 250 | 'weapon_base_damage': 15 |
233 | } | 251 | } |
234 | } | 252 | } |
235 | 253 | ||
254 | UnsortedZones = { | ||
255 | 'abyssea - uleguerand': {'cost': 10, 'find_percent': 50}, | ||
256 | 'beaucedine glacier': {'cost': 10, 'find_percent': 50}, | ||
257 | 'castle zvahl baileys': {'cost': 10, 'find_percent': 50}, | ||
258 | 'castle zvahl keep': {'cost': 10, 'find_percent': 50}, | ||
259 | 'ranguemont pass': {'cost': 10, 'find_percent': 50}, | ||
260 | 'xarcabard': {'cost': 10, 'find_percent': 50}, | ||
261 | } | ||
262 | |||
263 | Zones = collections.OrderedDict(sorted(UnsortedZones.items())) | ||
236 | 264 | ||
237 | class Pankration: | 265 | class Pankration: |
238 | def __init__(self): | 266 | def __init__(self): |
... | @@ -244,21 +272,27 @@ class Pankration: | ... | @@ -244,21 +272,27 @@ class Pankration: |
244 | return battle | 272 | return battle |
245 | 273 | ||
246 | def list_zones(self): | 274 | def list_zones(self): |
247 | zone_list = [] | 275 | return Zones |
248 | for monster in Monsters.itervalues(): | ||
249 | if monster['zone'] not in zone_list: | ||
250 | zone_list.append(monster['zone']) | ||
251 | return zone_list | ||
252 | 276 | ||
253 | def get_monsters(self, zone): | 277 | def get_monsters(self, zone): |
254 | monster_list = [] | 278 | monster_list = [] |
255 | for monster_name, monster in Monsters.iteritems(): | 279 | for monster_name, monster in Monsters.iteritems(): |
256 | if monster['zone'] == zone: | 280 | if zone.lower() in monster['zone']: |
257 | monster_list.append(monster_name) | 281 | monster_list.append(monster_name) |
258 | return monster_list | 282 | return monster_list |
259 | 283 | ||
284 | def get_zone_cost(self, zone): | ||
285 | zone = zone.lower() | ||
286 | if zone in Zones: | ||
287 | return Zones[zone]['cost'] | ||
288 | else: | ||
289 | return False | ||
290 | |||
260 | def hunt_monster(self, zone): | 291 | def hunt_monster(self, zone): |
261 | if random.randint(1, 100) < FIND_PERCENTAGE: | 292 | zone = zone.lower() |
293 | if not zone in Zones: | ||
294 | return HuntResponse(HuntResponse.FAILURE, "The zone was not found. {} - {}".format(zone, Zones), None) | ||
295 | if random.randint(1, 100) < Zones[zone]['find_percent']: | ||
262 | monster_name = random.choice(self.get_monsters(zone)) | 296 | monster_name = random.choice(self.get_monsters(zone)) |
263 | monster_data = Monsters[monster_name] | 297 | monster_data = Monsters[monster_name] |
264 | hp = monster_data['hp'] | 298 | hp = monster_data['hp'] |
... | @@ -266,7 +300,7 @@ class Pankration: | ... | @@ -266,7 +300,7 @@ class Pankration: |
266 | print("Monster: {} Data: {}".format(monster_name, monster_data)) | 300 | print("Monster: {} Data: {}".format(monster_name, monster_data)) |
267 | family_name = monster_data['family'] | 301 | family_name = monster_data['family'] |
268 | family = Families[family_name] | 302 | family = Families[family_name] |
269 | level = monster_data['initial_level'] | 303 | level = 1 |
270 | main_job = random.choice(family['available_main_job']) | 304 | main_job = random.choice(family['available_main_job']) |
271 | support_job = random.choice(family['available_support_job']) | 305 | support_job = random.choice(family['available_support_job']) |
272 | while support_job == main_job: | 306 | while support_job == main_job: |
... | @@ -356,13 +390,14 @@ class Monster: | ... | @@ -356,13 +390,14 @@ class Monster: |
356 | def add_xp(self, exp_to_add): | 390 | def add_xp(self, exp_to_add): |
357 | self.exp += exp_to_add | 391 | self.exp += exp_to_add |
358 | for i in range(self.level, 51): | 392 | for i in range(self.level, 51): |
359 | if self.exp > exp_to_level[i]: | 393 | if self.exp > 200 * i: |
360 | if i > self.level: | 394 | if i > self.level: |
361 | # We leveled up! | 395 | # We leveled up! |
362 | self.level = i | 396 | self.level = i |
363 | #print("Start level: {} New Level: {}".format(self.level, i)) | 397 | return (True, "Start level: {} New Level: {}".format(self.level, i)) |
364 | else: | 398 | else: |
365 | break | 399 | break |
400 | return (False,) | ||
366 | 401 | ||
367 | def get_current_posture(self): | 402 | def get_current_posture(self): |
368 | return TemperamentPosture[self.temperament_posture] | 403 | return TemperamentPosture[self.temperament_posture] |
... | @@ -652,8 +687,11 @@ if __name__ == "__main__": | ... | @@ -652,8 +687,11 @@ if __name__ == "__main__": |
652 | print("{} {} {} for {}.".format(action.attacker.monster_type, action.message, action.target.monster_type, action.damage)) | 687 | print("{} {} {} for {}.".format(action.attacker.monster_type, action.message, action.target.monster_type, action.damage)) |
653 | if isinstance(action, DefeatAction): | 688 | if isinstance(action, DefeatAction): |
654 | print("{} {}. {} gains {} xp.".format(action.target.monster_type, action.message, action.attacker.monster_type, action.xp)) | 689 | print("{} {}. {} gains {} xp.".format(action.target.monster_type, action.message, action.attacker.monster_type, action.xp)) |
690 | action.attacker.hp = 500 | ||
691 | print("{} {}".format(action.target.hp, action.attacker.hp)) | ||
655 | fighting = False | 692 | fighting = False |
656 | break | 693 | break |
694 | print("\n\nhp: {} {}\n\n".format(monster.hp, monster2.hp)) | ||
657 | print("\n{} {}% - {} {}%\n".format(monster.monster_type, monster.get_hp_percent(), monster2.monster_type, monster2.get_hp_percent())) | 695 | print("\n{} {}% - {} {}%\n".format(monster.monster_type, monster.get_hp_percent(), monster2.monster_type, monster2.get_hp_percent())) |
658 | 696 | ||
659 | 697 | ... | ... |
-
Please register or sign in to post a comment