import HTTPS, { NetGet, NetPost } from "../Template/HTTPS"; import LocalData, { WorkState } from "../Template/LocalData"; import Guide from "./Guide"; export type HonorWallDetailsType = { Id: number; Name: string; Picture?: string; Description?: string; IsWear?: number; // 0 表示未穿戴,1 表示穿戴 IsHold?: number; // 0 表示未拥有,1 表示拥有 } export type CheckSeatType = { uuid?: string,//移动座位节点的UUID MoveSeatTime?: number,//移动座位的单个耗时 毫秒 BronPos?: cc.Vec2,//座位出生时候的位置 NowPos?: cc.Vec2,//现在座位的位置 } //荣誉管理器 const { ccclass, property } = cc._decorator; @ccclass export default class HonorManger { private static instance: HonorManger; public static getInstance(): HonorManger { if (!HonorManger.instance) { HonorManger.instance = new HonorManger(); } return HonorManger.instance; } HonorWallDetails_Shangban: HonorWallDetailsType[] = [ // { // Id: 1, // Name: '全勤员工', // Description: '连续一周每天都过关', // }, // { // Id: 2, // Name: '搞小团体', // Description: '邀请满3人加入上班游戏', // }, // { // Id: 3, // Name: '最佳新人', // Description: '第一次成功过关', // }, // { // Id: 4, // Name: '带资进组', // Description: '全部道具用完才上班成功', // }, // { // Id: 5, // Name: '福布斯top 30', // Description: '连续14天挑战成功', // }, // { // Id: 6, // Name: '卷王', // Description: '连续3天偷偷加班', // }, // { // Id: 7, // Name: '强东的兄弟', // Description: '连续7天偷偷加班', // }, ] HonorWallDetails_ChiDao: HonorWallDetailsType[] = [ // { // Id: 301, // Name: '老油条', // Description: '连续1天每天都迟到', // }, // { // Id: 302, // Name: '摸鱼高手', // Description: '连续3天每天都迟到', // }, // { // Id: 303, // Name: '永远在路上', // Description: '连续7天每天都迟到', // }, // { // Id: 304, // Name: '司机等等我', // Description: '累计旷工1天', // }, // { // Id: 305, // Name: '病假王', // Description: '累计旷工3天', // }, // { // Id: 306, // Name: '公司蛀虫', // Description: '累计旷工7天', // }, // { // Id: 307, // Name: '混吃等死', // Description: '累计旷工14天', // }, ] HonorWallDetails_Qita: HonorWallDetailsType[] = [ // { // Id: 601, // Name: '金手指', // Description: '1秒内移动3个座位', // }, // { // Id: 602, // Name: '差点被门夹住', // Description: '最后1秒内通过成功', // }, // { // Id: 603, // Name: '痛苦追车人', // Description: '最后一个人没登上车导致通关失败', // }, // { // Id: 604, // Name: '上班最速传说', // Description: '开局5秒内成功通关', // }, // { // Id: 605, // Name: '游艇趴DJ', // Description: '首次通过游艇关卡', // }, ] // 需要的数据 //1 结束剩余的时间 //2 结束剩余的乘客 //3 当前通关的关卡类型 //当前选择的荣誉 private _SelectHonorM: number = 0; public get SelectHonorM(): number { return this._SelectHonorM; } public set SelectHonorM(value: number) { this._SelectHonorM = value; } //已有的荣誉数组 private _HonorMList: number[] = []; public get HonorMList(): number[] { return this._HonorMList; } public set HonorMList(value: number) { if (!this._HonorMList.includes(value)) { this._HonorMList.push(value) } console.log('当前拥有的勋章数组为', this.HonorMList); console.log('当前应该检测的ID数组为', this.GameCheckID); } init(d: ResponseData) { //初始化 HonorManger.getInstance().HonorWallDetails_Shangban = d.Data.List1 HonorManger.getInstance().HonorWallDetails_ChiDao = d.Data.List2 HonorManger.getInstance().HonorWallDetails_Qita = d.Data.List3 //设置已经拥有的荣誉数组 let All = [ ...HonorManger.getInstance().HonorWallDetails_Shangban, ...HonorManger.getInstance().HonorWallDetails_ChiDao, ...HonorManger.getInstance().HonorWallDetails_Qita]; let temp = All.filter(e => { return e.IsHold == 1 }) temp.forEach(e => { this.HonorMList = e.Id }) //设置当前选择的荣誉 this.SelectHonorM = d?.Data?.UserHonor?.Id } //游戏内最近移动的座位数据 private SeatMoveList: CheckSeatType[] = [];// uuid time 对象 UpSeatMove(temp: CheckSeatType) { //601 this.SeatMoveList.push(temp) if (this.SeatMoveList.length > 10) { this.SeatMoveList.shift(); } } //游戏内已用时间 ElapsedTime: number = 0; //游戏内剩余时间 remainder: number = -1; //游戏内剩余乘客 remainingpassengers: number = -1; //游戏内需要检测的ID GameCheckID: number[] = [] intervalId: number = 0 GameInit() { this.GameCheckID = [] for (let i = 0; i < this.HonorWallDetails_Qita.length; i++) { const element = this.HonorWallDetails_Qita[i]; if (!this.HonorMList.includes(element.Id)) { this.GameCheckID.push(element.Id) } } console.log('当前拥有的勋章数组为', this.HonorMList); console.log('当前应该检测的ID数组为', this.GameCheckID); } // Game601() { if (LocalData.getInstance().getWorkState() == WorkState.引导) { return } if (!this.GameCheckID.includes(601)) { return } let adjacentTriplets = this.getAdjacentTriplets(this.SeatMoveList); if (!adjacentTriplets) { return } for (let index = 0; index < adjacentTriplets.length; index++) { const element = adjacentTriplets[index]; if (element[0].uuid !== element[1].uuid && element[1].uuid !== element[2].uuid) { let total = element[0].MoveSeatTime + element[1].MoveSeatTime + element[2].MoveSeatTime if (total <= 1000) { console.log('三个最短耗时', total); this.GameCheckID = this.GameCheckID.filter(item => item !== 601); this.HonorMList = 601 //发送完成勋章 this.SendCompleteHonor(601) return } } } } Game602() { if (LocalData.getInstance().getWorkState() == WorkState.引导) { return } if (!this.GameCheckID.includes(602)) { return } if (this.remainingpassengers == 0 && this.remainder == 1) { console.log('差点被门夹住-最后1秒内通过成功'); this.GameCheckID = this.GameCheckID.filter(item => item !== 602); this.HonorMList = 602 //发送完成勋章 this.SendCompleteHonor(602) } } Game603() { if (LocalData.getInstance().getWorkState() == WorkState.引导) { return } if (!this.GameCheckID.includes(603)) { return } if (this.remainingpassengers == 1 && this.remainder == 0) { console.log('痛苦追车人-最后一个人没登上车导致通关失败'); this.GameCheckID = this.GameCheckID.filter(item => item !== 603); this.HonorMList = 603 //发送完成勋章 this.SendCompleteHonor(603) } } Game604() { if (LocalData.getInstance().getWorkState() == WorkState.引导) { return } if (!this.GameCheckID.includes(604)) { return } if (this.ElapsedTime != 0 && this.ElapsedTime <= 5) { console.log('上班最速传说-开局5秒内成功通关', this.ElapsedTime); this.GameCheckID = this.GameCheckID.filter(item => item !== 604); this.HonorMList = 604 //发送完成勋章 this.SendCompleteHonor(604) } } //发送完成勋章 SendCompleteHonor(ID: number) { HTTPS.Instance.post(NetPost.AddToBenotified, { "State": 1, "Type": 2, "Id": ID }).then((resp) => { // 初始化地图数据 }) } //#region 引导关卡 GuideStep = 0 GuideData = [{ bronPos: { x: 3, y: 6 }, NowPos: { x: 0, y: 6 } }, { bronPos: { x: 0, y: 5 }, NowPos: { x: 3, y: 5 } }, { bronPos: { x: 1, y: 0 }, NowPos: { x: 0, y: 2 } }, { bronPos: { x: 2, y: 0 }, NowPos: { x: 0, y: 0 } },] Guide1() { if (LocalData.getInstance().getWorkState() === WorkState.引导) { if (this.GuideStep > this.GuideData.length - 1) { //引导完毕 return } for (let index = 0; index < this.SeatMoveList.length; index++) { const element = this.SeatMoveList[index]; if (element.BronPos.x == this.GuideData[this.GuideStep].bronPos.x && element.BronPos.y == this.GuideData[this.GuideStep].bronPos.y && element.NowPos.x == this.GuideData[this.GuideStep].NowPos.x && element.NowPos.y == this.GuideData[this.GuideStep].NowPos.y ) { this.GuideStep++ return } } //手指出现 let GuideComp = cc.Canvas.instance.node.getChildByName("Guide").getComponent(Guide) GuideComp.playAni(this.GuideData[this.GuideStep].bronPos, this.GuideData[this.GuideStep].NowPos) // console.log(this.SeatMoveList); } } //#endregion //数组取全部相邻的三个数 getAdjacentTriplets(arr: T[]): T[][] { const result: T[][] = []; if (arr.length < 3) { return null; } for (let i = 0; i < arr.length - 2; i++) { result.push([arr[i], arr[i + 1], arr[i + 2]]); } return result; } } interface ResponseData { Version: string; Code: number; Message: string; Data: { List1: HonorItem[]; List2: HonorItem[]; List3: HonorItem[]; UserHonor: HonorItem; // 'UserHonor' 的具体类型不明确,暂时用 any }; DataCount: number; PageCount: number; Mac: string; Timestamp: string; } interface HonorItem { Id: number; Name: string; Picture: string; Description: string; IsWear: number; // 0 表示未穿戴,1 表示穿戴 IsHold: number; // 0 表示未保持,1 表示保持 }