|
@@ -421,4 +421,110 @@ export class MoveService {
|
|
|
reply['newUserStates'][0].renderInfo.isMoving = 0;
|
|
|
return reply;
|
|
|
}
|
|
|
+
|
|
|
+ async joystick(actionRequest) {
|
|
|
+ try {
|
|
|
+ const userId = actionRequest['user_id'];
|
|
|
+ const traceId = actionRequest['trace_id'];
|
|
|
+ const dir_action = actionRequest['dir_action'];
|
|
|
+ const user = this.users[userId];
|
|
|
+
|
|
|
+ const appId = user.appId;
|
|
|
+ //只是移动人物
|
|
|
+ if(dir_action.speed_level<7){
|
|
|
+ user.player.angle.yaw = dir_action.move_angle;
|
|
|
+ this.reply['newUserStates'][0]['userId'] = userId;
|
|
|
+ this.reply['newUserStates'][0].playerState.player.position = user.player.position;
|
|
|
+ this.reply['newUserStates'][0].playerState.player.angle.yaw = dir_action.move_angle;
|
|
|
+
|
|
|
+ this.reply['newUserStates'][0].playerState.camera.position = user.camera.position;
|
|
|
+ this.reply['newUserStates'][0].playerState.camera.angle = user.camera.angle;
|
|
|
+
|
|
|
+ this.reply['newUserStates'][0].playerState.cameraCenter = user.camera.position;
|
|
|
+
|
|
|
+ this.reply['actionResponses'][0].traceId = traceId;
|
|
|
+
|
|
|
+ return this.reply;
|
|
|
+ }
|
|
|
+ //选择过渡
|
|
|
+ else{
|
|
|
+ const breakPointId = user.breakPointId;
|
|
|
+ //先矫正
|
|
|
+ const breakPointRes = await this.cacheService.get('breakpoints:app_id:'+appId+':break_point_id:'+breakPointId);
|
|
|
+ if (breakPointRes == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ const breakPoint = JSON.parse(breakPointRes);
|
|
|
+ const contact = breakPoint.contact;
|
|
|
+ let chooseBreakPointId = null;
|
|
|
+ let minOffsetAngle = null;
|
|
|
+ let neighPoint = null
|
|
|
+ let angle = 0;
|
|
|
+ for(let i=0;i<contact.length;++i){
|
|
|
+ neighPoint = await this.cacheService.get('breakpoints:app_id:'+appId+':break_point_id:'+contact[i]); //通过contact[i],去redis里找
|
|
|
+ //通过user.player.position;neighPoint.position获得角度
|
|
|
+ angle = this.getAngle(user.player.position,{x:user.player.position.x+1,y:user.player.position.y},neighPoint.position) ;
|
|
|
+ if(Math.abs(angle - dir_action.move_angle)<45&&(minOffsetAngle == null||Math.abs(angle - dir_action.move_angle)<minOffsetAngle)){
|
|
|
+ chooseBreakPointId = contact[i];
|
|
|
+ minOffsetAngle = Math.abs(angle - dir_action.move_angle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(chooseBreakPointId == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ //人物矫正
|
|
|
+ user.player.angle.yaw = angle;
|
|
|
+
|
|
|
+ //相机纠正
|
|
|
+ let replys = [];
|
|
|
+ let traceIds = [];
|
|
|
+ traceIds.push(traceId);
|
|
|
+
|
|
|
+ let checkReplys = [];
|
|
|
+ angle = user.camera.angle.yaw%45; //纠正需要
|
|
|
+ for(let i=0;i<angle;++i){
|
|
|
+ //let reply = rotateService.rotateForAngle(userId,(angle+i)%359);
|
|
|
+ //reply.traceIds = [];
|
|
|
+ //reply.traceIds.push(traceId);
|
|
|
+ //let actionResponse = rotateService.createActionResponse(actionType,trace_id);
|
|
|
+ //reply.actionResponses = [];
|
|
|
+ //reply.actionResponses.push(actionResponse);
|
|
|
+ //checkReplys.push(reply);
|
|
|
+ }
|
|
|
+ replys.push(checkReplys);
|
|
|
+
|
|
|
+ //过渡
|
|
|
+ //读redis里的数据,按照frame_index的大小排序
|
|
|
+ const key ='moveframe:app_id:' +appId +':start_break_point_id:' +breakPointId +':end_break_point_id:' +chooseBreakPointId +':angle:' +user.camera.angle%45;
|
|
|
+ const moveFramesRes = await this.cacheService.get(key);
|
|
|
+ if (moveFramesRes == null) {
|
|
|
+ return replys;
|
|
|
+ }
|
|
|
+ const moveFrames = JSON.parse(moveFramesRes);
|
|
|
+ //读redis里的数据
|
|
|
+ const startBreakPointRes = await this.cacheService.get('breakpoints:app_id:' +appId +':break_point_id:' +breakPointId);
|
|
|
+ const startBreakPoint = JSON.parse(startBreakPointRes);
|
|
|
+
|
|
|
+ const endBreakPointRes = await this.cacheService.get('breakpoints:app_id:' +appId +':break_point_id:' +chooseBreakPointId);
|
|
|
+ const endBreakPoint = JSON.parse(endBreakPointRes);
|
|
|
+
|
|
|
+ let pathReplys = this.createCacheReplys(
|
|
|
+ moveFrames,
|
|
|
+ traceId,
|
|
|
+ userId,
|
|
|
+ breakPointId,
|
|
|
+ startBreakPoint.position,
|
|
|
+ endBreakPoint.position,
|
|
|
+ );
|
|
|
+ replys.push(pathReplys);
|
|
|
+ return replys;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log('MoveService', error);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|