123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854 |
- import { USER } from "../constant/constant-user";
- import AccountModel from "../data/Account/AccountModel";
- import buffDtManager from "../dataManager/buffDtManager";
- import itemDtManager from "../dataManager/itemDtManager";
- import npcHelper from "../dataManager/npcHelper";
- import { AssetsHelper } from "../framework/asset/AssetsHelper";
- import { BenzAssetManager } from "../framework/asset/BenzAssetManager";
- import EventManager from "../framework/event/EventManager";
- import { Log, LOG_TAG } from "../framework/log/Log";
- import AudioManager from "../framework/music/AudioManager";
- import UIBase from "../framework/ui/UIBase";
- import UIHelp from "../framework/ui/UIHelp";
- import Utils from "../framework/utils/utils";
- import bundleManager from "../manager/bundleManager";
- import dungeonManager from "../manager/dungeonManager";
- import effectManager from "../manager/effectManager";
- import levelManager from "../manager/levelManager";
- import UIFailView from "../ui/uiview/Interface/UIFailView";
- import UITopMenu from "../ui/uiview/Interface/UITopMenu";
- import UIFallitem from "../ui/uiview/map/UIFallitem";
- import BulletObject from "./gameObject/bullet/bulletObject";
- import GameObject from "./gameObject/gameObject";
- import NodeMove from "./gameObject/player/nodeMove";
- import PlayerObject from "./gameObject/player/playerObject";
- import PlayerProp from "./gameObject/player/playerProp";
- import PlayerView from "./gameObject/player/playerView";
- import NpcObject from "./gameObject/tool/npcObject";
- import WeaponProp from "./gameObject/tool/weaponProp";
- import ZomBieObject from "./gameObject/zombie/zombieObject";
- import zombieView from "./gameObject/zombie/zombieView";
- import gameData from "./utrl/gameData";
- import { ATTACK_MODE, EVENT_TYPE, GAME_OBJECT_TYPE, ITEM_TYPE, ROLE_STATE, WEAPON_TYPE } from "./utrl/gameEnum";
- import gameEventManager from "./utrl/gameEventManager";
- const { ccclass, property } = cc._decorator;
- /**副本逻辑类 */
- @ccclass
- export default class dungeonLogic extends cc.Component {
- @property(cc.Node)
- /**地图父节点 */
- map_parent: cc.Node = null;
- @property(cc.Node)
- /**实体父节点 */
- object_parent: cc.Node = null;
- /**道具父节点 */
- @property(cc.Node)
- prop_parent: cc.Node = null;
- /**道具预制体 */
- @property(cc.Prefab)
- prop_pre: cc.Prefab = null;
- /**摄像机节点 */
- private camera: cc.Node = null;
- /**玩家预制体 */
- private player_pre: cc.Prefab = null;
- /**僵尸预制体 */
- private zombie_pre: cc.Prefab = null;
- /**子弹预制体 */
- private bullet_pre: cc.Prefab = null;
- game_over: boolean = false;
- isClose: boolean = false;
- /**buff间隔时间 */
- private buff_dur = 10;
- /**buff间隔计时器 */
- private buff_timer = 0;
- /**buff回复子弹血量体力值组 */
- private buffs: number[][] = [];
- /**角色组,0玩家组,1僵尸组 */
- roles: cc.Node[][] = [null, null];
- dtCount: number;
- playerDiePos: cc.Vec3 = null;
- //对象池
- playerBulletPool: cc.NodePool;
- zombieNodePool: cc.NodePool;
- playerNodePool: cc.NodePool;
- propsNodePool: cc.NodePool;
- onEnable() {
- this.isClose = false;
- cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, () => { this.randomLeader() })
- gameEventManager.on(EVENT_TYPE.GAME_OVER, this.gameOver, this);
- gameEventManager.on(EVENT_TYPE.random_leader, this.randomLeader, this);
- gameEventManager.on(EVENT_TYPE.add_zombie, this.addZombie, this);
- gameEventManager.on(EVENT_TYPE.bullet0, this.playerRemoteAttack0, this);
- gameEventManager.on(EVENT_TYPE.bullet1, this.playerRemoteAttack1, this);
- gameEventManager.on(EVENT_TYPE.zombie_boom, this.zombieRemoteBoom, this);
- gameEventManager.on(EVENT_TYPE.player_die, this.diePlayerCbk, this);
- gameEventManager.on(EVENT_TYPE.zombie_die, this.dieZombieCbk, this);
- gameEventManager.on(EVENT_TYPE.GAME_RELIVE, this.gameRelive, this);
- gameEventManager.on(EVENT_TYPE.RECOVER_ZOMBIE, this.recoverZombie, this)
- gameEventManager.on(EVENT_TYPE.RECOVER_PLAYER, this.recoverPlayer, this)
- gameEventManager.on(EVENT_TYPE.RECOVER_PLAYER_BULLET, this.recoverPlayerBullet, this)
- this.scheduleOnce(() => {
- this.iniPlayer();
- }, 0.02)
- }
- onDisable() {
- gameEventManager.off(EVENT_TYPE.GAME_RELIVE, this.gameRelive, this);
- gameEventManager.off(EVENT_TYPE.random_leader, this.randomLeader, this);
- gameEventManager.off(EVENT_TYPE.GAME_OVER, this.gameOver, this);
- gameEventManager.off(EVENT_TYPE.add_zombie, this.addZombie, this);
- gameEventManager.off(EVENT_TYPE.bullet0, this.playerRemoteAttack0, this);
- gameEventManager.off(EVENT_TYPE.bullet1, this.playerRemoteAttack1, this);
- gameEventManager.off(EVENT_TYPE.zombie_boom, this.zombieRemoteBoom, this);
- gameEventManager.off(EVENT_TYPE.player_die, this.diePlayerCbk, this);
- gameEventManager.off(EVENT_TYPE.zombie_die, this.dieZombieCbk, this);
- gameEventManager.off(EVENT_TYPE.RECOVER_ZOMBIE, this.recoverZombie, this)
- gameEventManager.off(EVENT_TYPE.RECOVER_PLAYER, this.recoverPlayer, this)
- gameEventManager.off(EVENT_TYPE.RECOVER_PLAYER_BULLET, this.recoverPlayerBullet, this)
- }
- /**初始化
- * @param camera 摄像机
- * @param 玩家预制体
- * @param 僵尸预制体
- */
- init(camera: cc.Node, player_pre: cc.Prefab, zombie_pre: cc.Prefab, bullet_pre: cc.Prefab) {
- this.camera = camera;
- this.player_pre = player_pre;
- this.zombie_pre = zombie_pre;
- this.bullet_pre = bullet_pre;
- this.initBulletPool();
- this.initZombiePool();
- this.initPlayerPool();
- this.initPropPool();
- this.iniPlayer();
- this.initZomBie();
- this.buffs = [];
- for (let i = 1; i <= 9; i++) {
- let d = buffDtManager.getDataByID(i);
- let b = [d.att, d.hp, d.food];
- this.buffs.push(b);
- }
- }
- initPlayerPool() {
- this.playerNodePool = Utils.initNodePool(this.player_pre, 20);
- }
- initZombiePool() {
- this.zombieNodePool = Utils.initNodePool(this.zombie_pre, 15);
- }
- initBulletPool() {
- this.playerBulletPool = Utils.initNodePool(this.bullet_pre, 10);
- }
- initPropPool() {
- this.propsNodePool = new cc.NodePool();
- }
- //回收僵尸节点
- recoverZombie(nd) {
- let zombiePool = this.zombieNodePool;
- if (zombiePool) {
- zombiePool.put(nd);
- Log.log(LOG_TAG.DEBUG, zombiePool);
- } else {
- nd.destroy();
- }
- }
- recoverPlayer(nd) {
- let playerPool = this.playerNodePool;
- if (playerPool) {
- playerPool.put(nd);
- Log.log(LOG_TAG.DEBUG, playerPool);
- } else {
- nd.destroy();
- }
- }
- recoverPlayerBullet(nd) {
- let playerBulletPool = this.playerBulletPool;
- if (playerBulletPool) {
- playerBulletPool.put(nd);
- Log.log(LOG_TAG.DEBUG, playerBulletPool);
- } else {
- nd.destroy();
- }
- }
- clearPropPool() {
- let poolLen = this.propsNodePool.size();
- if (poolLen > 0 && poolLen > 20) {
- this.propsNodePool.clear();
- Log.log(LOG_TAG.DEBUG, 'clearpropsNodePool');
- }
- }
- //初始化僵尸
- initZomBie() {
- let zombieBorn: cc.Node[] = this.node.$zombieBorn_parent.children;
- zombieBorn.forEach(node => {
- let name: string = node.name;
- let bornDt = this.getZombieBornDtByName(name);
- let bornNum: number = bornDt.num;
- for (let i = 0; i < bornNum; ++i) {
- let randomId = bornDt.type == "s" ? npcHelper.getRandomSeniorZombieId() : npcHelper.getRandomZombieId();
- let offsetX = Utils.random(-80, 80);
- let offsetY = Utils.random(-80, 80);
- let pos = cc.v3(node.x + offsetX, node.y + offsetY);
- this.addZombie(randomId, pos);
- }
- });
- this.addZombieCbk();
- }
- private getZombieBornDtByName(name: string): { num: number, type: string } {
- if (name.indexOf('s') >= 0) {
- let nameArr = name.split('');
- return { num: +nameArr[1], type: 's' };
- } else {
- return { num: +name, type: 'c' };
- }
- }
- //是否已经初始化过玩家
- isInitedPlayer() {
- if (this.getPlayerArr().length > 0) {
- return true;
- }
- return false;
- }
- //初始化玩家
- iniPlayer() {
- if (this.isInitedPlayer()) {
- return;
- }
- var initCamerepos = cc.v2(0, 0);
- let playerDt = AccountModel.getInstance().playerDtList;
- for (let i = 0; i < playerDt.length; i++) {
- let bornNode = this.node.$playerBornNode //cc.v2(Math.random(), Math.random());
- let nd = this.playerNodePool.size() > 0 ? this.playerNodePool.get() : cc.instantiate(this.player_pre);
- let playerViewCom = nd.getChildByName('view').getComponent(PlayerView);
- let playerObjCom = nd.getComponent(PlayerObject);
- let randomID = playerDt[i].player_ID;
- this.object_parent.addChild(nd);
- playerObjCom.init(randomID, this.roles);
- playerViewCom.init(randomID);
- this.addBuffItem(randomID, nd);
- let pos = cc.v2(Math.random(), Math.random());
- nd.setPosition(bornNode.x + pos.x, bornNode.y + pos.y);
- if (i == 0) {
- initCamerepos = nd.getPosition();
- }
- }
- this.camera.setPosition(initCamerepos);
- this.randomLeader();
- this.addPlayerCbk();
- this.resetIsCover();
- }
- resetIsCover() {
- let dt = AccountModel.getInstance().playerDtList;
- if (dt.length > 0) {
- dt.forEach(element => {
- element.isCover = false;
- });
- }
- }
- update(dt: number) {
- this.cameraTrack(dt);
- //this.runBullets(dt);
- this.checkPlayerWithProp();
- this.checkPlayerBulletCrashZombie();
- this.isCloseDungeon();
- this.playerRunBuff(dt);
- this.checkPlayerWithNpc();
- //this.fast();
- // this.updateRoleDt();
- }
- updateRoleDt() {
- this.dtCount++;
- if (this.dtCount >= 30) {
- this.dtCount = 0;
- this.layInPlayerDt();
- AccountModel.getInstance().playerDtList = gameData.playerDtList;
- }
- }
- propAction(props) {
- let itemID = props.getComponent(UIFallitem).getID();
- let node = new cc.Node;
- node.addComponent(cc.Sprite);
- node.parent = this.node;
- node.setPosition(props.x, props.y);
- let ResName = itemDtManager.getItemResName(itemID);
- this.propsNodePool.put(props);
- bundleManager.setBundleFrame('UI', ResName, node);
- cc.tween(node)
- .to(0.2, { scale: 2, position: cc.v3(node.x, node.y + 50) })
- .to(0.2, { scale: 0 })
- .call(() => {
- this.propsNodePool.put(node);
- })
- .start();
- }
- gameOver() {
- this.removeNode();
- this.setPlayerDiePos();
- this.game_over = true;
- UITopMenu.getInstance().node.active = false;
- gameEventManager.emit(EVENT_TYPE.CANT_JOY, false);
- AccountModel.getInstance().playerDtList = [];
- AccountModel.getInstance().curPower = USER.init_powerNum;
- AccountModel.getInstance().curBullet = USER.init_bulletNum;
- AccountModel.getInstance().curDay = USER.init_day;
- gameData.init();
- gameData.isSetZomBie = false;
- zjSdk?.gameEnd(() => {
- UIHelp.ShowUI(UIFailView);
- })
- }
- /*复活*/
- gameRelive() {
- }
- //记录玩家死亡位置 方便复活用
- setPlayerDiePos() {
- let playerDt = AccountModel.getInstance().playerDtList;
- if (playerDt && playerDt.length > 0) {
- for (let i = 0; i < playerDt.length; ++i) {
- if (playerDt[i].is_leader) {
- this.playerDiePos = playerDt[i].pos;
- return;
- }
- }
- }
- }
- /**切换攻击模式 */
- switchAttackMode() {
- if (gameData.cur_attack_mode == ATTACK_MODE.close) {
- gameData.cur_attack_mode = ATTACK_MODE.remote;
- }
- else {
- gameData.cur_attack_mode = ATTACK_MODE.close;
- }
- gameEventManager.emit(EVENT_TYPE.attack_mode);
- }
- /**生成玩家
- * @param id 视图id
- * @param pos 生成位置
- */
- private addPlayer(id: number, pos: cc.Vec3) {
- // cc.log('增加npc', id, pos);
- let nd = cc.instantiate(this.player_pre);
- let playerViewCom = nd.getChildByName('view').getComponent(PlayerView);
- let playerObjCom = nd.getComponent(PlayerObject);
- nd.setPosition(pos);
- this.addBuffItem(id, nd);
- this.object_parent.addChild(nd);
- playerObjCom.init(id, this.roles);
- playerObjCom.setLeader(false);
- playerViewCom.init(id);
- gameData.curPeopleNum++;
- EventManager.emit(EVENT_TYPE.UPDATE_PEOPLE_NUM);
- this.addPlayerCbk();
- }
- addBuffItem(playerID, parent) {
- var path = null;
- if (playerID == 13) {
- path = 'main/egg';
- } else if (playerID == 19) {
- path = 'main/cake';
- }
- if (path) {
- let effNode = BenzAssetManager.getInstance().getAsset(AssetsHelper.EFF_obtain);
- let Prefb = cc.instantiate(effNode);
- Prefb.parent = parent;
- Prefb.y = 100;
- let node = new cc.Node
- node.parent = Prefb;
- node.addComponent(cc.Sprite);
- bundleManager.setBundleFrame('UI', path, node);
- }
- }
- /**生成僵尸
- * @param id 视图id
- * @param pos 生成位置
- */
- private addZombie(id: number, pos: cc.Vec3) {
- let nd = null;
- if (this.zombieNodePool.size() > 0) {
- nd = this.zombieNodePool.get();
- } else {
- nd = cc.instantiate(this.zombie_pre);
- }
- let comp = nd.getComponent(ZomBieObject);
- this.object_parent.addChild(nd);
- comp.init(id, pos, this.roles);
- this.addZombieCbk();
- }
- /**随机从解锁人员里选出领队 */
- private randomLeader() {
- let nds: cc.Node[] = this.getPlayerArr();
- if (nds.length == 0) {
- //console.log('所有玩家已死亡');
- return;
- }
- let index = Math.round(Math.random() * nds.length) - 1;
- index = index < 0 ? 0 : index;
- for (let i = 0; i < nds.length; i++) {
- let comp = nds[i].getComponent(PlayerObject);
- if (i == index) {
- comp.setLeader(true);
- }
- else {
- comp.setLeader(false);
- }
- }
- }
- /**检测玩家子弹与僵尸碰撞 */
- checkPlayerBulletCrashZombie() {
- let bs = this.getBullets();
- let zs = this.getZombies();
- for (let i = bs.length - 1; i >= 0; i--) {
- for (let j = zs.length - 1; j >= 0; j--) {
- let dis = this.getDis(bs[i], zs[j]);
- if (dis < 30) {
- // console.log('击中僵尸')
- let bc = bs[i].getComponent(BulletObject);
- let zc = zs[j].getComponent(ZomBieObject);
- let zv = zc.zombie_view;
- zv.hitEff();
- let hp = zc.zombie_prop.beHurt(bc.damage);
- if (hp == 0) {
- // console.log('僵尸死亡')
- effectManager.zombieDieEff(zs[j].parent.parent.$eff_parent, zs[j].getPosition());
- zs[j].destroy();
- zs.splice(j, 1);
- gameEventManager.emit(EVENT_TYPE.zombie_die);
- }
- bs[i].destroy();
- bs.splice(i, 1);
- break;
- }
- }
- }
- }
- /**检测玩解锁npc */
- checkPlayerWithNpc() {
- if (!this.node.$npc_parent) {
- return;
- }
- let dis = 200;
- let ps = this.getPlayerArr();
- let ns = this.node.$npc_parent.children;
- for (let i = 0; i < ps.length; i++) {
- for (let j = ns.length - 1; j >= 0; j--) {
- if (this.getDis(ps[i], ns[j]) < dis) {
- let npc_id = ns[j].getComponent(NpcObject).view_id;
- this.addPlayer(npc_id, ns[j].position);
- ns[j].destroy();
- }
- }
- }
- }
- /**检测玩家 */
- checkPlayerWithProp() {//检测玩家与道具作用
- let len = 50;
- let players = this.roles[0];
- let props = this.prop_parent.children;
- for (let i = players.length - 1; i >= 0; i--) {
- if (!cc.isValid(players[i])) {
- continue;
- }
- for (let j = props.length - 1; j >= 0; j--) {
- if (!cc.isValid(props[j])) {
- continue;
- }
- let dis = this.getDis(players[i], props[j]);
- if (dis < len) {
- let p_comp = players[i].getComponent(PlayerObject);
- let comp = props[j].getComponent(UIFallitem);
- switch (comp.getType()) {
- case 2: {
- this.getHeal(comp.getValue(), props[j]);
- AudioManager.play('pickup');
- break;
- }
- case 3: {
- this.getBullet(comp.getValue(), props[j]);
- AudioManager.play('pickup');
- break;
- }
- case 1: {
- this.getFood(comp.getValue(), props[j]);
- AudioManager.play('pickup');
- break;
- }
- case 4: {
- if (p_comp.player_prop.player_ID > 10) {
- continue;
- }
- this.getWeapon(comp.getID(), comp.getValue(), p_comp, true, props[j]);
- AudioManager.play('pickup');
- break;
- }
- case 5: {
- if (p_comp.player_prop.player_ID > 10) {
- continue;
- }
- this.getWeapon(comp.getID(), comp.getValue(), p_comp, false, props[j]);
- AudioManager.play('pickup');
- break;
- }
- }
- }
- }
- }
- }
- /**获取僵尸组 */
- getZombies(): cc.Node[] {
- let zs: cc.Node[] = [];
- let ch = this.object_parent.children;
- ch.forEach(function (z: cc.Node) {
- let comp = z.getComponent(GameObject);
- if (comp.type == GAME_OBJECT_TYPE.zombie) {
- zs.push(z);
- }
- });
- return zs;
- }
- /**获取两实体间的距离 */
- getDis(obj0: cc.Node, obj1: cc.Node): number {
- let dis = obj0.position.sub(obj1.position).mag();
- return dis;
- }
- /**
- * 出去副本 储存玩家数据
- */
- layInPlayerDt(cb?) {
- let playerList = this.roles[0];
- gameData.playerDtList = [];
- playerList.forEach((node) => {
- let propCom = node.getComponent(PlayerObject).player_prop;
- let playerDt = propCom.getPlayerDt();
- if (playerDt) {
- gameData.playerDtList.push(propCom.getPlayerDt());
- }
- })
- AccountModel.getInstance().playerDtList = gameData.playerDtList;
- Log.log(LOG_TAG.DEBUG, AccountModel.getInstance().playerDtList)
- this.scheduleOnce(() => {
- if (cb) {
- cb();
- }
- }, 0.06)
- }
- /**获取食物道具事件回调 */
- getFood(food: number, props: cc.Node) {
- this.propAction(props);
- gameData.curPowerNum += food;
- }
- /**获取子弹道具事件回调 */
- getBullet(bullet: number, props: cc.Node) {
- this.propAction(props);
- gameData.curBulletNum += bullet;
- }
- /**获得药箱事件回调 */
- getHeal(heal: number, props: cc.Node) {
- this.propAction(props);
- let players = this.getPlayerArr();
- players.forEach(function (player: cc.Node) {
- let comp = player.getComponent(PlayerObject);
- comp.player_prop.healHp(heal, player.getChildByName('view'));
- });
- }
- //靠近出口
- isCloseDungeon() {
- if (this.isClose) { return };
- let playerArr = this.getPlayerArr();
- let exportNode = this.node.$export_parent.$exportNode;
- if (!exportNode) return;
- for (let j = 0; j < playerArr.length; ++j) {
- let offset = 150;
- let min = playerArr[j].x >= (exportNode.x - offset);
- let max = playerArr[j].x <= (exportNode.x + offset);
- let minY = playerArr[j].y <= exportNode.y
- if (minY && min && max) {
- this.isClose = true;
- this.layInPlayerDt(() => {
- levelManager.open(AccountModel.getInstance().curLevel, () => {
- // gameData.curInDungeonType = null;
- dungeonManager.remove();
- this.removeNode();
- })
- });
- }
- }
- return false;
- }
- removeNode() {
- let playerList = this.getPlayerArr();
- let dogList = this.dogNode()
- if (playerList.length <= 0) {
- return;
- }
- for (let i = playerList.length - 1; i >= 0; i--) {
- playerList[i].destroy();
- }
- for (let i = dogList.length - 1; i >= 0; i--) {
- dogList[i].destroy();
- }
- }
- dogNode() {
- let nds: cc.Node[] = [];
- for (let nd of this.object_parent.children) {
- if (nd.name == 'dog_obj') {
- nds.push(nd);
- }
- }
- return nds;
- }
- /**获取武器事件回调 */
- getWeapon(id: number, damage: number, player: PlayerObject, is_close: boolean, props: cc.Node) {
- let drop: WeaponProp = null;
- if (is_close) {
- if (player.player_prop.close_weapon != null) {
- if (player.player_prop.close_weapon.damage < damage) {
- //更改近战武器
- drop = player.player_prop.close_weapon;
- player.player_prop.setWeapon(id, true);
- this.propAction(props);
- }
- }
- else {
- //更改近战武器
- player.player_prop.setWeapon(id, true);
- this.propAction(props);
- }
- }
- else {
- if (player.player_prop.remote_weapon != null) {
- if (player.player_prop.remote_weapon.damage < damage) {
- //更改远程武器
- drop = player.player_prop.remote_weapon;
- player.player_prop.setWeapon(id, false);
- this.propAction(props);
- }
- }
- else {
- //更改远程武器
- player.player_prop.setWeapon(id, false);
- this.propAction(props);
- }
- }
- if (drop != null) {
- //生成对应id武器道具
- let nd = cc.instantiate(this.prop_pre);
- this.prop_parent.addChild(nd);
- nd.setPosition(player.node.position);
- let comp = nd.getComponent(UIFallitem);
- comp.initItem(drop.id);
- }
- }
- /**玩家生成回调 */
- private addPlayerCbk() {
- this.roles[0] = this.getPlayerArr();
- }
- /**玩家死亡回调 */
- private diePlayerCbk() {
- this.roles[0] = this.getPlayerArr();
- }
- /**僵尸生成回调 */
- private addZombieCbk() {
- this.roles[1] = this.getZombies();
- }
- /**僵尸死亡回调 */
- private dieZombieCbk() {
- this.roles[1] = this.getZombies();
- }
- /**玩家远程步枪手枪子弹攻击回调
- * @param rad 发射角度
- * @param damage 子弹伤害
- * @param player 发射者
- */
- private playerRemoteAttack0(rad: number, damage: number, player: PlayerObject) {
- if (gameData.curBulletNum == 0) {
- return;
- }
- player.player_view.fireEff();
- gameData.curBulletNum--;
- let b = null;
- if (this.playerBulletPool.size() > 0) {
- b = this.playerBulletPool.get();
- } else {
- b = cc.instantiate(this.bullet_pre);
- }
- this.object_parent.addChild(b);
- let com = b.getComponent(BulletObject);
- com.init(player.node.position.add(cc.v3(0, 30, 0)), rad, damage, player);
- }
- /**玩家远程霰弹枪子弹攻击回调
- * @param rad 发射角度
- * @param damage 子弹伤害
- * @param player 发射者
- */
- private playerRemoteAttack1(rad: number, damage: number, player: PlayerObject) {
- if (gameData.curBulletNum == 0) {
- return;
- }
- gameData.curBulletNum--;
- damage *= 4;//单发合成一发,攻击*4
- let b = cc.instantiate(this.bullet_pre);
- this.object_parent.addChild(b);
- let com = b.getComponent(BulletObject);
- com.init(player.node.position.add(cc.v3(0, 30, 0)), rad, damage, player);
- }
- /**远程肉弹攻击回调
- * @param start_pos 开始位置
- * @param target_pos 目标位置
- */
- private zombieRemoteBoom(start_pos: cc.Vec3, target_pos: cc.Vec3) {
- }
- //获取玩家列表
- getPlayerArr() {
- let nds: cc.Node[] = [];
- for (let nd of this.object_parent.children) {
- if (nd.getComponent(GameObject).type == GAME_OBJECT_TYPE.player) {
- if (nd.getComponent(PlayerObject).player_prop.cur_state != ROLE_STATE.die) {
- nds.push(nd);
- }
- }
- }
- return nds;
- }
- /**获取子弹组 */
- getBullets(): cc.Node[] {
- let bs: cc.Node[] = [];
- let ch = this.object_parent.children;
- ch.forEach(function (b: cc.Node) {
- let comp = b.getComponent(GameObject);
- if (comp.type == GAME_OBJECT_TYPE.bullet) {
- bs.push(b);
- }
- });
- return bs;
- }
- /**摄像机跟随 */
- private cameraTrack(dt: number) {
- let dis = 500;
- let target: cc.Node = null;
- for (let p of this.object_parent.children) {
- let comp = p.getComponent(NodeMove);
- if (comp != null && comp.enabled) {
- target = p;
- break;
- }
- }
- if (target != null) {
- let v_sub = target.position.sub(this.camera.position);
- // if (v_sub.mag() > dis) {
- // v_sub = v_sub.normalize().mul(dis);
- // }
- this.camera.setPosition(this.camera.position.add(v_sub.mul(dt * 2)));
- }
- }
- /**运行玩家buff */
- playerRunBuff(dt: number) {
- this.buff_timer += dt;
- if (this.buff_timer > this.buff_dur) {
- this.buff_timer = 0;
- let self = this;
- let players: PlayerObject[] = [];
- this.getPlayerArr().forEach(function (nd: cc.Node) {
- players.push(nd.getComponent(PlayerObject));
- });
- players.forEach(function (player: PlayerObject) {
- let b_id = player.player_prop.buff_id;
- if (b_id == 0) {
- return;
- }
- let buff = self.buffs[b_id - 1];
- players.forEach(function (i_player, idx, players) {
- i_player.player_prop.healHp(buff[1], players[idx].node.getChildByName('view'));
- });
- if (buff[0] > 0) {
- gameData.curBulletNum += buff[0];
- }
- if (buff[2] > 0) {
- gameData.curPowerNum += buff[2];
- }
- });
- }
- }
- /**性能优化 */
- fast() {
- let mapWall = this.node.$map_parent.$map.$wall.children;
- let mapDecoration = this.node.$map_parent.$map.$TheDecoration.children;
- this.nodeIsActive(mapWall);
- this.nodeIsActive(mapDecoration);
- }
- nodeIsActive(nodeArr: cc.Node[]) {
- if (!nodeArr) { return };
- let self = this;
- let sw = (cc.winSize.width / 2) + 120;
- nodeArr.forEach(function (nd: cc.Node) {
- let rl = Math.sqrt(Math.pow(nd.width, 2) + Math.pow(nd.height, 2)) / 2;
- if (self.getDis(nd, self.camera) > rl + sw) {
- if (nd.active == true) {
- nd.active = false;
- }
- }
- else {
- if (nd.active == false) {
- nd.active = true;
- }
- }
- });
- }
- }
|