diff --git a/Engine/src/live/AnimalEntity.ts b/Engine/src/live/AnimalEntity.ts index 36c8a8c..a931cae 100644 --- a/Engine/src/live/AnimalEntity.ts +++ b/Engine/src/live/AnimalEntity.ts @@ -190,51 +190,59 @@ export class AnimalEntity extends Entity { think(delta: number) { this.thinkTimer += delta while (this.thinkTimer >= 100) { - if (!this.isMonster) { - if (this.seenTarget) { - let r = Math.atan2(this.y-(this.seenTarget.y+10), this.x-this.seenTarget.x) // FIXME: 10 ain't right son - let a = r * (180 / Math.PI) - if (a < 0) { - a += 360 - } + if (this.seenTarget && this.isMonster && planck.Vec2.distance(planck.Vec2(this.x, this.y), planck.Vec2(this.seenTarget.x, this.seenTarget.y)) < 35) { + this.desiredActions = adjustAction([], 'attack', 1) + if (Math.random() > 1 - this.mode.laziness/4) { + this.desiredActions = [] + } + } else if (this.seenTarget) { + let r = Math.atan2(this.y-(this.seenTarget.y+10), this.x-this.seenTarget.x) // FIXME: 10 ain't right son + let a = r * (180 / Math.PI) + if (a < 0) { + a += 360 + } + // Invert direction if not a monster. + if (!this.isMonster) { a -= 180 - if (a < 0) { - a = 360 - a - } + } + if (a < 0) { + a = 360 - a + } + this.desiredActions = adjustAction([], this.getCardinal(a), 0.85) + this.desiredActions = adjustAction(this.desiredActions, this.getCardinal(Math.random()*360), Math.random()) + if (Math.random() > 1 - this.mode.erratic) { + this.desiredActions = adjustAction(this.desiredActions, this.getCardinal(Math.random()*360), 1) + } + this.yell(1) + } else if (this.smelledTarget) { + let r = Math.atan2(this.y-this.smelledTarget.y, this.x-this.smelledTarget.x) + let a = r * (180 / Math.PI) + if (a < 0) { + a += 360 + } + if (!this.isMonster) { + a -= 180 + } + if (a < 0) { + a = 360 - a + } + // 5% to walk away, otherwise just chill. + if (Math.random() > 0.95) { this.desiredActions = adjustAction([], this.getCardinal(a), 0.85) - this.desiredActions = adjustAction(this.desiredActions, this.getCardinal(Math.random()*360), Math.random()) - if (Math.random() > 1 - this.mode.erratic) { - this.desiredActions = adjustAction(this.desiredActions, this.getCardinal(Math.random()*360), 1) + } + } else { + this.wanderTimer += delta + if (this.wanderTimer >= this.nextWander) { + this.nextWander = Math.max(10, Math.random() * 100) + if (Math.random() > 1 - this.mode.laziness) { + this.desiredActions = [] + } else { + this.desiredActions = adjustAction([], this.getCardinal(Math.random()*360), 1) } - this.yell(1) - } else if (this.smelledTarget) { - let r = Math.atan2(this.y-this.smelledTarget.y, this.x-this.smelledTarget.x) - let a = r * (180 / Math.PI) - if (a < 0) { - a += 360 - } - a -= 180 - if (a < 0) { - a = 360 - a - } - // 5% to walk away, otherwise just chill. - if (Math.random() > 0.95) { - this.desiredActions = adjustAction([], this.getCardinal(a), 0.85) - } - } else { - this.wanderTimer += delta - if (this.wanderTimer >= this.nextWander) { - this.nextWander = Math.max(10, Math.random() * 100) - if (Math.random() > 1 - this.mode.laziness) { - this.desiredActions = [] - } else { - this.desiredActions = adjustAction([], this.getCardinal(Math.random()*360), 1) - } - if (Math.random() > 1 - this.mode.noisiness) { - this.yell(0.1) - } - this.wanderTimer = 0 + if (Math.random() > 1 - this.mode.noisiness) { + this.yell(0.1) } + this.wanderTimer = 0 } } this.thinkTimer -= 100