Pets - UQcsse3200/2024-studio-1 GitHub Wiki
Pets are friendly animals that assist the player by engaging in combat with hostile creatures. They are summoned when the player picks up a tombstone.
Pets initially act unpredictably. If no enemies are nearby, they may become aggressive toward the player. However, once hostile animals are present, pets quickly recognize the player as an ally and focus their aggression on those enemies. This loyalty is also reestablished when moving into new rooms if enemies are detected.
Pets rely on a set of tasks to determine their behavior:
- Attack Enemies: This is the highest priority when pets detect hostile animals nearby. They immediately switch to engage and protect the player.
- Follow Player: Once all nearby enemies are defeated, pets default to the FollowTask, which is the lowest priority task. This means they follow the player throughout the game, staying close in case new threats emerge.
To provide more strategic control, the player can press Q to make pets specifically target enemies closest to them. This allows players to prioritize which threats pets handle, giving a tactical edge in managing multiple enemies.
- Summoning: Pets are summoned by collecting a tombstone, which acts as a special item binding the pet to the player.
- Loyalty Mechanism: Pets become loyal once an enemy is detected, transitioning from potential threats to loyal allies. This loyalty is retained when moving between rooms, provided enemies are present.
- Aggression: In the absence of enemies, pets may become hostile to the player. Therefore, it's crucial to either quickly find enemies or keep moving to prevent pets from attacking.
- Exploration and Rooms: Upon entering a new room, pets reassess their surroundings. If enemies are detected, they recognize the player as an ally, ensuring smoother transitions between areas.
- Strategic Use: Players can utilize pets to clear out animal threats, making exploration easier and allowing them to focus on other tasks or objectives.
Pets add an element of unpredictability and strategic depth, requiring players to manage them carefully to maximize their usefulness and overcome challenges.
classDiagram
class Pet {
<<interface>>
+getPetSpecification() String
+spawn(Entity) Entity
}
class Tombstone {
-String petName
+Tombstone(String)
+Tombstone()
+getPetSpecification() String
+spawn(Entity) Entity
-selectPet() String
+getName() String
+getIcon() Texture
}
class PetFactory {
+create(String) Entity
}
class FollowTask {
-float followSpeed
-float waitTime
-Vector2 followRange
-MovementTask movementTask
-WaitTask waitTask
-Task currentTask
+FollowTask(TaskConfig.FollowTaskConfig)
+start()
+update()
+stop()
+getPriority() int
-startWaiting()
-startMoving()
-swapTask(Task)
-getRandomPosInRange() Vector2
}
Pet <|-- Tombstone
Tombstone --> PetFactory : uses
FollowTask --|> DefaultTask
FollowTask ..|> PriorityTask
sequenceDiagram
participant Player
participant Tombstone
participant PetFactory
participant Pet
participant FollowTask
Player->>Tombstone: Collect
Tombstone->>PetFactory: create(petName)
PetFactory->>Pet: Create pet entity
Pet->>FollowTask: Create and start
loop While active
FollowTask->>FollowTask: update()
alt Current task finished
FollowTask->>FollowTask: Switch task (move/wait)
end
end
Player->>Pet: Press Q
Pet->>Pet: Target nearest enemy