EnemyData.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import { BattleUtil } from "./BattleUtil";
  2. import { DataBase } from "./DataBase";
  3. import { BattleDataPool } from "./BattleDataPool";
  4. import { EnemyConf } from "../conf/EnemyConf";
  5. import { BuffData } from "./BuffData";
  6. export class EnemyData extends DataBase{
  7. level: number;
  8. //所属类型编号
  9. //行径
  10. rold:Array<number>
  11. //当前坐标
  12. protected _position: BattleUtil.Vector2;
  13. //当前所处路线id
  14. protected _roldID: number = 0;
  15. // //出生动画时间 出生保护时间
  16. // bornTime: number = 10;
  17. //生命
  18. protected _life: number;
  19. //最大生命
  20. lifeMax: number;
  21. //基础速度 30帧移动的格子速度,单位是1个格子
  22. protected speed_30: number;
  23. protected _speedBase: number;
  24. //当前速度 //每帧的速度,单位是1个格子
  25. _speedCur: number;
  26. //不初始化表现会慢一帧吗? 一帧应该没关系
  27. protected _speedVector: BattleUtil.Vector2 = new BattleUtil.Vector2(0, 0);
  28. speedChange: boolean = false;
  29. //技能列表
  30. skillList: number[];
  31. //buff列表
  32. buffList: BuffData[] = [];
  33. //已经行走的距离
  34. moveLength: number = 0;
  35. init(typeID: number,level:number,rold:Array<number>) {
  36. super._init();
  37. this.level = level;
  38. this.typeID = typeID;
  39. let enemyConf = EnemyConf.data[typeID]
  40. if (enemyConf) {
  41. this.lifeMax = enemyConf.Life;
  42. this.life = this.lifeMax;
  43. this.speed_30 = enemyConf.Speed;
  44. this._speedBase = this.speed_30 / BattleUtil.FrameRate;
  45. this.speedCur = this._speedBase
  46. this.skillList = enemyConf.Skill
  47. }
  48. //读表
  49. this.skillList = [];
  50. this.buffList = [];
  51. this.rold = rold
  52. return this;
  53. }
  54. set speedCur(speed: number) {
  55. if (speed == 0) {
  56. return;
  57. }
  58. this._speedCur = speed;
  59. }
  60. get speedCur(): number {
  61. return this._speedCur;
  62. }
  63. set life(life: number) {
  64. this._life = life;
  65. // if(life <= 0){
  66. // console.log(this.ID,"EnemyData life is <= 0")
  67. // }
  68. }
  69. get life(): number {
  70. return this._life;
  71. }
  72. set position(pos:BattleUtil.Vector2) {
  73. this._position = pos;
  74. if (Number.isNaN(this._position.x) || Number.isNaN(this._position.y)) {
  75. console.log("EnemyData position is NaN")
  76. this._position = new BattleUtil.Vector2(0, 0);
  77. }
  78. // if (this._position.x < 0 || this._position.y < 0) {
  79. // console.log("EnemyData position is < 0")
  80. // // this._position = new BattleUtil.Vector2(0, 0);
  81. // }
  82. // console.log("EnemyData position", this._position)
  83. }
  84. get position():BattleUtil.Vector2 {
  85. if (Number.isNaN(this._position.x) || Number.isNaN(this._position.y)) {
  86. console.log("EnemyData position is NaN")
  87. //this._position = new BattleUtil.Vector2(0, 0);
  88. }
  89. return this._position;
  90. }
  91. //当前所处格子
  92. get posID(): number {
  93. return this.rold[this._roldID] || BattleUtil.PosID_Init;
  94. }
  95. set posID(id: number) {
  96. for (let i = 0; i < this.rold.length; i++) {
  97. if (this.rold[i] == id) {
  98. this._roldID = i;
  99. return;
  100. }
  101. }
  102. }
  103. get nextPosID(): number {
  104. return this.rold[this._roldID + 1] || BattleUtil.PosID_Init;
  105. }
  106. get roldID(): number {
  107. return this._roldID;
  108. }
  109. set roldID(id: number) {
  110. this._roldID = id;
  111. }
  112. get speedBase(): number {
  113. return this._speedBase;
  114. }
  115. addBuff(buff: BuffData) {
  116. this.buffList.push(buff);
  117. }
  118. removeBuff(buff: BuffData) {
  119. this.buffList.splice(this.buffList.indexOf(buff), 1);
  120. }
  121. set speedVector(vector:BattleUtil.Vector2){
  122. if(this._speedVector.x == vector.x && this._speedVector.y == vector.y)
  123. {
  124. return
  125. }
  126. // if((vector.x)**2 < 0.0000001 && vector.y**2 < 0.0000001){
  127. // console.log("EnemyData speedVector is 0")
  128. // }
  129. this.speedChange = true;
  130. this._speedVector = vector;
  131. }
  132. get speedVector():BattleUtil.Vector2{
  133. return this._speedVector;
  134. }
  135. clear() {
  136. //读表
  137. this.life = 0;
  138. this.level = 1;
  139. this.typeID = BattleUtil.TypeID_Init;
  140. this.posID = BattleUtil.PosID_Init;
  141. this.skillList = [];
  142. this.buffList = [];
  143. this.rold = []
  144. this.speedVector = new BattleUtil.Vector2(0, 0);
  145. this.moveLength = 0;
  146. super.clear();
  147. }
  148. }
  149. export let EnemyDataPool = new BattleDataPool(EnemyData,100)