HonorManger.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. import HTTPS, { NetGet, NetPost } from "../Template/HTTPS";
  2. import LocalData, { WorkState } from "../Template/LocalData";
  3. import Guide from "./Guide";
  4. export type HonorWallDetailsType = {
  5. Id: number;
  6. Name: string;
  7. Picture?: string;
  8. Description?: string;
  9. IsWear?: number; // 0 表示未穿戴,1 表示穿戴
  10. IsHold?: number; // 0 表示未拥有,1 表示拥有
  11. }
  12. export type CheckSeatType = {
  13. uuid?: string,//移动座位节点的UUID
  14. MoveSeatTime?: number,//移动座位的单个耗时 毫秒
  15. BronPos?: cc.Vec2,//座位出生时候的位置
  16. NowPos?: cc.Vec2,//现在座位的位置
  17. }
  18. //荣誉管理器
  19. const { ccclass, property } = cc._decorator;
  20. @ccclass
  21. export default class HonorManger {
  22. private static instance: HonorManger;
  23. public static getInstance(): HonorManger {
  24. if (!HonorManger.instance) {
  25. HonorManger.instance = new HonorManger();
  26. }
  27. return HonorManger.instance;
  28. }
  29. HonorWallDetails_Shangban: HonorWallDetailsType[] = [
  30. // {
  31. // Id: 1,
  32. // Name: '全勤员工',
  33. // Description: '连续一周每天都过关',
  34. // },
  35. // {
  36. // Id: 2,
  37. // Name: '搞小团体',
  38. // Description: '邀请满3人加入上班游戏',
  39. // },
  40. // {
  41. // Id: 3,
  42. // Name: '最佳新人',
  43. // Description: '第一次成功过关',
  44. // },
  45. // {
  46. // Id: 4,
  47. // Name: '带资进组',
  48. // Description: '全部道具用完才上班成功',
  49. // },
  50. // {
  51. // Id: 5,
  52. // Name: '福布斯top 30',
  53. // Description: '连续14天挑战成功',
  54. // },
  55. // {
  56. // Id: 6,
  57. // Name: '卷王',
  58. // Description: '连续3天偷偷加班',
  59. // },
  60. // {
  61. // Id: 7,
  62. // Name: '强东的兄弟',
  63. // Description: '连续7天偷偷加班',
  64. // },
  65. ]
  66. HonorWallDetails_ChiDao: HonorWallDetailsType[] = [
  67. // {
  68. // Id: 301,
  69. // Name: '老油条',
  70. // Description: '连续1天每天都迟到',
  71. // },
  72. // {
  73. // Id: 302,
  74. // Name: '摸鱼高手',
  75. // Description: '连续3天每天都迟到',
  76. // },
  77. // {
  78. // Id: 303,
  79. // Name: '永远在路上',
  80. // Description: '连续7天每天都迟到',
  81. // },
  82. // {
  83. // Id: 304,
  84. // Name: '司机等等我',
  85. // Description: '累计旷工1天',
  86. // },
  87. // {
  88. // Id: 305,
  89. // Name: '病假王',
  90. // Description: '累计旷工3天',
  91. // },
  92. // {
  93. // Id: 306,
  94. // Name: '公司蛀虫',
  95. // Description: '累计旷工7天',
  96. // },
  97. // {
  98. // Id: 307,
  99. // Name: '混吃等死',
  100. // Description: '累计旷工14天',
  101. // },
  102. ]
  103. HonorWallDetails_Qita: HonorWallDetailsType[] = [
  104. // {
  105. // Id: 601,
  106. // Name: '金手指',
  107. // Description: '1秒内移动3个座位',
  108. // },
  109. // {
  110. // Id: 602,
  111. // Name: '差点被门夹住',
  112. // Description: '最后1秒内通过成功',
  113. // },
  114. // {
  115. // Id: 603,
  116. // Name: '痛苦追车人',
  117. // Description: '最后一个人没登上车导致通关失败',
  118. // },
  119. // {
  120. // Id: 604,
  121. // Name: '上班最速传说',
  122. // Description: '开局5秒内成功通关',
  123. // },
  124. // {
  125. // Id: 605,
  126. // Name: '游艇趴DJ',
  127. // Description: '首次通过游艇关卡',
  128. // },
  129. ]
  130. // 需要的数据
  131. //1 结束剩余的时间
  132. //2 结束剩余的乘客
  133. //3 当前通关的关卡类型
  134. //当前选择的荣誉
  135. private _SelectHonorM: number = 0;
  136. public get SelectHonorM(): number {
  137. return this._SelectHonorM;
  138. }
  139. public set SelectHonorM(value: number) {
  140. this._SelectHonorM = value;
  141. }
  142. //已有的荣誉数组
  143. private _HonorMList: number[] = [];
  144. public get HonorMList(): number[] {
  145. return this._HonorMList;
  146. }
  147. public set HonorMList(value: number) {
  148. if (!this._HonorMList.includes(value)) {
  149. this._HonorMList.push(value)
  150. }
  151. console.log('当前拥有的勋章数组为', this.HonorMList);
  152. console.log('当前应该检测的ID数组为', this.GameCheckID);
  153. }
  154. init(d: ResponseData) {
  155. //初始化
  156. HonorManger.getInstance().HonorWallDetails_Shangban = d.Data.List1
  157. HonorManger.getInstance().HonorWallDetails_ChiDao = d.Data.List2
  158. HonorManger.getInstance().HonorWallDetails_Qita = d.Data.List3
  159. //设置已经拥有的荣誉数组
  160. let All = [
  161. ...HonorManger.getInstance().HonorWallDetails_Shangban,
  162. ...HonorManger.getInstance().HonorWallDetails_ChiDao,
  163. ...HonorManger.getInstance().HonorWallDetails_Qita];
  164. let temp = All.filter(e => { return e.IsHold == 1 })
  165. temp.forEach(e => { this.HonorMList = e.Id })
  166. //设置当前选择的荣誉
  167. this.SelectHonorM = d?.Data?.UserHonor?.Id
  168. }
  169. //游戏内最近移动的座位数据
  170. private SeatMoveList: CheckSeatType[] = [];// uuid time 对象
  171. UpSeatMove(temp: CheckSeatType) {
  172. //601
  173. this.SeatMoveList.push(temp)
  174. if (this.SeatMoveList.length > 10) {
  175. this.SeatMoveList.shift();
  176. }
  177. }
  178. //游戏内已用时间
  179. ElapsedTime: number = 0;
  180. //游戏内剩余时间
  181. remainder: number = -1;
  182. //游戏内剩余乘客
  183. remainingpassengers: number = -1;
  184. //游戏内需要检测的ID
  185. GameCheckID: number[] = []
  186. intervalId: number = 0
  187. GameInit() {
  188. this.GameCheckID = []
  189. for (let i = 0; i < this.HonorWallDetails_Qita.length; i++) {
  190. const element = this.HonorWallDetails_Qita[i];
  191. if (!this.HonorMList.includes(element.Id)) {
  192. this.GameCheckID.push(element.Id)
  193. }
  194. }
  195. console.log('当前拥有的勋章数组为', this.HonorMList);
  196. console.log('当前应该检测的ID数组为', this.GameCheckID);
  197. }
  198. //
  199. Game601() {
  200. if (LocalData.getInstance().getWorkState() == WorkState.引导) {
  201. return
  202. }
  203. if (!this.GameCheckID.includes(601)) {
  204. return
  205. }
  206. let adjacentTriplets = this.getAdjacentTriplets(this.SeatMoveList);
  207. if (!adjacentTriplets) {
  208. return
  209. }
  210. for (let index = 0; index < adjacentTriplets.length; index++) {
  211. const element = adjacentTriplets[index];
  212. if (element[0].uuid !== element[1].uuid && element[1].uuid !== element[2].uuid) {
  213. let total = element[0].MoveSeatTime + element[1].MoveSeatTime + element[2].MoveSeatTime
  214. if (total <= 1000) {
  215. console.log('三个最短耗时', total);
  216. this.GameCheckID = this.GameCheckID.filter(item => item !== 601);
  217. this.HonorMList = 601
  218. //发送完成勋章
  219. this.SendCompleteHonor(601)
  220. return
  221. }
  222. }
  223. }
  224. }
  225. Game602() {
  226. if (LocalData.getInstance().getWorkState() == WorkState.引导) {
  227. return
  228. }
  229. if (!this.GameCheckID.includes(602)) {
  230. return
  231. }
  232. if (this.remainingpassengers == 0 && this.remainder == 1) {
  233. console.log('差点被门夹住-最后1秒内通过成功');
  234. this.GameCheckID = this.GameCheckID.filter(item => item !== 602);
  235. this.HonorMList = 602
  236. //发送完成勋章
  237. this.SendCompleteHonor(602)
  238. }
  239. }
  240. Game603() {
  241. if (LocalData.getInstance().getWorkState() == WorkState.引导) {
  242. return
  243. }
  244. if (!this.GameCheckID.includes(603)) {
  245. return
  246. }
  247. if (this.remainingpassengers == 1 && this.remainder == 0) {
  248. console.log('痛苦追车人-最后一个人没登上车导致通关失败');
  249. this.GameCheckID = this.GameCheckID.filter(item => item !== 603);
  250. this.HonorMList = 603
  251. //发送完成勋章
  252. this.SendCompleteHonor(603)
  253. }
  254. }
  255. Game604() {
  256. if (LocalData.getInstance().getWorkState() == WorkState.引导) {
  257. return
  258. }
  259. if (!this.GameCheckID.includes(604)) {
  260. return
  261. }
  262. if (this.ElapsedTime != 0 && this.ElapsedTime <= 5) {
  263. console.log('上班最速传说-开局5秒内成功通关', this.ElapsedTime);
  264. this.GameCheckID = this.GameCheckID.filter(item => item !== 604);
  265. this.HonorMList = 604
  266. //发送完成勋章
  267. this.SendCompleteHonor(604)
  268. }
  269. }
  270. //发送完成勋章
  271. SendCompleteHonor(ID: number) {
  272. HTTPS.Instance.post(NetPost.AddToBenotified, {
  273. "State": 1,
  274. "Type": 2,
  275. "Id": ID
  276. }).then((resp) => {
  277. // 初始化地图数据
  278. })
  279. }
  280. //#region 引导关卡
  281. GuideStep = 0
  282. GuideData = [{
  283. bronPos: { x: 3, y: 6 },
  284. NowPos: { x: 0, y: 6 }
  285. }, {
  286. bronPos: { x: 0, y: 5 },
  287. NowPos: { x: 3, y: 5 }
  288. }, {
  289. bronPos: { x: 1, y: 0 },
  290. NowPos: { x: 0, y: 2 }
  291. }, {
  292. bronPos: { x: 2, y: 0 },
  293. NowPos: { x: 0, y: 0 }
  294. },]
  295. Guide1() {
  296. if (LocalData.getInstance().getWorkState() === WorkState.引导) {
  297. if (this.GuideStep > this.GuideData.length - 1) {
  298. //引导完毕
  299. return
  300. }
  301. for (let index = 0; index < this.SeatMoveList.length; index++) {
  302. const element = this.SeatMoveList[index];
  303. if (element.BronPos.x == this.GuideData[this.GuideStep].bronPos.x && element.BronPos.y == this.GuideData[this.GuideStep].bronPos.y &&
  304. element.NowPos.x == this.GuideData[this.GuideStep].NowPos.x && element.NowPos.y == this.GuideData[this.GuideStep].NowPos.y
  305. ) {
  306. this.GuideStep++
  307. return
  308. }
  309. }
  310. //手指出现
  311. let GuideComp = cc.Canvas.instance.node.getChildByName("Guide").getComponent(Guide)
  312. GuideComp.playAni(this.GuideData[this.GuideStep].bronPos, this.GuideData[this.GuideStep].NowPos)
  313. // console.log(this.SeatMoveList);
  314. }
  315. }
  316. //#endregion
  317. //数组取全部相邻的三个数
  318. getAdjacentTriplets<T>(arr: T[]): T[][] {
  319. const result: T[][] = [];
  320. if (arr.length < 3) {
  321. return null;
  322. }
  323. for (let i = 0; i < arr.length - 2; i++) {
  324. result.push([arr[i], arr[i + 1], arr[i + 2]]);
  325. }
  326. return result;
  327. }
  328. }
  329. interface ResponseData {
  330. Version: string;
  331. Code: number;
  332. Message: string;
  333. Data: {
  334. List1: HonorItem[];
  335. List2: HonorItem[];
  336. List3: HonorItem[];
  337. UserHonor: HonorItem; // 'UserHonor' 的具体类型不明确,暂时用 any
  338. };
  339. DataCount: number;
  340. PageCount: number;
  341. Mac: string;
  342. Timestamp: string;
  343. }
  344. interface HonorItem {
  345. Id: number;
  346. Name: string;
  347. Picture: string;
  348. Description: string;
  349. IsWear: number; // 0 表示未穿戴,1 表示穿戴
  350. IsHold: number; // 0 表示未保持,1 表示保持
  351. }