fix(statemachine): 🥅 fix for lookatPlayer when no or invalid player
Fixes the case when player isn't nearby or entity is invalid due to teleport
This commit is contained in:
parent
aded1e4193
commit
42138a421b
|
@ -78,8 +78,9 @@ function init(smName = "dummy", webserver) {
|
||||||
actions: {
|
actions: {
|
||||||
// action implementation
|
// action implementation
|
||||||
lookAtPlayerOnce: (context, event) => {
|
lookAtPlayerOnce: (context, event) => {
|
||||||
const player = context?.player || bot.nearestEntity(entity => entity.type === 'player');
|
const player = context?.player && (context?.player?.isValid || context?.player?.entity?.isValid)
|
||||||
if (player.position || player.entity) {
|
|| bot.nearestEntity(entity => entity.type === 'player');
|
||||||
|
if (player?.position || player?.entity) {
|
||||||
context.player = player;
|
context.player = player;
|
||||||
bot.lookAt((player.entity || player).position.offset(0, 1, 0));
|
bot.lookAt((player.entity || player).position.offset(0, 1, 0));
|
||||||
}
|
}
|
||||||
|
@ -87,9 +88,10 @@ function init(smName = "dummy", webserver) {
|
||||||
},
|
},
|
||||||
activities: {
|
activities: {
|
||||||
lookAtPlayer: (context, event) => {
|
lookAtPlayer: (context, event) => {
|
||||||
const player = context?.player || bot.nearestEntity(entity => entity.type === 'player');
|
const player = (context?.player?.isValid || context?.player?.entity?.isValid) && context?.player
|
||||||
// TODO check every event?
|
|| bot.nearestEntity(entity => entity.type === 'player' && entity.isValid);
|
||||||
if (player.position || player.entity) {
|
// TODO check pos every event?
|
||||||
|
if (player?.position || player?.entity) {
|
||||||
context.player = player;
|
context.player = player;
|
||||||
function looks() {
|
function looks() {
|
||||||
bot.lookAt((player.entity || player).position.offset(0, 1, 0));
|
bot.lookAt((player.entity || player).position.offset(0, 1, 0));
|
||||||
|
@ -97,6 +99,11 @@ function init(smName = "dummy", webserver) {
|
||||||
bot.on("time", looks);
|
bot.on("time", looks);
|
||||||
return () => bot.off("time", looks);
|
return () => bot.off("time", looks);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
quiet || bot.chat("look: no valid players");
|
||||||
|
// TODO use xstate logger
|
||||||
|
context.debug && console.log("sm: no valid player", this, context, player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
delays: {
|
delays: {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user