3c3cad9f by Barry

Basic pankration added with arena.

1 parent 8ccecd68
......@@ -337,9 +337,74 @@ def db_remove_reflector(member_id, idx):
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)
if not db_add_reflector(member_id, soul_plate):
return False
if not db_remove_soul_plate(member_id, idx):
return False
return True
def db_register_battle(member_id, reflector, idx, target_member=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 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)))
conn.commit()
conn.close()
db_remove_reflector(member_id, idx)
else:
for row in db_state:
primary_reflector = pickle.loads(str(row[1]))
primary_level = primary_reflector.level
# TODO: Setup challenges based on level difference of no more than 10 or spawn a new monster.
# if primary_level - 10 <= reflector.level <= primary_level + 10:
battle_id = row[0]
c.execute("""UPDATE pankration_arena SET secondary_member_id = ?, reflector_secondary = ?, battle_status = 'queued', queue_start = ?
WHERE battle_id = ?;""", (member_id, pickle.dumps(reflector), datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S'), battle_id))
conn.commit()
conn.close()
db_remove_reflector(member_id, idx)
return
def db_complete_battle(battle_id, primary_member_id, primary_reflector, secondary_member_id,
secondary_reflector):
pass
def db_start_battle(battle_id):
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
c.execute("""UPDATE pankration_arena SET battle_status = 'fighting', battle_start = ?
WHERE battle_id = ?;""", (datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S'), battle_id))
conn.commit()
conn.close()
def db_get_battle_queue():
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
result = c.execute("SELECT * FROM pankration_arena WHERE battle_status = 'queued' ORDER BY queue_start;").fetchall()
conn.close()
results = []
for row in result:
results.append(dict_factory(c, row))
return results
def db_get_member_username(member_id):
# 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')
c = member_conn.cursor()
result = c.execute("SELECT member_name FROM members WHERE member_id = ?;", (member_id,)).fetchone()
member_conn.close()
return result[0]
def db_get_member(discord_id=None, username=None):
......
No preview for this file type
......@@ -27,7 +27,7 @@ import wolframalpha
import sqlite3
from blackjack import Blackjack
import data
from pankration import Pankration, HuntResponse, Jobs
from pankration import Pankration, HuntResponse, Jobs, Action, MissAction, AttackAction, DefeatAction, TemperamentPosture, TemperamentAttitude
VERSION = 2.3
......@@ -35,6 +35,8 @@ quitting = False
grant_hour = 11
battle_in_progress = False
conn = sqlite3.connect('db.sqlite3')
credentials = 'creds.json'
......@@ -89,6 +91,8 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help',
'!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',
'!assignskill': 'do_assign_skill',
'!registerbattle': 'do_register_battle',
'!pankration': 'do_pankration',
}
......@@ -102,6 +106,7 @@ def log(message):
except:
pass
def send_message(client, target, message):
if type(target) is not discord.channel.PrivateChannel:
if target.id == '121468616414724100':
......@@ -110,6 +115,7 @@ def send_message(client, target, message):
return
client.send_message(target, message)
def format_exception(e):
exception_list = traceback.format_stack()
exception_list = exception_list[:-2]
......@@ -310,7 +316,7 @@ def do_gif(client, message_parts, message):
def do_gameslist(client, message_parts, message):
limit = 20
log("parts: {} {}".format(message_parts,message))
log("parts: {} {}".format(message_parts, message))
if len(message_parts) > 0 and message_parts[0].isdigit():
limit = int(message_parts[0])
games_list = data.db_get_games_list(limit)
......@@ -507,7 +513,7 @@ def do_startraffle(client, message_parts, message):
for member in client.get_all_members():
log(member.id)
if member.id == '78767557628133376':
priv_message = "1st: {} key: {}\n2nd: {} keys: {}\n3rd: {} keys: {}".format(byteify(winner), game_key, byteify(second), ' '.join(random_keys[0:2]), byteify(third), random_keys[3])
priv_message = "1st: {} key: {}\n2nd: {} keys: {}\n3rd: {} keys: {}".format(byteify(winner), game_key, byteify(second), ' '.join(random_keys[0:2]), byteify(third), random_keys[2])
log(priv_message)
send_message(client, member, priv_message)
break
......@@ -1047,6 +1053,41 @@ def do_pankration(client, message_parts, message):
""".format(message.author.mention()))
def do_register_battle(client, message_parts, message):
member = data.db_get_member(message.author.id)
if len(message_parts) < 1:
send_message(client, message.channel, 'You must provide at least 1 arguments to register for a battle. The reflector number and optionally a user name you wish to battle. Please see !pankration for an example.')
return
reflector_num = message_parts[0]
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
if len(message_parts) > 1:
user = ' '.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))
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))
else:
send_message(client, message.channel, 'You have no available reflectors. You can get reflectors by converting soul plates with !convertplate')
return
def do_assign_skill(client, message_parts, message):
send_message(client, message.channel, '**Feral Skills are not yet supported**')
def do_convert_plate(client, message_parts, message):
member = data.db_get_member(message.author.id)
......@@ -1064,12 +1105,15 @@ def do_convert_plate(client, message_parts, message):
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)
plate_num = int(plate_num) - 1
if convert_to == "reflector":
# do reflector stuff
data.db_convert_soul_plate_to_reflector(member['member_id'], soul_plates[plate_num], plate_num)
pass
if data.db_convert_soul_plate_to_reflector(member['member_id'], soul_plates[plate_num], plate_num):
send_message(client, message.channel, 'The soul plate was successfully converted into an official reflector. To view your reflectors: !listreflectors')
else:
send_message(client, message.channel, 'There was an issue converting your soul plate...Conversion failed.')
elif convert_to == "skill":
send_message(client, message.channel, '**Feral Skills are not yet supported**')
# do skill stuff
pass
else:
......@@ -1080,6 +1124,7 @@ def do_convert_plate(client, message_parts, message):
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)
......@@ -1090,6 +1135,7 @@ def do_list_soul_plates(client, message_parts, message):
else:
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)
......@@ -1111,6 +1157,7 @@ def do_list_feral_skills(client, message_parts, message):
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))
......@@ -1122,16 +1169,82 @@ def do_hunt_monster(client, message_parts, message):
str_out += str(soul_plate.get_soul_plate_description())
send_message(client, message.channel, str_out)
def do_list_zones(client, message_parts, message):
p = Pankration()
send_message(client, message.channel, ', '.join(p.list_zones()))
return
def check_arena():
global battle_in_progress
if battle_in_progress:
return
try:
battle_in_progress = True
battle = data.db_get_battle_queue()
if len(battle) == 0:
return
battle = battle[0]
for channel in client.get_all_channels():
if channel.id == '151942626130657280':
arena_channel = channel
break
# pop first battle off queue
log("Starting Battle: {}".format(battle['battle_id']))
monster = pickle.loads(str(battle['reflector_primary']))
monster2 = pickle.loads(str(battle['reflector_secondary']))
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))
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))
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))
time.sleep(5)
data.db_start_battle(battle['battle_id'])
p = Pankration()
battle_arena = p.start_battle(monster, monster2, "not used")
fighting = True
while fighting:
actions = battle_arena.step()
time.sleep(4)
out_str = ""
for action in actions:
if isinstance(action, MissAction):
out_str += "{} {} {}.\n".format(action.attacker.monster_type, action.message, action.target.monster_type)
if isinstance(action, AttackAction):
out_str += "{} {} {} for {}.\n".format(action.attacker.monster_type, action.message, action.target.monster_type, 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)
fighting = False
break
out_str += "\n{} {}% - {} {}%\n".format(monster.monster_type, monster.get_hp_percent(), monster2.monster_type, monster2.get_hp_percent())
log(out_str)
send_message(client, arena_channel, byteify(out_str))
#wait after each match before starting a new fight.
time.sleep(30)
except Exception as e:
log("{} - {}".format(format_exception(e), e.message))
finally:
battle_in_progress = False
### END PANKRATION
def start_timer(client):
needs_loot = True
while not quitting:
if not battle_in_progress:
thread.start_new_thread(check_arena, ())
if datetime.datetime.now().hour == grant_hour:
needs_loot = True
# This should fire anytime they need loot and it isn't 9.. this will change to 11 after testing
......@@ -1140,8 +1253,9 @@ def start_timer(client):
if channel.id == '47934985176354816':
do_grantcredits(client, None, None, channel)
needs_loot = False
time.sleep(10000)
#log('Sleeping')
time.sleep(10)
# log('Sleeping... Time: {}'.format(datetime.datetime.now()))
def thread_exception_handler(method, client, message_parts, message):
try:
......@@ -1152,6 +1266,7 @@ def thread_exception_handler(method, client, message_parts, message):
except Exception as e:
log("{} - {}".format(format_exception(e), e.message))
#################
# Client Events
#################
......@@ -1177,11 +1292,12 @@ def on_status(member):
log("Exception: {}".format(format_exception(e)))
pass
@client.event
def on_message(message):
#print message.content
#print message.author
#print client.user
# print message.content
# print message.author
# print client.user
# we do not want the bot to reply to itself
if message.author == client.user:
return
......
......@@ -365,10 +365,10 @@ class Monster:
break
def get_current_posture(self):
return TemperamentPosture(self.temperament_posture)
return TemperamentPosture[self.temperament_posture]
def get_current_attitude(self):
return TemperamentAttitude(self.temperament_attitude)
return TemperamentAttitude[self.temperament_attitude]
def get_dicipline_level(self):
if self.dicipline_level < 2:
......