Skip to content

Taming Animals

Mr Goh edited this page Oct 3, 2023 · 26 revisions

Begin Taming

To begin to tame the animal, an event listener that would listen out for the "feed event was added to the game. When this event has been triggered, it will enter the main logic for taming. More information about the addition of events and events listener can be found at Event Systems

  @Override
  public void create() {
    entity.getEvents().addListener("feed", this::feedAnimal);
  }

Taming Logic

The main logic for taming is that it uses pseudo random number generator to determine if the animal is tamed or not. Each animal species will have different tame levels, making it easier/harder to tame a specific animal. Down below is just a code segment of the tame logic. To feed the animal, the player must be holding the Animal's favourite food. This info is found in [Alien Fauna Passive(https://github.com/UQcsse3200/2023-studio-1/wiki/Alien-Fauna-%E2%80%90-Passive)

// Generate RNG number for taming
double randomDecimal = generateRandomDecimal();
if (numTimesFed == tamingThreshold || randomDecimal > tamingProbability) {
        isTamed = true;
        ServiceLocator.getMissionManager().getEvents().trigger(MissionManager.MissionEvent.ANIMAL_TAMED.name());
   } else {
           numTimesFed++;
          } 

Tamable Component UML Diagram

Clone this wiki locally