Role.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { MateData } from "../../datas/MateData";
  2. import GameM from "../../manager/GameM";
  3. import { thirdVideoTS } from "../../manager/topon/AnyThinkAdsMgr/thirdVideoTS";
  4. import CarSpace from "../../prefabs/CarSpace";
  5. import { PlayerPrefs } from "../../tools/MyExtends";
  6. import Random from "../../utils/Random";
  7. export class Role {
  8. //角色
  9. /**产生一次金币所花时间*/
  10. moneyTime: number = 0;
  11. /**产生一次金币计时器*/
  12. moneyTimer: number = 0;
  13. /**对应时间内产生金币数*/
  14. moneyDelta: string = '';
  15. /**罢工概率*/
  16. strikeRate: number = 0;
  17. /**是否已罢工*/
  18. isStriking: boolean = false;
  19. /**车位index*/
  20. index: number = 0;
  21. /**开始罢工的时间点*/
  22. strikeTime: number = 0;
  23. /**罢工剩余时间 秒*/
  24. strikeTimeNum: number = 0;
  25. /**罢工时间 秒*/
  26. strikeTargetTime: number = 180;
  27. carSpace: CarSpace = null
  28. /**
  29. * 角色初始化
  30. * @param type 角色等级
  31. * @param startRan 开始时间是否随机
  32. * @param carspace 车位
  33. */
  34. Init(type, startRan = false, carspace) {
  35. this.carSpace = carspace
  36. this.index = carspace.index;
  37. this.moneyDelta = GameM.commonData.carCfg[type.toString()].money;
  38. this.moneyTime = Number(GameM.commonData.carCfg[type.toString()].cost_time);
  39. //console.log("__Time1:" + this.moneyTime);
  40. //使用天赋 唐僧天赋2
  41. this.moneyTime -= this.moneyTime * MateData.Ins.Mate1Talent2 * 0.01;
  42. //console.log("__Time2:" + this.moneyTime);
  43. this.strikeRate = Number(GameM.commonData.carCfg[type.toString()].strike_rate);
  44. //this.schedule(this.AddCoinRunner, this.moneyTime);
  45. GameM.commonData.updateGoldSecond();
  46. this.moneyTimer = 0;
  47. if (startRan) {
  48. this.moneyTimer = Random.Range(0, this.moneyTime, false);
  49. }
  50. this.strikeTime = PlayerPrefs.GetInt("strike" + this.index, 0);
  51. let d = new Date();
  52. this.isStriking = ((d.getTime() - this.strikeTime) / 1000) < this.strikeTargetTime;
  53. this.strikeTimeNum = this.isStriking ? (this.strikeTargetTime - (d.getTime() - this.strikeTime) / 1000) : 0;
  54. //console.log("Index:" + this.index + " :" + ((d.getTime() - this.strikeTime) / 1000));
  55. //if (this.strikeTime == 0)
  56. carspace.RoleInit(this.isStriking, this.strikeTimeNum);
  57. }
  58. /**更新 角色车位信息*/
  59. UpdateRoleSpace(carspace) {
  60. this.carSpace = carspace
  61. this.index = carspace.index;
  62. PlayerPrefs.SetInt("strike" + this.index, this.strikeTime);
  63. this.carSpace.RoleInit(this.isStriking, this.strikeTimeNum);
  64. }
  65. /**金币获取*/
  66. //AddCoinRunner(dt) {
  67. // this.moneyTimer += dt;
  68. // if (this.moneyTimer >= this.moneyTime) {
  69. // this.moneyTimer = 0;
  70. // GameM.commonData.updateGold(this.moneyDelta);
  71. // //this.main.addCarGoldTip(this.moneyDelta);
  72. // //console.log("Add Coin "+this.moneyDelta);
  73. // }
  74. //}
  75. /**是否可以加速生产金币 减少金币产生等待时间*/
  76. IsCanAddSpeed() {
  77. //白龙马天赋1
  78. let rate = this.strikeRate * (1 - MateData.Ins.Mate3Talent1 * 0.01);
  79. if (rate < 0) rate = 0;
  80. let temp = Random.Range(0, 100, false);
  81. //console.log("cur: " + temp + " rate: " + rate);
  82. return temp > rate;
  83. }
  84. /**加速生产金币
  85. * 是否加速成功
  86. */
  87. AddSpeed(): boolean {
  88. if (!this.isStriking) {
  89. if (this.IsCanAddSpeed()) {
  90. this.moneyTimer += 15;
  91. //console.log("----");
  92. return true;
  93. } else {
  94. //罢工
  95. this.isStriking = true;
  96. let date = new Date();
  97. let time = date.getTime();
  98. this.strikeTime = time;
  99. this.strikeTimeNum = this.strikeTargetTime;
  100. //console.log("StartTime:" + time);
  101. PlayerPrefs.SetInt("strike" + this.index, time);
  102. this.carSpace.RoleInit(true, this.strikeTimeNum);
  103. return false;
  104. }
  105. }
  106. return false;
  107. }
  108. /**更新冷却时间*/
  109. UpdateIndex(index: number) {
  110. this.index = index;
  111. }
  112. /**解除罢工状态*/
  113. RemoveStrike() {
  114. this.isStriking = false;
  115. this.strikeTime = 0;
  116. this.strikeTimeNum = 0;
  117. PlayerPrefs.SetInt("strike" + this.index, 0);
  118. }
  119. /**解除旧车位罢工状态*/
  120. RemoveOldStrike() {
  121. PlayerPrefs.SetInt("strike" + this.index, 0);
  122. }
  123. /**合成新角色 移除罢工状态*/
  124. ComposeRole() {
  125. this.RemoveStrike();
  126. this.carSpace.RoleInit(false);
  127. }
  128. }