| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- import { MateData } from "../../datas/MateData";
- import GameM from "../../manager/GameM";
- import { thirdVideoTS } from "../../manager/topon/AnyThinkAdsMgr/thirdVideoTS";
- import CarSpace from "../../prefabs/CarSpace";
- import { PlayerPrefs } from "../../tools/MyExtends";
- import Random from "../../utils/Random";
- export class Role {
- //角色
- /**产生一次金币所花时间*/
- moneyTime: number = 0;
- /**产生一次金币计时器*/
- moneyTimer: number = 0;
- /**对应时间内产生金币数*/
- moneyDelta: string = '';
- /**罢工概率*/
- strikeRate: number = 0;
- /**是否已罢工*/
- isStriking: boolean = false;
- /**车位index*/
- index: number = 0;
- /**开始罢工的时间点*/
- strikeTime: number = 0;
- /**罢工剩余时间 秒*/
- strikeTimeNum: number = 0;
- /**罢工时间 秒*/
- strikeTargetTime: number = 180;
- carSpace: CarSpace = null
- /**
- * 角色初始化
- * @param type 角色等级
- * @param startRan 开始时间是否随机
- * @param carspace 车位
- */
- Init(type, startRan = false, carspace) {
- this.carSpace = carspace
- this.index = carspace.index;
- this.moneyDelta = GameM.commonData.carCfg[type.toString()].money;
- this.moneyTime = Number(GameM.commonData.carCfg[type.toString()].cost_time);
- //console.log("__Time1:" + this.moneyTime);
- //使用天赋 唐僧天赋2
- this.moneyTime -= this.moneyTime * MateData.Ins.Mate1Talent2 * 0.01;
- //console.log("__Time2:" + this.moneyTime);
- this.strikeRate = Number(GameM.commonData.carCfg[type.toString()].strike_rate);
- //this.schedule(this.AddCoinRunner, this.moneyTime);
- GameM.commonData.updateGoldSecond();
- this.moneyTimer = 0;
- if (startRan) {
- this.moneyTimer = Random.Range(0, this.moneyTime, false);
- }
- this.strikeTime = PlayerPrefs.GetInt("strike" + this.index, 0);
- let d = new Date();
- this.isStriking = ((d.getTime() - this.strikeTime) / 1000) < this.strikeTargetTime;
- this.strikeTimeNum = this.isStriking ? (this.strikeTargetTime - (d.getTime() - this.strikeTime) / 1000) : 0;
- //console.log("Index:" + this.index + " :" + ((d.getTime() - this.strikeTime) / 1000));
- //if (this.strikeTime == 0)
- carspace.RoleInit(this.isStriking, this.strikeTimeNum);
- }
- /**更新 角色车位信息*/
- UpdateRoleSpace(carspace) {
- this.carSpace = carspace
- this.index = carspace.index;
- PlayerPrefs.SetInt("strike" + this.index, this.strikeTime);
- this.carSpace.RoleInit(this.isStriking, this.strikeTimeNum);
- }
- /**金币获取*/
- //AddCoinRunner(dt) {
- // this.moneyTimer += dt;
- // if (this.moneyTimer >= this.moneyTime) {
- // this.moneyTimer = 0;
- // GameM.commonData.updateGold(this.moneyDelta);
- // //this.main.addCarGoldTip(this.moneyDelta);
- // //console.log("Add Coin "+this.moneyDelta);
- // }
- //}
- /**是否可以加速生产金币 减少金币产生等待时间*/
- IsCanAddSpeed() {
- //白龙马天赋1
- let rate = this.strikeRate * (1 - MateData.Ins.Mate3Talent1 * 0.01);
- if (rate < 0) rate = 0;
- let temp = Random.Range(0, 100, false);
- //console.log("cur: " + temp + " rate: " + rate);
- return temp > rate;
- }
- /**加速生产金币
- * 是否加速成功
- */
- AddSpeed(): boolean {
- if (!this.isStriking) {
- if (this.IsCanAddSpeed()) {
- this.moneyTimer += 15;
- //console.log("----");
- return true;
- } else {
- //罢工
- this.isStriking = true;
- let date = new Date();
- let time = date.getTime();
- this.strikeTime = time;
- this.strikeTimeNum = this.strikeTargetTime;
- //console.log("StartTime:" + time);
- PlayerPrefs.SetInt("strike" + this.index, time);
- this.carSpace.RoleInit(true, this.strikeTimeNum);
- return false;
- }
- }
- return false;
- }
- /**更新冷却时间*/
- UpdateIndex(index: number) {
- this.index = index;
- }
- /**解除罢工状态*/
- RemoveStrike() {
- this.isStriking = false;
- this.strikeTime = 0;
- this.strikeTimeNum = 0;
- PlayerPrefs.SetInt("strike" + this.index, 0);
- }
- /**解除旧车位罢工状态*/
- RemoveOldStrike() {
- PlayerPrefs.SetInt("strike" + this.index, 0);
- }
- /**合成新角色 移除罢工状态*/
- ComposeRole() {
- this.RemoveStrike();
- this.carSpace.RoleInit(false);
- }
- }
|