-
Notifications
You must be signed in to change notification settings - Fork 3
/
ship.py
754 lines (700 loc) · 50.8 KB
/
ship.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
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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# pylint: disable=line-too-long
import yaml
import copy
import math
PROPULSION_THRUST_BONUS = {}
PROPULSION_THRUST_BONUS["small"] = 1.35
PROPULSION_THRUST_BONUS["medium"] = 13.5
PROPULSION_THRUST_BONUS["large"] = 135
CAPACITOR_SIM_TIME = 60 * 60
CAPACITOR_SIM_RES_PER_SECOND = 10
class Ship():
def __init__(self, name, ship_data, profile_data):
self.profile_skills_data = profile_data.get_skills_data()
self.name = name
self.type = ship_data["type"]
self.faction = ship_data["faction"]
self.max_slots = ship_data["slots"]
self.max_rigs = ship_data["rigs"]
self.slots = {}
self.slots["high"] = [None] * self.max_slots["high"]
self.slots["high-base"] = [None] * self.max_slots["high"]
self.slots["mid"] = [None] * self.max_slots["mid"]
self.slots["drone"] = [None] * self.max_slots["drone"]
self.slots["drone-base"] = [None] * self.max_slots["drone"]
self.slots["drone_size"] = self.max_slots["drone_size"]
self.slots["low"] = [None] * self.max_slots["low"]
self.slots["combat"] = [None] * self.max_rigs["combat"]
self.slots["engineer"] = [None] * self.max_rigs["engineer"]
self.base_cargo = ship_data["cargo"]
self.base_targeting = ship_data["targeting"]
self.base_navigation = ship_data["navigation"]
self.base_navigation["propulsion_thrust_bonus"] = 0
self.base_defenses = ship_data["defenses"]
self.base_capacitor = ship_data["capacitor"]
self.base_capacitor["consumption"] = 0
self.base_capacitor["consumption_ext"] = [0] * CAPACITOR_SIM_TIME * CAPACITOR_SIM_RES_PER_SECOND
self.base_powergrid = ship_data["powergrid"]
with open("data/bonus_data.yaml", 'r') as stream:
try:
self.raw_bonus_data = yaml.safe_load(stream)
self.ship_bonus_data = copy.deepcopy(self.raw_bonus_data)
self.ship_role_data = copy.deepcopy(self.raw_bonus_data)
self.skills_bonus_data = copy.deepcopy(self.raw_bonus_data)
self.fittings_bonus_data = copy.deepcopy(self.raw_bonus_data)
self.rigs_bonus_data = copy.deepcopy(self.raw_bonus_data)
except yaml.YAMLError as exc:
print(exc)
self.get_skill_data()
ship_bonus = ship_data["bonus"]
if ship_bonus["role"] != 'none':
self.update_ship_bonus_data(ship_bonus["role"], is_role=True)
self.update_ship_bonus_data(ship_bonus["skills"]["first"])
self.update_ship_bonus_data(ship_bonus["skills"]["second"])
self.defenses = copy.deepcopy(self.base_defenses)
self.powergrid = copy.deepcopy(self.base_powergrid)
self.capacitor = copy.deepcopy(self.base_capacitor)
self.navigation = copy.deepcopy(self.base_navigation)
self.update_ship_stats()
def update_ship_bonus_data(self, current_bonus_type, is_role=False):
if current_bonus_type == 'none':
return
current_skill_level = 1
for bonus in current_bonus_type:
if bonus == "name":
try:
current_skill_level = self.profile_skills_data[current_bonus_type[bonus]]
except:
print("Skill", current_bonus_type[bonus], "not implemented yet")
continue
else:
slot_type = current_bonus_type[bonus]
for sub_slot_type in slot_type:
if sub_slot_type == "any":
for sub_slot_type in self.ship_bonus_data[bonus]:
for slot in slot_type["any"]:
if slot == "any":
for slot_size in self.ship_bonus_data[bonus][sub_slot_type]:
for slot_bonus in slot_type["any"]["any"]:
if slot_bonus in {"damage", "resists"}:
for damage_type in slot_type["any"]["any"][slot_bonus]:
if is_role:
self.ship_role_data[bonus][sub_slot_type][slot_size][slot_bonus][damage_type] += slot_type["any"]["any"][slot_bonus][damage_type]
else:
self.ship_bonus_data[bonus][sub_slot_type][slot_size][slot_bonus][damage_type] += slot_type["any"]["any"][slot_bonus][damage_type] * current_skill_level
else:
if is_role:
self.ship_role_data[bonus][sub_slot_type][slot_size][slot_bonus] += slot_type["any"]["any"][slot_bonus]
else:
self.ship_bonus_data[bonus][sub_slot_type][slot_size][slot_bonus] += slot_type["any"]["any"][slot_bonus] * current_skill_level
else:
for slot_bonus in slot_type["any"][slot]:
if slot_bonus in {"damage", "resists"}:
for damage_type in slot_type["any"][slot][slot_bonus]:
if is_role:
self.ship_role_data[bonus][sub_slot_type][slot][slot_bonus][damage_type] += slot_type["any"][slot][slot_bonus][damage_type]
else:
self.ship_bonus_data[bonus][sub_slot_type][slot][slot_bonus][damage_type] += slot_type["any"][slot][slot_bonus][damage_type] * current_skill_level
else:
if is_role:
self.ship_role_data[bonus][sub_slot_type][slot][slot_bonus] += slot_type["any"][slot][slot_bonus]
else:
self.ship_bonus_data[bonus][sub_slot_type][slot][slot_bonus] += slot_type["any"][slot][slot_bonus] * current_skill_level
else:
slot_size = slot_type[sub_slot_type]
for slot in slot_size:
if slot == "any":
for slot_size in self.ship_bonus_data[bonus][sub_slot_type]:
for slot_bonus in slot_type[sub_slot_type]["any"]:
if slot_bonus in {"damage", "resists"}:
for damage_type in slot_type[sub_slot_type]["any"][slot_bonus]:
if is_role:
self.ship_role_data[bonus][sub_slot_type][slot_size][slot_bonus][damage_type] += slot_type[sub_slot_type]["any"][slot_bonus][damage_type]
else:
self.ship_bonus_data[bonus][sub_slot_type][slot_size][slot_bonus][damage_type] += slot_type[sub_slot_type]["any"][slot_bonus][damage_type] * current_skill_level
elif slot_bonus == "ship":
continue
else:
if is_role:
self.ship_role_data[bonus][sub_slot_type][slot_size][slot_bonus] += slot_type[sub_slot_type]["any"][slot_bonus]
else:
self.ship_bonus_data[bonus][sub_slot_type][slot_size][slot_bonus] += slot_type[sub_slot_type]["any"][slot_bonus] * current_skill_level
else:
if not isinstance(slot_type[sub_slot_type][slot], dict):
if is_role:
self.ship_role_data[bonus][sub_slot_type][slot] += slot_type[sub_slot_type][slot]
else:
self.ship_bonus_data[bonus][sub_slot_type][slot] += slot_type[sub_slot_type][slot] * current_skill_level
continue
for slot_bonus in slot_type[sub_slot_type][slot]:
if slot_bonus in {"damage", "resists"}:
for damage_type in slot_type[sub_slot_type][slot][slot_bonus]:
if is_role:
self.ship_role_data[bonus][sub_slot_type][slot][slot_bonus][damage_type] += slot_type[sub_slot_type][slot][slot_bonus][damage_type]
else:
self.ship_bonus_data[bonus][sub_slot_type][slot][slot_bonus][damage_type] += slot_type[sub_slot_type][slot][slot_bonus][damage_type] * current_skill_level
elif slot_bonus == "value":
if is_role:
self.ship_role_data[bonus][sub_slot_type][slot][slot_bonus]["percent"] += slot_type[sub_slot_type][slot][slot_bonus]["percent"]
self.ship_role_data[bonus][sub_slot_type][slot][slot_bonus]["flat"] += slot_type[sub_slot_type][slot][slot_bonus]["flat"]
else:
self.ship_bonus_data[bonus][sub_slot_type][slot][slot_bonus]["percent"] += slot_type[sub_slot_type][slot][slot_bonus]["percent"] * current_skill_level
self.ship_bonus_data[bonus][sub_slot_type][slot][slot_bonus]["flat"] += slot_type[sub_slot_type][slot][slot_bonus]["flat"] * current_skill_level
else:
if is_role:
self.ship_role_data[bonus][sub_slot_type][slot][slot_bonus] += slot_type[sub_slot_type][slot][slot_bonus]
else:
self.ship_bonus_data[bonus][sub_slot_type][slot][slot_bonus] += slot_type[sub_slot_type][slot][slot_bonus] * current_skill_level
def is_slot_empty(self, slot):
slot_type, slot_number = slot.split("-")[1:]
current_slot = self.slots[slot_type][int(slot_number)]
return current_slot is None
def add_slot(self, slot, slot_data):
item_data = copy.deepcopy(slot_data)
slot_type, slot_number = slot.split("-")[1:]
current_slot = self.slots[slot_type][int(slot_number)]
if slot_type in {"high", "drone"}:
item_data_bonus = self.apply_bonus_to_high_slot_data(item_data)
else:
item_data_bonus = self.apply_bonus_to_bonus_slot_data(item_data)
data = list(item_data_bonus.values())[0]
slot_number = int(slot_number)
slot_added = False
num_full_slots = 0
slot_name = "powergrid"
num_max_slots = self.max_rigs[slot_type] if slot_type in {"combat", "engineer"} else self.max_slots[slot_type]
while current_slot:
num_full_slots += 1
if num_full_slots >= num_max_slots:
return False, "full"
slot_number += 1
if slot_number >= num_max_slots:
slot_number = 0
current_slot = self.slots[slot_type][int(slot_number)]
if (self.powergrid["used"] + data["powergrid"]) <= self.powergrid["value"]:
if slot_type == "high":
self.slots["high-base"][slot_number] = item_data
self.slots[slot_type][slot_number] = item_data_bonus
elif slot_type == "low":
self.slots[slot_type][slot_number] = item_data_bonus
elif slot_type == "drone":
self.slots["drone-base"][slot_number] = item_data
self.slots[slot_type][slot_number] = item_data_bonus
elif slot_type == "combat":
self.slots[slot_type][slot_number] = None
self.slots[slot_type][slot_number] = item_data_bonus
elif slot_type == "engineer":
self.slots[slot_type][slot_number] = None
self.slots[slot_type][slot_number] = item_data_bonus
else:
self.slots[slot_type][slot_number] = item_data_bonus
self.powergrid["used"] += data["powergrid"]
slot_added = True
self.fittings_bonus_data = copy.deepcopy(self.raw_bonus_data)
self.capacitor["consumption"] = 0
self.capacitor["consumption_ext"] = [0] * CAPACITOR_SIM_TIME * CAPACITOR_SIM_RES_PER_SECOND
for slot_type in ["low", "combat", "engineer"]:
self.update_fittings_bonus_data(slot_type)
self.update_slots_stats()
slot = slot.split("-")[0:-1]
slot.append(str(slot_number))
slot_name = ("-").join(slot)
return slot_added, slot_name
def remove_slot(self, slot):
slot_type, slot_number = slot.split("-")[1:]
current_slot = self.slots[slot_type][int(slot_number)]
slot_removed = False
if current_slot:
slot_powergrid = list(current_slot.values())[0]["powergrid"]
if slot_type == "high":
self.slots["high-base"][int(slot_number)] = None
self.slots[slot_type][int(slot_number)] = None
elif slot_type == "low":
self.slots[slot_type][int(slot_number)] = None
elif slot_type == "drone":
self.slots["drone-base"][int(slot_number)] = None
self.slots[slot_type][int(slot_number)] = None
elif slot_type == "combat":
self.slots[slot_type][int(slot_number)] = None
elif slot_type == "engineer":
self.slots[slot_type][int(slot_number)] = None
else:
self.slots[slot_type][int(slot_number)] = None
self.powergrid["used"] -= slot_powergrid
slot_removed = True
self.fittings_bonus_data = copy.deepcopy(self.raw_bonus_data)
self.capacitor["consumption"] = 0
self.capacitor["consumption_ext"] = [0] * CAPACITOR_SIM_TIME * CAPACITOR_SIM_RES_PER_SECOND
for slot_type in ["low", "combat", "engineer"]:
self.update_fittings_bonus_data(slot_type)
self.update_slots_stats()
return slot_removed
def apply_bonus_to_high_slot_data(self, item_data):
item_data_with_bonus = copy.deepcopy(item_data)
item_name = list(item_data_with_bonus.keys())[0]
item_info = item_name.split("_")
item_type, sub_item_type, item_size, *_ = item_info
stat_ship_bonus = self.ship_bonus_data[item_type][sub_item_type][item_size]
role_ship_bonus = self.ship_role_data[item_type][sub_item_type][item_size]
stat_skill_bonus = self.skills_bonus_data[item_type][sub_item_type][item_size]
for item_stat in stat_ship_bonus:
item_stat_data = item_data_with_bonus[item_name][item_stat]
if item_stat in {"damage", "resists"}:
for val in item_stat_data:
item_stat_data[val] = item_stat_data[val] * ((1 + stat_ship_bonus[item_stat][val] / 100) *
(1 + role_ship_bonus[item_stat][val] / 100) *
(1 + (stat_skill_bonus[item_stat][val] / 100) +
(self.fittings_bonus_data[item_type][sub_item_type][item_size][item_stat][val] / 100)))
if item_stat_data[val] >= 100:
item_stat_data[val] = round(item_stat_data[val])
elif item_stat == "activation_time":
item_data_with_bonus[item_name][item_stat] = item_data_with_bonus[item_name][item_stat] * ((1 - stat_ship_bonus[item_stat] / 100) *
(1 - stat_skill_bonus[item_stat] / 100) *
(1 - role_ship_bonus[item_stat] / 100) *
(1 - self.fittings_bonus_data[item_type][sub_item_type][item_size][item_stat] / 100))
elif item_stat == "control_range":
item_data_with_bonus[item_name][item_stat] += (stat_ship_bonus[item_stat] +
role_ship_bonus[item_stat] +
stat_skill_bonus[item_stat] +
self.fittings_bonus_data[item_type][sub_item_type][item_size][item_stat])
else:
item_data_with_bonus[item_name][item_stat] = item_data_with_bonus[item_name][item_stat] * ((1 + stat_ship_bonus[item_stat] / 100) *
(1 + role_ship_bonus[item_stat] / 100) *
(1 + stat_skill_bonus[item_stat] / 100))
return item_data_with_bonus
def apply_bonus_to_bonus_slot_data(self, item_data):
item_data_with_bonus = copy.deepcopy(item_data)
item_name = list(item_data_with_bonus.keys())[0]
item_info = item_name.split("_")
item_type, sub_item_type, item_size, *_ = item_info
stat_ship_bonus = self.ship_bonus_data[item_type][sub_item_type][item_size]
role_ship_bonus = self.ship_role_data[item_type][sub_item_type][item_size]
stat_skill_bonus = self.skills_bonus_data[item_type][sub_item_type][item_size]
ship_bonus = None
high_slot_bonus = None
high_slot_bonus_type = None
for item_stat in stat_ship_bonus:
item_stat_data = item_data_with_bonus[item_name][item_stat]
if item_stat == "ship":
for ship_bonus in item_stat_data:
if ship_bonus == "navigation":
stat_data = item_stat_data[ship_bonus]
for bonus in stat_data:
item_data_with_bonus[item_name][item_stat][ship_bonus][bonus] += (stat_ship_bonus[item_stat][ship_bonus][bonus] +
role_ship_bonus[item_stat][ship_bonus][bonus] +
stat_skill_bonus[item_stat][ship_bonus][bonus])
else:
print("Ship Bonus", ship_bonus, "not implemented yet!")
elif item_stat in {"launchers", "lasers", "railguns", "cannons", "turrets", "drones"}:
high_slot_bonus_type = ["lasers", "railguns", "cannons"] if item_stat == "turrets" else [item_stat]
high_slot_bonus = item_stat_data
elif item_stat == "activation_cost":
item_data_with_bonus[item_name][item_stat] = item_data_with_bonus[item_name][item_stat] * ((1 + -abs(stat_ship_bonus[item_stat])) *
(1 + -abs(role_ship_bonus[item_stat])) *
(1 + -abs(stat_skill_bonus[item_stat])))
if item_data_with_bonus[item_name][item_stat] >= 100:
item_data_with_bonus[item_name][item_stat] = round(item_data_with_bonus[item_name][item_stat])
elif item_stat == "activation_time":
added = False
if stat_skill_bonus[item_stat] >= 1:
item_data_with_bonus[item_name][item_stat] += stat_skill_bonus[item_stat]
added = True
if role_ship_bonus[item_stat] >= 1:
item_data_with_bonus[item_name][item_stat] += role_ship_bonus[item_stat]
added = True
if stat_ship_bonus[item_stat] >= 1:
item_data_with_bonus[item_name][item_stat] += stat_ship_bonus[item_stat]
added = True
if not added:
item_data_with_bonus[item_name][item_stat] = item_data_with_bonus[item_name][item_stat] * ((1 + stat_ship_bonus[item_stat]) *
(1 + role_ship_bonus[item_stat]) *
(1 + stat_skill_bonus[item_stat]))
if item_data_with_bonus[item_name][item_stat] >= 100:
item_data_with_bonus[item_name][item_stat] = round(item_data_with_bonus[item_name][item_stat])
else:
item_data_with_bonus[item_name][item_stat] = item_data_with_bonus[item_name][item_stat] * ((1 + stat_ship_bonus[item_stat] / 100) *
(1 + role_ship_bonus[item_stat] / 100) *
(1 + stat_skill_bonus[item_stat] / 100))
if item_data_with_bonus[item_name][item_stat] >= 100:
item_data_with_bonus[item_name][item_stat] = round(item_data_with_bonus[item_name][item_stat])
return item_data_with_bonus
def update_fittings_bonus_data(self, slot_type):
item_names = []
for slot_data in self.slots[slot_type]:
if not slot_data:
continue
item_data_with_bonus = copy.deepcopy(slot_data)
item_name = list(slot_data.keys())[0]
item_info = item_name.split("_")
item_type, sub_item_type, item_size, *_ = item_info
if item_type == "propulsion":
self.navigation["propulsion_thrust_bonus"] = PROPULSION_THRUST_BONUS[item_size]
num_same_items = 0
for same_item_name in item_names:
same_item_info = same_item_name.split("_")
same_item_type, same_sub_item_type, same_item_size, *_ = same_item_info
if item_type == same_item_type and sub_item_type == same_sub_item_type and item_size == same_item_size:
num_same_items += 1
item_names.append(item_name)
stat_ship_bonus = self.ship_bonus_data[item_type][sub_item_type][item_size]
for item_stat in stat_ship_bonus:
item_stat_data = item_data_with_bonus[item_name][item_stat]
if item_stat == "activation_cost":
act_cost = item_data_with_bonus[item_name]["activation_cost"]
act_time = item_data_with_bonus[item_name]["activation_time"]
self.add_capacitor_cost(act_cost, act_time)
if item_stat == "ship":
ship_bonus = item_stat_data
for stat_type in ship_bonus:
if stat_type == "defenses":
stat_data = ship_bonus[stat_type]
for stat_name in stat_data:
stat_bonus = stat_data[stat_name]
for bonus in stat_bonus:
if bonus == "value":
self.fittings_bonus_data["ship"][stat_type][stat_name]["value"]["percent"] += ship_bonus[stat_type][stat_name]["value"]["percent"]
self.fittings_bonus_data["ship"][stat_type][stat_name]["value"]["flat"] += ship_bonus[stat_type][stat_name]["value"]["flat"]
else:
for resist_type in stat_bonus["resists"]:
self.fittings_bonus_data["ship"][stat_type][stat_name]["resists"][resist_type] = (1 - ((1 - (self.fittings_bonus_data["ship"][stat_type][stat_name]["resists"][resist_type] / 100)) *
(1 - (self.get_stack_penalty(num_same_items) * ship_bonus[stat_type][stat_name]["resists"][resist_type] / 100)))) * 100
elif stat_type in {"capacitor", "powergrid"}:
stat_data = ship_bonus[stat_type]
for bonus in stat_data:
if bonus == "value":
self.fittings_bonus_data["ship"][stat_type]["value"]["percent"] += ship_bonus[stat_type]["value"]["percent"]
self.fittings_bonus_data["ship"][stat_type]["value"]["flat"] += ship_bonus[stat_type]["value"]["flat"]
elif bonus == "recharge":
self.fittings_bonus_data["ship"][stat_type]["recharge"] += ship_bonus[stat_type]["recharge"]
elif stat_type == "navigation":
stat_data = ship_bonus[stat_type]
for bonus in stat_data:
self.fittings_bonus_data["ship"][stat_type][bonus] += ship_bonus[stat_type][bonus]
else:
print("Stat", stat_type, "not yet implemented!")
elif item_stat in {"launchers", "lasers", "railguns", "cannons", "turrets", "drones"}:
high_slot_bonus_type = ["lasers", "railguns", "cannons"] if item_stat == "turrets" else [item_stat]
high_slot_bonus = item_stat_data
for high_slot_type in high_slot_bonus_type:
for sub_slot_type in self.ship_bonus_data[high_slot_type]:
for slot_size in self.ship_bonus_data[high_slot_type][sub_slot_type]:
for bonus in high_slot_bonus["any"]["any"]:
if bonus == "damage":
for damage_type in high_slot_bonus["any"]["any"]["damage"]:
self.fittings_bonus_data[high_slot_type][sub_slot_type][slot_size][bonus][damage_type] += self.get_stack_penalty(num_same_items) * high_slot_bonus["any"]["any"]["damage"][damage_type]
elif bonus == "activation_time":
self.fittings_bonus_data[high_slot_type][sub_slot_type][slot_size][bonus] = (1 - (1 - self.fittings_bonus_data[high_slot_type][sub_slot_type][slot_size][bonus] / 100) *
(1 + (self.get_stack_penalty(num_same_items) * high_slot_bonus["any"]["any"][bonus] / 100))) * 100
else:
self.fittings_bonus_data[high_slot_type][sub_slot_type][slot_size][bonus] += self.get_stack_penalty(num_same_items) * high_slot_bonus["any"]["any"][bonus]
return
def update_slots_stats(self):
for i in range(self.max_slots["high"]):
if self.slots["high-base"][i]:
self.slots["high"][i] = self.apply_bonus_to_high_slot_data(self.slots["high-base"][i])
for i in range(self.max_slots["drone"]):
if self.slots["drone-base"][i]:
self.slots["drone"][i] = self.apply_bonus_to_high_slot_data(self.slots["drone-base"][i])
return
def update_ship_stats(self):
self.update_powergrid()
self.update_capacitor()
self.update_defenses()
self.update_navigation()
def update_powergrid(self):
self.powergrid["value"] = round((self.base_powergrid["value"] +
self.skills_bonus_data["ship"]["powergrid"]["value"]["flat"] +
self.fittings_bonus_data["ship"]["powergrid"]["value"]["flat"]) *
(1 + self.ship_bonus_data["ship"]["powergrid"]["value"]["percent"] / 100) *
(1 + (self.skills_bonus_data["ship"]["powergrid"]["value"]["percent"] / 100) +
(self.fittings_bonus_data["ship"]["powergrid"]["value"]["percent"] / 100)))
self.powergrid["used"] = round(self.powergrid["used"])
def add_capacitor_cost(self, act_cost, act_time):
consumption = act_cost / act_time
self.capacitor["consumption"] += consumption
self.capacitor["consumption_ext"] = [self.capacitor["consumption_ext"][i] + act_cost * ((i % round(act_time * 10)) == 0) for i in range(len(self.capacitor["consumption_ext"]))]
def update_capacitor(self):
self.capacitor["value"] = round((self.base_capacitor["value"]) *
(1 + self.ship_bonus_data["ship"]["capacitor"]["value"]["percent"] / 100) *
(1 + (self.skills_bonus_data["ship"]["capacitor"]["value"]["percent"] / 100) +
(self.fittings_bonus_data["ship"]["capacitor"]["value"]["percent"] / 100)) +
(self.skills_bonus_data["ship"]["capacitor"]["value"]["flat"] +
self.fittings_bonus_data["ship"]["capacitor"]["value"]["flat"]), 0)
self.capacitor["recharge"] = round(self.base_capacitor["recharge"] *
(1 + self.ship_bonus_data["ship"]["capacitor"]["recharge"] / 100) *
(1 + (self.skills_bonus_data["ship"]["capacitor"]["recharge"] / 100) +
(self.fittings_bonus_data["ship"]["capacitor"]["recharge"] / 100)), 0)
self.capacitor["rate"] = self.get_capacitor_rate()
rate_percentage_list = []
for i in range(1001):
rate_percentage = round((10 * self.capacitor["value"] / self.capacitor["recharge"]) * (math.sqrt(i / 1000.0) - (i / 1000.0)), 2)
rate_percentage_list.append(rate_percentage)
"""
seconds = 0
percentage = 100
current_cap = self.capacitor["value"]
if self.capacitor["consumption"] > self.capacitor["rate"]:
percentage = 0
while current_cap >= self.capacitor["consumption"]:
current_cap += rate_percentage_list[round(1000 * (current_cap / self.capacitor["value"]))]
current_cap -= self.capacitor["consumption"]
seconds += 1
elif self.capacitor["consumption"] > 0:
while True:
current_cap -= self.capacitor["consumption"]
recharge = rate_percentage_list[round(1000 * (current_cap / self.capacitor["value"]))]
if recharge > self.capacitor["consumption"]:
break
current_cap += recharge
percentage = round(100 * (current_cap/self.capacitor["value"]))
self.capacitor["stability"] = seconds
self.capacitor["percentage"] = percentage
"""
current_cap = self.capacitor["value"]
max_consumption = max(self.capacitor["consumption_ext"])
for second, consumption in enumerate(self.capacitor["consumption_ext"]):
if second % CAPACITOR_SIM_RES_PER_SECOND == 0:
recover = rate_percentage_list[round(1000 * (current_cap / self.capacitor["value"]))]
else:
recover = 0
current_cap += recover
if current_cap > self.capacitor["value"]:
current_cap = self.capacitor["value"]
current_cap -= consumption
if current_cap <= max_consumption:
current_cap = 0
break
percentage = round(100 * (current_cap / self.capacitor["value"]))
self.capacitor["stability"] = round(second / CAPACITOR_SIM_RES_PER_SECOND)
self.capacitor["percentage"] = percentage
def update_defenses(self):
for defense in self.defenses:
self.defenses[defense]["value"] = round((self.base_defenses[defense]["value"]) *
(1 + self.ship_bonus_data["ship"]["defenses"][defense]["value"]["percent"] / 100) *
(1 + self.skills_bonus_data["ship"]["defenses"][defense]["value"]["percent"] / 100) *
(1 + self.fittings_bonus_data["ship"]["defenses"][defense]["value"]["percent"] / 100) +
(self.skills_bonus_data["ship"]["defenses"][defense]["value"]["flat"]) +
(self.fittings_bonus_data["ship"]["defenses"][defense]["value"]["flat"]), 0)
for res in self.defenses[defense]["resists"]:
self.defenses[defense]["resists"][res] = round(((1 - ((1 - self.base_defenses[defense]["resists"][res] / 100) *
(1 - self.ship_bonus_data["ship"]["defenses"][defense]["resists"][res] / 100) *
(1 - self.skills_bonus_data["ship"]["defenses"][defense]["resists"][res] / 100) *
(1 - self.fittings_bonus_data["ship"]["defenses"][defense]["resists"][res] / 100)))) * 100, 2)
def update_navigation(self):
self.navigation["mass"] = round(self.base_navigation["mass"] + self.fittings_bonus_data["ship"]["navigation"]["mass"], 0)
self.navigation["warp_speed"] = round(self.base_navigation["warp_speed"] * ((1 + self.fittings_bonus_data["ship"]["navigation"]["warp_speed"] / 100) *
(1 + self.skills_bonus_data["ship"]["navigation"]["warp_speed"] / 100) *
(1 + self.ship_role_data["ship"]["navigation"]["warp_speed"] / 100)), 1)
self.navigation["inertia_modifier"] = round(self.base_navigation["inertia_modifier"] * ((1 + self.fittings_bonus_data["ship"]["navigation"]["inertia_modifier"] / 100) *
(1 + self.skills_bonus_data["ship"]["navigation"]["inertia_modifier"] / 100)), 2)
self.navigation["flight_velocity"] = round(self.base_navigation["flight_velocity"] * ((1 + self.skills_bonus_data["ship"]["navigation"]["flight_velocity"] / 100) *
(1 + (self.navigation["propulsion_thrust_bonus"] / (self.navigation["mass"] / 1000000.0)) * self.fittings_bonus_data["ship"]["navigation"]["flight_velocity"] / 100)), 1)
def get_max_drone_size(self):
return self.slots["drone_size"]
def get_slot(self, slot):
slot_type, slot_number = slot.split("-")[1:]
return self.slots[slot_type][int(slot_number)]
def get_ehp(self):
self.update_defenses()
total_ehp = 0
for defense_type in self.defenses:
defense = self.defenses[defense_type]
min_resist = min(defense["resists"][val] for val in defense["resists"])
total_ehp += defense["value"] / (1 - min_resist / 100.0)
return int(total_ehp)
def get_capacitor_rate(self):
rate = (10 * self.capacitor["value"] / self.capacitor["recharge"]) * 0.25
return round(rate, 2)
def get_defenses(self):
self.update_defenses()
return self.defenses
def get_capacitor(self):
self.update_capacitor()
return self.capacitor
def get_powergrid(self):
self.update_powergrid()
return self.powergrid
def get_navigation(self):
self.update_navigation()
return self.navigation
def get_dps(self):
dps = {}
dps["launchers"] = 0
dps["turrets"] = 0
dps["drones"] = 0
control_range = 0
for slot in self.slots["high"]:
if slot:
slot_key = list(slot.keys())[0]
slot_info = slot_key.split("_")
slot_type, sub_slot_type, slot_size, *_ = slot_info
if slot_type == "launchers":
dps["launchers"] += self.get_launcher_dps(slot[slot_key])
else:
dps["turrets"] += self.get_turret_dps(slot[slot_key])
for slot in self.slots["drone"]:
if slot:
drone_dps, drone_control_range = self.get_drone_dps(slot)
dps["drones"] += drone_dps
control_range = drone_control_range
for dps_type in dps:
dps[dps_type] = round(dps[dps_type], 2)
total_dps = round(dps["launchers"] + dps["turrets"] + dps["drones"], 2)
return dps, total_dps, control_range
def get_launcher_dps(self, launcher_data):
total_damage = 0
launcher_damages = launcher_data["damage"]
for val in launcher_damages:
total_damage += launcher_damages[val]
total_damage /= launcher_data["activation_time"]
return total_damage
def get_turret_dps(self, turret_data):
total_damage = 0
turret_damages = turret_data["damage"]
for val in turret_damages:
total_damage += turret_damages[val]
total_damage /= turret_data["activation_time"]
return total_damage
def get_drone_dps(self, drone):
total_damage = 0
for dr in drone:
current_drone_stats = drone[dr]
drone_damages = current_drone_stats["damage"]
for val in drone_damages:
total_damage += drone_damages[val]
total_damage /= current_drone_stats["activation_time"]
control_range = current_drone_stats["control_range"]
return total_damage, control_range
def get_stack_penalty(self, num_items):
val = math.pow(math.e, -math.pow(num_items / 2.67, 2))
return val
def export_fit(self):
current_fit = {}
current_fit["ship"] = {}
current_fit["ship"]["faction"] = self.faction
current_fit["ship"]["type"] = self.type
current_fit["ship"]["name"] = self.name
current_fit["high"] = []
for slot in self.slots["high"]:
current_fit["high"].append(list(slot.keys())[0] if slot else None)
current_fit["mid"] = []
for slot in self.slots["mid"]:
current_fit["mid"].append(list(slot.keys())[0] if slot else None)
current_fit["low"] = []
for slot in self.slots["low"]:
current_fit["low"].append(list(slot.keys())[0] if slot else None)
current_fit["drone"] = []
for slot in self.slots["drone"]:
current_fit["drone"].append(list(slot.keys())[0] if slot else None)
current_fit["engineer"] = []
for slot in self.slots["engineer"]:
current_fit["engineer"].append(list(slot.keys())[0] if slot else None)
current_fit["combat"] = []
for slot in self.slots["combat"]:
current_fit["combat"].append(list(slot.keys())[0] if slot else None)
return current_fit
def get_skill_data(self):
with open("data/skills_data.yaml", 'r') as stream:
try:
skill_data = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
for skill_group_name in skill_data:
skill_group = skill_data[skill_group_name]
for skill_name in skill_group:
current_skill_level = self.profile_skills_data[skill_name]
if current_skill_level > 0:
skill = skill_group[skill_name][current_skill_level]
for skill_type in skill:
if skill_type == "ship":
if skill["ship"]["type"] == self.type:
skill_bonus = skill["ship"]["skill"]
for bonus_type in skill_bonus:
for bonus in skill_bonus[bonus_type]:
if bonus_type == "defenses":
self.skills_bonus_data["ship"][bonus_type][bonus]["value"]["percent"] += skill_bonus[bonus_type][bonus]["value"]["percent"]
self.skills_bonus_data["ship"][bonus_type][bonus]["value"]["flat"] += skill_bonus[bonus_type][bonus]["value"]["flat"]
elif bonus == "value":
self.skills_bonus_data["ship"][bonus_type][bonus]["percent"] += skill_bonus[bonus_type][bonus]["percent"]
self.skills_bonus_data["ship"][bonus_type][bonus]["flat"] += skill_bonus[bonus_type][bonus]["flat"]
else:
self.skills_bonus_data["ship"][bonus_type][bonus] += skill_bonus[bonus_type][bonus]
else:
slot_type = skill[skill_type]
for sub_slot_type in slot_type:
if sub_slot_type == "any":
for sub_slot_type in self.skills_bonus_data[skill_type]:
for slot in slot_type["any"]:
if slot == "any":
for slot_size in self.skills_bonus_data[skill_type][sub_slot_type]:
for slot_bonus in slot_type["any"]["any"]:
if slot_bonus in {"damage", "resists"}:
for damage_type in slot_type["any"]["any"][slot_bonus]:
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus][damage_type] += slot_type["any"]["any"][slot_bonus][damage_type]
elif slot_bonus == "value":
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus]["percent"] += slot_type["any"]["any"][slot_bonus]["percent"]
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus]["flat"] += slot_type["any"]["any"][slot_bonus]["flat"]
else:
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus] += slot_type["any"]["any"][slot_bonus]
elif slot in list(self.skills_bonus_data[skill_type][sub_slot_type].keys()):
for slot_bonus in slot_type["any"][slot]:
if slot_bonus in {"damage", "resists"}:
for damage_type in slot_type["any"][slot][slot_bonus]:
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus][damage_type] += slot_type["any"][slot][slot_bonus][damage_type]
elif slot_bonus == "value":
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus]["percent"] += slot_type["any"][slot][slot_bonus]["percent"]
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus]["flat"] += slot_type["any"][slot][slot_bonus]["flat"]
else:
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus] += slot_type["any"][slot][slot_bonus]
else:
slot_size = slot_type[sub_slot_type]
for slot in slot_size:
if slot == "any":
for slot_size in self.skills_bonus_data[skill_type][sub_slot_type]:
for slot_bonus in slot_type[sub_slot_type]["any"]:
if slot_bonus in {"damage", "resists"}:
for damage_type in slot_type[sub_slot_type]["any"][slot_bonus]:
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus][damage_type] += slot_type[sub_slot_type]["any"][slot_bonus][damage_type]
elif slot_bonus == "value":
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus]["percent"] += slot_type[sub_slot_type]["any"][slot_bonus]["percent"]
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus]["flat"] += slot_type[sub_slot_type]["any"][slot_bonus]["flat"]
elif slot_bonus == "activation_time":
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus] = ((1 + self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus]) * (1 + slot_type[sub_slot_type]["any"][slot_bonus] / 100)) - 1
elif slot_bonus == "activation_cost":
# self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus] = 1 - ((1 - self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus]) * (1 + slot_type[sub_slot_type]["any"][slot_bonus] / 100))
if sub_slot_type in {"boosters", "reparirers"}:
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus] += slot_type[sub_slot_type]["any"][slot_bonus] / 100
else:
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus] = 1 - ((1 - self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus]) * (1 + slot_type[sub_slot_type]["any"][slot_bonus] / 100))
elif slot_bonus == "ship":
for ship_bonus_type in slot_type[sub_slot_type]["any"]["ship"]:
ship_bonus_list = slot_type[sub_slot_type]["any"]["ship"][ship_bonus_type]
for ship_bonus in ship_bonus_list:
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus][ship_bonus_type][ship_bonus] += slot_type[sub_slot_type]["any"][slot_bonus][ship_bonus_type][ship_bonus]
else:
self.skills_bonus_data[skill_type][sub_slot_type][slot_size][slot_bonus] += slot_type[sub_slot_type]["any"][slot_bonus]
else:
for slot_bonus in slot_type[sub_slot_type][slot]:
if slot_bonus in {"damage", "resists"}:
for damage_type in slot_type[sub_slot_type][slot][slot_bonus]:
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus][damage_type] += slot_type[sub_slot_type][slot][slot_bonus][damage_type]
elif slot_bonus == "value":
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus]["percent"] += slot_type[sub_slot_type][slot][slot_bonus]["percent"]
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus]["flat"] += slot_type[sub_slot_type][slot][slot_bonus]["flat"]
elif slot_bonus == "activation_time":
if skill_type in {"weapons"}:
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus] += slot_type[sub_slot_type][slot][slot_bonus]
else:
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus] = ((1 + self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus]) * (1 + slot_type[sub_slot_type][slot][slot_bonus] / 100)) - 1
elif slot_bonus == "activation_cost":
if sub_slot_type in {"boosters", "repairers"}:
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus] += slot_type[sub_slot_type][slot][slot_bonus] / 100
else:
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus] = 1 - ((1 - self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus]) * (1 + slot_type[sub_slot_type][slot][slot_bonus] / 100))
elif slot_bonus == "ship":
for ship_bonus_type in slot_type[sub_slot_type][slot]["ship"]:
ship_bonus_list = slot_type[sub_slot_type][slot]["ship"][ship_bonus_type]
for ship_bonus in ship_bonus_list:
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus][ship_bonus_type][ship_bonus] += slot_type[sub_slot_type][slot][slot_bonus][ship_bonus_type][ship_bonus]
else:
self.skills_bonus_data[skill_type][sub_slot_type][slot][slot_bonus] += slot_type[sub_slot_type][slot][slot_bonus]