forked from vakdev/VakScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entities.py
201 lines (168 loc) · 9.18 KB
/
entities.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
#ext
from collections import namedtuple
from pyMeow import r_string, r_float, r_bool, r_int, r_ints64
from math import hypot
from functools import partial
#own
from data import Offsets
from world_to_screen import World
class ReadAttributes:
def __init__(self, process, base_address):
self.obj_name = Offsets.obj_name
self.obj_health = Offsets.obj_health
self.obj_max_health = Offsets.obj_max_health
self.obj_team = Offsets.obj_team
self.obj_gold = Offsets.obj_gold
self.obj_base_attack = Offsets.obj_base_attack
self.obj_bonus_attack = Offsets.obj_bonus_attack
self.obj_bonus_as = Offsets.obj_bonus_as
self.obj_magic_damage = Offsets.obj_magic_damage
self.obj_armor = Offsets.obj_armor
self.obj_attack_range = Offsets.obj_attack_range
self.obj_spawn_count = Offsets.obj_spawn_count
self.obj_targetable = Offsets.obj_targetable
self.obj_visible = Offsets.obj_visible
self.obj_x = Offsets.obj_x
self.obj_y = Offsets.obj_y
self.obj_z = Offsets.obj_z
self.obj_spell_book = Offsets.obj_spell_book
self.spell_level = Offsets.spell_level
self.spell_cooldown = Offsets.spell_cooldown
self.spells_keys = ['Q', 'W', 'E', 'R', 'D', 'F']
self.game_time = Offsets.game_time
self.process = process
self.base_address = base_address
self.PlayerNamedtuple = namedtuple('Player', 'name basic_attack bonus_attack x y z attack_range')
self.EnemyNamedtuple = namedtuple('Enemy', 'name health max_health gold armor basic_attack bonus_attack magic_damage x y z alive targetable visible attack_range pointer')
self.MinionNamedtuple = namedtuple('Minion', 'health armor x y z alive targetable visible')
self.TurretNamedTuple = namedtuple('Turret', 'attack_range x y z')
def read_player(self, local_player):
d, process = {}, self.process
d['name'] = r_string(process, local_player + self.obj_name)
d['basic_attack'] = r_float(process, local_player + self.obj_base_attack)
d['bonus_attack'] = r_float(process, local_player + self.obj_bonus_attack)
d['x'] = r_float(process, local_player + self.obj_x)
d['y'] = r_float(process, local_player + self.obj_y)
d['z'] = r_float(process, local_player + self.obj_z)
d['attack_range'] = r_float(process, local_player + self.obj_attack_range)
return self.PlayerNamedtuple(**d)
def read_enemy(self, pointer):
d, process = {}, self.process
d['name'] = r_string(process, pointer + self.obj_name)
d['health'] = r_float(process, pointer + self.obj_health)
d['max_health'] = r_float(process, pointer + self.obj_max_health)
d['gold'] = r_int(process, pointer + self.obj_gold)
d['armor'] = r_float(process, pointer + self.obj_armor)
d['basic_attack'] = r_float(process, pointer + self.obj_base_attack)
d['bonus_attack'] = r_float(process, pointer + self.obj_bonus_attack)
d['magic_damage'] = r_float(process, pointer + self.obj_magic_damage)
d['x'] = r_float(process, pointer + self.obj_x)
d['y'] = r_float(process, pointer + self.obj_y)
d['z'] = r_float(process, pointer + self.obj_z)
d['alive'] = r_int(process, pointer + self.obj_spawn_count) % 2 == 0
d['targetable'] = r_bool(process, pointer + self.obj_targetable)
d['visible'] = r_bool(process, pointer + self.obj_visible)
d['attack_range'] = r_float(process, pointer + self.obj_attack_range)
d['pointer'] = pointer
return self.EnemyNamedtuple(**d)
def read_minion(self, pointer):
d, process = {}, self.process
d['health'] = r_float(process, pointer + self.obj_health)
d['armor'] = r_float(process, pointer + self.obj_armor)
d['x'] = r_float(process, pointer + self.obj_x)
d['y'] = r_float(process, pointer + self.obj_y)
d['z'] = r_float(process, pointer + self.obj_z)
d['alive'] = r_int(process, pointer + self.obj_spawn_count) % 2 == 0
d['targetable'] = r_bool(process, pointer + self.obj_targetable)
d['visible'] = r_bool(process, pointer + self.obj_visible)
return self.MinionNamedtuple(**d)
def read_turret(self, pointer):
d, process = {}, self.process
d['attack_range'] = r_float(process, pointer + self.obj_attack_range)
d['x'] = r_float(process, pointer + self.obj_x)
d['y'] = r_float(process, pointer + self.obj_y)
d['z'] = r_float(process, pointer + self.obj_z)
return self.TurretNamedTuple(**d)
def read_spells(self, pointer):
spells, process = [], self.process
spell_book = r_ints64(process, pointer + self.obj_spell_book, 0x4)
for spell_slot in spell_book:
level = r_int(process, spell_slot + self.spell_level)
spells.append(level)
return spells
#Entity + EntityDrawings
def distance(player, target):
return hypot(player.x - target.x, player.y - target.y)
def get_effective_damage(damage, armor):
if armor >= 0:
return damage * 100. / (100. + armor)
return damage * (2. - (100. / (100. - armor)))
def get_min_attacks(player, target):
return target.health / get_effective_damage(player.basic_attack + player.bonus_attack, target.armor)
class Entity:
def __init__(self, stats):
self.stats = stats
self.radius = self.stats.get_targets_radius()
def in_distance(self, player, target):
return distance(player, target) - self.radius.get(target.name, 65.) <= player.attack_range + self.radius.get(player.name, 65.)
def in_distance_minion(self, player, target):
return distance(player, target) - 65.0 <= player.attack_range + self.radius.get(player.name, 65.)
def is_hurtable(self, target):
return target.alive and target.visible and target.targetable
def select_by_health(self, player, targets):
target, min_autos = None, None
for entity in targets:
if self.is_hurtable(entity) and self.in_distance(player, entity):
autos = get_min_attacks(player, entity)
if target is None or 0 < autos < min_autos:
target, min_autos = entity, autos
return target
def select_by_damage(self, player, targets):
target, max_damage = None, None
for entity in targets:
if self.is_hurtable(entity) and self.in_distance(player, entity):
damage = max(entity.basic_attack + entity.bonus_attack + entity.attack_range, entity.magic_damage)
if target is None or damage > max_damage:
target, max_damage = entity, damage
return target
def select_by_distance(self, player, targets):
target, min_distance = None, None
for entity in targets:
if self.is_hurtable(entity) and self.in_distance(player, entity):
d = distance(player, entity)
if target is None or d < min_distance:
target, min_distance = entity, d
return target
def select_lowest_minion(self, player, targets):
target, min_health = None, None
for entity in targets:
if self.is_hurtable(entity) and self.in_distance_minion(player, entity):
if target is None or entity.health < min_health:
target, min_health = entity, entity.health
return target
def select_lasthit_minion(self, player, targets):
for target in targets:
if self.is_hurtable(target) and target.health <= get_effective_damage(player.basic_attack + player.bonus_attack, target.armor) and self.in_distance_minion(player, target):
return target
class EntityDrawings:
def __init__(self, process, base_address, width, height):
self.world = World(process, base_address, width, height)
self.world_to_screen = self.world.world_to_screen_limited
self.get_view_proj_matrix = self.world.get_view_proj_matrix
def _has_pos(self, target):
return self.world_to_screen(self.get_view_proj_matrix(), target.x, target.z, target.y) and target.alive and target.targetable and target.visible
@staticmethod
def min_attacks(player, target):
return get_min_attacks(player, target)
@staticmethod
def max_damage(target):
return max(target.basic_attack + target.bonus_attack, target.magic_damage)
@staticmethod
def min_distance(player, target):
return distance(player, target)
def select_by_health(self, player, targets):
return min(filter(self._has_pos, targets), key=partial(EntityDrawings.min_attacks, player), default=None)
def select_by_damage(self, player, targets):
return max(filter(self._has_pos, targets), key=EntityDrawings.max_damage, default=None)
def select_by_distance(self, player, targets):
return min(filter(self._has_pos, targets), key=partial(EntityDrawings.min_distance, player), default=None)