HeroData.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import { Role } from "../../../common/InterfaceAddEnum";
  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(role:Role, level:number, posID: number) {
  63. super._init();
  64. this.level = level;
  65. this.typeID = Number(role.id);
  66. this.posID = posID;
  67. this._raceID = role.conf.Race
  68. // let roleData = RoleData.getRoleDataByID(this.typeID)
  69. //读地图
  70. this.position = new BattleUtil.Vector2(0, 0);
  71. let heroConf = role.conf
  72. if (heroConf) {
  73. this.attackType = heroConf.AttackType;
  74. this._speed = role.attr.speed;
  75. this.coolDown = this._speed
  76. this._attackRadius = heroConf.Radius;
  77. this._attackDamage = role.attr.attack;
  78. this._critical = role.attr.crite;
  79. this._criticalDamage = role.attr.critedamage;
  80. this.skillList = heroConf.SkillArray
  81. if(this.skillList && this.skillList.length > 0){
  82. for (let i = 0; i < this.skillList.length; i++) {
  83. let skillID = this.skillList[i];
  84. let skillData = SkillDataPool.getObject();
  85. skillData.init(skillID, this);
  86. this.skillDataList.push(skillData);
  87. }
  88. }
  89. this.skillBulletList = heroConf.SkillBulletArray
  90. if(this.skillBulletList && this.skillBulletList.length > 0){
  91. for (let i = 0; i < this.skillBulletList.length; i++) {
  92. let skillID = this.skillBulletList[i];
  93. let skillData = SkillDataPool.getObject();
  94. skillData.init(skillID, this);
  95. this.skillDataBulletList.push(skillData);
  96. }
  97. }
  98. this.updataLevel()
  99. return this;
  100. }
  101. return null;
  102. }
  103. set position(pos:BattleUtil.Vector2) {
  104. this._position = pos;
  105. }
  106. get position():BattleUtil.Vector2 {
  107. return this._position;
  108. }
  109. //攻击速度 攻击间隔
  110. get speed(): number{
  111. return this._speedCur;
  112. }
  113. //攻击范围
  114. get attackRadius(): number{
  115. return this._attackRadiusCur;
  116. }
  117. //攻击力
  118. get attackDamage(): number{
  119. return this._attackDamageCur;
  120. }
  121. //暴击率
  122. get critical(): number{
  123. return this._criticalCur;
  124. }
  125. //暴击伤害
  126. get criticalDamage(): number{
  127. return this._criticalDamageCur;
  128. }
  129. get raceID(): number{
  130. return this._raceID;
  131. }
  132. //只对buff进行记录
  133. addBuff(buff:BuffData) {
  134. this.buffList.push(buff);
  135. return this;
  136. }
  137. levelUp() {
  138. this.level++;
  139. this.updataLevel()
  140. }
  141. levelTo(newLevel: number){
  142. this.level = newLevel;
  143. this.updataLevel()
  144. }
  145. updataLevel() {
  146. let conf = UptypeConf.data
  147. this._speedCur = this._speed / (conf.HeroSpeedColArr[this.level]||1);
  148. this._attackRadiusCur = this._attackRadius;
  149. this._attackDamageCur = this._attackDamage* (conf.HeroAttackColArr[this.level]||1);
  150. this._criticalCur = this._critical;
  151. this._criticalDamageCur = this._criticalDamage;
  152. }
  153. updateRole(role:Role){
  154. let heroConf = role.conf
  155. if (heroConf) {
  156. this._speed = role.attr.speed;
  157. this._attackDamage = role.attr.attack;
  158. this._critical = role.attr.crite;
  159. this._criticalDamage = role.attr.critedamage;
  160. this.updataLevel()
  161. return this;
  162. }
  163. return null;
  164. }
  165. removeBuff(ID: number) {
  166. for (let i = 0; i < this.buffList.length; i++) {
  167. let buff = this.buffList[i];
  168. if (buff.ID == ID) {
  169. this.buffList.splice(i,1);
  170. break;
  171. }
  172. }
  173. return this;
  174. }
  175. // addSkill(skill:SkillData) {
  176. // this.skillDataList.push(skill);
  177. // return this;
  178. // }
  179. clear() {
  180. this.level = 0;
  181. this.typeID = BattleUtil.TypeID_Init;
  182. this.posID = BattleUtil.PosID_Init;
  183. //读表
  184. this.attackType = BulletType.Single;
  185. this._speed = 0;
  186. this._attackRadius = 0;
  187. this._attackDamage = 0;
  188. this._critical = 0;
  189. this._criticalDamage = 0;
  190. this._attackDamageCur = 0;
  191. this._attackRadiusCur = 0;
  192. this._criticalCur = 0;
  193. this._criticalDamageCur = 0;
  194. this._speedCur = 0;
  195. this.coolDown = 0;
  196. // this.spaceValueList.clear();
  197. for (let i = 0; i < this.skillDataList.length; i++) {
  198. SkillDataPool.putObject(this.skillDataList[i]);
  199. }
  200. this.skillDataList = [];
  201. this.skillList = [];
  202. for (let i = 0; i < this.skillDataBulletList.length; i++) {
  203. SkillDataPool.putObject(this.skillDataBulletList[i]);
  204. }
  205. this.skillDataBulletList = [];
  206. this.skillBulletList = [];
  207. this.buffList = [];
  208. this.targetEnemy = null;
  209. }
  210. }
  211. export let HeroDataPool = new BattleDataPool(HeroData,30)