You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.5 KiB
97 lines
3.5 KiB
|
1 week ago
|
/**
|
||
|
|
* 激光武器持续攻击
|
||
|
|
*/
|
||
|
|
import { _decorator, Component, sp, v3, Vec3 } from 'cc';
|
||
|
|
|
||
|
|
import BombSpine from '../WeaponSkill/BombSpine';
|
||
|
|
import { GBundle } from '../../../game/ConfigRes';
|
||
|
|
import { ConstManager, ConstEnum } from '../../../manager/ConstManager';
|
||
|
|
import { MonsterType } from '../../../manager/MonsterDataManager';
|
||
|
|
import { Monster } from '../Monster';
|
||
|
|
import { BattlePerformance } from '../BattlePerformance';
|
||
|
|
const { ccclass, property } = _decorator;
|
||
|
|
|
||
|
|
@ccclass('SingleBombProp')
|
||
|
|
export class SingleBombProp extends Component {
|
||
|
|
|
||
|
|
_dt: number = 0
|
||
|
|
isStartTime: boolean = false
|
||
|
|
propertyArr: number[] = []
|
||
|
|
isPlayAudio: boolean = false
|
||
|
|
|
||
|
|
start() {
|
||
|
|
this.init()
|
||
|
|
}
|
||
|
|
protected update(dt: number): void {
|
||
|
|
if (!gg.game.CurentBattle.canUpdateFrame()) return;
|
||
|
|
if (!this.isStartTime) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if (!this.isPlayAudio) {
|
||
|
|
this.isPlayAudio = true
|
||
|
|
gg.audio.playEffect({ name: '2秒定时', path: 'sound/武器音效/' });
|
||
|
|
}
|
||
|
|
this._dt += dt * gg.game.CurentBattle.TimeScale;
|
||
|
|
if (this._dt >= this.propertyArr[0]) {
|
||
|
|
this._dt = 0
|
||
|
|
this.isStartTime = false
|
||
|
|
let spineName = '汽水炸弹落地'
|
||
|
|
this.playColaBomb(spineName, this.node.worldPosition.clone(), 1)
|
||
|
|
//爆炸范围内的怪物
|
||
|
|
console.log('汽水炸弹爆炸范围内的怪物==', this.propertyArr[1])
|
||
|
|
let bombMonsters = gg.game.CurentBattle.MonsterSpawner.getMonstersInArea(this.node.worldPosition, this.propertyArr[1]);
|
||
|
|
bombMonsters.forEach(monster => {
|
||
|
|
let totalHp = monster.getComponent(Monster).getTotalHP()
|
||
|
|
let isBoss = monster.getComponent(Monster).getMonsterType() == MonsterType.Boss
|
||
|
|
if (isBoss && this.propertyArr[3] == 0) {
|
||
|
|
|
||
|
|
} else {
|
||
|
|
monster.getComponent(Monster).subHP(-1, totalHp * this.propertyArr[2] / 10000, false, 1, true)
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
init() {
|
||
|
|
this.isStartTime = true
|
||
|
|
this.isPlayAudio = false
|
||
|
|
let str = ConstManager.getConstStringById(ConstEnum.BombPropRange)
|
||
|
|
let idArr = str.split(',').map(item => parseInt(item))
|
||
|
|
this.propertyArr = idArr
|
||
|
|
}
|
||
|
|
/**汽水炸弹爆炸 */
|
||
|
|
public playColaBomb(bombSpine: string, pos: Vec3, scale: number) {
|
||
|
|
//gg.audio.playEffect({ name: '汽水炸弹爆炸', path: 'sound/武器音效/' });
|
||
|
|
let bombComp = this.createBombComponent(bombSpine, pos, scale)
|
||
|
|
if (!bombComp) return;
|
||
|
|
bombComp.playSpine('play', () => {
|
||
|
|
bombComp.destoryNode()
|
||
|
|
}, 1, false)
|
||
|
|
}
|
||
|
|
/**生成爆炸Component */
|
||
|
|
public createBombComponent(bombSpine: string, pos: Vec3, scale: number) {
|
||
|
|
if (!BattlePerformance.rollShowCombatVfx()) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
let spineNode = gg.res.getNode(`prefab/爆炸/`, `${bombSpine}`, GBundle.BattleGameWeapon)
|
||
|
|
if (!spineNode) {
|
||
|
|
console.warn('[SingleBombProp] bombSpine 未就绪=', bombSpine);
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
const mapNode = gg.game.CurentBattle?.Map?.node ?? gg.game.CurentBattle?.curMap?.node;
|
||
|
|
if (!mapNode?.isValid) {
|
||
|
|
gg.res.putNode(spineNode);
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
spineNode.setParent(mapNode);
|
||
|
|
spineNode.setWorldPosition(pos)
|
||
|
|
const adj = BattlePerformance.adjustVfxScale(scale);
|
||
|
|
spineNode.scale = v3(adj, adj, 0)
|
||
|
|
|
||
|
|
let bombComp = spineNode.getComponent(BombSpine);
|
||
|
|
return bombComp
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|