123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461 |
- import D2BallSrc from "../d2Obj/D2BallSrc";
- import DataMgr from "../data/DataMgr";
- import { ALL_BALL_STOP, ballCamp, BALL_SHOOT, ClassicWordsType, FIRST_BALL_HOLE, FoulType, GameMode, PlaceBallType, RESET_GAME, SkillType, TipsType, WAIT_SHOOT } from "../data/Define";
- import UIGameEnd from "../ui/UIGameEnd";
- import UIRepentProp from "../ui/UIRepentProp";
- import UIMsg from "../ui/UIMsg";
- import UIVideoShare from "../ui/UIVideoShare";
- import { getScreenImg } from "../utils/Utils";
- import { xGame } from "../xGame";
- import PlatMgr from "./PlatMgr";
- import UITips from "../ui/UITips";
- //游戏数据相关的值
- export default class GameMgr {
- selfCamp = "";
- selfFoulNum = 0;//玩家犯规次数
- selfBallArr = [];//除了黑8以外的球
- selfTimer: number = 0;
- selfScore: number = 0;
- selfCurSkill: SkillType;
- //
- aiCamp = "";
- aiFoulNum = 0;//ai犯规次数
- aiBallArr = [];//除了黑8以外的球
- aiTimer: number = 0;
- aiScore: number = 0;
- aiCurSkill: SkillType;
- /**ai选中的技能的等级 */
- aiSkillLevelNum: number = 1;
- //目前分数
- targertScore: number = 0;
- //计时器
- setTime = 30;
- //开局轮到自己的概率
- selfTurnRate = 0.5;
- accTime = 0;
- curTimer: fgui.GProgressBar;
- //犯规类型
- curFoul = "";
- //最大犯规次数
- maxFoulTimes = 3;
- //是否是一句游戏中的第一杆
- isFirstInGame: boolean = true;
- //首次碰撞到的球
- firstColliObj: any = null;
- //打进洞的所有球
- inHoleBalls = [];
- //黑8
- blackNum: number = 8;
- //
- success: boolean = false;
- //袋口位置
- holePosList = [];
- posObj = {};
- //
- public _selfTurn: boolean = false;//是否轮到自己
- //上一次白球位置
- lastRootBallPos = new Laya.Vector2(311, 430);
- //是否已经确定了双方的阵营了
- public ensureBallType: boolean = false;
- //是否是开球时刻,第一次进球之后开球就变为false
- public isOpenBall: boolean = true;
- public finishOneShoot: boolean = true;
- //
- public isEnd = false;//游戏是否结束
- public isChangeTurn = false;//是否交换球权
- public isInterrupt = false;//连击是否被打断了
- //
- //public isSelfOutSkills: boolean = false;
- public aiPlayedBreakArmy: boolean = false;
- //
- public isTouchedBall: boolean = false;
- //摆球达人模式
- //已完成的进球数
- public finishBalls: number = 0;
- //需要进球的总数目
- public needBalls: number = 0;
- //场上除了白球的所有球数目
- public allBallNum: number = 0;
- //上一次操作的所有球位置信息
- public placeBallPosData = {};
- //当前血量
- public curHP: number = 0;
- //摆球达人数据
- public placeBallData: cfgTable.placeball;
- //
- public showLongView: boolean = false;
- //首次shoot
- firstShoot = true;
- //
- //游戏是否暂停
- _gamePause: boolean = false;
- /**
- * 换边次数
- */
- trunCount: number = 0;
- public get gamePause(): boolean {
- return this._gamePause;
- }
- public set gamePause(v: boolean) {
- if (v) {
- //游戏暂定
- Laya.physicsTimer.pause();
- }
- else {
- //游戏恢复
- Laya.physicsTimer.resume();
- }
- this._gamePause = v;
- }
- //
- public get selfTurn(): boolean {
- return this._selfTurn;
- }
- public set selfTurn(val) {
- this.trunCount++;
- this._selfTurn = val;
- if (val) {
- xGame.common.d2World.d2Gan.ui.self.visible = true;
- xGame.common.d2World.d2Gan.ui.ai.visible = false;
- }
- else {
- xGame.common.d2World.d2Gan.ui.self.visible = false;
- xGame.common.d2World.d2Gan.ui.ai.visible = true;
- if (this.trunCount > 1)
- PlatMgr.openBox();
- }
- }
- //是否有人打进了黑8
- public isBlackInHole: boolean = false;
- //
- constructor() {
- xGame.eventMgr.offAll(ALL_BALL_STOP)
- xGame.eventMgr.on(ALL_BALL_STOP, this, this.gameRun);
- //
- xGame.eventMgr.off(BALL_SHOOT, this, this.ballShoot);
- xGame.eventMgr.on(BALL_SHOOT, this, this.ballShoot);
- //
- xGame.eventMgr.off(FIRST_BALL_HOLE, this, this.ensureCamp);
- xGame.eventMgr.on(FIRST_BALL_HOLE, this, this.ensureCamp);
- //
- xGame.eventMgr.off(RESET_GAME, this, this.resetGame);
- xGame.eventMgr.on(RESET_GAME, this, this.resetGame);
- }
- resetGame() {
- this.inHoleBalls = [];
- this.isFirstInGame = true;
- this.firstColliObj = null;
- this.aiCamp = "";
- this.selfCamp = "";
- this.aiFoulNum = 0;
- this.selfFoulNum = 0;
- this.selfBallArr = [];
- this.aiBallArr = [];
- this.gamePause = false;
- this.ensureBallType = false;
- this.isInterrupt = false;
- this.updateLeftBall();
- this.clearTime();
- //
- // this.isSelfOutSkills = false;
- this.aiPlayedBreakArmy = false;
- //
- this.isBlackInHole = false;
- this.placeBallPosData = {};
- //
- if (xGame.common.d3World.knifeRoot) {
- xGame.common.d3World.knifeRoot.destroyChildren();
- }
- }
- //游戏准备ok
- gameReady() {
- //开球顺序
- this.trunCount = 0;
- this.firstColliObj = null;
- this.isFirstInGame = true;
- this.selfTurn = Math.random() <= this.selfTurnRate;
- let challengeNum = DataMgr.getChallengeTimes();
- if (xGame.common.gameMode == GameMode.classic && challengeNum >= 1 && challengeNum <= 3) {
- this.selfTurn = true;
- }
- if (xGame.common.gameMode == GameMode.placeBall) this.selfTurn = true;
- if (xGame.common.gameMode == GameMode.bigMove && !DataMgr.getSkillGuide()) {
- this.selfTurn = true;
- }
- xGame.common.gameUI.setTurnAlpha(this.selfTurn);
- this.checkGuide();
- //高低杆重置
- if (xGame.common.uiRodMethod) xGame.common.uiRodMethod.resetRod();
- //辅助线
- xGame.common.d2World.getHelpLine();
- //开局可以摆球
- this.isOpenBall = true;
- this.isTouchedBall = false;
- //
- xGame.common.aiPlayer.stopRun();
- this.setTime = 30;
- let ui = xGame.common.gameUI.ui;
- switch (xGame.common.gameMode) {
- case GameMode.classic:
- //AI初始化
- xGame.common.aiPlayer.init();
- this.blackNum = 8;
- this.placeRootBall();
- this.peoplePlay(9, 10);
- ui.wordsBtn.visible = true;
- ui.aiWordsBtn.visible = true;
- xGame.common.talkMgr.changeAIState(true);
- DataMgr.gameData.gameCount++;
- DataMgr.saveGameData();
- break;
- case GameMode.bigMove:
- this.blackNum = -1;
- this.selfScore = 0;
- this.aiScore = 0;
- //AI初始化
- xGame.common.aiPlayer.init();
- //
- this.targertScore = cfgTable.bigmoveData[xGame.common.bigMoveLevelIndex].target;
- //
- this.updateSelfScore();
- this.updateAIScore();
- this.updateTargetSroce();
- this.placeRootBall();
- this.peoplePlay(9, 10);
- ui.wordsBtn.visible = true;
- ui.aiWordsBtn.visible = true;
- xGame.common.talkMgr.changeAIState(true);
- if (DataMgr.getSkillGuide() < 1)
- DataMgr.gameData.gameCount = 0;
- else {
- DataMgr.gameData.gameCount++;
- DataMgr.saveGameData();
- PlatMgr.openTry();
- }
- //
- if (xGame.common.d3World.knifeRoot) {
- xGame.common.d3World.knifeRoot.destroyChildren();
- }
- //
- break;
- case GameMode.placeBall:
- this.blackNum = -1;
- this.selfTurn = true;
- this.setTime = 10000;
- this.placeBallData = cfgTable.placeballData[xGame.common.placeBallCurLevel];
- this.curHP = this.placeBallData.hp;
- //
- if (this.placeBallData.ball == -1) this.needBalls = xGame.common.d2World.ballArr.length - 1;
- else this.needBalls = this.placeBallData.ball;
- console.log("需要的进球数目", this.needBalls);
- this.allBallNum = xGame.common.d2World.ballArr.length - 1;
- //
- this.finishBalls = 0;
- this.placeBallPosData = {};
- this.updatePlaceBallPos();
- this.updatePlaceBallState();
- this.finishOneShoot = true;
- xGame.common.gameUI.ui.moveNode.visible = false;
- this.isOpenBall = false;
- xGame.common.d2World.d2Gan.ui.ai.visible = false;
- ui.wordsBtn.visible = false;
- ui.aiWordsBtn.visible = false;
- xGame.common.talkMgr.changeAIState(false);
- Laya.timer.frameOnce(xGame.tools.random(2000, 5100), this, () => {
- PlatMgr.openBox();
- })
- break;
- default:
- break;
- }
- //
- this.showLongView = false;
- xGame.common.wordsMgr.comboTimes = 1;
- let guide = DataMgr.getSkillGuide();
- if (guide) xGame.eventMgr.event(WAIT_SHOOT);
- //
- xGame.common.upSkillLevel = false;
- xGame.common.gameStartTime = new Date().getTime();
- //
- this.firstShoot = true;
- }
- checkGuide() {
- let guide = DataMgr.getSkillGuide();
- let gameUI = xGame.common.gameUI.ui;
- gameUI.guide1.visible = false;
- gameUI.guide2.visible = false;
- gameUI.guide3.visible = false;
- if (guide == 0 && xGame.common.gameMode == GameMode.bigMove) {
- this.selfTurn = true;
- }
- else {
- return;
- }
- //////
- let oneBall = this.getOneBall();
- gameUI.guide1.visible = true;
- gameUI.guide1.fingerNode.x = oneBall.gameObj.x;
- gameUI.guide1.fingerNode.y = oneBall.gameObj.y;
- }
- getOneBall() {
- let arr = xGame.common.d2World.ballArr;
- for (let index = 0; index < arr.length; index++) {
- if (arr[index].number == 0) continue;
- return arr[index];
- }
- }
- updateSelfScore() {
- let ui = xGame.common.gameUI.ui.topNode;
- ui.selfScoreTxt.text = this.selfScore + "";
- }
- updateAIScore() {
- let ui = xGame.common.gameUI.ui.topNode;
- ui.aiScoreTxt.text = this.aiScore + "";
- }
- updateTargetSroce() {
- let ui = xGame.common.gameUI.ui.topNode;
- ui.middleNode.targetScoreTxt.text = this.targertScore + "";
- }
- updateLeftBall() {
- let topUI = xGame.common.gameUI.ui.topNode;
- //设置自己的球
- topUI.selfBallList.numItems = this.selfBallArr.length;
- topUI.aiBallList.numItems = this.aiBallArr.length;
- }
- //母球发射
- ballShoot() {
- this.clearTime();
- //
- this.finishOneShoot = false;
- xGame.common.gameUI.ui.moveNode.visible = false;
- //xGame.common.longHelpLine = false;
- if (xGame.common.gameUI.ui.guideNode.visible) {
- xGame.common.gameUI.ui.guideNode.visible = false;
- }
- //
- if (this.firstShoot) {
- this.firstShoot = false;
- Moyu.sendDataEvent(`gameType${xGame.common.gameMode}`);
- }
- }
- //确定阵营
- ensureCamp(number) {
- this.ensureBallType = true;
- this.isOpenBall = false;
- if (xGame.common.gameMode != GameMode.classic) return;
- let full = [1, 2, 3, 4, 5, 6, 7];
- let flower = [9, 10, 11, 12, 13, 14, 15];
- let sayWords = "";
- if (this.selfTurn) {
- if (number <= 7) {
- this.selfCamp = ballCamp.full;
- this.selfBallArr = full;
- //
- this.aiCamp = ballCamp.flower;
- this.aiBallArr = flower
- //玩家为全色球
- sayWords = cfgTable.wordsData[3].msg;
- }
- else {
- this.selfCamp = ballCamp.flower;
- this.selfBallArr = flower;
- //
- this.aiCamp = ballCamp.full;
- this.aiBallArr = full;
- //玩家为花色球
- sayWords = cfgTable.wordsData[4].msg;
- }
- }
- else {
- if (number <= 7) {
- this.selfCamp = ballCamp.flower;
- this.selfBallArr = flower;
- //
- this.aiCamp = ballCamp.full;
- this.aiBallArr = full;
- //玩家为花色球
- sayWords = cfgTable.wordsData[2].msg;
- }
- else {
- this.selfCamp = ballCamp.full;
- this.selfBallArr = full;
- //
- this.aiCamp = ballCamp.flower;
- this.aiBallArr = flower
- //玩家为全色球
- sayWords = cfgTable.wordsData[1].msg;
- }
- }
- this.updateLeftBall();
- //
- xGame.uiMgr.Show(UIMsg, sayWords);
- }
- updatePlaceBallState() {
- let ui = xGame.common.gameUI.ui;
- switch (this.placeBallData.type) {
- case PlaceBallType.normal:
- let normal = ui.placeNormalNode;
- normal.hpTxt.text = this.curHP + "";
- this.updatePlaceBallStar(normal);
- normal.ballTxt.text = this.finishBalls + "/" + this.needBalls;
- normal.levelTxt.text = `Level ${xGame.common.placeBallCurLevel}`;
- break;
- case PlaceBallType.challenge:
- let challenge = ui.placeChallengeNode;
- challenge.hpTxt.text = "Shots:" + this.curHP;//杆数
- challenge.ballTxt.text = this.finishBalls + "/" + this.allBallNum;
- challenge.levelTxt.text = `Level ${xGame.common.placeBallCurLevel}`;
- challenge.tipsTxt.text = `Pocket ${this.needBalls} balls `;//打进颗球
- break;
- default:
- break;
- }
- }
- playSubHpAni() {
- let ui = xGame.common.gameUI.ui;
- switch (this.placeBallData.type) {
- case PlaceBallType.normal:
- let normal = ui.placeNormalNode;
- normal.hpTxt.visible = false;
- normal.starAni.c1.selectedIndex = 1;
- normal.starAni.t0.play(Laya.Handler.create(this, () => {
- normal.hpTxt.visible = true;
- normal.starAni.c1.selectedIndex = 0;
- }))
- break;
- default:
- break;
- }
- }
- getEndStarNum() {
- let num;
- let level = xGame.common.placeBallCurLevel;
- if (this.curHP == this.placeBallData.hp) {
- num = 3;
- }
- else if (this.curHP <= 1) {
- num = 1;
- }
- else {
- num = 2;
- }
- if (!this.success) {
- num = 0;
- }
- else {
- DataMgr.setPlaceBallLevel(level, num);
- }
- //
- let myType = cfgTable.placeballData[level].type;
- if (this.success && myType == 1) {
- num = 3;
- }
- xGame.common.placeBallStarNum = num;
- }
- //更新摆球达人清台模式通关星星等级
- updatePlaceBallStar(node) {
- let star = 0
- if (this.curHP == this.placeBallData.hp) {
- star = 3
- }
- else if (this.curHP >= 2) {
- star = 2;
- }
- else if (this.curHP == 1) {
- star = 1;
- }
- else {
- star = 0;
- }
- let temp;
- for (let index = 1; index <= 3; index++) {
- temp = node["star" + index];
- temp.c1.selectedIndex = star >= index ? 1 : 0;
- }
- node.myProgress.value = (star / 3) * 100;
- }
- openRegretView(isFoul, GoalNum, challenge = false) {
- let regretType = -1;
- if (isFoul) {
- //白球进洞
- regretType = 1;
- }
- else {
- //未进球
- if (GoalNum <= 0) {
- regretType = 0;
- }
- }
- //挑战模式白球进洞,
- if (challenge) {
- regretType = 1;
- }
- //
- if (regretType != -1) {
- xGame.uiMgr.Show(UIRepentProp, 1, regretType, (success) => {
- if (success) {
- //成功悔球
- this.curHP++;
- this.updatePlaceBallState();
- this.setPlaceBallAllPos();
- xGame.common.gameUI.ui.moveNode.visible = false;
- }
- else {
- //未进行悔球,弹出失败结算界面
- if (this.curHP <= 0) {
- this.success = false;
- this.gameEnd();
- }
- this.playSubHpAni();
- }
- this.updatePlaceBallState();
- this.updatePlaceBallPos();
- });
- }
- }
- setPlaceBallAllPos() {
- let allBall = xGame.common.d2World.ballArr;
- let cfgArr = this.placeBallPosData;
- let temp: D2BallSrc;
- let obj;
- for (let index = 0; index < allBall.length; index++) {
- temp = allBall[index];
- if (temp.destroyed) continue;
- obj = cfgArr[temp.myUNID];
- if (obj && obj.src && !obj.src.destroyed) {
- temp.gameObj.x = obj.posX;
- temp.gameObj.y = obj.posY;
- temp.d3BallSrc.setTransPos(obj.posX, obj.posY);
- }
- }
- xGame.common.d2World.getHelpLine();
- }
- updatePlaceBallPos() {
- let arr = xGame.common.d2World.ballArr;
- let temp: D2BallSrc;
- for (let index = 0; index < arr.length; index++) {
- temp = arr[index];
- if (!this.placeBallPosData[temp.myUNID]) {
- this.placeBallPosData[temp.myUNID] = {
- src: temp,
- posX: temp.gameObj.x,
- posY: temp.gameObj.y
- };
- }
- else {
- this.placeBallPosData[temp.myUNID].posX = temp.gameObj.x;
- this.placeBallPosData[temp.myUNID].posY = temp.gameObj.y;
- }
- }
- //
- let check;
- for (const key in this.placeBallPosData) {
- check = this.placeBallPosData[key];
- if (check.src.destroyed) {
- delete this.placeBallPosData[key]
- }
- }
- }
- //所有球静止,进行下一次打球判断
- gameRun(type) {
- //
- if (this.gamePause) return;
- this.curFoul = this.getFoulType();
- if (type) {
- xGame.common.d2World.d2Gan.shoot();
- xGame.common.gameUI.forceCancel();
- this.curFoul = type;
- }
- //
- this.isEnd = false;
- this.isChangeTurn = true;
- //
- if (xGame.common.gameMode == GameMode.classic) {
- this.judgeClassic(this.curFoul);
- this.checkClassicWords(() => {
- xGame.common.destroyClassicEmotion();
- if (this.isEnd) {
- if (this.isBlackInHole) {
- //黑8进洞
- xGame.common.gameUI.ui.blackAni.visible = true;
- xGame.common.gameUI.ui.blackAni.t0.play(Laya.Handler.create(this, () => {
- xGame.common.gameUI.ui.blackAni.visible = false;
- this.gameEnd();
- }))
- }
- else {
- this.gameEnd();
- }
- }
- else {
- this.waitShoot();
- xGame.eventMgr.event(WAIT_SHOOT);
- }
- });
- }
- else if (xGame.common.gameMode == GameMode.bigMove) {
- xGame.common.aiPlayer.stopRun();
- let scoreArr = this.getScore(this.curFoul);
- if (this.judgeScoreEnd(scoreArr[0], scoreArr[1])) {
- this.isEnd = true;
- }
- this.checkBigSkillWords(() => {
- if (this.isEnd) {
- this.gameEnd();
- }
- else {
- this.waitShoot();
- xGame.eventMgr.event(WAIT_SHOOT);
- }
- })
- }
- else if (xGame.common.gameMode == GameMode.placeBall) {
- //
- xGame.common.destroyAwardSpine();
- //
- //是否犯规
- let isFoul = this.curFoul == FoulType.rootHole;
- //是否进球(白球进不算)
- let GoalNum = this.inHoleBalls.length;
- if (this.inHoleBalls.indexOf(0) > -1) GoalNum -= 1;
- //
- if (isFoul) {
- this.placeRootBall();
- }
- console.log("neeballs", this.needBalls);
- console.log("当前完成的goalNum", GoalNum);
- this.finishBalls += GoalNum;
- console.log("当前完成的finishballs", this.finishBalls);
- let need = this.needBalls;
- if (this.placeBallData.type == PlaceBallType.challenge) {
- need += 100;
- }
- if (this.finishBalls >= need) {
- //游戏成功
- this.success = true;
- this.gameEnd();
- }
- else {
- switch (this.placeBallData.type) {
- case PlaceBallType.normal:
- if (!isFoul && GoalNum > 0) {
- //未犯规且进球了,不扣除hp
- this.updatePlaceBallPos();
- this.updatePlaceBallState();
- }
- else {
- this.curHP--;
- this.openRegretView(isFoul, GoalNum);
- }
- this.waitShoot();
- xGame.eventMgr.event(WAIT_SHOOT);
- break;
- case PlaceBallType.challenge:
- this.curHP--;
- this.updatePlaceBallState();
- if (isFoul) {
- this.openRegretView(isFoul, GoalNum, true);
- }
- else {
- this.updatePlaceBallPos();
- if (this.curHP <= 0) {
- this.success = true;
- this.gameEnd();
- }
- }
- this.waitShoot();
- xGame.eventMgr.event(WAIT_SHOOT);
- break;
- default:
- break;
- }
- }
- }
- }
- //经典版本的spine话语
- checkClassicWords(callback) {
- //未犯规和第一次错误的touch 都不算犯规
- xGame.common.wordsMgr.setClassicCombo(this.isChangeTurn);
- let condition = !this.isChangeTurn && (this.curFoul == "" || this.curFoul == FoulType.wrongTouch);
- let type = this.getClassicWordsType();
- if (condition && type != -1) {
- let str = Math.random() <= 0.5 ? "hint01" : "hint02";
- xGame.soundMgr.playSound(str);
- xGame.common.wordsMgr.playClassicWords(type, callback);
- }
- else {
- //违规了,不播放spine
- //没有出现5种进球的话语
- Laya.timer.once(300, this, () => {
- callback && callback();
- })
- }
- }
- getClassicWordsType() {
- let d2world = xGame.common.d2World;
- let type = -1;
- if (!this.isInterrupt && this.judgeNormalSuccess()) {
- //未交换过球权且全部打进
- type = ClassicWordsType.perfectShow;
- return type;
- }
- if (this.inHoleBalls.length == 1 && d2world.targetBall && this.inHoleBalls[0] == d2world.targetBall.number && d2world.isOnSameLine) {
- //空心入袋
- type = ClassicWordsType.directShoot;
- return type;
- }
- if (this.inHoleBalls.length > 0 && (d2world.targetBall == null || this.inHoleBalls.indexOf(d2world.targetBall.number) <= -1)) {
- //借力使力
- type = ClassicWordsType.anotherShoot;
- return type;
- }
- if (d2world.powerPercent == 100 && this.inHoleBalls.length > 0) {
- //大力出奇迹
- type = ClassicWordsType.bigPower;
- return type;
- }
- //只进一个球,且最后进洞速度小于一个值
- let minSpeed = 1;
- if (this.inHoleBalls.length == 1 && xGame.common.d2World.inHolesSpeed[0] <= minSpeed) {
- type = ClassicWordsType.hardShoot;
- return type;
- }
- if (this.inHoleBalls.length > 0) {
- type = ClassicWordsType.directShoot;
- return type;
- }
- return type;
- }
- //大招版本的spine的话语
- checkBigSkillWords(callback) {
- if (this.curFoul == FoulType.timeOut) {
- callback && callback();
- }
- else {
- let playSkill = false;
- if (this.selfTurn) {
- // if (!this.isSelfOutSkills) {
- // this.isSelfOutSkills = true;
- // playSkill = true;
- // }
- playSkill = true;
- }
- else {
- if (!this.aiPlayedBreakArmy) {
- this.aiPlayedBreakArmy = true;
- playSkill = true;
- }
- if (this.aiCurSkill != SkillType.breakArmy) {
- playSkill = true;
- }
- }
- if (xGame.common.skillMgr.playedLastSkill) {
- xGame.common.skillMgr.playedLastSkill = false;
- playSkill = false;
- }
- //
- ///////////////////
- if (playSkill) {
- //判断大招破军
- xGame.common.skillMgr.runBigSkill((extraScore) => {
- //播放大招技能后增加的额外分数
- let selfExtra = 0;
- let aiExtra = 0;
- if (this.selfTurn) selfExtra += extraScore;
- else aiExtra += extraScore;
- if (this.judgeScoreEnd(selfExtra, aiExtra)) {
- this.isEnd = true;
- }
- this.playBigSkillTimes(callback);
- });
- }
- else {
- this.playBigSkillTimes(callback);
- }
- }
- }
- playBigSkillTimes(callback) {
- //播放spine
- let length = this.inHoleBalls.length;
- if (this.inHoleBalls.indexOf(0) > -1) {
- length = this.inHoleBalls.length - 1;
- }
- if (length <= 0) {
- callback && callback();
- return;
- }
- xGame.common.wordsMgr.playBigSkillTimes(length, () => {
- callback && callback();
- })
- }
- playSkillTips() {
- let levelNum = 0;
- let curType;
- if (this.selfTurn) {
- levelNum = DataMgr.getBigSkillByIndex(this.selfCurSkill);
- curType = this.selfCurSkill;
- if (curType == DataMgr.gameData.trySkill && Laya.timer.currTimer < DataMgr.gameData.tryTime) {
- levelNum += 5;
- }
- }
- else {
- levelNum = this.aiSkillLevelNum;
- curType = this.aiCurSkill;
- }
- //
- let str = ``;
- switch (curType) {
- case SkillType.highSpace:
- str = `An extra ${xGame.common.extraMoveNum} balls were moved`;
- break;
- case SkillType.breakArmy:
- str = `You pocketed ${levelNum} extra balls`;
- break;
- case SkillType.ice:
- str = `${levelNum*2} extra balls were frozen`;
- break;
- case SkillType.fireworks:
- str = `${levelNum} extra balls exploded `;
- break;
- case SkillType.GuanYu:
- str = `There were ${xGame.common.extraMoveNum} displacement movements`;
- break;
- default:
- break;
- }
- //
- xGame.uiMgr.Show(UIMsg, str);
- }
- getFoulType() {
- //判断是否存在犯规
- //没碰到球
- let foulType = "";
- if (this.firstColliObj == null) {
- if (this.inHoleBalls.length == 1 && this.inHoleBalls[0] == 0) {
- //白球未碰任何球且直接进洞
- return FoulType.rootHole;
- }
- return FoulType.notTouch;
- }
- else {
- //
- if (this.selfTurn) {
- if (this.selfBallArr.length > 0) {
- if (this.selfBallArr.indexOf(this.firstColliObj) <= -1) {
- foulType = FoulType.wrongTouch;
- }
- }
- else {
- //
- if (this.ensureBallType) {
- //只剩下黑8了
- }
- else {
- //还未确定阵营
- if (this.firstColliObj == this.blackNum) {
- foulType = FoulType.wrongTouch;
- }
- }
- }
- }
- else {
- if (this.aiBallArr.length > 0) {
- if (this.aiBallArr.indexOf(this.firstColliObj) <= -1) {
- foulType = FoulType.wrongTouch;
- }
- }
- else {
- //
- if (this.ensureBallType) {
- //只剩下黑8了
- }
- else {
- //还未确定阵营
- if (this.firstColliObj == this.blackNum) {
- foulType = FoulType.wrongTouch;
- }
- }
- }
- }
- //
- if (this.inHoleBalls.length <= 0) {
- return foulType;
- }
- //进球了
- //是否白球入袋
- let temp;
- if (this.inHoleBalls.indexOf(0) > -1) {
- foulType = FoulType.rootHole;
- }
- else {
- //白球未入带
- for (let index = 0; index < this.inHoleBalls.length; index++) {
- temp = this.inHoleBalls[index];
- if (this.selfTurn) {
- if (this.aiBallArr.indexOf(temp) > -1 && !this.isOpenBall) {
- foulType = FoulType.wrongHole;
- break;
- }
- }
- else {
- if (this.selfBallArr.indexOf(temp) > -1 && !this.isOpenBall) {
- foulType = FoulType.wrongHole;
- break;
- }
- }
- }
- }
- //移除对应的球
- let foo;
- for (let index = 0; index < this.inHoleBalls.length; index++) {
- temp = this.inHoleBalls[index];
- foo = this.selfBallArr.indexOf(temp);
- if (foo > -1) {
- this.selfBallArr.splice(foo, 1);
- }
- //
- foo = this.aiBallArr.indexOf(temp);
- if (foo > -1) {
- this.aiBallArr.splice(foo, 1);
- }
- }
- //
- this.updateLeftBall();
- //
- }
- return foulType;
- }
- //判断是否是黑8进球导致的游戏失败
- judgeGameEndByBlack(arr: Array<any>) {
- if (this.selfTurn) {
- if (this.selfBallArr.length > 0 && arr.indexOf(this.blackNum) > -1) {
- this.selfFoulNum = this.maxFoulTimes;
- return true;
- }
- }
- else {
- if (this.aiBallArr.length > 0 && arr.indexOf(this.blackNum) > -1) {
- this.aiFoulNum = this.maxFoulTimes;
- return true;
- }
- }
- }
- //判断犯规情况
- judgeClassic(type) {
- this.isBlackInHole = this.judgeGameEndByBlack(this.inHoleBalls);
- //ai停止操作
- xGame.common.aiPlayer.stopRun();
- //判断游戏是否成功
- if (this.judgeNormalSuccess()) {
- //游戏结束
- this.isEnd = true;
- return;
- }
- ////判断是否犯规导致游戏结束
- let isFoul = (type == FoulType.timeOut || type == FoulType.rootHole);
- if (this.selfTurn) {
- if (isFoul) {
- this.selfFoulNum++;
- }
- if (this.selfFoulNum >= this.maxFoulTimes) {
- this.success = false;
- this.isEnd = true;
- return;
- }
- }
- else {
- if (isFoul) this.aiFoulNum++;
- if (this.aiFoulNum >= this.maxFoulTimes) {
- this.success = true;
- this.isEnd = true;
- return;
- }
- }
- if ((type == "" || type == FoulType.wrongTouch) && this.inHoleBalls.length > 0) {
- this.isChangeTurn = false;
- }
- else {
- this.isInterrupt = true;
- }
- }
- //初始化完成等待射击
- waitShoot() {
- if (xGame.common.gameMode == GameMode.classic) {
- switch (this.curFoul) {
- case FoulType.timeOut://超时,犯规+1
- case FoulType.rootHole://白球进了犯规+1
- this.selfTurn = !this.selfTurn;
- this.peoplePlay(5, 6, true);
- break;
- case FoulType.notTouch:
- this.selfTurn = !this.selfTurn;
- this.peoplePlay(7, 7);
- break;
- // case FoulType.wrongTouch:
- // break;
- case FoulType.wrongHole:
- this.selfTurn = !this.selfTurn;
- this.peoplePlay(11, 11);
- break;
- default:
- //没有犯规
- if (this.inHoleBalls.length > 0) {
- //进球
- //不出现提示语直接继续流程
- this.peoplePlay(0, 0, false, false);
- }
- else {
- //未进球
- this.selfTurn = !this.selfTurn;
- this.peoplePlay(7, 7);
- }
- break;
- }
- }
- else if (xGame.common.gameMode == GameMode.bigMove) {
- if (this.curFoul == FoulType.timeOut) {
- this.selfTurn = !this.selfTurn;
- this.peoplePlay(14, 15);
- this.placeRootBall();
- }
- else {
- //未结束
- this.selfTurn = !this.selfTurn;
- if (this.curFoul == FoulType.rootHole) {
- this.peoplePlay(12, 13);
- this.placeRootBall();
- }
- else {
- this.peoplePlay(0, 0, false, false);
- }
- }
- }
- else if (xGame.common.gameMode == GameMode.placeBall) {
- this.finishOneShoot = true;
- }
- //
- this.gameResult();
- //
- }
- //处理一杆结束后的逻辑
- gameResult() {
- this.firstColliObj = null;
- //进球设置为0
- this.inHoleBalls = [];
- //记录白球的位置
- let curX = xGame.common.d2World.rootBall.gameObj.x
- let curY = xGame.common.d2World.rootBall.gameObj.y
- xGame.common.gameMgr.lastRootBallPos.setValue(curX, curY);
- //高低杆重置
- if (xGame.common.uiRodMethod) xGame.common.uiRodMethod.resetRod();
- //显示母球
- xGame.common.d2World.rootBall.showSelf();
- //清除冰冻效果
- this.clearIceSkill();
- if (this.selfTurn) {
- // console.log("zh:处理一杆结束后的逻辑 gameResult");
- PlatMgr.gameInsert();
- }
- //
- xGame.common.d3World.knifeRoot.destroyChildren();
- //判断延长线引导
- if (this.selfTurn) {
- xGame.common.gameUI.showHelpLineGuide();
- //显示杆和刻度尺
- xGame.common.gameUI.setTurnAlpha(true);
- }
- else {
- //隐藏刻度尺和杆等
- xGame.common.gameUI.setTurnAlpha(false);
- }
- }
- getScore(type) {
- let selfAdd = 0;
- let aiAdd = 0;
- if (type == FoulType.timeOut) {
- if (this.selfTurn) aiAdd += 3;
- else selfAdd += 3;
- //
- }
- else {
- if (this.inHoleBalls.length > 0) {
- if (this.selfTurn) {
- if (type == FoulType.rootHole) {
- aiAdd += 3;
- if (this.inHoleBalls.length - 1 > 0) {
- selfAdd += this.inHoleBalls.length - 1;
- }
- }
- else {
- selfAdd += this.inHoleBalls.length;
- }
- }
- else {
- if (type == FoulType.rootHole) {
- selfAdd += 3;
- if (this.inHoleBalls.length - 1 > 0) {
- aiAdd += this.inHoleBalls.length - 1;
- }
- }
- else {
- aiAdd += this.inHoleBalls.length;
- }
- }
- }
- }
- return [selfAdd, aiAdd];
- }
- judgeScoreEnd(selfAdd, aiAdd) {
- this.selfScore += selfAdd;
- this.aiScore += aiAdd;
- this.updateAIScore();
- this.updateSelfScore();
- //判断是否结束
- if (this.selfScore >= this.targertScore) {
- this.success = true;
- return true
- }
- if (this.aiScore >= this.targertScore) {
- this.success = false;
- return true
- }
- //如果场上只剩下白球了。
- let ballArr = xGame.common.d2World.ballArr;
- if (ballArr.length == 1 && ballArr[0].number == 0) {
- if (this.selfScore > this.aiScore) {
- this.success = true;
- return true
- }
- else if (this.selfScore < this.aiScore) {
- this.success = false;
- return true
- }
- else {
- //相等的话,先达到该分数的 算做胜利
- if (this.selfTurn) {
- this.success = false;
- }
- else {
- this.success = true;
- }
- return true;
- }
- }
- }
- clearIceSkill() {
- //自己布置的冰冻效果,轮到自己的时候会消失
- let arr = xGame.common.d2World.ballArr;
- let temp: D2BallSrc;
- if (this.selfTurn) {
- if (this.selfCurSkill == SkillType.ice) {
- //将所有玩家的冰冻求变为正常
- for (let index = 0; index < arr.length; index++) {
- temp = arr[index];
- if (temp.ballFunc == "ice") {
- temp.setBallFunc("normal", "self");
- }
- }
- }
- }
- else {
- if (this.aiCurSkill == SkillType.ice) {
- for (let index = 0; index < arr.length; index++) {
- temp = arr[index];
- //将所有ai的冰冻求变为正常
- if (temp.ballFunc == "ice") {
- temp.setBallFunc("normal", "ai");
- }
- }
- }
- }
- }
- judgeNormalSuccess() {
- if (this.selfTurn) {
- if (this.selfBallArr.length <= 0 && this.inHoleBalls.indexOf(this.blackNum) > -1) {
- //玩家正常胜利
- this.success = true;
- return true;
- }
- }
- else {
- if (this.aiBallArr.length <= 0 && this.inHoleBalls.indexOf(this.blackNum) > -1) {
- //对手ai正常胜利
- this.success = false;
- return true;
- }
- }
- }
- public isEnter: boolean = true;
- gameEnd() {
- if (Moyu.isTT) {
- xGame.common.screenImg = getScreenImg();
- }
- console.log("游戏结束", this.success);
- xGame.common.aiPlayer.stopRun();
- if (xGame.common.gameMode == GameMode.placeBall) {
- this.getEndStarNum();
- this.updatePlaceBallState();
- }
- this.isEnter = false;
- Moyu.recordEnd(this, () => {
- //
- if (this.isEnter) return;
- this.isEnter = true;
- console.log("进入录结束回调");
- this.enterNext();
- });
- Laya.timer.once(1000, this, () => {
- if (this.isEnter) return;
- this.isEnter = true;
- this.enterNext();
- })
- //
- xGame.common.longHelpLine = false;
- //
- }
- enterNext() {
- Laya.timer.clearAll(this);
- //
- if (Moyu.canShare() > 100 || Moyu.isKs) {
- xGame.uiMgr.Show(UIVideoShare, this.success);
- }
- else {
- xGame.uiMgr.Show(UIGameEnd, this.success);
- }
- }
- aiLeave() {
- let ui = xGame.common.gameUI.ui;//离线
- ui.topNode.aiNameTxt.text = "offline";
- }
- aiGameEnd(suc: boolean) {
- this.success = suc;
- xGame.common.aiPlayer.stopRun();
- if (this.success) {
- //对手已逃跑!
- xGame.uiMgr.Show(UIMsg, "The opponent has fled");
- Laya.timer.once(1000, this, () => {
- this.clearTime();
- this.gameEnd();
- })
- }
- }
- openTimer() {
- let src = xGame.common.gameUI;
- if (this.selfTurn) {
- src.ui.topNode.selfProgress.visible = true;
- src.ui.topNode.aiProgress.visible = false;
- this.curTimer = src.ui.topNode.selfProgress;
- }
- else {
- src.ui.topNode.selfProgress.visible = false;
- src.ui.topNode.aiProgress.visible = true;
- this.curTimer = src.ui.topNode.aiProgress;
- }
- this.accTime = 0;
- Laya.timer.clearAll(this);
- Laya.timer.loop(20, this, this.updateTime, [0.02]);
- this.curTimer.value = 100;
- }
- updateTime(dt) {
- if (this.gamePause) return;
- this.accTime += dt;
- this.curTimer.value = 100 * (this.setTime - this.accTime) / this.setTime;
- if (this.accTime >= this.setTime) {
- this.clearTime();
- console.log("时钟进入了gameRun");
- this.gameRun(FoulType.timeOut)
- }
- }
- clearTime() {
- let src = xGame.common.gameUI;
- src.ui.topNode.selfProgress.visible = false;
- src.ui.topNode.aiProgress.visible = false;
- //清除计时时间
- Laya.timer.clearAll(this);
- }
- peoplePlay(selfIndex, aiIndex, Foul = false, sayWords = true) {
- let ui = xGame.common.gameUI.ui;
- //foul判负犯规
- let selfMsg, aiMsg;
- if (sayWords) {
- selfMsg = cfgTable.wordsData[selfIndex].msg;
- aiMsg = cfgTable.wordsData[aiIndex].msg;
- if (Foul) {
- selfMsg = selfMsg.replace("$", this.aiFoulNum + "");
- aiMsg = aiMsg.replace("$", this.selfFoulNum + "");
- //摆放白球
- this.placeRootBall();
- if (!this.selfTurn && xGame.common.gameMode == GameMode.classic) {
- if (this.curFoul == FoulType.rootHole) {
- if (!DataMgr.getRootBallFoul()) {
- DataMgr.setRootBallFoul();
- //
- aiMsg = "";
- //白球进洞了,3次犯规本局游戏失败。
- let tips = "The cue ball (white ball) has been pocketed. Three fouls have been committed—you lose this game"
- //老板,下次注意啦~
- let woman = "Boss, pay attention next time~"
- xGame.uiMgr.Show(UITips, tips, woman, TipsType.foul);
- }
- }
- else if (this.curFoul == FoulType.timeOut) {
- if (!DataMgr.getTimeoutFoul()) {
- DataMgr.setTimeoutFoul();
- aiMsg = "";
- //游戏超时,3次犯规本局游戏失败。
- let tips = "Game timeout, 3 fouls, this game failed."
- //老板,注意时间楼~
- let woman = "Boss, pay attention to the timeline~"
- xGame.uiMgr.Show(UITips, tips, woman, TipsType.foul);
- }
- }
- }
- }
- }
- if (this.selfTurn) {
- //该玩家击球
- if (sayWords) {
- xGame.uiMgr.Show(UIMsg, selfMsg, () => {
- ui.selfTurn.visible = true;
- ui.aiTurn.visible = false;
- ui.selfTurn.t0.play();
- //
- Moyu.vibration();
- });
- }
- }
- else {
- //该对手ai击球
- let aiNum = xGame.tools.random(1, 11);
- let challengeNum = DataMgr.getChallengeTimes();
- let delay = false;
- if (xGame.common.gameMode == GameMode.classic && challengeNum >= 1 && challengeNum <= 3) {
- aiNum = 9;
- if (this.aiBallArr.length <= 2 && this.ensureBallType) {
- aiNum = 3;
- if (challengeNum == 3) {
- if (!this.showLongView) {
- this.showLongView = true;
- delay = true;
- }
- }
- }
- }
- if (delay) {
- xGame.uiMgr.Show(UIRepentProp, 0, 0, (success) => {
- if (success) {
- //延长辅助线
- xGame.common.longHelpLine = true;
- xGame.common.d2World.getHelpLine();
- }
- else {
- // 不做操作退出
- aiNum = 10;
- }
- //
- xGame.common.aiPlayer.setAiLevel(aiNum);
- if (sayWords) {
- xGame.uiMgr.Show(UIMsg, aiMsg, () => {
- xGame.common.aiPlayer.runAI();
- //
- ui.selfTurn.visible = false;
- ui.aiTurn.visible = true;
- ui.aiTurn.t0.play();
- //
- });
- }
- else {
- xGame.common.aiPlayer.runAI();
- }
- this.openTimer();
- this.finishOneShoot = true;
- //
- if (this.selfTurn) {
- ui.topNode.selfKuang.visible = true;
- ui.topNode.aiKuang.visible = false;
- ui.topNode.selfTips.visible = true;
- ui.topNode.aiTips.visible = false;
- }
- else {
- ui.topNode.selfKuang.visible = false;
- ui.topNode.aiKuang.visible = true;
- ui.topNode.selfTips.visible = false;
- ui.topNode.aiTips.visible = true;
- }
- //
- })
- return;
- }
- if (xGame.common.gameMode == GameMode.classic) {
- let cfg = cfgTable.modeselectData[xGame.common.classicRoomType];
- if (cfg) {
- let aiLevel = xGame.common.randomNum(cfg.aiLevel[0], cfg.aiLevel[1]);
- aiNum = aiLevel;
- }
- }
- xGame.common.aiPlayer.setAiLevel(aiNum);
- //
- if (sayWords) {
- xGame.uiMgr.Show(UIMsg, aiMsg, () => {
- xGame.common.aiPlayer.runAI();
- //
- ui.selfTurn.visible = false;
- ui.aiTurn.visible = true;
- ui.aiTurn.t0.play();
- //
- });
- }
- else {
- xGame.common.aiPlayer.runAI();
- }
- }
- this.openTimer();
- this.finishOneShoot = true;
- //
- if (this.selfTurn) {
- ui.topNode.selfKuang.visible = true;
- ui.topNode.aiKuang.visible = false;
- ui.topNode.selfTips.visible = true;
- ui.topNode.aiTips.visible = false;
- }
- else {
- ui.topNode.selfKuang.visible = false;
- ui.topNode.aiKuang.visible = true;
- ui.topNode.selfTips.visible = false;
- ui.topNode.aiTips.visible = true;
- }
- }
- //放置白球位置
- placeRootBall() {
- //移动至上一次白球的位置
- let rootBall = xGame.common.d2World.rootBall;
- if (!rootBall) return;
- rootBall.gameObj.x = this.lastRootBallPos.x;
- rootBall.gameObj.y = this.lastRootBallPos.y;
- rootBall.d3BallSrc.setTransPos(this.lastRootBallPos.x, this.lastRootBallPos.y);
- //
- let moveNode = xGame.common.gameUI.ui.moveNode;
- moveNode.visible = true;
- moveNode.x = this.lastRootBallPos.x;
- moveNode.y = this.lastRootBallPos.y;
- //ai犯规玩家才能移动白球
- if (!this.selfTurn) {
- xGame.common.aiPlayer.resetRoot();
- }
- }
- }
|