Skip to content

Commit

Permalink
feat: modern era artefacts (#1654)
Browse files Browse the repository at this point in the history
* feat: add modern artefacts

* clean up artefact files

* update lock file

* add artefacts logic

* remove debug
  • Loading branch information
dionizh committed May 9, 2022
1 parent deb36f1 commit 1e59903
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 1,322 deletions.
58 changes: 31 additions & 27 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 12 additions & 30 deletions aimmo-game-worker/simulation/world_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
# how many nearby artefacts to return
SCAN_LIMIT = 3
SCAN_RADIUS = 12
ARTEFACT_TYPES = ["chest", "key", "yellow_orb"]
ARTEFACT_TYPES = ["chest", "key", "yellow_orb", "phone", "keyboard"]
PICKUP_TYPES = ["damage_boost", "invulnerability", "health"] + ARTEFACT_TYPES


class ArtefactType(Enum):
CHEST = "chest"
KEY = "key"
YELLOW_ORB = "yellow_orb"
PHONE = "phone"
KEYBOARD = "keyboard"
COINS = "coins"

def __eq__(self, other):
return self.value == other
Expand Down Expand Up @@ -51,15 +54,10 @@ def habitable(self):
return not (self.avatar or self.obstacle)

def has_artefact(self):
return (
self.interactable is not None
and self.interactable["type"] in ARTEFACT_TYPES
)
return self.interactable is not None and self.interactable["type"] in ARTEFACT_TYPES

def __repr__(self):
return "Cell({} a={} i={})".format(
self.location, self.avatar, self.interactable
)
return "Cell({} a={} i={})".format(self.location, self.avatar, self.interactable)

def __eq__(self, other):
return self.location == other.location
Expand All @@ -78,9 +76,7 @@ def generate_world_map_from_cells_data(cells: List[Cell]) -> "WorldMap":

def generate_world_map_from_game_state(game_state) -> "WorldMap":
cells: Dict[Location, Cell] = {}
for x in range(
game_state["southWestCorner"]["x"], game_state["northEastCorner"]["x"] + 1
):
for x in range(game_state["southWestCorner"]["x"], game_state["northEastCorner"]["x"] + 1):
for y in range(
game_state["southWestCorner"]["y"],
game_state["northEastCorner"]["y"] + 1,
Expand All @@ -89,9 +85,7 @@ def generate_world_map_from_game_state(game_state) -> "WorldMap":
cells[Location(x, y)] = cell

for interactable in game_state["interactables"]:
location = Location(
interactable["location"]["x"], interactable["location"]["y"]
)
location = Location(interactable["location"]["x"], interactable["location"]["y"])
cells[location].interactable = interactable

for obstacle in game_state["obstacles"]:
Expand Down Expand Up @@ -123,18 +117,10 @@ def interactable_cells(self):
return [cell for cell in self.all_cells() if cell.interactable]

def pickup_cells(self):
return [
cell
for cell in self.interactable_cells()
if cell.interactable["type"] in PICKUP_TYPES
]
return [cell for cell in self.interactable_cells() if cell.interactable["type"] in PICKUP_TYPES]

def score_cells(self):
return [
cell
for cell in self.interactable_cells()
if "score" == cell.interactable["type"]
]
return [cell for cell in self.interactable_cells() if "score" == cell.interactable["type"]]

def partially_fogged_cells(self):
return [cell for cell in self.all_cells() if cell.partially_fogged]
Expand All @@ -144,9 +130,7 @@ def is_visible(self, location):

def get_cell(self, location):
cell = self.cells[location]
assert (
cell.location == location
), "location lookup mismatch: arg={}, found={}".format(location, cell.location)
assert cell.location == location, "location lookup mismatch: arg={}, found={}".format(location, cell.location)
return cell

def can_move_to(self, target_location):
Expand All @@ -169,9 +153,7 @@ def _scan_artefacts(self, start_location, radius):
artefacts.append(cell)
return artefacts

def scan_nearby(
self, avatar_location, radius=SCAN_RADIUS
) -> NearbyArtefactsList[dict]:
def scan_nearby(self, avatar_location, radius=SCAN_RADIUS) -> NearbyArtefactsList[dict]:
"""
From the given location point search the given radius for artefacts.
Returns list of nearest artefacts (artefact/interactable represented as dict).
Expand Down
6 changes: 6 additions & 0 deletions aimmo-game/simulation/interactables/pickups/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
ChestArtefact,
KeyArtefact,
YellowOrbArtefact,
PhoneArtefact,
KeyboardArtefact,
CoinsArtefact,
)
from simulation.interactables.pickups.damage_boost_pickup import DamageBoostPickup
from simulation.interactables.pickups.health_pickup import HealthPickup
Expand All @@ -21,4 +24,7 @@ def serialize_pickups(world_map):
YellowOrbArtefact,
ChestArtefact,
KeyArtefact,
PhoneArtefact,
KeyboardArtefact,
CoinsArtefact,
)
18 changes: 18 additions & 0 deletions aimmo-game/simulation/interactables/pickups/artefacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,21 @@ class YellowOrbArtefact(_Artefact):
def __init__(self, cell):
super().__init__(cell)
self._type = "yellow_orb"


class PhoneArtefact(_Artefact):
def __init__(self, cell):
super().__init__(cell)
self._type = "phone"


class KeyboardArtefact(_Artefact):
def __init__(self, cell):
super().__init__(cell)
self._type = "keyboard"


class CoinsArtefact(_Artefact):
def __init__(self, cell):
super().__init__(cell)
self._type = "coins"
9 changes: 5 additions & 4 deletions aimmo-game/simulation/worksheet/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
YellowOrbArtefact,
ChestArtefact,
KeyArtefact,
PhoneArtefact,
KeyboardArtefact,
CoinsArtefact,
)
from .avatar_state_serializers import (
worksheet1_avatar_state_serializer,
Expand All @@ -27,9 +30,7 @@
from simulation.avatar.avatar_wrapper import AvatarWrapper
from simulation.game_logic.map_updaters import _MapUpdater

AvatarStateSerializer = NewType(
"AvatarStateSerializer", Callable[[AvatarWrapper], Dict]
)
AvatarStateSerializer = NewType("AvatarStateSerializer", Callable[[AvatarWrapper], Dict])


@dataclass
Expand Down Expand Up @@ -66,7 +67,7 @@ class WorksheetData:
4: WorksheetData(
worksheet_id=4,
era="modern",
map_updaters=[PickupUpdater(pickup_types=[ChestArtefact, KeyArtefact])],
map_updaters=[PickupUpdater(pickup_types=[PhoneArtefact, KeyboardArtefact, CoinsArtefact])],
number_of_obstacle_textures=1,
avatar_state_serializer=worksheet4_avatar_state_serializer,
),
Expand Down
Binary file not shown.
Loading

0 comments on commit 1e59903

Please sign in to comment.