HeroData.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import { HeroConf } from "../conf/HeroConf";
  2. import { UptypeConf } from "../conf/UptypeConf";
  3. import { BattleDataPool } from "./BattleDataPool";
  4. import { BulletType, ObjectValueType } from "./BattleEnum";
  5. import { BattleUtil } from "./BattleUtil";
  6. import { BuffData, BuffDataPool } from "./BuffData";
  7. import { DataBase } from "./DataBase";
  8. import { EnemyData } from "./EnemyData";
  9. import { SkillData, SkillDataPool } from "./SkillData";
  10. export class HeroData extends DataBase{
  11. level: number;
  12. //所属格子 -1表示暂无
  13. posID: number;
  14. //当前坐标
  15. protected _position:BattleUtil.Vector2;
  16. // //动画
  17. // //前摇时间
  18. // preTime: number;
  19. // //攻击动画时间
  20. // attackTime: number;
  21. //攻击类型 瞬发单体/瞬发群体/弹道单体/弹道群体
  22. attackType: BulletType;
  23. //攻击速度 攻击间隔
  24. protected _speed: number;
  25. //攻击范围
  26. protected _attackRadius: number;
  27. //攻击力
  28. protected _attackDamage: number;
  29. //暴击率
  30. protected _critical: number;
  31. //暴击伤害
  32. protected _criticalDamage: number;
  33. //攻击速度 攻击间隔
  34. protected _speedCur: number;
  35. //攻击范围
  36. protected _attackRadiusCur: number;
  37. //攻击力
  38. protected _attackDamageCur: number;
  39. //暴击率
  40. protected _criticalCur: number;
  41. //暴击伤害
  42. protected _criticalDamageCur: number;
  43. //特殊攻击
  44. // spaceValueList:Map<ObjectValueType,BattleUtil.SpecialValue[]> = new Map();
  45. //技能列表
  46. skillList: number[];
  47. //实例化后的技能列表
  48. skillDataList: Array<SkillData> = [];
  49. //子弹命中后释放的技能列表
  50. skillBulletList: number[];
  51. skillDataBulletList: Array<SkillData> = [];
  52. //buff列表
  53. buffList: Array<BuffData> = [];
  54. //目标敌人
  55. targetEnemy:EnemyData;
  56. //冷却剩余时间
  57. coolDown: number;
  58. init(typeID:number, level:number, posID: number) {
  59. super._init();
  60. this.level = level;
  61. this.typeID = typeID;
  62. this.posID = posID;
  63. //读地图
  64. this.position = new BattleUtil.Vector2(0, 0);
  65. let heroConf = HeroConf.data[typeID]
  66. if (heroConf) {
  67. this.attackType = heroConf.AttackType;
  68. this._speed = heroConf.Speed;
  69. this.coolDown = this._speed
  70. this._attackRadius = heroConf.Radius;
  71. this._attackDamage = heroConf.Damage;
  72. this._critical = heroConf.Critical;
  73. this._criticalDamage = heroConf.CriticalDamage;
  74. this.skillList = heroConf.SkillArray
  75. if(this.skillList && this.skillList.length > 0){
  76. for (let i = 0; i < this.skillList.length; i++) {
  77. let skillID = this.skillList[i];
  78. let skillData = SkillDataPool.getObject();
  79. skillData.init(skillID, this);
  80. this.skillDataList.push(skillData);
  81. }
  82. }
  83. this.skillBulletList = heroConf.SkillBulletArray
  84. if(this.skillBulletList && this.skillBulletList.length > 0){
  85. for (let i = 0; i < this.skillBulletList.length; i++) {
  86. let skillID = this.skillBulletList[i];
  87. let skillData = SkillDataPool.getObject();
  88. skillData.init(skillID, this);
  89. this.skillDataBulletList.push(skillData);
  90. }
  91. }
  92. this.upDataLevel()
  93. return this;
  94. }
  95. return null;
  96. }
  97. set position(pos:BattleUtil.Vector2) {
  98. this._position = pos;
  99. }
  100. get position():BattleUtil.Vector2 {
  101. return this._position;
  102. }
  103. //攻击速度 攻击间隔
  104. get speed(): number{
  105. return this._speedCur;
  106. }
  107. //攻击范围
  108. get attackRadius(): number{
  109. return this._attackRadiusCur;
  110. }
  111. //攻击力
  112. get attackDamage(): number{
  113. return this._attackDamageCur;
  114. }
  115. //暴击率
  116. get critical(): number{
  117. return this._criticalCur;
  118. }
  119. //暴击伤害
  120. get criticalDamage(): number{
  121. return this._criticalDamageCur;
  122. }
  123. //只对buff进行记录
  124. addBuff(buff:BuffData) {
  125. this.buffList.push(buff);
  126. return this;
  127. }
  128. levelUp() {
  129. this.level++;
  130. this.upDataLevel()
  131. }
  132. levelTo(newLevel: number){
  133. this.level = newLevel;
  134. this.upDataLevel()
  135. }
  136. upDataLevel() {
  137. let conf = UptypeConf.data
  138. this._speedCur = this._speed / (conf.HeroSpeedColArr[this.level]||1);
  139. this._attackRadiusCur = this._attackRadius;
  140. this._attackDamageCur = this._attackDamage* (conf.HeroAttackColArr[this.level]||1);
  141. this._criticalCur = this._critical;
  142. this._criticalDamageCur = this._criticalDamage;
  143. }
  144. removeBuff(ID: number) {
  145. for (let i = 0; i < this.buffList.length; i++) {
  146. let buff = this.buffList[i];
  147. if (buff.ID == ID) {
  148. this.buffList.splice(i,1);
  149. break;
  150. }
  151. }
  152. return this;
  153. }
  154. // addSkill(skill:SkillData) {
  155. // this.skillDataList.push(skill);
  156. // return this;
  157. // }
  158. clear() {
  159. this.level = 0;
  160. this.typeID = BattleUtil.TypeID_Init;
  161. this.posID = BattleUtil.PosID_Init;
  162. //读表
  163. this.attackType = BulletType.Single;
  164. this._speed = 0;
  165. this._attackRadius = 0;
  166. this._attackDamage = 0;
  167. this._critical = 0;
  168. this._criticalDamage = 0;
  169. this._attackDamageCur = 0;
  170. this._attackRadiusCur = 0;
  171. this._criticalCur = 0;
  172. this._criticalDamageCur = 0;
  173. this._speedCur = 0;
  174. this.coolDown = 0;
  175. // this.spaceValueList.clear();
  176. for (let i = 0; i < this.skillDataList.length; i++) {
  177. SkillDataPool.putObject(this.skillDataList[i]);
  178. }
  179. this.skillDataList = [];
  180. this.skillList = [];
  181. for (let i = 0; i < this.skillDataBulletList.length; i++) {
  182. SkillDataPool.putObject(this.skillDataBulletList[i]);
  183. }
  184. this.skillDataBulletList = [];
  185. this.skillBulletList = [];
  186. this.buffList = [];
  187. this.targetEnemy = null;
  188. }
  189. }
  190. export let HeroDataPool = new BattleDataPool(HeroData,30)