HeroData.ts 6.5 KB

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