Do not leave group when following is active
This commit is contained in:
@@ -139,6 +139,7 @@ export class GameRoom {
|
||||
joinRoomMessage.getIpaddress(),
|
||||
position,
|
||||
false,
|
||||
[],
|
||||
this.positionNotifier,
|
||||
socket,
|
||||
joinRoomMessage.getTagList(),
|
||||
@@ -231,7 +232,7 @@ export class GameRoom {
|
||||
// If the user is part of a group:
|
||||
// should he leave the group?
|
||||
const distance = GameRoom.computeDistanceBetweenPositions(user.getPosition(), user.group.getPosition());
|
||||
if (distance > this.groupRadius) {
|
||||
if (user.following.length === 0 && distance > this.groupRadius) {
|
||||
this.leaveGroup(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ export class User implements Movable {
|
||||
public readonly IPAddress: string,
|
||||
private position: PointInterface,
|
||||
public silent: boolean,
|
||||
public following: string[],
|
||||
private positionNotifier: PositionNotifier,
|
||||
public readonly socket: UserSocket,
|
||||
public readonly tags: string[],
|
||||
@@ -48,6 +49,21 @@ export class User implements Movable {
|
||||
this.positionNotifier.updatePosition(this, position, oldPosition);
|
||||
}
|
||||
|
||||
public addFollower(name: string): void {
|
||||
if (this.following.includes(name)) {
|
||||
return;
|
||||
}
|
||||
this.following.push(name);
|
||||
}
|
||||
|
||||
public delFollower(name: string): void {
|
||||
const idx = this.following.indexOf(name);
|
||||
if (idx === -1) {
|
||||
return;
|
||||
}
|
||||
this.following.splice(idx, 1);
|
||||
}
|
||||
|
||||
private batchedMessages: BatchMessage = new BatchMessage();
|
||||
private batchTimeout: NodeJS.Timeout | null = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user