|
@@ -128,6 +128,8 @@ export class MoveService implements OnModuleInit {
|
|
|
};
|
|
|
private breakPointInfo: any;
|
|
|
|
|
|
+ private cameraInfos = [];
|
|
|
+
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
|
async onModuleInit() {
|
|
|
const app_id = '0000000003';
|
|
@@ -433,13 +435,14 @@ export class MoveService implements OnModuleInit {
|
|
|
const user = this.users[userId];
|
|
|
user.breakPointId = breakPointId;
|
|
|
|
|
|
- user.player.position =
|
|
|
- lastReply['newUserStates'][0].playerState.player.position;
|
|
|
+ if(lastReply.actionResponses[0].actionType != 15)
|
|
|
+ {
|
|
|
+ user.player.position = lastReply['newUserStates'][0].playerState.player.position;
|
|
|
+ }
|
|
|
user.player.angle = lastReply['newUserStates'][0].playerState.player.angle;
|
|
|
user.camera.position =
|
|
|
lastReply['newUserStates'][0].playerState.camera.position;
|
|
|
user.camera.angle = lastReply['newUserStates'][0].playerState.camera.angle;
|
|
|
- console.log('rotateForAngle-1:' + user.breakPointId);
|
|
|
}
|
|
|
|
|
|
getBreakPoints(actionRequest) {
|
|
@@ -553,12 +556,226 @@ export class MoveService implements OnModuleInit {
|
|
|
reply.startBreakPointId = startBreakPointId;
|
|
|
reply.endBreakPointId = breakPointId;
|
|
|
reply['newUserStates'][0].renderInfo.isMoving = 0;
|
|
|
- console.log('rotateForAngle-2:' + user.breakPointId);
|
|
|
return reply;
|
|
|
}
|
|
|
// 顺序旋转请求
|
|
|
seqExeJoystick = seqExeAsyncFn(this.joystick);
|
|
|
|
|
|
+ // async joystick(actionRequest) {
|
|
|
+ // try {
|
|
|
+ // const userId = actionRequest['user_id'];
|
|
|
+ // const traceId = actionRequest['trace_id'];
|
|
|
+ // const dir_action = actionRequest['dir_action'];
|
|
|
+ // const actionType = actionRequest['action_type'];
|
|
|
+ // const user = this.users[userId];
|
|
|
+ // const breakPointId = user.breakPointId;
|
|
|
+ // const appId = user.appId;
|
|
|
+
|
|
|
+ // const replys = [];
|
|
|
+ // const step = 0.3;
|
|
|
+ // const closestDis = 85; //小于这个距离就跳到邻居呼吸点
|
|
|
+ // const distance = step * dir_action.speed_level;
|
|
|
+ // let angle = null;
|
|
|
+ // let move_angle = dir_action.move_angle + user.camera.angle.yaw;
|
|
|
+ // move_angle = move_angle % 360;
|
|
|
+
|
|
|
+ // //TODO 临时增加断言
|
|
|
+ // const playerPosition: Point = { x: 0, y: 0, z: 0 };
|
|
|
+ // playerPosition.x =
|
|
|
+ // user.player.position.x +
|
|
|
+ // distance * Math.cos((move_angle / 360) * 2 * Math.PI);
|
|
|
+ // playerPosition.y =
|
|
|
+ // user.player.position.y +
|
|
|
+ // distance * Math.sin((move_angle / 360) * 2 * Math.PI);
|
|
|
+
|
|
|
+ // //找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
|
|
|
+ // let chooseBreakPointId = null;
|
|
|
+ // const breakPoint = this.breakPointInfo[breakPointId];
|
|
|
+ // const surroundPointIds = breakPoint.contact;
|
|
|
+ // //const neighAngles = [];
|
|
|
+ // const traceIds = [];
|
|
|
+
|
|
|
+ // user.player.angle.yaw = move_angle;
|
|
|
+ // traceIds.push(traceId);
|
|
|
+ // this.reply.traceIds = traceIds;
|
|
|
+ // this.reply['newUserStates'][0].userId = userId;
|
|
|
+ // this.reply['actionResponses'][0].traceId = traceId;
|
|
|
+ // this.reply['newUserStates'][0].playerState.player.angle.yaw = move_angle;
|
|
|
+
|
|
|
+ // this.reply['newUserStates'][0].playerState.camera.angle = JSON.parse(
|
|
|
+ // JSON.stringify(user.camera.angle),
|
|
|
+ // );
|
|
|
+ // this.reply['newUserStates'][0].playerState.camera.position = JSON.parse(
|
|
|
+ // JSON.stringify(user.camera.position),
|
|
|
+ // );
|
|
|
+ // this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
|
|
|
+ // JSON.stringify(breakPoint.position),
|
|
|
+ // );
|
|
|
+ // this.reply['newUserStates'][0].renderInfo.isMoving = 1;
|
|
|
+ // this.reply['actionResponses'][0].traceId = traceId;
|
|
|
+ // this.reply.mediaSrc = null;
|
|
|
+
|
|
|
+ // if (surroundPointIds.length == 1) {
|
|
|
+ // return await this.moveDirect(
|
|
|
+ // playerPosition,
|
|
|
+ // closestDis,
|
|
|
+ // breakPointId,
|
|
|
+ // surroundPointIds[0],
|
|
|
+ // appId,
|
|
|
+ // userId,
|
|
|
+ // traceId,
|
|
|
+ // actionType,
|
|
|
+ // );
|
|
|
+ // }
|
|
|
+
|
|
|
+ // let count = 0;
|
|
|
+ // const neighPoints = [];
|
|
|
+ // //人在哪个角度
|
|
|
+ // let _angle = this.getAngle(
|
|
|
+ // breakPoint.position,
|
|
|
+ // { x: breakPoint.position.x + 1, y: breakPoint.position.y },
|
|
|
+ // playerPosition,
|
|
|
+ // );
|
|
|
+ // if (_angle < 0) {
|
|
|
+ // _angle += 360;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // let singleInfo = null;
|
|
|
+ // for (let i = 0; i < surroundPointIds.length; ++i) {
|
|
|
+ // const neighPoint = this.breakPointInfo[surroundPointIds[i]];
|
|
|
+ // neighPoint.breakPointId = surroundPointIds[i];
|
|
|
+ // angle = this.getAngle(
|
|
|
+ // breakPoint.position,
|
|
|
+ // { x: breakPoint.position.x + 1, y: breakPoint.position.y },
|
|
|
+ // neighPoint.position,
|
|
|
+ // );
|
|
|
+ // if (angle < 0) {
|
|
|
+ // angle += 360;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // //if(angle<45&&angle!=0){
|
|
|
+ // if (
|
|
|
+ // // Math.abs(angle - move_angle) < 45 &&
|
|
|
+ // // Math.abs(angle - move_angle) != 0
|
|
|
+ // Math.abs(angle - _angle) < 45 &&
|
|
|
+ // Math.abs(angle - _angle) != 0
|
|
|
+ // ) {
|
|
|
+ // neighPoint.angle = angle;
|
|
|
+ // neighPoints.push(neighPoint);
|
|
|
+ // ++count;
|
|
|
+ // } else if (Math.abs(angle - move_angle) == 0) {
|
|
|
+ // return await this.moveDirect(
|
|
|
+ // playerPosition,
|
|
|
+ // closestDis,
|
|
|
+ // breakPointId,
|
|
|
+ // surroundPointIds[i],
|
|
|
+ // appId,
|
|
|
+ // userId,
|
|
|
+ // traceId,
|
|
|
+ // actionType,
|
|
|
+ // );
|
|
|
+ // }
|
|
|
+
|
|
|
+ // //if (angle == 0 && Math.abs(360 - move_angle) < 45) {
|
|
|
+ // if (angle == 0 && Math.abs(360 - _angle) < 45) {
|
|
|
+ // neighPoint.angle = angle;
|
|
|
+ // neighPoints.push(neighPoint);
|
|
|
+ // ++count;
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+ // if(Math.abs(angle - move_angle)<45||Math.abs(angle+360 - move_angle)<45){
|
|
|
+ // if(singleInfo == null){
|
|
|
+ // singleInfo = {
|
|
|
+ // angle:angle,
|
|
|
+ // breakPointId:surroundPointIds[i]
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (count == 2) {
|
|
|
+ // //人物移动
|
|
|
+ // user.player.position = JSON.parse(JSON.stringify(playerPosition));
|
|
|
+ // this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
|
|
|
+ // JSON.stringify(playerPosition),
|
|
|
+ // );
|
|
|
+ // }
|
|
|
+ // else{
|
|
|
+ // if(singleInfo != null){
|
|
|
+ // return await this.moveDirect(
|
|
|
+ // playerPosition,
|
|
|
+ // closestDis,
|
|
|
+ // breakPointId,
|
|
|
+ // singleInfo.breakPointId,
|
|
|
+ // appId,
|
|
|
+ // userId,
|
|
|
+ // traceId,
|
|
|
+ // actionType,
|
|
|
+ // );
|
|
|
+ // }
|
|
|
+ // else if (count == 1) {
|
|
|
+ // return await this.moveDirect(
|
|
|
+ // playerPosition,
|
|
|
+ // closestDis,
|
|
|
+ // breakPointId,
|
|
|
+ // neighPoints[0].breakPointId,
|
|
|
+ // appId,
|
|
|
+ // userId,
|
|
|
+ // traceId,
|
|
|
+ // actionType,
|
|
|
+ // );
|
|
|
+ // }
|
|
|
+ // 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;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // //count == 2
|
|
|
+ // //超出范围了
|
|
|
+ // if (this.getDistance(playerPosition, breakPoint.position) > closestDis) {
|
|
|
+ // 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;
|
|
|
+ // }
|
|
|
+ // return await this.moveCamera(
|
|
|
+ // breakPointId,
|
|
|
+ // chooseBreakPointId,
|
|
|
+ // appId,
|
|
|
+ // userId,
|
|
|
+ // traceId,
|
|
|
+ // actionType,
|
|
|
+ // );
|
|
|
+ // } else {
|
|
|
+ // user.player.position = JSON.parse(JSON.stringify(playerPosition));
|
|
|
+ // 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) {
|
|
|
+ // console.log('MoveService', error);
|
|
|
+ // debugger;
|
|
|
+ // return null;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
async joystick(actionRequest) {
|
|
|
try {
|
|
|
const userId = actionRequest['user_id'];
|
|
@@ -569,13 +786,13 @@ export class MoveService implements OnModuleInit {
|
|
|
const breakPointId = user.breakPointId;
|
|
|
const appId = user.appId;
|
|
|
|
|
|
- const replys = [];
|
|
|
const step = 0.3;
|
|
|
- const closestDis = 90; //小于这个距离就跳到邻居呼吸点
|
|
|
+ const closestDis = 85; //小于这个距离就跳到邻居呼吸点
|
|
|
const distance = step * dir_action.speed_level;
|
|
|
let angle = null;
|
|
|
let move_angle = dir_action.move_angle + user.camera.angle.yaw;
|
|
|
move_angle = move_angle % 360;
|
|
|
+
|
|
|
//TODO 临时增加断言
|
|
|
const playerPosition: Point = { x: 0, y: 0, z: 0 };
|
|
|
playerPosition.x =
|
|
@@ -589,7 +806,6 @@ export class MoveService implements OnModuleInit {
|
|
|
let chooseBreakPointId = null;
|
|
|
const breakPoint = this.breakPointInfo[breakPointId];
|
|
|
const surroundPointIds = breakPoint.contact;
|
|
|
- //const neighAngles = [];
|
|
|
const traceIds = [];
|
|
|
|
|
|
user.player.angle.yaw = move_angle;
|
|
@@ -612,18 +828,8 @@ export class MoveService implements OnModuleInit {
|
|
|
this.reply['actionResponses'][0].traceId = traceId;
|
|
|
this.reply.mediaSrc = null;
|
|
|
|
|
|
- //方向不对的话,人物不能走动,只是修改朝向
|
|
|
- // 找到和角度最贴近的邻居点
|
|
|
- let _angle = this.getAngle(
|
|
|
- breakPoint.position,
|
|
|
- {
|
|
|
- x: this.breakPointInfo[surroundPointIds[0]].position.x,
|
|
|
- y: this.breakPointInfo[surroundPointIds[0]].position.y,
|
|
|
- },
|
|
|
- playerPosition,
|
|
|
- );
|
|
|
-
|
|
|
if (surroundPointIds.length == 1) {
|
|
|
+ console.log('joystick校验--->'+breakPointId+'-'+surroundPointIds[0]);
|
|
|
return await this.moveDirect(
|
|
|
playerPosition,
|
|
|
closestDis,
|
|
@@ -635,40 +841,41 @@ export class MoveService implements OnModuleInit {
|
|
|
actionType,
|
|
|
);
|
|
|
}
|
|
|
- //判断_angle与angle的差在45以内的个数,两个的话表示可以走
|
|
|
+
|
|
|
let count = 0;
|
|
|
const neighPoints = [];
|
|
|
- // _angle = this.getAngle(
|
|
|
- // user.player.position,
|
|
|
- // { x: user.player.position.x + 1, y: user.player.position.y },
|
|
|
- // playerPosition,
|
|
|
- // );
|
|
|
- // if (_angle < 0) {
|
|
|
- // _angle += 360;
|
|
|
- // }
|
|
|
+ //人在哪个角度
|
|
|
+ let _angle = this.getAngle(
|
|
|
+ breakPoint.position,
|
|
|
+ { x: breakPoint.position.x + 1, y: breakPoint.position.y },
|
|
|
+ playerPosition,
|
|
|
+ );
|
|
|
+ if (_angle < 0) {
|
|
|
+ _angle += 360;
|
|
|
+ }
|
|
|
|
|
|
+ let singleInfo = null;
|
|
|
for (let i = 0; i < surroundPointIds.length; ++i) {
|
|
|
const neighPoint = this.breakPointInfo[surroundPointIds[i]];
|
|
|
neighPoint.breakPointId = surroundPointIds[i];
|
|
|
angle = this.getAngle(
|
|
|
breakPoint.position,
|
|
|
{ x: breakPoint.position.x + 1, y: breakPoint.position.y },
|
|
|
- //playerPosition,
|
|
|
neighPoint.position,
|
|
|
);
|
|
|
- if (angle < 0) {
|
|
|
- angle += 360;
|
|
|
- }
|
|
|
|
|
|
//if(angle<45&&angle!=0){
|
|
|
if (
|
|
|
- Math.abs(angle - move_angle) < 45 &&
|
|
|
- Math.abs(angle - move_angle) != 0
|
|
|
+ // Math.abs(angle - move_angle) < 45 &&
|
|
|
+ // Math.abs(angle - move_angle) != 0
|
|
|
+ Math.abs(angle - _angle) < 45 &&
|
|
|
+ Math.abs(angle - _angle) != 0
|
|
|
) {
|
|
|
neighPoint.angle = angle;
|
|
|
neighPoints.push(neighPoint);
|
|
|
++count;
|
|
|
} else if (Math.abs(angle - move_angle) == 0) {
|
|
|
+ console.log('joystick直走--->'+breakPointId+'-'+surroundPointIds[i]);
|
|
|
return await this.moveDirect(
|
|
|
playerPosition,
|
|
|
closestDis,
|
|
@@ -681,27 +888,21 @@ export class MoveService implements OnModuleInit {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- if (angle == 0 && Math.abs(360 - move_angle) < 45) {
|
|
|
+ //if (angle == 0 && Math.abs(360 - move_angle) < 45) {
|
|
|
+ if (angle == 0 && Math.abs(360 - _angle) < 45) {
|
|
|
neighPoint.angle = angle;
|
|
|
neighPoints.push(neighPoint);
|
|
|
++count;
|
|
|
}
|
|
|
- /*
|
|
|
- //neighAngles.push(angle);
|
|
|
- if (Math.abs(angle - _angle) < 45) {
|
|
|
- neighPoint.angle = angle;
|
|
|
- neighPoints.push(neighPoint);
|
|
|
- ++count;
|
|
|
- } else if (angle == 0 && _angle > 315) {
|
|
|
- neighPoint.angle = angle;
|
|
|
- neighPoints.push(neighPoint);
|
|
|
- ++count;
|
|
|
- } else if (Math.abs(angle - _angle) == 0) {
|
|
|
- neighPoint.angle = angle;
|
|
|
- neighPoints.push(neighPoint);
|
|
|
- ++count;
|
|
|
+
|
|
|
+ if(Math.abs(angle - move_angle)<45||Math.abs(angle+360 - move_angle)<45){
|
|
|
+ if(singleInfo == null){
|
|
|
+ singleInfo = {
|
|
|
+ angle:angle,
|
|
|
+ breakPointId:surroundPointIds[i]
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- */
|
|
|
}
|
|
|
|
|
|
if (count == 2) {
|
|
@@ -710,52 +911,46 @@ export class MoveService implements OnModuleInit {
|
|
|
this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
|
|
|
JSON.stringify(playerPosition),
|
|
|
);
|
|
|
- } else if (count == 1) {
|
|
|
- return await this.moveDirect(
|
|
|
- playerPosition,
|
|
|
- closestDis,
|
|
|
- breakPointId,
|
|
|
- neighPoints[0].breakPointId,
|
|
|
- appId,
|
|
|
- userId,
|
|
|
- traceId,
|
|
|
- actionType,
|
|
|
- );
|
|
|
- } 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;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ if(singleInfo != null){
|
|
|
+ console.log('joystick校验--->'+breakPointId+'-'+singleInfo.breakPointId);
|
|
|
+ return await this.moveDirect(
|
|
|
+ playerPosition,
|
|
|
+ closestDis,
|
|
|
+ breakPointId,
|
|
|
+ singleInfo.breakPointId,
|
|
|
+ appId,
|
|
|
+ userId,
|
|
|
+ traceId,
|
|
|
+ actionType,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ else if (count == 1) {
|
|
|
+ console.log('joystick校验--->'+breakPointId+'-'+neighPoints[0].breakPointId);
|
|
|
+ return await this.moveDirect(
|
|
|
+ playerPosition,
|
|
|
+ closestDis,
|
|
|
+ breakPointId,
|
|
|
+ neighPoints[0].breakPointId,
|
|
|
+ appId,
|
|
|
+ userId,
|
|
|
+ traceId,
|
|
|
+ actionType,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//count == 2
|
|
|
//超出范围了
|
|
|
if (this.getDistance(playerPosition, breakPoint.position) > closestDis) {
|
|
|
- _angle = this.getAngle(
|
|
|
- breakPoint.position,
|
|
|
- {
|
|
|
- x: breakPoint.position.x + 1,
|
|
|
- y: breakPoint.position.y,
|
|
|
- },
|
|
|
- playerPosition,
|
|
|
- );
|
|
|
- //角度是45的倍数
|
|
|
- // 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));
|
|
@@ -771,6 +966,7 @@ export class MoveService implements OnModuleInit {
|
|
|
} else {
|
|
|
chooseBreakPointId = neighPoints[0].breakPointId;
|
|
|
}
|
|
|
+ console.log('joystick镜头过渡--->'+breakPointId+'-'+chooseBreakPointId);
|
|
|
return await this.moveCamera(
|
|
|
breakPointId,
|
|
|
chooseBreakPointId,
|
|
@@ -780,12 +976,20 @@ export class MoveService implements OnModuleInit {
|
|
|
actionType,
|
|
|
);
|
|
|
} else {
|
|
|
- console.log('joystick-1:');
|
|
|
user.player.position = JSON.parse(JSON.stringify(playerPosition));
|
|
|
this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
|
|
|
JSON.stringify(user.player.position),
|
|
|
);
|
|
|
this.reply.actionResponses[0].actionType = actionType;
|
|
|
+ const cameraInfo = this.getCameraInfo();
|
|
|
+ if(cameraInfo != null){
|
|
|
+ console.log('joystick自由--->合并');
|
|
|
+ this.reply['newUserStates'][0].playerState.camera.position = cameraInfo.cameraPosition;
|
|
|
+ this.reply['newUserStates'][0].playerState.camera.angle = cameraInfo.cameraAngle;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ console.log('joystick自由--->不合并');
|
|
|
+ }
|
|
|
return this.reply;
|
|
|
}
|
|
|
} catch (error) {
|
|
@@ -795,6 +999,7 @@ export class MoveService implements OnModuleInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //沿着最合适的neighBreakPointId走
|
|
|
async moveDirect(
|
|
|
playerPosition,
|
|
|
closestDis,
|
|
@@ -807,13 +1012,13 @@ export class MoveService implements OnModuleInit {
|
|
|
) {
|
|
|
const breakPoint = this.breakPointInfo[breakPointId];
|
|
|
const user = this.users[userId];
|
|
|
- const player_Position = this.getTarget(
|
|
|
+ let player_Position = this.getTarget(
|
|
|
playerPosition,
|
|
|
breakPoint.position,
|
|
|
- //this.breakPointInfo[surroundPointIds[0]].position,
|
|
|
- this.breakPointInfo[neighBreakPointId].position,
|
|
|
+ this.breakPointInfo[neighBreakPointId].position
|
|
|
);
|
|
|
- if (player_Position != null) {
|
|
|
+
|
|
|
+ if(player_Position != null){
|
|
|
playerPosition.x = player_Position.x;
|
|
|
playerPosition.y = player_Position.y;
|
|
|
user.player.position = JSON.parse(JSON.stringify(playerPosition));
|
|
@@ -833,6 +1038,11 @@ export class MoveService implements OnModuleInit {
|
|
|
JSON.stringify(user.player.position),
|
|
|
);
|
|
|
this.reply.actionResponses[0].actionType = actionType;
|
|
|
+ const cameraInfo = this.getCameraInfo();
|
|
|
+ if(cameraInfo != null){
|
|
|
+ this.reply['newUserStates'][0].playerState.camera.position = cameraInfo.camera_position;
|
|
|
+ this.reply['newUserStates'][0].playerState.camera.angle = cameraInfo.camera_angle;
|
|
|
+ }
|
|
|
return this.reply;
|
|
|
}
|
|
|
}
|
|
@@ -857,13 +1067,12 @@ export class MoveService implements OnModuleInit {
|
|
|
//相机纠正加过渡
|
|
|
else {
|
|
|
if (chooseBreakPointId == user.breakPointId) {
|
|
|
- console.log('joystick-3:');
|
|
|
this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
|
|
|
JSON.stringify(user.player.position),
|
|
|
);
|
|
|
return this.reply;
|
|
|
}
|
|
|
- const replys = [];
|
|
|
+
|
|
|
const angle = user.camera.angle.yaw % 45; //纠正需要
|
|
|
//通过user.camera.angle矫正相机的angle
|
|
|
const checkReplys = await this.modeifyCameraAngle(
|
|
@@ -872,11 +1081,13 @@ export class MoveService implements OnModuleInit {
|
|
|
traceId,
|
|
|
actionType,
|
|
|
);
|
|
|
+
|
|
|
for (let i = 0; i < checkReplys.length; ++i) {
|
|
|
- checkReplys[i].actionResponses[0].actionType = actionType;
|
|
|
+ //checkReplys[i].actionResponses[0].actionType = actionType;
|
|
|
+ this.addCameraInfo(checkReplys[i]['newUserStates'][0].playerState.camera.position,checkReplys[i]['newUserStates'][0].playerState.camera.angle,checkReplys[i].mediaSrc);
|
|
|
}
|
|
|
- replys.push(checkReplys);
|
|
|
-
|
|
|
+
|
|
|
+ //replys.push(checkReplys);
|
|
|
//读redis里的数据,按照frame_index的大小排序
|
|
|
const key =
|
|
|
'moveframe:app_id:' +
|
|
@@ -889,26 +1100,79 @@ export class MoveService implements OnModuleInit {
|
|
|
Math.floor(user.camera.angle.yaw / 45);
|
|
|
const moveFramesRes = await this.cacheService.get(key);
|
|
|
const moveFrames = JSON.parse(moveFramesRes);
|
|
|
- const pathReplys = this.createCacheReplys(
|
|
|
- appId,
|
|
|
- moveFrames,
|
|
|
- traceId,
|
|
|
- userId,
|
|
|
- breakPointId,
|
|
|
- chooseBreakPointId,
|
|
|
- true,
|
|
|
- );
|
|
|
- for (let i = 0; i < pathReplys.length; ++i) {
|
|
|
- pathReplys[i].actionResponses[0].actionType = actionType;
|
|
|
- }
|
|
|
- replys.push(pathReplys);
|
|
|
+ this.setCameraInfo(moveFrames);
|
|
|
+ // const pathReplys = this.createCacheReplys(
|
|
|
+ // appId,
|
|
|
+ // moveFrames,
|
|
|
+ // traceId,
|
|
|
+ // userId,
|
|
|
+ // breakPointId,
|
|
|
+ // 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];
|
|
|
- user.camera.position = JSON.parse(
|
|
|
- JSON.stringify(lastFrame.camera_position),
|
|
|
- );
|
|
|
- user.camera.angle.yaw = lastFrame.camera_angle.yaw;
|
|
|
- return replys;
|
|
|
+ const cameraInfo = this.getCameraInfo();
|
|
|
+ if(cameraInfo != null){
|
|
|
+ this.reply['newUserStates'][0].playerState.camera.position = cameraInfo.camera_position;
|
|
|
+ this.reply['newUserStates'][0].playerState.camera.angle = cameraInfo.camera_angle;
|
|
|
+
|
|
|
+ user.camera.position = JSON.parse(
|
|
|
+ JSON.stringify(cameraInfo.camera_position),
|
|
|
+ );
|
|
|
+ user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
|
|
|
+
|
|
|
+ if(cameraInfo.mediaSrc){
|
|
|
+ this.reply.mediaSrc = cameraInfo.mediaSrc;
|
|
|
+ }
|
|
|
+ else if(cameraInfo.file_name){
|
|
|
+ this.reply.mediaSrc =
|
|
|
+ '/' +
|
|
|
+ appId +
|
|
|
+ '/' +
|
|
|
+ breakPointId +
|
|
|
+ '/' +
|
|
|
+ cameraInfo.file_name.substring(0, cameraInfo.file_name.indexOf('.')) +
|
|
|
+ '/' +
|
|
|
+ cameraInfo.file_name +
|
|
|
+ '?m=' +
|
|
|
+ new Date().getTime();
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ debugger;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return this.reply;
|
|
|
+ // user.camera.position = JSON.parse(
|
|
|
+ // JSON.stringify(lastFrame.camera_position),
|
|
|
+ // );
|
|
|
+ // user.camera.angle.yaw = lastFrame.camera_angle.yaw;
|
|
|
+ // return replys;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ setCameraInfo(moveFrames){
|
|
|
+ this.cameraInfos = moveFrames
|
|
|
+ }
|
|
|
+
|
|
|
+ addCameraInfo(cameraPosition,cameraAngle,mediaSrc){
|
|
|
+ this.cameraInfos.push({
|
|
|
+ camera_position:cameraPosition,
|
|
|
+ camera_angle:cameraAngle,
|
|
|
+ mediaSrc:mediaSrc
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ getCameraInfo(){
|
|
|
+ if(this.cameraInfos.length>0){
|
|
|
+ const item = this.cameraInfos.shift();
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1141,4 +1405,26 @@ export class MoveService implements OnModuleInit {
|
|
|
const decimal = 2;
|
|
|
return parseFloat(num.toFixed(decimal));
|
|
|
}
|
|
|
+
|
|
|
+ isPointInPoly(position,breakPointIds){
|
|
|
+ const x = position.x;
|
|
|
+ const y = position.y;
|
|
|
+
|
|
|
+ let inside = false;
|
|
|
+
|
|
|
+ for(let i=0,j=breakPointIds.length-1;i<breakPointIds.length;j=i++){
|
|
|
+ let pt1 = this.breakPointInfo[breakPointIds[i]]
|
|
|
+ let pt2 = this.breakPointInfo[breakPointIds[j]]
|
|
|
+
|
|
|
+ const xi = pt1.x
|
|
|
+ const yi = pt1.y
|
|
|
+ const xj = pt2.x
|
|
|
+ const yj = pt2.y
|
|
|
+
|
|
|
+ const intersect = yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi
|
|
|
+ if (intersect) inside = !inside
|
|
|
+ }
|
|
|
+
|
|
|
+ return inside
|
|
|
+ }
|
|
|
}
|