Trying to get my head around a problem I have just solved...
What is skip_hooks actually doing? My understanding is that it ignores all pre/post hooks and calls the function like normal... however running some code I am still ending up in a server crash when using skip_hooks. Rather than this, I have replaced it to directly use call_trampoline and the problem is resolved.
I know this code is not ideal to debug as it is part of a plugin (but as the problem is solved) I wanted others' opinions on how this even resolves the crashes
For sanity's sake, any of the functions wrapper in
Code: Select all
@events
Code: Select all
@clientcommands
The crash occurs any time 2 people are attacking each other and they both have these callbacks registered.
TLDR: Why is call_trampoline working in the SpikedCarapace skill, and the commented skip_hooks line causes a server crash?
Syntax: Select all
## cryptlord declaration
class CryptLord(Race):
@classproperty
def description(cls):
return 'Recoded Crypt Lord. (Kryptonite)'
@classproperty
def max_level(cls):
return 99
@classproperty
def requirement_sort_key(cls):
return 8
@CryptLord.add_skill
class Impale(Skill):
@classproperty
def description(cls):
return 'Upon attacking, knock your enemy up and shake. 7-15% chance.'
@classproperty
def max_level(cls):
return 8
_msg_a = '{{PALE_GREEN}}You {{DULL_RED}}impaled {{RED}}{name}{{GREEN}}!'
@events('player_pre_attack')
def _on_player_pre_attack_impale(self, attacker, victim, **kwargs):
if randint(1, 100) <= 7 + self.level and not victim.dead:
victim.push(1, 200, True)
Shake(100, 1.5).send(victim.index)
send_wcs_saytext_by_index(self._msg_a.format(name=victim.name), attacker.index)
@CryptLord.add_skill
class SpikedCarapace(Skill):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.total_damage_prevented = 0
@classproperty
def description(cls):
return 'Reduces incoming damage by 5-20% and deal 3-7 reflected damage when being attacked.'
@classproperty
def max_level(cls):
return 8
@property
def reduction(self):
return min(5 + (2 * self.level), 20)
@property
def reflect_damage(self):
return 3 + (self.level / 2)
_msg_a = '{{GREEN}}Spiked Carapace {{PALE_GREEN}}prevented {{DULL_RED}}{damage} {{PALE_GREEN}}last round.'
@events('player_spawn')
def _on_player_spawn(self, player, **kwargs):
send_wcs_saytext_by_index(self._msg_a.format(damage=int(self.total_damage_prevented)), player.index)
self.total_damage_prevented = 0
@events('player_pre_victim')
def _on_player_pre_victim(self, attacker, victim, info, **kwargs):
multiplier = 1 - (self.reduction / 100)
old_damage = info.damage
info.damage *= multiplier
reduced_damage = old_damage - info.damage
self.total_damage_prevented += reduced_damage
@events('player_victim')
def _on_player_victim(self, attacker, victim, **kwargs):
if attacker.dead:
return
##attacker.take_damage(self.reflect_damage, attacker_index=victim.index, skip_hooks=True)
info = TakeDamageInfo()
info.inflictor = victim.index
info.damage = self.reflect_damage
attacker.on_take_damage.call_trampoline(info)
@CryptLord.add_skill
class ShadowStrike(Skill):
@classproperty
def description(cls):
return 'Grants you 7-15% chance to deal an additional 9-17 damage when attacking.'
@classproperty
def max_level(cls):
return 8
@property
def extra_damage(self):
return 9 + self.level
@property
def chance(self):
return 7 + self.level
_msg_a = '{{DARK_BLUE}}Shadow Strike {{PALE_GREEN}}dealt {{DULL_RED}}{damage} {{PALE_GREEN}}extra to {{RED}}{name}{{PALE_GREEN}}.'
@events('player_pre_attack')
def _on_player_pre_attack(self, attacker, victim, info, **kwargs):
if randint(0, 101) <= self.chance and not victim.dead:
info.damage += self.extra_damage
send_wcs_saytext_by_index(self._msg_a.format(damage=self.extra_damage, name=victim.name), attacker.index)