-
Notifications
You must be signed in to change notification settings - Fork 2
/
character.py
162 lines (135 loc) · 6.31 KB
/
character.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import random
import database
import hashlib
import discord
import logging
import game
db = database.Database()
#give the bosses proper weapons
#implement some kind system of ranged weapons for bows and mages
logging.basicConfig(handlers=[logging.FileHandler(filename="logs/TBG.log",
encoding='utf-8', mode='a+')],
format="%(asctime)s %(name)s:%(levelname)s:%(message)s",
datefmt="%F %A %T",
level=logging.INFO)
beginner_classes = ["Archer","Barbarian","Infantry","Tactician","Swordsmen"]
intermediate_classes = ["Spearmen","Knight","Brigand","Mercenary","Dueler","Strategist","Longbowmen","Mounted Archer"]
advanced_classes = ["Warrior","Wizard","Sniper","Knight","Spearmaster","Ninja","Rocketeer","Mounted Knight"]
class_road_map = {
"bow":["Archer","Longbowmen-Mounted Archer","Sniper-Ninja-Rocketeer"],
"sword":["Swordsmen","Mercenary","Knight-Ninja-Mounted Knight"],
"spear":["Infantry","Spearmen","Spearmaster-Mounted Knight"],
"axe":["Barbarian","Brigand","Warrior"],
"tome":["Tactician","Strategist","Wizard"]
}
weapons = {}
def determine_enemy_class(level):
if level > 40:
return random.choice(database.advanced_classes)
if level > 20:
return random.choice(database.intermediate_classes)
return random.choice(database.beginner_classes)
def generate_enemy(name,level):
#used the 0 at the start as placement for the message id
weapon_type = random.choice(list(class_road_map.keys()))
num_classes = min(int(level/20)+1,len(class_road_map[weapon_type]))
classes = class_road_map[weapon_type][:num_classes]
for num in range(len(classes)):
classes[num] = random.choice(classes[num].split("-"))
weapon_thing = generate_class_weapon(classes[-1],level)
weapon_id = game.hash_string(weapon_thing)
current_level = 0
enemy_data = [0, name, weapon_id, classes[-1], level, 0, 0, 3, 1, 1, 1, 1, 1,generate_enemy_loot(level),""]
for class_name in classes:
growth_rates = db.get_class(class_name)[1].split("-")
for x in range(20):
if current_level == level:
break
current_level+=1
for num in range(len(growth_rates)):
if rng(float(growth_rates[num])):
enemy_data[7+num]+=1
enemy_data[6] = enemy_data[7]
return enemy_data
def generate_boss(name,level,class_name,weapon_id):
#used the 0 at the start as placement for the message id
boss_data = [0, name, weapon_id, class_name, level, 0, 0, 20, 10, 10, 10, 10, 10,generate_boss_loot(level),""]
growth_rates = db.get_class(class_name)[1].split("-")
for x in range(level):
for num in range(len(growth_rates)):
if rng(float(growth_rates[num])):
boss_data[7+num]+=1
boss_data[7] = int(boss_data[7]*1.5)
boss_data[6] = boss_data[7]
return boss_data
def generate_class_weapon(class_name,level):
weapon_choice = random.choice(db.get_class(class_name)[4].split("-"))
return database.weapons[weapon_choice][int(min(level/90,0.99)*len(database.weapons[weapon_choice]))]
def generate_enemy_loot(level):
return f"{str(2+int((random.randint(4,7)/10)*level))}.gold coin-{str(5+int((random.randint(15,20)/10)*level))}.exp"
def generate_boss_loot(level):
return f"{str(120+int((level*4)))}.gold coin-{str(int((level*10)**1.25))}.exp"
def generate_character(user_id, name, user_class, weapon_id, resets):
return (user_id, name, weapon_id, user_class, 1, 0, 20+resets, 20+resets, 7+resets, 6+resets, 8+resets, 6+resets, 4+resets)
def can_equip(char_data,target_weapon):
if target_weapon[4] == "physical":
if char_data[8] >= int(target_weapon[2]*0.5):
return True,0
return False,f"you need at least {int(target_weapon[2]*0.5)} STR to equip it"
if target_weapon[4] == "magical":
if char_data[9] >= int(target_weapon[2]*0.5):
return True,0
return False,f"you need at least {int(target_weapon[2]*0.5)} MAG to equip it"
def change_class(character_data,target_class):
class_growth = db.get_class(target_class)[1].split("-")[1:]
stat_requirements = class_requirement(target_class)
for num in range(len(stat_requirements)):
if character_data[8+stat_requirements[num][0]] >= stat_requirements[num][1]:
character_data[3] = target_class
unequip_weapon(character_data)
return True
return False
def class_requirement(target_class):
class_growth = db.get_class(target_class)[1].split("-")[1:]
stat_requirement = max(class_growth)
stat_requirements = []
for x in range(len(class_growth)):
if class_growth[x] == stat_requirement:
stat_requirements.append((x,0.2*int(class_growth[x])))
return stat_requirements
async def character_check(user_data,user,msg):
next_level_requirement = next_level(user_data[4])
while user_data[5] >= next_level_requirement:
user_data[5] -= next_level_requirement
user_data[4] += 1
growth_rates = db.get_class(user_data[3])[1].split("-")
for num in range(len(growth_rates)):
if rng(float(growth_rates[num])):
user_data[7+num]+=1
next_level_requirement = next_level(user_data[4])
logging.info(f"{str(user_data[0])} leveled up")
user_data[6] = user_data[7]
await msg.channel.send(f"{user.mention} leveled up, health also healed back to full!")
user_data[6] = min(user_data[6],user_data[7])
user_data[6] = max(user_data[6],0)
return user_data
def get_class_attribute(class_name):
return db.get_character(class_name)[3].split("-")
def unequip_weapon(character_data):
if character_data[2] != hash_string("fist"):
db.add_item(character_data[0],character_data[2],1)
character_data[2] = hash_string("fist")
return character_data
#would be nice to have something more complex here
def next_level(current_level):
if current_level < 60:
return int(current_level*10.25)+100
return int(1.12**current_level)
def get_class_weapons(class_name):
return db.get_class(class_name)[4].split("-")
def rng(odds):
if random.random()*100 < odds:
return True
return False
def hash_string(string_input):
return int(hashlib.sha256(string_input.encode('utf-8')).hexdigest(), 16) % 10**8