@@ -976,12 +976,14 @@ def __init__(self) -> None:
976
976
self .race = "" # the name of the race of this creature
977
977
self .strength = 3
978
978
self .dexterity = 3
979
+ self .perception = 3
980
+ self .intelligence = 3
979
981
self .unarmed_attack = Weapon (UnarmedAttack .FISTS .name , weapon_type = WeaponType .UNARMED )
980
982
self .weapon_skills = {} # type: Dict[WeaponType, int] # weapon type -> skill level
981
983
self .magic_skills = {} # type: Dict[MagicType, MagicSkill]
982
984
self .skills = {} # type: Dict[str, int] # skill name -> skill level
983
985
self .action_points = 0 # combat points
984
- self .max_combat_points = 5 # max combat points
986
+ self .max_action_points = 5 # max combat points
985
987
self .max_magic_points = 5 # max magic points
986
988
self .magic_points = 0 # magic points
987
989
@@ -1001,7 +1003,7 @@ def from_race(cls: type, race: builtins.str, gender: builtins.str='n') -> 'Stats
1001
1003
def set_stats_from_race (self ) -> None :
1002
1004
# the stats that are static are always initialized from the races table
1003
1005
# we look it up via the name, not needed to store the actual Race object here
1004
- r = races .races [self .race ]
1006
+ r = races .races [self .race ] # type: Race
1005
1007
self .bodytype = r .body
1006
1008
self .language = r .language
1007
1009
self .weight = r .mass
@@ -1028,9 +1030,9 @@ def replenish_combat_points(self, amount: int = None) -> None:
1028
1030
if amount :
1029
1031
self .action_points += amount
1030
1032
else :
1031
- self .action_points = self .max_combat_points
1032
- if self .action_points > self .max_combat_points :
1033
- self .action_points = self .max_combat_points
1033
+ self .action_points = self .max_action_points
1034
+ if self .action_points > self .max_action_points :
1035
+ self .action_points = self .max_action_points
1034
1036
1035
1037
def replenish_magic_points (self , amount : int = None ) -> None :
1036
1038
if amount :
@@ -1650,6 +1652,8 @@ def do_on_death(self) -> 'Container':
1650
1652
return remains
1651
1653
1652
1654
def hide (self , hide : bool = True ):
1655
+ """ Hide or reveal the living entity. """
1656
+
1653
1657
if not hide :
1654
1658
self .hidden = False
1655
1659
self .hidden = False
@@ -1673,19 +1677,29 @@ def hide(self, hide: bool = True):
1673
1677
self .tell ("You hide yourself." )
1674
1678
self .location .tell ("%s hides" % self .title , exclude_living = self )
1675
1679
1676
- def search_hidden (self ):
1680
+ def search_hidden (self , silent : bool = False ):
1681
+ """ Search for hidden entities in the room.
1682
+ For automatic searches (like when entering a room),
1683
+ no fail messages will show, and no action points will be used."""
1684
+
1677
1685
if self .stats .action_points < 1 :
1678
1686
raise ActionRefused ("You don't have enough action points to search." )
1679
1687
1680
1688
livings = self .location .livings
1681
1689
1682
- self .location .tell ("%s searches for something in the room." % (self .title ), exclude_living = self )
1690
+ if not silent :
1691
+ self .stats .action_points -= 1
1692
+ self .location .tell ("%s searches for something in the room." % (self .title ), exclude_living = self )
1683
1693
1684
1694
if len (self .location .livings ) == 1 :
1685
- self .tell ("You don't find anything." )
1695
+ if not silent :
1696
+ self .tell ("You don't find anything." )
1686
1697
return
1687
1698
1688
- skillValue = self .stats .skills .get (SkillType .SEARCH , 0 )
1699
+ if silent :
1700
+ skillValue = self .stats .perception * 5
1701
+ else :
1702
+ skillValue = self .stats .skills .get (SkillType .SEARCH , 0 )
1689
1703
1690
1704
found = False
1691
1705
@@ -1698,9 +1712,31 @@ def search_hidden(self):
1698
1712
self .location .tell ("%s reveals %s" % (self .title , living .title ), exclude_living = self )
1699
1713
found = True
1700
1714
1701
- if not found :
1715
+ if not found and not silent :
1702
1716
self .tell ("You don't find anything." )
1703
1717
1718
+ def pick_lock (self , door : 'Door' ):
1719
+ """ Pick a lock on an exit. """
1720
+ if not door .locked :
1721
+ raise ActionRefused ("The door is not locked." )
1722
+
1723
+ if self .stats .action_points < 1 :
1724
+ raise ActionRefused ("You don't have enough action points to pick the lock." )
1725
+
1726
+ self .stats .action_points -= 1
1727
+
1728
+ skillValue = self .stats .skills .get (SkillType .PICK_LOCK , 0 )
1729
+
1730
+ if random .randint (1 , 100 ) > skillValue :
1731
+ self .tell ("You fail to pick the lock." )
1732
+ return
1733
+
1734
+ door .unlock ()
1735
+
1736
+ self .tell ("You successfully pick the lock." , evoke = True )
1737
+
1738
+ if not self .hidden :
1739
+ self .location .tell ("%s picks the lock on the door." % self .title , exclude_living = self )
1704
1740
1705
1741
class Container (Item ):
1706
1742
"""
@@ -2044,6 +2080,33 @@ def insert(self, item: Union[Living, Item], actor: Optional[Living]) -> None:
2044
2080
else :
2045
2081
raise ActionRefused ("You could try to lock the door with it instead." )
2046
2082
raise ActionRefused ("The %s doesn't fit." % item .title )
2083
+
2084
+ def pick_lock (self , actor : Living ) -> None :
2085
+ if not self .locked :
2086
+ raise ActionRefused ("The door is not locked." )
2087
+
2088
+ if actor .stats .action_points < 1 :
2089
+ raise ActionRefused ("You don't have enough action points to pick the lock." )
2090
+
2091
+ actor .stats .action_points -= 1
2092
+
2093
+ skillValue = actor .stats .skills .get (SkillType .PICK_LOCK , 0 )
2094
+
2095
+ if random .randint (1 , 100 ) > skillValue :
2096
+ actor .tell ("You fail to pick the lock." )
2097
+ return
2098
+
2099
+ self .locked = False
2100
+ self .opened = True
2101
+
2102
+ actor .tell ("You successfully pick the %s." % (self .name ), evoke = True , short_len = True )
2103
+ if not actor .hidden :
2104
+ actor .location .tell ("%s picks the lock on the door." % actor .title , exclude_living = actor )
2105
+ actor .tell_others ("{Actor} picks the %s, and opens it." % (self .name ), evoke = True , short_len = True )
2106
+ if self .linked_door :
2107
+ self .linked_door .locked = False
2108
+ self .linked_door .opened = True
2109
+ self .target .tell ("The %s is unlocked and opened from the other side." % self .linked_door .name , evoke = False , short_len = True )
2047
2110
2048
2111
2049
2112
class Key (Item ):
0 commit comments