卡牌技能位置

This commit is contained in:
2024-08-21 11:08:40 +08:00
parent a7f168dd72
commit 3f18763730
9 changed files with 81 additions and 15 deletions

View File

@@ -8,6 +8,8 @@ import { VM } from "../../../../extensions/oops-plugin-framework/assets/libs/mod
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { Initialize } from "../initialize/Initialize";
import { GameMap } from "../map/GameMap";
import { BoxSet } from "./config/BoxSet";
// import { Role } from "../role/Role";
// import { data } from "../data/data";
/** 游戏模块 */
@@ -17,6 +19,17 @@ export class SingletonModuleComp extends ecs.Comp {
initialize: Initialize = null!;
/** 游戏地图 */
map: GameMap = null!;
player_buffs: any = {
1:{x:-BoxSet.CSKILL_X,y:BoxSet.CSKILL_Y,eid:0},
2:{x:-BoxSet.CSKILL_X+70,y:BoxSet.CSKILL_Y,eid:0},
3:{x:-BoxSet.CSKILL_X+140,y:BoxSet.CSKILL_Y,eid:0},
4:{x:-BoxSet.CSKILL_X+210,y:BoxSet.CSKILL_Y,eid:0},
5:{x:-BoxSet.CSKILL_X,y:BoxSet.CSKILL_Y-70,eid:0},
6:{x:-BoxSet.CSKILL_X+70,y:BoxSet.CSKILL_Y-70,eid:0},
7:{x:-BoxSet.CSKILL_X+140,y:BoxSet.CSKILL_Y-70,eid:0},
8:{x:-BoxSet.CSKILL_X+210,y:BoxSet.CSKILL_Y-70,eid:0},
};
monster_buffs: any = [];
/** 游戏主角 */
// own: Role = null;
/** 游戏数据 */
@@ -82,6 +95,7 @@ export class SingletonModuleComp extends ecs.Comp {
vmAdd() {
console.log("smc vm_data vmAdd");
VM.add(this.vm_data, "data");
}
reset() {
for (var key in this.vm_data) {

View File

@@ -26,6 +26,6 @@ export enum BoxSet {
END_POINT = 360,
//游戏地平线
GAME_LINE = 0,
CSKILL_X = 200,
CSKILL_Y = 500,
CSKILL_X = 280,
CSKILL_Y = 420,
}

View File

@@ -19,8 +19,8 @@ export class MapSkillComp extends CCComp {
oops.message.on("hero_load", this.doHeroLoad, this);
oops.message.on("do_use_skill", this.doSkill, this);
}
doSkill(){
this.addSkill();
doSkill(event: string, args: any){
this.addSkill(args.uuid);
}
addSkill(uuid:number=1001){
let csk =ecs.getEntity<CSkill>(CSkill);

View File

@@ -3,6 +3,8 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
import { CSkillComp } from "./CSkillComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { smc } from "../common/SingletonModuleComp";
import { SkillSet } from "../common/config/CardSet";
/** CSkill 模块 */
@ecs.register(`CSkill`)
export class CSkill extends ecs.Entity {
@@ -14,6 +16,7 @@ export class CSkill extends ecs.Entity {
/** 模块资源释放 */
destroy() {
this.remove(CSkillComp);
// 注: 自定义释放逻辑,视图层实现 ecs.IComp 接口的 ecs 组件需要手动释放
super.destroy();
}
@@ -24,19 +27,30 @@ export class CSkill extends ecs.Entity {
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,camp:number = 1,uuid:number=1001) {
// var path = "game/monster/"+prefab_path;
console.log("load skill",this)
var path = "game/heros/skill";
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*camp, node.getChildByName("skill").scale.y, node.getChildByName("skill").scale.z);
node.setPosition(pos)
let cskills = ecs.query(ecs.allOf(CSkillComp))
for (let index = 1; 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
}
}
console.log("load skill",pos,smc.player_buffs)
node.setPosition(pos.x*-camp,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('1002');
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[uuid].path);
});
this.skill_init(uuid,node,pos)
oops.message.dispatchEvent("cskill_load",this)

View File

@@ -40,7 +40,7 @@ export class CSkillComp extends CCComp {
// console.log("CSkillComp.node.isValid");
setTimeout(() => {
// console.log("CSkillComp.node.destroy",this);
this.node.destroy()
this.ent.destroy()
}, 10);
}
}

View File

@@ -0,0 +1,26 @@
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

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

View File

@@ -8,6 +8,7 @@ import { CardSet } from "../common/config/CardSet";
import { HeroCard } from "./HeroCard";
import { HeroModelComp } from "./HeroModelComp";
import { Hero } from "./Hero";
import { MonsterViewComp } from "./MonsterViewComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@@ -100,8 +101,10 @@ export class HeroCardViewComp extends CCComp {
}
use_card(){
Hero
let heros = ecs.query(ecs.allOf(HeroModelComp))
// let heross= ecs.query(ecs.allOf(MonsterViewComp))
// console.log("heross",heross)
if(heros.length >= 4){
oops.gui.toast("英雄数量达到上限");
this.node.setPosition(this.pos_x,this.pos_y);