|
@@ -1,4 +1,4 @@
|
|
-import { _decorator, Collider, Enum, Node, RigidBody, SkeletalAnimation, Vec3 } from 'cc';
|
|
|
|
|
|
+import { _decorator, Collider, Enum, Node, RigidBody, Animation, Vec3 } from 'cc';
|
|
import { BaseExp } from '../core/base/BaseExp';
|
|
import { BaseExp } from '../core/base/BaseExp';
|
|
import { PoolManager } from '../core/manager/PoolManager';
|
|
import { PoolManager } from '../core/manager/PoolManager';
|
|
import { userIns } from '../data/UserData';
|
|
import { userIns } from '../data/UserData';
|
|
@@ -10,8 +10,11 @@ import { Enemy, EPartType } from './Enemy';
|
|
import { audioMgr } from '../core/manager/AudioManager';
|
|
import { audioMgr } from '../core/manager/AudioManager';
|
|
import { Constants } from '../data/Constants';
|
|
import { Constants } from '../data/Constants';
|
|
import MsgHints from '../utils/MsgHints';
|
|
import MsgHints from '../utils/MsgHints';
|
|
-
|
|
|
|
const { ccclass, property } = _decorator;
|
|
const { ccclass, property } = _decorator;
|
|
|
|
+
|
|
|
|
+//沙袋堆动画
|
|
|
|
+const sandbge_take = "take"
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 战场障碍物类型
|
|
* 战场障碍物类型
|
|
*/
|
|
*/
|
|
@@ -31,10 +34,8 @@ export enum ObstacleType {
|
|
*/
|
|
*/
|
|
@ccclass('Sundries')
|
|
@ccclass('Sundries')
|
|
export class Sundries extends BaseExp {
|
|
export class Sundries extends BaseExp {
|
|
- @property({ type: Enum(ObstacleType), tooltip: "SANDBAG_PILE: 沙袋堆 OIL_BARREL: 油桶 MILITARY_TRUCK: 军车 SMALL_SANDBAG: 小沙袋 ", displayName: "障碍物类型"})
|
|
|
|
|
|
+ @property({ type: Enum(ObstacleType), tooltip: "沙袋堆:SANDBAG_PILE 油桶:OIL_BARREL 军车: MILITARY_TRUCK 小沙袋:SMALL_SANDBAG", displayName: "障碍物类型"})
|
|
public obstacleType: ObstacleType = ObstacleType.SANDBAG_PILE;
|
|
public obstacleType: ObstacleType = ObstacleType.SANDBAG_PILE;
|
|
- @autoBind({type: SkeletalAnimation,tooltip: "杂物动画节点"})
|
|
|
|
- public skeletal: SkeletalAnimation = null!;
|
|
|
|
|
|
|
|
//杂物信息数据
|
|
//杂物信息数据
|
|
public data: any = null;
|
|
public data: any = null;
|
|
@@ -42,14 +43,10 @@ export class Sundries extends BaseExp {
|
|
private isDead: boolean = false;
|
|
private isDead: boolean = false;
|
|
//杂物当前的总血量
|
|
//杂物当前的总血量
|
|
private totalHp: number = 0;
|
|
private totalHp: number = 0;
|
|
- //杂物身上的Collider
|
|
|
|
- public collider: Collider = null!;
|
|
|
|
|
|
|
|
start() {
|
|
start() {
|
|
- this.collider = this.node.getComponent(Collider);
|
|
|
|
- if(this.collider){
|
|
|
|
- this.collider["args"] = [EPartType.sundries,this];
|
|
|
|
- }
|
|
|
|
|
|
+ //给碰撞体绑定数据
|
|
|
|
+ this.setupColliders(this.node);
|
|
//根据障碍物类型设置总血量
|
|
//根据障碍物类型设置总血量
|
|
let sundrie_id: number = -1;
|
|
let sundrie_id: number = -1;
|
|
switch (this.obstacleType) {
|
|
switch (this.obstacleType) {
|
|
@@ -103,30 +100,31 @@ export class Sundries extends BaseExp {
|
|
public scrap(){
|
|
public scrap(){
|
|
switch (this.obstacleType) {
|
|
switch (this.obstacleType) {
|
|
case ObstacleType.SANDBAG_PILE:{//沙袋堆
|
|
case ObstacleType.SANDBAG_PILE:{//沙袋堆
|
|
- if(this.skeletal)return;
|
|
|
|
|
|
+ let skeletal:Animation = this.node.getComponent(Animation);
|
|
|
|
+ if(!skeletal)return;
|
|
//沙袋掀开的动画
|
|
//沙袋掀开的动画
|
|
- this.skeletal.play('take');
|
|
|
|
- this.scheduleOnce(this.recycle.bind(this), 1.5);
|
|
|
|
|
|
+ skeletal.play(sandbge_take);
|
|
|
|
+ skeletal.scheduleOnce(()=>{
|
|
|
|
+ skeletal.pause();
|
|
|
|
+ },0.9);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case ObstacleType.OIL_BARREL:{//油桶
|
|
case ObstacleType.OIL_BARREL:{//油桶
|
|
- //油漆桶爆炸动画
|
|
|
|
|
|
+ //油漆桶音效
|
|
audioMgr.playOneShot(Constants.audios.Oildrum_explosion);
|
|
audioMgr.playOneShot(Constants.audios.Oildrum_explosion);
|
|
//爆炸后生成爆炸特效 粒子路径、自动回收时间、外部设置回调
|
|
//爆炸后生成爆炸特效 粒子路径、自动回收时间、外部设置回调
|
|
ResUtil.playParticle(
|
|
ResUtil.playParticle(
|
|
`effects/Prefabs/OilBoom`,
|
|
`effects/Prefabs/OilBoom`,
|
|
4,
|
|
4,
|
|
(particle) => {
|
|
(particle) => {
|
|
- particle.position = new Vec3(0.1,0.1, 0.1);
|
|
|
|
- particle.children.forEach((c) => {
|
|
|
|
- c.position = new Vec3(0.1, 0.1, 0.1);
|
|
|
|
- });
|
|
|
|
|
|
+ particle.position = new Vec3(0.2,0.2,0.2);
|
|
particle.parent = Game.I.map.node;
|
|
particle.parent = Game.I.map.node;
|
|
- particle.worldPosition = this.node.worldPosition.clone();
|
|
|
|
|
|
+ const targetPos: Vec3 = this.node.worldPosition.clone();
|
|
|
|
+ particle.worldPosition = targetPos;
|
|
particle.active = true;
|
|
particle.active = true;
|
|
this.recycle();
|
|
this.recycle();
|
|
//爆炸后生成爆炸伤害
|
|
//爆炸后生成爆炸伤害
|
|
- this.explosionDamage();
|
|
|
|
|
|
+ this.explosionDamage(targetPos);
|
|
}
|
|
}
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -137,21 +135,23 @@ export class Sundries extends BaseExp {
|
|
.then((military: Node | null) => {
|
|
.then((military: Node | null) => {
|
|
if(!military)return;
|
|
if(!military)return;
|
|
military.active = true;
|
|
military.active = true;
|
|
- military.parent = Game.I.map.node;
|
|
|
|
- military.worldPosition = this.node.worldPosition.clone();
|
|
|
|
|
|
+ military.parent = this.node.parent;
|
|
|
|
+ const targetPos: Vec3 = this.node.worldPosition.clone();
|
|
|
|
+ military.worldPosition = targetPos;
|
|
|
|
+ military.eulerAngles = this.node.eulerAngles.clone();
|
|
|
|
+ military.scale = this.node.scale.clone();
|
|
//回收原有的军车
|
|
//回收原有的军车
|
|
this.recycle();
|
|
this.recycle();
|
|
//播放爆炸过后的浓烟
|
|
//播放爆炸过后的浓烟
|
|
ResUtil.playParticle(
|
|
ResUtil.playParticle(
|
|
`effects/Prefabs/HeavySmoke`,
|
|
`effects/Prefabs/HeavySmoke`,
|
|
- 4,
|
|
|
|
|
|
+ 3,
|
|
(particle) => {
|
|
(particle) => {
|
|
particle.parent = Game.I.map.node;
|
|
particle.parent = Game.I.map.node;
|
|
- particle.worldPosition = this.node.worldPosition.clone();
|
|
|
|
|
|
+ particle.worldPosition = targetPos;
|
|
particle.active = true;
|
|
particle.active = true;
|
|
- particle.scale = new Vec3(0.5, 0.5, 0.5);
|
|
|
|
//爆炸后生成爆炸伤害
|
|
//爆炸后生成爆炸伤害
|
|
- this.explosionDamage();
|
|
|
|
|
|
+ this.explosionDamage(targetPos);
|
|
}
|
|
}
|
|
);
|
|
);
|
|
});
|
|
});
|
|
@@ -186,25 +186,39 @@ export class Sundries extends BaseExp {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 爆炸物产生爆炸伤害
|
|
* 爆炸物产生爆炸伤害
|
|
- * @returns
|
|
|
|
|
|
+ * @param targetPos 爆炸物的位置
|
|
*/
|
|
*/
|
|
- public explosionDamage(){
|
|
|
|
|
|
+ public explosionDamage(targetPos: Vec3){
|
|
//爆炸半径
|
|
//爆炸半径
|
|
- const eRadius: number = this.data.explosion_radius;
|
|
|
|
|
|
+ const eRadius: number = this.data.explosion_radius / 10;
|
|
const allEnemys = Game.I.buildEnemys.allEnemys.filter(e=>!e.isDead);
|
|
const allEnemys = Game.I.buildEnemys.allEnemys.filter(e=>!e.isDead);
|
|
if(allEnemys.length <= 0)return;
|
|
if(allEnemys.length <= 0)return;
|
|
//爆炸伤害
|
|
//爆炸伤害
|
|
const damage: number = this.data.explosion_injury;
|
|
const damage: number = this.data.explosion_injury;
|
|
allEnemys.forEach((e: Enemy) => {
|
|
allEnemys.forEach((e: Enemy) => {
|
|
const ePos: Vec3 = e.node.worldPosition;
|
|
const ePos: Vec3 = e.node.worldPosition;
|
|
- const sPos: Vec3 = this.node.worldPosition;
|
|
|
|
- const distance = ePos.clone().subtract(sPos).length();
|
|
|
|
|
|
+ const distance = ePos.clone().subtract(targetPos).length();
|
|
if(distance <= eRadius) {
|
|
if(distance <= eRadius) {
|
|
e.subHP(damage, this.data);
|
|
e.subHP(damage, this.data);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 递归设置所有子节点的Collider参数
|
|
|
|
+ * @param node 起始节点
|
|
|
|
+ */
|
|
|
|
+ private setupColliders(node: Node) {
|
|
|
|
+ const collider = node.getComponent(Collider);
|
|
|
|
+ if(collider){
|
|
|
|
+ collider["args"] = [EPartType.sundries, this];
|
|
|
|
+ }
|
|
|
|
+ //递归处理所有子节点
|
|
|
|
+ node.children.forEach(child => {
|
|
|
|
+ this.setupColliders(child);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 杂物回收
|
|
* 杂物回收
|
|
*/
|
|
*/
|