X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/balance2?a=blobdiff_plain;f=plomrogue%2Fthings.py;h=7234d8ea395e05ab017fa55796bc32df1f21d94c;hb=52b01fc00d6ea2c053f9022981498b97ebd05839;hp=18cdf4c78069e9273e411c38223f4baae080a38f;hpb=8d0b5840b7df40ee883fdcf2fa1b4cd1d39e26fa;p=plomrogue2 diff --git a/plomrogue/things.py b/plomrogue/things.py index 18cdf4c..7234d8e 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -1,5 +1,6 @@ from plomrogue.errors import GameError, PlayError from plomrogue.mapping import YX +from plomrogue.misc import quote import random @@ -22,6 +23,7 @@ class Thing(ThingBase): portable = False protection = '.' commandable = False + carried = False def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -39,7 +41,6 @@ class Thing(ThingBase): def sound(self, name, msg): from plomrogue.mapping import DijkstraMap - from plomrogue.misc import quote def lower_msg_by_volume(msg, volume, largest_audible_distance): import random @@ -150,11 +151,32 @@ class Thing_Bottle(Thing): portable = True full = True thing_char = '~' + spinnable = True def empty(self): self.thing_char = '_' self.full = False + def spin(self): + import random + all_players = [t for t in self.game.things if t.type_ == 'Player'] + # TODO: refactor with ThingPlayer.prepare_multiprocessible_fov_stencil + # and ThingPlayer.fov_test + fov_map_class = self.game.map_geometry.fov_map_class + fov_radius = 12 + fov = fov_map_class(self.game.things, self.game.maps, + self.position, fov_radius, self.game.get_map) + fov.init_terrain() + visible_players = [] + for p in all_players: + test_position = fov.target_yx(p.position[0], p.position[1]) + if fov.inside(test_position) and fov[test_position] == '.': + visible_players += [p] + if len(visible_players) == 0: + self.sound('BOTTLE', 'no visible players in spin range') + pick = random.choice(visible_players) + self.sound('BOTTLE', 'BOTTLE picks: ' + pick.name) + class Thing_BottleSpawner(ThingSpawner): @@ -436,3 +458,9 @@ class Thing_Player(ThingAnimate): if self.game.sessions[c_id]['thing_id'] == self.id_: self.game.io.send(msg, c_id) break + + def uncarry(self): + t = self.carrying + t.carried = False + self.carrying = None + return t