Skip to content

Taming Animals

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

Begin Taming

To begin to tame a passive 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

When the animal is fed, a random decimal is generated. If this decimal is higher than the taming probability, the animal would them be tamed. If not, a numTimesFed counter is incremented. If this counter exceeds a threshold, the animal would then automatically be tamed. This was done so that the player would not get frustrated when trying to tame the animals.

// 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

System Overview

The taming feature in the game is handled by the following classes. image

Sequence Diagram

UMLSeq
Clone this wiki locally