import AccountModel from "../../../data/Account/AccountModel"; import itemDtManager from "../../../dataManager/itemDtManager"; import modelDtlManager from "../../../dataManager/modelDtlManager"; import npcDtManager from "../../../dataManager/npcDtManager"; import npcHelper from "../../../dataManager/npcHelper"; import { AssetsHelper } from "../../../framework/asset/AssetsHelper"; import { Log, LOG_TAG } from "../../../framework/log/Log"; import AudioManager from "../../../framework/music/AudioManager"; import effectManager from "../../../manager/effectManager"; import gameData from "../../utrl/gameData"; import { ATTACK_MODE, EVENT_TYPE, ITEM_TYPE, ROLE_STATE, WEAPON_TYPE } from "../../utrl/gameEnum"; import gameEventManager from "../../utrl/gameEventManager"; import WeaponProp from "../tool/weaponProp"; import ZomBieObject from "../zombie/zombieObject"; import ZombieProp from "../zombie/zombieProp"; /**玩家逻辑属性 */ export default class PlayerProp { /**是领队 */ is_leader = false; /*基础攻击力 */ base_damage = 0; /**空手攻击范围 */ hand_range = 80; /**当前武器 */ cur_weapon: WeaponProp = null; /**近战武器 */ close_weapon: WeaponProp = null; /**远程武器 */ remote_weapon: WeaponProp = null; /**攻击间隔 */ attack_dur = 0.5; /**攻击计时器 */ attack_timer = Number.MAX_VALUE; /**索敌范围 */ search_range = 200; /**入队范围 */ in_range = 200; /**玩家等级 */ level = 0; exp = 0; //升级条件 upgradeCondition = 8; /**基础血量 */ base_hp = 100; /**当前血量 */ cur_hp = 100; //总血量 total_hp = 100; /**玩家状态 */ cur_state = ROLE_STATE.idle; player_ID = 0; refresh_cmd = false; buff_id = 0; pos = null; isCover = false; //是否已经覆盖过数据 /**初始化 */ init(playerID) { this.player_ID = playerID; this.initWeaponDt(); this.initHpDt(); this.initAckDt(); this.initupgradeNum(); this.coverDt(); //是否需要覆盖数据 this.attack_timer = Number.MAX_VALUE; this.buff_id = npcDtManager.getDataByID(playerID).buffID; } initAckDt() { let modelDt = npcHelper.getModelAttrByID(this.player_ID); this.base_damage = modelDt.att; } //升级条件 initupgradeNum() { if (this.level == 0) { this.upgradeCondition = 8 } else if (this.level == 1) { this.upgradeCondition = 64 } else if (this.level == 2) { this.upgradeCondition = 128 } else if (this.level == 3) { this.upgradeCondition = 256 } } initHpDt() { let modelDt = npcHelper.getModelAttrByID(this.player_ID); if (npcHelper.isHero(this.player_ID)) { //英雄默认满级 特殊判断 this.level = 4; this.base_hp = modelDt.hp; this.total_hp = this.base_hp this.cur_hp = this.total_hp; return; } this.total_hp = this.base_hp + this.level * 50; this.base_hp = modelDt.hp; this.cur_hp = this.total_hp; } initWeaponDt() { let itemDt = npcHelper.getItemByID(this.player_ID); //获取玩家默认武器数据 let remoteItemDt = npcHelper.getRemoteItemByID(this.player_ID); //远程武器Dt let closeWeapon = null; let remoteWeapon = null; if (remoteItemDt) { if (remoteItemDt.type == ITEM_TYPE.REMOTE_WEAPON) { remoteWeapon = new WeaponProp(remoteItemDt.id, WEAPON_TYPE.remote, remoteItemDt.value, remoteItemDt.attArea); } } if (itemDt) { if (itemDt.type == ITEM_TYPE.CLOSE_WEAPON) { closeWeapon = new WeaponProp(itemDt.id, WEAPON_TYPE.close, itemDt.value, 100); } else if (itemDt.type == ITEM_TYPE.REMOTE_WEAPON) { remoteWeapon = new WeaponProp(itemDt.id, WEAPON_TYPE.remote, itemDt.value, itemDt.attArea); } } if (gameData.cur_attack_mode == ATTACK_MODE.close) { this.cur_weapon = closeWeapon; } else { this.cur_weapon = remoteWeapon; } //英雄玩家有的默认远程 if (this.player_ID == 50) { this.cur_weapon = remoteWeapon; } this.close_weapon = closeWeapon; this.remote_weapon = remoteWeapon; } /**升级 */ levelUp() { this.level++; this.initHpDt(); this.initupgradeNum(); } //更新总血量 updateTotalHp() { this.total_hp = this.base_hp + this.level * 50; Log.log(LOG_TAG.DEBUG, '当前总血量:' + this.total_hp); } /**受伤 * @param damage 伤害 */ beHurt(damage: number) { this.cur_hp -= damage; if (this.cur_hp <= 0) { this.cur_hp = 0; } return this.cur_hp; } /**攻击间隔 * @param dt 每帧时间 * @param cbk 攻击回调 */ attackRun(dt: number, cbk: Function) { this.attack_timer += dt; if (this.cur_weapon != null && this.cur_weapon.type != WEAPON_TYPE.close) { this.attack_timer += dt * 1; } if (this.attack_timer > this.attack_dur) { this.attack_timer = 0; cbk(); } } /**攻击 * @param target 目标 * @param damage 伤害 * @returns 如果目标已死,返回目标等级,否则返回-1 */ attack(target: ZomBieObject, damage: number): boolean { let hp = target.zombie_prop.beHurt(damage); if (hp == 0) { target.isDie = true; gameData.curKillZomNum += 1; this.cur_state = ROLE_STATE.idle; return true; } return false; } /**行走 */ walk() { this.cur_state = ROLE_STATE.walk; } /**回血 */ healHp(heal: number, node?: cc.Node) { if (heal == 0) return; let max = this.total_hp; if (this.cur_hp < max) { AudioManager.play('skillcure'); effectManager.playEff(node, 'treatment', null, true); } this.cur_hp += heal; this.cur_hp = this.cur_hp > max ? max : this.cur_hp; } /**更换武器 */ setWeapon(id: number, is_close: boolean) { let wd = itemDtManager.getDataByID(id); if (is_close) { this.close_weapon = new WeaponProp(id, WEAPON_TYPE.close, wd.value, 100); } else { this.remote_weapon = new WeaponProp(id, WEAPON_TYPE.remote, wd.value, wd.attArea); } this.refreshWeapon(); } /**刷新武器 */ refreshWeapon() { if (gameData.cur_attack_mode == ATTACK_MODE.close) { this.cur_weapon = this.close_weapon; } else { this.cur_weapon = this.remote_weapon; } this.refresh_cmd = true; } //-------------------------------存取数据相关-----------------------------------------// coverDt() { let playerLayIndt = AccountModel.getInstance().playerDtList; if (playerLayIndt.length > 0) { for (let i = 0; i < playerLayIndt.length; ++i) { if (playerLayIndt[i].player_ID == this.player_ID && playerLayIndt[i].isCover == false) { this.cover(playerLayIndt[i]); playerLayIndt[i].isCover = true; return; } } } } cover(obj) { this.is_leader = obj.is_leader, this.base_damage = obj.base_damage, this.hand_range = obj.hand_range, this.cur_weapon = obj.cur_weapon, this.close_weapon = obj.close_weapon, this.remote_weapon = obj.remote_weapon, this.attack_dur = obj.attack_dur, this.attack_timer = obj.attack_timer, this.search_range = obj.search_range, this.in_range = obj.in_range, this.level = obj.level, this.base_hp = obj.base_hp, this.cur_hp = obj.cur_hp, this.cur_state = obj.cur_state, this.player_ID = obj.player_ID, this.refresh_cmd = obj.refresh_cmd, this.exp = obj.exp, this.pos = obj.pos, this.isCover = obj.isCover, this.total_hp = obj.total_hp } getPlayerDt() { let obj = { is_leader: this.is_leader, base_damage: this.base_damage, hand_range: this.hand_range, cur_weapon: this.cur_weapon, close_weapon: this.close_weapon, remote_weapon: this.remote_weapon, attack_dur: this.attack_dur, attack_timer: Number.MAX_VALUE, search_range: this.search_range, in_range: 200, level: this.level, base_hp: this.base_hp, cur_hp: this.cur_hp, cur_state: ROLE_STATE.idle, player_ID: this.player_ID, refresh_cmd: this.refresh_cmd, exp: this.exp, pos: this.pos, isCover: this.isCover, total_hp: this.total_hp } return obj; } }