|
@@ -37,7 +37,7 @@ export class MoveService implements OnModuleInit {
|
|
|
private cacheService: CacheService,
|
|
|
private rotateService: RotateService,
|
|
|
private configService: ConfigService,
|
|
|
- ) { }
|
|
|
+ ) {}
|
|
|
private logger: Logger = new Logger('MoveService');
|
|
|
private Actions = {
|
|
|
Clicking: 1,
|
|
@@ -198,62 +198,19 @@ export class MoveService implements OnModuleInit {
|
|
|
const replys = [];
|
|
|
const traceIds = [];
|
|
|
traceIds.push(traceId);
|
|
|
- /*
|
|
|
- //纠正,旋转传到缓存里
|
|
|
- const checkReplys = [];
|
|
|
- // console.log('矫正: ' + angle + ' 度');
|
|
|
- if (angle > 22) {
|
|
|
- angle = 45 - angle;
|
|
|
- for (let i = 0; i < angle; ++i) {
|
|
|
- // console.warn('矫正一次:' + i);
|
|
|
- const reply = await this.rotateService.rotateForAngle(userId, 1);
|
|
|
- // console.warn(
|
|
|
- // '矫正:' + reply.newUserStates[0].playerState.camera.angle.yaw,
|
|
|
- // );
|
|
|
- reply.traceIds = [];
|
|
|
- reply.traceIds.push(traceId);
|
|
|
- const actionResponse = this.rotateService.createActionResponse(
|
|
|
- actionType,
|
|
|
- traceId,
|
|
|
- );
|
|
|
- reply.actionResponses = [];
|
|
|
- reply.actionResponses.push(actionResponse);
|
|
|
- checkReplys.push(reply);
|
|
|
- }
|
|
|
- } else if (angle != 0) {
|
|
|
- for (let i = angle; i > -1; --i) {
|
|
|
- // console.warn('矫正一次:' + i);
|
|
|
- const reply = await this.rotateService.rotateForAngle(userId, -1);
|
|
|
- // console.warn(
|
|
|
- // '矫正:' + reply.newUserStates[0].playerState.camera.angle.yaw,
|
|
|
- // );
|
|
|
- reply.traceIds = [];
|
|
|
- reply.traceIds.push(traceId);
|
|
|
- const actionResponse = this.rotateService.createActionResponse(
|
|
|
- actionType,
|
|
|
- traceId,
|
|
|
- );
|
|
|
- reply.actionResponses = [];
|
|
|
- reply.actionResponses.push(actionResponse);
|
|
|
- checkReplys.push(reply);
|
|
|
- }
|
|
|
- }
|
|
|
- */
|
|
|
+
|
|
|
const checkReplys = await this.modeifyCameraAngle(
|
|
|
angle,
|
|
|
userId,
|
|
|
traceId,
|
|
|
actionType,
|
|
|
);
|
|
|
+ for (let i = 0; i < checkReplys.length; ++i) {
|
|
|
+ checkReplys[i].actionResponses[0].actionType = actionType;
|
|
|
+ }
|
|
|
//replys['P' + user.breakPointId + 'T' + user.breakPointId] = checkReplys;
|
|
|
replys.push(checkReplys);
|
|
|
- if (checkReplys.length > 0) {
|
|
|
- console.log(
|
|
|
- 'move-1' +
|
|
|
- checkReplys[checkReplys.length - 1].newUserStates[0].playerState
|
|
|
- .camera.angle.yaw,
|
|
|
- );
|
|
|
- }
|
|
|
+
|
|
|
//过渡传到缓存里
|
|
|
this.reply.traceIds = traceIds;
|
|
|
this.reply['newUserStates'][0].userId = userId;
|
|
@@ -293,6 +250,9 @@ export class MoveService implements OnModuleInit {
|
|
|
'newUserStates'
|
|
|
][0].renderInfo.isMoving = 0;
|
|
|
}
|
|
|
+ for (let j = 0; j < pathReplys.length; ++j) {
|
|
|
+ pathReplys[j].actionResponses[0].actionType = actionType;
|
|
|
+ }
|
|
|
replys.push(pathReplys);
|
|
|
//replys['P' + start_break_point_id + 'T' + end_break_point_id] =pathReplys;
|
|
|
}
|
|
@@ -750,30 +710,11 @@ export class MoveService implements OnModuleInit {
|
|
|
traceId,
|
|
|
actionType,
|
|
|
);
|
|
|
- // //投影
|
|
|
- // let player_Position = this.getTarget(
|
|
|
- // playerPosition,
|
|
|
- // breakPoint.position,
|
|
|
- // neighPoints[0].position,
|
|
|
- // );
|
|
|
- // if (player_Position != null) {
|
|
|
- // playerPosition.x = player_Position.x;
|
|
|
- // player_Position.y = player_Position.y;
|
|
|
- // user.player.position = JSON.parse(JSON.stringify(playerPosition));
|
|
|
- // }
|
|
|
-
|
|
|
- // if (this.getDistance(playerPosition, breakPoint.position) > closestDis) {
|
|
|
- // debugger;
|
|
|
- // return await this.moveCamera(breakPointId,neighPoints[0].breakPointId,appId,userId,traceId,actionType);
|
|
|
- // }
|
|
|
- // else{
|
|
|
- // this.reply['newUserStates'][0].playerState.player.position = JSON.parse(JSON.stringify(user.player.position));
|
|
|
- // return this.reply;
|
|
|
- // }
|
|
|
} else if (count == 0) {
|
|
|
this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
|
|
|
JSON.stringify(user.player.position),
|
|
|
);
|
|
|
+ this.reply.actionResponses[0].actionType = actionType;
|
|
|
return this.reply;
|
|
|
}
|
|
|
|
|
@@ -789,14 +730,32 @@ export class MoveService implements OnModuleInit {
|
|
|
playerPosition,
|
|
|
);
|
|
|
//角度是45的倍数
|
|
|
- if (_angle % 45 == 0) {
|
|
|
- chooseBreakPointId = neighPoints[0].breakPointId;
|
|
|
- } else if (
|
|
|
- //this.getDistance(playerPosition, neighPoints[0].position) >
|
|
|
- //this.getDistance(playerPosition, neighPoints[1].position)
|
|
|
- Math.abs(_angle - neighPoints[0].angle) >
|
|
|
- Math.abs(_angle - neighPoints[1].angle)
|
|
|
- ) {
|
|
|
+ // if (_angle % 45 == 0) {
|
|
|
+ // chooseBreakPointId = neighPoints[0].breakPointId;
|
|
|
+ // } else if (
|
|
|
+ console.log(
|
|
|
+ 'joystick-breakPointId:' +
|
|
|
+ _angle +
|
|
|
+ ',' +
|
|
|
+ neighPoints[0].angle +
|
|
|
+ ',' +
|
|
|
+ neighPoints[0].breakPointId +
|
|
|
+ ',' +
|
|
|
+ neighPoints[1].angle +
|
|
|
+ ',' +
|
|
|
+ neighPoints[1].breakPointId,
|
|
|
+ );
|
|
|
+ let offsetAngle1 = Math.abs(_angle - neighPoints[0].angle);
|
|
|
+ if (neighPoints[0].angle == 0) {
|
|
|
+ offsetAngle1 = Math.min(offsetAngle1, Math.abs(_angle - 360));
|
|
|
+ }
|
|
|
+
|
|
|
+ let offsetAngle2 = Math.abs(_angle - neighPoints[1].angle);
|
|
|
+ if (neighPoints[1].angle == 0) {
|
|
|
+ offsetAngle2 = Math.min(offsetAngle2, Math.abs(_angle - 360));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (offsetAngle1 > offsetAngle2) {
|
|
|
chooseBreakPointId = neighPoints[1].breakPointId;
|
|
|
} else {
|
|
|
chooseBreakPointId = neighPoints[0].breakPointId;
|
|
@@ -815,6 +774,7 @@ export class MoveService implements OnModuleInit {
|
|
|
this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
|
|
|
JSON.stringify(user.player.position),
|
|
|
);
|
|
|
+ this.reply.actionResponses[0].actionType = actionType;
|
|
|
return this.reply;
|
|
|
}
|
|
|
} catch (error) {
|
|
@@ -849,7 +809,6 @@ export class MoveService implements OnModuleInit {
|
|
|
}
|
|
|
|
|
|
if (this.getDistance(playerPosition, breakPoint.position) > closestDis) {
|
|
|
- //return await this.moveCamera(breakPointId,surroundPointIds[0],appId,userId,traceId,actionType);
|
|
|
return await this.moveCamera(
|
|
|
breakPointId,
|
|
|
neighBreakPointId,
|
|
@@ -862,6 +821,7 @@ export class MoveService implements OnModuleInit {
|
|
|
this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
|
|
|
JSON.stringify(user.player.position),
|
|
|
);
|
|
|
+ this.reply.actionResponses[0].actionType = actionType;
|
|
|
return this.reply;
|
|
|
}
|
|
|
}
|
|
@@ -879,7 +839,7 @@ export class MoveService implements OnModuleInit {
|
|
|
this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
|
|
|
JSON.stringify(user.player.position),
|
|
|
);
|
|
|
- console.log('joystick-2:');
|
|
|
+ this.reply.actionResponses[0].actionType = actionType;
|
|
|
return this.reply;
|
|
|
}
|
|
|
//判断人物离该邻接点的距离是否在最小路径内,如果是,跳到这个邻接点里
|
|
@@ -901,6 +861,9 @@ export class MoveService implements OnModuleInit {
|
|
|
traceId,
|
|
|
actionType,
|
|
|
);
|
|
|
+ for (let i = 0; i < checkReplys.length; ++i) {
|
|
|
+ checkReplys[i].actionResponses[0].actionType = actionType;
|
|
|
+ }
|
|
|
replys.push(checkReplys);
|
|
|
|
|
|
//读redis里的数据,按照frame_index的大小排序
|
|
@@ -924,6 +887,9 @@ export class MoveService implements OnModuleInit {
|
|
|
chooseBreakPointId,
|
|
|
true,
|
|
|
);
|
|
|
+ for (let i = 0; i < pathReplys.length; ++i) {
|
|
|
+ pathReplys[i].actionResponses[0].actionType = actionType;
|
|
|
+ }
|
|
|
replys.push(pathReplys);
|
|
|
user.breakPointId = chooseBreakPointId;
|
|
|
const lastFrame = moveFrames[moveFrames.length - 1];
|
|
@@ -931,7 +897,6 @@ export class MoveService implements OnModuleInit {
|
|
|
JSON.stringify(lastFrame.camera_position),
|
|
|
);
|
|
|
user.camera.angle.yaw = lastFrame.camera_angle.yaw;
|
|
|
- console.log('joystick-4:');
|
|
|
return replys;
|
|
|
}
|
|
|
}
|
|
@@ -991,7 +956,7 @@ export class MoveService implements OnModuleInit {
|
|
|
getDistance(position1, position2) {
|
|
|
return Math.sqrt(
|
|
|
(position1.x - position2.x) * (position1.x - position2.x) +
|
|
|
- (position1.y - position2.y) * (position1.y - position2.y),
|
|
|
+ (position1.y - position2.y) * (position1.y - position2.y),
|
|
|
);
|
|
|
}
|
|
|
|