修改了挺多, 继续完善 战斗流程设计

This commit is contained in:
2025-06-13 10:59:41 +08:00
parent 3312c2addf
commit 2376c952d2
12 changed files with 2544 additions and 1640 deletions

View File

@@ -1,5 +1,6 @@
import { _decorator, Component, Node, view, UITransform, Vec3, math, EventHandler, Graphics, Color, TweenEasing, Enum } from 'cc';
import { SkillCom } from '../skills/SkillCom';
import { smc } from '../common/SingletonModuleComp';
const { ccclass, property } = _decorator;
// 定义缓动类型枚举
@@ -139,7 +140,7 @@ export class BezierMove extends Component {
update(deltaTime: number) {
if (!this._isMoving || this._totalTime <= 0) return; // 如果没有移动或路径生成失败,则返回
if (!this._isMoving || this._totalTime <= 0||smc.mission.pause||!smc.mission.play) return; // 如果没有移动或路径生成失败,则返回
// 更新进度
this._t += deltaTime / this._totalTime;
@@ -152,7 +153,7 @@ export class BezierMove extends Component {
this.node.setPosition(this._endPoint);
this._isMoving = false;
// 触发移动完成事件
console.log("onMoveComplete")
// console.log("onMoveComplete")
let skill=this.node.getComponent(SkillCom)
if(skill){
skill.doDestroy()

View File

@@ -18,6 +18,7 @@ export class SingletonModuleComp extends ecs.Comp {
status:0, //0:未开始 1:进行中 2:胜利 3:失败
play:false,
pause:false,
in_select:false,
score:888,
};
fight_heros=[]

View File

@@ -40,4 +40,5 @@ export enum GameEvent {
EquipRemove = "EquipRemove",
EquipSelect = "EquipSelect",
EquipSelectEnd = "EquipSelectEnd",
WaveUpdate = "WaveUpdate",
}

View File

@@ -52,32 +52,34 @@ export const MissionStatus = {
end:4,
}
export enum FightSet {
ATK_TO_ATK_RATIO=0.1,
ATK_TO_HP_RATIO=0.2,
ATK_TO_SHIELD_RATIO=2,
ATK_LINES = 3, //英雄数
MON_GOLD_ADD =2,
MON_COIN_ADD=2,
COIN_ADD=1,
DEF_RATE=0.7,
DODGE_MAX=70,
HERO_NUM=3,
AP_UPDATE_RATE=100,
AP_CHANGE_RATE=0,
FRIND_WAVE_UP=2, //伙伴登场波次
// ATK_TO_ATK_RATIO=0.1,
// ATK_TO_HP_RATIO=0.2,
// ATK_TO_SHIELD_RATIO=2,
// ATK_LINES = 3, //英雄数
// MON_GOLD_ADD =2,
// MON_COIN_ADD=2,
// COIN_ADD=1,
// DEF_RATE=0.7,
// DODGE_MAX=70,
// HERO_NUM=3,
// AP_UPDATE_RATE=100,
// AP_CHANGE_RATE=0,
}
export const MissionData = {
gold:10,//金币
score:0,//分数
refrsh_time:5, //刷新时间
refresh_gold:3,//刷新金币
refrsh_time:1, //刷新时间
call_gold:0,//召唤金币
add_gold:1,//金币增加
change_gold:0,//金币变化
exp:0,//经验
skp:0,//技能点
box:0,//宝箱
energy:0,//能量
hp:0,//血量
ap:0,//攻击
lv:0,
back_gold:1,//返还金币
buff_back_gold:0,//额外返还金币
buff_add_gold:0,//额外增加金币
buff_refrsh_time:0,//额外刷新时间
buff_refresh_gold:0,//额外发现所需的金币
current_wave:0,
in_fight:false,
fight_time:0,//战斗时间
}

View File

@@ -25,7 +25,7 @@ export class CardComp extends CCComp {
onLoad(){
// this.on(GameEvent.HeroSelect,this.hero_select,this)
// this.on(GameEvent.HeroSkillSelect,this.hero_skill_select,this)
this.on(GameEvent.CardRefresh,this.onCardRefresh,this)
// this.on(GameEvent.CardRefresh,this.rad,this)
}
start() {
@@ -36,10 +36,10 @@ export class CardComp extends CCComp {
this.node.getChildByName("Button").active=false
this.node.getChildByName("show").active=false
}
hero_select(event: string, args: any){
hero_select(args: any){
this.c_type=0
this.c_uuid=args.uuid
console.log("onCardRefresh c_uuid:"+this.c_uuid)
console.log("card hero_select c_uuid:"+this.c_uuid)
this.show_hero(this.c_uuid)
this.node.getChildByName("show").active=false
this.node.getChildByName("anim").getChildByName("up").getComponent(Animation).play('carsup')
@@ -48,7 +48,7 @@ export class CardComp extends CCComp {
this.node.getChildByName("Button").active=true
}, 0.1);
}
hero_skill_select(event: string, args: any){
hero_skill_select(args: any){
this.c_type=1
console.log("card hero_skill_select",args)
this.c_uuid=args.uuid
@@ -60,7 +60,7 @@ export class CardComp extends CCComp {
this.node.getChildByName("Button").active=true
}, 0.1);
}
equip_select(event: string, args: any){
equip_select(args: any){
this.c_type=2
this.c_uuid=args.uuid
this.node.getChildByName("show").active=false
@@ -70,20 +70,22 @@ export class CardComp extends CCComp {
this.node.getChildByName("show").active=true
this.node.getChildByName("Button").active=true
}, 0.1);
}
onCardRefresh(event: string, args: any){
let card =getRandomCardUUID()
console.log("onCardRefresh 开始请求卡牌",card)
}
func_select(args: any){
console.log("card func_select",args)
}
random_select(){
let card =getRandomCardUUID() //随机获取卡牌类型
console.log("rad 开始请求卡牌",card)
switch(card.type){
case cardType.HERO:
this.hero_select(GameEvent.HeroSelect,card)
this.hero_select(card)
break
case cardType.SKILL:
this.hero_skill_select(GameEvent.HeroSkillSelect,card)
this.hero_skill_select(card)
break
case cardType.EQUIP:
this.equip_select(GameEvent.EquipSelect,card)
this.equip_select(card)
break
}
}

View File

@@ -4,6 +4,7 @@ import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/modu
import { GameEvent } from "../common/config/GameEvent";
import { CardComp } from "./CardComp";
import { cardType, getRandomCardsByType } from "../common/config/CardSet";
import { smc } from "../common/SingletonModuleComp";
const { ccclass, property } = _decorator;
@@ -20,16 +21,22 @@ export class CardsCompComp extends CCComp {
card3c:CardComp=null
card4c:CardComp=null
/** 卡牌展示队列 */
private cardQueue: Array<{type: GameEvent, data?: any}> = [];
/** 是否正在展示卡牌 */
private isShowing: boolean = false;
/** 视图层逻辑代码分离演示 */
onLoad() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
this.on(GameEvent.HeroSkillSelect, this.onHeroSkillSelect, this);
this.on(GameEvent.HeroSkillSelectEnd, this.hide, this);
this.on(GameEvent.HeroSelect, this.onHeroSelect, this);
this.on(GameEvent.HeroSelectEnd, this.hide, this);
this.on(GameEvent.CardRefresh, this.show, this);
this.on(GameEvent.CardRefreshEnd, this.hide, this);
this.on(GameEvent.CardsClose, this.hide, this);
this.on(GameEvent.HeroSkillSelect, this.addToQueue, this);
this.on(GameEvent.HeroSelect, this.addToQueue, this);
this.on(GameEvent.CardRefresh, this.addToQueue, this);
this.on(GameEvent.HeroSkillSelectEnd, this.close_cards, this);
this.on(GameEvent.HeroSelectEnd, this.close_cards, this);
this.on(GameEvent.CardRefreshEnd, this.close_cards, this);
this.on(GameEvent.CardsClose, this.close_cards, this);
this.card1=this.node.getChildByName("card1")
this.card2=this.node.getChildByName("card2")
@@ -42,29 +49,99 @@ export class CardsCompComp extends CCComp {
}
onHeroSelect(event: string, args: any){
this.show(GameEvent.HeroSelect,args)
hero_select(){
let list=getRandomCardsByType(cardType.HERO,4)
console.log("cards onHeroSelect",list)
this.card1c.hero_select(GameEvent.HeroSelect,list[0])
this.card2c.hero_select(GameEvent.HeroSelect,list[1])
this.card3c.hero_select(GameEvent.HeroSelect,list[2])
this.card4c.hero_select(GameEvent.HeroSelect,list[3])
console.log("英雄选择卡牌列表",list)
this.card1c.hero_select(list[0])
this.card2c.hero_select(list[1])
this.card3c.hero_select(list[2])
this.card4c.hero_select(list[3])
}
onHeroSkillSelect(event: string, args: any){
hero_skill_select(){
this.show(GameEvent.HeroSkillSelect,args)
let list=getRandomCardsByType(cardType.SKILL,4)
console.log("cards onHeroSkillSelect",list)
this.card1c.hero_skill_select(GameEvent.HeroSkillSelect,list[0])
this.card2c.hero_skill_select(GameEvent.HeroSkillSelect,list[1])
this.card3c.hero_skill_select(GameEvent.HeroSkillSelect,list[2])
this.card4c.hero_skill_select(GameEvent.HeroSkillSelect,list[3])
console.log("技能选择卡牌列表",list)
this.card1c.hero_skill_select(list[0])
this.card2c.hero_skill_select(list[1])
this.card3c.hero_skill_select(list[2])
this.card4c.hero_skill_select(list[3])
}
equip_select(){
let list=getRandomCardsByType(cardType.EQUIP,4)
console.log("装备选择卡牌列表",list)
this.card1c.equip_select(list[0])
this.card2c.equip_select(list[1])
this.card3c.equip_select(list[2])
this.card4c.equip_select(list[3])
}
func_select(){
console.log("功能选择卡牌")
}
random_select(){
this.card1c.random_select()
this.card2c.random_select()
this.card3c.random_select()
this.card4c.random_select()
}
/** 添加卡牌展示到队列 */
private addToQueue(e: GameEvent, data?: any) {
console.log("添加卡牌到队列", e);
this.cardQueue.push({type: e, data: data});
this.processQueue();
}
show(e:GameEvent,data:any){
/** 处理卡牌队列 */
private processQueue() {
if (this.isShowing || this.cardQueue.length === 0) {
return;
}
const nextCard = this.cardQueue.shift();
this.isShowing = true;
this.show_cards(nextCard.type, nextCard.data);
}
show_cards(e:GameEvent,data:any){
this.node.getChildByName("Button").active=false
switch(e){
case GameEvent.HeroSelect:
console.log("显示英雄选择卡牌")
this.hero_select()
break
case GameEvent.HeroSkillSelect:
console.log("显示技能选择卡牌")
this.hero_skill_select()
break
case GameEvent.CardRefresh:
console.log("显示随机刷新卡牌")
this.node.getChildByName("Button").active=true
this.random_select()
break
}
this.show()
}
close_cards(e:GameEvent,data:any){
switch(e){
case GameEvent.HeroSelect:
console.log("关闭英雄选择卡牌")
break
case GameEvent.HeroSkillSelect:
console.log("关闭技能选择卡牌")
break
case GameEvent.CardRefresh:
console.log("关闭随机刷新卡牌")
break
case GameEvent.CardsClose:
console.log("关闭所有卡牌")
break
}
this.hide()
}
show(){
// 设置初始状态
smc.mission.pause=true
this.node.setPosition(v3(0, 0, 0));
this.node.setScale(v3(0, 0, 1));
@@ -77,7 +154,8 @@ export class CardsCompComp extends CCComp {
.start();
}
hide(e:GameEvent,data:any){
hide(){
smc.mission.pause=false
tween(this.node)
.parallel(
tween().to(0.3, { scale: v3(0, 0, 1) }, { easing: 'backIn' }),
@@ -85,12 +163,23 @@ export class CardsCompComp extends CCComp {
)
.call(()=>{
this.node.setPosition(v3(0, -1000, 0));
this.isShowing = false;
this.processQueue(); // 处理队列中的下一个卡牌
})
.start();
}
//放弃选择
give_up_select(){
this.hide()
let mission_data=smc.vmdata.mission_data
mission_data.gold+=(mission_data.back_gold+mission_data.buff_back_gold) //返还金币
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.cardQueue = [];
this.isShowing = false;
this.node.destroy();
}

View File

@@ -3,7 +3,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
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 { MissionData, Missions, MissionStatus} from "../common/config/Mission";
import { FightSet, MissionData, Missions, MissionStatus} from "../common/config/Mission";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { GameEvent } from "../common/config/GameEvent";
import { HeroViewComp } from "../hero/HeroViewComp";
@@ -21,21 +21,42 @@ export class MissionComp extends CCComp {
reward:number = 0;
reward_num:number = 0;
GlodAddTimer:Timer = new Timer(1);
waveTimer:Timer = new Timer(10);
normal_max_wave:number = 10;
is_fight:boolean = false;
onLoad(){
this.on(GameEvent.MissionStart,this.mission_start,this)
this.on(GameEvent.FightEnd,this.fight_end,this)
this.on(GameEvent.MissionEnd,this.mission_end,this)
this.on(GameEvent.CardsClose,this.after_used_skill_card,this)
this.on(GameEvent.WaveUpdate,this.on_mon_wave_update,this)
}
protected update(dt: number): void {
if(!smc.mission.play||smc.mission.pause){
return
}
if(this.GlodAddTimer.update(dt)){
smc.vmdata.mission_data.gold+=smc.vmdata.mission_data.add_gold
if(smc.vmdata.mission_data.in_fight){
smc.vmdata.mission_data.fight_time+=dt
if(this.GlodAddTimer.update(dt)){
smc.vmdata.mission_data.gold+=(smc.vmdata.mission_data.add_gold+smc.vmdata.mission_data.buff_add_gold)
}
}
}
private on_mon_wave_update(){
smc.vmdata.mission_data.current_wave++
console.log("[任务系统] 当前波次 :",smc.vmdata.mission_data.current_wave)
switch(smc.vmdata.mission_data.current_wave){
case FightSet.FRIND_WAVE_UP:
this.to_hero_select()
break
case 2:
break
case 3:
}
}
async mission_start(){
@@ -60,15 +81,10 @@ export class MissionComp extends CCComp {
after_used_skill_card(){
switch(smc.mission.status){
case MissionStatus.ready_skill_select:
console.log("next to_hero_select")
console.log("next => to_fight")
this.scheduleOnce(()=>{
this.to_hero_select()
this.to_fight()
},0.3)
break
case MissionStatus.ready_hero_select:
console.log("netx to_fight")
this.to_fight()
break
case MissionStatus.playing:
break
@@ -82,6 +98,7 @@ export class MissionComp extends CCComp {
to_fight(){
smc.mission.status=MissionStatus.playing
smc.vmdata.mission_data.in_fight=true
oops.message.dispatchEvent(GameEvent.FightStart)
}
@@ -99,9 +116,11 @@ export class MissionComp extends CCComp {
this.cleanComponents()
}, 0.5)
}
mission_end(){
this.node.active=false
}
data_init(){
//局内数据初始化
console.log("局内数据初始化")
@@ -121,12 +140,13 @@ export class MissionComp extends CCComp {
}
card_refresh(){
if(smc.vmdata.mission_data.gold< smc.vmdata.mission_data.refresh_gold){
let mission_data=smc.vmdata.mission_data
if(mission_data.gold < (mission_data.refresh_gold+mission_data.buff_refresh_gold)){
oops.gui.toast("金币不足", false);
return
}
oops.message.dispatchEvent(GameEvent.CardRefresh)
smc.vmdata.mission_data.gold-=smc.vmdata.mission_data.refresh_gold
mission_data.gold-=(mission_data.refresh_gold+mission_data.buff_refresh_gold)
}

View File

@@ -9,6 +9,7 @@ import { RandomManager } from "db://oops-framework/core/common/random/RandomMana
import { Timer } from "db://oops-framework/core/common/timer/Timer";
import { smc } from "../common/SingletonModuleComp";
import { GameEvent } from "../common/config/GameEvent";
import { oops } from "db://oops-framework/core/Oops";
const { ccclass, property } = _decorator;
@@ -52,7 +53,8 @@ export class MissionMonCompComp extends CCComp {
mon_refresh(){
console.log("mon_refresh:start load monster lv :",smc.mission.lv)
oops.message.dispatchEvent(GameEvent.WaveUpdate)
console.log("怪物登场,当前波次 :",smc.vmdata.mission_data.current_wave)
let positions = [0, 1, 2];
positions.forEach(pos => {
let x = RandomManager.instance.getRandomInt(0, Missions[0].length, 1);

View File

@@ -259,7 +259,7 @@ export class SkillCom extends CCComp {
}
}
doDestroy(){
console.log("doDestroy")
// console.log("doDestroy")
this.is_destroy=true
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */