| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558 |
- import AdM from "../manager/AdM";
- import GameM from "../manager/GameM";
- import HttpM from "../manager/HttpM";
- import { thirdVideoTS } from "../manager/topon/AnyThinkAdsMgr/thirdVideoTS";
- import WealthMng, { WealthState } from "../manager/WealthMng";
- import UIMng, { PanelType } from "../uiFrames/UIMng";
- import Random from "../utils/Random";
- import Sciencen_M from "../utils/Sciencen_M";
- import { HTTP_TYPE } from "./CommonData";
- import { MateData } from "./MateData";
- export class WealthData {
- //财神降临数据管理类
- private static _ins: WealthData = null;
- public static get Ins(): WealthData {
- if (this._ins == null) {
- this._ins = new WealthData();
- }
- return this._ins;
- }
- wealthMng: WealthMng = null;
- isUnlock: boolean = false;
- wealthInfo: any = null;
- /**财神配置文件*/
- wealthCfg: any = null;
- /**已挑战次数*/
- challengedTimes: number = 0;
- /**能挑战的总次数*/
- challengeTimes: number = 2;
- private isFirstChallenge: boolean = false;
- blood: string = "200";
- bloodValue: string = "200";
- giftValue: string = "150";
- /**财神挑战周期*/
- lifeDuration: number = 100;
- /**财神降临周期计时器 初始化 后台获取*/
- lifeTimer: number = 0;
- /**冷却时间*/
- coolingTime: number = 20;
- /**是否在冷却中*/
- isCooling: boolean = false;
- /**冷却时间计时器 初始化 后台获取*/
- coolingTimer: number = 0;
- /**金钟罩时间*/
- shieldTime: number = 10;
- /**金钟罩计时器 初始化 后台获取*/
- shieldTimer: number = 0;
- shieldIndex: number = 0;
- /**金钟罩触发的血量值数组*/
- shieldBloods: number[] = [150, 130, 100, 50, 10];
- /**眩晕技能 技能1 触发概率*/
- skill1Rate: number = 5;
- /**眩晕时间*/
- skill1Time: number = 30;
- /**眩晕时间计时器*/
- skill1Timer: number = 0;
- /**血量系数 金币系数*/
- paramBlood: number = 3.5;
- /**结算礼包金币系数*/
- paramGift: number = 2;
- /**武将攻击系数 财神掉落的金币*/
- paramMasterAttack: number = 0.0005;
- /**玩家攻击系数数组*/
- paramPlayAttackECPMAry: string[] = null;
- /**金钟罩触发系数 血量百分比 数组*/
- paramBloodShieldECPMAry: string[] = null;
- norEcpm: number = 100;
- /**武将攻击间隔系数*/
- paramAttackTime: number = 1;
- /**平均ecpm*/
- paramEcpm: number = 0;
- /**ecpm请求是否完毕*/
- private isReqEcpmEnd: boolean = false;
- /**财神开始战斗请求是否完毕*/
- private isReqFightEnd: boolean = false;
- /**是否开始战斗 完全进入战斗*/
- isWealthing: boolean = false;
- /**是否触发战斗*/
- isTriggerWealth: boolean = false;
- //1.冷却 2.可触发 3.已触发(战斗) 4.云游
- //wealthGodStatus
- //operationType 1.可触发 2.战斗 3.战斗结束
- Destroy() {
- WealthData._ins = null;
- if (this.wealthMng != null) {
- this.wealthMng.Destroy();
- }
- }
- /**财神战斗数据初始化*/
- WealthFightInit() {
- this.shieldIndex = 0;
- this.isTriggerWealth = true;
- }
- /**检查是否满足金钟罩技能触发条件
- */
- CheckShield() {
- let param = 0;
- for (let i = 0; i < this.paramBloodShieldECPMAry.length; i++) {
- if (Number(Sciencen_M.instance.accDiv(this.blood, this.bloodValue)) > Number(this.paramBloodShieldECPMAry[i].split(',')[0])) {
- param = Number(this.paramBloodShieldECPMAry[i].split(',')[1]);
- break;
- }
- }
- //console.log("Shield Rate P:" + param);
- if (this.paramEcpm <= this.norEcpm) {
- param *= (1 + Math.min(0.8, (this.norEcpm - this.paramEcpm) / 40 * 0.42));
- } else {
- param *= (1 - Math.min(0.15, (this.paramEcpm - this.norEcpm) / 80 * 0.06));
- }
- //console.log("Shield Rate: " + param + " a:" + this.paramEcpm + " b:" + this.norEcpm);
- //param = 0;
- return Random.Range(0, 100, false) < param;
- //console.log("Index: "+this.shieldIndex+" cur: "+curblood+" Target: "+this.shieldBloods[this.shieldIndex]);
- //if (this.shieldIndex < this.shieldBloods.length
- // && curblood <= this.shieldBloods[this.shieldIndex]) {
- // this.shieldIndex++;
- // //console.log("-------------1");
- // return true;
- //}
- //return false;
- }
- /**检测是否触发眩晕技能*/
- CheckTriggerSkill1() {
- let p = Random.Range(0, 100, false);
- //console.log("--CheckSkillRandom:" + p + " TargetRate:" + this.skill1Rate);
- if (p < this.skill1Rate) {
- return true;
- }
- return false;
- }
- /**触发*/
- CheckTrigger() {
- //财神降临
- //console.log("--CheckTriggerWealth: IsUnlock:" + this.isUnlock + " ClgedTimes:" + this.challengedTimes + " ClgTimes: " + this.challengeTimes);
- //console.log("--CheckTriggerWealth: Info:", this.wealthInfo);
- if (this.wealthInfo != null && this.wealthInfo.wealthGodStatus != 3 && Random.Range(0, 100, false) < this.wealthCfg.TriggerRate) {
- WealthMng.Ins.CheckTriggerWealth();
- }
- }
- /**检查是否可以触发财神降临*/
- CheckTriggerWealth(isunlocktrigger: boolean = false, callback: Function) {
- if (this.isUnlock && this.challengedTimes < this.challengeTimes) {
- if (!this.isCooling) {
- console.log("trigger");
- this.isReqEcpmEnd = this.isReqFightEnd = this.isWealthing = false;
- this.GoldInit();
- //获取ecpm
- HttpM.Instance.SendData(HTTP_TYPE.adShowConfig,
- {}, (res) => {
- //console.log("redMoneyInGiftBag:", res);
- if (res && res.data) {
- this.paramEcpm = res.data.average_ecpm;
- this.isReqEcpmEnd = true;
- if (this.isReqEcpmEnd && this.isReqFightEnd) {
- this.TriggerWealth(callback);
- }
- }
- }, null, () => {
- this.isReqEcpmEnd = true;
- })
- if (isunlocktrigger) {
- this.isReqFightEnd = true;
- if (this.isReqEcpmEnd && this.isReqFightEnd) {
- this.TriggerWealth(callback);
- }
- } else {
- //operationType 1.可触发 2.战斗 3.战斗结束
- HttpM.Instance.SendData(HTTP_TYPE.wealthUpdateStatus, {
- consumeGold: "0",
- gold: this.bloodValue,
- giftGold: this.giftValue,
- operationType: 2
- }, (res) => {
- console.log("-->WealthUpdateStatus fight:", res);
- if (res.data != null) {
- this.wealthInfo = res.data.WealthGodInfo;
- this.lifeTimer = res.data.WealthGodInfo.endLifeSurplusTime;
- this.isFirstChallenge = res.data.WealthGodInfo.isFistChallenge == 1;
- this.isReqFightEnd = true;
- if (this.isReqEcpmEnd && this.isReqFightEnd) {
- this.TriggerWealth(callback);
- }
- }
- });
- }
- }
- }
- }
- /**触发战斗*/
- TriggerWealth(callback: Function) {
- if (!this.isWealthing) {
- this.isWealthing = true;
- this.challengedTimes++;
- callback();
- AdM.onSendEvent('caishen_fight', '财神触发战斗', 'caishen');
- GameM.commonData.addDailyFinishTimesDataByType(8)
- }
- }
- /**财神降临开始冷却计时*/
- WealthCooling() {
- this.lifeTimer = 0;
- if (this.challengedTimes >= this.challengeTimes) {
- this.coolingTimer = 0;
- this.isCooling = false;
- this.wealthMng.isCooling = false;
- } else {
- this.coolingTimer = this.coolingTime;
- this.isCooling = true;
- this.wealthMng.isCooling = true;
- }
- }
- /**财神准备就位*/
- WealthReady() {
- this.wealthMng.isCooling = false;
- this.isCooling = false;
- this.coolingTimer = 0;
- this.wealthMng.wealthState = WealthState.ReadyFight;
- //operationType 1.可触发 2.战斗 3.战斗结束
- HttpM.Instance.SendData(HTTP_TYPE.wealthUpdateStatus, {
- consumeGold: "0",
- gold: this.bloodValue,
- giftGold: this.giftValue,
- operationType: 1
- }, (res) => {
- if (res.data != null) {
- this.wealthInfo = res.data.WealthGodInfo;
- console.log("-->WealthUpdateStatus ready:", res);
- }
- });
- }
- /**直接切换为战斗状态 离开游戏时 还处于财神降临状态*/
- SwitchFightingState() {
- //this.coolingTimer = 20;
- //this.lifeTimer = 20;
- //this.shieldTimer = 10;
- this.isWealthing = true;
- this.isCooling = this.coolingTimer > 0;
- console.log("Cooling1:" + this.isCooling);
- }
- Click_MainWealthBtn() {
- //console.log("+++++------");
- if (this.wealthMng.wealthState != WealthState.Fighting) {
- if (this.challengedTimes < this.challengeTimes) {
- console.log("Cooling:" + this.isCooling);
- if (!this.isCooling) {
- console.log("-------1");
- UIMng.Ins.AsyncGetPanel(PanelType.WealthPanel, (panel) => {
- panel.OnEnter(1);
- });
- //UIMng.Ins.GetPanel(PanelType.WealthPanel).OnEnter(1);
- } else {
- console.log("-------2");
- UIMng.Ins.AsyncGetPanel(PanelType.WealthPanel, (panel) => {
- panel.OnEnter(2);
- });
- //UIMng.Ins.GetPanel(PanelType.WealthPanel).OnEnter(2);
- }
- } else {
- console.log("-------5");
- UIMng.Ins.AsyncGetPanel(PanelType.WealthPanel, (panel) => {
- panel.OnEnter(5);
- });
- //UIMng.Ins.GetPanel(PanelType.WealthPanel).OnEnter(5);
- }
- } else {
- console.log("-------6");
- UIMng.Ins.AsyncGetPanel(PanelType.WealthPanel, (panel) => {
- panel.OnEnter(6);
- });
- //UIMng.Ins.GetPanel(PanelType.WealthPanel).OnEnter(6);
- }
- }
- /**解锁财神降临*/
- CheckUnLockWealth() {
- if (GameM.commonData.maxCarLevel >= GameM.commonData.unlockWealthLevel) {
- this.GoldInit();
- HttpM.Instance.SendData(HTTP_TYPE.wealthGodOpen, {
- gold: this.bloodValue,
- giftGold: this.giftValue
- }, (res) => {
- //console.log("WealthOpenRes------------:", res);
- if (res.data != null) {
- console.log("WealthOpen:", res.data);
- this.isUnlock = true;
- this.wealthInfo = res.data.WealthGodInfo;
- this.lifeTimer = res.data.WealthGodInfo.endLifeSurplusTime;
- this.shieldTimer = res.data.WealthGodInfo.defenseSurplusSecond;
- this.coolingTimer = res.data.WealthGodInfo.coolingSurplusSecond;
- this.isFirstChallenge = res.data.WealthGodInfo.isFistChallenge == 1;
- console.log("解锁财神:" + this.bloodValue);
- console.log("财神参数:武将攻击:" + this.GetMasterDamageCoin(1));
- this.wealthMng.CheckTriggerWealth(true);
- }
- }, null, null, null, false);
- }
- }
- /**财神战斗结束
- * @param callback 回调
- */
- WealthFightEnd(callback: Function = null) {
- //this.wealthState = WealthState.ReadyFight;
- //
- //if (this.challengedTimes < this.challengeTimes) {
- // this.coolingTimer = this.coolingTime;
- // this.isCooling = true;
- // this.wealthMng.isCooling = true;
- //}
- this.isReqEcpmEnd = this.isReqFightEnd = this.isWealthing = this.isTriggerWealth = false;
- //operationType 1.可触发 2.战斗 3.战斗结束
- HttpM.Instance.SendData(HTTP_TYPE.wealthUpdateStatus, {
- consumeGold: Sciencen_M.instance.subtraction(this.bloodValue, this.blood),
- gold: 0,
- giftGold: this.giftValue,
- operationType: 3
- }, (res) => {
- console.log("-->WealthUpdateStatus fight end:", res);
- if (res.data != null) {
- this.wealthInfo = res.data.WealthGodInfo;
- //let dnow = new Date();
- //console.log("CoolingTimer FightEnd:" + (this.wealthInfo.coolingSurplusSecond - dnow.getTime()));
- //this.coolingTimer = (this.wealthInfo.coolingSurplusSecond - dnow.getTime()) * 0.001;
- if (callback)
- callback();
- }
- });
- }
- WealthInit(wealthinfo, ecpm) {
- if (this.wealthCfg != null) {
- GameM.commonData.unlockWealthLevel = this.wealthCfg.GodOpenGrade;
- this.challengeTimes = this.wealthCfg.triggerCount;
- this.lifeDuration = this.wealthCfg.triggerTime;
- this.coolingTime = this.wealthCfg.coolingTime;
- this.shieldTime = this.wealthCfg.CoverskillTime;
- this.skill1Time = this.wealthCfg.VertigoskillTime;
- this.skill1Rate = this.wealthCfg.Vertigoskillprobability;
- this.paramBlood = this.wealthCfg.Beatcoincoefficient;
- this.paramGift = this.wealthCfg.Settlementcoincoefficient;
- //怪物攻击系数 攻击伤害 掉落的金币
- this.paramMasterAttack = this.wealthCfg.Monsters_attack_coefficient
- //玩家攻击系数
- this.paramPlayAttackECPMAry = this.wealthCfg.Player_attack_coefficient_ecpm.split(";");
- this.paramBloodShieldECPMAry = this.wealthCfg.Blood_Coverskill_probability.split(";");
- this.norEcpm = this.wealthCfg.NorECPM;
- this.paramAttackTime = this.wealthCfg.AttackTimeParam;
- }
- //1.冷却 2.可触发 3.已触发(战斗) 4.云游
- //wealthGodStatus
- if (wealthinfo != null) {
- this.wealthInfo = wealthinfo;
- this.isUnlock = true;
- this.lifeTimer = this.wealthInfo.endLifeSurplusTime;
- this.shieldTimer = this.wealthInfo.defenseSurplusSecond;
- this.isFirstChallenge = this.wealthInfo.isFistChallenge == 1;
- let dnow = new Date();
- //let dserver=new Date(this.wealthInfo.coolingSurplusSecond);
- //console.log("CoolingTimer:" + (this.wealthInfo.coolingSurplusSecond - dnow.getTime() * 0.001));
- this.coolingTimer = (this.wealthInfo.coolingSurplusSecond - dnow.getTime() * 0.001);
- this.isCooling = this.coolingTimer > 0;
- this.blood = Sciencen_M.instance.subtraction(this.wealthInfo.gold, this.wealthInfo.consumeGold);// this.wealthInfo.consumeGold "1000000";// this.wealthInfo.consumeGold;
- this.bloodValue = this.wealthInfo.gold;// this.wealthInfo.gold;
- this.giftValue = this.wealthInfo.giftGold;
- let status = this.wealthInfo.wealthGodStatus;
- this.challengedTimes = this.challengeTimes - this.wealthInfo.triggerSurplusCount;
- }
- this.paramEcpm = ecpm;
- console.log("--->WealthDataInit:", wealthinfo, ecpm);
- //console.log("-----------PlayCfg:", this.paramPlayAttackECPMAry);
- }
- WealthStatusInit() {
- this.isCooling = this.coolingTimer > 0;
- this.wealthMng.isCooling = this.coolingTimer > 0;
- }
- /**更新财神降临 时间*/
- UpdateWealthState() {
- //console.log("WealthData2:",this.wealthMng);
- if (this.wealthMng.isWealthing || this.coolingTimer > 0) {
- //console.log("_______1:"+this.shieldTimer);
- HttpM.Instance.SendData(HTTP_TYPE.wealthUpdateTime, {
- //coolingSurplusSecond: this.coolingTimer,
- defenseSurplusSecond: this.shieldTimer,
- endLifeSurplusTime: this.lifeTimer
- }, (res) => {
- //console.log("WealthTimeStateRes------------:", res);
- if (res.data != null) {
- //console.log("_____WealthTimeStateRes:", res.data);
- }
- });
- if (this.wealthMng.isWealthing) {
- HttpM.Instance.SendData(HTTP_TYPE.wealthUpdateGold, {
- consumeGold: Sciencen_M.instance.subtraction(this.bloodValue, this.blood),
- gold: this.bloodValue
- }, (res) => {
- //console.log("wealthUpdateGold------------:", res);
- if (res.data != null) {
- //console.log("wealthUpdateGold:", res.data);
- }
- });
- }
- }
- }
- GetBloodGold(isDynamicGet: boolean = true) {
- if (isDynamicGet) {
- let gold = GameM.commonData.buyNumCfg[(GameM.commonData.buyTimeTotal + 1).toString()].gold;
- //唐僧天赋3
- gold = Sciencen_M.instance.addition(gold, Sciencen_M.instance.accMul(gold, (MateData.Ins.Mate1Talent3 * 0.01).toString()));
- gold = Sciencen_M.instance.accMul(gold, this.paramBlood.toString());//Sciencen_M.instance.addition(gold, Sciencen_M.instance.accMul(gold, this.paramBlood.toString()));
- //console.log("--------Gold1:" + gold);
- return Sciencen_M.instance.format(gold);
- } else {
- return Sciencen_M.instance.format(this.bloodValue);
- }
- }
- GetGiftGold(isDynamicGet: boolean = true) {
- if (isDynamicGet) {
- let gold = GameM.commonData.buyNumCfg[(GameM.commonData.buyTimeTotal + 1).toString()].gold;
- //唐僧天赋3
- gold = Sciencen_M.instance.addition(gold, Sciencen_M.instance.accMul(gold, (MateData.Ins.Mate1Talent3 * 0.01).toString()));
- gold = Sciencen_M.instance.accMul(gold, this.paramGift.toString());//Sciencen_M.instance.addition(gold, Sciencen_M.instance.accMul(gold, this.paramGift.toString()));
- //console.log("--------Gold2:" + gold);
- return Sciencen_M.instance.format(gold);
- }
- else {
- return Sciencen_M.instance.format(this.giftValue);
- }
- }
- /**金币初始化*/
- GoldInit() {
- let gold = GameM.commonData.buyNumCfg[(GameM.commonData.buyTimeTotal + 1).toString()].gold;
- let giftgold = gold;
- //唐僧天赋3
- gold = Sciencen_M.instance.addition(gold, Sciencen_M.instance.accMul(gold, (MateData.Ins.Mate1Talent3 * 0.01).toString()));
- gold = Sciencen_M.instance.accMul(gold, this.paramBlood.toString());// Sciencen_M.instance.addition(gold, Sciencen_M.instance.accMul(gold, this.paramBlood.toString()));
- //唐僧天赋3
- giftgold = Sciencen_M.instance.addition(giftgold, Sciencen_M.instance.accMul(giftgold, (MateData.Ins.Mate1Talent3 * 0.01).toString()));
- giftgold = Sciencen_M.instance.accMul(giftgold, this.paramGift.toString());//Sciencen_M.instance.addition(giftgold, Sciencen_M.instance.accMul(giftgold, this.paramGift.toString()));
- this.bloodValue = this.blood = gold;
- this.giftValue = giftgold;
- }
- /**获取武将攻击伤害 掉落的金币*/
- GetMasterDamageCoin(masterlv: number) {
- let gold = Sciencen_M.instance.accDiv(this.bloodValue, this.paramBlood.toString());
- //唐僧天赋3
- gold = Sciencen_M.instance.addition(gold, Sciencen_M.instance.accMul(gold, (MateData.Ins.Mate1Talent3 * 0.01).toString()));
- let p = this.paramMasterAttack / Number(GameM.commonData.carCfg[masterlv.toString()].cost_time) * this.paramAttackTime * GameM.commonData.carCfg[masterlv.toString()].attack_rate;
- //gold = Sciencen_M.instance.accMul(gold, this.paramMasterAttack.toString());
- //p=0;
- gold = Sciencen_M.instance.accMul(gold, p.toString());
- //console.log("--MasterAttack:"+gold);
- return gold;
- }
- /**获取玩家攻击伤害 掉落的金币*/
- GetPlayDamageCoin() {
- let gold = Sciencen_M.instance.accDiv(this.bloodValue, this.paramBlood.toString());
- //唐僧天赋3
- gold = Sciencen_M.instance.addition(gold, Sciencen_M.instance.accMul(gold, (MateData.Ins.Mate1Talent3 * 0.01).toString()));
- //console.log("-----------PlayCfg:", this.paramPlayAttackECPMAry);
- let param = 1;
- for (let i = 0; i < this.paramPlayAttackECPMAry.length; i++) {
- if (this.paramEcpm <= Number(this.paramPlayAttackECPMAry[i].split(',')[0])) {
- param = Number(this.paramPlayAttackECPMAry[i].split(',')[1]);
- break;
- }
- }
- if (this.isFirstChallenge) {
- //param *= this.wealthCfg.FirstChallengeAtkParam;
- gold = Sciencen_M.instance.accMul(gold, this.wealthCfg.FirstChallengeAtkParam.toString());
- } else {
- gold = Sciencen_M.instance.accMul(gold, (param * this.paramMasterAttack).toString());
- }
- //param *= 40; //test
- //console.log("---------PlayParam:" + param + " attack:" + this.paramMasterAttack);
- //gold = Sciencen_M.instance.accMul(gold, (param * this.paramMasterAttack).toString());
- //console.log("---------PlayParam:" + param + " attack:" + this.paramMasterAttack + " gold:" + gold);
- //console.log("--PlayerAttack:"+gold);
- return gold;
- }
- /**获取武将攻击时间
- * @param type 武将类型id
- */
- GetMasterAttackTime(type: number) {
- return GameM.commonData.carCfg[type.toString()].attack_rate;
- }
- }
|