DnD_5e.battlemap package

Module contents

class DnD_5e.battlemap.BattleMap(**kwargs)[source]

Bases: object

A representation of the battlemap on the table. Used for movement, range, etc.

invalid_point_errorMsg = 'Points on a grid must have integers for x and y coordinates'
class Point(x, y)

Bases: tuple

x

Alias for field number 0

y

Alias for field number 1

class PointWithDistance(x, y, f, g, h)

Bases: tuple

f

Alias for field number 2

g

Alias for field number 3

h

Alias for field number 4

x

Alias for field number 0

y

Alias for field number 1

static validate_point(point)[source]

Check that the given point is valid for use in this BattleMap :param point: the point to check :raise: ValueError if the point is invalid

static validate_points(points: set)[source]

Check that all points in the list are valid for use in this BattleMap :param points: the list of points to check :raise: ValueError if any of the points (or the points argument itself) is invalid

get_square_size()[source]
get_light_source(point: Point)[source]
set_normal_dark_point(point: Point)[source]

Add the given point to self._normal_dark. Does not change any magical darkness that might be present. :param point: the Point to become dark :return: None

set_magical_dark_point(point: Point)[source]

Add the given point to self._magical_dark. Does not change any normal darkness that might be present. :param point: the Point to become dark :return: None

dispel_normal_darkness(point: Point)[source]

Remove normal darkness from the given point. Does not change any magical darkness that might be present. :param point: the Point to remove darkness from :return: None

dispel_magical_darkness(point: Point)[source]

Remove magical darkness from the given point. Does not change any normal darkness that might be present. :param point: the Point to remove darkness from :return: None

dispel_all_darkness(point: Point)[source]

Remove all darkness (normal and magical) from the given point. :param point: the Point to remove darkness from :return: None

is_in_bounds(point: Point)[source]
is_walkable(point: Point)[source]
Parameters:

point – the point to check

Returns:

True if the point is traversable and not swimmable, False otherwise

is_swimmable(point: Point)[source]
Parameters:

point – the point to check

Returns:

True if the point is swimmable, False otherwise

is_traversable(point: Point)[source]
Parameters:

point – the point to check

Returns:

True if the point can be traveled through, False otherwise

get_dpr_for_point(point: Point, ac=10)[source]

Get the expected damage for entering the given point :param point: the point to check :param ac: the ac of the Combatant that will be entering the given point :return: the expected damage

set_damage_for_point(point: Point, attack)[source]

Store the given point in self._damage_terrain :param point: the Point to add damage for :param attack: the attack to get dpr from. Replaces any previous attack that was stored for point :return:

clear_damage_for_point(point)[source]

Remove the given point from self._damage_terrain, setting dpr back to 0 :param point: the point to clear damage for :return:

get_occupant(point: Point)[source]
Parameters:

point – the point to check

Returns:

the occupant in the given point, or False if nobody is there

set_occupant(point: Point, occupant)[source]

Put occupant in the given point. Note: if there was an occupant at point, they are replaced. :param point: the point to occupy :param occupant: the Combatant that will occupy the point :return: None

get_neighbors(point: Point, distance=5)[source]

Get all points adjacent (orthogonal and diagonal) to point that are within the bounds of the map. Note: if a neighbor would be out of bounds, get the neighbor that would be within bounds (e.g., 5ft away instead of 10ft) :param point: the point to get neighbors of :param distance: how many feet away from point to look for neighbors :return: a list of all adjacent, in-map neighbors

get_traversable_neighbors(point: Point)[source]

Get all points adjacent (orthogonal and diagonal) to point that are traversable and within the bounds of the map :param point: the point to get neighbors of :return: a list of all adjacent, in-map, traversable neighbors

get_distance_to_traverse(point: Point, can_ignore_difficult=False, can_ignore_swim=False)[source]

Calculate the distance to travel onto a given point, returning the distance and what type of movement is needed :param point: the point to check :param can_ignore_difficult: True if difficult terrain counts the same as normal :param can_ignore_swim: True if swimming counts the same as normal :return: a tuple with the movement speed to traverse the point and the movement type,

or False if the point is not traversable

get_heuristic_distance(start: Point, end: Point)[source]

Estimate the distance from a start point to an end point. Assumes diagonal moves are the same distance as orthogonal (i.e., ignore the Pythagorean Theorem) :param start: the point to start the search at :param end: the point to end the search :return: the calculated distance (in this case, maximum of x distance and y distance)

find_path(start: Point, goal: Point, can_ignore_difficult=False, can_ignore_swim=False, ac=10)[source]

Find a path from source to dest using A star algorithm. Could be overridden in a subclass to use a different algorithm. Code taken from https://www.redblobgames.com/pathfinding/a-star/introduction.html :param start: the starting point :param goal: the ending point. Double-check that the goal is in bounds. We don’t check that the start is in bounds because that’s not an expected use case. :param can_ignore_difficult: True if difficult terrain counts the same as normal :param can_ignore_swim: True if swimming counts the same as normal :param ac: The AC of the Combatant that will be taking this path :return: a dict with info about the path: path -> list of `Point`s, distance -> int of total distance, swim_distance -> int of distance that requires swimming, damage -> estimated damage taken

static construct_path(point: Point, came_from: dict)[source]

Construct the path found by A star algorithm :param point: the end point of the path :param came_from: a dictionary mapping each point to the point that came before it :return: a list of points in order of the path, ending with point