攻击距离设定

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

View File

@@ -1,100 +0,0 @@
import { Prefab,instantiate,Vec3,v3 ,SpriteAtlas,resources,Sprite,Node} from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CSkillComp } from "./CSkillComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { smc } from "../common/SingletonModuleComp";
import { SkillSet } from "../common/config/SkillSet";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
/** CSkill 模块 */
@ecs.register(`CSkill`)
export class CSkill extends ecs.Entity {
CSkillView!: CSkillComp;
/** 实始添加的数据层组件 */
protected init() {
}
/** 模块资源释放 */
destroy() {
this.remove(CSkillComp);
// 注: 自定义释放逻辑,视图层实现 ecs.IComp 接口的 ecs 组件需要手动释放
super.destroy();
}
start(){
}
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001) {
// var path = "game/monster/"+prefab_path;
// console.log("load skill",this)
var path = "game/heros/cskill";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
var scene = smc.map.MapView.scene;
node.parent = scene.entityLayer!.node!;
node.getChildByName("skill").setScale(node.getChildByName("skill").scale.x*scale, node.getChildByName("skill").scale.y, node.getChildByName("skill").scale.z);
// let cskills = ecs.query(ecs.allOf(CSkillComp))
if(SkillSet[uuid].type >= 90){
pos = this.add_buff()
}else{
pos = this.add_skill()
}
// console.log("load skill",pos,smc.player_buffs)
node.setPosition(pos.x*scale,pos.y,pos.z)
// console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
const url = 'game/heros/skill';
resources.load(url, SpriteAtlas, (err: any, atlas) => {
const sprite = node.getChildByName("skill").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(smc.skills[uuid].path);
});
this.skill_init(uuid,node,pos)
oops.message.dispatchEvent("cskill_load",this)
}
add_buff(){
let pos = v3(0,0,0)
for (let index = 0; index < 4; index++) {
if(smc.player_buffs[index].eid == 0){
pos.x=smc.player_buffs[index].x
pos.y=smc.player_buffs[index].y
smc.player_buffs[index].eid=this.eid
break
}
}
return pos
}
add_skill(){
let pos = v3(0,0,0)
for (let index = 4; index < 8; index++) {
if(smc.player_buffs[index].eid == 0){
pos.x=smc.player_buffs[index].x
pos.y=smc.player_buffs[index].y
smc.player_buffs[index].eid=this.eid
break
}
}
return pos
}
skill_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
var mv = node.getComponent(CSkillComp)
mv.scale = 1;
mv.skill_uuid = uuid;
mv.atk=smc.skills[uuid].atk;
this.add(mv);
}
}
/** CSkill 模块业务逻辑系统组件,如无业务逻辑处理可删除此对象 */
export class EcsCSkillSystem extends ecs.System {
constructor() {
super();
// this.add(new ecs.ComblockSystem());
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "430ee378-c69f-409a-b098-d3daec37d90b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,171 +0,0 @@
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 { Monster } from "./Monster";
import { MonsterModelComp } from "./MonsterModelComp";
import { MonsterViewComp } from "./MonsterViewComp";
import { BoxSet, GameSet } from "../common/config/BoxSet";
import { smc } from "../common/SingletonModuleComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { HeroModelComp } from "./HeroModelComp";
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
import { MonModelComp } from "../mon/MonModelComp";
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();
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "31174503-d934-4bd4-bd68-01aaa5534e81",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,26 +0,0 @@
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { VM } from "../../../../extensions/oops-plugin-framework/assets/libs/model-view/ViewModel";
/** 数据层对象 */
@ecs.register('CSkillModel')
export class CSkillModelComp extends ecs.Comp {
/** 提供 MVVM 组件使用的数据 */
// private vm: any = {};
// /** 显示数据添加到 MVVM 框架中监视 */
// vmAdd() {
// VM.add(this.vm, "CSkillModel");
// }
// /** 显示数据从 MVVM 框架中移除 */
// vmRemove() {
// VM.remove("CSkillModel");
// }
/** 数据层组件移除时,重置所有数据为默认值 */
reset() {
// for (var key in this.vm) {
// delete this.vm[key];
// }
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "917ea8ef-8f1b-498c-8bfe-654cd28a86a5",
"files": [],
"subMetas": {},
"userData": {}
}