| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- import { WealthData } from "../../datas/WealthData";
- import Main from "../../Main";
- import AdM from "../../manager/AdM";
- import GameM, { AUDIO_TYPE } from "../../manager/GameM";
- import UiM from "../../manager/UiM";
- import WealthMng, { WealthState } from "../../manager/WealthMng";
- import MyExtends from "../../tools/MyExtends";
- import Time from "../../tools/Time";
- import EffectNode from "../../ui/EffectNode";
- import UIMng, { PanelType } from "../../uiFrames/UIMng";
- import Sciencen_M from "../../utils/Sciencen_M";
- const { ccclass, property } = cc._decorator;
- export enum WealthFightState {
- normal, //正常
- shielding, //金钟罩使用中
- damaging, //受伤中
- skill1ing, //使用技能 眩晕技能中
- }
- @ccclass
- export default class Wealth extends cc.Component {
- @property(cc.Node)
- cloud: cc.Node = null;
- @property(sp.Skeleton)
- wealthSpine: sp.Skeleton = null;
- @property(sp.Skeleton)
- shield: sp.Skeleton = null;
- @property(cc.Node)
- sliderNode: cc.Node = null;
- @property(cc.Sprite)
- slider: cc.Sprite = null;
- @property(cc.Label)
- txt: cc.Label = null;
- @property(cc.Label)
- txtTimer: cc.Label = null;
- @property(cc.Node)
- bulletShield: cc.Node = null;
- //@property(cc.Collider)
- wealthCollider: cc.PhysicsCollider = null;
- private fightState: WealthFightState = WealthFightState.normal;
- private isShielding: boolean = false;
- private isCanAttack: boolean = false;
- private playerAttackTimer: number = 0;
- private isDamaging: boolean = false;
- private isFightEnd: boolean = true;
- onLoad() {
- //console.log("_______________");
- this.wealthCollider = this.node.getComponent(cc.PhysicsCollider);
- this.wealthCollider.enabled = false;
- this.shield.node.active = false;
- //console.log("Collider:", this.wealthCollider);
- }
- start() {
- //console.log("_______________2");
- }
- update(dt) {
- this.TimerShield(dt);
- this.TimerAttack(dt);
- this.TimerWealthDuration(dt);
- }
- TriggerWealth(pos: cc.Vec2, callback: Function) {
- this.isDamaging = false;
- this.playerAttackTimer = 0;
- this.fightState = WealthFightState.normal;
- this.sliderNode.active = false;
- //this.node.setPosition(610, 500);
- this.node.setPosition(MyExtends.convetOtherNodeSpaceAR(UiM.Instance.hallNode.getComponent(Main).wealthBtn, this.node.parent));
- this.cloud.parent = this.node;
- this.cloud.setSiblingIndex(0);
- this.cloud.setPosition(0, -172);
- this.cloud.active = true;
- //this.UnUseShield();
- this.node.scale = 0.4;
- this.node.active = true;
- this.wealthSpine.setAnimation(0, "bainian", true);
- GameM.audioM.playEffect(AUDIO_TYPE.wealthlaugh, false);
- //let posBtn = MyExtends.convetOtherNodeSpaceAR(UiM.Instance.hallNode.getComponent(Main).wealthBtn, this.node.parent);
- cc.tween(this.node)
- .to(1, { position: cc.v2(-540, 310), scale: 0.75 })
- .to(1, { position: cc.v2(222.454, 160), scale: 1 })
- .call(() => {
- this.cloud.parent = this.node.parent;
- this.cloud.setPosition(this.node.x, this.node.y + this.cloud.y);
- this.cloud.setSiblingIndex(this.node.getSiblingIndex());
- //this.node.getSiblingIndex
- cc.tween(this.cloud).to(0.5, { position: cc.v2(this.cloud.x + 500, this.cloud.y) }).call(() => { this.cloud.active = false; }).start();
- console.log("StartPos:(" + pos.x + "," + pos.y + ")");
- let a1 = cc.jumpTo(0.7, pos, 300, 1);
- let a2 = cc.callFunc(() => {
- this.isFightEnd = false;
- this.isCanAttack = true;
- callback();
- this.wealthSpine.setAnimation(0, "idle", true);
- MyExtends.ScreenShock(UiM.Instance.hallNode, 0.3);
- });
- this.node.runAction(cc.sequence(a1, a2));
- })
- .start();
- }
- /**切换为战斗状态*/
- SwitchFightingState(pos: cc.Vec2, callback: Function) {
- this.isDamaging = false;
- this.playerAttackTimer = 0;
- this.fightState = WealthFightState.normal;
- this.sliderNode.active = false;
- //this.node.setPosition(610, 500);
- this.node.setPosition(MyExtends.convetOtherNodeSpaceAR(UiM.Instance.hallNode.getComponent(Main).wealthBtn, this.node.parent));
- this.cloud.parent = this.node;
- this.cloud.setSiblingIndex(0);
- this.cloud.setPosition(0, -172);
- this.cloud.active = true;
- //this.UnUseShield();
- this.node.scale = 0.4;
- this.node.active = true;
- this.wealthSpine.setAnimation(0, "bainian", true);
- GameM.audioM.playEffect(AUDIO_TYPE.wealthlaugh, false);
- //let posBtn = MyExtends.convetOtherNodeSpaceAR(UiM.Instance.hallNode.getComponent(Main).wealthBtn, this.node.parent);
- cc.tween(this.node)
- .to(1, { position: cc.v2(-540, 310), scale: 0.75 })
- .to(1, { position: cc.v2(222.454, 160), scale: 1 })
- .call(() => {
- this.cloud.parent = this.node.parent;
- this.cloud.setPosition(this.node.x, this.node.y + this.cloud.y);
- this.cloud.setSiblingIndex(this.node.getSiblingIndex());
- //this.node.getSiblingIndex
- cc.tween(this.cloud).to(0.5, { position: cc.v2(this.cloud.x + 500, this.cloud.y) }).call(() => { this.cloud.active = false; }).start();
- //console.log("StartPos:(" + pos.x + "," + pos.y + ")");
- let a1 = cc.jumpTo(0.7, pos, 300, 1);
- let a2 = cc.callFunc(() => {
- this.isFightEnd = false;
- this.isCanAttack = true;
- callback();
- this.wealthSpine.setAnimation(0, "idle", true);
- //console.log("=++++++++++:" + WealthData.Ins.shieldTimer);
- if (WealthData.Ins.shieldTimer > 0) {
- this.fightState = WealthFightState.shielding;
- this.wealthCollider.enabled = true;
- this.wealthCollider.enabled = false;
- this.wealthCollider.enabled = true;
- this.shield.node.active = true;
- this.shield.setAnimation(0, "animation", true);
- //WealthData.Ins.shieldTimer = WealthData.Ins.shieldTime;
- this.isShielding = true;
- //let a: cc.RigidBody = this.getComponent(cc.RigidBody);
- //a.allowSleep = false;
- this.wealthSpine.setAnimation(0, "jinzhongzhao", true);
- } else {
- this.wealthSpine.setAnimation(0, "idle", true);
- }
- MyExtends.ScreenShock(UiM.Instance.hallNode, 0.3);
- });
- this.node.runAction(cc.sequence(a1, a2));
- })
- .start();
- /*
- this.isDamaging = false;
- this.playerAttackTimer = 0;
- this.fightState = WealthFightState.normal;
- this.node.setPosition(pos);
- this.node.active = true;
- this.isFightEnd = false;
- this.isCanAttack = true;
- callback();
- if (WealthData.Ins.shieldTimer > 0) {
- console.log("----------0");
- this.fightState = WealthFightState.shielding;
- this.wealthCollider.enabled = true;
- this.wealthCollider.enabled = false;
- this.wealthCollider.enabled = true;
- this.shield.active = true;
- //WealthData.Ins.shieldTimer = WealthData.Ins.shieldTime;
- this.isShielding = true;
- //let a: cc.RigidBody = this.getComponent(cc.RigidBody);
- //a.allowSleep = false;
- this.wealthSpine.setAnimation(0, "jinzhongzhao", true);
- } else {
- this.wealthSpine.setAnimation(0, "idle", true);
- }
- */
- }
- UpdateTxt(curblood: string, totalblood: string) {
- if (!this.sliderNode.active) this.sliderNode.active = true;
- //console.log("AAA:" + curblood + " BBB:" + totalblood);
- this.slider.fillRange = 1 - Number(Sciencen_M.instance.accDiv(curblood, totalblood));
- //this.txt.string = Sciencen_M.instance.format(Sciencen_M.instance.subtraction(totalblood, curblood)) + "/" + Sciencen_M.instance.format(totalblood);
- //this.txt.string = Math.floor(((1 - Number(Sciencen_M.instance.accDiv(curblood, totalblood))) * 100)) + "%";
- this.txt.string = ((1 - Number(Sciencen_M.instance.accDiv(curblood, totalblood))) * 100).toFixed(2) + "%";
- }
- async GetDamage() {
- if (!this.isDamaging) {
- if (this.fightState != WealthFightState.skill1ing) {
- this.isDamaging = true;
- this.fightState = WealthFightState.damaging;
- this.wealthSpine.setAnimation(0, "shouji", false);
- await Time.WaitForSeconds(this.wealthSpine.findAnimation("shouji").duration);
- this.isDamaging = false;
- this.fightState = WealthFightState.normal;
- if (!this.isFightEnd) {
- this.wealthSpine.setAnimation(0, "idle", true);
- }
- }
- }
- }
- /**使用眩晕技能*/
- async UseSkill1(targetpos: cc.Vec2, callback: Function) {
- if (this.isFightEnd) return;
- this.fightState = WealthFightState.skill1ing;
- this.wealthSpine.setAnimation(0, "gongjiyubei", false);
- await Time.WaitForSeconds(this.wealthSpine.findAnimation("gongjiyubei").duration);
- this.fightState = WealthFightState.normal;
- this.wealthSpine.setAnimation(0, "idle", true);
- //let a1 = cc.jumpTo(0.3, this.node.getPosition(), 80, 1);
- let a1 = cc.jumpTo(0.3, targetpos, 80, 1);
- let a2 = cc.callFunc(callback);
- this.node.runAction(cc.sequence(a1, a2));
- }
- UseShield() {
- if (!this.isShielding) {
- this.fightState = WealthFightState.shielding;
- this.wealthCollider.enabled = true;
- this.wealthCollider.enabled = false;
- this.wealthCollider.enabled = true;
- //this.wealthCollider.enabled = false;
- this.shield.node.active = true;
- this.shield.setAnimation(0, "animation", true);
- WealthData.Ins.shieldTimer = WealthData.Ins.shieldTime;
- this.isShielding = true;
- //let a: cc.RigidBody = this.getComponent(cc.RigidBody);
- //a.allowSleep = false;
- this.wealthSpine.setAnimation(0, "jinzhongzhao", true);
- AdM.onSendEvent('caishen_skill_open', '财神金钟罩技能触发', 'caishen');
- WealthData.Ins.UpdateWealthState();
- }
- }
- async UnUseShield() {
- this.isShielding = false;
- WealthData.Ins.shieldTimer = 0;
- //console.log("Collider2:", this.node.getComponent(cc.Collider));
- this.shield.setAnimation(0, "animation2", false);
- await Time.WaitForSeconds(this.shield.findAnimation("animation2").duration);
- this.wealthCollider.enabled = false;
- this.shield.node.active = false;
- //let a: cc.RigidBody = this.getComponent(cc.RigidBody);
- //a.allowSleep = true;
- this.wealthSpine.setAnimation(0, "idle", true);
- WealthData.Ins.UpdateWealthState();
- }
- /**财神被击败*/
- WealthEnd(isSuccess: boolean) {
- this.isFightEnd = true;
- this.isShielding = false;
- WealthData.Ins.shieldTimer = WealthData.Ins.shieldTime;
- this.fightState = WealthFightState.normal;
- this.shield.node.active = false;
- this.sliderNode.active = false;
- if (!isSuccess) {
- this.cloud.parent = this.node;
- this.cloud.setSiblingIndex(0);
- this.cloud.setPosition(530, -172);
- //this.cloud.setPosition(0, -172);
- this.cloud.active = true;
- this.wealthSpine.setAnimation(0, "bainian", true);
- cc.tween(this.cloud)
- .to(0.5, { position: cc.v2(0, this.cloud.y) })
- .call(() => {
- cc.tween(this.node)
- .to(1, { position: cc.v2(-540, 100), scale: 0.85 })
- .call(() => {
- this.node.setPosition(-540, 520);
- let pos = MyExtends.convetOtherNodeSpaceAR(UiM.Instance.hallNode.getComponent(Main).wealthBtn, this.node.parent);
- cc.tween(this.node)
- .to(1, { position: pos, scale: 0.4 })
- .call(() => {
- this.node.active = false;
- //let wealthbtn = UiM.Instance.hallNode.getComponent(Main).wealthBtn;
- //wealthbtn.active = true;
- //wealthbtn.runAction(cc.fadeIn(0.3));
- })
- .start();
- })
- .start();
- })
- .start();
- }
- else {
- let pos = WealthMng.Ins.GetUiWealthPos();
- console.log("Pos::" + "(" + pos.x + "," + pos.y + ")");
- let a1 = cc.spawn(cc.jumpTo(1, pos, 120, 1), cc.scaleTo(1, 1.3));
- let a2 = cc.callFunc(() => {
- this.node.active = false;
- let wealthbtn = UiM.Instance.hallNode.getComponent(Main).wealthBtn;
- wealthbtn.active = true;
- wealthbtn.runAction(cc.fadeIn(0.3));
- if (UIMng.Ins.IsExistPanel(PanelType.WealthPanel)) {
- UIMng.Ins.GetPanel(PanelType.WealthPanel).OnExit();
- }
- console.log("-------4");
- UIMng.Ins.AsyncGetPanel(PanelType.WealthPanel, (panel) => {
- panel.OnEnter(4);
- });
- //UIMng.Ins.GetPanel(PanelType.WealthPanel).OnEnter(4);
- });
- this.node.runAction(cc.sequence(a1, a2));
- //cc.tween(this.node)
- // .to(1, { position: pos, scale: 1.3 })
- // .call(() => {
- // this.node.active = false;
- // let wealthbtn = UiM.Instance.hallNode.getComponent(Main).wealthBtn;
- // wealthbtn.active = true;
- // wealthbtn.runAction(cc.fadeIn(0.3));
- // UIMng.Ins.GetPanel(PanelType.WealthPanel).OnEnter(4);
- // })
- // .start();
- }
- }
- FightEnd() {
- //this.UnUseShield();
- }
- TimerShield(dt) {
- if (this.isShielding) {
- if (WealthMng.Ins.wealthState == WealthState.Fighting) {
- WealthData.Ins.shieldTimer -= dt;
- if (WealthData.Ins.shieldTimer <= 0) {
- this.UnUseShield();
- }
- } else {
- this.UnUseShield();
- }
- //if(WealthMng.Instance.wealthState==WealthState.)
- }
- }
- TimerAttack(dt) {
- if (!this.isFightEnd) {
- if (WealthMng.Ins.wealthState == WealthState.Fighting) {
- if (!this.isCanAttack) {
- this.playerAttackTimer += dt;
- if (this.playerAttackTimer > 0.1) {
- this.isCanAttack = true;
- }
- }
- }
- //if(WealthMng.Instance.wealthState==WealthState.)
- }
- }
- TimerWealthDuration(dt) {
- if (this.sliderNode.active) {
- this.txtTimer.string = MyExtends.TimeToFormat(WealthData.Ins.lifeTimer);
- }
- }
- async CreateBulletEft(info: cc.WorldManifold) {
- let eft = cc.instantiate(this.bulletShield);
- eft.active = true;
- eft.parent = this.node;
- eft.angle = cc.v2(0, 1).signAngle(info.normal) * 180 / Math.PI - 90;
- let pos = MyExtends.worldConvertLocalPointAR2D(this.node, info.points[0]);
- //console.log("Pos:",pos);
- eft.setPosition(pos);
- await Time.WaitForSeconds(0.5);
- eft.destroy();
- }
- //onCollisionEnter(other, self) {
- // //console.log("collider self:", self);
- // other.node.destroy();
- //}
- onBeginContact(contact, selfCollider, otherCollider) {
- //console.log("contact self:", contact.getWorldManifold());
- if (this.wealthCollider.enabled) {
- this.CreateBulletEft(contact.getWorldManifold());
- otherCollider.node.destroy();
- }
- }
- Click_WealthBtn() {
- if (!this.isFightEnd) {
- if (!this.isShielding) {
- if (this.isCanAttack) {
- this.isCanAttack = false;
- //console.log("click the wealth");
- WealthMng.Ins.GetDamage(2);
- if (WealthData.Ins.CheckShield()) {
- this.UseShield();
- } else {
- WealthMng.Ins.CheckUseSkill1();
- }
- }
- } else {
- console.log("-------3");
- GameM.audioM.playEffect(AUDIO_TYPE.wealthshield, false);
- UIMng.Ins.AsyncGetPanel(PanelType.WealthPanel, (panel) => {
- panel.OnEnter(3);
- });
- //UIMng.Ins.GetPanel(PanelType.WealthPanel).OnEnter(3);
- }
- AdM.onSendEvent('caishen_dianji', '财神点击次数');
- }
- }
- Click_WealthBowl() {
- console.log("-------7");
- UIMng.Ins.AsyncGetPanel(PanelType.WealthPanel, (panel) => {
- panel.OnEnter(7);
- });
- //UIMng.Ins.GetPanel(PanelType.WealthPanel).OnEnter(7);
- }
- }
|