消消方块阵换皮表情
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.
 
 
 

158 lines
5.2 KiB

/**
* 龙卷风持续攻击
*/
import { _decorator, Component, Tween, tween, v3, Vec3 } from 'cc';
import { BattleDataManager, IWeaponProperty } from '../BattleDataManager';
import { Monster } from '../Monster';
const { ccclass, property } = _decorator;
@ccclass('TornadoContinueSchedule')
export class TornadoContinueSchedule extends Component {
_dt:number = 0;
_weaponid:number = 0;
_addBuffInterval:number = 1;
_repeatCount:number = 1;
curRepeatCount:number = 0;
// _allDamage:number = 0;
_damageRadius:number = 0;
// _isCrit:boolean = false;
pointCount: number = 5;
moveDuration: number = 1.0; // 每段移动时间(秒)
radius: number = 100; // 移动半径
centerPos:Vec3 = new Vec3(); // 中心点位置
points: Vec3[] = []; // 等分点位置数组
currentPath: Vec3[] = []; // 当前移动路径
currentIndex: number = 0; // 当前路径索引
start() {
}
update(deltaTime: number) {
if (!gg.game.CurentBattle.canUpdateFrame()) return;
this._dt += deltaTime * gg.game.CurentBattle.TimeScale;
if(this._dt >= this._addBuffInterval){
this._dt = 0
this.curRepeatCount++
// console.log('龙卷风造成一次伤害')
const bombMonsters = gg.game.CurentBattle.MonsterSpawner.getMonstersInArea(this.centerPos, this._damageRadius);
for (let i = 0; i < bombMonsters.length; i++) {
const monster = bombMonsters[i];
const monsterComp = monster.getComponent(Monster);
monsterComp.attackByWeapon(this._weaponid);
}
if(this.curRepeatCount >= this._repeatCount){
this.destroyNode()
}
}
}
destroyNode(){
//移除当前脚本
this.removeSelf()
gg.res.putNode(this.node)
}
atkToMonster(weaponId,centerPos,weaponProperty:IWeaponProperty){
this._weaponid = weaponId
this.centerPos = centerPos
this._dt = 0
this._addBuffInterval = weaponProperty.damageInterval
this._repeatCount = Math.floor(weaponProperty.weaponContinueTime/weaponProperty.damageInterval)
// this._allDamage = weaponProperty.allAtk
this._damageRadius = weaponProperty.explodeRadius
// this._isCrit = weaponProperty.isCrit
this.initializeMovement()
}
removeSelf() {
this.destroy()
}
onDestroy() {
// console.log('TornadoContinueSchedule组件已被移除');
}
/**
* 初始化龙卷风移动
* @param center 中心点位置(默认为当前节点位置)
*/
initializeMovement() {
this.pointCount = 5;
this.moveDuration = 1.0; // 每段移动时间(秒)
this.radius = 100; // 移动半径
this.points = []; // 等分点位置数组
this.currentPath = []; // 当前移动路径
this.currentIndex = 0; // 当前路径索引
// 生成等分点
this.generatePoints();
// 生成初始路径
this.generateNewPath();
// 开始移动
this.moveToNextPoint();
}
/**
* 生成等分点位置
*/
private generatePoints() {
this.points = [];
const angleStep = (2 * Math.PI) / this.pointCount;
for (let i = 0; i < this.pointCount; i++) {
const angle = i * angleStep;
const x = this.centerPos.x + this.radius * Math.cos(angle);
const y = this.centerPos.y + this.radius * Math.sin(angle);
const z = this.centerPos.z;
this.points.push(v3(x, y, z));
}
}
/**
* 生成新的移动路径
*/
private generateNewPath() {
// 复制点数组并随机排序(排除当前点)
const availablePoints = [...this.points];
this.shuffleArray(availablePoints);
this.currentPath = availablePoints;
this.currentIndex = 0;
}
/**
* 数组随机排序(Fisher-Yates洗牌算法)
*/
private shuffleArray(array: any[]) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
/**
* 移动到下一个点
*/
private moveToNextPoint() {
// console.log('移动到下一个点',this.currentIndex,this.currentPath)
// 如果当前路径已经走完,生成新路径
if (this.currentIndex >= this.currentPath.length) {
this.generateNewPath();
}
const targetPos = this.currentPath[this.currentIndex];
this.currentIndex++;
// 计算移动速度变化(随机速度变化,但保持总时间不变)
const actualDuration = this.moveDuration * (0.8 + Math.random() * 0.4); // 0.8-1.2倍速度变化
// 使用tween实现移动
Tween.stopAllByTarget(this.node);
tween(this.node)
.to(actualDuration, { worldPosition: targetPos.clone() })
.call(() => {
// 移动完成后继续下一个点
this.moveToNextPoint();
})
.start();
}
}