3c3cad9f by Barry

Basic pankration added with arena.

1 parent 8ccecd68
...@@ -337,9 +337,74 @@ def db_remove_reflector(member_id, idx): ...@@ -337,9 +337,74 @@ def db_remove_reflector(member_id, idx):
337 WHERE member_id = ?;""", (pickle.dumps(reflectors), member_id)) 337 WHERE member_id = ?;""", (pickle.dumps(reflectors), member_id))
338 conn.commit() 338 conn.commit()
339 339
340
340 def db_convert_soul_plate_to_reflector(member_id, soul_plate, idx): 341 def db_convert_soul_plate_to_reflector(member_id, soul_plate, idx):
341 db_add_reflector(member_id, soul_plate) 342 if not db_add_reflector(member_id, soul_plate):
342 db_remove_soul_plate(member_id, idx) 343 return False
344 if not db_remove_soul_plate(member_id, idx):
345 return False
346 return True
347
348
349 def db_register_battle(member_id, reflector, idx, target_member=None):
350 pan_record = db_get_pankration_record(member_id)
351 conn = sqlite3.connect('db.sqlite3')
352 c = conn.cursor()
353 db_state = c.execute("SELECT battle_id, reflector_primary member_id FROM pankration_arena WHERE battle_status = 'waiting';").fetchall()
354 if not db_state:
355 log("No battles available: {}".format(idx,))
356 c.execute("""INSERT INTO pankration_arena(primary_member_id, reflector_primary)
357 VALUES(?, ?);""", (member_id, pickle.dumps(reflector)))
358 conn.commit()
359 conn.close()
360 db_remove_reflector(member_id, idx)
361 else:
362 for row in db_state:
363 primary_reflector = pickle.loads(str(row[1]))
364 primary_level = primary_reflector.level
365 # TODO: Setup challenges based on level difference of no more than 10 or spawn a new monster.
366 # if primary_level - 10 <= reflector.level <= primary_level + 10:
367 battle_id = row[0]
368 c.execute("""UPDATE pankration_arena SET secondary_member_id = ?, reflector_secondary = ?, battle_status = 'queued', queue_start = ?
369 WHERE battle_id = ?;""", (member_id, pickle.dumps(reflector), datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S'), battle_id))
370 conn.commit()
371 conn.close()
372 db_remove_reflector(member_id, idx)
373 return
374
375 def db_complete_battle(battle_id, primary_member_id, primary_reflector, secondary_member_id,
376 secondary_reflector):
377 pass
378
379
380 def db_start_battle(battle_id):
381 conn = sqlite3.connect('db.sqlite3')
382 c = conn.cursor()
383 c.execute("""UPDATE pankration_arena SET battle_status = 'fighting', battle_start = ?
384 WHERE battle_id = ?;""", (datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S'), battle_id))
385 conn.commit()
386 conn.close()
387
388 def db_get_battle_queue():
389 conn = sqlite3.connect('db.sqlite3')
390 c = conn.cursor()
391 result = c.execute("SELECT * FROM pankration_arena WHERE battle_status = 'queued' ORDER BY queue_start;").fetchall()
392 conn.close()
393 results = []
394 for row in result:
395 results.append(dict_factory(c, row))
396
397 return results
398
399
400 def db_get_member_username(member_id):
401 # 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
402 member_conn = sqlite3.connect('db.sqlite3')
403
404 c = member_conn.cursor()
405 result = c.execute("SELECT member_name FROM members WHERE member_id = ?;", (member_id,)).fetchone()
406 member_conn.close()
407 return result[0]
343 408
344 409
345 def db_get_member(discord_id=None, username=None): 410 def db_get_member(discord_id=None, username=None):
......
No preview for this file type
...@@ -365,10 +365,10 @@ class Monster: ...@@ -365,10 +365,10 @@ class Monster:
365 break 365 break
366 366
367 def get_current_posture(self): 367 def get_current_posture(self):
368 return TemperamentPosture(self.temperament_posture) 368 return TemperamentPosture[self.temperament_posture]
369 369
370 def get_current_attitude(self): 370 def get_current_attitude(self):
371 return TemperamentAttitude(self.temperament_attitude) 371 return TemperamentAttitude[self.temperament_attitude]
372 372
373 def get_dicipline_level(self): 373 def get_dicipline_level(self):
374 if self.dicipline_level < 2: 374 if self.dicipline_level < 2:
......