dd
This commit is contained in:
@@ -9,6 +9,8 @@ import { BoxSet, FacSet } from '../common/config/BoxSet';
|
||||
import { smc } from '../common/SingletonModuleComp';
|
||||
import { CCComp } from 'db://oops-framework/module/common/CCComp';
|
||||
import { FightConComp } from '../map/FightConComp';
|
||||
import { MonModelComp } from './MonModelComp';
|
||||
import { HeroModelComp } from './HeroModelComp';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('SkillCon')
|
||||
@@ -87,19 +89,9 @@ export class SkillConComp extends CCComp {
|
||||
/** 施放技能 */
|
||||
castSkill(config: typeof SkillSet[keyof typeof SkillSet],count:number=1,dmg:number=0) {
|
||||
// console.log(view.uuid+"=>"+view.hero_name+"施放技能:"+config.uuid);
|
||||
if (config.TargetGroup === TargetGroup.Enemy) {
|
||||
this.HeroView.playSkillEffect(config.uuid);
|
||||
|
||||
this.doSkill(config,count,dmg);
|
||||
}
|
||||
|
||||
if (config.TargetGroup === TargetGroup.Ally) {
|
||||
const targets = this.selectAllyTargets( config);
|
||||
if (targets.length === 0) return;
|
||||
this.doSkill(config,count,dmg);
|
||||
}
|
||||
if (config.TargetGroup === TargetGroup.Self) {
|
||||
this.doSkill(config,count,dmg);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private doSkill(config: typeof SkillSet[keyof typeof SkillSet],count:number=1,angle:number=0,dmg:number=0) {
|
||||
@@ -107,9 +99,27 @@ export class SkillConComp extends CCComp {
|
||||
if (!this.node || !this.node.isValid || !this.HeroView || !this.HeroView.node || !this.HeroView.node.isValid) {
|
||||
return;
|
||||
}
|
||||
let targets:any=null
|
||||
switch(config.TargetGroup){
|
||||
case TargetGroup.Enemy: //单个敌人
|
||||
targets = this.filterFrontRow();
|
||||
break
|
||||
case TargetGroup.Ally: //所有敌人
|
||||
targets = this.selectAllyTargets();
|
||||
break
|
||||
case TargetGroup.Self: //自身
|
||||
targets = this.HeroView.ent
|
||||
break
|
||||
case TargetGroup.Team: //所有友方
|
||||
|
||||
break
|
||||
case TargetGroup.All: //所有单位
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
const skillEntity = ecs.getEntity<Skill>(Skill);
|
||||
const targets = this.selectEnemyTargets(config);
|
||||
if (targets.length === 0) return;
|
||||
|
||||
const timerId = setTimeout(() => {
|
||||
@@ -145,46 +155,49 @@ export class SkillConComp extends CCComp {
|
||||
this._timers[`skill_${config.uuid}`] = timerId;
|
||||
}
|
||||
|
||||
private selectEnemyTargets(config: typeof SkillSet[keyof typeof SkillSet]): ecs.Entity[] {
|
||||
const team = this.HeroView.fac;
|
||||
const isEnemyTeam = team === FacSet.HERO ? FacSet.MON : FacSet.HERO;
|
||||
const candidates= ecs.query(ecs.allOf(HeroViewComp)).filter(e => e.get(HeroViewComp).fac !== team);
|
||||
return this.filterFrontRow(candidates, isEnemyTeam);
|
||||
}
|
||||
|
||||
|
||||
/** 筛选最前排单位 */
|
||||
private filterFrontRow(entities: ecs.Entity[], isEnemyTeam: number): ecs.Entity[] {
|
||||
private filterFrontRow(): ecs.Entity[] {
|
||||
// 敌方最前排是x坐标最大的,我方最前排是x坐标最小的
|
||||
const keyPos = isEnemyTeam ?
|
||||
let entities:any=null
|
||||
if(this.HeroView.fac==FacSet.HERO){
|
||||
entities = ecs.query(ecs.allOf(MonModelComp))
|
||||
}else{
|
||||
entities = ecs.query(ecs.allOf(HeroModelComp))
|
||||
}
|
||||
|
||||
let keyPos = this.HeroView.fac==FacSet.HERO ?
|
||||
Math.min(...entities.map(e => e.get(HeroViewComp).node.position.x)) :
|
||||
Math.max(...entities.map(e => e.get(HeroViewComp).node.position.x));
|
||||
|
||||
return entities.filter(e =>
|
||||
Math.abs(e.get(HeroViewComp).node.position.x - keyPos) < 10
|
||||
);
|
||||
)
|
||||
}
|
||||
private selectAllyTargets( config: typeof SkillSet[keyof typeof SkillSet]): ecs.Entity[] {
|
||||
const team = this.HeroView.fac;
|
||||
const candidates= ecs.query(ecs.allOf(HeroViewComp)).filter(e => e.get(HeroViewComp).fac === team);
|
||||
// 第二阶段:位置/血量等精细筛选
|
||||
switch(config.TargetType) {
|
||||
case TargetType.Melee:
|
||||
return candidates.filter(e => e.get(HeroViewComp).type === 0);
|
||||
case TargetType.Ranged:
|
||||
return candidates.filter(e => e.get(HeroViewComp).type === 1);
|
||||
case TargetType.SupportClass:
|
||||
return candidates.filter(e => e.get(HeroViewComp).type === 2);
|
||||
case TargetType.Random:
|
||||
return this.pickRandomTarget(candidates, config.count || 1);
|
||||
default:
|
||||
return candidates;
|
||||
|
||||
private selectAllyTargets( ): ecs.Entity[] {
|
||||
if(this.HeroView.fac==FacSet.HERO){
|
||||
return ecs.query(ecs.allOf(MonModelComp))
|
||||
}else{
|
||||
return ecs.query(ecs.allOf(MonModelComp))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** 随机选择目标 */
|
||||
private pickRandomTarget(entities: ecs.Entity[], count: number): ecs.Entity[] {
|
||||
private pickRandomTarget(count: number): ecs.Entity[] {
|
||||
let entities:any=null
|
||||
if(this.HeroView.fac==FacSet.HERO){
|
||||
entities = ecs.query(ecs.allOf(MonModelComp))
|
||||
}else{
|
||||
entities = ecs.query(ecs.allOf(HeroModelComp))
|
||||
}
|
||||
const shuffled = [...entities].sort(() => 0.5 - Math.random());
|
||||
return shuffled.slice(0, count);
|
||||
}
|
||||
|
||||
|
||||
public clear_timer() {
|
||||
// console.log("clear_timer");
|
||||
Object.values(this._timers).forEach(clearTimeout);
|
||||
|
||||
Reference in New Issue
Block a user