@@ -1270,7 +1270,11 @@ def do_socialize_cmd(self, parsed: ParseResult) -> None:
12701270 if attacking :
12711271 for thing in who :
12721272 if isinstance (thing , Living ):
1273- pending_actions .send (lambda victim = thing : self .start_attack (victim ))
1273+ body_part = None
1274+ if len (parsed .args ) == 2 :
1275+ arg = parsed .args [1 ].upper ()
1276+ body_part = arg if arg in wearable .WearLocation .__members__ else None
1277+ pending_actions .send (lambda victim = thing : self .start_attack (victim , target_body_part = body_part ))
12741278 elif parsed .verb in verbdefs .AGGRESSIVE_VERBS :
12751279 # usually monsters immediately attack,
12761280 # other npcs may choose to attack or to ignore it
@@ -1415,11 +1419,11 @@ def locate_item(self, name: str, include_inventory: bool=True, include_location:
14151419 break
14161420 return (found , containing_object ) if found else (None , None )
14171421
1418- def start_attack (self , victim : 'Living' ) -> combat .Combat :
1422+ def start_attack (self , defender : 'Living' , target_body_part : wearable . WearLocation = None ) -> combat .Combat :
14191423 """Starts attacking the given living for one round."""
14201424 attacker_name = lang .capital (self .title )
1421- victim_name = lang .capital (victim .title )
1422- c = combat .Combat (self , victim )
1425+ victim_name = lang .capital (defender .title )
1426+ c = combat .Combat (self , defender , target_body_part = target_body_part )
14231427 result , damage_to_attacker , damage_to_defender = c .resolve_attack ()
14241428
14251429 room_msg = "%s attacks %s! %s" % (attacker_name , victim_name , result )
@@ -1428,30 +1432,30 @@ def start_attack(self, victim: 'Living') -> combat.Combat:
14281432 #victim.tell(victim_msg, evoke=True, short_len=False)
14291433
14301434 combat_prompt , attacker_msg = mud_context .driver .prepare_combat_prompt (attacker = self ,
1431- defender = victim ,
1435+ defender = defender ,
14321436 location_title = self .location .title ,
14331437 combat_result = result ,
14341438 attacker_msg = attacker_msg )
14351439
14361440 combat_context = CombatContext (attacker_name = self .name ,
14371441 attacker_health = self .stats .hp / self .stats .max_hp ,
14381442 attacker_weapon = self .wielding .name ,
1439- defender_name = victim .name ,
1440- defender_health = victim .stats .hp / victim .stats .max_hp ,
1441- defender_weapon = victim .wielding .name ,
1443+ defender_name = defender .name ,
1444+ defender_health = defender .stats .hp / defender .stats .max_hp ,
1445+ defender_weapon = defender .wielding .name ,
14421446 location_description = self .location .description )
14431447
1444- victim .location .tell (room_msg ,
1448+ defender .location .tell (room_msg ,
14451449 evoke = True ,
14461450 short_len = False ,
14471451 alt_prompt = combat_prompt ,
14481452 extra_context = combat_context .to_prompt_string ())
14491453 self .stats .hp -= damage_to_attacker
1450- victim .stats .hp -= damage_to_defender
1454+ defender .stats .hp -= damage_to_defender
14511455 if self .stats .hp < 1 :
1452- self . do_on_death ( util . Context )
1453- if victim .stats .hp < 1 :
1454- victim . do_on_death ( util . Context )
1456+ mud_context . driver . defer ( 0.1 , self . do_on_death )
1457+ if defender .stats .hp < 1 :
1458+ mud_context . driver . defer ( 0.1 , defender . do_on_death )
14551459 return c
14561460
14571461 def allow_give_money (self , amount : float , actor : Optional ['Living' ]) -> None :
@@ -1585,7 +1589,7 @@ def get_worn_items(self) -> Iterable[Wearable]:
15851589 """Return all items that are currently worn."""
15861590 return self .__wearing .values ()
15871591
1588- def do_on_death (self , ctx : util . Context ) -> 'Container' :
1592+ def do_on_death (self ) -> 'Container' :
15891593 """Called when the living dies."""
15901594 remains = None
15911595 self .alive = False
@@ -1595,7 +1599,7 @@ def do_on_death(self, ctx: util.Context) -> 'Container':
15951599 self .location .insert (remains , None )
15961600 if self .on_death_callback :
15971601 self .on_death_callback ()
1598- self .destroy (ctx )
1602+ self .destroy (util . Context )
15991603 return remains
16001604
16011605
0 commit comments