Files
heros/assets/script/game/map/CardController.ts
2024-09-29 08:06:30 +08:00

244 lines
11 KiB
TypeScript

import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,UITransform,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 { smc } from "../common/SingletonModuleComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
import { SkillSet } from "../common/config/SkillSet";
import { HeroModelComp } from "../hero/HeroModelComp";
import { RewardSet } from "../common/config/RewardSet";
import { GameSet } from "../common/config/BoxSet";
import { GameMap } from "./GameMap";
import { MapModelComp } from "./model/MapModelComp";
import { Talent } from "../Role/Talent";
import { Talents } from "../common/config/TalentSet";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('CardControllerComp')
@ecs.register('CardController', false)
export class CardControllerComp extends CCComp {
card_level:number = 1;
in_load:boolean = false
touch_time:number = 0
in_touch:boolean = false
cards:any = {
1:{uuid:1101,type:1,lv:0,cost:0,alive:false},
2:{uuid:1102,type:1,lv:0,cost:0,alive:false},
3:{uuid:1103,type:1,lv:0,cost:0,alive:false},
4:{uuid:1104,type:1,lv:0,cost:0,alive:false},
5:{uuid:1105,type:1,lv:0,cost:0,alive:false},
6:{uuid:1106,type:1,lv:0,cost:0,alive:false},
}
rewards:any = {
1:{uuid: 5001,path: "5001",type: 1,lv: 1,name: "",info:"",atk:0,hp:0,atk_cd:0,},
2:{uuid: 5001,path: "5001",type: 1,lv: 1,name: "",info:"",atk:0,hp:0,atk_cd:0,},
3:{uuid: 5001,path: "5001",type: 1,lv: 1,name: "",info:"",atk:0,hp:0,atk_cd:0,},
}
rewards_set:any = []
reward_lv = 0;
protected onLoad(): void {
// oops.message.on("do_reward", this.do_reward, this)
oops.message.on("minssion_victory", this.do_minssion_victory, this)
oops.message.on("minssion_defeat", this.do_minssion_defeat, this)
}
start() {
}
show_info(uuid:number,type:number){
// console.log("show_info",uuid)
let node =this.node.getChildByName("item_box")
if(type == 2){
smc.vm_data.item_box.info = smc.items[uuid].info
smc.vm_data.item_box.name = smc.items[uuid].name
smc.vm_data.item_box.skillcd = smc.items[uuid].cd
smc.vm_data.item_box.skillsd = smc.items[uuid].sd
smc.vm_data.item_box.atk = smc.items[uuid].atk
smc.vm_data.item_box.hp = smc.items[uuid].hp
smc.vm_data.item_box.shield = smc.items[uuid].shield
node.active=true
if(smc.items[uuid].shield > 0){
node.getChildByName("data").getChildByName("shield").active=true
}
if(smc.items[uuid].hp > 0){
node.getChildByName("data").getChildByName("hp").active=true
}
}
}
do_minssion_victory(){
this.node.getChildByName("victory").active=true
}
do_minssion_defeat(){
this.node.getChildByName("defeat").active=true
}
end_mission(){
this.node.getChildByName("victory").active=false
this.node.getChildByName("defeat").active=false
console.log("end_mission")
}
normal_call(){
if(smc.vm_data.mission.coin >= smc.vm_data.mission.normal_cost){
smc.vm_data.mission.coin -= smc.vm_data.mission.normal_cost
oops.message.dispatchEvent("normal_call");
}else{
oops.gui.toast("铜币不足!");
}
}
better_call(){
if(smc.vm_data.mission.coin >= smc.vm_data.mission.better_cost){
smc.vm_data.mission.coin -= smc.vm_data.mission.better_cost
oops.message.dispatchEvent("better_call");
}else{
oops.gui.toast("铜币不够!");
}
}
do_reward(){
if(!smc.vm_data.mission.coin >= smc.vm_data.mission.enhancement_cost) return
smc.vm_data.mission.coin -= smc.vm_data.mission.enhancement_cost
smc.vm_data.game_pause = true;
this.reward_lv+=1
this.rewards_set=JSON.parse(JSON.stringify(RewardSet[1]));
// console.log("rewards_set:",this.rewards_set,RewardSet[1])
let i=RandomManager.instance.getRandomInt(0,this.rewards_set.length-1, 2)
this.rewards[1]=this.rewards_set[i]
this.rewards_set.splice(i,1)
// console.log("rewards:",i,this.rewards_set)
i=RandomManager.instance.getRandomInt(0,this.rewards_set.length-1, 2)
this.rewards[2]=this.rewards_set[i]
this.rewards_set.splice(i,1)
// console.log("rewards:",i,this.rewards_set)
i=RandomManager.instance.getRandomInt(0,this.rewards_set.length-1, 2)
this.rewards[3]=this.rewards_set[i]
this.rewards_set=[]
// console.log("rewards:",i,this.rewards,this.rewards_set)
let re1=this.node.getChildByName('rewards').getChildByName('reward1')
let re2=this.node.getChildByName('rewards').getChildByName('reward2')
let re3=this.node.getChildByName('rewards').getChildByName('reward3')
re1.getChildByName('name').getComponent(Label).string=this.rewards[1].name
re2.getChildByName('name').getComponent(Label).string=this.rewards[2].name
re3.getChildByName('name').getComponent(Label).string=this.rewards[3].name
re1.getChildByName('info').getComponent(Label).string=this.rewards[1].info
re2.getChildByName('info').getComponent(Label).string=this.rewards[2].info
re3.getChildByName('info').getComponent(Label).string=this.rewards[3].info
resources.load("gui/rewards", SpriteAtlas, (err: any, atlas) => {
let pathName: string = this.rewards[1].path;
let node=re1.getChildByName('icon')
node.getComponent(Sprite).spriteFrame = atlas.getSpriteFrame(pathName);
pathName=this.rewards[2].path;
node=re2.getChildByName('icon')
node.getComponent(Sprite).spriteFrame = atlas.getSpriteFrame(pathName);
pathName=this.rewards[3].path;
node=re3.getChildByName('icon')
node.getComponent(Sprite).spriteFrame = atlas.getSpriteFrame(pathName);
})
this.node.getChildByName('rewards').active = true;
}
colse_reward(value:number){
this.node.getChildByName('rewards').active = false;
smc.vm_data.game_pause = false;
let reward=this.rewards[value]
if(reward.type==1){
smc.vm_data.mission.hero.atk += reward.atk / 100
smc.vm_data.mission.hero.atk_cd += reward.atk_cd/100
smc.vm_data.mission.hero.hp += reward.hp / 100;
this.add_hero_hp_max(reward.hp / 100)
smc.vm_data.mission.coin_reward_add += reward.coin / 100
}
console.log("card mission",smc.vm_data.mission)
}
do_reward_1(){
this.colse_reward(1)
}
do_reward_2(){
this.colse_reward(2)
}
do_reward_3(){
this.colse_reward(3)
}
add_hero_hp_max(hp:number){
let heros:any = ecs.query(ecs.allOf(HeroModelComp));
if (heros.length > 0) {
for (let i = 0; i < heros.length; i++) {
let hero = heros[i];
if(!hero.HeroView) continue
hero.HeroView.add_hp_max(Math.floor(hero.HeroView.hp_max*hp))
}
}
}
protected update(dt: number): void {
if(smc.vm_data.game_over||smc.vm_data.game_pause){
return
}
this.coin_add(dt)
}
coin_add(dt: number) {
smc.vm_data.gold.time += dt;
if (smc.vm_data.gold.time >= smc.vm_data.gold.cd) {
let coin =(GameSet.COIN_ADD*smc.vm_data.mission.coin_reward_add*(1+Talents[1006].bonus*smc.vm_data.talent[1006].lv)).toFixed(0)
smc.vm_data.mission.coin += parseFloat(coin)
smc.vm_data.gold.time = 0;
}
}
to_mission(){
this.node.getChildByName("mission_home").active=true
this.node.getChildByName("hero_home").active=false
this.node.getChildByName("shop_home").active=false
this.node.getChildByName("bar").getChildByName("mission_btn").getChildByName("bg").active=true
this.node.getChildByName("bar").getChildByName("hero_btn").getChildByName("bg").active=false
this.node.getChildByName("bar").getChildByName("home_btn").getChildByName("bg").active=false
this.node.getChildByName("bar").getChildByName("mission_btn").setScale(1.2,1.2)
this.node.getChildByName("bar").getChildByName("hero_btn").setScale(1,1)
this.node.getChildByName("bar").getChildByName("home_btn").setScale(1,1)
}
mission_start(){
this.node.getChildByName("bar").active=false;
this.node.getChildByName("mission_home").active=false
this.node.getChildByName("mission").active=true
smc.vm_data.mission.play = true;
oops.message.dispatchEvent("mission_start")
}
to_home(){
this.node.getChildByName("mission_home").active=false
this.node.getChildByName("hero_home").active=false
this.node.getChildByName("shop_home").active=true
this.node.getChildByName("bar").getChildByName("mission_btn").getChildByName("bg").active=false
this.node.getChildByName("bar").getChildByName("hero_btn").getChildByName("bg").active=false
this.node.getChildByName("bar").getChildByName("home_btn").getChildByName("bg").active=true
this.node.getChildByName("bar").getChildByName("mission_btn").setScale(1,1)
this.node.getChildByName("bar").getChildByName("hero_btn").setScale(1,1)
this.node.getChildByName("bar").getChildByName("home_btn").setScale(1.2,1.2)
}
to_hero(){
this.node.getChildByName("mission_home").active=false
this.node.getChildByName("hero_home").active=true
this.node.getChildByName("shop_home").active=false
this.node.getChildByName("bar").getChildByName("mission_btn").getChildByName("bg").active=false
this.node.getChildByName("bar").getChildByName("hero_btn").getChildByName("bg").active=true
this.node.getChildByName("bar").getChildByName("home_btn").getChildByName("bg").active=false
this.node.getChildByName("bar").getChildByName("mission_btn").setScale(1,1)
this.node.getChildByName("bar").getChildByName("hero_btn").setScale(1.2,1.2)
this.node.getChildByName("bar").getChildByName("home_btn").setScale(1,1)
}
/** 视图对象通过 ecs.Entity.remove(ControllerComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}