技能移动修改
This commit is contained in:
@@ -25,7 +25,7 @@ export class CSkill extends ecs.Entity {
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,camp:number = 1,uuid:number=1001) {
|
||||
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/skill";
|
||||
@@ -33,7 +33,7 @@ export class CSkill extends ecs.Entity {
|
||||
var node = instantiate(prefab);
|
||||
var scene = smc.map.MapView.scene;
|
||||
node.parent = scene.entityLayer!.node!;
|
||||
node.getChildByName("skill").setScale(node.getChildByName("skill").scale.x*camp, node.getChildByName("skill").scale.y, node.getChildByName("skill").scale.z);
|
||||
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))
|
||||
for (let index = 1; index <= 8; index++) {
|
||||
if(smc.player_buffs[index].eid == 0){
|
||||
@@ -45,7 +45,7 @@ export class CSkill extends ecs.Entity {
|
||||
|
||||
}
|
||||
console.log("load skill",pos,smc.player_buffs)
|
||||
node.setPosition(pos.x*-camp,pos.y,pos.z)
|
||||
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) => {
|
||||
@@ -59,7 +59,7 @@ export class CSkill extends ecs.Entity {
|
||||
|
||||
skill_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
|
||||
var mv = node.getComponent(CSkillComp)
|
||||
mv.camp = 1;
|
||||
mv.scale = 1;
|
||||
this.add(mv);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { _decorator } from "cc";
|
||||
import { _decorator,v3,Vec3 } 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/CardSet";
|
||||
import { Monster } from "./Monster";
|
||||
import { MonsterModelComp } from "./MonsterModelComp";
|
||||
import { MonsterViewComp } from "./MonsterViewComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@@ -10,21 +14,47 @@ const { ccclass, property } = _decorator;
|
||||
@ecs.register('CSkill', false)
|
||||
export class CSkillComp extends CCComp {
|
||||
//持续时间
|
||||
in_time: Timer = new Timer(5)
|
||||
is_destroy:boolean = false;
|
||||
camp:number = 1;
|
||||
private sd:Timer = new Timer(5)
|
||||
private cd:Timer = new Timer(1)
|
||||
private is_destroy:boolean = false;
|
||||
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.on(ModuleEvent.Cmd, this.onHandler, this);
|
||||
this.sd =new Timer(SkillSet[this.skill_uuid].sd)
|
||||
this.cd = new Timer(SkillSet[this.skill_uuid].cd)
|
||||
|
||||
}
|
||||
protected update(dt: number): void {
|
||||
if (this.in_time.update(dt)) {
|
||||
if (this.sd.update(dt)) {
|
||||
if (this.is_destroy) {
|
||||
return
|
||||
}
|
||||
this.to_destroy()
|
||||
}
|
||||
if (this.cd.update(dt)) {
|
||||
this.shoot()
|
||||
}
|
||||
}
|
||||
shoot() {
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let pos = v3(0,0)
|
||||
let t_pos:Vec3=null
|
||||
let monsters:any = ecs.query(ecs.allOf(MonsterModelComp));
|
||||
for (const monster of monsters) {
|
||||
t_pos= monster.getComponent(MonsterViewComp).get_monster_pos()
|
||||
}
|
||||
let scale = this.scale
|
||||
let dis = SkillSet[this.skill_uuid].dis+this.dis;
|
||||
let atk = SkillSet[this.skill_uuid].atk+this.atk;
|
||||
let speed = SkillSet[this.skill_uuid].speed+this.speed;
|
||||
let sp_name = SkillSet[this.skill_uuid].sp_name
|
||||
skill.load(pos,speed,dis,scale,this.node,sp_name,atk,t_pos);
|
||||
}
|
||||
/** 全局消息逻辑处理 */
|
||||
// private onHandler(event: string, args: any) {
|
||||
|
||||
@@ -35,7 +35,7 @@ export class Hero extends ecs.Entity {
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,camp:number = 1,uuid:number=1001) {
|
||||
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001) {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/heros/hero";
|
||||
|
||||
@@ -45,7 +45,7 @@ export class Hero extends ecs.Entity {
|
||||
node.parent = scene.entityLayer!.node!;
|
||||
// var as = node.getComponent(MonsterSpine);
|
||||
|
||||
node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*scale, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
node.setPosition(pos)
|
||||
// console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
|
||||
const url = 'game/heros/heros';
|
||||
@@ -70,7 +70,7 @@ export class Hero extends ecs.Entity {
|
||||
mv.power = smc.heros[uuid].power;
|
||||
mv.type = smc.heros[uuid].type;
|
||||
mv.Tpos = v3(0,0,0);
|
||||
mv.camp = 1;
|
||||
mv.scale = 1;
|
||||
mv.change_name(smc.heros[uuid].name,1)
|
||||
this.add(mv);
|
||||
this.push_monsters_in(uuid,mv.ent.eid)
|
||||
|
||||
@@ -60,7 +60,7 @@ export class HeroCard extends ecs.Entity {
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.parent = parent;
|
||||
// node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
// node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*scale, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
node.setPosition(pos)
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ export class Monster extends ecs.Entity {
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,camp:number = -1,uuid:number=1001) {
|
||||
load(pos: Vec3 = Vec3.ZERO,scale:number = -1,uuid:number=1001) {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/heros/hero";
|
||||
|
||||
@@ -45,7 +45,7 @@ export class Monster extends ecs.Entity {
|
||||
node.parent = scene.entityLayer!.node!;
|
||||
var as = node.getComponent(MonsterSpine);
|
||||
|
||||
node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*scale, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
node.setPosition(pos)
|
||||
// console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
|
||||
const url = 'game/heros/heros';
|
||||
@@ -67,7 +67,7 @@ export class Monster extends ecs.Entity {
|
||||
mv.atk_cd = smc.heros[uuid].atk_cd;
|
||||
mv.power = smc.heros[uuid].power;
|
||||
mv.type = smc.heros[uuid].type;
|
||||
mv.camp = -1;
|
||||
mv.scale = -1;
|
||||
mv.Tpos = v3(0,0,0);
|
||||
mv.change_name(smc.heros[uuid].name,-1)
|
||||
this.add(mv);
|
||||
|
||||
@@ -20,7 +20,7 @@ export class MonsterModelComp extends ecs.Comp {
|
||||
// speed: number = 0;
|
||||
/** 动画名资源 */
|
||||
anim: string = "monster";
|
||||
|
||||
|
||||
reset() {
|
||||
this.id = -1;
|
||||
// this.speed = 0;
|
||||
|
||||
@@ -29,7 +29,7 @@ export class MonsterViewComp extends CCComp {
|
||||
hero_uuid:number = 1001;
|
||||
hero_name : string = "hero";
|
||||
level:number =1;
|
||||
camp: number = 1; /** 角色阵营 1:hero -1 :monster */
|
||||
scale: number = 1; /** 角色阵营 1:hero -1 :monster */
|
||||
type: number = 1; /**角色类型 1:前排 2 后排 */
|
||||
state: number = 1; /** 状态 1:move ,2: act 3: stop */
|
||||
|
||||
@@ -105,12 +105,12 @@ export class MonsterViewComp extends CCComp {
|
||||
// EPhysics2DDrawFlags.Joint |
|
||||
// EPhysics2DDrawFlags.Shape;
|
||||
}
|
||||
change_name(hero_name:string='hero',camp:number=1){
|
||||
change_name(hero_name:string='hero',scale:number=1){
|
||||
this.name=hero_name;
|
||||
let label:any =this.node.getChildByName("lab_name")
|
||||
label.getComponent(Label)!.string = hero_name;
|
||||
let collider = this.getComponent(Collider2D);
|
||||
if(camp==1){
|
||||
if(scale==1){
|
||||
collider.group=BoxSet.HERO;
|
||||
}else{
|
||||
collider.group=BoxSet.MONSTER;
|
||||
@@ -144,14 +144,17 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
/**
|
||||
* 根据角色的阵营检查角色的 x 轴位置是否满足特定条件。
|
||||
* 如果角色属于正向阵营 (camp == 1) 且 x 轴位置大于等于 0,则直接返回。
|
||||
* 如果角色属于反向阵营 (camp != 1) 且 x 轴位置小于等于 0,则直接返回。
|
||||
* 如果角色属于正向阵营 (scale == 1) 且 x 轴位置大于等于 0,则直接返回。
|
||||
* 如果角色属于反向阵营 (scale != 1) 且 x 轴位置小于等于 0,则直接返回。
|
||||
*/
|
||||
if ((this.camp === 1 && this.node.position.x >= 0) || (this.camp !== 1 && this.node.position.x <= -180)) {
|
||||
if ((this.scale === 1 && this.node.position.x >= 0) || (this.scale !== 1 && this.node.position.x <= -180)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.node.setPosition(this.node.position.x+dt*this.speed*this.camp, this.node.position.y, this.node.position.z);
|
||||
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale, this.node.position.y, this.node.position.z);
|
||||
}
|
||||
get_monster_pos(){
|
||||
return this.node.getPosition()
|
||||
}
|
||||
power_change(power: number){
|
||||
this.power += power;
|
||||
@@ -167,7 +170,10 @@ export class MonsterViewComp extends CCComp {
|
||||
this.atk_time = 0;
|
||||
// console.log("atk_cd:"+this.atk_cd);
|
||||
this.as.atk();
|
||||
this.load_skill(this.skill_name);
|
||||
this.scheduleOnce(()=>{
|
||||
this.load_skill(this.skill_name);
|
||||
},0.2)
|
||||
|
||||
}
|
||||
this.atk_time += dt;
|
||||
}
|
||||
@@ -200,7 +206,7 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
}
|
||||
in_destroy(){
|
||||
// switch (this.camp) {
|
||||
// switch (this.scale) {
|
||||
// case -1:
|
||||
// if(this.node.position.x < BoxSet.LETF_END){
|
||||
// this.toDestroy();
|
||||
@@ -223,9 +229,9 @@ export class MonsterViewComp extends CCComp {
|
||||
load_skill(skill_name){
|
||||
// console.log("load_skill");
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let pos = v3(this.camp*30,30)
|
||||
let pos = v3(this.scale*30,30)
|
||||
let speed =400
|
||||
let scale = this.camp
|
||||
let scale = this.scale
|
||||
let range = 120;
|
||||
skill.load(pos,speed,range,scale,this.node,skill_name,this.atk);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user