Common.ts 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. import SpineMgr from "../core/mgrs/SpineMgr";
  2. import LightShader from "../core/shader/2d/LightShader";
  3. import AIPlayer from "../d2Obj/AIPlayer";
  4. import D2BallSrc from "../d2Obj/D2BallSrc";
  5. import D2World from "../d2Obj/D2World";
  6. import D3World from "../d3Obj/D3World";
  7. import DataMgr from "../data/DataMgr";
  8. import { AwardType, FIRST_BALL_HOLE, GameMode, Prop, SkillType } from "../data/Define";
  9. import ui_UIMoney from "../fgui/res/game/ui_UIMoney";
  10. import GameMgr from "../game/GameMgr";
  11. import SkillMgr from "../game/SkillMgr";
  12. import TalkMgr from "../game/TalkMgr";
  13. import WordsMgr from "../game/WordsMgr";
  14. import UIDraw from "../ui/UIDraw";
  15. import UIFlyEft from "../ui/UIFlyEft";
  16. import { UIGame } from "../UI/UIGame";
  17. import UIGameEnd from "../ui/UIGameEnd";
  18. import UIGetAward from "../ui/UIGetAward";
  19. import UIMain from "../ui/UIMain";
  20. import UIRodMethod from "../UI/UIRodMethod";
  21. import UISign from "../ui/UISign";
  22. import UISkill from "../ui/UISkill";
  23. import { xGame } from "../xGame";
  24. export default class Common {
  25. // 单例对象
  26. private static _instance: Common = null;
  27. public static getInstance(): Common {
  28. if (!this._instance) {
  29. this._instance = new Common();
  30. }
  31. return this._instance;
  32. }
  33. constructor() {
  34. Common._instance = this;
  35. window["common"] = this;
  36. }
  37. gameMgr: GameMgr;
  38. //3d场景
  39. d3Scene: Laya.Scene3D;
  40. d2World: D2World;
  41. d3World: D3World;
  42. gameUI: UIGame;
  43. uiRodMethod: UIRodMethod;
  44. aiPlayer: AIPlayer;
  45. /**标准分辨率下,固定相机下2d3d转换关系 */
  46. convertNum: number = 0.025;
  47. //gameUI: UIGame;
  48. VectorUp = new Laya.Vector3(0, 1, 0);
  49. scaleV3One = new Laya.Vector3();
  50. scaleV3Two = new Laya.Vector3();
  51. //
  52. posV4 = new Laya.Vector4();
  53. showDebug: boolean = false;
  54. openGuide: boolean = true;
  55. //
  56. screenImg: Laya.Texture;
  57. //高低杆偏移值
  58. rodOffest = new Laya.Vector2(0, 0);
  59. //高低杆偏移角度
  60. rodAngle: number = 0;
  61. //游戏模式
  62. gameMode: GameMode = GameMode.classic;
  63. //秘书spine
  64. secretary: SpineMgr;
  65. //经典模式表情spine
  66. classicEmotionSpine: SpineMgr;
  67. //挑战模式的奖励模式
  68. awardSpine: SpineMgr;
  69. //大招技能管理
  70. skillMgr: SkillMgr;
  71. wordsMgr: WordsMgr;
  72. talkMgr: TalkMgr;
  73. //大招关卡当前得索引
  74. bigMoveLevelIndex: number = 1;
  75. //进入大招模式需要的金币数目
  76. bigMoveNeedCoin: number = 1000;
  77. //进入巅峰赛需要的金币数目
  78. classicNiceNeddCoin: number = 1000;
  79. //通过后奖励的金币数目
  80. passAwardCoin: number = 2000;
  81. //经典模式的房间类型
  82. classicRoomType: number = 1;
  83. /**最大体力值 */
  84. maxPower: number = 20;
  85. /**自然恢复最大值 */
  86. natureMaxPower: number = 5;
  87. /**看视频增加的体力数 */
  88. videoPower: number = 2;
  89. /**自然恢复量 */
  90. powerRecoverNum: number = 900;
  91. //当前玩家所选择的技能类型
  92. curPlayerSkillType: number = 0;
  93. //是否是新的一天
  94. isNewDay: boolean = false;
  95. //玩家的回合点击了球球
  96. clickedBall: boolean = false;
  97. //摆球达人当前选择的关卡
  98. placeBallCurLevel: number = 0;
  99. //通关摆球达人时的星星数目
  100. placeBallStarNum: number = 0;
  101. //是否已经延长了辅助线
  102. longHelpLine: boolean = false;
  103. /**每日分享钻石的最大次数 */
  104. maxShareDiamondTimes: number = 3;
  105. //uigame界面中guide步骤
  106. guideStep: number = 0;
  107. temSelfLevel = 0;//新手引导下玩家的技能等级
  108. extraMoveNum = 0;//大招模式额外移动量,
  109. ///
  110. curRankID: number = 0;
  111. rankID = {
  112. normalStar: 12000,
  113. wxStar: 12001
  114. }
  115. //
  116. skillNameList = ["Fall from the sky", "Unstoppable Force", "Freeze Shot","Coming Soon"];
  117. skillIconList = ["gf_jn1", "gf_jn2", "gf_jn4", "gf_jn4"];
  118. btnClickStr: string = "buttonclick";
  119. //大招可升级到的最大等级
  120. maxSkillLevel: number = 10;
  121. //当前看广告提升了大招技能等级
  122. upSkillLevel: boolean = false;
  123. //游戏开始时间
  124. gameStartTime: number = 0;
  125. ////////////////////
  126. _sysOffestNum: number = 0;
  127. public get sysOffestNum(): number {
  128. if (this._sysOffestNum == 0) {
  129. this._sysOffestNum = (Laya.stage.width - 1334) / 2;
  130. }
  131. return this._sysOffestNum;
  132. }
  133. testShader() {
  134. let test = new LightShader();
  135. test.texture = <any>"res/d3Res/ballTexture/ball1.png";
  136. Laya.stage.addChild(test);
  137. }
  138. playScale(node) {
  139. Laya.Tween.to(node, { scaleX: 1.1, scaleY: 1.1 }, 100, null, Laya.Handler.create(this, () => {
  140. Laya.Tween.to(node, { scaleX: 1, scaleY: 1 }, 100, null, Laya.Handler.create(this, () => {
  141. //
  142. }))
  143. }))
  144. }
  145. setGroup(colli: Laya.PhysicsCollider | Laya.Rigidbody3D, ...group) {
  146. let out = 0;
  147. for (let index = 0; index < group.length; index++) {
  148. if (index == 0) {
  149. out = Laya.Physics3DUtils[`COLLISIONFILTERGROUP_CUSTOMFILTER${group[index]}`];
  150. }
  151. else {
  152. out = out | Laya.Physics3DUtils[`COLLISIONFILTERGROUP_CUSTOMFILTER${group[index]}`];
  153. }
  154. }
  155. colli.collisionGroup = out;
  156. }
  157. setCanGroupWith(colli: Laya.PhysicsCollider | Laya.Rigidbody3D, ...group) {
  158. let out = 0;
  159. for (let index = 0; index < group.length; index++) {
  160. if (index == 0) {
  161. out = Laya.Physics3DUtils[`COLLISIONFILTERGROUP_CUSTOMFILTER${group[index]}`];
  162. }
  163. else {
  164. out = out | Laya.Physics3DUtils[`COLLISIONFILTERGROUP_CUSTOMFILTER${group[index]}`];
  165. }
  166. }
  167. colli.canCollideWith = out;
  168. }
  169. loadPrefab(name, callback) {
  170. Laya.loader.create(`prefab/${name}.json`, Laya.Handler.create(this, (obj) => {
  171. let prefab = new Laya.Prefab();
  172. prefab.json = obj;
  173. let img: Laya.Image = Laya.Pool.getItemByCreateFun(name, prefab.create, prefab);
  174. callback && callback(img);
  175. }))
  176. }
  177. pos2to3Convert(x, y, d3Pos: Laya.Vector3) {
  178. //转换2D屏幕坐标系统到3D正交投影下的坐标系统
  179. x = x + this.sysOffestNum;
  180. d3Pos.setValue(x, y, 0);
  181. let success = this.d3World.camera.convertScreenCoordToOrthographicCoord(d3Pos, d3Pos);
  182. if (success) {
  183. //success
  184. }
  185. else {
  186. console.error("转换出错了。。。。。。。。");
  187. }
  188. }
  189. scale2to3Convert(num) {
  190. this.scaleV3One.setValue(0, 0, 0);
  191. this.d3World.camera.convertScreenCoordToOrthographicCoord(this.scaleV3One, this.scaleV3One);
  192. this.scaleV3Two.setValue(0, num, 0);
  193. this.d3World.camera.convertScreenCoordToOrthographicCoord(this.scaleV3Two, this.scaleV3Two);
  194. let outNum = Math.abs(this.scaleV3One.x - this.scaleV3Two.x);
  195. return outNum;
  196. }
  197. pos3to2Convert(d3Pos) {
  198. this.d3World.camera.viewport.project(d3Pos, this.d3World.camera.projectionViewMatrix, this.posV4);
  199. d3Pos.x = this.posV4.x / Laya.stage.clientScaleX;
  200. d3Pos.y = this.posV4.y / Laya.stage.clientScaleY;
  201. //
  202. d3Pos.x -= this.sysOffestNum;
  203. }
  204. scale3to2Convert(num) {
  205. let scale = this.scale2to3Convert(1);
  206. //2d的一个单位对应的3d值
  207. let d2Out = num / scale;
  208. return d2Out;
  209. }
  210. //type=box,circle
  211. getCollider(type, restitution = 0.9, density = 10) {
  212. let colli;
  213. //
  214. if (type == "box") colli = new Laya.BoxCollider();
  215. else colli = new Laya.CircleCollider();
  216. //
  217. colli.friction = 0;
  218. colli.restitution = restitution;
  219. colli.density = density;
  220. return colli;
  221. }
  222. getRigbody() {
  223. let rigy = new Laya.RigidBody();
  224. rigy.bullet = true;
  225. rigy.allowRotation = false;
  226. rigy.allowSleep = false;
  227. rigy.gravityScale = 0;
  228. return rigy;
  229. }
  230. angleV2 = new Laya.Vector2();
  231. rootV = new Laya.Vector2(0, 1);
  232. getfguiRotation(x, y) {
  233. this.angleV2.setValue(x, y);
  234. Laya.Vector2.normalize(this.angleV2, this.angleV2);
  235. let angle = Math.acos(Laya.Vector2.dot(this.rootV, this.angleV2)) * 180 / Math.PI;
  236. if ((this.angleV2.x >= 0 && this.angleV2.y >= 0) || (this.angleV2.x >= 0 && this.angleV2.y < 0)) {
  237. angle = -angle;
  238. }
  239. return 180 + angle;
  240. }
  241. getAngle(x, y) {
  242. this.angleV2.setValue(x, y);
  243. Laya.Vector2.normalize(this.angleV2, this.angleV2);
  244. let angle = Math.acos(Laya.Vector2.dot(this.rootV, this.angleV2)) * 180 / Math.PI;
  245. return angle;
  246. }
  247. randomNum(a, b) {
  248. return a + Math.floor((b - a + 1) * Math.random());
  249. }
  250. getRandArrEle(arr: Array<any>) {
  251. return arr[Math.floor(arr.length * Math.random())];
  252. }
  253. getSign(val) {
  254. return val >= 0 ? 1 : -1;
  255. }
  256. botherArr(arr: Array<any>) {
  257. let times = arr.length + 2;
  258. let length = arr.length;
  259. let a;
  260. let b;
  261. let temp;
  262. for (let index = 0; index < times; index++) {
  263. a = Math.floor(Math.random() * length);
  264. b = Math.floor(Math.random() * length);
  265. //
  266. temp = arr[a];
  267. arr[a] = arr[b];
  268. arr[b] = temp;
  269. }
  270. }
  271. getGameIconUrl(id: string): string {
  272. return "ui://game/" + id;
  273. }
  274. getComponentUrl(id: string): string {
  275. return "ui://game/" + id;
  276. }
  277. getAnimation() {
  278. }
  279. //
  280. judgeSkillType(type: SkillType = SkillType.highSpace) {
  281. if (this.gameMode == GameMode.classic) return;
  282. let gameMgr = this.gameMgr;
  283. if (gameMgr.selfTurn) {
  284. if (gameMgr.selfCurSkill == type) {
  285. return true;
  286. }
  287. }
  288. else {
  289. if (gameMgr.aiCurSkill == type) {
  290. return true;
  291. }
  292. }
  293. }
  294. //球碰到6个桌球洞口了
  295. ballColliHole(collider) {
  296. //首次进球,确定阵营,白球进入无效
  297. if (xGame.common.gameMgr.isFirstInGame && collider.owner["mySrc"].number != 0) {
  298. xGame.common.gameMgr.isFirstInGame = false;
  299. xGame.eventMgr.event(FIRST_BALL_HOLE, collider.owner["mySrc"].number);
  300. }
  301. collider.owner.mySrc.checkWrongBall();
  302. }
  303. //
  304. getArrMaxEle(arr) {
  305. let max = -Infinity;
  306. for (let index = 0; index < arr.length; index++) {
  307. max = Math.max(arr[index], max);
  308. }
  309. return max;
  310. }
  311. getArrMinEle(arr) {
  312. let min = Infinity;
  313. for (let index = 0; index < arr.length; index++) {
  314. min = Math.min(arr[index], min);
  315. }
  316. return min;
  317. }
  318. playRandomMutiBallBigSkillSound() {
  319. if (Math.random() <= 0.5) return;
  320. let rand = this.randomNum(1, 6);
  321. let str = "ganfa0" + rand;
  322. xGame.soundMgr.playSound(str);
  323. }
  324. showOneCamera(type) {
  325. let object = xGame.common.d3World.cameraObj;
  326. for (const key in object) {
  327. if (Object.prototype.hasOwnProperty.call(object, key)) {
  328. object[key].init();
  329. object[key].owner.active = key == type;
  330. }
  331. }
  332. }
  333. //检测球是否已经超出了边境
  334. checkBallOverBorder(x, y) {
  335. let radius = 17;
  336. let condition = this._checkBorder(x + radius, y) ||
  337. this._checkBorder(x - radius, y) ||
  338. this._checkBorder(x, y + radius) ||
  339. this._checkBorder(x, y - radius);
  340. //
  341. if (condition) {
  342. //超出边境了
  343. return true;
  344. }
  345. }
  346. private _checkBorder(x, y) {
  347. let borderRect = this.d2World.borderRect;
  348. let xOffest = 20;
  349. let yOffest = 20;
  350. //上边界
  351. if (y <= borderRect.y - yOffest) {
  352. return true;
  353. }
  354. //下边界
  355. if (y >= borderRect.y + borderRect.height + yOffest) {
  356. return true;
  357. }
  358. //左边界
  359. if (x <= borderRect.x - xOffest) {
  360. return true;
  361. }
  362. //右边界
  363. if (x >= borderRect.x + borderRect.width + xOffest) {
  364. return true;
  365. }
  366. }
  367. //权重// cfg只有id和weight两个参数
  368. initWeight(cfg) {
  369. let allCfgData = { data: {}, allWeightNum: 0 };
  370. let weightCfg = allCfgData.data;
  371. //
  372. let weight = 0;
  373. for (const key in cfg) {
  374. weightCfg[key] = {};
  375. weightCfg[key].id = cfg[key].id;
  376. weightCfg[key].minWeight = weight;
  377. //
  378. weight += cfg[key].weight;
  379. //
  380. weightCfg[key].maxWeight = weight
  381. }
  382. allCfgData.allWeightNum = weight;
  383. return allCfgData;
  384. }
  385. getRandomWeightData(cfg) {
  386. let weightCfg = cfg.data;
  387. let allWeightNum = cfg.allWeightNum;
  388. let rand = Math.floor(Math.random() * allWeightNum);
  389. for (const key in weightCfg) {
  390. if (rand > weightCfg[key].minWeight && rand <= weightCfg[key].maxWeight) {
  391. return weightCfg[key];
  392. }
  393. }
  394. return weightCfg[1];
  395. }
  396. //显示小秘书对话框
  397. showGirlTalkPop(wordsIndex, node, msgNode) {
  398. node.visible = true;
  399. msgNode.text = cfgTable.secretaryData[wordsIndex].msg;
  400. node.t0.play(Laya.Handler.create(this, () => {
  401. node.visible = false;
  402. }));
  403. }
  404. stopGirlPop(node) {
  405. node.t0.stop();
  406. node.visible = false;
  407. }
  408. createHead(loader: fgui.GLoader, url, size = 107) {
  409. if (Laya.Browser.name == "Browser") {
  410. //console.log("处于浏览器中", Laya.Browser.name);
  411. loader.url = url;
  412. return;
  413. }
  414. if (Moyu.isTT) {
  415. let localImage = new Image();
  416. localImage.src = url;
  417. localImage.onload = () => {
  418. let t2d = new Laya.Texture2D();
  419. t2d.width = size;
  420. t2d.height = size;
  421. loader.displayObject.graphics.drawImage(new Laya.Texture(t2d), 0, 0);
  422. t2d.loadImageSource(localImage);
  423. }
  424. }
  425. else {
  426. loader.url = url;
  427. }
  428. }
  429. addTestCoin(num) {
  430. DataMgr.setCoin(num);
  431. }
  432. addTestDiamond(num) {
  433. DataMgr.setDiamond(num);
  434. }
  435. addTestSkill() {
  436. DataMgr.setBigSkill(0, 99);
  437. DataMgr.setBigSkill(1, 99);
  438. DataMgr.setBigSkill(2, 99);
  439. }
  440. playClassicEmotion(number, x, y) {
  441. if (this.gameMode == GameMode.bigMove) return;
  442. //
  443. let randIndex = this.randomNum(0, 2);
  444. let data = { x: x, y: y, scaleX: 1, scaleY: 1 };
  445. let parent = this.gameUI.ui.classicEmotionSpineNode.displayObject;
  446. if (this.gameMgr.selfTurn) {
  447. if (this.gameMgr.selfBallArr.indexOf(number) > -1) {
  448. //进了己方阵营的球
  449. this.classicEmotionSpine.play(data, randIndex, false, parent);
  450. }
  451. else {
  452. if (this.gameMgr.aiBallArr.indexOf(number) > -1) {
  453. //进了别人的球
  454. }
  455. else {
  456. if (number == this.gameMgr.blackNum) {
  457. //黑8
  458. if (this.gameMgr.selfBallArr.length == 0) {
  459. //胜利进球
  460. this.classicEmotionSpine.play(data, randIndex, false, parent);
  461. }
  462. else {
  463. //失败
  464. }
  465. }
  466. else {
  467. //不是黑8,首次进球
  468. this.classicEmotionSpine.play(data, randIndex, false, parent);
  469. }
  470. }
  471. }
  472. }
  473. else {
  474. if (this.gameMgr.aiBallArr.indexOf(number) > -1) {
  475. //进了ai阵营的球
  476. this.classicEmotionSpine.play(data, randIndex, false, parent);
  477. }
  478. else {
  479. if (this.gameMgr.selfBallArr.indexOf(number) > -1) {
  480. //进了玩家的球
  481. }
  482. else {
  483. if (number == this.gameMgr.blackNum) {
  484. //黑8
  485. if (this.gameMgr.aiBallArr.length == 0) {
  486. //胜利进球
  487. this.classicEmotionSpine.play(data, randIndex, false, parent);
  488. }
  489. else {
  490. //失败
  491. }
  492. }
  493. else {
  494. //不是黑8,首次进球
  495. this.classicEmotionSpine.play(data, randIndex, false, parent);
  496. }
  497. }
  498. }
  499. }
  500. }
  501. playHappySound(number) {
  502. if (this.gameMode != GameMode.classic) return;
  503. if (number == 8) return;
  504. //
  505. let play = false;
  506. //
  507. if (this.gameMgr.selfTurn) {
  508. if (this.gameMgr.ensureBallType) {
  509. //已经确定阵营,且进球了
  510. if (this.gameMgr.selfBallArr.indexOf(number) > -1) {
  511. //进了己方阵营的球
  512. play = true;
  513. }
  514. }
  515. else {
  516. play = true;
  517. }
  518. }
  519. else {
  520. if (this.gameMgr.ensureBallType) {
  521. //已经确定阵营,且进球了
  522. if (this.gameMgr.aiBallArr.indexOf(number) > -1) {
  523. //进了己方阵营的球
  524. play = true;
  525. }
  526. }
  527. else {
  528. play = true;
  529. }
  530. }
  531. //
  532. if (play) xGame.soundMgr.playSound("applause");
  533. }
  534. destroyClassicEmotion() {
  535. if (this.gameMode == GameMode.bigMove) return;
  536. let parent = this.gameUI.ui.classicEmotionSpineNode.displayObject;
  537. parent.destroyChildren();
  538. }
  539. playAwardSpine(x, y) {
  540. let data = { x: x, y: y, scaleX: 1, scaleY: 1 };
  541. let parent = this.gameUI.ui.awardSpineNode.displayObject;
  542. this.awardSpine.play(data, 0, false, parent);
  543. }
  544. destroyAwardSpine() {
  545. let parent = this.gameUI.ui.awardSpineNode.displayObject;
  546. parent.destroyChildren();
  547. }
  548. tempDir1 = new Laya.Vector2();
  549. tempDir2 = new Laya.Vector2();
  550. ballSize = 33;
  551. isBlock(bx, by, hx, hy, except: D2BallSrc = null) {
  552. this.tempDir1 = xGame.tools.getV2Dir(bx, by, hx, hy, this.tempDir1);
  553. let balls = xGame.common.d2World.ballArr;
  554. let outArr = [];
  555. for (let index = 0; index < balls.length; index++) {
  556. let obj = balls[index];
  557. if (obj.number == 0) continue;
  558. if (obj == except) continue;
  559. //其他球与该球的方向距离
  560. let dis = xGame.tools.getDistance(obj.gameObj.x, obj.gameObj.y, bx, by);
  561. this.tempDir2 = xGame.tools.getV2Dir(bx, by, obj.gameObj.x, obj.gameObj.y, this.tempDir2);
  562. let num = Laya.Vector2.dot(this.tempDir1, this.tempDir2);
  563. if (num >= 1) num = 1;
  564. if (num < 0) //大于90
  565. continue;
  566. let gap = Math.sin(Math.acos(num)) * dis;
  567. if (gap < this.ballSize) {
  568. outArr.push({
  569. dis: xGame.tools.getDis(bx, by, obj.gameObj.x, obj.gameObj.y),
  570. disHon: Math.cos(Math.acos(num)) * dis,
  571. disVer: Math.sin(Math.acos(num)) * dis,
  572. src: balls[index],
  573. dir: this.tempDir1
  574. })
  575. }
  576. }
  577. //
  578. if (outArr.length > 0) {
  579. outArr.sort((a, b) => { return a.dis - b.dis });
  580. return outArr[0];
  581. }
  582. }
  583. public AngleBetween(vector1, vector2) {
  584. let rad = Math.acos(Laya.Vector2.dot(vector1, vector2));
  585. return rad * (180 / Math.PI);
  586. }
  587. public getSecretaryScale() {
  588. if (this.secretary.spineName == "mishu") {
  589. return 1.28;
  590. }
  591. else {
  592. return 1.024;
  593. }
  594. }
  595. //签到奖励中是否包含球杆
  596. public signAwardContainsRod(arr) {
  597. let temp;
  598. for (let index = 0; index < arr.length; index++) {
  599. temp = arr[index].split('-')[0];
  600. if (parseInt(temp) > 2) {
  601. return true;
  602. }
  603. }
  604. }
  605. judgeSameDay() {
  606. let lastTime = DataMgr.getSignTime();
  607. let curTime = new Date().getTime();
  608. if (new Date(lastTime).toDateString() === new Date(curTime).toDateString()) {
  609. return true;
  610. }
  611. return false;
  612. }
  613. getAward(arr: Array<AwardType>, callback?) {
  614. let showTriple = arr[0].type <= 2;
  615. xGame.uiMgr.Show(UIGetAward, arr, showTriple, (watchVideo) => {
  616. let temp: AwardType;
  617. for (let index = 0; index < arr.length; index++) {
  618. temp = arr[index];
  619. switch (temp.type) {
  620. case 1:
  621. //钻石
  622. this.playObjFlyAnim(temp.num, temp.type);
  623. break;
  624. case 2:
  625. //金币
  626. this.playObjFlyAnim(temp.num, temp.type);
  627. break;
  628. case 3:
  629. case 4:
  630. case 5:
  631. case 6:
  632. DataMgr.setBallRod(temp.type - 2, 1);
  633. DataMgr.setCurBallRod(temp.type - 2);
  634. break;
  635. default:
  636. break;
  637. }
  638. }
  639. //
  640. callback && callback(watchVideo);
  641. })
  642. }
  643. //飞金币或飞钱钱特效
  644. stPos = new Laya.Point();
  645. edPos = new Laya.Point();
  646. getMoneyNode() {
  647. let moneyNode: ui_UIMoney;
  648. let sign = <UISign>xGame.uiMgr.getUI(UISign);
  649. let draw = <UIDraw>xGame.uiMgr.getUI(UIDraw);
  650. let end = <UIGameEnd>xGame.uiMgr.getUI(UIGameEnd);
  651. let skill = <UISkill>xGame.uiMgr.getUI(UISkill);
  652. if (sign && !sign.isHide) moneyNode = sign.ui.moneyNode;
  653. if (draw && !draw.isHide) moneyNode = draw.ui.moneyNode;
  654. if (end && !end.isHide) moneyNode = end.ui.moneyNode;
  655. if (skill && !skill.isHide) moneyNode = skill.ui.moneyNode;
  656. let condition1 = (!sign || sign.isHide) && (!draw || draw.isHide) && (!skill || skill.isHide);
  657. let main = <UIMain>xGame.uiMgr.getUI(UIMain);
  658. if (condition1 && main && !main.isHide) {
  659. moneyNode = main.ui.moneyNode;
  660. }
  661. return moneyNode;
  662. }
  663. playObjFlyAnim(num, type, callback = null) {
  664. this.stPos.x = Laya.stage.width / 2;
  665. this.stPos.y = Laya.stage.height / 2;
  666. //
  667. let moneyNode = this.getMoneyNode();
  668. //
  669. switch (type) {
  670. case Prop.diamond:
  671. this.edPos.x = moneyNode.x + moneyNode.diamondImg.x
  672. this.edPos.y = moneyNode.y + moneyNode.diamondImg.y
  673. moneyNode.diamondImg.displayObject.localToGlobal(this.edPos);
  674. this.edPos.x /= 2;
  675. this.edPos.y /= 2;
  676. break;
  677. case Prop.coin:
  678. this.edPos.x = moneyNode.x + moneyNode.coinImg.x
  679. this.edPos.y = moneyNode.y + moneyNode.coinImg.y
  680. moneyNode.coinImg.displayObject.localToGlobal(this.edPos);
  681. this.edPos.x /= 2;
  682. this.edPos.y /= 2;
  683. break;
  684. default:
  685. break;
  686. }
  687. // this.edPos.x += this.sysOffestNum;
  688. xGame.soundMgr.playSound("coinbag");
  689. //
  690. xGame.uiMgr.Show(UIFlyEft, this.stPos, this.edPos, num, type, () => {
  691. //完成后的回调用
  692. switch (type) {
  693. case Prop.diamond:
  694. DataMgr.setDiamond(num);
  695. break;
  696. case Prop.coin:
  697. DataMgr.setCoin(num);
  698. break;
  699. default:
  700. break;
  701. }
  702. callback && callback();
  703. })
  704. }
  705. //
  706. autoPopUIView() {
  707. let arr = [];
  708. let sign = this.judgeSameDay() ? false : true;
  709. if (sign) arr.push("sign");
  710. let draw = DataMgr.getDailyfreeDrawTimes() > 0;
  711. if (draw) arr.push("draw");
  712. if (arr.length <= 0) return;
  713. let str = this.getRandArrEle(arr);
  714. switch (str) {
  715. case "sign":
  716. xGame.uiMgr.Show(UISign);
  717. break;
  718. case "draw":
  719. xGame.uiMgr.Show(UIDraw);
  720. break;
  721. default:
  722. break;
  723. }
  724. }
  725. //
  726. getMSTime(time) {
  727. let min: any = Math.floor(time / 60);
  728. let sec: any = Math.floor((time - min * 60))
  729. if (sec < 10) sec = "0" + sec;
  730. if (min < 10) min = "0" + min;
  731. return `${min}:${sec}`
  732. }
  733. testPower() {
  734. DataMgr.setPower(0, false);
  735. }
  736. getAllStarNum() {
  737. let data = DataMgr.getPlaceBallLevelList();
  738. let out = 0;
  739. for (let index = 0; index < data.length; index++) {
  740. out += data[index].star;
  741. }
  742. return out;
  743. }
  744. recoverCameraView() {
  745. Laya.timer.once(900, this, () => {
  746. xGame.common.showOneCamera("mainCamera");
  747. if (xGame.common.gameUI.ui.d2Node.alpha == 0) {
  748. xGame.common.gameUI.ui.d2Node.alpha = 1;
  749. xGame.common.gameUI.ui.border.alpha = 0;
  750. //
  751. if (Laya.physicsTimer.scale < 1) {
  752. Laya.physicsTimer.scale = 1;
  753. }
  754. }
  755. })
  756. }
  757. //获取经典模式的段位
  758. getClassicLevel() {
  759. let successTimes = DataMgr.getClassicTimes();
  760. let needKey = "";
  761. let lastKey = "";
  762. let cfg = cfgTable.classictimesData;
  763. let data: cfgTable.classictimes;
  764. for (const key in cfg) {
  765. data = cfg[key];
  766. if (successTimes <= data.times) {
  767. needKey = key;
  768. }
  769. lastKey = key;
  770. }
  771. if (needKey == "") needKey = lastKey;
  772. //
  773. return cfg[needKey];
  774. }
  775. }