pankration.py
19.9 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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
import random
import time
import pickle
import math
FIND_PERCENTAGE = 100
SKILL_PERCENT = 80
class HuntResponse:
ERROR = -1
FAILURE = 0
SUCCESS = 1
def __init__(self, result, message, monster):
self.result = result
self.message = message
self.monster = monster
exp_to_level = [0, 500, 1250, 2250, 3500, 5000, 6750, 8750, 10950, 13350, 15950, 18750, 21750, 24950, 28350, 31950, 35750, 39750, 43950, 48350, 52950, 57750, 62750, 67850, 73050, 78350, 83750, 89250, 94850, 100550, 106350, 112250, 118250, 124350, 130550, 136850, 143250, 149750, 156350, 163050, 169850, 176750, 183750, 190850, 198050, 205350, 212750, 220250, 227850, 235550, 243350]
exp_table = {
15: 600,
14: 600,
13: 600,
12: 600,
11: 600,
10: 600,
9: 600,
8: 600,
7: 550,
6: 450,
5: 350,
4: 300,
3: 240,
2: 220,
1: 210,
0: 200,
-1: 180,
-2: 160,
-3: 150,
-4: 140,
-5: 130,
-6: 120,
-7: 110,
-8: 100,
-9: 80,
-10: 60,
-11: 40,
-12: 40,
-13: 40,
-14: 40,
-15: 40,
}
class Jobs:
WAR = 1
MNK = 2
BLM = 3
WHM = 4
THF = 5
RDM = 6
PLD = 7
DRK = 8
BST = 9
BRD = 10
RNG = 11
SAM = 12
NIN = 13
DRG = 14
SMN = 15
BLU = 16
COR = 17
PUP = 18
DNC = 19
SCH = 20
GEO = 21
RUN = 22
TemperamentPosture = {
4: {"name": "Very Agressive", "message": "Show no mercy!", "value": 4},
3: {"name": "Somewhat Agressive", "message": "Give em' a little more bite!", "value": 3},
2: {"name": "Somewhat Defensive", "message": "Back off a bit!", "value": 2},
1: {"name": "Very Defensive", "message": "Guard! Block! Parry! Hold!", "value": 1}
}
TemperamentAttitude = {
4: {"name": "Very Wild", "message": "Don't think, kill!", "value": 4},
3: {"name": "Somewhat Wild", "message": "Less thinking, more striking!", "value": 3},
2: {"name": "Somewhat Tame", "message": "Watch your opponent, then attack!", "value": 2},
1: {"name": "Very Tame", "message": "Think, and think again!", "value": 1}
}
PhysicalDamageTypes = {
'blunt': ['Hand-to-Hand', 'Club', 'Staff', 'Harlequin Frame', 'Stormwaker Frame', 'Sharpshot Frame'],
'slashing': ['Axe', 'Great Axe', 'Great Sword', 'Sword', 'Scythe', 'Katana', 'Great Katana', 'Valoredge Frame'],
'piercing': ['Dagger', 'Polearm', 'Archery', 'Marksmanship', 'Shuriken', 'Boomerang']
}
FeralSkills = {
'Airy Shield': {'fp_cost': 0, 'type': 'Enhancing', 'sub_type': 'arrow shield', 'shadows': 'ignore', 'range': None, 'aoe': False, 'spell': 'arrow shield'},
'Binding Wave': {'type': 'Enfeebling', 'shadows': 'ignore', 'range': 15, 'aoe': True, 'spell': 'bind'},
'Dire Straight': {'type': 'Physical', 'shadows': 'wipe', 'range': None, 'aoe': False},
'Dismemberment': {'type': 'Piercing', 'shadows': 'absorb', 'range': None, 'aoe': False}, # causes the monster to lose a body part
'Earthshatter': {'type': 'Piercing', 'shadows': 'wipe', 'range': None, 'aoe': True},
'Eyes On Me': {'type': 'Magical', 'sub_type': 'Dark', 'mp_cost': 112, 'shadows': 'absorb', 'range': 13, 'aoe': False},
'Hypnosis': {'type': 'Enfeebling', 'sub_type': 'sleep', 'shadows': 'ignore', 'range': 'gaze', 'aoe': True},
'Magic Barrier': {'type': 'Magical', 'sub_type': 'Dark', 'mp_cost': 29, 'shadows': 'absorb', 'range': None, 'aoe': True},
'Sinker Drill': {'type': 'Physical', 'sub_type': 'Piercing', 'shadows': 'absorb', 'range': None, 'aoe': False},
}
Families = {
'acrolith': {
'base_fp': 50,
'fp_per_level': 0.1,
'max_fp': 55,
'available_main_job': [Jobs.WAR, Jobs.DRG, Jobs.DRK, Jobs.PLD],
'available_support_job': [Jobs.WAR, Jobs.DRG, Jobs.DRK, Jobs.PLD],
'innate_feral_skills': ['Sinker Drill', 'Dire Straight', 'Dismemberment', 'Earthshatter'],
'type': 'Arcana',
'strong_vs': ['Dark'],
'charmable': False,
'aspir': False,
'drain': False,
'base_vit': 10,
'vit_per_level': 0.9334,
'base_str': 9,
'str_per_level': 0.8934,
'base_agi': 7,
'agi_per_level': 0.76,
'temperament_attitude': {
'initial_value': 4,
'actions': {
4: {'use_tp_chance': 100, 'ws': ['Sinker Drill'], 'side_attack_chance': 0, 'range_chance': 0},
3: {'use_tp_chance': 75, 'ws': ['Eyes On Me'], 'side_attack_chance': 70, 'range_chance': 10},
2: {'use_tp_chance': 50, 'ws': ['Binding Wave', 'Hypnosis'], 'side_attack_chance': 25, 'range_chance': 70},
1: {'use_tp_chance': 70, 'ws': ['Binding Wave', 'Hypnosis', 'Magic Barrier', 'Airy Shield'], 'side_attack_chance': 25, 'range_chance': 70}
}
},
'temperament_posture': {
'initial_value': 4,
'actions': {
4: {'use_tp_chance': 100, 'ws': ['Eyes On Me'], 'side_attack_chance': 0, 'range_chance': 0},
3: {'use_tp_chance': 75, 'ws': ['Eyes On Me'], 'side_attack_chance': 70, 'range_chance': 10},
2: {'use_tp_chance': 50, 'ws': ['Binding Wave', 'Hypnosis'], 'side_attack_chance': 25, 'range_chance': 70},
1: {'use_tp_chance': 70, 'ws': ['Magic Barrier', 'Airy Shield'], 'side_attack_chance': 25, 'range_chance': 100}
}
}
},
'ahriman': {
'base_fp': 65,
'fp_per_level': 0.3,
'max_fp': 80,
'available_main_job': [Jobs.BLM, Jobs.RDM, Jobs.WAR],
'available_support_job': [Jobs.BLM, Jobs.RDM, Jobs.WAR],
'innate_feral_skills': ['Binding Wave', 'Magic Barrier', 'Hypnosis', 'Eyes On Me', 'Airy Shield'],
'type': 'Demon',
'traits': ['magic defence bonus +25%'],
'charmable': False,
'aspir': True,
'drain': True,
'base_vit': 8,
'vit_per_level': 0.8,
'base_str': 8,
'str_per_level': 0.8534,
'base_agi': 9,
'agi_per_level': 0.88,
'temperament_attitude': {
'initial_value': 4,
'actions': {
4: {'use_tp_chance': 100, 'ws': ['Eyes On Me'], 'side_attack_chance': 0, 'range_chance': 0},
3: {'use_tp_chance': 75, 'ws': ['Eyes On Me'], 'side_attack_chance': 70, 'range_chance': 10},
2: {'use_tp_chance': 50, 'ws': ['Binding Wave', 'Hypnosis'], 'side_attack_chance': 25, 'range_chance': 70},
1: {'use_tp_chance': 70, 'ws': ['Binding Wave', 'Hypnosis', 'Magic Barrier', 'Airy Shield'], 'side_attack_chance': 25, 'range_chance': 70}
}
},
'temperament_posture': {
'initial_value': 4,
'actions': {
4: {'use_tp_chance': 100, 'ws': ['Eyes On Me'], 'side_attack_chance': 0, 'range_chance': 0},
3: {'use_tp_chance': 75, 'ws': ['Eyes On Me'], 'side_attack_chance': 70, 'range_chance': 10},
2: {'use_tp_chance': 50, 'ws': ['Binding Wave', 'Hypnosis'], 'side_attack_chance': 25, 'range_chance': 70},
1: {'use_tp_chance': 70, 'ws': ['Magic Barrier', 'Airy Shield'], 'side_attack_chance': 25, 'range_chance': 100}
}
}
}
}
Monsters = {
'Mechanical Menace': {
'initial_level': 9,
'family': 'acrolith',
'zone': 'Abyssea - Uleguerand',
'hp': 1000,
'weapon_base_damage': 40
},
'Floating Eye': {
'initial_level': 3,
'family': 'ahriman',
'zone': 'Ranguemont Pass',
'hp': 1000,
'weapon_base_damage': 120
}
}
class Pankration:
def __init__(self):
pass
def start_battle(self, monster1, monster2, battle_type):
battle = Arena(monster1, monster2, battle_type)
battle.start()
return battle
def list_zones(self):
zone_list = []
for monster in Monsters.itervalues():
if monster['zone'] not in zone_list:
zone_list.append(monster['zone'])
return zone_list
def get_monsters(self, zone):
monster_list = []
for monster_name, monster in Monsters.iteritems():
if monster['zone'] == zone:
monster_list.append(monster_name)
return monster_list
def hunt_monster(self, zone):
if random.randint(1, 100) < FIND_PERCENTAGE:
monster_name = random.choice(self.get_monsters(zone))
monster_data = Monsters[monster_name]
hp = monster_data['hp']
weapon_base_damage = monster_data['weapon_base_damage']
print("Monster: {} Data: {}".format(monster_name, monster_data))
family_name = monster_data['family']
level = monster_data['initial_level']
family = Families[family_name]
main_job = random.choice(family['available_main_job'])
support_job = random.choice(family['available_support_job'])
feral_skills = []
skills = random.sample(family['innate_feral_skills'], 3)
if random.randint(1, 100) < SKILL_PERCENT:
feral_skills.append(skills[0])
if random.randint(1, 100) < SKILL_PERCENT:
feral_skills.append(skills[1])
if random.randint(1, 100) < SKILL_PERCENT:
feral_skills.append(skills[2])
dicipline_level = 1
monster = Monster(monster_name, family, hp, level, weapon_base_damage, main_job, support_job, feral_skills,
[], dicipline_level)
return HuntResponse(HuntResponse.SUCCESS, "You captured the monster!",
monster)
else:
return HuntResponse(HuntResponse.FAILURE, "You were unable to capture a monster's soul.",
None)
def get_action():
return ""
class Monster:
def __init__(self, monster_type, family, hp, level, weapon_base_damage, main_job, support_job, innate_feral_skills,
equipped_feral_skills, dicipline_level):
self.monster_type = monster_type
self.family = family
self.max_hp = hp
self.hp = hp
self.level = level
self.main_job = main_job
self.support_job = support_job
self.innate_feral_skills = innate_feral_skills
self.equipped_feral_skills = equipped_feral_skills
self.discipline_level = dicipline_level
self.temperament_posture = family['temperament_posture']['initial_value']
self.temperament_attitude = family['temperament_attitude']['initial_value']
self.pre_fight_command = {"temperament_posture": None, "temperament_attitude": None}
self.exp = exp_to_level[level] + 1
# TODO: Setup something more interesting for each monster.
self.weapon_base_damage = weapon_base_damage
self.ammo_damage = 0
self.base_vit = family['base_vit']
self.vit_per_level = family['vit_per_level']
self.base_str = family['base_str']
self.str_per_level = family['str_per_level']
self.base_agi = family['base_agi']
self.agi_per_level = family['agi_per_level']
def __str__(self):
return "Family: {}\nLevel: {}\nMain Job: {}\nSupport Job: {}\nInnate Feral Skills: {}\nEquipped Feral Skills: {}\nDicipline Level: {}\nTemperament...".format(self.family, self.level, self.main_job, self.support_job, self.innate_feral_skills, self.equipped_feral_skills, self.discipline_level)
def get_fp(self):
return int(self.level / self.family['fp_per_level'])
def add_xp(self, exp_to_add):
self.exp += exp_to_add
for i in range(self.level, 51):
if self.exp > exp_to_level[i]:
if i > self.level:
# We leveled up!
self.level = i
#print("Start level: {} New Level: {}".format(self.level, i))
else:
pass#print("Just another brick in the wall...")
else:
break
# calc level based on xp
# stop at 50
pass
def get_current_posture(self):
return TemperamentPosture(self.temperament_posture)
def get_current_attitude(self):
return TemperamentAttitude(self.temperament_attitude)
def get_dicipline_level(self):
if self.dicipline_level < 2:
return "Defiant"
elif self.dicipline_level < 5:
return "Disrespectful"
elif self.dicipline_level < 7:
return "Disobedient"
else:
return "Obedient"
def get_vitality(self):
return 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)))
def get_agility(self):
return int(round(max(self.base_agi, self.level * self.agi_per_level)))
def get_base_defense(self):
return (math.floor(self.get_vitality()/2) + 8 + self.level)
def get_hp_percent(self):
return max(0, int(round((self.hp/self.max_hp)*100)))
# Calculate the base damage against the provided defense
# attack_type can be 'ranged' or 'melee'
def get_physical_base_damage(self, defense, attack_type, level_difference):
#print("Defense: {} Type: {} Level diff: {}".format(defense, attack_type, level_difference))
# Calculate the attack/defense ratio
bd = float(self.weapon_base_damage)
if attack_type == 'ranged':
bd += self.ammo_damage
# NOTE: We are not using fStr1 or fStr2 since we are not keeping str / vit as data
if defense == 0:
ratio = 99
else:
ratio = bd / float(defense)
if attack_type == 'ranged':
cap = 3.0
else:
cap = 2.25
if ratio > cap:
ratio = cap
# Get the level correction ratio
if attack_type == 'ranged':
cRatio = ratio - 0.025 * level_difference
else:
cRatio = ratio - 0.050 * level_difference
if cRatio < 0:
cRatio = 0
if attack_type == 'ranged':
if cRatio > 3.0:
cRatio = 3.0
else:
if cRatio > 2.25:
cRatio = 2.25
# Calculate the pDif max as the max of our RNG
if cRatio <= 0.5:
pDif_max = 1+(10/9)*(cRatio-0.5)
elif 0.5 <= cRatio <= float(3/4):
pDif_max = 1
elif float(3/4) <= cRatio <= cap:
pDif_max = 1+(10/9)*(cRatio-float(3/4))
# Calculate the pDif max as the max of our RNG
if cRatio <= 0.5:
pDif_min = 1/6
elif 0.5 <= cRatio <= 1.25:
pDif_min = 1+(10/9)*(cRatio-1.25)
elif 1.25 <= cRatio <= 1.5:
pDif_min = 1
elif 1.5 <= cRatio <= cap:
pDif_min = 1+(10/9)*(cRatio-1.5)
# Some fuckery since python doesn't let you do a rand between decimals
pDif_rand = float(random.randint(int(pDif_min*100000), int(pDif_max*100000))) / 100000.0
final_damage = bd * (pDif_rand * cRatio)
return final_damage
def attack(self, monster):
phy_damage = self.get_physical_base_damage(monster.get_base_defense(), 'melee', monster.level - self.level)
return (phy_damage, 'hits')
def apply_damage(self, damage):
self.hp -= damage
# Check life and return 'awesome', 'fucked up', 'dead' or something
# This should ONLY be executed at the start of battle.
def set_strategy(self, temperament_posture, temperament_attitude):
distance_from_nature = abs(self.temperament_posture - temperament_posture)
distance_from_nature += abs(self.temperament_attitude - temperament_attitude)
if distance_from_nature == 0:
chance_of_listening = self.discipline_level
else:
chance_of_listening = float(float(self.discipline_level) / (float(distance_from_nature)/10))
chance_of_listening = abs(float((float(chance_of_listening)-1)/(20-1)))
if random.randint(1, 100) > chance_of_listening * 100:
print("DO ACTION:")
# adjust dicipline_level
# move temperament
else:
#continue action
#if severe request then reduce dicipline_level
pass
class Action:
def __init__(self, monster):
self.monster = monster
class AttackAction(Action):
def __init__(self, attacker, target, damage, message):
self.attacker = attacker
self.target = target
self.damage = damage
self.message = message
class DefeatAction(Action):
def __init__(self, attacker, target, message, xp):
self.attacker = attacker
self.target = target
self.message = message
self.xp = xp
class Arena:
def __init__(self, monster1, monster2, battle_type):
self.monster1 = monster1
self.monster2 = monster2
self.battle_type = battle_type
def heal_monsters(self):
pass
def start(self):
self.heal_monsters()
self.m1_init = self.monster1.get_agility() + random.randint(1, 20)
self.m2_init = self.monster2.get_agility() + random.randint(1, 20)
def step(self):
actions = []
if self.m1_init > self.m2_init:
primary = self.monster1
secondary = self.monster2
else:
primary = self.monster2
secondary = self.monster1
result1 = primary.attack(secondary)
secondary.apply_damage(result1[0])
actions.append(AttackAction(primary, secondary, result1[0], result1[1]))
if secondary.hp <= 0:
xp = 200 + (20 * (primary.level - secondary.level))
actions.append(DefeatAction(secondary, primary, 'was defeated', xp))
return actions
result2 = secondary.attack(primary)
primary.apply_damage(result2[0])
actions.append(AttackAction(secondary, primary, result2[0], result2[1]))
if primary.hp <= 0:
xp = 200 + (20 * (secondary.level - primary.level))
actions.append(DefeatAction(primary, secondary, 'was defeated', xp))
return actions
return actions
#print Families
p = Pankration()
print("Zones: \n\n{}".format('\n'.join(p.list_zones())))
hunt_zone = p.list_zones()[0]
print("Hunting for monster in zone: {}\n".format(hunt_zone))
hunt_response = p.hunt_monster(hunt_zone)
print("hunt_response")
print(str(hunt_response.result))
time.sleep(0.5)
if hunt_response.result == HuntResponse.SUCCESS:
print(hunt_response.message)
monster = hunt_response.monster
# print("The Soul Plate Shows: \n\n{}".format(monster))
# print(monster.set_strategy(4, 3))
# print(monster.set_strategy(1, 1))
# print(monster.set_strategy(1, 2))
#monster.add_xp(22900)
# phy_damage = monster.get_physical_base_damage(100, 'melee', -15)
# print("Phys Attack: {}".format(phy_damage))
# print(monster.get_base_defense())
# monster.add_xp(22900)
# print(monster.get_base_defense())
# monster.add_xp(222900)
# print(monster.get_base_defense())
else:
print(hunt_response.message)
hunt_zone = p.list_zones()[1]
hunt_response = p.hunt_monster(hunt_zone)
if hunt_response.result == HuntResponse.SUCCESS:
monster2 = hunt_response.monster
monster2.add_xp(16900)
phy_damage = monster2.attack(monster)
print("Phys Attack: {}".format(phy_damage))
battle_arena = p.start_battle(monster, monster2, "derp")
fighting = True
while fighting:
actions = battle_arena.step()
time.sleep(2)
for action in actions:
if isinstance(action, AttackAction):
print("{} {} {} for {}.".format(action.attacker.monster_type, action.message, action.target.monster_type, action.damage))
if isinstance(action, DefeatAction):
print("{} {}. {} gains {} xp.".format(action.target.monster_type, action.message, action.attacker.monster_type, action.xp))
fighting = False
break
print("\n{} {}% - {} {}%\n".format(monster.monster_type, monster.get_hp_percent(), monster2.monster_type, monster2.get_hp_percent()))