diff --git a/src/panel/pets.ts b/src/panel/pets.ts index 1a4b1112..a72eeeec 100644 --- a/src/panel/pets.ts +++ b/src/panel/pets.ts @@ -221,7 +221,7 @@ abstract class BasePetType implements IPetType { this.currentState = resolveState(this.currentStateEnum, this); this._name = name; - this._speed = speed; // TODO #183 : Add a random modifier (+/- 30%) to this value. + this._speed = this.randomizeSpeed(speed); // Increment the static count of the Pet class that the constructor belongs to (this.constructor as any).count += 1; @@ -285,6 +285,13 @@ abstract class BasePetType implements IPetType { return this._speed; } + randomizeSpeed(speed: number): number { + const min = speed * 0.7; + const max = speed * 1.3; + const newSpeed = Math.random() * (max - min) + min; + return newSpeed; + } + isMoving(): boolean { return this._speed !== PetSpeed.still; }