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 _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 item(item_type: ItemType): entity = create_item_on_ground(item_type, (0, 0)).world_entity e = MapEditorWorldEntity( entity.sprite, (entity.pygame_collision_rect.w, entity.pygame_collision_rect.h)) e.item_type = item_type return e
def drop_inventory_item_on_ground(self, item_slot: int, game_world_position: Tuple[int, int]): item_equip_event = self.game_state.player_state.item_inventory.remove_item_from_slot( item_slot) item_type = item_equip_event.item_type self._handle_item_equip_event(item_equip_event) item = create_item_on_ground(item_type, game_world_position) self.game_state.items_on_ground.append(item)
def _add_item(item_type: ItemType, game_state, snapped_mouse_world_position): already_has_item = any([ x for x in game_state.items_on_ground if x.world_entity.get_position() == snapped_mouse_world_position ]) if not already_has_item: item_on_ground = create_item_on_ground(item_type, snapped_mouse_world_position) game_state.items_on_ground.append(item_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 on_select(self, game_engine: GameEngine) -> Optional[str]: game_state = game_engine.game_state player_has_it = game_state.player_state.item_inventory.has_item_in_inventory( plain_item_id(self.quest_item_type)) if player_has_it: game_state.player_state.item_inventory.lose_item_from_inventory(plain_item_id(self.quest_item_type)) play_sound(SoundId.EVENT_COMPLETED_QUEST) game_state.player_state.complete_quest(self.quest) reward_item_id = self.reward_item_id(game_state) if reward_item_id: did_add_item = game_engine.try_add_item_to_inventory(reward_item_id) if not did_add_item: game_state.game_world.items_on_ground.append( create_item_on_ground(reward_item_id, game_state.game_world.player_entity.get_position())) return "Quest completed! Reward gained: " + reward_item_id.name return "Quest completed!" else: play_sound(SoundId.WARNING) return "You don't have that!"
def on_select(self, game_state: GameState) -> Optional[str]: player_has_it = game_state.player_state.item_inventory.has_item_in_inventory( ITEM_TYPE_FROG) if player_has_it: game_state.player_state.item_inventory.lose_item_from_inventory( ITEM_TYPE_FROG) reward_item_type = get_reward_for_hero( game_state.player_state.hero_id) reward_effect = get_item_effect(reward_item_type) reward_data = ITEMS[reward_item_type] reward_equipment_category = reward_data.item_equipment_category did_add_item = try_add_item_to_inventory( game_state, reward_effect, reward_equipment_category) if not did_add_item: game_state.items_on_ground.append( create_item_on_ground( reward_item_type, game_state.player_entity.get_position())) play_sound(SoundId.EVENT_COMPLETED_QUEST) return "Reward gained: " + reward_data.name else: play_sound(SoundId.WARNING) return "You don't have that!"
def deserialize(data) -> ItemOnGround: item_id = ItemId.from_id_string(data["item_id"]) return create_item_on_ground(item_id, data["position"])
def deserialize(data) -> ItemOnGround: return create_item_on_ground(ItemType[data["item_type"]], data["position"])
def item(item_id: ItemId): entity = create_item_on_ground(item_id, (0, 0)).world_entity e = MapEditorWorldEntity(entity.sprite, (entity.pygame_collision_rect.w, entity.pygame_collision_rect.h)) e.item_id = item_id return e