| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
- import { MONEY_TYPE } from "../datas/CommonData";
- import GameM, { AUDIO_TYPE, Game_Quality, VIDEO_TYPE } from "../manager/GameM";
- import UiM from "../manager/UiM";
- import Main from "../Main";
- import Sciencen_M from "../utils/Sciencen_M";
- import { Role } from "../other/item/Role";
- import MyExtends from "../tools/MyExtends";
- import EffectNode from "../ui/EffectNode";
- import { MateData } from "../datas/MateData";
- import Gift from "../ui/Gift";
- import WealthMng from "../manager/WealthMng";
- import Time from "../tools/Time";
- import { WealthData } from "../datas/WealthData";
- import { Utils } from "../utils/Utils";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class CarSpace extends cc.Component {
- @property(cc.Node)
- chewei: cc.Node = null
- @property(cc.Node)
- green: cc.Node = null;
- @property(cc.Node)
- cheweihc: cc.Node = null
- @property(cc.Sprite)
- coinSlider: cc.Sprite = null;
- @property(cc.Node)
- car: cc.Node = null;
- @property(cc.Node)
- box: cc.Node = null;
- @property(cc.Node)
- boxHead: cc.Node = null;
- @property(cc.Node)
- xuhao: cc.Node = null
- @property(cc.Label)
- labLv: cc.Label = null
- @property(cc.Label)
- labNum: cc.Label = null
- @property(cc.Animation)
- boxShakeAni: cc.Animation = null
- @property(sp.Skeleton)
- lightAni: sp.Skeleton = null
- @property(sp.Skeleton)
- composeAni: sp.Skeleton = null
- @property(cc.Node)
- coinEft: cc.Node = null;
- @property(cc.Label)
- coinTxt: cc.Label = null;
- @property(cc.Node)
- strikeNode: cc.Node = null;
- @property(cc.Label)
- strikeTimerTxt: cc.Label = null;
- qipao: cc.Node = null
- boatTween = null
- //位置
- index: number = 0
- //类型
- //被其他占用
- /*
- 10001:金币
- 10002:红包币
- 10003:时间段收益(当前的每秒收益*时间段)
- 10004:惊喜礼包(打开后获得对应等级的汽车)
- */
- type: number = 0
- /** 数量 */
- num: number = 0
- // LIFE-CYCLE CALLBACKS:
- //西游
- role: Role = null;
- /**是否金币孵化 对应addRunCar 生产金币*/
- isSpawn: boolean = false;
- /**产生一次金币所花时间*/
- moneyTime: number = 0;
- /**产生一次金币计时器*/
- moneyTimer: number = 0;
- /**对应时间内产生金币数*/
- moneyDelta: string = '';
- main = null;
- onLoad() {
- this.qipao = this.box.getChildByName('main_icon_qipao')
- this.main = UiM.Instance.hallNode.getComponent(Main)
- this.box.active = false
- this.composeAni.node.active = false;
- this.labNum.node.active = false
- this.xuhao.active = false
- this.labLv.string = ''
- cc.loader.loadRes("prefabs/item/MasterSwimEft",cc.Prefab);
- }
- start() {
- }
- update(dt) {
- this.AddCoinRunner(dt);
- this.AttackRunner(dt);
- }
- /** 初始化
- * @param drop true 掉落
- */
- init(drop = false, num = 1) {
- this.unschedule(this.playBoxShakeDown); //停止播放左右抖动动画
- this.boxShakeAni.stop()
- this.boxOpen = false
- let self = this
- this.cheweihc.active = false
- this.green.active = false;
- this.num = num
- this.lightAni.node.active = false
- this.composeAni.node.active = false;
- this.qipao.active = false
- if (this.boatTween) {
- this.boatTween.stop()
- }
- // console.log('this.type ', this.type)
- if (this.type == 0) {
- this.coinSlider.node.active = false;
- this.car.active = false
- this.xuhao.active = false
- this.labLv.string = ''
- this.labNum.node.active = false
- this.boxHead.active = false
- this.box.active = false
- }
- else {
- this.coinSlider.node.active = this.type < 10000;
- if (this.type < 10000) {
- self.car.scale = 0;
- this.boxHead.active = false
- this.car.active = true
- this.box.active = false
- this.labNum.node.active = false
- this.xuhao.active = true
- cc.loader.loadRes('carPic/side/side_' + this.type, cc.SpriteFrame, (err, assets) => {
- if (err) {
- cc.error(err);
- return;
- }
- self.car.getComponent(cc.Sprite).spriteFrame = assets;
- if (cc.sys.platform != cc.sys.WECHAT_GAME) {
- self.car.scale = 1.1;
- // cc.tween(self.car).to(0.15, { scale: 1.1 }).start();
- if (drop) {
- self.car.y = 1300
- cc.tween(self.car)
- //.to(0.3, { y: -60 })
- .to(0.3, { y: -75 })
- .call(() => {
- if (GameM.commonData.quality > Game_Quality.medium) {
- //航海
- //this.shuihua.setAnimation(0, 'animation', false);
- //this.shuihua.node.active = true
- }
- })
- //.to(0.3, { y: -50 })
- .to(0.3, { y: -68.5 })
- .call(() => {
- this.boatWave()
- })
- .start()
- }
- else {
- //self.car.y = -54
- self.car.y = -68.5
- this.boatWave()
- }
- }
- else {
- self.car.scale = 1.1
- if (GameM.commonData.quality > Game_Quality.medium) {
- if (drop) {
- self.car.y = 1300
- cc.tween(self.car)
- //.to(0.3, { y: -60 })
- .to(0.3, { y: -75 })
- .call(() => {
- if (GameM.commonData.quality > Game_Quality.medium) {
- //航海
- //this.shuihua.setAnimation(0, 'animation', false);
- //this.shuihua.node.active = true
- }
- })
- //.to(0.3, { y: -50 })
- .to(0.3, { y: -68.5 })
- .call(() => {
- this.boatWave()
- })
- .start()
- }
- else {
- //self.car.y = -54
- self.car.y = -68.5
- this.boatWave()
- }
- }
- else {
- //self.car.y = -54
- self.car.y = -68.5
- this.boatWave()
- }
- }
- })
- this.labLv.string = this.type.toString()
- }
- else {
- this.labNum.node.active = true
- this.labNum.string = Sciencen_M.instance.format(this.num.toString())
- this.xuhao.active = false
- this.labLv.string = ''
- this.car.active = false
- this.box.active = true
- //航海
- //this.qipao.active = true
- let str = ''
- if (this.type == MONEY_TYPE.gold) {
- str = 'gift/gold'
- this.boxHead.active = false
- this.green.active = true;
- if (!drop) {
- self.boxShakeAni.play("boxGoldAni");
- }
- }
- else if (this.type == MONEY_TYPE.redMoney) {
- str = 'gift/redMoney'
- this.boxHead.active = false
- this.green.active = true;
- this.labNum.string = this.num.toString()
- if (!drop) {
- self.boxShakeAni.play("boxRedMoneyAni");
- }
- }
- else if (this.type == MONEY_TYPE.box) {
- str = 'gift/box'
- this.boxHead.active = true
- this.labNum.node.active = false
- this.qipao.active = false
- this.boxShakeAni.setCurrentTime(0, 'boxShake')
- this.boxShakeAni.stop()
- }
- else if (this.type == MONEY_TYPE.speedCard) {
- str = 'gift/iconJiasuka'
- this.boxHead.active = false
- this.green.active = true;
- this.labNum.string = this.num.toString()
- if (!drop) {
- self.boxShakeAni.play("boxRedMoneyAni");
- }
- }
- else if (this.type == MONEY_TYPE.turnTableCard) {
- str = 'gift/iconZhuanpanka'
- this.boxHead.active = false
- this.green.active = true;
- this.labNum.string = this.num.toString()
- if (!drop) {
- self.boxShakeAni.play("boxRedMoneyAni");
- }
- }
- else if (this.type == MONEY_TYPE.treasureCard) {
- str = 'gift/iconDuobaoquan'
- this.boxHead.active = false
- this.green.active = true;
- this.labNum.string = this.num.toString()
- if (!drop) {
- self.boxShakeAni.play("boxRedMoneyAni");
- }
- }
- // console.log('str ', str)
- self.box.getComponent(cc.Sprite).spriteFrame = cc.loader.getRes(str, cc.SpriteFrame)
- if (drop) {
- if (GameM.commonData.quality > Game_Quality.medium) {
- self.box.setPosition(cc.v2(0, 1300))
- cc.tween(self.box)
- .to(0.3, { position: cc.v2(0, -7.5) })
- .call(() => {
- if (self.type == MONEY_TYPE.box) {
- self.scheduleOnce(self.playBoxShakeDown, 0.5);
- self.scheduleOnce(self.delayOpenBox, 5);
- }
- else if (self.type == MONEY_TYPE.redMoney) {
- self.boxShakeAni.play("boxRedMoneyAni");
- }
- else if (self.type == MONEY_TYPE.gold) {
- self.boxShakeAni.play("boxGoldAni");
- } else {
- self.boxShakeAni.play("boxGoldAni");
- }
- })
- .start()
- }
- else {
- self.box.setPosition(cc.v2(0, -7.5))
- if (self.type == MONEY_TYPE.box) {
- self.scheduleOnce(self.playBoxShakeDown, 0.5);
- self.scheduleOnce(self.delayOpenBox, 5);
- }
- else if (self.type == MONEY_TYPE.redMoney) {
- self.boxShakeAni.play("boxRedMoneyAni");
- }
- else if (self.type == MONEY_TYPE.gold) {
- self.boxShakeAni.play("boxGoldAni");
- } else {
- self.boxShakeAni.play("boxGoldAni");
- }
- }
- }
- }
- }
- this.CheckAttack();
- this.ClearSwimState();
- }
- playBoxShakeDown() {
- this.boxShakeAni.play("boxShakeDown");
- }
- /** 船上下晃动 */
- boatWave() {
- if (GameM.commonData.quality <= Game_Quality.medium) {
- return
- }
- this.boatTween = cc.tween(this.car)
- //.to(1, { y: -50 })
- //.to(1, { y: -54 })
- .to(1, { y: -68.5 })
- .to(1, { y: -64.5 })
- .union()
- .repeatForever()
- .start()
- }
- delayOpenBox() {
- this.openBox(Number(GameM.commonData.buyNumCfg[(GameM.commonData.buyTimeTotal + 1).toString()].box_car));
- }
- hideImg() {
- this.car.active = false
- }
- showImg() {
- if (this.type < 10000 && this.type != 0) {
- this.car.active = true
- }
- }
- showCanCompose() {
- this.cheweihc.active = true;
- //this.cheweihc.opacity = 255;
- cc.tween(this.cheweihc).repeatForever(cc.tween(this.cheweihc).to(0.5, { scale: 1.1 }).to(0.5, { scale: 1 })).start();
- }
- hideCanCompose() {
- this.cheweihc.active = false;
- cc.Tween.stopAllByTarget(this.cheweihc);
- }
- /** 改变车类型
- * @param type 类型 0 为空车位
- */
- changeType(type) {
- if (type != 0) {
- this.showImg()
- }
- if (this.type == type) {
- return
- }
- this.type = type
- this.init()
- }
- boxOpen = false
- /** 打开宝箱
- * @type 车等级
- */
- openBox(type) {
- if (this.boxOpen) {
- return
- }
- this.unschedule(this.delayOpenBox)
- GameM.audioM.playEffect(AUDIO_TYPE.giftOpen)
- this.boxOpen = true
- let self = this
- this.scheduleOnce(function () {
- self.scheduleOnce(function () {
- GameM.audioM.playEffect(AUDIO_TYPE.giftGetCar)
- self.changeType(type)
- self.boxOpen = false
- GameM.commonData.updateBagCarData(self.index.toString(), type)
- if (GameM.commonData.isUseXiYouAddCoin) {
- //西游
- UiM.Instance.hallNode.getComponent(Main).addRunRole(type, this, true);
- //self.AddCoinSpawn(true);
- }
- self.composeAni.node.active = true;
- self.composeAni.setAnimation(0, 'animation', false);
- self.scheduleOnce(() => { self.composeAni.node.active = false }, 1.5);
- UiM.Instance.hallNode.getComponent(Main).CheckNormalGuide();
- }, 0.3)
- }, 1.2)
- this.boxShakeAni.setCurrentTime(0, 'boxShake')
- this.boxShakeAni.play()
- }
- // update (dt) {}
- /**判断武将是否未罢工*/
- CheckIsStrike() {
- if (this.role != null && GameM.commonData.IsUnlockStrike()) {
- return !this.role.isStriking;
- }
- return false;
- }
- /**点击角色 加速获取金币*/
- ClickRole() {
- //弃用
- return;
- //console.log("you click park " + this.node.name);
- if (this.role != null && GameM.commonData.IsUnlockStrike()) {
- if (GameM.commonData.clickStrikeNum < GameM.commonData.clickStrikeMaxNum) {
- if (this.role.AddSpeed()) {
- GameM.commonData.clickStrikeNum++;
- GameM.commonData.addDailyFinishTimesDataByType(5);
- } else {
- if (GameM.commonData.maxCarLevel >= GameM.commonData.clearCoolTimeLVOpen) {
- UiM.Instance.giftNode.active = true
- let gift = UiM.Instance.giftNode.getComponent(Gift)
- gift.init(MONEY_TYPE.clearCooltime, "0", null, false, 0, VIDEO_TYPE.clearCoolTime, -1, false)
- } else {
- EffectNode.instance.PlayTip('你太贪心了,都不让我休息会');
- }
- }
- } else {
- EffectNode.instance.PlayTip('你太贪心了,今天加速次数已用完');
- }
- }
- GameM.audioM.playEffect(AUDIO_TYPE.button);
- }
- RoleInit(isStriking: boolean, time = 0) {
- if (isStriking) {
- this.strikeNode.active = true;
- this.strikeTimerTxt.string = MyExtends.TimeToFormat(time);
- } else {
- this.strikeNode.active = false;
- }
- }
- ClearRole() {
- this.role = null;
- this.strikeNode.active = false;
- }
- /**金币获取*/
- AddCoinRunner(dt) {
- if (this.role != null) {
- //加速金币
- this.role.moneyTimer += dt;
- this.coinSlider.fillRange = this.role.moneyTimer / this.role.moneyTime;
- if (this.role.moneyTimer >= this.role.moneyTime) {
- this.role.moneyTimer = 0;
- //console.log("Index:" + this.type + " Money:" + this.role.moneyDelta + " Talent:" + MateData.Ins.Mate1Talent1);
- //唐僧天赋1
- let num = Sciencen_M.instance.addition(this.role.moneyDelta, Sciencen_M.instance.accMul(this.role.moneyDelta, (MateData.Ins.Mate1Talent1 * 0.01).toString()));
- GameM.commonData.updateGold(num)
- //GameM.commonData.updateGold(this.role.moneyDelta);
- //this.main.addCarGoldTip(this.role.moneyDelta);
- //this.PlayCoinAni(this.role.moneyDelta);
- if (this.isCanOperate)
- this.PlayCoinAni(num);
- //console.log("Add Coin "+this.role.moneyDelta);
- }
- //罢工计时
- if (this.role.isStriking) {
- this.role.strikeTimeNum -= dt;
- //if(this.role.strikeTimeNum<=0)this.role.strikeTimeNum=0;
- this.strikeTimerTxt.string = MyExtends.TimeToFormat(this.role.strikeTimeNum);
- if (this.role.strikeTimeNum <= 0) {
- console.log("-->Space " + this.index);
- this.role.RemoveStrike();
- this.strikeNode.active = false;
- }
- }
- }
- }
- PlayCoinAni(coinStr: string) {
- //this.coinEft.active = true;
- //this.coinEft.stopAllActions();
- this.coinEft.opacity = 255;
- this.coinEft.setPosition(0, 0);
- this.coinTxt.string = Sciencen_M.instance.format(coinStr);
- let copy = cc.instantiate(this.coinEft);
- copy.parent = this.coinEft.parent;
- copy.active = true;
- let a = cc.moveTo(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);
- copy.runAction(cc.spawn(a, b));
- }
- private isWealthing: boolean = false;
- private isCanAttack: boolean = false;
- private attackTimer: number = 0;
- private attackTime: number = 0.5;
- private swinEftNode: cc.Node = null;
- /**是否可以操作 false 座位被财神站住时 不可以被合成*/
- isCanOperate: boolean = true;
- CheckAttack() {
- if (WealthMng.Ins.isWealthing) {
- if (this.type > 0 && this.type < 10000) {
- if (this.isCanOperate) {
- this.attackTime = WealthData.Ins.GetMasterAttackTime(this.type);
- this.attackTimer = 0;
- if (!this.isWealthing) {
- this.isWealthing = true;
- this.isCanAttack = true;
- this.CheckAttackAni(true);
- WealthMng.Ins.Shoot(this.node, this.type);
- }
- } else {
- this.AttackEnd();
- }
- } else {
- this.AttackEnd();
- }
- } else {
- this.AttackEnd();
- }
- }
- /**检查车位可操作状态*/
- CheckSpaceState(active: boolean) {
- this.isCanOperate = active;
- if (this.type != 0) {
- if (active) {
- if (this.type < 10000) {
- cc.Tween.stopAllByTarget(this.car);
- cc.tween(this.car)
- .to(0.2, { scaleY: 1.1 })
- .call(() => this.boatWave())
- .start();
- //this.car.scale=1.1;
- //this.boatWave();
- }
- this.box.opacity = 255;
- this.car.opacity = 255;
- this.coinSlider.node.opacity = 255;
- this.xuhao.opacity = 255;
- this.labLv.node.opacity = 255;
- this.labNum.node.opacity = 255;
- this.strikeNode.opacity = 255;
- this.cheweihc.opacity = 255;
- } else {
- if (this.type < 10000) {
- cc.Tween.stopAllByTarget(this.car);
- cc.tween(this.car)
- .to(0.2, { scaleY: 0 })
- .call(() => this.car.opacity = 0)
- .start();
- }
- this.box.opacity = 0;
- //this.car.opacity = 0;
- this.coinSlider.node.opacity = 0;
- this.xuhao.opacity = 0;
- this.labLv.node.opacity = 0;
- this.labNum.node.opacity = 0;
- this.strikeNode.opacity = 0;
- this.cheweihc.opacity = 0;
- }
- }
- }
- CheckAttackAni(isAttack: boolean) {
- if (isAttack) {
- cc.tween(this.car)
- .to(0.07, { angle: 10 })
- .to(0.14, { angle: -10 })
- .to(0.07, { angle: 0 })
- .start();
- } else {
- //cc.Tween.stopAllByTarget(this.car);
- this.car.angle = 0;
- }
- }
- MasterEffect() {
- this.isCanAttack = false;
- if (this.type > 0 && this.type < 10000) {
- if (this.isCanOperate) {
- this.CheckAttackAni(false);
- this.CreateEffect();
- } else {
- if (this.swinEftNode != null) {
- this.swinEftNode.destroy();
- this.swinEftNode = null;
- }
- }
- }
- }
- async CreateEffect() {
- this.node.stopAllActions();
- let eftdmg = cc.instantiate(await Utils.loadResPromise("prefabs/item/MasterDmgEft"));
- eftdmg.parent = this.node;
- let a1 = cc.delayTime(0.5);
- let a2 = cc.callFunc(() => {
- eftdmg.destroy();
- if (this.swinEftNode != null) {
- this.swinEftNode.destroy();
- this.swinEftNode = null;
- }
- this.swinEftNode = cc.instantiate(cc.loader.getRes("prefabs/item/MasterSwimEft"));
- this.swinEftNode.parent = this.node;
- this.swinEftNode.setPosition(0, 40);
- });
- let a3 = cc.delayTime(WealthData.Ins.skill1Time);
- let a4 = cc.callFunc(() => {
- if (this.swinEftNode != null) {
- this.swinEftNode.destroy();
- this.swinEftNode = null;
- }
- this.isCanAttack = true;
- this.CheckAttack();
- });
- this.node.runAction(cc.sequence(a1, a2, a3, a4));
- //this.isCanAttack = false;
- //let eftdmg = cc.instantiate(cc.loader.getRes("prefabs/item/MasterDmgEft"));
- //eftdmg.parent = this.node;
- //await Time.WaitForSeconds(0.5);
- //eftdmg.destroy();
- //if (this.swinEftNode != null) {
- // this.swinEftNode.destroy();
- // this.swinEftNode = null;
- //}
- //
- //this.swinEftNode = cc.instantiate(cc.loader.getRes("prefabs/item/MasterSwimEft"));
- //this.swinEftNode.parent = this.node;
- //this.swinEftNode.setPosition(0, 40);
- //await Time.WaitForSeconds(WealthData.Ins.skill1Time);
- //if (this.swinEftNode != null) {
- // this.swinEftNode.destroy();
- // this.swinEftNode = null;
- //}
- //this.isCanAttack = true;
- //this.CheckAttack();
- }
- ClearSwimState() {
- if (this.swinEftNode != null) {
- this.swinEftNode.destroy();
- this.swinEftNode = null;
- }
- this.isCanAttack = true;
- }
- AttackRunner(dt) {
- if (this.isWealthing && this.isCanAttack) {
- this.attackTimer += dt;
- if (this.attackTimer >= this.attackTime) {
- this.attackTimer = 0;
- this.CheckAttackAni(true);
- WealthMng.Ins.Shoot(this.node, this.type);
- }
- }
- }
- AttackEnd() {
- this.isWealthing = false;
- this.isCanAttack = false;
- this.attackTimer = 0;
- this.CheckAttackAni(false);
- }
- }
|