Common.ts 26 KB

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