8ccecd68 by Barry

Added soul plates, reflectors and messaging for pankration.

1 parent 71937a50
......@@ -247,26 +247,101 @@ def db_get_pankration_record(member_id):
pan_record.close()
return dict_factory(c, result)
def db_add_monster(member_id, monster):
def db_add_soul_plate(member_id, soul_plate):
pan_record = db_get_pankration_record(member_id)
log("{}".format(member_id))
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
db_state = c.execute("SELECT monster_inventory FROM pankration WHERE member_id = ?;", (member_id,)).fetchone()
db_state = c.execute("SELECT soul_plates, member_id FROM pankration WHERE member_id = ?;", (member_id,)).fetchone()
if not db_state:
c.execute("""INSERT INTO pankration(member_id, wins, losses, monster_inventory)
VALUES(?, ?, ?, ?);""", (member_id, 0, 0, pickle.dumps([monster])))
log("no record")
c.execute("""INSERT INTO pankration(member_id, wins, losses, soul_plates)
VALUES(?, ?, ?, ?);""", (member_id, 0, 0, pickle.dumps([soul_plate])))
conn.commit()
else:
log(db_state)
inv = str(db_state[0])
log(inv)
monster_inventory = pickle.loads(inv)
monster_inventory.append(monster)
c.execute("""UPDATE pankration SET monster_inventory = ?
WHERE member_id = ?;""", (pickle.dumps(monster_inventory), member_id))
if db_state[0] and len(db_state[0]) > 0:
inv = str(db_state[0])
soul_plates = pickle.loads(inv)
else:
soul_plates = []
soul_plates.append(soul_plate)
c.execute("""UPDATE pankration SET soul_plates = ?
WHERE member_id = ?;""", (pickle.dumps(soul_plates), member_id))
conn.commit()
def db_remove_soul_plate(member_id, idx):
pan_record = db_get_pankration_record(member_id)
log("{}".format(member_id))
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
db_state = c.execute("SELECT soul_plates, member_id FROM pankration WHERE member_id = ?;", (member_id,)).fetchone()
if not db_state:
log("Invalid remove request for reflector: {}".format(idx,))
return False
else:
log(db_state)
if db_state[0] and len(db_state[0]) > 0:
inv = str(db_state[0])
soul_plates = pickle.loads(inv)
else:
log("Invalid remove request for reflector: {}".format(idx,))
return False
del soul_plates[idx]
c.execute("""UPDATE pankration SET soul_plates = ?
WHERE member_id = ?;""", (pickle.dumps(soul_plates), member_id))
conn.commit()
def db_add_reflector(member_id, reflector):
pan_record = db_get_pankration_record(member_id)
log("{}".format(member_id))
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
db_state = c.execute("SELECT reflectors, member_id FROM pankration WHERE member_id = ?;", (member_id,)).fetchone()
if not db_state:
log("no record")
c.execute("""INSERT INTO pankration(member_id, wins, losses, reflectors)
VALUES(?, ?, ?, ?);""", (member_id, 0, 0, pickle.dumps([reflector])))
conn.commit()
else:
log(db_state)
if db_state[0] and len(db_state[0]) > 0:
inv = str(db_state[0])
reflectors = pickle.loads(inv)
else:
reflectors = []
reflectors.append(reflector)
c.execute("""UPDATE pankration SET reflectors = ?
WHERE member_id = ?;""", (pickle.dumps(reflectors), member_id))
conn.commit()
def db_remove_reflector(member_id, idx):
pan_record = db_get_pankration_record(member_id)
log("{}".format(member_id))
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
db_state = c.execute("SELECT reflectors, member_id FROM pankration WHERE member_id = ?;", (member_id,)).fetchone()
if not db_state:
log("Invalid remove request for reflector: {}".format(idx,))
return False
else:
log(db_state)
if db_state[0] and len(db_state[0]) > 0:
inv = str(db_state[0])
reflectors = pickle.loads(inv)
else:
log("Invalid remove request for reflector: {}".format(idx,))
return False
del reflectors[idx]
c.execute("""UPDATE pankration SET reflectors = ?
WHERE member_id = ?;""", (pickle.dumps(reflectors), member_id))
conn.commit()
def db_convert_soul_plate_to_reflector(member_id, soul_plate, idx):
db_add_reflector(member_id, soul_plate)
db_remove_soul_plate(member_id, idx)
def db_get_member(discord_id=None, username=None):
# 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
member_conn = sqlite3.connect('db.sqlite3')
......
No preview for this file type
......@@ -85,7 +85,11 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help',
'!rigged': 'do_rigged',
'!listzones': 'do_list_zones',
'!huntmonster': 'do_hunt_monster',
'!listmonster': 'do_list_monsters',
'!listferalskills': 'do_list_feral_skills', '!listferalskill': 'do_list_feral_skills',
'!listreflectors': 'do_list_reflectors', '!listreflector': 'do_list_reflectors',
'!listsoulplates': 'do_list_soul_plates', '!listsoulplate': 'do_list_soul_plates',
'!convertplate': 'do_convert_plate', '!convertsoulplate': 'do_convert_plate',
'!pankration': 'do_pankration',
}
......@@ -1015,34 +1019,116 @@ def do_rigged(client, message_parts, message):
send_message(client, message.channel, ":musical_note: {} :musical_note:".format(random.choice(lines)))
return
def do_list_monsters(client, message_parts, message):
#### PANKRATION
def do_pankration(client, message_parts, message):
send_message(client, message.channel, """**NOTE! This is NOT implemented yet.. only partially**
{} Available Commands:
*Hunting for Soul Plates:*
**!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.
**!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.
*Viewing Your Inventory:*
**!listsoulplates** - Returns a list of all soul plates you have in your posession.
**!listreflectors** - Returns a list of all reflectors you have in your posession (The available monsters you can fight with).
**!listferalskills** - Returns a list of all feral skills you have in your inventory
*Editing Your Collections:*
**!convertplate <plate number> <convert_to>** - From the list of soul plates you can choose to either convert the plate into a \"reflector\" or \"skill\".
Ex: **!convertplate 1 reflector**
**!convertplate 4 skill**
**!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.
*Arena Battle:*
**!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.
**!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.
""".format(message.author.mention()))
def do_convert_plate(client, message_parts, message):
member = data.db_get_member(message.author.id)
pankration_data = data.db_get_pankration_record(member['member_id'])
if pankration_data and pankration_data['soul_plates']:
log(message_parts)
if len(message_parts) < 2:
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.')
return
plate_num = message_parts[0]
convert_to = message_parts[1]
soul_plates = pickle.loads(str(pankration_data['soul_plates']))
if not plate_num.isdigit() or int(plate_num) < 1 or int(plate_num) > len(soul_plates):
send_message(client, message.channel, 'The requested plate is invalid. Please provide the number from !listsoulplates')
return
plate_num = int(plate_num)
if convert_to == "reflector":
# do reflector stuff
data.db_convert_soul_plate_to_reflector(member['member_id'], soul_plates[plate_num], plate_num)
pass
elif convert_to == "skill":
# do skill stuff
pass
else:
send_message(client, message.channel, 'A plate can only be converted into a reflector or skill. Please see !pankration for an example.')
return
#send_message(client, message.channel, "\n\n".join("{}. {}".format(idx+1, str(soul_plate)) for idx, soul_plate in enumerate(soul_plates)))
else:
send_message(client, message.channel, 'You have no soul plates to convert.')
def do_list_soul_plates(client, message_parts, message):
member = data.db_get_member(message.author.id)
log(member)
monster_data = data.db_get_pankration_record(member['member_id'])
if monster_data:
monsters = pickle.loads(str(monster_data['monster_inventory']))
send_message(client, message.channel, "\n\n".join(str(monster) for monster in monsters))
pankration_data = data.db_get_pankration_record(member['member_id'])
if pankration_data and pankration_data['soul_plates']:
soul_plates = pickle.loads(str(pankration_data['soul_plates']))
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)))
else:
send_message(client, message.channel, 'You have no monsters.')
send_message(client, message.channel, 'You have no soul plates.')
def do_list_reflectors(client, message_parts, message):
member = data.db_get_member(message.author.id)
pankration_data = data.db_get_pankration_record(member['member_id'])
if pankration_data and pankration_data['reflectors']:
reflectors = pickle.loads(str(pankration_data['reflectors']))
send_message(client, message.channel, "\n\n".join("{}. {}".format(idx+1, str(reflector)) for idx, reflector in enumerate(reflectors)))
else:
send_message(client, message.channel, 'You have no reflectors.')
def do_list_feral_skills(client, message_parts, message):
member = data.db_get_member(message.author.id)
pankration_data = data.db_get_pankration_record(member['member_id'])
if pankration_data and pankration_data['feral_skills']:
feral_skills = pickle.loads(str(pankration_data['feral_skills']))
send_message(client, message.channel, "\n\n".join("{}. {}".format(idx+1, str(feral_skill)) for idx, feral_skill in enumerate(feral_skills)))
else:
send_message(client, message.channel, 'You have no feral skills.')
def do_hunt_monster(client, message_parts, message):
p = Pankration()
hunt_response = p.hunt_monster(' '.join(message_parts))
str_out = hunt_response.message + "\n\n"
if hunt_response.result == HuntResponse.SUCCESS:
monster = hunt_response.monster
soul_plate = hunt_response.monster
member = data.db_get_member(message.author.id)
data.db_add_monster(member['member_id'], monster)
str_out += str(monster)
data.db_add_soul_plate(member['member_id'], soul_plate)
str_out += str(soul_plate.get_soul_plate_description())
send_message(client, message.channel, str_out)
return
def do_list_zones(client, message_parts, message):
p = Pankration()
send_message(client, message.channel, ', '.join(p.list_zones()))
return
### END PANKRATION
def start_timer(client):
needs_loot = True
while not quitting:
......