Skip to content

Mob Task

gregchan550 edited this page Oct 21, 2023 · 4 revisions

Overview

The MobTask class is responsible for executing the AI logic for all general mob (also known as NPC) entities within the game. This task handles the sequencing for melee and ranged mobs as well as animations for all mobs. Its sequence is based on whether the mob is a melee or ranged mob which dictates its attack method. The class is designed to be added to an AiTaskComponent, which should be attached to all mob entities.

Usage

To utilize MobTask, execute the following steps:

  1. Create an instance of MobTask.
  2. Add it to an AiTaskComponent instance that is connected to a NPC entities.
// Create a NPC Entity
skeleton = NPCFactory.createSkeleton();

// Create an AiTaskComponent instance
AITaskComponent aiTaskComponent = new AITaskComponent();

// Add the MobTask to the AiTaskComponent - The MobType must be passed into the class as a param.
aiTaskComponent.addTask(new MobTask(MobType.SKELETON));

// Add AiTaskComponent to Droid entity
skeleton.addComponent(aiTaskComponent);

Sequence Diagram

IMG_0077

Methods

animate()

This method handles all the animations and sounds for every general mob.

changeState()

This method handles all state changes of the general mob

enemyDetected()

This method detects if a human entity is within proximity for melee mobs to attack. If a mob is stuck this method will also check nearby tiles and attack the closest human entity which is causing it to be stuck.

meleeAttack()

Performs a melee attack by getting the combat stats of a target set by enemyDetected(). The base damage (10) of a general mob is then done to the target.

rangeAttack()

Stops the movement of a ranged mob to shoot a projectile every few seconds and continues moving after.

setDodge()

Sets dodge flag to true if mob is able to dodge projectiles.

dropCurrency()

Drops currency upon death based on a predetermined probability.

Clone this wiki locally