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

161 lines
5.7 KiB

import { _decorator, CCBoolean, CCInteger, Collider2D, Component, Contact2DType, IPhysics2DContact, Label, Node, tween, Tween, v3 } from 'cc';
import { atgSkill } from './atgSkill';
import MTools from 'db://assets/mx/tools/MTools';
import { gaoyaguo } from './gaoyaguo';
import { GEvent } from 'db://assets/mx/module/event/GEvent';
const { ccclass, property } = _decorator;
@ccclass('atgDoor')
export class atgDoor extends Component {
@property(CCBoolean)
isLock: boolean = false; //是否锁定
@property(CCBoolean)
isMove: boolean = false; //是否移动
@property(CCInteger)
doorNumber: number = 0; //门上的数字
@property(CCBoolean)
isZidanDestroy: boolean = false; //是否子弹销毁
//方向
@property(CCInteger)
direction: number = 0; //方向 0 上 1主角
attackEffect:Node = null;
labNode:Label = null;
subNum = 1
/** 已绑定 BEGIN_CONTACT 的碰撞体(含子节点,避免碰撞盒做在子物体上时进不了 onBeginContact) */
private _boundColliders: Collider2D[] = [];
protected onEnable(): void {
this._unbindDoorColliders();
const all = this.node.getComponentsInChildren(Collider2D);
for (const col of all) {
const doorOnSameNode = col.node.getComponent(atgDoor);
if (doorOnSameNode && doorOnSameNode !== this) {
continue;
}
col.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
this._boundColliders.push(col);
}
}
protected onDisable(): void {
this._unbindDoorColliders();
}
private _unbindDoorColliders(): void {
for (const col of this._boundColliders) {
if (col?.isValid) {
col.off(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
}
this._boundColliders.length = 0;
}
protected start(): void {
this.attackEffect = this.node.getChildByName('攻击效果');
this.labNode = this.node?.getChildByName('lab')?.getComponent(Label);
if(this.labNode){
if(this.doorNumber>0){
this.labNode.string ='x'+ this.doorNumber.toString();
}else{
this.labNode.string =this.doorNumber.toString();
}
}
}
onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null){
//selfCollider 门
//otherCollider 子弹
// 忽略“由本门生成的子弹”在生成瞬间与本门的碰撞,避免递归触发卡死
const bulletSkill = otherCollider.getComponent(atgSkill);
if (bulletSkill?.owner == 'player') {
return
}
if (bulletSkill?.isRecycling) {
return;
}
let zidanTakeNumber = bulletSkill?.zidanTakeNumber ?? 1;
// 同一颗子弹对同一扇门只处理一次(避免飞行过程中重复进入 onBeginContact)
if (bulletSkill?.processedDoorUuids?.[this.node.uuid]) {
return;
}
if (bulletSkill) {
bulletSkill.processedDoorUuids[this.node.uuid] = true;
}
// 永久忽略:同一扇门生成的子弹再次碰到同门时不处理(防止 x5 这类倍率门指数递归)
if (bulletSkill?.generatedByDoorUuid === this.node.uuid && !this.isLock) {
return;
}
if (bulletSkill?.ignoreDoorUuid === this.node.uuid && (bulletSkill.ignoreContactFrames ?? 0) > 0 && !this.isLock) {
return;
}
if(bulletSkill?.ignoreContactFrames == this.doorNumber && this.doorNumber > 0 && !this.isLock){
return;
}
bulletSkill.setIsDie(true)
if (!MTools.beforeTimes(110, "attackEffect") && this.attackEffect) {
this.attackEffect.active = true
this.attackEffect.scale = v3(0.1,0.1,0.1)
tween(this.attackEffect)
.to(0.1,{scale:v3(1,1,1)})
.call(()=>{
this.attackEffect.active = false
})
.start()
}
if(this.isLock && this.labNode){
//锁起来了 数字变化
this.doorNumber -= this.subNum;
this.labNode.string ='x'+ this.doorNumber.toString();
if(this.doorNumber<=0){
this.node.active = false
gaoyaguo.Instance.jiedianIndex = 4
}
}else {
//没有被锁
//子弹变化中,穿过门的变化
if(this.doorNumber>0){
//子弹变多 ,当前这个子弹移除,创建多个新子弹攻击
if( gaoyaguo.Instance.jiedianIndex == 2 ){
//当前阶段打高压锅
GEvent.Ins.emit(GEvent.gaoyaguoAttack,this.doorNumber, this.node);
}else if( gaoyaguo.Instance.jiedianIndex == 3 || gaoyaguo.Instance.jiedianIndex == 4){
//当前阶段子弹飞向主角
if((this.doorNumber == 30 || this.doorNumber == 20) && gaoyaguo.Instance.jiedianIndex == 3 ){
return
}
GEvent.Ins.emit(GEvent.gaoyaguoAttackToPlayer,this.doorNumber, this.node,zidanTakeNumber);
}
}else{
//子弹减少子弹本身就是1,击中之后直接移除
if(this.isZidanDestroy){
// 只消化敌方子弹,避免主角自己发射的子弹碰到“消化门/区域”导致自吞
GEvent.Ins.emit(GEvent.hitZhujue,zidanTakeNumber)
}
}
}
//击中效果
bulletSkill?.removeZidan();
}
}