攻击距离设定

This commit is contained in:
2024-09-11 10:19:35 +08:00
parent 0f7f2ad49b
commit f5a8cb20de
31 changed files with 114 additions and 191 deletions

View File

@@ -0,0 +1,168 @@
import { _decorator,v3,Vec3 ,Label} from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { Skill } from "../skills/Skill";
import { SkillSet } from "../common/config/SkillSet";
import { BoxSet, GameSet } from "../common/config/BoxSet";
import { smc } from "../common/SingletonModuleComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
import { MonModelComp } from "../mon/MonModelComp";
import { HeroModelComp } from "../hero/HeroModelComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('CSkillComp')
@ecs.register('CSkill', false)
export class CSkillComp extends CCComp {
//持续时间
private sd:Timer = new Timer(5)
private cd:Timer = new Timer(1)
private is_destroy:boolean = false;
time:number = 0;
scale:number = 1;
speed:number = 0;
dis:number = 0;
atk:number = 0;
skill_uuid:number = 1001;
/** 视图层逻辑代码分离演示 */
start() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
this.sd =new Timer(smc.skills[this.skill_uuid].sd)
this.cd = new Timer(smc.skills[this.skill_uuid].cd)
this.time =smc.skills[this.skill_uuid].sd
this.node.getChildByName("time").getComponent(Label).string = this.time.toString()
}
protected update(dt: number): void {
if (this.sd.update(dt)) {
if (this.is_destroy) {
return
}
this.to_destroy()
}
if (this.cd.update(dt)) {
this.time -=1
this.node.getChildByName("time").getComponent(Label).string = this.time.toString()
if(smc.skills[this.skill_uuid].type == 1){
this.shoot()
}
if(smc.skills[this.skill_uuid].type > 90){
this.add_buff()
}
}
}
shoot() {
let skill = ecs.getEntity<Skill>(Skill);
let pos = v3(0,0)
let t_pos = v3(0,0)
let angle = 0
let m_pos=v3(0,0)
let monsters:any = ecs.query(ecs.allOf(MonModelComp));
if (monsters.length > 0) {
m_pos = monsters[0].MonView.node.position
}else{
m_pos = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
}
t_pos = v3(m_pos.x-this.node.position.x,m_pos.y-this.node.position.y) // 目标增量
// console.log("m_pos",m_pos);
// console.log("pos",this.node.position);
// console.log("t_pos",t_pos);
let dx=m_pos.x-this.node.position.x
let dy=m_pos.y-this.node.position.y
let dir=v3(dx,dy,0)
let randian=Math.atan2(dir.y,dir.x)
angle = randian * (180 / Math.PI);
// console.log("angle",angle);
let scale = this.scale
let dis = smc.skills[this.skill_uuid].dis+this.dis;
let atk = smc.skills[this.skill_uuid].atk+this.atk;
let speed = smc.skills[this.skill_uuid].speed+this.speed;
skill.load(pos,speed,dis,scale,this.node,this.skill_uuid,atk,angle,t_pos);
}
add_buff(){
// 1 远距离攻击,碰撞后 结束
// 2 远距离攻击,碰撞后 持续,直到技能结束
// 3 远距离攻击,碰撞后 持续,带击退功能
// 4 双技能技能1技能结束后触发2技能
// 5: 特殊技能,触发特殊弹窗选项
// 9 buff物品
// 91: 单体buff物品加最少血临时
// 92单体buff物品随机临时
// 93: 群体buff物品
// 94role 临时buff
// 95role 永久buff
let uuid= this.skill_uuid;
let atk:number=smc.Role.RoleView.atk?smc.Role.RoleView.atk:0
let args:any = {
atk:atk*GameSet.ATK_TO_ATK_RATIO,
hp:atk*GameSet.ATK_TO_HP_RATIO,
shield:atk*GameSet.ATK_TO_SHIELD_RATIO,
}
let heros:any = ecs.query(ecs.allOf(HeroModelComp));
let least_hp:number=999999
let t_hero:any= null
if (heros.length > 0) {
if(SkillSet[uuid].type==92){ //随机添加buff
let i = RandomManager.instance.getRandomInt(0,heros.length-1,3)
console.log("i %%length:",i,heros.length)
heros[i].MonsterBuff.add_buff(uuid,args);
}else{
for (let i = 0; i < heros.length; i++) {
let hero = heros[i];
// console.log(" CSkillComp hero",hero);
if(SkillSet[uuid].type==91){ //血量最少单体
console.log(" CSkillComp hero 91",hero,least_hp,t_hero);
if(hero.MonsterView.hp < least_hp){
least_hp = hero.MonsterView.hp
t_hero = hero
}
}else{ //群体
hero.MonsterBuff.add_buff(uuid,args);
}
}
if(t_hero){ //血量最少单体
t_hero.MonsterBuff.add_buff(uuid,args);
}
}
}
// oops.message.dispatchEvent("add_buff",{uuid:this.skill_uuid,eid:0,group:BoxSet.HERO})
}
/** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) {
// switch (event) {
// case ModuleEvent.Cmd:
// break;
// }
// }
to_destroy() {
this.is_destroy = true
this.remove_buff()
// console.log("CSkillComp toDestroy");
if (this.node.isValid) {
// console.log("CSkillComp.node.isValid");
// console.log("CSkillComp.node.destroy",this);
this.ent.destroy()
}
}
remove_buff(){
for (let index = 0; index < 8; index++) {
if(smc.player_buffs[index].eid == this.ent.eid){
smc.player_buffs[index].eid=0
break
}
}
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.sd.reset()
this.cd.reset()
this.node.destroy();
}
}