-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerDataContainer.py
More file actions
429 lines (344 loc) · 16 KB
/
Copy pathPlayerDataContainer.py
File metadata and controls
429 lines (344 loc) · 16 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
import os
import sys
import numpy as np
import pandas as pd
"""
STATS GENERATOR FOR TURN BASED OR ACTION RPG (ROLE PLAYING GAMES)
By: ROHMAN WIDIYANTO
GitHub: http://github.com/rohwid/
All component or object defined separately, here's the reason:
- Levels: Because sometimes the characters won't start from 1st level.
- Magic Point: Because sometimes the games doesn't need it (ex: action RPG).
- Number of Weaknesses: Same reason with Magic Point.
- Generate data container: Generate data container dynamically.
Notes:
- Anything which contain "show" in the function was used for debug or check the values.
- Every common function set to be more flexible and ready to be "override".
"""
from Visualization import player_stats_graph, player_hp_graph, player_mp_graph
class Player:
def __init__(self, max_level):
self.max_level = max_level
self.start_level = 0
self.range_level = np.array([])
self.range_hp = np.array([])
self.range_mp = np.array([])
self.name_element = []
self.element_container = np.array([])
self.name_stats = np.array([])
self.stats_container = np.array([])
self.main_column = np.array([])
self.data_container = np.array([])
@staticmethod
def set_column_main(pref, column_name, column_info):
if pref == 0:
if not column_info:
column_info = [column_name, 'HP(Auto)']
if column_info[1] != 'HP(Auto)':
column_info[0] = column_name
if pref == 1:
if not column_info:
column_info = ['Levels (Auto)', column_info]
if column_info[0] != 'Level(Auto)':
column_info[1] = column_name
if pref == 2:
if len(column_info) == 2:
column_info.append(column_name)
else:
sys.exit('[ERROR] Please define HP and Level first!')
return column_info
def range_levels(self, start_level, column_name):
self.start_level = start_level
self.range_level = np.arange(1, (self.max_level - start_level) + 2)
self.main_column = Player.set_column_main(0, column_name, self.main_column)
def show_range_levels(self, debug):
if debug:
print('[DEBUG] ~ LEVELS')
print('[DEBUG] Range Levels: ')
print(self.range_level)
print('\n\n')
def range_health_points(self, start_hp, second_hp, column_name):
self.range_hp = np.arange(
start_hp,
start_hp + (self.max_level * (second_hp - start_hp)),
second_hp - start_hp
)
self.main_column = Player.set_column_main(1, column_name, self.main_column)
def show_range_health_points(self, graph_title, graph=None, title=None, debug=None):
if debug:
print('[DEBUG] ~ NAMES')
print('[DEBUG] Range HP: ')
print(self.range_hp)
print('\n\n')
player_hp_graph(self.range_level, self.range_hp, graph_title, graph, title)
def range_magic_points(self, start_mp, second_mp, column_name):
self.range_mp = np.arange(
start_mp,
start_mp + (self.max_level * (second_mp - start_mp)),
second_mp - start_mp
)
self.main_column = Player.set_column_main(2, column_name, self.main_column)
def show_range_magic_points(self, graph_title, graph=None, title=None, debug=None):
if debug:
print('[DEBUG] ~ MP')
print('[DEBUG] Range MP: ')
print(self.range_mp)
print('\n\n')
player_mp_graph(self.range_level, self.range_mp, graph_title, graph, title)
def range_element_weak(self, name_element, char_weak_number):
self.name_element = name_element
for i in range(len(char_weak_number)):
if char_weak_number[i] == 2:
if self.element_container.size == 0:
self.element_container = np.full((self.max_level, 1), 2)
else:
self.element_container = np.concatenate(
(self.element_container, np.full((self.max_level, 1), 2)),
axis=1
)
if char_weak_number[i] == 1:
if self.element_container.size == 0:
self.element_container = np.ones((self.max_level, 1))
else:
self.element_container = np.concatenate(
(self.element_container, np.ones((self.max_level, 1))),
axis=1
)
if char_weak_number[i] == 0:
if self.element_container.size == 0:
self.element_container = np.zeros((self.max_level, 1))
else:
self.element_container = np.concatenate(
(self.element_container, np.zeros((self.max_level, 1))),
axis=1
)
def show_element_weak(self, debug):
if debug:
print('[DEBUG] ~ WEAKNESSES')
print('[DEBUG] List of characters elements: ', self.name_element)
print('[DEBUG] List of characters elements stats: ')
print(self.element_container)
print('\n\n')
def range_stats(self, name_stats, stats_max_value, stats_to_assign):
self.name_stats = name_stats
self.stats_container = np.zeros((self.max_level, len(stats_max_value)))
distribute_limit = np.zeros((len(stats_to_assign), len(stats_max_value)))
for i in range(len(stats_max_value)):
limit_cache = np.zeros(len(stats_to_assign))
check_limit = 0
for j in range(len(stats_to_assign)):
for k in range(len(stats_to_assign)):
check_limit = check_limit + limit_cache[k]
if check_limit > stats_max_value[i]:
break
if check_limit == 0:
limit = int(stats_max_value[i] / stats_to_assign[j])
distribute_limit[j][i] = np.random.randint(0, limit + 1)
limit_cache[j] = distribute_limit[j][i] * stats_to_assign[j]
else:
if (len(stats_to_assign) - j) == 1:
distribute_limit[j][i] = stats_max_value[i] - check_limit
limit_cache[j] = distribute_limit[j][i] * stats_to_assign[j]
else:
limit = int((stats_max_value[i] - check_limit) / stats_to_assign[j])
distribute_limit[j][i] = np.random.randint(0, limit + 1)
limit_cache[j] = distribute_limit[j][i] * stats_to_assign[j]
# Assign all stats data to container
for i in range(len(stats_max_value)):
last_stats = 0
for j in range(len(stats_to_assign)):
for k in range(int(distribute_limit[j][i])):
if last_stats == 0:
self.stats_container[k][i] = stats_to_assign[j]
else:
self.stats_container[last_stats + k][i] = stats_to_assign[j]
if distribute_limit[j][i] - k == 1:
last_stats = k + 1
# Shuffle the stats
for i in range(len(stats_max_value)):
np.random.shuffle(self.stats_container[:, i])
def show_range_stats(self, graph_title, graph=None, title=None, debug=None):
if debug:
print('[DEBUG] ~ STATS')
print('List of characters stats: ')
print(self.stats_container)
print('\n\n')
player_stats_graph(self.stats_container, self.range_level, self.name_stats, graph_title, graph, title)
@staticmethod
def set_level_container(data_container, column_info, max_level, range_level):
if data_container[column_info[0]].shape[0] == max_level:
data_container[column_info[0]] = range_level
return data_container
else:
sys.exit('[ERROR] The levels not match with the rows of data container!')
@staticmethod
def set_hp_container(data_container, column_info, max_level, range_hp):
if data_container[column_info[1]].shape[0] == max_level:
data_container[column_info[1]] = range_hp
return data_container
else:
sys.exit('[ERROR] The HP\'s rows not match with the rows of data container!')
@staticmethod
def set_mp_container(data_container, column_info, max_level, range_mp):
if data_container[column_info[2]].shape[0] == max_level:
data_container[column_info[2]] = range_mp
return data_container
else:
sys.exit('[ERROR] The MP\'s rows not match with the rows of data container!')
@staticmethod
def set_element_container(data_container, init_column, column_info, max_level, element_container):
if element_container.shape[0] == max_level:
# With MP (Usually Turn-based)
if len(init_column) == 3:
for i in range(element_container.shape[1]):
data_container[column_info[3 + i]] = element_container[:, i]
# Without MP (Usually Action)
else:
for i in range(element_container.shape[1]):
data_container[column_info[2 + i]] = element_container[:, i]
return data_container
else:
sys.exit('[ERROR] The Element\'s rows not match with the rows of data container!')
@staticmethod
def set_stats(data_container, init_column, column_info, max_level, stats_container):
if stats_container.shape[0] == max_level:
# Without Element (Usually Action)
if len(init_column) == 3:
len_element_container = column_info.shape[0] - (len(init_column) + stats_container.shape[1])
for i in range(stats_container.shape[1]):
data_container[column_info[len(init_column) + len_element_container + i]] = stats_container[:, i]
# Without MP and Element (Usually Action)
elif len(init_column) == 2:
len_element_container = column_info.shape[0] - (len(init_column) + stats_container.shape[1])
for i in range(stats_container.shape[1]):
data_container[column_info[len(init_column) + len_element_container + i]] = stats_container[:, i]
# Others
else:
for i in range(stats_container.shape[1]):
data_container[column_info.shape[2 + i]] = stats_container[:, i]
return data_container
else:
sys.exit('[ERROR] The Stats\'s rows not match with the rows of data container!')
def generate_stats(self):
row_level = np.arange((self.max_level - (self.max_level - self.start_level)), self.max_level + 1)
init_column = self.main_column
if self.range_mp.size == 0:
if not self.name_element:
column_info = np.concatenate((init_column, self.name_stats), axis=None)
self.data_container = pd.DataFrame(0, row_level[:], column_info[:])
self.data_container = Player.set_level_container(
self.data_container,
column_info,
self.max_level,
self.range_level
)
self.data_container = Player.set_hp_container(
self.data_container,
column_info,
self.max_level,
self.range_hp
)
self.data_container = Player.set_stats(
self.data_container,
init_column,
column_info,
self.max_level,
self.stats_container
)
else:
column_info = np.concatenate((init_column, self.name_element, self.name_stats), axis=None)
self.data_container = pd.DataFrame(0, row_level[:], column_info[:])
self.data_container = Player.set_level_container(
self.data_container,
column_info,
self.max_level,
self.range_level
)
self.data_container = Player.set_hp_container(
self.data_container,
column_info,
self.max_level,
self.range_hp
)
self.data_container = Player.set_element_container(
self.data_container,
init_column,
column_info,
self.max_level,
self.element_container
)
self.data_container = Player.set_stats(
self.data_container,
init_column, column_info,
self.max_level,
self.stats_container
)
elif not self.name_element:
column_info = np.concatenate((init_column, self.name_stats), axis=None)
self.data_container = pd.DataFrame(0, row_level[:], column_info[:])
self.data_container = Player.set_level_container(
self.data_container,
column_info,
self.max_level,
self.range_level
)
self.data_container = Player.set_hp_container(
self.data_container,
column_info,
self.max_level,
self.range_hp
)
self.data_container = Player.set_mp_container(
self.data_container,
column_info,
self.max_level,
self.range_mp
)
self.data_container = Player.set_stats(
self.data_container,
init_column,
column_info,
self.max_level,
self.stats_container
)
else:
column_info = np.concatenate((init_column, self.name_element, self.name_stats), axis=None)
self.data_container = pd.DataFrame(0, row_level[:], column_info[:])
self.data_container = Player.set_level_container(
self.data_container,
column_info,
self.max_level,
self.range_level
)
self.data_container = Player.set_hp_container(
self.data_container,
column_info,
self.max_level,
self.range_hp
)
self.data_container = Player.set_mp_container(
self.data_container,
column_info,
self.max_level,
self.range_mp
)
self.data_container = Player.set_element_container(
self.data_container,
init_column,
column_info,
self.max_level,
self.element_container
)
self.data_container = Player.set_stats(
self.data_container,
init_column,
column_info,
self.max_level,
self.stats_container
)
pd.set_option('display.max_rows', 200)
print('[RESULT] All Player Character Stats: \n')
print(self.data_container)
print('\n[DEBUG] Current TOTAL STATS: ', self.stats_container.sum(axis=0))
current_work_dir = os.path.dirname(os.path.abspath(__file__))
self.data_container.to_csv(current_work_dir + '/csv_output_result/PlayerStats.csv', index=True)