def _put_loot_on_ground(self, enemy_death_position: Tuple[int, int], loot: List[LootEntry]): for loot_entry in loot: if len(loot) > 1: position_offset = (random.randint(-20, 20), random.randint(-20, 20)) else: position_offset = (0, 0) loot_position = sum_of_vectors(enemy_death_position, position_offset) if loot_entry.money_amount: money_pile_on_ground = create_money_pile_on_ground( loot_entry.money_amount, loot_position) self.game_state.money_piles_on_ground.append( money_pile_on_ground) elif loot_entry.item_type: item_on_ground = create_item_on_ground(loot_entry.item_type, loot_position) self.game_state.items_on_ground.append(item_on_ground) elif loot_entry.consumable_type: consumable_on_ground = create_consumable_on_ground( loot_entry.consumable_type, loot_position) self.game_state.consumables_on_ground.append( consumable_on_ground)
def drop_consumable_on_ground(self, consumable_slot: int, game_world_position: Tuple[int, int]): consumable_type = self.game_state.player_state.consumable_inventory.remove_consumable_from_slot( consumable_slot) consumable = create_consumable_on_ground(consumable_type, game_world_position) self.game_state.consumables_on_ground.append(consumable)
def _put_loot_on_ground(self, enemy_death_position: Tuple[int, int], loot: List[LootEntry]): for loot_entry in loot: if len(loot) > 1: position_offset = (random.randint(-20, 20), random.randint(-20, 20)) else: position_offset = (0, 0) loot_position = sum_of_vectors(enemy_death_position, position_offset) if isinstance(loot_entry, MoneyLootEntry): money_pile_on_ground = create_money_pile_on_ground( loot_entry.amount, loot_position) self.game_state.money_piles_on_ground.append( money_pile_on_ground) elif isinstance(loot_entry, ItemLootEntry): item_id = randomized_item_id(loot_entry.item_type) item_on_ground = create_item_on_ground(item_id, loot_position) self.game_state.items_on_ground.append(item_on_ground) elif isinstance(loot_entry, SuffixedItemLootEntry): item_id = randomized_suffixed_item_id(loot_entry.item_type, loot_entry.suffix_id) item_on_ground = create_item_on_ground(item_id, loot_position) self.game_state.items_on_ground.append(item_on_ground) elif isinstance(loot_entry, ConsumableLootEntry): consumable_on_ground = create_consumable_on_ground( loot_entry.consumable_type, loot_position) self.game_state.consumables_on_ground.append( consumable_on_ground)
def consumable(consumable_type: ConsumableType): entity = create_consumable_on_ground(consumable_type, (0, 0)).world_entity e = MapEditorWorldEntity( entity.sprite, (entity.pygame_collision_rect.w, entity.pygame_collision_rect.h)) e.consumable_type = consumable_type return e
def _add_consumable(consumable_type: ConsumableType, game_state, snapped_mouse_world_position): already_has_consumable = any([ x for x in game_state.consumables_on_ground if x.world_entity.get_position() == snapped_mouse_world_position ]) if not already_has_consumable: consumable_on_ground = create_consumable_on_ground( consumable_type, snapped_mouse_world_position) game_state.consumables_on_ground.append(consumable_on_ground)
def _put_loot_on_ground(self, enemy_death_position: Tuple[int, int], loot: List[LootEntry]): for loot_entry in loot: if len(loot) > 1: position_offset = (random.randint(-20, 20), random.randint(-20, 20)) else: position_offset = (0, 0) loot_position = sum_of_vectors(enemy_death_position, position_offset) if isinstance(loot_entry, MoneyLootEntry): money_pile_on_ground = create_money_pile_on_ground( loot_entry.amount, loot_position) self.game_state.game_world.money_piles_on_ground.append( money_pile_on_ground) elif isinstance(loot_entry, ItemLootEntry): item_id = randomized_item_id(loot_entry.item_type) item_on_ground = create_item_on_ground(item_id, loot_position) self.game_state.game_world.items_on_ground.append( item_on_ground) elif isinstance(loot_entry, AffixedItemLootEntry): item_id = loot_entry.item_id item_on_ground = create_item_on_ground(item_id, loot_position) self.game_state.game_world.items_on_ground.append( item_on_ground) loot_center_pos = (loot_position[0] + ITEM_ENTITY_SIZE[0] // 2, loot_position[1] + ITEM_ENTITY_SIZE[1] // 2) self.game_state.game_world.visual_effects.append( VisualCircle((170, 200, 170), loot_center_pos, 30, 40, Millis(500), 2)) self.game_state.game_world.visual_effects.append( VisualCircle((70, 100, 70), loot_center_pos, 25, 35, Millis(500), 2)) elif isinstance(loot_entry, ConsumableLootEntry): consumable_on_ground = create_consumable_on_ground( loot_entry.consumable_type, loot_position) self.game_state.game_world.consumables_on_ground.append( consumable_on_ground)
def deserialize(data) -> ConsumableOnGround: return create_consumable_on_ground( ConsumableType[data["consumable_type"]], data["position"])