194 lines
7.3 KiB
TypeScript
194 lines
7.3 KiB
TypeScript
import { _decorator ,Label,NodeEventType,EventTouch,v3} 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 { data } from "../data/data";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { SkillSet } from "../common/config/SkillSet";
|
|
import { HeroCard } from "./HeroCard";
|
|
import { HeroModelComp } from "./HeroModelComp";
|
|
import { Hero } from "./Hero";
|
|
import { MonsterViewComp } from "./MonsterViewComp";
|
|
import { MapMonsterComp } from "../map/MapMonsterComp";
|
|
import { MapSkillComp } from "../map/MapSkillComp";
|
|
import { InfoBox } from "../gui/InfoBox";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('HeroCardViewComp')
|
|
@ecs.register('HeroCardView', false)
|
|
export class HeroCardViewComp extends CCComp {
|
|
MM: MapMonsterComp;
|
|
MS: MapSkillComp;
|
|
card_name:string = "hero_card";
|
|
card_uid:number = 1000;
|
|
in_destroy:boolean = false;
|
|
pos_x:number = 0;
|
|
pos_y:number = 0;
|
|
card_type:number = 1;
|
|
card_level:number = 1;
|
|
alive:boolean = false;
|
|
|
|
protected onLoad(): void {
|
|
this.node.on(NodeEventType.TOUCH_START, this.onTouchMove, this);
|
|
this.node.on(NodeEventType.TOUCH_MOVE, this.onTouchMove, this);
|
|
this.node.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
|
|
this.node.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
|
|
// oops.message.on("active_card_eid", this.do_active_card_eid, this);
|
|
}
|
|
|
|
/** 视图层逻辑代码分离演示 */
|
|
start() {
|
|
this.pos_x=this.node.position.x;
|
|
this.pos_y=this.node.position.y;
|
|
this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = this.card_level.toString();
|
|
this.node.getChildByName("name").getComponent(Label).string = this.card_name
|
|
|
|
}
|
|
/** 全局消息逻辑处理 */
|
|
// private onHandler(event: string, args: any) {
|
|
// switch (event) {
|
|
// case ModuleEvent.Cmd:
|
|
// break;
|
|
// }
|
|
// }
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.in_destroy = false;
|
|
this.node.destroy();
|
|
}
|
|
onTouchMove(event: EventTouch) {
|
|
let delta = event.getDelta();
|
|
this.node.setPosition(this.node.position.x+delta.x,this.node.position.y+delta.y);
|
|
this.show_info()
|
|
}
|
|
show_info(){
|
|
console.log("show_info",this.card_uid)
|
|
let parent = this.node.parent.parent
|
|
let node =parent.getChildByName("item_box")
|
|
if(this.card_type == 2){
|
|
smc.vm_data.item_box.info = SkillSet[this.card_uid].info
|
|
smc.vm_data.item_box.name = SkillSet[this.card_uid].name
|
|
smc.vm_data.item_box.skillcd = SkillSet[this.card_uid].cd
|
|
smc.vm_data.item_box.skillsd = SkillSet[this.card_uid].sd
|
|
smc.vm_data.item_box.atk = SkillSet[this.card_uid].atk
|
|
smc.vm_data.item_box.hp = SkillSet[this.card_uid].hp
|
|
node.active=true
|
|
}
|
|
if(this.card_type == 3){
|
|
console.log(SkillSet[this.card_uid])
|
|
smc.vm_data.item_box.info = SkillSet[this.card_uid].info
|
|
smc.vm_data.item_box.name = SkillSet[this.card_uid].name
|
|
smc.vm_data.item_box.skillcd = SkillSet[this.card_uid].cd
|
|
smc.vm_data.item_box.skillsd = SkillSet[this.card_uid].sd
|
|
smc.vm_data.item_box.atk = SkillSet[this.card_uid].atk
|
|
smc.vm_data.item_box.hp = SkillSet[this.card_uid].hp
|
|
smc.vm_data.item_box.shield = SkillSet[this.card_uid].shield
|
|
node.active=true
|
|
if(SkillSet[this.card_uid].shield > 0){
|
|
node.getChildByName("data").getChildByName("shield").active=true
|
|
}
|
|
if(SkillSet[this.card_uid].hp > 0){
|
|
node.getChildByName("data").getChildByName("hp").active=true
|
|
}
|
|
}
|
|
}
|
|
onTouchEnd(){
|
|
if(this.node.position.y-this.pos_y > 150){
|
|
this.use_card()
|
|
}else{
|
|
this.node.setPosition(this.pos_x,this.pos_y);
|
|
}
|
|
let parent = this.node.parent.parent
|
|
let node = parent.getChildByName("item_box")
|
|
node.active=false
|
|
node.getChildByName("data").getChildByName("shield").active=false
|
|
node.getChildByName("data").getChildByName("hp").active=false
|
|
|
|
}
|
|
|
|
private do_active_card_eid(event: string, args: any) {
|
|
console.log("active_card_eid",args,this.ent.eid)
|
|
if(this.ent.eid != args.eid){
|
|
this.no_active()
|
|
}
|
|
|
|
}
|
|
do_active(){
|
|
// console.log(this.node.getChildByName("active"),this.node.getChildByName("use"), this.node.getChildByName("bag"))
|
|
// let use = this.node.getChildByName("use")
|
|
// let bag = this.node.getChildByName("bag")
|
|
// let active = this.node.getChildByName("active")
|
|
// active.active = !active.active
|
|
|
|
// use.active = !use.active
|
|
// bag.active = !bag.active
|
|
// this.alive=!this.alive
|
|
// if(this.alive){
|
|
// this.node.setScale(1.5,1.5,1)
|
|
// }else{
|
|
// this.node.setScale(1,1,0)
|
|
// }
|
|
|
|
}
|
|
no_active(){
|
|
// let active = this.node.getChildByName("active")
|
|
// // let use = this.node.getChildByName("use")
|
|
// // let bag = this.node.getChildByName("bag")
|
|
// active.active = false
|
|
// this.node.setScale(1,1)
|
|
// use.active = false
|
|
// bag.active = false
|
|
}
|
|
|
|
doit(){
|
|
// this.do_active()
|
|
smc.vm_data.cards.eid = this.ent.eid;
|
|
this.do_active()
|
|
let hero_cards = ecs.query(ecs.allOf(HeroCardViewComp))
|
|
hero_cards.forEach(element => {
|
|
if(element.eid != this.ent.eid)
|
|
element.get(HeroCardViewComp).no_active()
|
|
});
|
|
// console.log("doit",hero_cards)
|
|
// oops.message.dispatchEvent("active_card_eid",{eid:this.ent.eid})
|
|
}
|
|
|
|
use_card(){
|
|
|
|
let heros = ecs.query(ecs.allOf(HeroModelComp))
|
|
// let heross= ecs.query(ecs.allOf(MonsterViewComp))
|
|
// console.log("heross",heross)
|
|
if(heros.length >= 4&&this.card_type == 1){
|
|
oops.gui.toast("英雄数量达到上限");
|
|
this.node.setPosition(this.pos_x,this.pos_y);
|
|
return;
|
|
}
|
|
if(smc.vm_data.gold.min >= this.card_level){
|
|
this.in_destroy = true;
|
|
this.do_use_card()
|
|
this.ent.destroy();
|
|
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 });
|
|
break;
|
|
case 3:
|
|
oops.message.dispatchEvent("do_use_skill", { uuid: this.card_uid });
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
} |