123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import BaseEvent from "../fight/evnet/base/BaseEvent";
- import FSprite from "../fight/object/FSprite";
- /**
- * 地刺
- */
- const { ccclass, property } = cc._decorator;
- interface ThornSprite {
- isAtk: boolean,
- sprite: FSprite
- }
- @ccclass
- export default class JG0108 extends BaseEvent {
- @property({
- displayName: '数值(怪物id)'
- })
- public monsterId = 1001;
- @property({
- displayName: '地刺出现间隔时间'
- })
- public interval = 2;
- @property({
- type: sp.Skeleton,
- displayName: '地刺动画'
- })
- public spine: sp.Skeleton = null;
- private isAtk = false;
- private isPause = false;
- //当前处于碰撞区域的对象
- private spriteList: Array<ThornSprite> = [];
- start() {
- this.run();
- }
- update(dt) {
- if (!this.ff.lockCamera) {
- if (!this.ff.lockCamera != this.isPause) {
- this.isPause = true;
- if (this.spine) {
- this.spine.paused = true;
- }
- return
- }
- } else {
- if (!this.ff.lockCamera != this.isPause) {
- this.isPause = false;
- if (this.spine) {
- this.spine.paused = false;
- }
- }
- }
- if (this.isAtk) {
- this.spriteList.forEach(element => {
- this.rmHP(element);
- });
- }
- }
- private rmHP(thornSprite: ThornSprite) {
- if (thornSprite.isAtk) {
- return;
- }
- if (thornSprite.sprite.hp <= 0) {
- return;
- }
- thornSprite.isAtk = true;
- let main = this.ff.main;
- let attrData = main.sManage.getMonsterData(this.monsterId);
- thornSprite.sprite.bAtkjs(attrData);
- }
- private run() {
- this.spriteList.forEach(element => {
- element.isAtk = false;
- });
- if (!this.interval) {
- this.isAtk = true;
- } else {
- cc.tween(this).sequence(
- cc.delayTime(this.interval),
- cc.callFunc(() => {
- this.playAtk();
- })
- ).start()
- }
- }
- private playAtk() {
- this.isAtk = true;
- this.spine.setAnimation(0, 'atk', false);
- this.spine.setCompleteListener(() => {
- this.isAtk = false;
- this.spine.setCompleteListener(null);
- this.spine.setAnimation(0, 'idle', true);
- this.run()
- });
- }
- onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, other: cc.PhysicsCollider) {
- if (other.node.group == 'A') {
- let obj = other.node.getComponent(FSprite);
- this.ff = obj.ff;
- this.pushSprite(obj);
- }
- }
- onEndContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, other: cc.PhysicsCollider) {
- if (other.node.group == 'A') {
- let obj = other.node.getComponent(FSprite);
- this.removeSprite(obj);
- }
- }
- private pushSprite(sprite: FSprite) {
- for (let i = 0; i < this.spriteList.length; i++) {
- const element = this.spriteList[i];
- if (element.sprite == sprite) {
- return
- }
- }
- this.spriteList.push({
- isAtk: false,
- sprite: sprite
- })
- }
- private removeSprite(sprite: FSprite) {
- for (let i = 0; i < this.spriteList.length; i++) {
- const element = this.spriteList[i];
- if (element.sprite == sprite) {
- this.spriteList.splice(i, 1);
- break
- }
- }
- }
- }
|