import { HTTP_TYPE } from "../datas/CommonData"; import { RichData } from "../datas/RichData"; import { WealthData } from "../datas/WealthData"; import Main from "../Main"; import Wealth from "../other/control/Wealth"; import Bullet from "../other/item/Bullet"; import CarSpace from "../prefabs/CarSpace"; import MyExtends from "../tools/MyExtends"; import Time from "../tools/Time"; import UIMng, { PanelType } from "../uiFrames/UIMng"; import Sciencen_M from "../utils/Sciencen_M"; import AdM from "./AdM"; import { GameController } from "./GameController"; import GameM, { AUDIO_TYPE } from "./GameM"; import GuideMng from "./GuideMng"; import HttpM from "./HttpM"; import UiM from "./UiM"; const { ccclass, property } = cc._decorator; export enum WealthState { Cooling = 0, ReadyFight = 1, Fighting = 2, End = 3, } @ccclass export default class WealthMng extends cc.Component { private static ins: WealthMng = null static get Ins(): WealthMng { if (!this.ins) { this.ins = new WealthMng(); } return this.ins; } Destroy() { this.node.destroy(); WealthMng.ins = null; } @property(cc.Node) private gameView: cc.Node = null; @property(cc.Node) private posNodeAry: cc.Node[] = []; @property(cc.Node) private wealth: cc.Node = null; @property(cc.Node) private bullet: cc.Node = null; @property(cc.Node) private bulletEft: cc.Node = null; @property(sp.Skeleton) private groundDeftSpine: sp.Skeleton = null; @property(sp.Skeleton) private titleSpine: sp.Skeleton = null; //@property(cc.Node) //private bg1: cc.Node = null; //@property(cc.Node) //private bg2: cc.Node = null; //@property(cc.Node) //private tip: cc.Node = null; @property(cc.Node) private coinEft: cc.Node = null; @property(cc.Label) private coinEftTxt: cc.Label = null; @property(sp.Skeleton) private pointSpine: sp.Skeleton = null; @property(cc.Node) uiWealthNode: cc.Node = null; @property(cc.Node) mask: cc.Node = null; @property(cc.Node) inputBlock: cc.Node = null; private bulletParent: cc.Node = null; private wealthScr: Wealth = null; private mainScr: Main = null; private carSpaceAry: CarSpace[] = []; private timer: number = 0; isWealthing: boolean = false; isUsingSkill: boolean = false; private changeStateTime: number = 5; private curPosNodeIndex: number = 0; /**是否在冷却中*/ isCooling: boolean = false; blood: number = 200; bloodValue: number = 200; private triggerTimer: number = 0; private triggerTime: number = 5; private triggerCheck: boolean = false; private titleNodePos: cc.Vec2 = null; wealthState: WealthState = WealthState.ReadyFight; isJumping: boolean = false; onLoad() { WealthMng.ins = this; WealthData.Ins.wealthMng = this; //WealthData.Ins.WealthInit(); this.mainScr = UiM.Instance.hallNode.getComponent(Main); this.wealthScr = this.wealth.getComponent(Wealth); this.wealthScr.onLoad(); //this.carSpaceAry = this.mainScr.carSpaceArr; this.wealth.active = false; this.mainScr.carSpaceArr.forEach(element => { this.carSpaceAry.push(element.getComponent(CarSpace)); }); //cc.director.getCollisionManager().enabled = true; cc.director.getPhysicsManager().enabled = true; //console.log("WealthData1:", WealthData.Ins.wealthMng); //console.log("++++++++++++", this.wealthScr); this.titleNodePos = this.titleSpine.node.getPosition(); this.Init(); //console.log("Wealth WorldPos:",MyExtends.localConvertWorldPointAR(this.node)); //let worldpos = MyExtends.localConvertWorldPointAR(this.uiWealthNode);// this.node.parent.parent.convertToWorldSpaceAR(cc.v2(0, -162)); //MyExtends.localConvertWorldPointAR(this.node.parent.parent,cc.v2(0, -162)); //worldpos = MyExtends.worldConvertLocalPointAR2D(this.gameView, worldpos); //console.log("WorldPos:(" + worldpos.x + "," + worldpos.y + ")"); this.schedule(() => { WealthData.Ins.UpdateWealthState(); }, 5); //console.log("+++++++++++++++++: " + Sciencen_M.instance.subtraction("100", "150")); } start() { } update(dt) { this.CheckWealth(dt); //this.TimerCheckTriggerWealth(dt); this.TimerCooling(dt); this.TimerLife(dt); } GetUiWealthPos() { let worldpos = MyExtends.localConvertWorldPointAR(this.uiWealthNode); worldpos = MyExtends.worldConvertLocalPointAR2D(this.gameView, worldpos); return worldpos; } Init() { //console.log("WealthOpenResRequest-------------------1:"); //HttpM.Instance.SendData(HTTP_TYPE.wealthGodOpen, {}, (res) => { // console.log("WealthOpenRes------------:", res); // if (res.data != null) { // console.log("WealthOpen:", res.data); // } //}); //WealthData.Ins.CheckUnLockWealth(); WealthData.Ins.WealthStatusInit(); this.scheduleOnce(() => { if (WealthData.Ins.lifeTimer > 0 && WealthData.Ins.wealthInfo.wealthGodStatus == 3) { this.SwitchFightingState(); GameM.audioM.setPauseMusic(); GameM.audioM.playMateEffect(AUDIO_TYPE.wealthbgm, true); } else { //this.CheckTriggerWealth(); } }, 2); } /**切换为战斗状态*/ async SwitchFightingState() { this.triggerCheck = false; WealthData.Ins.WealthFightInit(); this.inputBlock.active = true; this.mask.opacity = 0; this.mask.active = true; this.mask.runAction(cc.fadeTo(0.3, 130)); await Time.WaitForSeconds(0.3); this.titleSpine.node.setPosition(this.titleNodePos); this.titleSpine.node.opacity = 255; this.titleSpine.node.active = true; this.titleSpine.setAnimation(0, "animation", false); await Time.WaitForSeconds(this.titleSpine.findAnimation("animation").duration + 0.5); let b1 = cc.delayTime(0.2); let b2 = cc.spawn(cc.moveTo(0.5, cc.v2(0, this.titleNodePos.y + 100)), cc.fadeOut(0.5)); let b3 = cc.callFunc(() => { this.titleSpine.node.active = false; }); this.titleSpine.node.runAction(cc.sequence(b1, b2, b3)); await Time.WaitForSeconds(0.5); //let wealthbtn = UiM.Instance.hallNode.getComponent(Main).wealthBtn; //wealthbtn.runAction(cc.sequence(cc.fadeOut(0.3), cc.callFunc(() => wealthbtn.active = false))); this.curPosNodeIndex = 3; this.wealthScr.SwitchFightingState(this.posNodeAry[this.curPosNodeIndex].getPosition(), () => { this.triggerTimer = 0; //WealthData.Ins.blood = WealthData.Ins.bloodValue; this.timer = 0; this.isJumping = false; this.isUsingSkill = false; //this.wealth.setPosition(500, -140); //this.wealth.scale = 1; //this.wealth.active = true; //this.curPosNodeIndex = MyExtends.GetIndexByAry(this.posNodeAry, this.curPosNodeIndex); //let a1 = cc.jumpTo(0.7, this.posNodeAry[this.curPosNodeIndex].getPosition(), 800, 1); //let a2 = cc.callFunc(() => { this.CheckAttack(); }); //this.wealth.runAction(cc.sequence(a1, a2)); this.wealthScr.UpdateTxt(WealthData.Ins.blood, WealthData.Ins.bloodValue); this.isWealthing = true; this.wealthState = WealthState.Fighting; this.CheckAttack(); this.mainScr.ChangeNormalGuideState(0); this.mask.active = false; this.inputBlock.active = false; WealthData.Ins.SwitchFightingState(); }); if (UIMng.Ins.IsExistPanel(PanelType.WealthPanel)) { UIMng.Ins.GetPanel(PanelType.WealthPanel).OnExit(); } } /**触发财神降临*/ CheckTriggerWealth(isunlocktrigger: boolean = false) { if (!this.isWealthing) { WealthData.Ins.CheckTriggerWealth(isunlocktrigger, () => { this.CreatWealth(); GameM.audioM.setPauseMusic(); GameM.audioM.playMateEffect(AUDIO_TYPE.wealthbgm, true); }); } } async CreatWealth() { this.triggerCheck = false; WealthData.Ins.WealthFightInit(); this.inputBlock.active = true; this.mask.opacity = 0; this.mask.active = true; this.mask.runAction(cc.fadeTo(0.3, 130)); await Time.WaitForSeconds(0.3); this.titleSpine.node.setPosition(this.titleNodePos); this.titleSpine.node.opacity = 255; this.titleSpine.node.active = true; this.titleSpine.setAnimation(0, "animation", false); await Time.WaitForSeconds(this.titleSpine.findAnimation("animation").duration + 0.5); let b1 = cc.delayTime(0.2); let b2 = cc.spawn(cc.moveTo(0.5, cc.v2(0, this.titleNodePos.y + 100)), cc.fadeOut(0.5)); let b3 = cc.callFunc(() => { this.titleSpine.node.active = false; }); this.titleSpine.node.runAction(cc.sequence(b1, b2, b3)); await Time.WaitForSeconds(0.5); //let wealthbtn = UiM.Instance.hallNode.getComponent(Main).wealthBtn; //wealthbtn.runAction(cc.sequence(cc.fadeOut(0.3), cc.callFunc(() => wealthbtn.active = false))); this.curPosNodeIndex = 3; this.wealthScr.TriggerWealth(this.posNodeAry[this.curPosNodeIndex].getPosition(), () => { this.triggerTimer = 0; WealthData.Ins.blood = WealthData.Ins.bloodValue; this.timer = 0; this.isJumping = false; this.isUsingSkill = false; //this.wealth.setPosition(500, -140); //this.wealth.scale = 1; //this.wealth.active = true; //this.curPosNodeIndex = MyExtends.GetIndexByAry(this.posNodeAry, this.curPosNodeIndex); //let a1 = cc.jumpTo(0.7, this.posNodeAry[this.curPosNodeIndex].getPosition(), 800, 1); //let a2 = cc.callFunc(() => { this.CheckAttack(); }); //this.wealth.runAction(cc.sequence(a1, a2)); this.wealthScr.UpdateTxt(WealthData.Ins.blood, WealthData.Ins.bloodValue); this.isWealthing = true; this.wealthState = WealthState.Fighting; this.CheckAttack(); this.mainScr.ChangeNormalGuideState(0); this.mask.active = false; this.inputBlock.active = false; //没有进入大富翁界面才允许引导 if (!RichData.Ins.isOpenRichPanel) GuideMng.Ins.CheckWealthGuide17(); }); if (UIMng.Ins.IsExistPanel(PanelType.WealthPanel)) { UIMng.Ins.GetPanel(PanelType.WealthPanel).OnExit(); } } CheckWealth(dt) { //if (this.isWealthing && !this.isUsingSkill) { // this.timer += dt; // if (this.timer >= this.changeStateTime) { // this.timer = 0; // this.curPosNodeIndex = MyExtends.GetIndexByAry(this.posNodeAry, this.curPosNodeIndex); // this.isJumping = true; // let a1 = cc.jumpTo(0.7, this.posNodeAry[this.curPosNodeIndex].getPosition(), 800, 1); // let a2 = cc.callFunc(() => { this.CheckAttack(); }); // this.wealth.runAction(cc.sequence(a1, a2)); // } //} } /**触发 改为购买武将触发*/ TimerCheckTriggerWealth(dt) { return; if (this.triggerCheck) { this.triggerTimer += dt; if (this.triggerTimer >= this.triggerTime) { //this.triggerCheck = false; this.CheckTriggerWealth(); } } } /**财神挑战冷却计时器*/ TimerCooling(dt) { if (this.isCooling) { WealthData.Ins.coolingTimer -= dt; if (WealthData.Ins.coolingTimer <= 0) { WealthData.Ins.WealthReady(); // WealthData.Ins.coolingTimer = 0; // this.isCooling = false; // WealthData.Ins.isCooling = false; console.log("trigger cooling end"); } } } TimerLife(dt) { if (this.isWealthing) { WealthData.Ins.lifeTimer -= dt; if (WealthData.Ins.lifeTimer <= 0) { this.CheckAttackEnd(false); } } } CheckAttack() { this.isJumping = false; if (!this.isWealthing) return; let carindexs: number[] = []; if (this.curPosNodeIndex < 4) { carindexs.push(this.curPosNodeIndex); carindexs.push(this.curPosNodeIndex + 1); carindexs.push(this.curPosNodeIndex + 5); carindexs.push(this.curPosNodeIndex + 6); } else { carindexs.push(this.curPosNodeIndex - 4 + 5); carindexs.push(this.curPosNodeIndex - 4 + 6); carindexs.push(this.curPosNodeIndex - 4 + 10); carindexs.push(this.curPosNodeIndex - 4 + 11); } for (let i = 0; i < this.carSpaceAry.length; i++) { //if (!this.isWealthing) break; if (carindexs.includes(i)) { this.carSpaceAry[i].CheckSpaceState(false); //console.log("====1 index:"+this.curPosNodeIndex); } else { this.carSpaceAry[i].CheckSpaceState(true); } this.carSpaceAry[i].CheckAttack(); } } MasterEffect() { for (let i = 0; i < this.carSpaceAry.length; i++) { this.carSpaceAry[i].MasterEffect(); } //this.carSpaceAry.forEach(element => { // element.MasterEffect(); //}); this.isUsingSkill = false; if (this.bulletParent != null) { this.bulletParent.destroy(); this.bulletParent = null; } this.PlayGroundAni(); MyExtends.ScreenShock(UiM.Instance.hallNode, 0.3); } async PlayGroundAni() { this.groundDeftSpine.node.setPosition(this.posNodeAry[this.curPosNodeIndex].x, this.posNodeAry[this.curPosNodeIndex].y - 170); this.groundDeftSpine.node.active = true; this.groundDeftSpine.setAnimation(0, "animation", false); await Time.WaitForSeconds(1); this.groundDeftSpine.node.active = false; } Shoot(carspace: cc.Node, masterlv: number) { if (this.isWealthing) { if (this.bulletParent == null) { this.bulletParent = new cc.Node("BulletParent"); this.bulletParent.parent = this.gameView; } let bulletcopy = cc.instantiate(this.bullet); //bulletcopy.parent = this.gameView; bulletcopy.parent = this.bulletParent; bulletcopy.setPosition(MyExtends.convetOtherNodeSpaceAR(carspace, this.gameView)); bulletcopy.active = true; bulletcopy.getComponent(Bullet).Shoot(this.wealth, masterlv); } } async ShootEft(pos: cc.Vec2) { let bulleteftc = cc.instantiate(this.bulletEft); bulleteftc.parent = this.gameView; bulleteftc.setPosition(pos); bulleteftc.active = true; await Time.WaitForSeconds(1); bulleteftc.destroy(); } /**受到伤害 * @param damageType 伤害类型 1 武将攻击伤害 2 玩家攻击伤害 * @param masterlv 武将等级 */ GetDamage(damageType = 1, masterlv: number = 1) { if (this.isWealthing && WealthData.Ins.blood != "0" && WealthData.Ins.blood[0] != "-") { let damage = damageType == 1 ? WealthData.Ins.GetMasterDamageCoin(masterlv) : WealthData.Ins.GetPlayDamageCoin(); WealthData.Ins.blood = Sciencen_M.instance.subtraction(WealthData.Ins.blood, damage); //WealthData.Ins.blood--; if (WealthData.Ins.blood[0] == "0" || WealthData.Ins.blood[0] == "-") { WealthData.Ins.blood = "0"; this.CheckAttackEnd(true); } else { if (damageType == 1) this.CheckUseSkill1(); this.wealthScr.UpdateTxt(WealthData.Ins.blood, WealthData.Ins.bloodValue); if (!this.isUsingSkill && damageType == 2) this.wealthScr.GetDamage(); } if (damageType == 2) GameM.audioM.playEffect(AUDIO_TYPE.getGold, false) this.PlayCoinAni(damage, damageType); GameM.commonData.updateGold(damage); //GameM.httpM.sendDatas(HTTP_TYPE.updateGold, { 'gold': GameM.commonData.gold }); } } /**使用眩晕技能*/ async CheckUseSkill1() { if (GuideMng.Ins.CurGuideId == 17) return; if (!this.isUsingSkill && !this.isJumping && WealthData.Ins.CheckTriggerSkill1()) { //console.log("--->2", this.carSpaceAry); this.isUsingSkill = true; this.curPosNodeIndex = MyExtends.GetIndexByAry(this.posNodeAry, this.curPosNodeIndex); this.pointSpine.node.setPosition(this.posNodeAry[this.curPosNodeIndex].getPosition().x, this.posNodeAry[this.curPosNodeIndex].getPosition().y - 140); this.pointSpine.node.active = true; this.pointSpine.setAnimation(0, "animation", true); //this.posNodeAry[this.curPosNodeIndex].active = true; await Time.WaitForSeconds(0.5); //this.posNodeAry[this.curPosNodeIndex].active = false; this.wealthScr.UseSkill1(this.posNodeAry[this.curPosNodeIndex].getPosition(), () => { this.MasterSkill1Effect(); if (!RichData.Ins.isOpenRichPanel) GameM.audioM.playEffect(AUDIO_TYPE.wealthswim, false); this.pointSpine.clearTrack(0); this.pointSpine.node.active = false; }); } } MasterSkill1Effect() { this.isJumping = false; if (!this.isWealthing) return; let carindexs: number[] = []; if (this.curPosNodeIndex < 4) { carindexs.push(this.curPosNodeIndex); carindexs.push(this.curPosNodeIndex + 1); carindexs.push(this.curPosNodeIndex + 5); carindexs.push(this.curPosNodeIndex + 6); } else { carindexs.push(this.curPosNodeIndex - 4 + 5); carindexs.push(this.curPosNodeIndex - 4 + 6); carindexs.push(this.curPosNodeIndex - 4 + 10); carindexs.push(this.curPosNodeIndex - 4 + 11); } for (let i = 0; i < this.carSpaceAry.length; i++) { if (carindexs.includes(i)) { this.carSpaceAry[i].CheckSpaceState(false); } else { this.carSpaceAry[i].CheckSpaceState(true); } this.carSpaceAry[i].MasterEffect(); } //for (let i = 0; i < this.carSpaceAry.length; i++) { // this.carSpaceAry[i].MasterEffect(); //} //this.carSpaceAry.forEach(element => { // element.MasterEffect(); //}); this.isUsingSkill = false; if (this.bulletParent != null) { this.bulletParent.destroy(); this.bulletParent = null; } this.PlayGroundAni(); MyExtends.ScreenShock(UiM.Instance.hallNode, 0.3); } /**播放金币动画 * @param coinStr 金币 * @param roletype 角色类型 1 武将 2 玩家 */ PlayCoinAni(coinStr: string, roletype: number) { //this.coinEft.active = true; //this.coinEft.stopAllActions(); this.coinEft.opacity = 255; this.coinEft.setPosition(0, 0); this.coinEftTxt.string = Sciencen_M.instance.format(coinStr); this.coinEftTxt.node.color = roletype == 1 ? cc.color(255, 255, 255, 255) : cc.color(254, 241, 65, 255); let copy = cc.instantiate(this.coinEft); copy.parent = this.coinEft.parent; copy.setPosition(this.wealth.x, this.wealth.y + 150); copy.active = true; let a, c; if (roletype == 1) { copy.scale = 0.5; a = cc.moveBy(0.5, cc.v2(0, 150)); c = cc.scaleTo(0.5, 1); } else { copy.scale = 0.7; a = cc.moveBy(0.5, cc.v2(-40, 150)); c = cc.scaleTo(0.5, 1.2); } //let a = cc.moveBy(0.5, cc.v2(0, 100)); let b1 = cc.delayTime(0.4); let b2 = cc.fadeOut(0.1); let b3 = cc.callFunc(() => { copy.destroy(); }); let b = cc.sequence(b1, b2, b3); //let c = cc.scaleTo(0.5, 1); copy.runAction(cc.spawn(a, b, c)); } CheckAttackEnd(isSuccess: boolean) { if (this.isWealthing) { this.isWealthing = false; WealthData.Ins.WealthCooling(); this.curPosNodeIndex = 0; this.timer = 0; this.wealthState = WealthState.ReadyFight; if (this.pointSpine.node.active == true) { this.pointSpine.clearTrack(0); this.pointSpine.node.active = false; } this.wealth.stopAllActions(); this.wealthScr.WealthEnd(isSuccess); for (let i = 0; i < this.carSpaceAry.length; i++) { this.carSpaceAry[i].AttackEnd(); this.carSpaceAry[i].CheckSpaceState(true); } this.mainScr.ChangeNormalGuideState(1); this.triggerCheck = true; if (UIMng.Ins.IsExistPanel(PanelType.WealthPanel)) { UIMng.Ins.GetPanel(PanelType.WealthPanel).OnExit(); } console.log("WealthInfo: Challenge have times:" + (WealthData.Ins.challengeTimes - WealthData.Ins.challengedTimes) + " Cooling Time:" + WealthData.Ins.coolingTimer); //不在每日五福界面则关闭音效 GameController.Ins.SwitchAudio(2); WealthData.Ins.WealthFightEnd(); } } GetOccupyCarSpaces() { let carindexs: number[] = []; if (this.curPosNodeIndex < 4) { carindexs.push(this.curPosNodeIndex); carindexs.push(this.curPosNodeIndex + 1); carindexs.push(this.curPosNodeIndex + 5); carindexs.push(this.curPosNodeIndex + 6); } else { carindexs.push(this.curPosNodeIndex - 4 + 5); carindexs.push(this.curPosNodeIndex - 4 + 6); carindexs.push(this.curPosNodeIndex - 4 + 10); carindexs.push(this.curPosNodeIndex - 4 + 11); } } ClearShield() { this.wealthScr.UnUseShield(); } }