Adding an "out-of-bounds" notion for a group.
This allows hiding a group when some players are out of the radius but the group still exists because of the "follow" feature.
This commit is contained in:
parent
524339a3a0
commit
05bedf0c22
@ -219,8 +219,8 @@ export class GameRoom {
|
|||||||
if (user.silent) {
|
if (user.silent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const group = user.group;
|
||||||
if (user.group === undefined) {
|
if (group === undefined) {
|
||||||
// If the user is not part of a group:
|
// If the user is not part of a group:
|
||||||
// should he join a group?
|
// should he join a group?
|
||||||
|
|
||||||
@ -251,18 +251,29 @@ export class GameRoom {
|
|||||||
} else {
|
} else {
|
||||||
// If the user is part of a group:
|
// If the user is part of a group:
|
||||||
// should he leave the group?
|
// should he leave the group?
|
||||||
const users = user.group.getUsers().filter((u) => !u.hasFollowers() && !u.following);
|
let noOneOutOfBounds = true;
|
||||||
users.forEach((foreignUser: User) => {
|
group.getUsers().forEach((foreignUser: User) => {
|
||||||
if (foreignUser.group === undefined) {
|
if (foreignUser.group === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const usrPos = foreignUser.getPosition();
|
const usrPos = foreignUser.getPosition();
|
||||||
const grpPos = foreignUser.group.getPosition();
|
const grpPos = foreignUser.group.getPosition();
|
||||||
const distance = GameRoom.computeDistanceBetweenPositions(usrPos, grpPos);
|
const distance = GameRoom.computeDistanceBetweenPositions(usrPos, grpPos);
|
||||||
|
|
||||||
if (distance > this.groupRadius) {
|
if (distance > this.groupRadius) {
|
||||||
|
if (foreignUser.hasFollowers() || foreignUser.following) {
|
||||||
|
// If one user is out of the group bounds BUT following, the group still exists... but should be hidden.
|
||||||
|
// We put it in 'outOfBounds' mode
|
||||||
|
group.setOutOfBounds(true);
|
||||||
|
noOneOutOfBounds = false;
|
||||||
|
} else {
|
||||||
this.leaveGroup(foreignUser);
|
this.leaveGroup(foreignUser);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
if (noOneOutOfBounds && !user.group?.isEmpty()) {
|
||||||
|
group.setOutOfBounds(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,10 @@ export class Group implements Movable {
|
|||||||
private wasDestroyed: boolean = false;
|
private wasDestroyed: boolean = false;
|
||||||
private roomId: string;
|
private roomId: string;
|
||||||
private currentZone: Zone | null = null;
|
private currentZone: Zone | null = null;
|
||||||
|
/**
|
||||||
|
* When outOfBounds = true, a user if out of the bounds of the group BUT still considered inside it (because we are in following mode)
|
||||||
|
*/
|
||||||
|
private outOfBounds = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
roomId: string,
|
roomId: string,
|
||||||
@ -78,6 +82,10 @@ export class Group implements Movable {
|
|||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
|
||||||
|
if (this.outOfBounds) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (oldX === undefined) {
|
if (oldX === undefined) {
|
||||||
this.currentZone = this.positionNotifier.enter(this);
|
this.currentZone = this.positionNotifier.enter(this);
|
||||||
} else {
|
} else {
|
||||||
@ -154,4 +162,14 @@ export class Group implements Movable {
|
|||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setOutOfBounds(outOfBounds: boolean): void {
|
||||||
|
if (this.outOfBounds === true && outOfBounds === false) {
|
||||||
|
this.positionNotifier.enter(this);
|
||||||
|
this.outOfBounds = false;
|
||||||
|
} else if (this.outOfBounds === false && outOfBounds === true) {
|
||||||
|
this.positionNotifier.leave(this);
|
||||||
|
this.outOfBounds = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user