Make players mobs too !
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
// what mobs decide to do, like minecraft's Goal and GoalSelector. each goal says when it wants to run and which
|
||||
// controls it needs (its flags), and the most important goals that can run get them. a lower priority number is
|
||||
// more important, and can take a flag from a less important goal that's running
|
||||
import { PLAYER_WIDTH } from "$/common/constants.ts";
|
||||
import { ATTRIBUTES } from "./attributes.ts";
|
||||
import { Entity, type PlayerTarget } from "./entity.ts";
|
||||
import { LivingEntity } from "./living_entity.ts";
|
||||
import type { LivingEntity } from "./living_entity.ts";
|
||||
import type { Mob } from "./mob.ts";
|
||||
|
||||
export type GoalFlag = "move" | "look" | "jump" | "target";
|
||||
@@ -196,7 +194,7 @@ export class PanicGoal extends Goal {
|
||||
// looks at a nearby player for a couple of seconds, now and then
|
||||
export class LookAtPlayerGoal extends Goal {
|
||||
override flags: GoalFlag[] = ["look"];
|
||||
#player: PlayerTarget | undefined;
|
||||
#player: LivingEntity | undefined;
|
||||
#ticks = 0;
|
||||
|
||||
constructor(readonly mob: Mob, readonly range = 8, readonly probability = 0.02) {
|
||||
@@ -291,7 +289,7 @@ export class MeleeAttackGoal extends Goal {
|
||||
mob.move_control.move_to(target.x, target.y, target.z, this.speed_modifier);
|
||||
this.#cooldown = Math.max(0, this.#cooldown - 1);
|
||||
// minecraft's reach: its width doubled, squared, plus the target's width
|
||||
const reach = (mob.width * 2) ** 2 + (target instanceof Entity ? target.width : PLAYER_WIDTH);
|
||||
const reach = (mob.width * 2) ** 2 + target.width;
|
||||
const distance = (target.x - mob.x) ** 2 + (target.y - mob.y) ** 2 + (target.z - mob.z) ** 2;
|
||||
if (distance <= reach && this.#cooldown === 0) {
|
||||
this.#cooldown = this.attack_interval;
|
||||
@@ -333,9 +331,8 @@ export class NearestAttackablePlayerGoal extends Goal {
|
||||
}
|
||||
}
|
||||
|
||||
// players are always alive to mobs, they respawn straight away
|
||||
function is_alive(target: LivingEntity | PlayerTarget) {
|
||||
return !(target instanceof LivingEntity) || target.alive;
|
||||
function is_alive(target: LivingEntity) {
|
||||
return target.alive;
|
||||
}
|
||||
|
||||
// somewhere random within range it could stand: solid ground under it, room for its box, and inside its home.
|
||||
|
||||
Reference in New Issue
Block a user