840d3f95 by Barry

Added a reset tickets, updated the bot and pankration.

1 parent 5489faaf
......@@ -68,6 +68,18 @@ def db_buy_ticket(member_id, amount):
except Exception as e:
log(e)
def db_reset_all_tickets(member_id):
log("Resetting Tickets - DB")
try:
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
c.execute("""UPDATE members SET tickets = 0
WHERE member_id = ?;""", (member_id,))
conn.commit()
return True
except Exception as e:
log(e)
def db_update_credit(member_id, amount):
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
......
No preview for this file type
......@@ -62,6 +62,7 @@ registered_commands = {'!help': 'do_help', '!commands': 'do_help',
'!whoplayed': 'do_whoplayed',
'!gimmecredits': 'do_gimmecredits', '!gimmecredit': 'do_gimmecredits',
'!grantcredits': 'do_grantcredits',
'!resetalltickets': 'do_resetalltickets',
'!ticketrank': 'do_ticketrank',
'!startraffle': 'do_startraffle',
'!raffle': 'do_raffle',
......@@ -414,6 +415,19 @@ def do_gimmecredits(client, message_parts, message):
send_message(client, message.author, "You already have credits. Stop begging.")
return
def do_resetalltickets(client, message_parts, message, channel=None):
if not channel and message.author.id != '78767557628133376':
send_message(client, message.channel, "You are not Hellsbreath. Go away.")
return
members = data.db_get_all_members()
if len(members) < 0:
send_message(client, message.channel, "There was a problem looking up your information.")
else:
for member in members:
if member['tickets'] > 0:
data.db_reset_all_tickets(member['member_id'])
send_message(client, message.channel, "{} had {} tickets and was reset to 0.".format(member['member_name'], member['tickets']))
return
def do_grantcredits(client, message_parts, message, channel=None):
if not channel and message.author.id != '78767557628133376':
......@@ -1289,13 +1303,22 @@ def check_arena():
fighting = False
if action.attacker == monster:
result, xp_msg = monster.add_xp(action.xp)
# give a small amount to the loser
if result:
out_str += xp_msg
result, xp_msg = monster2.add_xp(5)
if result:
out_str += xp_msg
winner = 1
monster.wins += 1
monster2.losses += 1
else:
# give a small amount to the loser
result, xp_msg = monster2.add_xp(action.xp)
# give a small amount to the loser
if result:
out_str += xp_msg
result, xp_msg = monster.add_xp(5)
if result:
out_str += xp_msg
winner = 2
......
......@@ -212,7 +212,8 @@ class Spells:
'magic_acc_stat': spell['magic_acc_stat'],
'base_damage': type_data[spell['damage_type']],
'multiplier': type_data['multiplier'],
'mp_cost': spell['mp_cost']
'mp_cost': spell['mp_cost'],
'damage_type': spell['damage_type']
}
return spell_data
......@@ -515,6 +516,8 @@ class Monster:
def __init__(self, monster_type, family_name, family, base_hp, base_mp, level, weapon_base_damage, main_job,
support_job, innate_feral_skills, equipped_feral_skills, dicipline_level):
self.custom_name = None
self.status_effects = {}
self.monster_type = monster_type
self.family_name = family_name
self.family = family
......@@ -553,6 +556,7 @@ class Monster:
self.mp = self.get_mp()
self.wins = 0
self.losses = 0
self.battle_memory = []
def __str__(self):
try:
......@@ -586,7 +590,7 @@ class Monster:
def get_hp(self):
#this is a bit dumb but it's close enough.
return int((self.level * 20) + self.base_hp)
return self.get_status_effect('hp', int((self.level * 20) + self.base_hp))
def get_mp(self):
#this is a bit dumb but it's close enough.
......@@ -596,7 +600,7 @@ class Monster:
main_mp = int((self.level * (self.base_mp + main_add_amount)) + self.base_mp)
sub_mp = int((self.level/2) * sub_add_amount)
return main_mp + sub_mp
return self.get_status_effect('mp', main_mp + sub_mp)
def get_fp(self):
......@@ -637,45 +641,45 @@ class Monster:
def get_dexterity(self):
return int(round(max(self.base_dex, self.level * self.dex_per_level)))
return self.get_status_effect('dex', int(round(max(self.base_dex, self.level * self.dex_per_level))))
def get_accuracy(self):
# We ignore magic / ranged / melee here and give everyone a good acc. This could be improved by doing a lookup for each type and based on the
# type of monster (magic, range, or melee) then adjust the combat skill according to what type of attack is being performed.
return int(math.floor(3*self.get_dexterity()/4) + self.get_combat_skill())
return self.get_status_effect('acc', math.floor(3*self.get_dexterity()/4) + self.get_combat_skill())
def get_evasion(self):
job_eva = adjustments_by_job[self.main_job]
base_eva = int(round(max(job_eva['base_eva'], self.level * job_eva['eva_per_level'])))
return base_eva + int(self.get_agility() / 2)
return self.get_status_effect('eva', base_eva + int(self.get_agility() / 2))
def get_vitality(self):
return int(round(max(self.base_vit, self.level * self.vit_per_level)))
return self.get_status_effect('vit', int(round(max(self.base_vit, self.level * self.vit_per_level))))
def get_strength(self):
return int(round(max(self.base_str, self.level * self.str_per_level)))
return self.get_status_effect('str', int(round(max(self.base_str, self.level * self.str_per_level))))
def get_agility(self):
return int(round(max(self.base_agi, self.level * self.agi_per_level)))
return self.get_status_effect('agi', round(max(self.base_agi, self.level * self.agi_per_level)))
def get_mind(self):
return int(round(max(self.base_mnd, self.level * self.mnd_per_level)))
return self.get_status_effect('mnd', int(round(max(self.base_mnd, self.level * self.mnd_per_level))))
def get_intelligence(self):
return int(round(max(self.base_int, self.level * self.int_per_level)))
return self.get_status_effect('int', int(round(max(self.base_int, self.level * self.int_per_level))))
def get_charisma(self):
return int(round(max(self.base_chr, self.level * self.chr_per_level)))
return self.get_status_effect('cha', int(round(max(self.base_chr, self.level * self.chr_per_level))))
def get_base_defense(self):
return (math.floor(self.get_vitality()/2) + 8 + self.level)
return self.get_status_effect('def', (math.floor(self.get_vitality()/2) + 8 + self.level))
def get_hp_percent(self):
return max(1, int(round((self.hp/self.get_hp())*100)))
def get_magic_evasion(self):
return max(1, int(1+round(self.level/4)))
def get_magic_evasion(self, damage_type):
# This handles spell types and elemental additions due to damage type
return self.get_status_effect(damage_type + '_resist', max(1, int(1+round(self.level/4))))
def get_hit_rate(self, enemy_eva, level_difference):
rate = 75 + math.floor(((self.get_accuracy() - enemy_eva)/2)) - (2*level_difference)
......@@ -699,7 +703,7 @@ class Monster:
elif magic_acc_stat == 'agi':
dSTAT = self.get_agility() - enemy.get_agility()
magic_hit_rate = 50 - 0.5 * (enemy.get_magic_evasion() - dSTAT)
magic_hit_rate = 50 - 0.5 * (enemy.get_magic_evasion(spell_data['damage_type']) - dSTAT)
if magic_hit_rate < 5:
magic_hit_rate = 5
......@@ -838,6 +842,47 @@ class Monster:
return base_damage
# it is up to the rest of the system to understand how to read this data and act on it.
# Example Call: ('acc', '10', False, 30)
def set_status_effect(self, effect, amount, is_percent, expires_seconds):
self.status_effects[effect] = {'amount': amount, 'is_percent': is_percent, 'expires_seconds': expires_seconds}
def get_status_effect(self, effect, base_amount):
if effect in self.status_effects:
amount = self.status_effects[effect]['amount']
if self.status_effects[effect]['is_percent']:
return int(base_amount + base_amount * (amount/100))
else:
return int(base_amount + amount)
else:
return base_amount
# This is a list of all status effects that are available.
def get_status_effect_list(self):
return [
'acc',
'agi',
'cha',
'def',
'dex',
'eva',
'hp',
'int',
'mnd',
'mp',
'str',
'vit',
'fire_resist',
'water_resist',
'ice_resist',
'wind_resist',
'earth_resist',
'thunder_resist',
'light_resist',
'dark_resist'
]
# Calculate the base damage against the provided defense
# attack_type can be 'ranged' or 'melee'
# TODO: Replace enemyvit with the actual enemy variable
......@@ -855,6 +900,33 @@ class Monster:
final_damage = int(bd * pDif)
return final_damage
# Choose the best action for the monster
def get_best_action(self, monster):
# Step 0: Am I already casting a spell? Is it time to calc damage from that?
# Step 1: Is magic possible?
spell_list = Spells().get_spell_list(self.level, job=self.main_job, sub_job=self.sub_job)
# Step 2: Do i have a memory of this monster from past battles? Does it have any elemental weakness?
# Step 3: What status effects is the monster currently under? What are the effects(DOTS) we can apply?
# find out the avg damage from each type of attack and sort them
# find out if we need to do defensive actions given the amount of life left in the enemy vs how much damage it does.
# We should also store how hard the AI has hit previously and adjust accordingly (Store previous average damage per hit). IE project how much damage we will
# do vs how much they will do and choose an action
# Decide if we need to do healing as part of the defensive strategy.
# - This should be partially decided based on the class and the efficacy of healing
# - This should be comparied against shielding. Shielding is often based on a specific type of hit so remember the hits they have
# Taken on us in the past.
# Modify apply damage to pass what type of damage it was (magic, melee, or ranged)
# If we don't need defense (we thi)
pass
def attack(self, monster):
is_a_crit = False
is_a_hit = False
......@@ -862,6 +934,7 @@ class Monster:
resisted = False
damage = 0
self.get_best_action(monster)
######
# TODO: Build some type of AI / testing to find the most powerful attack and use that (magic, melee, or ranged)
......@@ -1077,6 +1150,7 @@ if __name__ == "__main__":
print(hunt_response.message)
monster = hunt_response.monster
monster.set_monster_name('Kickass 1')
monster.set_status_effect('int', 100, False, None)
print("The Soul Plate Shows: \n\n{}".format(monster))
# print(monster.set_strategy(4, 3))
# print(monster.set_strategy(1, 1))
......