226fb773 by Barry

Added the start of weapon skills calc and lots of little fixes.

1 parent 5f1e010c
......@@ -339,6 +339,14 @@ def db_remove_soul_plate(member_id, idx):
conn.commit()
return True
def db_update_pankration_record(member_id, column_name, value):
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
c.execute("""UPDATE pankration SET """ + column_name + """ = ?
WHERE member_id = ?;""", (value, member_id))
conn.commit()
conn.close()
def db_add_reflector(member_id, reflector):
pan_record = db_get_pankration_record(member_id)
log("{}".format(member_id))
......@@ -394,15 +402,22 @@ def db_convert_soul_plate_to_reflector(member_id, soul_plate, idx):
return True
def db_register_battle(member_id, reflector, idx, target_member=None):
def db_register_battle(member_id, reflector, idx, target_member_id=None):
pan_record = db_get_pankration_record(member_id)
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
db_state = c.execute("SELECT battle_id, reflector_primary member_id FROM pankration_arena WHERE battle_status = 'waiting';").fetchall()
if target_member_id:
db_state = c.execute("SELECT battle_id, reflector_primary FROM pankration_arena WHERE battle_status = 'waiting' AND direct_challenge = ?;", (member_id,)).fetchall()
else:
db_state = c.execute("SELECT battle_id, reflector_primary FROM pankration_arena WHERE battle_status = 'waiting' AND direct_challenge = 0;").fetchall()
if not db_state:
log("No battles available: {}".format(idx,))
c.execute("""INSERT INTO pankration_arena(primary_member_id, reflector_primary)
VALUES(?, ?);""", (member_id, pickle.dumps(reflector)))
if target_member_id:
c.execute("""INSERT INTO pankration_arena(primary_member_id, reflector_primary, direct_challenge)
VALUES(?, ?, ?);""", (member_id, pickle.dumps(reflector), target_member_id))
else:
c.execute("""INSERT INTO pankration_arena(primary_member_id, reflector_primary)
VALUES(?, ?);""", (member_id, pickle.dumps(reflector)))
conn.commit()
conn.close()
db_remove_reflector(member_id, idx)
......@@ -440,16 +455,17 @@ def db_complete_battle(battle_id, primary_member_id, primary_reflector, secondar
else:
c.execute("""UPDATE pankration SET reflectors = ?, losses = losses + 1
WHERE member_id = ?;""", (pickle.dumps(reflectors), primary_member_id))
conn.commit()
reflectors = pickle.loads(str(db_get_pankration_record(secondary_member_id)['reflectors']))
reflectors.append(secondary_reflector)
reflectors2 = pickle.loads(str(db_get_pankration_record(secondary_member_id)['reflectors']))
reflectors2.append(secondary_reflector)
log('Completing battle - secondary')
if winner == 2:
c.execute("""UPDATE pankration SET reflectors = ?, wins = wins + 1
WHERE member_id = ?;""", (pickle.dumps(reflectors), secondary_member_id))
WHERE member_id = ?;""", (pickle.dumps(reflectors2), secondary_member_id))
else:
c.execute("""UPDATE pankration SET reflectors = ?, losses = losses + 1
WHERE member_id = ?;""", (pickle.dumps(reflectors), secondary_member_id))
WHERE member_id = ?;""", (pickle.dumps(reflectors2), secondary_member_id))
conn.commit()
conn.close()
log('Completing battle - done')
......
No preview for this file type
......@@ -93,6 +93,7 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help',
'!convertplate': 'do_convert_plate', '!convertsoulplate': 'do_convert_plate',
'!assignskill': 'do_assign_skill',
'!registerbattle': 'do_register_battle',
'!setreflectorname': 'do_set_reflector_name',
'!pankration': 'do_pankration',
}
......@@ -1041,6 +1042,7 @@ def do_pankration(client, message_parts, message):
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.
**!setreflectorname <reflector number> <name>** - This will rename a monster in your collection to a custom name.
*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.
......@@ -1048,6 +1050,28 @@ def do_pankration(client, message_parts, message):
""".format(message.author.mention()))
def do_set_reflector_name(client, message_parts, message):
member = data.db_get_member(message.author.id)
if len(message_parts) < 2:
send_message(client, message.channel, 'You must provide the reflector number and the new name.')
return
reflector_num = message_parts[0]
new_name = ' '.join(message_parts[1:])
pankration_data = data.db_get_pankration_record(member['member_id'])
if pankration_data and pankration_data['reflectors']:
reflectors = pickle.loads(str(pankration_data['reflectors']))
if not reflector_num.isdigit() or int(reflector_num) < 1 or int(reflector_num) > len(reflectors):
send_message(client, message.channel, 'The requested reflector is invalid. Please provide the number from !listreflectors')
return
reflector_num = int(reflector_num) - 1
reflectors[reflector_num].set_monster_name(new_name)
data.db_update_pankration_record(member['member_id'], 'reflectors', pickle.dumps(reflectors))
send_message(client, message.channel, 'The reflector (monster) name has been updated.')
else:
send_message(client, message.channel, 'Unable to find the reflector data.')
def do_register_battle(client, message_parts, message):
member = data.db_get_member(message.author.id)
......@@ -1067,13 +1091,17 @@ def do_register_battle(client, message_parts, message):
reflector_num = int(reflector_num) - 1
if len(message_parts) > 1:
user = ' '.join(message_parts[1:])
username = ' '.join(message_parts[1:])
data.db_register_battle(member['member_id'], reflectors[reflector_num], reflector_num, user)
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))
target_member = data.db_get_member(username=username)
if target_member and 'member_id' in target_member:
data.db_register_battle(member['member_id'], reflectors[reflector_num], reflector_num, target_member['member_id'])
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))
else:
send_message(client, message.channel, "There was a problem looking up that user.")
else:
data.db_register_battle(member['member_id'], reflectors[reflector_num], reflector_num)
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))
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))
else:
send_message(client, message.channel, 'You have no available reflectors. You can get reflectors by converting soul plates with !convertplate')
return
......@@ -1221,15 +1249,15 @@ def check_arena():
send_message(client, arena_channel, "Ladies and gentlemen!\nFor our next match...")
time.sleep(5)
send_message(client, arena_channel, "In the red corner we have...\n **{}**!".format(monster.monster_type))
send_message(client, arena_channel, "In the red corner we have...\n **{}**!".format(monster.get_monster_name()))
time.sleep(5)
send_message(client, arena_channel, "Hmmm... This monster seems {} and {}.".format(monster.get_current_posture()["name"], monster.get_current_attitude()["name"]))
time.sleep(5)
send_message(client, arena_channel, "And in the blue corner is...\n **{}**!".format(monster2.monster_type))
send_message(client, arena_channel, "And in the blue corner is...\n **{}**!".format(monster2.get_monster_name()))
time.sleep(5)
send_message(client, arena_channel, "Hmmm... This monster seems {} and {}.".format(monster2.get_current_posture()["name"], monster2.get_current_attitude()["name"]))
time.sleep(5)
send_message(client, arena_channel, "Alright, Pankration fans, the match is about to begin!\n *Chaaaaaarge!*".format(monster2.monster_type))
send_message(client, arena_channel, "Alright, Pankration fans, the match is about to begin!\n *Chaaaaaarge!*".format(monster2.get_monster_name()))
time.sleep(5)
data.db_start_battle(battle['battle_id'])
......@@ -1244,12 +1272,12 @@ def check_arena():
out_str = ""
for action in actions:
if isinstance(action, MissAction):
out_str += "{} {} {}.\n".format(action.attacker.monster_type, action.message, action.target.monster_type)
out_str += "{} {} {}.\n".format(action.attacker.get_monster_name(), action.message, action.target.get_monster_name())
if isinstance(action, AttackAction):
out_str += "{} {} {} for {}.\n".format(action.attacker.monster_type, action.message, action.target.monster_type, int(action.damage))
out_str += "{} {} {} for {}.\n".format(action.attacker.get_monster_name(), action.message, action.target.get_monster_name(), int(action.damage))
if isinstance(action, DefeatAction):
out_str += "\n\n**{}** {}. {} gains {} xp.\n\n".format(action.target.monster_type, action.message, action.attacker.monster_type, action.xp)
out_str += "\n\n**{}** {}. {} gains {} xp.\n\n".format(action.target.get_monster_name(), action.message, action.attacker.get_monster_name(), action.xp)
fighting = False
if action.attacker == monster:
result, xp_msg = monster.add_xp(action.xp)
......@@ -1266,7 +1294,7 @@ def check_arena():
monster2.wins += 1
monster.losses += 1
break
out_str += "\n{} {}% - {} {}%\n".format(monster.monster_type, monster.get_hp_percent(), monster2.monster_type, monster2.get_hp_percent())
out_str += "\n{} {}% - {} {}%\n".format(monster.get_monster_name(), monster.get_hp_percent(), monster2.get_monster_name(), monster2.get_hp_percent())
log(out_str)
send_message(client, arena_channel, byteify(out_str))
# Heal the monsters before they are returned to the player inventory
......