|
@@ -1,15 +1,20 @@
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
import { CacheService } from 'src/cache/cache.service';
|
|
|
+import { RotateService } from 'src/rotate/rotate.service';
|
|
|
+// import { SceneService } from 'src/scene/scene.service';
|
|
|
|
|
|
@Injectable()
|
|
|
export class MoveService {
|
|
|
- constructor(private cacheService: CacheService) {}
|
|
|
+ constructor(
|
|
|
+ private cacheService: CacheService,
|
|
|
+ private rotateService: RotateService,
|
|
|
+ ) {}
|
|
|
private Actions = {
|
|
|
Clicking: 1,
|
|
|
Rotation: 1014,
|
|
|
Joystick: 15,
|
|
|
};
|
|
|
- public users = {};
|
|
|
+ public users = this.rotateService.users;
|
|
|
|
|
|
private reply = {
|
|
|
traceIds: [],
|
|
@@ -153,14 +158,22 @@ export class MoveService {
|
|
|
|
|
|
//纠正,旋转传到缓存里
|
|
|
const checkReplys = [];
|
|
|
+ console.log('矫正: ' + angle + ' 度');
|
|
|
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);
|
|
|
+ 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);
|
|
|
}
|
|
|
replys['P' + user.breakPointId + 'T' + user.breakPointId] = checkReplys;
|
|
|
//replys.push(checkReplys);
|
|
@@ -428,29 +441,36 @@ export class MoveService {
|
|
|
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){
|
|
|
+ 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.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.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['newUserStates'][0].playerState.cameraCenter = user.camera.position;
|
|
|
-
|
|
|
this.reply['actionResponses'][0].traceId = traceId;
|
|
|
|
|
|
return this.reply;
|
|
|
}
|
|
|
//选择过渡
|
|
|
- else{
|
|
|
+ else {
|
|
|
const breakPointId = user.breakPointId;
|
|
|
//先矫正
|
|
|
- const breakPointRes = await this.cacheService.get('breakpoints:app_id:'+appId+':break_point_id:'+breakPointId);
|
|
|
+ const breakPointRes = await this.cacheService.get(
|
|
|
+ 'breakpoints:app_id:' + appId + ':break_point_id:' + breakPointId,
|
|
|
+ );
|
|
|
if (breakPointRes == null) {
|
|
|
return null;
|
|
|
}
|
|
@@ -459,68 +479,92 @@ export class MoveService {
|
|
|
const contact = breakPoint.contact;
|
|
|
let chooseBreakPointId = null;
|
|
|
let minOffsetAngle = null;
|
|
|
- let neighPoint = 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);
|
|
|
- }
|
|
|
+ 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);
|
|
|
+ if (chooseBreakPointId == null) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ //人物矫正
|
|
|
+ user.player.angle.yaw = angle;
|
|
|
+
|
|
|
+ //相机纠正
|
|
|
+ const replys = [];
|
|
|
+ const traceIds = [];
|
|
|
+ traceIds.push(traceId);
|
|
|
+
|
|
|
+ const 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);
|
|
|
+
|
|
|
+ const pathReplys = this.createCacheReplys(
|
|
|
+ moveFrames,
|
|
|
+ traceId,
|
|
|
+ userId,
|
|
|
+ breakPointId,
|
|
|
+ startBreakPoint.position,
|
|
|
+ endBreakPoint.position,
|
|
|
+ );
|
|
|
+ replys.push(pathReplys);
|
|
|
+ return replys;
|
|
|
}
|
|
|
}
|
|
|
} catch (error) {
|