adjust vision through/into terrain
This commit is contained in:
+5
-7
@@ -500,9 +500,10 @@ export default class Entity {
|
|||||||
const bboxCheckedObstacles = terrains.filter((it) => SATX.bboxCheck(bbox, it.bbox))
|
const bboxCheckedObstacles = terrains.filter((it) => SATX.bboxCheck(bbox, it.bbox))
|
||||||
if (bboxCheckedObstacles.length < 1) { return true }
|
if (bboxCheckedObstacles.length < 1) { return true }
|
||||||
|
|
||||||
const posCollider = Entity.collider(this.position.x, this.position.y, 0)
|
const inWallVisionBypassRadius = Math.max(0, this.radius - 1)
|
||||||
const posBbox = Entity.bbox(this.position.x, this.position.y, 0)
|
const posCollider = Entity.collider(this.position.x, this.position.y, inWallVisionBypassRadius)
|
||||||
const unpassableTerrain = bboxCheckedObstacles.filter((it) => !(SATX.bboxCheck(posBbox, it.bbox) && it.colliders().some((c) => SATX.collideObject(posCollider, c))))
|
const posBbox = Entity.bbox(this.position.x, this.position.y, inWallVisionBypassRadius)
|
||||||
|
const unpassableTerrain = bboxCheckedObstacles.filter((it) => !SATX.bboxCheck(posBbox, it.bbox) || !it.colliders().some((c) => SATX.collideObject(posCollider, c)))
|
||||||
|
|
||||||
const colliders = unpassableTerrain.map((it) => it.colliders()).flat()
|
const colliders = unpassableTerrain.map((it) => it.colliders()).flat()
|
||||||
const collider = Entity.tunnelCollider(this.position.x, this.position.y, destination.x, destination.y, 0)
|
const collider = Entity.tunnelCollider(this.position.x, this.position.y, destination.x, destination.y, 0)
|
||||||
@@ -661,11 +662,8 @@ export default class Entity {
|
|||||||
|
|
||||||
#castingVision() {
|
#castingVision() {
|
||||||
const enemyTeam = this.team == Team.blue ? Team.red : (this.team == Team.red ? Team.blue : null)
|
const enemyTeam = this.team == Team.blue ? Team.red : (this.team == Team.red ? Team.blue : null)
|
||||||
if (enemyTeam == null) {
|
|
||||||
return // only blue/red teams have casting vision
|
|
||||||
}
|
|
||||||
|
|
||||||
const enemiesNearby = (this.game?.entities ?? []).some((it) => !it.dead && it.team == enemyTeam && it.distanceTo(this.position) <= (it.visionRange + this.radius))
|
const enemiesNearby = (this.game?.entities ?? []).some((it) => !it.dead && (enemyTeam == null || it.team == enemyTeam) && it.distanceTo(this.position) <= (it.visionRange + this.radius))
|
||||||
if (enemiesNearby) {
|
if (enemiesNearby) {
|
||||||
const radius = 300
|
const radius = 300
|
||||||
const duration = this.game?.secToTick(2) ?? 0
|
const duration = this.game?.secToTick(2) ?? 0
|
||||||
|
|||||||
+3
-1
@@ -122,8 +122,10 @@ export default class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subscription(websocket, id) {
|
subscription(websocket, id) {
|
||||||
return function builtSubscription() {
|
return function builtSubscription(query = null) {
|
||||||
const game = this
|
const game = this
|
||||||
|
if (query == 'id') { return id }
|
||||||
|
if (query != null) { return }
|
||||||
|
|
||||||
const entity = game.entities.find((it) => it.id == id)
|
const entity = game.entities.find((it) => it.id == id)
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
|
|||||||
+3
-1
@@ -59,6 +59,8 @@ export default class Template {
|
|||||||
|
|
||||||
return function builtBasiliskLogic() {
|
return function builtBasiliskLogic() {
|
||||||
const entity = this
|
const entity = this
|
||||||
|
if (Array.from(entity.game?.subscriptions.values()).some((it) => it('id') == entity.id)) { return }
|
||||||
|
|
||||||
const attackDelaySec = 2
|
const attackDelaySec = 2
|
||||||
const despawnDelaySec = 5
|
const despawnDelaySec = 5
|
||||||
|
|
||||||
@@ -82,7 +84,7 @@ export default class Template {
|
|||||||
|
|
||||||
const attackDelay = entity.game?.secToTick(attackDelaySec) ?? 1
|
const attackDelay = entity.game?.secToTick(attackDelaySec) ?? 1
|
||||||
if (targetInRangeSince + attackDelay < timestamp) {
|
if (targetInRangeSince + attackDelay < timestamp) {
|
||||||
entity.attackAction(target.position)
|
entity.castAction('a', target.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
const directionToTarget = target.position.clone().sub(entity.position).normalize()
|
const directionToTarget = target.position.clone().sub(entity.position).normalize()
|
||||||
|
|||||||
Reference in New Issue
Block a user