This commit is contained in:
pan
2024-08-20 18:27:34 +08:00
parent 87a445c225
commit b9edfd7001
17 changed files with 407 additions and 143 deletions

View File

@@ -52,7 +52,7 @@ export class Hero extends ecs.Entity {
resources.load(url, SpriteAtlas, (err: any, atlas) => {
const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(CardSet[uuid].path);
sprite.spriteFrame = atlas.getSpriteFrame(smc.heros[uuid].path);
});
this.hero_init(uuid,node)
oops.message.dispatchEvent("hero_load",this)
@@ -61,22 +61,22 @@ export class Hero extends ecs.Entity {
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
var mv = node.getComponent(MonsterViewComp)!;
mv.hero_uuid=uuid;
mv.speed =mv.ospeed = CardSet[uuid].speed;
mv.hero_name= CardSet[uuid].name;
mv.hp= mv.hp_max = CardSet[uuid].hp;
mv.level = CardSet[uuid].level;
mv.atk = CardSet[uuid].atk;
mv.atk_cd = CardSet[uuid].atk_cd;
mv.power = CardSet[uuid].power;
mv.type = CardSet[uuid].type;
mv.speed =mv.ospeed = smc.heros[uuid].speed;
mv.hero_name= smc.heros[uuid].name;
mv.hp= mv.hp_max = smc.heros[uuid].hp;
mv.level = smc.heros[uuid].level;
mv.atk = smc.heros[uuid].atk;
mv.atk_cd = smc.heros[uuid].atk_cd;
mv.power = smc.heros[uuid].power;
mv.type = smc.heros[uuid].type;
mv.Tpos = v3(0,0,0);
mv.camp = 1;
mv.change_name(CardSet[uuid].name,1)
mv.change_name(smc.heros[uuid].name,1)
this.add(mv);
this.push_monsters_in(uuid,mv.ent.eid)
}
push_monsters_in(uuid:number=1001,eid:number=0){
smc.monsters_in.push({name:CardSet[uuid].name,eid:eid})
smc.monsters_in.push({name:smc.heros[uuid].name,eid:eid})
}

View File

@@ -12,7 +12,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
import { UIID } from "../common/config/GameUIConfig";
import { smc } from "../common/SingletonModuleComp";
import{HeroCardViewComp} from "./HeroCardViewComp";
import { CardSet } from "../common/config/CardSet";
import { CardSet ,SkillSet} from "../common/config/CardSet";
/** 角色实体 */
@ecs.register(`HeroCard`)
export class HeroCard extends ecs.Entity {
@@ -32,20 +32,28 @@ export class HeroCard extends ecs.Entity {
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,uuid:number=1001,parent:Node,type:number=1) {
// console.log("load hero",uuid);
// var path = "game/monster/"+prefab_path;
switch(type){
let path: string;
let url: string;
let pathName: string;
let name: string;
let level: number;
switch (type) {
case 1:
var path = "game/heros/hero_card";
path = "game/heros/hero_card";
url = "game/heros/heros";
({ path: pathName, name, level } = smc.heros[uuid]);
break;
case 2:
var path = "game/heros/skill_card";
path = "game/heros/skill_card";
url = "game/heros/skill";
({ path: pathName, name, level } = SkillSet[uuid]);
break;
case 3:
var path = "game/heros/item_card";
break;
default:
var path = "game/heros/hero_card";
path = "game/heros/hero_card";
url = "game/heros/heros";
({ path: pathName, name, level } = smc.heros[uuid]);
}
@@ -55,20 +63,19 @@ export class HeroCard extends ecs.Entity {
// node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
node.setPosition(pos)
const url = 'game/heros/heros';
resources.load(url, SpriteAtlas, (err: any, atlas) => {
const sprite = node.getChildByName("hero").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(CardSet[uuid].path);
sprite.spriteFrame = atlas.getSpriteFrame(pathName);
});
var hcv = node.getComponent(HeroCardViewComp)!;
hcv.card_name=CardSet[uuid].name
hcv.card_name=name
hcv.card_uid=uuid
hcv.card_type=type
hcv.card_level=level
this.add(hcv);
}
}
}

View File

@@ -13,11 +13,12 @@ const { ccclass, property } = _decorator;
@ecs.register('HeroCardView', false)
export class HeroCardViewComp extends CCComp {
card_name:string = "hero_card";
card_type:string = "hero";
card_uid:number = 1000;
in_destroy:boolean = false;
pos_x:number = 0;
pos_y:number = 0;
card_type:number = 1;
card_level:number = 1;
protected onLoad(): void {
this.node.on(NodeEventType.TOUCH_START, this.onTouchMove, this);
@@ -31,7 +32,7 @@ export class HeroCardViewComp extends CCComp {
start() {
this.pos_x=this.node.position.x;
this.pos_y=this.node.position.y;
this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = CardSet[this.card_uid].level.toString();
this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = this.card_level.toString();
this.node.getChildByName("name").getComponent(Label).string = this.card_name
}
@@ -97,14 +98,30 @@ export class HeroCardViewComp extends CCComp {
}
use_card(){
if(smc.vm_data.gold.min >= smc.vm_data.cards.ref_cost){
if(smc.vm_data.gold.min >= this.card_level){
this.in_destroy = true;
oops.message.dispatchEvent("do_add_hero",{uuid:this.card_uid})
this.do_use_card()
this.ent.destroy();
smc.vm_data.gold.min -= smc.vm_data.cards.ref_cost;
smc.vm_data.gold.min -= this.card_level;
}else{
oops.gui.toast("金币不够");
this.node.setPosition(this.pos_x,this.pos_y);
}
}
do_use_card(){
switch (this.card_type) { // 添加括号并修正语法
case 1:
oops.message.dispatchEvent("do_add_hero", { uuid: this.card_uid }); // 添加分号
break;
case 2:
oops.message.dispatchEvent("do_use_skill", { uuid: this.card_uid }); // 添加分号
// console.log("do_use_skill",this.card_uid)
break;
default:
break;
}
}
}

View File

@@ -52,29 +52,29 @@ export class Monster extends ecs.Entity {
resources.load(url, SpriteAtlas, (err: any, atlas) => {
const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(CardSet[uuid].path);
sprite.spriteFrame = atlas.getSpriteFrame(smc.heros[uuid].path);
});
this.hero_init(uuid,node)
oops.message.dispatchEvent("monster_load",this)
}
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
var mv = node.getComponent(MonsterViewComp)!;
mv.speed =mv.ospeed = CardSet[uuid].speed;
mv.hero_name= CardSet[uuid].name;
mv.hp= mv.hp_max = CardSet[uuid].hp;
mv.level = CardSet[uuid].level;
mv.atk = CardSet[uuid].atk;
mv.atk_cd = CardSet[uuid].atk_cd;
mv.power = CardSet[uuid].power;
mv.type = CardSet[uuid].type;
mv.speed =mv.ospeed = smc.heros[uuid].speed;
mv.hero_name= smc.heros[uuid].name;
mv.hp= mv.hp_max = smc.heros[uuid].hp;
mv.level = smc.heros[uuid].level;
mv.atk = smc.heros[uuid].atk;
mv.atk_cd = smc.heros[uuid].atk_cd;
mv.power = smc.heros[uuid].power;
mv.type = smc.heros[uuid].type;
mv.camp = -1;
mv.Tpos = v3(0,0,0);
mv.change_name(CardSet[uuid].name,-1)
mv.change_name(smc.heros[uuid].name,-1)
this.add(mv);
this.push_monsters_in(uuid,mv.ent.eid)
}
push_monsters_in(uuid:number=1001,eid:number=0){
smc.monsters_in.push({name:CardSet[uuid].name,eid:eid})
smc.monsters_in.push({name:smc.heros[uuid].name,eid:eid})
}
}