-
Notifications
You must be signed in to change notification settings - Fork 0
/
MonsterGenerator.py
119 lines (105 loc) · 3.97 KB
/
MonsterGenerator.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
""" This will allow adding monster dynamically from a set of configuration files
in the 'mobs' directory, images for the monsters should be put in the images directory.
Eventually the images will get restructured into better locations, but for now thats where its going. """
import os
from random import choice
import configparser
from Mob import Mob
from molecular import Molecule
from JobList import JobList
# load up the mobs into a list of config files, will be read by the __init__ of the MonsterGenerator class
MOB_DIR = "mobs"
DIR_PATH = os.path.join(os.getcwd(), MOB_DIR)
FILES_IN_DIR = os.listdir(DIR_PATH)
FILE_LIST = []
for filename in FILES_IN_DIR:
FILE_LIST.append(os.path.join(DIR_PATH, filename))
def namegen_orc_first():
"""Generate an Orcish first name"""
name = Molecule()
name.load("namefiles/orcs_t.nam")
return name.name()
def namegen_orc_second():
"""Generate an Orcish last name"""
name = Molecule()
name.load("namefiles/orcs_wh.nam")
return name.name()
class MonsterGenerator:
"""MonsterGenerator Class"""
def __init__(self):
self.monster_list = []
self.JL = JobList()
self.job_list = self.JL.get_list()
for item in FILE_LIST:
config = configparser.ConfigParser()
# config.readfp(open(os.path.join('mobs', item)))
config.read_file(open(item))
name = config.get("mob", "name")
image = config.get("mob", "image")
portrait = config.get("mob", "portrait")
dead_image = config.get("mob", "dead_image")
job = config.get("mob", "job")
level = config.getint("mob", "level")
damage = config.getint("mob", "damage")
view_range = config.getint("mob", "view_range")
experience = config.getint("mob", "experience")
mob_dict = {
"name": name,
"image": image,
"portrait": portrait,
"dead_image": dead_image,
"job": job,
"level": level,
"damage": damage,
"view_range": view_range,
"experience": experience,
}
self.monster_list.append(mob_dict)
# load the list of different types of monsters on init
def generate_monster(self, mob_level, name=None, job=None):
"""This is the function thats called and will generate the specified monster, 2 optional params (name and job)"""
temp_list = []
for monster in self.monster_list:
if name:
pass
else:
name = monster["name"]
if job:
pass
else:
job = monster["job"]
if monster["level"] == mob_level:
if name == "generate":
name = namegen_orc_first() + " " + namegen_orc_second()
if job == "generate":
job = choice(self.job_list)
else:
job = self.JL.generate_job_for(job)
mob = Mob(
name,
job,
monster["image"],
monster["portrait"],
monster["dead_image"],
)
mob.job = job
mob.level = monster["level"]
mob.view_range = monster["view_range"]
mob.experience = monster["experience"]
temp_list.append(mob)
# pick one of the monsters from the list randomly
return choice(temp_list)
def __str__(self):
return self.monster_list
if __name__ == "__main__":
# debugging
MG = MonsterGenerator()
mob_test = MG.generate_monster(1)
mob_test2 = MG.generate_monster(1, "testname")
mob_test3 = MG.generate_monster(1, "testname2", "testjob")
print(mob_test.name)
print(mob_test.job)
print(mob_test2.name)
print(mob_test2.job)
print(mob_test3.name)
print(mob_test3.job)