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

170 lines
5.8 KiB

import { _decorator, Component, instantiate, Node, sp, tween, v3, Vec3 } from 'cc';
import { IWeaponProperty, SaveBattleDataType, SpecialSkillType } from '../BattleDataManager';
import { Skill } from './Skill';
const { ccclass, property } = _decorator;
@ccclass('FireworksGyro')
export class FireworksGyro extends Component {
rotateNode: Node = null;
animNode: sp.Skeleton = null;
protected onLoad(): void {
this.rotateNode = this.node.find('烟花');
this.animNode = this.node.find('陀螺')?.getComponent(sp.Skeleton);
}
/** 旋转速度,单位为度每秒 */
angleSpeed: number = 360;
Count = 3;
angleInterval = 120;
/**存在时间,单位为秒 */
existTime: number = 0.5;
/**武器的基础配置数据 */
weaponData: ITableWeapon2;
/**武器的伤害属性 */
weaponPropertyData: IWeaponProperty;
isStart: boolean = false;
isMoveNew = false;
moveTarget: Vec3 = null;
canMoveCount = 1;
moveSpeed: number = 100;
setData(weaponData: ITableWeapon2, weaponPropertyData: IWeaponProperty) {
this.rotateNode = this.node.find('烟花');
this.animNode = this.node.find('陀螺')?.getComponent(sp.Skeleton);
this.weaponData = weaponData;
this.weaponPropertyData = weaponPropertyData;
this.isStart = true;
this.Count = weaponPropertyData.fireworkCount;
this.angleSpeed = 360 / weaponPropertyData.rotateSpeed;
this.angleInterval = 360 / this.Count;
this.existTime = weaponPropertyData.weaponExistTime;
this.rotateNode.active = true;
this.moveSpeed = weaponPropertyData.speed;
this.canMoveCount = 1;
this.initItem();
}
protected update(dt: number): void {
if (!gg.game.CurentBattle.canUpdateFrame()) return;
if (!this.isStart) return;
const scaledDt = dt * gg.game.CurentBattle.TimeScale;
this.existTime -= scaledDt;
if (this.existTime <= 0)
this.endAtk();
this.rotateNode.angle += this.angleSpeed * scaledDt;
if (this.isMoveNew && this.moveTarget) {
const wp = this.node.worldPosition;
const dx = this.moveTarget.x - wp.x;
const dy = this.moveTarget.y - wp.y;
const dz = this.moveTarget.z - wp.z;
const distSq = dx * dx + dy * dy + dz * dz;
const reachThresholdSq = 120 * 120;
if (distSq <= reachThresholdSq) {
const tx = this.moveTarget.x;
const ty = this.moveTarget.y;
const tz = this.moveTarget.z;
this.isMoveNew = false;
this.node.setWorldPosition(tx, ty, tz);
this.moveTarget = null;
return;
}
const dist = Math.sqrt(distSq);
const step = this.moveSpeed * scaledDt;
const ratio = step / dist;
this.node.setWorldPosition(
wp.x + dx * ratio,
wp.y + dy * ratio,
wp.z + dz * ratio
);
}
}
initItem() {
for (let i = 0; i < this.rotateNode.children.length; i++) {
this.rotateNode.children[i].active = false;
}
for (let i = 0; i < this.Count; i++) {
let n: Node = null;
if (i < this.rotateNode.children.length) {
n = this.rotateNode.children[i];
} else {
n = instantiate(this.rotateNode.children[0]);
this.rotateNode.addChild(n);
}
n.active = true;
n.angle = this.angleInterval * i;
let commp: Skill = n.getOrAddComponent(Skill);
commp.isGyroBullet = true;
commp.setData(this.weaponData, v3(0, 0, 0));
}
let animIndex = Math.max(3, Math.min(6, this.Count));
this.animNode.setAnimation(0, animIndex + "开始", false);
this.animNode.timeScale = this.angleSpeed / 360;
this.animNode.setCompleteListener(() => {
this.animNode.setCompleteListener(null);
this.animNode.setAnimation(0, animIndex + "喷射循环", true);
})
}
endAtk() {
// let buff = this.weaponPropertyData.specialSkillInfo;
// if (buff.length > 0) {
// let str = buff[0];
// let arr = str.split(",");
// if (arr.length > 0) {
// let s = arr[0];
// if (s != "") {
// let type = Number(s);
// if (type == SpecialSkillType.fireworkGyroSpecial) {
// this.moveNew();
// return;
// }
// }
// }
// }
this.remove();
}
moveNew() {
if (this.canMoveCount > 0) {
let targetArr = gg.game.CurentBattle.MonsterSpawner.getFireworkGyroTargetMonster(this.node.worldPosition, 1, true);
if (targetArr.length > 0) {
this.moveTarget = targetArr[0].worldPosition;
this.isMoveNew = true;
this.existTime = this.weaponPropertyData.weaponExistTime;
this.canMoveCount--;
return;
} else {
this.remove();
}
}
this.remove();
}
remove() {
this.rotateNode.active = false;
tween(this.node)
.to(0.5, { opacity: 0 })
.call(() => {
// 避免 destroy 造成 GC:使用资源池归还
gg.res.putNode(this.node);
})
.start();
// let animIndex = Math.max(3, Math.min(6, this.Count));
// this.animNode.setAnimation(0, animIndex + "结束", false);
// this.scheduleOnce(() => {
// this.node.destroy();
// }, 0.5);
//gg.res.putNode(this.node);
}
}