复制的数据 删除后的 代码需要注意
This commit is contained in:
@@ -13,8 +13,6 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('CardControllerComp')
|
||||
@ecs.register('CardController', false)
|
||||
export class CardControllerComp extends CCComp {
|
||||
|
||||
|
||||
|
||||
card_level:number = 1;
|
||||
in_load:boolean = false
|
||||
@@ -37,122 +35,14 @@ export class CardControllerComp extends CCComp {
|
||||
reward_lv = 0;
|
||||
|
||||
protected onLoad(): void {
|
||||
oops.message.on("do_reward", this.do_reward, this);
|
||||
|
||||
let card1 = this.node.getChildByName("cards").getChildByName("card1");
|
||||
let card2 = this.node.getChildByName("cards").getChildByName("card2");
|
||||
let card3 = this.node.getChildByName("cards").getChildByName("card3");
|
||||
let card4 = this.node.getChildByName("cards").getChildByName("card4");
|
||||
let card5 = this.node.getChildByName("cards").getChildByName("card5");
|
||||
let card6 = this.node.getChildByName("cards").getChildByName("card6");
|
||||
// info_button.on(NodeEventType.TOUCH_START, this.onTouchMove, this);
|
||||
// info_button.on(NodeEventType.TOUCH_MOVE, this.onTouchMove, this);
|
||||
card1.on(NodeEventType.TOUCH_START, this.touch1, this);
|
||||
card1.on(NodeEventType.TOUCH_MOVE, this.touch1, this);
|
||||
card2.on(NodeEventType.TOUCH_START, this.touch2, this);
|
||||
card2.on(NodeEventType.TOUCH_MOVE, this.touch2, this);
|
||||
card3.on(NodeEventType.TOUCH_START, this.touch3, this);
|
||||
card3.on(NodeEventType.TOUCH_MOVE, this.touch3, this);
|
||||
card4.on(NodeEventType.TOUCH_START, this.touch4, this);
|
||||
card4.on(NodeEventType.TOUCH_MOVE, this.touch4, this);
|
||||
card5.on(NodeEventType.TOUCH_START, this.touch5, this);
|
||||
card5.on(NodeEventType.TOUCH_MOVE, this.touch5, this);
|
||||
card6.on(NodeEventType.TOUCH_START, this.touch6, this);
|
||||
card6.on(NodeEventType.TOUCH_MOVE, this.touch6, this);
|
||||
|
||||
card1.on(NodeEventType.TOUCH_END, this.end1, this);
|
||||
card1.on(NodeEventType.TOUCH_CANCEL, this.end1, this);
|
||||
card2.on(NodeEventType.TOUCH_END, this.end2, this);
|
||||
card2.on(NodeEventType.TOUCH_CANCEL, this.end2, this);
|
||||
card3.on(NodeEventType.TOUCH_END, this.end3, this);
|
||||
card3.on(NodeEventType.TOUCH_CANCEL, this.end3, this);
|
||||
card4.on(NodeEventType.TOUCH_END, this.end4, this);
|
||||
card4.on(NodeEventType.TOUCH_CANCEL, this.end4, this);
|
||||
card5.on(NodeEventType.TOUCH_END, this.end5, this);
|
||||
card5.on(NodeEventType.TOUCH_CANCEL, this.end5, this);
|
||||
card6.on(NodeEventType.TOUCH_END, this.end6, this);
|
||||
card6.on(NodeEventType.TOUCH_CANCEL, this.end6, this);
|
||||
|
||||
|
||||
oops.message.on("do_reward", this.do_reward, this)
|
||||
}
|
||||
start() {
|
||||
this.load_cards()
|
||||
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
||||
// this.on(ModuleEvent.Cmd, this.onHandler, this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/** 全局消息逻辑处理 */
|
||||
// private onHandler(event: string, args: any) {
|
||||
// switch (event) {
|
||||
// case ModuleEvent.Cmd:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
touch1(event: EventTouch) {
|
||||
this.in_touch=true
|
||||
if(this.in_load)return
|
||||
if(!this.cards[1].alive)return
|
||||
this.show_info(this.cards[1].uuid,this.cards[1].type)
|
||||
}
|
||||
|
||||
touch2(event: EventTouch) {
|
||||
this.in_touch=true
|
||||
if(this.in_load)return
|
||||
if(!this.cards[2].alive)return
|
||||
this.show_info(this.cards[2].uuid,this.cards[2].type)
|
||||
}
|
||||
|
||||
touch3(event: EventTouch) {
|
||||
this.in_touch=true
|
||||
if(this.in_load)return
|
||||
if(!this.cards[3].alive)return
|
||||
this.show_info(this.cards[3].uuid,this.cards[3].type)
|
||||
}
|
||||
|
||||
touch4(event: EventTouch) {
|
||||
this.in_touch=true
|
||||
if(this.in_load)return
|
||||
if(!this.cards[4].alive)return
|
||||
this.show_info(this.cards[4].uuid,this.cards[4].type)
|
||||
}
|
||||
|
||||
touch5(event: EventTouch) {
|
||||
this.in_touch=true
|
||||
if(this.in_load)return
|
||||
if(!this.cards[5].alive)return
|
||||
this.show_info(this.cards[5].uuid,this.cards[5].type)
|
||||
}
|
||||
|
||||
touch6(event: EventTouch) {
|
||||
this.in_touch=true
|
||||
if(this.in_load)return
|
||||
if(!this.cards[6].alive)return
|
||||
this.show_info(this.cards[6].uuid,this.cards[6].type)
|
||||
}
|
||||
end1(event: EventTouch) {
|
||||
this.onTouchEnd(1)
|
||||
}
|
||||
|
||||
end2(event: EventTouch) {
|
||||
this.onTouchEnd(2)
|
||||
}
|
||||
|
||||
end3(event: EventTouch) {
|
||||
this.onTouchEnd(3)
|
||||
}
|
||||
|
||||
end4(event: EventTouch) {
|
||||
this.onTouchEnd(4)
|
||||
}
|
||||
|
||||
end5(event: EventTouch) {
|
||||
this.onTouchEnd(5)
|
||||
}
|
||||
|
||||
end6(event: EventTouch) {
|
||||
this.onTouchEnd(6)
|
||||
}
|
||||
|
||||
|
||||
show_info(uuid:number,type:number){
|
||||
// console.log("show_info",uuid)
|
||||
let node =this.node.getChildByName("item_box")
|
||||
@@ -173,199 +63,37 @@ export class CardControllerComp extends CCComp {
|
||||
}
|
||||
}
|
||||
}
|
||||
onTouchEnd(index:number){
|
||||
if(this.touch_time < 0.2){
|
||||
this.use_card(index)
|
||||
}
|
||||
this.in_touch=false
|
||||
this.touch_time = 0
|
||||
let node = this.node.getChildByName("item_box")
|
||||
node.active=false
|
||||
node.getChildByName("data").getChildByName("shield").active=false
|
||||
node.getChildByName("data").getChildByName("hp").active=false
|
||||
}
|
||||
shuaxin(dt: number) {
|
||||
smc.vm_data.shuaxin.min += smc.vm_data.shuaxin.speed*dt;
|
||||
if (smc.vm_data.shuaxin.min >= smc.vm_data.shuaxin.max) {
|
||||
smc.vm_data.shuaxin.min = 0;
|
||||
this.load_cards()
|
||||
}
|
||||
}
|
||||
// cards_update(){
|
||||
// if(smc.vm_data.gold.min >= smc.vm_data.cards.up_cost){
|
||||
// smc.vm_data.gold.min -= smc.vm_data.cards.up_cost;
|
||||
// smc.vm_data.cards.level += 1;
|
||||
// smc.vm_data.gold.max +=2;
|
||||
// smc.vm_data.cards.up_cost += 2
|
||||
// if(smc.vm_data.cards.level >= smc.vm_data.cards.level_max){
|
||||
// smc.vm_data.cards.level = smc.vm_data.cards.level_max;
|
||||
// smc.vm_data.cards.up_cost = 11
|
||||
// }
|
||||
// console.log("card _level:"+this.card_level+"cost:"+smc.vm_data.cards.up_cost)
|
||||
// }else{
|
||||
// oops.gui.toast("金币不够");
|
||||
// }
|
||||
// }
|
||||
palyer_ref(){
|
||||
if (this.in_load) {
|
||||
return
|
||||
}
|
||||
if((smc.vm_data.shuaxin.max-smc.vm_data.shuaxin.min) < 0.5 ){
|
||||
oops.gui.toast("马上就要刷新了")
|
||||
return
|
||||
}
|
||||
if(smc.vm_data.shuaxin.min < 0.5){
|
||||
oops.gui.toast("不要刷新太快哦")
|
||||
return
|
||||
}
|
||||
if (smc.vm_data.gold.min < smc.vm_data.cards.ref_cost) {
|
||||
oops.gui.toast("金币不足")
|
||||
return
|
||||
}
|
||||
smc.vm_data.gold.min -= smc.vm_data.cards.ref_cost;
|
||||
this.load_cards()
|
||||
smc.vm_data.shuaxin.min = -5
|
||||
if(smc.vm_data.shuaxin.min <=0 ){
|
||||
smc.vm_data.shuaxin.min = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
load_cards() {
|
||||
this.in_load = true
|
||||
|
||||
let card:any=null
|
||||
for (let index = 1; index <= 6; index++) {
|
||||
card=RandomManager.instance.getRandomByObjectList(smc.cards, 1);
|
||||
this.cards[index].uuid=card[0].uuid
|
||||
this.cards[index].type=card[0].type
|
||||
|
||||
let url: string = "";
|
||||
let pathName: string = "";
|
||||
let name: string = "";
|
||||
let level: number = 0;
|
||||
let cost: number = 0;
|
||||
let { uuid, type } = card[0];
|
||||
url = "game/hero/hero_icon";
|
||||
({ uuid: pathName, name, level ,cost} = smc.heros[uuid]);
|
||||
this.cards[index].lv=level
|
||||
this.cards[index].cost = cost
|
||||
let node=this.node.getChildByName('cards').getChildByName('card'+index)
|
||||
node.getChildByName('cost').getComponent(Label).string=cost.toString()
|
||||
node.getChildByName('lv').getChildByName('lv').getComponent(Label).string=level.toString()
|
||||
node.getChildByName('name').getComponent(Label).string=name
|
||||
// const sprite = node.getChildByName("item").getComponent(Sprite);
|
||||
// console.log(this['card'+index],url,pathName,sprite)
|
||||
resources.load(url, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = node.getChildByName("item").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(pathName);
|
||||
});
|
||||
this.cards[index].alive=true
|
||||
}
|
||||
// for (let index = 5; index <= 6; index++) {
|
||||
// card=RandomManager.instance.getRandomByObjectList(smc.item_list, 1);
|
||||
// this.cards[index].uuid=card[0].uuid
|
||||
// this.cards[index].type=card[0].type
|
||||
// let url: string = "";
|
||||
// let pathName: string = "";
|
||||
// let name: string = "";
|
||||
// let level: number = 0;
|
||||
// let { uuid, type } = card[0];
|
||||
// url = "game/heros/skill";
|
||||
// ({ path: pathName, name, level } = smc.items[uuid]);
|
||||
// this.cards[index].lv=level
|
||||
// let node=this.node.getChildByName('cards').getChildByName('card'+index)
|
||||
// node.getChildByName('cost').getComponent(Label).string=level.toString()
|
||||
// node.getChildByName('name').getComponent(Label).string=name
|
||||
// // const sprite = node.getChildByName("item").getComponent(Sprite);
|
||||
// // console.log(this['card'+index],url,pathName,sprite)
|
||||
// resources.load(url, SpriteAtlas, (err: any, atlas) => {
|
||||
// const sprite = node.getChildByName("item").getComponent(Sprite);
|
||||
// sprite.spriteFrame = atlas.getSpriteFrame(pathName);
|
||||
// });
|
||||
// this.cards[index].alive=true
|
||||
// }
|
||||
// console.log("cards:",this.cards)
|
||||
this.in_load = false
|
||||
}
|
||||
remove_card(index:number){
|
||||
this.cards[index].alive=false
|
||||
this.cards[index].uuid=0
|
||||
this.cards[index].type=0
|
||||
this.cards[index].lv=0
|
||||
let url: string = "gui/gui";
|
||||
let pathName: string = "129";
|
||||
let node=this.node.getChildByName('cards').getChildByName('card'+index)
|
||||
node.getChildByName('cost').getComponent(Label).string=""
|
||||
node.getChildByName('name').getComponent(Label).string=""
|
||||
// const sprite = node.getChildByName("item").getComponent(Sprite);
|
||||
// console.log(this['card'+index],url,pathName,sprite)
|
||||
resources.load(url, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = node.getChildByName("item").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(pathName);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
use_card(index: number){
|
||||
this.check_card(index)
|
||||
// console.log("cards:",this.cards)
|
||||
}
|
||||
check_card(index:number){
|
||||
// let heros = ecs.query(ecs.allOf(HeroModelComp))
|
||||
// let heross= ecs.query(ecs.allOf(MonsterViewComp))
|
||||
// console.log("heross",heross)
|
||||
// if(heros.length >= 4&&this.cards[index].type == 1){
|
||||
// oops.gui.toast("英雄数量达到上限");
|
||||
// return;
|
||||
// }
|
||||
if(!this.cards[index].alive) {
|
||||
// console.log("card_index:",index,"card_alive:",this.cards[index].alive)
|
||||
return;
|
||||
};
|
||||
if(smc.vm_data.gold.min >= this.cards[index].cost){
|
||||
this.cards[index].alive=false
|
||||
this.do_use_card(index)
|
||||
|
||||
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("金币不够");
|
||||
oops.gui.toast("铜币不够!");
|
||||
|
||||
}
|
||||
}
|
||||
do_use_card(index:number){
|
||||
this.cards[index].alive=false
|
||||
smc.vm_data.gold.min -= this.cards[index].cost;
|
||||
oops.message.dispatchEvent("do_add_hero", { uuid: this.cards[index].uuid });
|
||||
// switch (this.cards[index].type) {
|
||||
// case 1:
|
||||
// oops.message.dispatchEvent("do_add_hero", { uuid: this.cards[index].uuid });
|
||||
// break;
|
||||
// case 2:
|
||||
// oops.message.dispatchEvent("do_use_item", { uuid: this.cards[index].uuid });
|
||||
// break;
|
||||
// case 3:
|
||||
// oops.message.dispatchEvent("do_use_item", { uuid: this.cards[index].uuid });
|
||||
// break;
|
||||
// }
|
||||
this.remove_card(index)
|
||||
}
|
||||
|
||||
|
||||
|
||||
do_reward(){
|
||||
smc.vm_data.game_pause = true;
|
||||
this.reward_lv+=1
|
||||
this.rewards_set=RewardSet[this.reward_lv]
|
||||
let i=RandomManager.instance.getRandomInt(0,this.rewards_set.length-1, 1)
|
||||
console.log("rewards:",i)
|
||||
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)
|
||||
i=RandomManager.instance.getRandomInt(0,this.rewards_set.length-1, 1)
|
||||
console.log("rewards:",i)
|
||||
// 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)
|
||||
i=RandomManager.instance.getRandomInt(0,this.rewards_set.length-1, 1)
|
||||
console.log("rewards:",i)
|
||||
// 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:",this.rewards)
|
||||
// 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')
|
||||
@@ -398,17 +126,13 @@ export class CardControllerComp extends CCComp {
|
||||
smc.vm_data.game_pause = false;
|
||||
let reward=this.rewards[value]
|
||||
if(reward.type==1){
|
||||
if(reward.atk > 0){
|
||||
smc.vm_data.mission.hero.atk += reward.atk / 100
|
||||
}
|
||||
if(reward.atk_cd > 0){
|
||||
smc.vm_data.mission.hero.atk_cd -= reward.atk_cd/100
|
||||
}
|
||||
if(reward.hp > 0){
|
||||
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)
|
||||
@@ -433,18 +157,15 @@ export class CardControllerComp extends CCComp {
|
||||
if(smc.vm_data.game_over||smc.vm_data.game_pause){
|
||||
return
|
||||
}
|
||||
this.shuaxin(dt)
|
||||
// this.gold_add(dt)
|
||||
this.coin_add(dt)
|
||||
|
||||
if(this.in_touch){
|
||||
this.touch_time+=dt
|
||||
}
|
||||
}
|
||||
|
||||
gold_add(dt: number) {
|
||||
coin_add(dt: number) {
|
||||
smc.vm_data.gold.time += dt;
|
||||
if (smc.vm_data.gold.time >= smc.vm_data.gold.cd) {
|
||||
smc.vm_data.gold.min += 1;
|
||||
let coin =(smc.vm_data.mission.coin_add*smc.vm_data.mission.coin_reward_add*(1+smc.vm_data.talent[6].bonus*smc.vm_data.talent[6].lv)).toFixed(0)
|
||||
smc.vm_data.mission.coin += parseFloat(coin)
|
||||
smc.vm_data.gold.time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user