playerProp.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. import AccountModel from "../../../data/Account/AccountModel";
  2. import itemDtManager from "../../../dataManager/itemDtManager";
  3. import modelDtlManager from "../../../dataManager/modelDtlManager";
  4. import npcDtManager from "../../../dataManager/npcDtManager";
  5. import npcHelper from "../../../dataManager/npcHelper";
  6. import { AssetsHelper } from "../../../framework/asset/AssetsHelper";
  7. import { Log, LOG_TAG } from "../../../framework/log/Log";
  8. import AudioManager from "../../../framework/music/AudioManager";
  9. import effectManager from "../../../manager/effectManager";
  10. import gameData from "../../utrl/gameData";
  11. import { ATTACK_MODE, EVENT_TYPE, ITEM_TYPE, ROLE_STATE, WEAPON_TYPE } from "../../utrl/gameEnum";
  12. import gameEventManager from "../../utrl/gameEventManager";
  13. import WeaponProp from "../tool/weaponProp";
  14. import ZomBieObject from "../zombie/zombieObject";
  15. import ZombieProp from "../zombie/zombieProp";
  16. /**玩家逻辑属性 */
  17. export default class PlayerProp {
  18. /**是领队 */
  19. is_leader = false;
  20. /*基础攻击力 */
  21. base_damage = 0;
  22. /**空手攻击范围 */
  23. hand_range = 80;
  24. /**当前武器 */
  25. cur_weapon: WeaponProp = null;
  26. /**近战武器 */
  27. close_weapon: WeaponProp = null;
  28. /**远程武器 */
  29. remote_weapon: WeaponProp = null;
  30. /**攻击间隔 */
  31. attack_dur = 0.5;
  32. /**攻击计时器 */
  33. attack_timer = Number.MAX_VALUE;
  34. /**索敌范围 */
  35. search_range = 200;
  36. /**入队范围 */
  37. in_range = 200;
  38. /**玩家等级 */
  39. level = 0;
  40. exp = 0;
  41. //升级条件
  42. upgradeCondition = 8;
  43. /**基础血量 */
  44. base_hp = 100;
  45. /**当前血量 */
  46. cur_hp = 100;
  47. //总血量
  48. total_hp = 100;
  49. /**玩家状态 */
  50. cur_state = ROLE_STATE.idle;
  51. player_ID = 0;
  52. refresh_cmd = false;
  53. buff_id = 0;
  54. pos = null;
  55. isCover = false; //是否已经覆盖过数据
  56. /**初始化 */
  57. init(playerID) {
  58. this.player_ID = playerID;
  59. this.initWeaponDt();
  60. this.initHpDt();
  61. this.initAckDt();
  62. this.initupgradeNum();
  63. this.coverDt(); //是否需要覆盖数据
  64. this.attack_timer = Number.MAX_VALUE;
  65. this.buff_id = npcDtManager.getDataByID(playerID).buffID;
  66. }
  67. initAckDt() {
  68. let modelDt = npcHelper.getModelAttrByID(this.player_ID);
  69. this.base_damage = modelDt.att;
  70. }
  71. //升级条件
  72. initupgradeNum() {
  73. if (this.level == 0) {
  74. this.upgradeCondition = 8
  75. } else if (this.level == 1) {
  76. this.upgradeCondition = 64
  77. } else if (this.level == 2) {
  78. this.upgradeCondition = 128
  79. } else if (this.level == 3) {
  80. this.upgradeCondition = 256
  81. }
  82. }
  83. initHpDt() {
  84. let modelDt = npcHelper.getModelAttrByID(this.player_ID);
  85. if (npcHelper.isHero(this.player_ID)) { //英雄默认满级 特殊判断
  86. this.level = 4;
  87. this.base_hp = modelDt.hp;
  88. this.total_hp = this.base_hp
  89. this.cur_hp = this.total_hp;
  90. return;
  91. }
  92. this.total_hp = this.base_hp + this.level * 50;
  93. this.base_hp = modelDt.hp;
  94. this.cur_hp = this.total_hp;
  95. }
  96. initWeaponDt() {
  97. let itemDt = npcHelper.getItemByID(this.player_ID); //获取玩家默认武器数据
  98. let remoteItemDt = npcHelper.getRemoteItemByID(this.player_ID); //远程武器Dt
  99. let closeWeapon = null;
  100. let remoteWeapon = null;
  101. if (remoteItemDt) {
  102. if (remoteItemDt.type == ITEM_TYPE.REMOTE_WEAPON) {
  103. remoteWeapon = new WeaponProp(remoteItemDt.id, WEAPON_TYPE.remote, remoteItemDt.value, remoteItemDt.attArea);
  104. }
  105. }
  106. if (itemDt) {
  107. if (itemDt.type == ITEM_TYPE.CLOSE_WEAPON) {
  108. closeWeapon = new WeaponProp(itemDt.id, WEAPON_TYPE.close, itemDt.value, 100);
  109. } else if (itemDt.type == ITEM_TYPE.REMOTE_WEAPON) {
  110. remoteWeapon = new WeaponProp(itemDt.id, WEAPON_TYPE.remote, itemDt.value, itemDt.attArea);
  111. }
  112. }
  113. if (gameData.cur_attack_mode == ATTACK_MODE.close) {
  114. this.cur_weapon = closeWeapon;
  115. } else {
  116. this.cur_weapon = remoteWeapon;
  117. }
  118. //英雄玩家有的默认远程
  119. if (this.player_ID == 50) {
  120. this.cur_weapon = remoteWeapon;
  121. }
  122. this.close_weapon = closeWeapon;
  123. this.remote_weapon = remoteWeapon;
  124. }
  125. /**升级 */
  126. levelUp() {
  127. this.level++;
  128. this.initHpDt();
  129. this.initupgradeNum();
  130. }
  131. //更新总血量
  132. updateTotalHp() {
  133. this.total_hp = this.base_hp + this.level * 50;
  134. Log.log(LOG_TAG.DEBUG, '当前总血量:' + this.total_hp);
  135. }
  136. /**受伤
  137. * @param damage 伤害
  138. */
  139. beHurt(damage: number) {
  140. this.cur_hp -= damage;
  141. if (this.cur_hp <= 0) {
  142. this.cur_hp = 0;
  143. }
  144. return this.cur_hp;
  145. }
  146. /**攻击间隔
  147. * @param dt 每帧时间
  148. * @param cbk 攻击回调
  149. */
  150. attackRun(dt: number, cbk: Function) {
  151. this.attack_timer += dt;
  152. if (this.cur_weapon != null && this.cur_weapon.type != WEAPON_TYPE.close) {
  153. this.attack_timer += dt * 1;
  154. }
  155. if (this.attack_timer > this.attack_dur) {
  156. this.attack_timer = 0;
  157. cbk();
  158. }
  159. }
  160. /**攻击
  161. * @param target 目标
  162. * @param damage 伤害
  163. * @returns 如果目标已死,返回目标等级,否则返回-1
  164. */
  165. attack(target: ZomBieObject, damage: number): boolean {
  166. let hp = target.zombie_prop.beHurt(damage);
  167. if (hp == 0) {
  168. target.isDie = true;
  169. gameData.curKillZomNum += 1;
  170. this.cur_state = ROLE_STATE.idle;
  171. return true;
  172. }
  173. return false;
  174. }
  175. /**行走 */
  176. walk() {
  177. this.cur_state = ROLE_STATE.walk;
  178. }
  179. /**回血 */
  180. healHp(heal: number, node?: cc.Node) {
  181. if (heal == 0) return;
  182. let max = this.total_hp;
  183. if (this.cur_hp < max) {
  184. AudioManager.play('skillcure');
  185. effectManager.playEff(node, 'treatment', null, true);
  186. }
  187. this.cur_hp += heal;
  188. this.cur_hp = this.cur_hp > max ? max : this.cur_hp;
  189. }
  190. /**更换武器 */
  191. setWeapon(id: number, is_close: boolean) {
  192. let wd = itemDtManager.getDataByID(id);
  193. if (is_close) {
  194. this.close_weapon = new WeaponProp(id, WEAPON_TYPE.close, wd.value, 100);
  195. }
  196. else {
  197. this.remote_weapon = new WeaponProp(id, WEAPON_TYPE.remote, wd.value, wd.attArea);
  198. }
  199. this.refreshWeapon();
  200. }
  201. /**刷新武器 */
  202. refreshWeapon() {
  203. if (gameData.cur_attack_mode == ATTACK_MODE.close) {
  204. this.cur_weapon = this.close_weapon;
  205. }
  206. else {
  207. this.cur_weapon = this.remote_weapon;
  208. }
  209. this.refresh_cmd = true;
  210. }
  211. //-------------------------------存取数据相关-----------------------------------------//
  212. coverDt() {
  213. let playerLayIndt = AccountModel.getInstance().playerDtList;
  214. if (playerLayIndt.length > 0) {
  215. for (let i = 0; i < playerLayIndt.length; ++i) {
  216. if (playerLayIndt[i].player_ID == this.player_ID && playerLayIndt[i].isCover == false) {
  217. this.cover(playerLayIndt[i]);
  218. playerLayIndt[i].isCover = true;
  219. return;
  220. }
  221. }
  222. }
  223. }
  224. cover(obj) {
  225. this.is_leader = obj.is_leader,
  226. this.base_damage = obj.base_damage,
  227. this.hand_range = obj.hand_range,
  228. this.cur_weapon = obj.cur_weapon,
  229. this.close_weapon = obj.close_weapon,
  230. this.remote_weapon = obj.remote_weapon,
  231. this.attack_dur = obj.attack_dur,
  232. this.attack_timer = obj.attack_timer,
  233. this.search_range = obj.search_range,
  234. this.in_range = obj.in_range,
  235. this.level = obj.level,
  236. this.base_hp = obj.base_hp,
  237. this.cur_hp = obj.cur_hp,
  238. this.cur_state = obj.cur_state,
  239. this.player_ID = obj.player_ID,
  240. this.refresh_cmd = obj.refresh_cmd,
  241. this.exp = obj.exp,
  242. this.pos = obj.pos,
  243. this.isCover = obj.isCover,
  244. this.total_hp = obj.total_hp
  245. }
  246. getPlayerDt() {
  247. let obj = {
  248. is_leader: this.is_leader,
  249. base_damage: this.base_damage,
  250. hand_range: this.hand_range,
  251. cur_weapon: this.cur_weapon,
  252. close_weapon: this.close_weapon,
  253. remote_weapon: this.remote_weapon,
  254. attack_dur: this.attack_dur,
  255. attack_timer: Number.MAX_VALUE,
  256. search_range: this.search_range,
  257. in_range: 200,
  258. level: this.level,
  259. base_hp: this.base_hp,
  260. cur_hp: this.cur_hp,
  261. cur_state: ROLE_STATE.idle,
  262. player_ID: this.player_ID,
  263. refresh_cmd: this.refresh_cmd,
  264. exp: this.exp,
  265. pos: this.pos,
  266. isCover: this.isCover,
  267. total_hp: this.total_hp
  268. }
  269. return obj;
  270. }
  271. }