@@ -244,4 +244,64 @@ def perform(self) -> None:
244244 if self .entity .equipment .item_is_equipped (self .item ):
245245 self .entity .equipment .toggle_equip (self .item )
246246
247- self .entity .inventory .drop (self .item )
247+ self .entity .inventory .drop (self .item )
248+
249+ class PounceAction (Action ):
250+ def __init__ (self , entity : Actor , x : int , y : int , effect :StatusEffect ):
251+ super ().__init__ (entity )
252+
253+ self .x = x
254+ self .y = y
255+ self .effect = effect
256+
257+ def perform (self ) -> None :
258+ self .entity .move (self .x - self .entity .x , self .y - self .entity .y )
259+
260+ target = None
261+ for entity in self .engine .game_map .actors :
262+ if entity .x == self .x and entity .y == self .y :
263+ target = entity
264+ break
265+ if not target :
266+ self .engine .message_log .add_message (f"{ self .entity .name } pounces, but misses the target." )
267+ else :
268+ damage = (self .entity .fighter .power ** 2 ) - target .fighter .defense # Deal 2x the power of the attacker's power
269+
270+ # If the attacker is the player and godmode is on, then the attacker will do max damage
271+ if self .entity is self .engine .player and self .engine .game_world .godmode :
272+ damage = 99999999
273+
274+ attack_desc = f"{ self .entity .name .capitalize ()} pounces and attacks { target .name .capitalize ()} "
275+ if self .entity is self .engine .player :
276+ attack_color = color .player_atk
277+ else :
278+ attack_color = color .enemy_atk
279+ if damage > 0 :
280+
281+ # if the target is the player and godmode is on, then the target will take no damage
282+ if target is self .engine .player and self .engine .game_world .godmode :
283+ return
284+
285+ self .engine .message_log .add_message (
286+ f"{ attack_desc } for { damage } hit points!" ,
287+ attack_color
288+ )
289+ target .fighter .hp -= damage
290+ target .fighter .last_actor_hurt_by = self .entity .internal_name
291+
292+ # trigger any on_attack of the equipment of the attacker, if any.
293+ if self .entity .equipment and self .entity .equipment .weapon :
294+ self .entity .equipment .weapon .equippable .on_attack (target )
295+
296+ # trigger any on_hit of the equipment of the target, if any.
297+ if target .equipment and target .equipment .armor :
298+ target .equipment .armor .equippable .on_hit (self .entity , damage )
299+
300+ # Apply the status effect to the target, if any.
301+ if self .effect is not None :
302+ target .fighter .apply_status_effect (self .effect )
303+ else :
304+ self .engine .message_log .add_message (
305+ f"{ attack_desc } , but does no damage." ,
306+ attack_color
307+ )
0 commit comments