1
0

GameMgr.ts 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. import D2BallSrc from "../d2Obj/D2BallSrc";
  2. import DataMgr from "../data/DataMgr";
  3. import { ALL_BALL_STOP, ballCamp, BALL_SHOOT, ClassicWordsType, FIRST_BALL_HOLE, FoulType, GameMode, PlaceBallType, RESET_GAME, SkillType, TipsType, WAIT_SHOOT } from "../data/Define";
  4. import UIGameEnd from "../ui/UIGameEnd";
  5. import UIRepentProp from "../ui/UIRepentProp";
  6. import UIMsg from "../ui/UIMsg";
  7. import UIVideoShare from "../ui/UIVideoShare";
  8. import { getScreenImg } from "../utils/Utils";
  9. import { xGame } from "../xGame";
  10. import PlatMgr from "./PlatMgr";
  11. import UITips from "../ui/UITips";
  12. //游戏数据相关的值
  13. export default class GameMgr {
  14. selfCamp = "";
  15. selfFoulNum = 0;//玩家犯规次数
  16. selfBallArr = [];//除了黑8以外的球
  17. selfTimer: number = 0;
  18. selfScore: number = 0;
  19. selfCurSkill: SkillType;
  20. //
  21. aiCamp = "";
  22. aiFoulNum = 0;//ai犯规次数
  23. aiBallArr = [];//除了黑8以外的球
  24. aiTimer: number = 0;
  25. aiScore: number = 0;
  26. aiCurSkill: SkillType;
  27. /**ai选中的技能的等级 */
  28. aiSkillLevelNum: number = 1;
  29. //目前分数
  30. targertScore: number = 0;
  31. //计时器
  32. setTime = 30;
  33. //开局轮到自己的概率
  34. selfTurnRate = 0.5;
  35. accTime = 0;
  36. curTimer: fgui.GProgressBar;
  37. //犯规类型
  38. curFoul = "";
  39. //最大犯规次数
  40. maxFoulTimes = 3;
  41. //是否是一句游戏中的第一杆
  42. isFirstInGame: boolean = true;
  43. //首次碰撞到的球
  44. firstColliObj: any = null;
  45. //打进洞的所有球
  46. inHoleBalls = [];
  47. //黑8
  48. blackNum: number = 8;
  49. //
  50. success: boolean = false;
  51. //袋口位置
  52. holePosList = [];
  53. posObj = {};
  54. //
  55. public _selfTurn: boolean = false;//是否轮到自己
  56. //上一次白球位置
  57. lastRootBallPos = new Laya.Vector2(311, 430);
  58. //是否已经确定了双方的阵营了
  59. public ensureBallType: boolean = false;
  60. //是否是开球时刻,第一次进球之后开球就变为false
  61. public isOpenBall: boolean = true;
  62. public finishOneShoot: boolean = true;
  63. //
  64. public isEnd = false;//游戏是否结束
  65. public isChangeTurn = false;//是否交换球权
  66. public isInterrupt = false;//连击是否被打断了
  67. //
  68. //public isSelfOutSkills: boolean = false;
  69. public aiPlayedBreakArmy: boolean = false;
  70. //
  71. public isTouchedBall: boolean = false;
  72. //摆球达人模式
  73. //已完成的进球数
  74. public finishBalls: number = 0;
  75. //需要进球的总数目
  76. public needBalls: number = 0;
  77. //场上除了白球的所有球数目
  78. public allBallNum: number = 0;
  79. //上一次操作的所有球位置信息
  80. public placeBallPosData = {};
  81. //当前血量
  82. public curHP: number = 0;
  83. //摆球达人数据
  84. public placeBallData: cfgTable.placeball;
  85. //
  86. public showLongView: boolean = false;
  87. //首次shoot
  88. firstShoot = true;
  89. //
  90. //游戏是否暂停
  91. _gamePause: boolean = false;
  92. /**
  93. * 换边次数
  94. */
  95. trunCount: number = 0;
  96. public get gamePause(): boolean {
  97. return this._gamePause;
  98. }
  99. public set gamePause(v: boolean) {
  100. if (v) {
  101. //游戏暂定
  102. Laya.physicsTimer.pause();
  103. }
  104. else {
  105. //游戏恢复
  106. Laya.physicsTimer.resume();
  107. }
  108. this._gamePause = v;
  109. }
  110. //
  111. public get selfTurn(): boolean {
  112. return this._selfTurn;
  113. }
  114. public set selfTurn(val) {
  115. this.trunCount++;
  116. this._selfTurn = val;
  117. if (val) {
  118. xGame.common.d2World.d2Gan.ui.self.visible = true;
  119. xGame.common.d2World.d2Gan.ui.ai.visible = false;
  120. }
  121. else {
  122. xGame.common.d2World.d2Gan.ui.self.visible = false;
  123. xGame.common.d2World.d2Gan.ui.ai.visible = true;
  124. if (this.trunCount > 1)
  125. PlatMgr.openBox();
  126. }
  127. }
  128. //是否有人打进了黑8
  129. public isBlackInHole: boolean = false;
  130. //
  131. constructor() {
  132. xGame.eventMgr.offAll(ALL_BALL_STOP)
  133. xGame.eventMgr.on(ALL_BALL_STOP, this, this.gameRun);
  134. //
  135. xGame.eventMgr.off(BALL_SHOOT, this, this.ballShoot);
  136. xGame.eventMgr.on(BALL_SHOOT, this, this.ballShoot);
  137. //
  138. xGame.eventMgr.off(FIRST_BALL_HOLE, this, this.ensureCamp);
  139. xGame.eventMgr.on(FIRST_BALL_HOLE, this, this.ensureCamp);
  140. //
  141. xGame.eventMgr.off(RESET_GAME, this, this.resetGame);
  142. xGame.eventMgr.on(RESET_GAME, this, this.resetGame);
  143. }
  144. resetGame() {
  145. this.inHoleBalls = [];
  146. this.isFirstInGame = true;
  147. this.firstColliObj = null;
  148. this.aiCamp = "";
  149. this.selfCamp = "";
  150. this.aiFoulNum = 0;
  151. this.selfFoulNum = 0;
  152. this.selfBallArr = [];
  153. this.aiBallArr = [];
  154. this.gamePause = false;
  155. this.ensureBallType = false;
  156. this.isInterrupt = false;
  157. this.updateLeftBall();
  158. this.clearTime();
  159. //
  160. // this.isSelfOutSkills = false;
  161. this.aiPlayedBreakArmy = false;
  162. //
  163. this.isBlackInHole = false;
  164. this.placeBallPosData = {};
  165. //
  166. if (xGame.common.d3World.knifeRoot) {
  167. xGame.common.d3World.knifeRoot.destroyChildren();
  168. }
  169. }
  170. //游戏准备ok
  171. gameReady() {
  172. //开球顺序
  173. this.trunCount = 0;
  174. this.firstColliObj = null;
  175. this.isFirstInGame = true;
  176. this.selfTurn = Math.random() <= this.selfTurnRate;
  177. let challengeNum = DataMgr.getChallengeTimes();
  178. if (xGame.common.gameMode == GameMode.classic && challengeNum >= 1 && challengeNum <= 3) {
  179. this.selfTurn = true;
  180. }
  181. if (xGame.common.gameMode == GameMode.placeBall) this.selfTurn = true;
  182. if (xGame.common.gameMode == GameMode.bigMove && !DataMgr.getSkillGuide()) {
  183. this.selfTurn = true;
  184. }
  185. xGame.common.gameUI.setTurnAlpha(this.selfTurn);
  186. this.checkGuide();
  187. //高低杆重置
  188. if (xGame.common.uiRodMethod) xGame.common.uiRodMethod.resetRod();
  189. //辅助线
  190. xGame.common.d2World.getHelpLine();
  191. //开局可以摆球
  192. this.isOpenBall = true;
  193. this.isTouchedBall = false;
  194. //
  195. xGame.common.aiPlayer.stopRun();
  196. this.setTime = 30;
  197. let ui = xGame.common.gameUI.ui;
  198. switch (xGame.common.gameMode) {
  199. case GameMode.classic:
  200. //AI初始化
  201. xGame.common.aiPlayer.init();
  202. this.blackNum = 8;
  203. this.placeRootBall();
  204. this.peoplePlay(9, 10);
  205. ui.wordsBtn.visible = true;
  206. ui.aiWordsBtn.visible = true;
  207. xGame.common.talkMgr.changeAIState(true);
  208. DataMgr.gameData.gameCount++;
  209. DataMgr.saveGameData();
  210. break;
  211. case GameMode.bigMove:
  212. this.blackNum = -1;
  213. this.selfScore = 0;
  214. this.aiScore = 0;
  215. //AI初始化
  216. xGame.common.aiPlayer.init();
  217. //
  218. this.targertScore = cfgTable.bigmoveData[xGame.common.bigMoveLevelIndex].target;
  219. //
  220. this.updateSelfScore();
  221. this.updateAIScore();
  222. this.updateTargetSroce();
  223. this.placeRootBall();
  224. this.peoplePlay(9, 10);
  225. ui.wordsBtn.visible = true;
  226. ui.aiWordsBtn.visible = true;
  227. xGame.common.talkMgr.changeAIState(true);
  228. if (DataMgr.getSkillGuide() < 1)
  229. DataMgr.gameData.gameCount = 0;
  230. else {
  231. DataMgr.gameData.gameCount++;
  232. DataMgr.saveGameData();
  233. PlatMgr.openTry();
  234. }
  235. //
  236. if (xGame.common.d3World.knifeRoot) {
  237. xGame.common.d3World.knifeRoot.destroyChildren();
  238. }
  239. //
  240. break;
  241. case GameMode.placeBall:
  242. this.blackNum = -1;
  243. this.selfTurn = true;
  244. this.setTime = 10000;
  245. this.placeBallData = cfgTable.placeballData[xGame.common.placeBallCurLevel];
  246. this.curHP = this.placeBallData.hp;
  247. //
  248. if (this.placeBallData.ball == -1) this.needBalls = xGame.common.d2World.ballArr.length - 1;
  249. else this.needBalls = this.placeBallData.ball;
  250. console.log("需要的进球数目", this.needBalls);
  251. this.allBallNum = xGame.common.d2World.ballArr.length - 1;
  252. //
  253. this.finishBalls = 0;
  254. this.placeBallPosData = {};
  255. this.updatePlaceBallPos();
  256. this.updatePlaceBallState();
  257. this.finishOneShoot = true;
  258. xGame.common.gameUI.ui.moveNode.visible = false;
  259. this.isOpenBall = false;
  260. xGame.common.d2World.d2Gan.ui.ai.visible = false;
  261. ui.wordsBtn.visible = false;
  262. ui.aiWordsBtn.visible = false;
  263. xGame.common.talkMgr.changeAIState(false);
  264. Laya.timer.frameOnce(xGame.tools.random(2000, 5100), this, () => {
  265. PlatMgr.openBox();
  266. })
  267. break;
  268. default:
  269. break;
  270. }
  271. //
  272. this.showLongView = false;
  273. xGame.common.wordsMgr.comboTimes = 1;
  274. let guide = DataMgr.getSkillGuide();
  275. if (guide) xGame.eventMgr.event(WAIT_SHOOT);
  276. //
  277. xGame.common.upSkillLevel = false;
  278. xGame.common.gameStartTime = new Date().getTime();
  279. //
  280. this.firstShoot = true;
  281. }
  282. checkGuide() {
  283. let guide = DataMgr.getSkillGuide();
  284. let gameUI = xGame.common.gameUI.ui;
  285. gameUI.guide1.visible = false;
  286. gameUI.guide2.visible = false;
  287. gameUI.guide3.visible = false;
  288. if (guide == 0 && xGame.common.gameMode == GameMode.bigMove) {
  289. this.selfTurn = true;
  290. }
  291. else {
  292. return;
  293. }
  294. //////
  295. let oneBall = this.getOneBall();
  296. gameUI.guide1.visible = true;
  297. gameUI.guide1.fingerNode.x = oneBall.gameObj.x;
  298. gameUI.guide1.fingerNode.y = oneBall.gameObj.y;
  299. }
  300. getOneBall() {
  301. let arr = xGame.common.d2World.ballArr;
  302. for (let index = 0; index < arr.length; index++) {
  303. if (arr[index].number == 0) continue;
  304. return arr[index];
  305. }
  306. }
  307. updateSelfScore() {
  308. let ui = xGame.common.gameUI.ui.topNode;
  309. ui.selfScoreTxt.text = this.selfScore + "";
  310. }
  311. updateAIScore() {
  312. let ui = xGame.common.gameUI.ui.topNode;
  313. ui.aiScoreTxt.text = this.aiScore + "";
  314. }
  315. updateTargetSroce() {
  316. let ui = xGame.common.gameUI.ui.topNode;
  317. ui.middleNode.targetScoreTxt.text = this.targertScore + "";
  318. }
  319. updateLeftBall() {
  320. let topUI = xGame.common.gameUI.ui.topNode;
  321. //设置自己的球
  322. topUI.selfBallList.numItems = this.selfBallArr.length;
  323. topUI.aiBallList.numItems = this.aiBallArr.length;
  324. }
  325. //母球发射
  326. ballShoot() {
  327. this.clearTime();
  328. //
  329. this.finishOneShoot = false;
  330. xGame.common.gameUI.ui.moveNode.visible = false;
  331. //xGame.common.longHelpLine = false;
  332. if (xGame.common.gameUI.ui.guideNode.visible) {
  333. xGame.common.gameUI.ui.guideNode.visible = false;
  334. }
  335. //
  336. if (this.firstShoot) {
  337. this.firstShoot = false;
  338. Moyu.sendDataEvent(`gameType${xGame.common.gameMode}`);
  339. }
  340. }
  341. //确定阵营
  342. ensureCamp(number) {
  343. this.ensureBallType = true;
  344. this.isOpenBall = false;
  345. if (xGame.common.gameMode != GameMode.classic) return;
  346. let full = [1, 2, 3, 4, 5, 6, 7];
  347. let flower = [9, 10, 11, 12, 13, 14, 15];
  348. let sayWords = "";
  349. if (this.selfTurn) {
  350. if (number <= 7) {
  351. this.selfCamp = ballCamp.full;
  352. this.selfBallArr = full;
  353. //
  354. this.aiCamp = ballCamp.flower;
  355. this.aiBallArr = flower
  356. //玩家为全色球
  357. sayWords = cfgTable.wordsData[3].msg;
  358. }
  359. else {
  360. this.selfCamp = ballCamp.flower;
  361. this.selfBallArr = flower;
  362. //
  363. this.aiCamp = ballCamp.full;
  364. this.aiBallArr = full;
  365. //玩家为花色球
  366. sayWords = cfgTable.wordsData[4].msg;
  367. }
  368. }
  369. else {
  370. if (number <= 7) {
  371. this.selfCamp = ballCamp.flower;
  372. this.selfBallArr = flower;
  373. //
  374. this.aiCamp = ballCamp.full;
  375. this.aiBallArr = full;
  376. //玩家为花色球
  377. sayWords = cfgTable.wordsData[2].msg;
  378. }
  379. else {
  380. this.selfCamp = ballCamp.full;
  381. this.selfBallArr = full;
  382. //
  383. this.aiCamp = ballCamp.flower;
  384. this.aiBallArr = flower
  385. //玩家为全色球
  386. sayWords = cfgTable.wordsData[1].msg;
  387. }
  388. }
  389. this.updateLeftBall();
  390. //
  391. xGame.uiMgr.Show(UIMsg, sayWords);
  392. }
  393. updatePlaceBallState() {
  394. let ui = xGame.common.gameUI.ui;
  395. switch (this.placeBallData.type) {
  396. case PlaceBallType.normal:
  397. let normal = ui.placeNormalNode;
  398. normal.hpTxt.text = this.curHP + "";
  399. this.updatePlaceBallStar(normal);
  400. normal.ballTxt.text = this.finishBalls + "/" + this.needBalls;
  401. normal.levelTxt.text = `Level ${xGame.common.placeBallCurLevel}`;
  402. break;
  403. case PlaceBallType.challenge:
  404. let challenge = ui.placeChallengeNode;
  405. challenge.hpTxt.text = "Shots:" + this.curHP;//杆数
  406. challenge.ballTxt.text = this.finishBalls + "/" + this.allBallNum;
  407. challenge.levelTxt.text = `Level ${xGame.common.placeBallCurLevel}`;
  408. challenge.tipsTxt.text = `Pocket ${this.needBalls} balls `;//打进颗球
  409. break;
  410. default:
  411. break;
  412. }
  413. }
  414. playSubHpAni() {
  415. let ui = xGame.common.gameUI.ui;
  416. switch (this.placeBallData.type) {
  417. case PlaceBallType.normal:
  418. let normal = ui.placeNormalNode;
  419. normal.hpTxt.visible = false;
  420. normal.starAni.c1.selectedIndex = 1;
  421. normal.starAni.t0.play(Laya.Handler.create(this, () => {
  422. normal.hpTxt.visible = true;
  423. normal.starAni.c1.selectedIndex = 0;
  424. }))
  425. break;
  426. default:
  427. break;
  428. }
  429. }
  430. getEndStarNum() {
  431. let num;
  432. let level = xGame.common.placeBallCurLevel;
  433. if (this.curHP == this.placeBallData.hp) {
  434. num = 3;
  435. }
  436. else if (this.curHP <= 1) {
  437. num = 1;
  438. }
  439. else {
  440. num = 2;
  441. }
  442. if (!this.success) {
  443. num = 0;
  444. }
  445. else {
  446. DataMgr.setPlaceBallLevel(level, num);
  447. }
  448. //
  449. let myType = cfgTable.placeballData[level].type;
  450. if (this.success && myType == 1) {
  451. num = 3;
  452. }
  453. xGame.common.placeBallStarNum = num;
  454. }
  455. //更新摆球达人清台模式通关星星等级
  456. updatePlaceBallStar(node) {
  457. let star = 0
  458. if (this.curHP == this.placeBallData.hp) {
  459. star = 3
  460. }
  461. else if (this.curHP >= 2) {
  462. star = 2;
  463. }
  464. else if (this.curHP == 1) {
  465. star = 1;
  466. }
  467. else {
  468. star = 0;
  469. }
  470. let temp;
  471. for (let index = 1; index <= 3; index++) {
  472. temp = node["star" + index];
  473. temp.c1.selectedIndex = star >= index ? 1 : 0;
  474. }
  475. node.myProgress.value = (star / 3) * 100;
  476. }
  477. openRegretView(isFoul, GoalNum, challenge = false) {
  478. let regretType = -1;
  479. if (isFoul) {
  480. //白球进洞
  481. regretType = 1;
  482. }
  483. else {
  484. //未进球
  485. if (GoalNum <= 0) {
  486. regretType = 0;
  487. }
  488. }
  489. //挑战模式白球进洞,
  490. if (challenge) {
  491. regretType = 1;
  492. }
  493. //
  494. if (regretType != -1) {
  495. xGame.uiMgr.Show(UIRepentProp, 1, regretType, (success) => {
  496. if (success) {
  497. //成功悔球
  498. this.curHP++;
  499. this.updatePlaceBallState();
  500. this.setPlaceBallAllPos();
  501. xGame.common.gameUI.ui.moveNode.visible = false;
  502. }
  503. else {
  504. //未进行悔球,弹出失败结算界面
  505. if (this.curHP <= 0) {
  506. this.success = false;
  507. this.gameEnd();
  508. }
  509. this.playSubHpAni();
  510. }
  511. this.updatePlaceBallState();
  512. this.updatePlaceBallPos();
  513. });
  514. }
  515. }
  516. setPlaceBallAllPos() {
  517. let allBall = xGame.common.d2World.ballArr;
  518. let cfgArr = this.placeBallPosData;
  519. let temp: D2BallSrc;
  520. let obj;
  521. for (let index = 0; index < allBall.length; index++) {
  522. temp = allBall[index];
  523. if (temp.destroyed) continue;
  524. obj = cfgArr[temp.myUNID];
  525. if (obj && obj.src && !obj.src.destroyed) {
  526. temp.gameObj.x = obj.posX;
  527. temp.gameObj.y = obj.posY;
  528. temp.d3BallSrc.setTransPos(obj.posX, obj.posY);
  529. }
  530. }
  531. xGame.common.d2World.getHelpLine();
  532. }
  533. updatePlaceBallPos() {
  534. let arr = xGame.common.d2World.ballArr;
  535. let temp: D2BallSrc;
  536. for (let index = 0; index < arr.length; index++) {
  537. temp = arr[index];
  538. if (!this.placeBallPosData[temp.myUNID]) {
  539. this.placeBallPosData[temp.myUNID] = {
  540. src: temp,
  541. posX: temp.gameObj.x,
  542. posY: temp.gameObj.y
  543. };
  544. }
  545. else {
  546. this.placeBallPosData[temp.myUNID].posX = temp.gameObj.x;
  547. this.placeBallPosData[temp.myUNID].posY = temp.gameObj.y;
  548. }
  549. }
  550. //
  551. let check;
  552. for (const key in this.placeBallPosData) {
  553. check = this.placeBallPosData[key];
  554. if (check.src.destroyed) {
  555. delete this.placeBallPosData[key]
  556. }
  557. }
  558. }
  559. //所有球静止,进行下一次打球判断
  560. gameRun(type) {
  561. //
  562. if (this.gamePause) return;
  563. this.curFoul = this.getFoulType();
  564. if (type) {
  565. xGame.common.d2World.d2Gan.shoot();
  566. xGame.common.gameUI.forceCancel();
  567. this.curFoul = type;
  568. }
  569. //
  570. this.isEnd = false;
  571. this.isChangeTurn = true;
  572. //
  573. if (xGame.common.gameMode == GameMode.classic) {
  574. this.judgeClassic(this.curFoul);
  575. this.checkClassicWords(() => {
  576. xGame.common.destroyClassicEmotion();
  577. if (this.isEnd) {
  578. if (this.isBlackInHole) {
  579. //黑8进洞
  580. xGame.common.gameUI.ui.blackAni.visible = true;
  581. xGame.common.gameUI.ui.blackAni.t0.play(Laya.Handler.create(this, () => {
  582. xGame.common.gameUI.ui.blackAni.visible = false;
  583. this.gameEnd();
  584. }))
  585. }
  586. else {
  587. this.gameEnd();
  588. }
  589. }
  590. else {
  591. this.waitShoot();
  592. xGame.eventMgr.event(WAIT_SHOOT);
  593. }
  594. });
  595. }
  596. else if (xGame.common.gameMode == GameMode.bigMove) {
  597. xGame.common.aiPlayer.stopRun();
  598. let scoreArr = this.getScore(this.curFoul);
  599. if (this.judgeScoreEnd(scoreArr[0], scoreArr[1])) {
  600. this.isEnd = true;
  601. }
  602. this.checkBigSkillWords(() => {
  603. if (this.isEnd) {
  604. this.gameEnd();
  605. }
  606. else {
  607. this.waitShoot();
  608. xGame.eventMgr.event(WAIT_SHOOT);
  609. }
  610. })
  611. }
  612. else if (xGame.common.gameMode == GameMode.placeBall) {
  613. //
  614. xGame.common.destroyAwardSpine();
  615. //
  616. //是否犯规
  617. let isFoul = this.curFoul == FoulType.rootHole;
  618. //是否进球(白球进不算)
  619. let GoalNum = this.inHoleBalls.length;
  620. if (this.inHoleBalls.indexOf(0) > -1) GoalNum -= 1;
  621. //
  622. if (isFoul) {
  623. this.placeRootBall();
  624. }
  625. console.log("neeballs", this.needBalls);
  626. console.log("当前完成的goalNum", GoalNum);
  627. this.finishBalls += GoalNum;
  628. console.log("当前完成的finishballs", this.finishBalls);
  629. let need = this.needBalls;
  630. if (this.placeBallData.type == PlaceBallType.challenge) {
  631. need += 100;
  632. }
  633. if (this.finishBalls >= need) {
  634. //游戏成功
  635. this.success = true;
  636. this.gameEnd();
  637. }
  638. else {
  639. switch (this.placeBallData.type) {
  640. case PlaceBallType.normal:
  641. if (!isFoul && GoalNum > 0) {
  642. //未犯规且进球了,不扣除hp
  643. this.updatePlaceBallPos();
  644. this.updatePlaceBallState();
  645. }
  646. else {
  647. this.curHP--;
  648. this.openRegretView(isFoul, GoalNum);
  649. }
  650. this.waitShoot();
  651. xGame.eventMgr.event(WAIT_SHOOT);
  652. break;
  653. case PlaceBallType.challenge:
  654. this.curHP--;
  655. this.updatePlaceBallState();
  656. if (isFoul) {
  657. this.openRegretView(isFoul, GoalNum, true);
  658. }
  659. else {
  660. this.updatePlaceBallPos();
  661. if (this.curHP <= 0) {
  662. this.success = true;
  663. this.gameEnd();
  664. }
  665. }
  666. this.waitShoot();
  667. xGame.eventMgr.event(WAIT_SHOOT);
  668. break;
  669. default:
  670. break;
  671. }
  672. }
  673. }
  674. }
  675. //经典版本的spine话语
  676. checkClassicWords(callback) {
  677. //未犯规和第一次错误的touch 都不算犯规
  678. xGame.common.wordsMgr.setClassicCombo(this.isChangeTurn);
  679. let condition = !this.isChangeTurn && (this.curFoul == "" || this.curFoul == FoulType.wrongTouch);
  680. let type = this.getClassicWordsType();
  681. if (condition && type != -1) {
  682. let str = Math.random() <= 0.5 ? "hint01" : "hint02";
  683. xGame.soundMgr.playSound(str);
  684. xGame.common.wordsMgr.playClassicWords(type, callback);
  685. }
  686. else {
  687. //违规了,不播放spine
  688. //没有出现5种进球的话语
  689. Laya.timer.once(300, this, () => {
  690. callback && callback();
  691. })
  692. }
  693. }
  694. getClassicWordsType() {
  695. let d2world = xGame.common.d2World;
  696. let type = -1;
  697. if (!this.isInterrupt && this.judgeNormalSuccess()) {
  698. //未交换过球权且全部打进
  699. type = ClassicWordsType.perfectShow;
  700. return type;
  701. }
  702. if (this.inHoleBalls.length == 1 && d2world.targetBall && this.inHoleBalls[0] == d2world.targetBall.number && d2world.isOnSameLine) {
  703. //空心入袋
  704. type = ClassicWordsType.directShoot;
  705. return type;
  706. }
  707. if (this.inHoleBalls.length > 0 && (d2world.targetBall == null || this.inHoleBalls.indexOf(d2world.targetBall.number) <= -1)) {
  708. //借力使力
  709. type = ClassicWordsType.anotherShoot;
  710. return type;
  711. }
  712. if (d2world.powerPercent == 100 && this.inHoleBalls.length > 0) {
  713. //大力出奇迹
  714. type = ClassicWordsType.bigPower;
  715. return type;
  716. }
  717. //只进一个球,且最后进洞速度小于一个值
  718. let minSpeed = 1;
  719. if (this.inHoleBalls.length == 1 && xGame.common.d2World.inHolesSpeed[0] <= minSpeed) {
  720. type = ClassicWordsType.hardShoot;
  721. return type;
  722. }
  723. if (this.inHoleBalls.length > 0) {
  724. type = ClassicWordsType.directShoot;
  725. return type;
  726. }
  727. return type;
  728. }
  729. //大招版本的spine的话语
  730. checkBigSkillWords(callback) {
  731. if (this.curFoul == FoulType.timeOut) {
  732. callback && callback();
  733. }
  734. else {
  735. let playSkill = false;
  736. if (this.selfTurn) {
  737. // if (!this.isSelfOutSkills) {
  738. // this.isSelfOutSkills = true;
  739. // playSkill = true;
  740. // }
  741. playSkill = true;
  742. }
  743. else {
  744. if (!this.aiPlayedBreakArmy) {
  745. this.aiPlayedBreakArmy = true;
  746. playSkill = true;
  747. }
  748. if (this.aiCurSkill != SkillType.breakArmy) {
  749. playSkill = true;
  750. }
  751. }
  752. if (xGame.common.skillMgr.playedLastSkill) {
  753. xGame.common.skillMgr.playedLastSkill = false;
  754. playSkill = false;
  755. }
  756. //
  757. ///////////////////
  758. if (playSkill) {
  759. //判断大招破军
  760. xGame.common.skillMgr.runBigSkill((extraScore) => {
  761. //播放大招技能后增加的额外分数
  762. let selfExtra = 0;
  763. let aiExtra = 0;
  764. if (this.selfTurn) selfExtra += extraScore;
  765. else aiExtra += extraScore;
  766. if (this.judgeScoreEnd(selfExtra, aiExtra)) {
  767. this.isEnd = true;
  768. }
  769. this.playBigSkillTimes(callback);
  770. });
  771. }
  772. else {
  773. this.playBigSkillTimes(callback);
  774. }
  775. }
  776. }
  777. playBigSkillTimes(callback) {
  778. //播放spine
  779. let length = this.inHoleBalls.length;
  780. if (this.inHoleBalls.indexOf(0) > -1) {
  781. length = this.inHoleBalls.length - 1;
  782. }
  783. if (length <= 0) {
  784. callback && callback();
  785. return;
  786. }
  787. xGame.common.wordsMgr.playBigSkillTimes(length, () => {
  788. callback && callback();
  789. })
  790. }
  791. playSkillTips() {
  792. let levelNum = 0;
  793. let curType;
  794. if (this.selfTurn) {
  795. levelNum = DataMgr.getBigSkillByIndex(this.selfCurSkill);
  796. curType = this.selfCurSkill;
  797. if (curType == DataMgr.gameData.trySkill && Laya.timer.currTimer < DataMgr.gameData.tryTime) {
  798. levelNum += 5;
  799. }
  800. }
  801. else {
  802. levelNum = this.aiSkillLevelNum;
  803. curType = this.aiCurSkill;
  804. }
  805. //
  806. let str = ``;
  807. switch (curType) {
  808. case SkillType.highSpace:
  809. str = `An extra ${xGame.common.extraMoveNum} balls were moved`;
  810. break;
  811. case SkillType.breakArmy:
  812. str = `You pocketed ${levelNum} extra balls`;
  813. break;
  814. case SkillType.ice:
  815. str = `${levelNum*2} extra balls were frozen`;
  816. break;
  817. case SkillType.fireworks:
  818. str = `${levelNum} extra balls exploded `;
  819. break;
  820. case SkillType.GuanYu:
  821. str = `There were ${xGame.common.extraMoveNum} displacement movements`;
  822. break;
  823. default:
  824. break;
  825. }
  826. //
  827. xGame.uiMgr.Show(UIMsg, str);
  828. }
  829. getFoulType() {
  830. //判断是否存在犯规
  831. //没碰到球
  832. let foulType = "";
  833. if (this.firstColliObj == null) {
  834. if (this.inHoleBalls.length == 1 && this.inHoleBalls[0] == 0) {
  835. //白球未碰任何球且直接进洞
  836. return FoulType.rootHole;
  837. }
  838. return FoulType.notTouch;
  839. }
  840. else {
  841. //
  842. if (this.selfTurn) {
  843. if (this.selfBallArr.length > 0) {
  844. if (this.selfBallArr.indexOf(this.firstColliObj) <= -1) {
  845. foulType = FoulType.wrongTouch;
  846. }
  847. }
  848. else {
  849. //
  850. if (this.ensureBallType) {
  851. //只剩下黑8了
  852. }
  853. else {
  854. //还未确定阵营
  855. if (this.firstColliObj == this.blackNum) {
  856. foulType = FoulType.wrongTouch;
  857. }
  858. }
  859. }
  860. }
  861. else {
  862. if (this.aiBallArr.length > 0) {
  863. if (this.aiBallArr.indexOf(this.firstColliObj) <= -1) {
  864. foulType = FoulType.wrongTouch;
  865. }
  866. }
  867. else {
  868. //
  869. if (this.ensureBallType) {
  870. //只剩下黑8了
  871. }
  872. else {
  873. //还未确定阵营
  874. if (this.firstColliObj == this.blackNum) {
  875. foulType = FoulType.wrongTouch;
  876. }
  877. }
  878. }
  879. }
  880. //
  881. if (this.inHoleBalls.length <= 0) {
  882. return foulType;
  883. }
  884. //进球了
  885. //是否白球入袋
  886. let temp;
  887. if (this.inHoleBalls.indexOf(0) > -1) {
  888. foulType = FoulType.rootHole;
  889. }
  890. else {
  891. //白球未入带
  892. for (let index = 0; index < this.inHoleBalls.length; index++) {
  893. temp = this.inHoleBalls[index];
  894. if (this.selfTurn) {
  895. if (this.aiBallArr.indexOf(temp) > -1 && !this.isOpenBall) {
  896. foulType = FoulType.wrongHole;
  897. break;
  898. }
  899. }
  900. else {
  901. if (this.selfBallArr.indexOf(temp) > -1 && !this.isOpenBall) {
  902. foulType = FoulType.wrongHole;
  903. break;
  904. }
  905. }
  906. }
  907. }
  908. //移除对应的球
  909. let foo;
  910. for (let index = 0; index < this.inHoleBalls.length; index++) {
  911. temp = this.inHoleBalls[index];
  912. foo = this.selfBallArr.indexOf(temp);
  913. if (foo > -1) {
  914. this.selfBallArr.splice(foo, 1);
  915. }
  916. //
  917. foo = this.aiBallArr.indexOf(temp);
  918. if (foo > -1) {
  919. this.aiBallArr.splice(foo, 1);
  920. }
  921. }
  922. //
  923. this.updateLeftBall();
  924. //
  925. }
  926. return foulType;
  927. }
  928. //判断是否是黑8进球导致的游戏失败
  929. judgeGameEndByBlack(arr: Array<any>) {
  930. if (this.selfTurn) {
  931. if (this.selfBallArr.length > 0 && arr.indexOf(this.blackNum) > -1) {
  932. this.selfFoulNum = this.maxFoulTimes;
  933. return true;
  934. }
  935. }
  936. else {
  937. if (this.aiBallArr.length > 0 && arr.indexOf(this.blackNum) > -1) {
  938. this.aiFoulNum = this.maxFoulTimes;
  939. return true;
  940. }
  941. }
  942. }
  943. //判断犯规情况
  944. judgeClassic(type) {
  945. this.isBlackInHole = this.judgeGameEndByBlack(this.inHoleBalls);
  946. //ai停止操作
  947. xGame.common.aiPlayer.stopRun();
  948. //判断游戏是否成功
  949. if (this.judgeNormalSuccess()) {
  950. //游戏结束
  951. this.isEnd = true;
  952. return;
  953. }
  954. ////判断是否犯规导致游戏结束
  955. let isFoul = (type == FoulType.timeOut || type == FoulType.rootHole);
  956. if (this.selfTurn) {
  957. if (isFoul) {
  958. this.selfFoulNum++;
  959. }
  960. if (this.selfFoulNum >= this.maxFoulTimes) {
  961. this.success = false;
  962. this.isEnd = true;
  963. return;
  964. }
  965. }
  966. else {
  967. if (isFoul) this.aiFoulNum++;
  968. if (this.aiFoulNum >= this.maxFoulTimes) {
  969. this.success = true;
  970. this.isEnd = true;
  971. return;
  972. }
  973. }
  974. if ((type == "" || type == FoulType.wrongTouch) && this.inHoleBalls.length > 0) {
  975. this.isChangeTurn = false;
  976. }
  977. else {
  978. this.isInterrupt = true;
  979. }
  980. }
  981. //初始化完成等待射击
  982. waitShoot() {
  983. if (xGame.common.gameMode == GameMode.classic) {
  984. switch (this.curFoul) {
  985. case FoulType.timeOut://超时,犯规+1
  986. case FoulType.rootHole://白球进了犯规+1
  987. this.selfTurn = !this.selfTurn;
  988. this.peoplePlay(5, 6, true);
  989. break;
  990. case FoulType.notTouch:
  991. this.selfTurn = !this.selfTurn;
  992. this.peoplePlay(7, 7);
  993. break;
  994. // case FoulType.wrongTouch:
  995. // break;
  996. case FoulType.wrongHole:
  997. this.selfTurn = !this.selfTurn;
  998. this.peoplePlay(11, 11);
  999. break;
  1000. default:
  1001. //没有犯规
  1002. if (this.inHoleBalls.length > 0) {
  1003. //进球
  1004. //不出现提示语直接继续流程
  1005. this.peoplePlay(0, 0, false, false);
  1006. }
  1007. else {
  1008. //未进球
  1009. this.selfTurn = !this.selfTurn;
  1010. this.peoplePlay(7, 7);
  1011. }
  1012. break;
  1013. }
  1014. }
  1015. else if (xGame.common.gameMode == GameMode.bigMove) {
  1016. if (this.curFoul == FoulType.timeOut) {
  1017. this.selfTurn = !this.selfTurn;
  1018. this.peoplePlay(14, 15);
  1019. this.placeRootBall();
  1020. }
  1021. else {
  1022. //未结束
  1023. this.selfTurn = !this.selfTurn;
  1024. if (this.curFoul == FoulType.rootHole) {
  1025. this.peoplePlay(12, 13);
  1026. this.placeRootBall();
  1027. }
  1028. else {
  1029. this.peoplePlay(0, 0, false, false);
  1030. }
  1031. }
  1032. }
  1033. else if (xGame.common.gameMode == GameMode.placeBall) {
  1034. this.finishOneShoot = true;
  1035. }
  1036. //
  1037. this.gameResult();
  1038. //
  1039. }
  1040. //处理一杆结束后的逻辑
  1041. gameResult() {
  1042. this.firstColliObj = null;
  1043. //进球设置为0
  1044. this.inHoleBalls = [];
  1045. //记录白球的位置
  1046. let curX = xGame.common.d2World.rootBall.gameObj.x
  1047. let curY = xGame.common.d2World.rootBall.gameObj.y
  1048. xGame.common.gameMgr.lastRootBallPos.setValue(curX, curY);
  1049. //高低杆重置
  1050. if (xGame.common.uiRodMethod) xGame.common.uiRodMethod.resetRod();
  1051. //显示母球
  1052. xGame.common.d2World.rootBall.showSelf();
  1053. //清除冰冻效果
  1054. this.clearIceSkill();
  1055. if (this.selfTurn) {
  1056. // console.log("zh:处理一杆结束后的逻辑 gameResult");
  1057. PlatMgr.gameInsert();
  1058. }
  1059. //
  1060. xGame.common.d3World.knifeRoot.destroyChildren();
  1061. //判断延长线引导
  1062. if (this.selfTurn) {
  1063. xGame.common.gameUI.showHelpLineGuide();
  1064. //显示杆和刻度尺
  1065. xGame.common.gameUI.setTurnAlpha(true);
  1066. }
  1067. else {
  1068. //隐藏刻度尺和杆等
  1069. xGame.common.gameUI.setTurnAlpha(false);
  1070. }
  1071. }
  1072. getScore(type) {
  1073. let selfAdd = 0;
  1074. let aiAdd = 0;
  1075. if (type == FoulType.timeOut) {
  1076. if (this.selfTurn) aiAdd += 3;
  1077. else selfAdd += 3;
  1078. //
  1079. }
  1080. else {
  1081. if (this.inHoleBalls.length > 0) {
  1082. if (this.selfTurn) {
  1083. if (type == FoulType.rootHole) {
  1084. aiAdd += 3;
  1085. if (this.inHoleBalls.length - 1 > 0) {
  1086. selfAdd += this.inHoleBalls.length - 1;
  1087. }
  1088. }
  1089. else {
  1090. selfAdd += this.inHoleBalls.length;
  1091. }
  1092. }
  1093. else {
  1094. if (type == FoulType.rootHole) {
  1095. selfAdd += 3;
  1096. if (this.inHoleBalls.length - 1 > 0) {
  1097. aiAdd += this.inHoleBalls.length - 1;
  1098. }
  1099. }
  1100. else {
  1101. aiAdd += this.inHoleBalls.length;
  1102. }
  1103. }
  1104. }
  1105. }
  1106. return [selfAdd, aiAdd];
  1107. }
  1108. judgeScoreEnd(selfAdd, aiAdd) {
  1109. this.selfScore += selfAdd;
  1110. this.aiScore += aiAdd;
  1111. this.updateAIScore();
  1112. this.updateSelfScore();
  1113. //判断是否结束
  1114. if (this.selfScore >= this.targertScore) {
  1115. this.success = true;
  1116. return true
  1117. }
  1118. if (this.aiScore >= this.targertScore) {
  1119. this.success = false;
  1120. return true
  1121. }
  1122. //如果场上只剩下白球了。
  1123. let ballArr = xGame.common.d2World.ballArr;
  1124. if (ballArr.length == 1 && ballArr[0].number == 0) {
  1125. if (this.selfScore > this.aiScore) {
  1126. this.success = true;
  1127. return true
  1128. }
  1129. else if (this.selfScore < this.aiScore) {
  1130. this.success = false;
  1131. return true
  1132. }
  1133. else {
  1134. //相等的话,先达到该分数的 算做胜利
  1135. if (this.selfTurn) {
  1136. this.success = false;
  1137. }
  1138. else {
  1139. this.success = true;
  1140. }
  1141. return true;
  1142. }
  1143. }
  1144. }
  1145. clearIceSkill() {
  1146. //自己布置的冰冻效果,轮到自己的时候会消失
  1147. let arr = xGame.common.d2World.ballArr;
  1148. let temp: D2BallSrc;
  1149. if (this.selfTurn) {
  1150. if (this.selfCurSkill == SkillType.ice) {
  1151. //将所有玩家的冰冻求变为正常
  1152. for (let index = 0; index < arr.length; index++) {
  1153. temp = arr[index];
  1154. if (temp.ballFunc == "ice") {
  1155. temp.setBallFunc("normal", "self");
  1156. }
  1157. }
  1158. }
  1159. }
  1160. else {
  1161. if (this.aiCurSkill == SkillType.ice) {
  1162. for (let index = 0; index < arr.length; index++) {
  1163. temp = arr[index];
  1164. //将所有ai的冰冻求变为正常
  1165. if (temp.ballFunc == "ice") {
  1166. temp.setBallFunc("normal", "ai");
  1167. }
  1168. }
  1169. }
  1170. }
  1171. }
  1172. judgeNormalSuccess() {
  1173. if (this.selfTurn) {
  1174. if (this.selfBallArr.length <= 0 && this.inHoleBalls.indexOf(this.blackNum) > -1) {
  1175. //玩家正常胜利
  1176. this.success = true;
  1177. return true;
  1178. }
  1179. }
  1180. else {
  1181. if (this.aiBallArr.length <= 0 && this.inHoleBalls.indexOf(this.blackNum) > -1) {
  1182. //对手ai正常胜利
  1183. this.success = false;
  1184. return true;
  1185. }
  1186. }
  1187. }
  1188. public isEnter: boolean = true;
  1189. gameEnd() {
  1190. if (Moyu.isTT) {
  1191. xGame.common.screenImg = getScreenImg();
  1192. }
  1193. console.log("游戏结束", this.success);
  1194. xGame.common.aiPlayer.stopRun();
  1195. if (xGame.common.gameMode == GameMode.placeBall) {
  1196. this.getEndStarNum();
  1197. this.updatePlaceBallState();
  1198. }
  1199. this.isEnter = false;
  1200. Moyu.recordEnd(this, () => {
  1201. //
  1202. if (this.isEnter) return;
  1203. this.isEnter = true;
  1204. console.log("进入录结束回调");
  1205. this.enterNext();
  1206. });
  1207. Laya.timer.once(1000, this, () => {
  1208. if (this.isEnter) return;
  1209. this.isEnter = true;
  1210. this.enterNext();
  1211. })
  1212. //
  1213. xGame.common.longHelpLine = false;
  1214. //
  1215. }
  1216. enterNext() {
  1217. Laya.timer.clearAll(this);
  1218. //
  1219. if (Moyu.canShare() > 100 || Moyu.isKs) {
  1220. xGame.uiMgr.Show(UIVideoShare, this.success);
  1221. }
  1222. else {
  1223. xGame.uiMgr.Show(UIGameEnd, this.success);
  1224. }
  1225. }
  1226. aiLeave() {
  1227. let ui = xGame.common.gameUI.ui;//离线
  1228. ui.topNode.aiNameTxt.text = "offline";
  1229. }
  1230. aiGameEnd(suc: boolean) {
  1231. this.success = suc;
  1232. xGame.common.aiPlayer.stopRun();
  1233. if (this.success) {
  1234. //对手已逃跑!
  1235. xGame.uiMgr.Show(UIMsg, "The opponent has fled");
  1236. Laya.timer.once(1000, this, () => {
  1237. this.clearTime();
  1238. this.gameEnd();
  1239. })
  1240. }
  1241. }
  1242. openTimer() {
  1243. let src = xGame.common.gameUI;
  1244. if (this.selfTurn) {
  1245. src.ui.topNode.selfProgress.visible = true;
  1246. src.ui.topNode.aiProgress.visible = false;
  1247. this.curTimer = src.ui.topNode.selfProgress;
  1248. }
  1249. else {
  1250. src.ui.topNode.selfProgress.visible = false;
  1251. src.ui.topNode.aiProgress.visible = true;
  1252. this.curTimer = src.ui.topNode.aiProgress;
  1253. }
  1254. this.accTime = 0;
  1255. Laya.timer.clearAll(this);
  1256. Laya.timer.loop(20, this, this.updateTime, [0.02]);
  1257. this.curTimer.value = 100;
  1258. }
  1259. updateTime(dt) {
  1260. if (this.gamePause) return;
  1261. this.accTime += dt;
  1262. this.curTimer.value = 100 * (this.setTime - this.accTime) / this.setTime;
  1263. if (this.accTime >= this.setTime) {
  1264. this.clearTime();
  1265. console.log("时钟进入了gameRun");
  1266. this.gameRun(FoulType.timeOut)
  1267. }
  1268. }
  1269. clearTime() {
  1270. let src = xGame.common.gameUI;
  1271. src.ui.topNode.selfProgress.visible = false;
  1272. src.ui.topNode.aiProgress.visible = false;
  1273. //清除计时时间
  1274. Laya.timer.clearAll(this);
  1275. }
  1276. peoplePlay(selfIndex, aiIndex, Foul = false, sayWords = true) {
  1277. let ui = xGame.common.gameUI.ui;
  1278. //foul判负犯规
  1279. let selfMsg, aiMsg;
  1280. if (sayWords) {
  1281. selfMsg = cfgTable.wordsData[selfIndex].msg;
  1282. aiMsg = cfgTable.wordsData[aiIndex].msg;
  1283. if (Foul) {
  1284. selfMsg = selfMsg.replace("$", this.aiFoulNum + "");
  1285. aiMsg = aiMsg.replace("$", this.selfFoulNum + "");
  1286. //摆放白球
  1287. this.placeRootBall();
  1288. if (!this.selfTurn && xGame.common.gameMode == GameMode.classic) {
  1289. if (this.curFoul == FoulType.rootHole) {
  1290. if (!DataMgr.getRootBallFoul()) {
  1291. DataMgr.setRootBallFoul();
  1292. //
  1293. aiMsg = "";
  1294. //白球进洞了,3次犯规本局游戏失败。
  1295. let tips = "The cue ball (white ball) has been pocketed. Three fouls have been committed—you lose this game"
  1296. //老板,下次注意啦~
  1297. let woman = "Boss, pay attention next time~"
  1298. xGame.uiMgr.Show(UITips, tips, woman, TipsType.foul);
  1299. }
  1300. }
  1301. else if (this.curFoul == FoulType.timeOut) {
  1302. if (!DataMgr.getTimeoutFoul()) {
  1303. DataMgr.setTimeoutFoul();
  1304. aiMsg = "";
  1305. //游戏超时,3次犯规本局游戏失败。
  1306. let tips = "Game timeout, 3 fouls, this game failed."
  1307. //老板,注意时间楼~
  1308. let woman = "Boss, pay attention to the timeline~"
  1309. xGame.uiMgr.Show(UITips, tips, woman, TipsType.foul);
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. if (this.selfTurn) {
  1316. //该玩家击球
  1317. if (sayWords) {
  1318. xGame.uiMgr.Show(UIMsg, selfMsg, () => {
  1319. ui.selfTurn.visible = true;
  1320. ui.aiTurn.visible = false;
  1321. ui.selfTurn.t0.play();
  1322. //
  1323. Moyu.vibration();
  1324. });
  1325. }
  1326. }
  1327. else {
  1328. //该对手ai击球
  1329. let aiNum = xGame.tools.random(1, 11);
  1330. let challengeNum = DataMgr.getChallengeTimes();
  1331. let delay = false;
  1332. if (xGame.common.gameMode == GameMode.classic && challengeNum >= 1 && challengeNum <= 3) {
  1333. aiNum = 9;
  1334. if (this.aiBallArr.length <= 2 && this.ensureBallType) {
  1335. aiNum = 3;
  1336. if (challengeNum == 3) {
  1337. if (!this.showLongView) {
  1338. this.showLongView = true;
  1339. delay = true;
  1340. }
  1341. }
  1342. }
  1343. }
  1344. if (delay) {
  1345. xGame.uiMgr.Show(UIRepentProp, 0, 0, (success) => {
  1346. if (success) {
  1347. //延长辅助线
  1348. xGame.common.longHelpLine = true;
  1349. xGame.common.d2World.getHelpLine();
  1350. }
  1351. else {
  1352. // 不做操作退出
  1353. aiNum = 10;
  1354. }
  1355. //
  1356. xGame.common.aiPlayer.setAiLevel(aiNum);
  1357. if (sayWords) {
  1358. xGame.uiMgr.Show(UIMsg, aiMsg, () => {
  1359. xGame.common.aiPlayer.runAI();
  1360. //
  1361. ui.selfTurn.visible = false;
  1362. ui.aiTurn.visible = true;
  1363. ui.aiTurn.t0.play();
  1364. //
  1365. });
  1366. }
  1367. else {
  1368. xGame.common.aiPlayer.runAI();
  1369. }
  1370. this.openTimer();
  1371. this.finishOneShoot = true;
  1372. //
  1373. if (this.selfTurn) {
  1374. ui.topNode.selfKuang.visible = true;
  1375. ui.topNode.aiKuang.visible = false;
  1376. ui.topNode.selfTips.visible = true;
  1377. ui.topNode.aiTips.visible = false;
  1378. }
  1379. else {
  1380. ui.topNode.selfKuang.visible = false;
  1381. ui.topNode.aiKuang.visible = true;
  1382. ui.topNode.selfTips.visible = false;
  1383. ui.topNode.aiTips.visible = true;
  1384. }
  1385. //
  1386. })
  1387. return;
  1388. }
  1389. if (xGame.common.gameMode == GameMode.classic) {
  1390. let cfg = cfgTable.modeselectData[xGame.common.classicRoomType];
  1391. if (cfg) {
  1392. let aiLevel = xGame.common.randomNum(cfg.aiLevel[0], cfg.aiLevel[1]);
  1393. aiNum = aiLevel;
  1394. }
  1395. }
  1396. xGame.common.aiPlayer.setAiLevel(aiNum);
  1397. //
  1398. if (sayWords) {
  1399. xGame.uiMgr.Show(UIMsg, aiMsg, () => {
  1400. xGame.common.aiPlayer.runAI();
  1401. //
  1402. ui.selfTurn.visible = false;
  1403. ui.aiTurn.visible = true;
  1404. ui.aiTurn.t0.play();
  1405. //
  1406. });
  1407. }
  1408. else {
  1409. xGame.common.aiPlayer.runAI();
  1410. }
  1411. }
  1412. this.openTimer();
  1413. this.finishOneShoot = true;
  1414. //
  1415. if (this.selfTurn) {
  1416. ui.topNode.selfKuang.visible = true;
  1417. ui.topNode.aiKuang.visible = false;
  1418. ui.topNode.selfTips.visible = true;
  1419. ui.topNode.aiTips.visible = false;
  1420. }
  1421. else {
  1422. ui.topNode.selfKuang.visible = false;
  1423. ui.topNode.aiKuang.visible = true;
  1424. ui.topNode.selfTips.visible = false;
  1425. ui.topNode.aiTips.visible = true;
  1426. }
  1427. }
  1428. //放置白球位置
  1429. placeRootBall() {
  1430. //移动至上一次白球的位置
  1431. let rootBall = xGame.common.d2World.rootBall;
  1432. if (!rootBall) return;
  1433. rootBall.gameObj.x = this.lastRootBallPos.x;
  1434. rootBall.gameObj.y = this.lastRootBallPos.y;
  1435. rootBall.d3BallSrc.setTransPos(this.lastRootBallPos.x, this.lastRootBallPos.y);
  1436. //
  1437. let moveNode = xGame.common.gameUI.ui.moveNode;
  1438. moveNode.visible = true;
  1439. moveNode.x = this.lastRootBallPos.x;
  1440. moveNode.y = this.lastRootBallPos.y;
  1441. //ai犯规玩家才能移动白球
  1442. if (!this.selfTurn) {
  1443. xGame.common.aiPlayer.resetRoot();
  1444. }
  1445. }
  1446. }