def paint(self): num_bubbles = dice.d(2, 3) + 1 blocked = set(self.region.shape.border) for point in self.region.connections.keys(): blocked.add(point) blocked.update(geometry.neighbors(point)) field = BubbleField(self.region, blocked, num_bubbles) field.expand_bubbles() self.terrain_fill(Wall) for access_point in self.region.connections.keys(): self.board[access_point].terrain = Floor() rooms = [] for bubble in field.bubbles: rooms.append(ClusterableRoom(bubble.rect)) cluster = RoomCluster(rooms, self) cluster.connect() for room in rooms: for point in room.interior: self.board[point].terrain = Floor() for point in room.walls: self.board[point].terrain = Wall(artificial=True) for point in room.doors: self.board[point].terrain = ClosedDoor()
def paint(self): self.terrain_fill(wall.Wall) border = self.region.shape.border connections = list(self.region.connections.keys())[:] costs = {} base_cost = 1000 for point in self.region.shape.points: costs[point] = base_cost for point in border: costs[point] = 10 * base_cost random.shuffle(connections) path_endpoints = connections[0:2] extra_connections = connections[2:] inflection_candidates = list( set(self.region.shape.points) - set(self.region.shape.border)) inflection_points = [] for i in range(dice.d(2, 2)): p = random.choice(inflection_candidates) inflection_points.append(p) inflection_candidates.remove(p) path_start, path_end = path_endpoints path = [path_start] + inflection_points + [path_end] for point in path: costs[point] = 40 * base_cost for n in geometry.neighbors(point): costs[n] = 10 * base_cost segments = [] for i, point in enumerate(path[:-1]): segments.append((point, path[i + 1])) # dig out the path for segment in segments: start, end = segment dug = self.smart_draw_corridor(start, end, costs=costs) for p in dug: costs[p] = 10 * base_cost for p in geometry.neighbors(p): if p not in dug: costs[p] = 10 * base_cost #connect any extra access points to the path for start in extra_connections: end = random.choice(inflection_points) dug = self.smart_draw_corridor(start, end, costs=costs) for p in dug: # try and keep adacent tunnels from being dug costs[p] = 10 * base_cost for p in geometry.neighbors(p): if p not in dug: costs[p] = 10 * base_cost
def paint(self): self.terrain_fill(wall.Wall) border = self.region.shape.border connections = list(self.region.connections.keys())[:] costs = {} base_cost = 1000 for point in self.region.shape.points: costs[point] = base_cost for point in border: costs[point] = 10*base_cost random.shuffle(connections) path_endpoints = connections[0:2] extra_connections = connections[2:] inflection_candidates = list(set(self.region.shape.points) - set(self.region.shape.border)) inflection_points = [] for i in range(dice.d(2, 2)): p = random.choice(inflection_candidates) inflection_points.append(p) inflection_candidates.remove(p) path_start, path_end = path_endpoints path = [path_start] + inflection_points + [path_end] for point in path: costs[point] = 40*base_cost for n in geometry.neighbors(point): costs[n] = 10*base_cost segments = [] for i, point in enumerate(path[:-1]): segments.append((point, path[i+1])) # dig out the path for segment in segments: start, end = segment dug = self.smart_draw_corridor(start, end, costs=costs) for p in dug: costs[p] = 10*base_cost for p in geometry.neighbors(p): if p not in dug: costs[p] = 10*base_cost #connect any extra access points to the path for start in extra_connections: end = random.choice(inflection_points) dug = self.smart_draw_corridor(start, end, costs=costs) for p in dug: # try and keep adacent tunnels from being dug costs[p] = 10*base_cost for p in geometry.neighbors(p): if p not in dug: costs[p] = 10*base_cost
def do_tactics(self): if self.actor.can_see_entity( self.actor.tile.board.world.player) and dice.one_chance_in(3): raise events.SeeHostileEvent() if not self.destination: self.choose_destination() self.compute_path() if self.actor.tile.pos == self.destination: if not self.should_stop(): # let's wander somewhere else self.choose_destination() self.compute_path() else: # nah, let's ask the strategy what to do. raise events.TacticsCompleteEvent() # try to move: if not self.path: self.destination = None return wait.WaitAction(self.actor) try: result = self.smart_move(self.path) # reset our wait timer: if self.wait_timer == 0: self.wait_timer = dice.d(1, self.max_wait) return result except PathBlockedException: # logger.debug('path blocked') # wait and see if the blocker clears if self.wait_timer > 0: # logger.debug('waiting: {timer} more turns'.format(timer=self.wait_timer)) self.wait_timer -= 1 return wait.WaitAction(self.actor) else: # logger.debug('trying to repath') # ok, let's recompute the path, or go somewhere else path_found = self.recompute_path(ab=True, md=10) if not path_found: # logger.debug('no path found, going somewhere else') dest = self.nearby_reachable_destination() if dest: # logger.debug('nearby destination found!') self.destination = dest self.compute_path() return wait.WaitAction(self.actor)
def do_tactics(self): if self.actor.can_see_entity(self.actor.tile.board.world.player) and dice.one_chance_in(3): raise events.SeeHostileEvent() if not self.destination: self.choose_destination() self.compute_path() if self.actor.tile.pos == self.destination: if not self.should_stop(): # let's wander somewhere else self.choose_destination() self.compute_path() else: # nah, let's ask the strategy what to do. raise events.TacticsCompleteEvent() # try to move: if not self.path: self.destination = None return wait.WaitAction(self.actor) try: result = self.smart_move(self.path) # reset our wait timer: if self.wait_timer == 0: self.wait_timer = dice.d(1, self.max_wait) return result except PathBlockedException: # logger.debug('path blocked') # wait and see if the blocker clears if self.wait_timer > 0: # logger.debug('waiting: {timer} more turns'.format(timer=self.wait_timer)) self.wait_timer -= 1 return wait.WaitAction(self.actor) else: # logger.debug('trying to repath') # ok, let's recompute the path, or go somewhere else path_found = self.recompute_path(ab=True, md=10) if not path_found: # logger.debug('no path found, going somewhere else') dest = self.nearby_reachable_destination() if dest: # logger.debug('nearby destination found!') self.destination = dest self.compute_path() return wait.WaitAction(self.actor)
def paint(self): self.terrain_fill(Wall) center, width, height = self.get_bounding_box() circle = geometry.Circle(center, min(width, height) / 2) room = Room(circle) # place 1d3 doors doorsteps = [] for _ in range(dice.d(1, 3)): door_pos = random.choice(room.door_candidates()) room.place_door(door_pos) doorsteps.append(room.doorstep(door_pos)) # draw room for pos in room.interior: self.board[pos].terrain = Floor() for pos in room.walls: self.board[pos].terrain = Wall(artificial=True) for pos in room.doors: self.board[pos].terrain = ClosedDoor() # draw corridors connections = list(self.region.connections.keys()) blocked = set(room.all_points()).union(set(self.region.shape.border)) blocked -= set(connections) connected_doorsteps = [] for p in connections: self.board[p].terrain = Floor() doorstep = random.choice(doorsteps) connected_doorsteps.append(doorstep) self.smart_draw_corridor(p, doorstep, blocked) for p in doorsteps: if p not in connected_doorsteps: self.board[p].terrain = Floor() border_point = random.choice(connections) self.smart_draw_corridor(p, border_point, blocked)
def fight(attacker, defender): to_hit = 3 to_miss = 1 if attacker.dex > defender.dex: to_hit += attacker.dex - defender.dex else: to_miss += defender.dex - attacker.dex hit_chance = to_hit / (to_hit + to_miss) logger.debug('hit_chance: {hit_chance:2}'.format(hit_chance=hit_chance)) attack_power = attacker.str damage = 0 if random.random() <= hit_chance: result_type = CombatResultTypes.hit damage = dice.d(1, attack_power) else: result_type = CombatResultTypes.miss return CombatEvent(attacker, defender, result_type, damage)
def should_stop(self): return dice.d(1, 3) == 3
def use_effect(self, actor): amount = dice.d(2, 8) actor.heal(amount) actor.inventory.remove(item=self) return [GainHealthEvent(actor, amount)]
def __init__(self, strategy=None): super().__init__(strategy) self.turns_to_sleep = dice.d(2, 50)