super-hero/assets/cc-game/scripts/game_play/creep/CreepBase.ts

140 lines
4.8 KiB
TypeScript
Raw Normal View History

2024-04-19 03:49:41 -07:00
import { Collider2D, Vec3 } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { UmUtil } from '../../../../cc-common/cc-util/UmUtil';
import { ColliderObject } from '../../base/ColliderObject';
import { UmLog } from '../../../../cc-common/cc-util/UmLog';
import { GameDefine, EPHYSIC_GROUP, EACTIVE_SKILL_TYPE, ENEMY_TYPE, EMOVE_MODE, EATTACK_TYPE } from '../../config/GameDefine';
import { BulletBase } from '../bullet/BulletBase';
import { LayoutManager } from '../LayoutManager';
import { Sprite } from 'cc';
import { Color } from 'cc';
import { ShootingBase } from '../bullet/ShootingBase';
import { GameGlobalData } from '../../global/GameGlobalData';
import { EnemyDataInfo } from '../../global/GameInterface';
import { ActiveSkillBase } from '../hero/ActiveSkillBase';
import { HPBar } from '../../game_ui/HPBar';
import { CreepMove } from './CreepMove';
import { UmClientEvent } from '../../../../cc-common/cc-util/UmOneToMultiListener';
import { EnemyBase } from '../enemy/EnemyBase';
const { ccclass, property } = _decorator;
@ccclass('CreepBase')
export class CreepBase extends EnemyBase {
@property(HPBar) hpBar: HPBar = null!;
@property(CreepMove) creepMove: CreepMove = null!;
start(): void {
super.start();
this.isShootEnable = false;
}
setEnemyData(data) {
super.setEnemyData(data);
this.hpBar.setMaxHPBar(this.hp);
this.creepMove.setMoveData(data, this.enemyType, this.attackType);
}
protected registerColliderContact() {
this.colliderObject.registerBeginContact(this.onBeginContact.bind(this), true);
this.colliderObject.registerEndContact(this.onEndContact.bind(this), true);
}
onBeginContact(a: Collider2D, b: Collider2D) {
//override
var bGroup = b.group;
UmLog.log("CREEP | Contact Begin = " + GameDefine.getPhysicGroupName(a.group), " vs ", GameDefine.getPhysicGroupName(bGroup));
if (bGroup == Number(EPHYSIC_GROUP.ENEMY) || bGroup == Number(EPHYSIC_GROUP.OBSTACLE)
|| bGroup == Number(EPHYSIC_GROUP.DEFAULT)) {
this.creepMove?.setIsContactObstacle(true);
return;
}
if (bGroup == Number(EPHYSIC_GROUP.BULLET_HERO)) {
this.onBulletContact(b.node);
return;
}
if (bGroup == Number(EPHYSIC_GROUP.ACTIVE_SKILL)) {
this.onHeroActiveSkillContact(b.node);
return;
}
if (bGroup == Number(EPHYSIC_GROUP.HERO)) {
this.creepMove.setIsContactHero(true);
return;
}
}
onEndContact(a: Collider2D, b: Collider2D) {
//override
var bGroup = b.group;
if (bGroup == Number(EPHYSIC_GROUP.ENEMY) || bGroup == Number(EPHYSIC_GROUP.OBSTACLE)
|| bGroup == Number(EPHYSIC_GROUP.DEFAULT)) {
this.creepMove?.setIsContactObstacle(false);
return;
}
if (bGroup == Number(EPHYSIC_GROUP.HERO)) {
this.creepMove.setIsContactHero(false);
return;
}
}
onSensorBegin(a: Collider2D, b: Collider2D) {
//override
var bGroup = b.group;
// UmLog.log("BOSS |onSensor Begin = " + GameDefine.getPhysicGroupName(a.group), " vs ", GameDefine.getPhysicGroupName(b.group));
if (bGroup != EPHYSIC_GROUP.HERO) return;
this.heroTarget = b.node;
this.creepMove.setIsSensorHero(true, this.heroTarget);
this.checkEnableShoot(true);
// this.creepMove.changeMode(EMOVE_MODE.TARGET);
}
onSensorEnd(a: Collider2D, b: Collider2D) {
//override
var bGroup = b.group;
// UmLog.log("BOSS | onSensor End = " + GameDefine.getPhysicGroupName(a.group), " vs ", GameDefine.getPhysicGroupName(b.group));
GameDefine.getPhysicGroupName(bGroup);
if (bGroup != EPHYSIC_GROUP.HERO) return;
this.heroTarget = null;
this.creepMove.setIsSensorHero(false, this.heroTarget);
this.checkEnableShoot(false);
}
checkEnableShoot(isSensorHero)
{
this.isShootEnable = isSensorHero && this.attackType == EATTACK_TYPE.RANGE;
}
hitDamage(damage: number) {
this.hpBar?.decreaseHP(damage);
this.runHitEffect();
if (this.hpBar && this.hpBar.currentHP <= 0) {
this.checkWin();
this?.destroyNode();
}
}
checkWin() {
if (this.isCheckedWin) return;
this.isCheckedWin = true;
UmClientEvent.dispatchEvent(GameDefine.EVENT_CHECK_WIN, GameDefine.ENEMY_CREEP);
}
protected update(dt: number): void {
if (!GameGlobalData.Instance.isStatePlay()) return;
if (!this.isShootEnable) return;
var targetShoot = this.findShootTargetNode();
if (!targetShoot) return;
2024-04-22 01:32:16 -07:00
this.shooting.shooting(this.node, targetShoot, this.ShootingDataConfig);
2024-04-19 03:49:41 -07:00
}
}