Usable Items key methods - UQcsse3200/2024-studio-1 GitHub Wiki
Key methods
Describing Item Effects on the Player
Bear Trap
- BearTrap.java
spawnBearTrap(Entity entity)
: Spawns a bear trap entity at the player's current position using the DeployableItemFactory.
getName()
: Returns the name of the bear trap item as a string ("Bear Trap").
getIcon()
: Provides the texture for the bear trap's icon, used in the inventory or UI.
getItemSpecification()
: Returns the specification identifier ("beartrap") for the bear trap item.
apply(Entity entity)
: Applies the bear trap to an entity by calling spawnBearTrap()
to deploy the trap in the game world.
- TrapComponent.java
create()
: Registers the event listener for detecting collisions when the trap is initialized.
onCollisionStart(Fixture me, Fixture other)
: Handles collision events, applies damage to enemies, immobilizes them, and removes the trap after use.
isEnemy(Entity enemy)
: Determines if the colliding entity is an enemy (non-pet) by checking for specific AI task configurations.
markEntityForRemoval(Entity trap)
: Marks the trap entity for removal from the game after it has been used.
immobilizeEnemies(Entity enemy)
: Stops the tasks of the enemy entity and then restarts them after a set time (5 seconds) to simulate immobilization.
Medkit
- Increases the player's health by a large boost of 100 and caps it at player's current maximum health when required.
- Uses
setHealth()
inCombatStatsComponent.java
to update health.
Bandage:
- Increases the player's health by a small health boost of 20 and caps it at 100 when required.
- Uses
setHealth()
inCombatStatsComponent.java
to update health.
Syringe
- Gives an instant boost of 50 to player and it does not care about the capping.
- It uses
addHealth()
inCombatStatsComponent.java
to increase health
ShieldPotion:
- Provides temporary immunity by negating the next two hits.
Big Red Button
- This item's
effect()
instantly kills all enemies in the current room.
Teleporter
- This item's
effect()
allows the player to instantly teleport to the boss room bypassing all other rooms
Gasoline
- Gasoline.java
spawnRingFire(Entity entity)
: Spawns a ring of fire around the player's current position using the DeployableItemFactory.
getName()
: Returns the name of the item as a string ("Gasoline").
getItemSpecification()
: Returns the specification identifier ("gasoline").
apply(Entity entity)
: Spawns 12 different instances of the fire to form a ring.
Reroll item
Reroll creation
- The reroll item is created using...
CollectibleFactory collectibleFactory = new CollectibleFactory()
Entity collectible = collectibleFactory.createCollectibleEntity("item:reroll")
//Creates a usable reroll item
Relevant classes
- Reroll.java: The class for a reroll item
- ItemPickupComponent.java: Contains a method
handleReroll()
that handles the reroll item effect. It spawns another item in place of the other item in collision. The random newly spawned item is handled in therandomItemGenerator()
method of this class.
Important features
- Key presses: Unlike most UsableItems, the reroll item is "used" by pressing "R" when in collision with another item
Testing
This item is currently only tested manually.
Methods to Create Item Entities
Creating a collectible entity (returns Entity)
- Use
createCollectibleEntity(String specification)
method in CollectibleFactory.java. This method then creates a Collectible instance of an item based on the specification using thecreate()
method of this class. If the string specifies an "item" or "buff", thecreate()
method of the ItemFactory is called (see below for 'Creating a collectible item')
- After the Collectible instance is obtained, the second
createCollectibleEntity(String specification, Collectible collectible)
method is called, which returns the Entity of this collectible item. This method also checks for "mystery" in the specification. If this is the case, then the TextureRenderComponent has the mystery box icon associated with that collectible and is otherwise the collectible icon. This method also checks for "buyable" in the specification. If this is the case, then it adds a BuyableComponent to this entity, with a default cost of 10.
Creating a collectible item (returns Collectible)
- Uses
create()
method in ItemFactory.java. This method checks that the item type specification is correct. It then calls upon theloadCreators()
method of this class to create the items based on the specification.