当前位置: 首页 > news >正文

游戏任务简单设计

对!这样最省事。两种超简单的实现方案:

方案一:所有任务同时开启 📋
TYPESCRIPT
@ccclass(‘LazyQuestManager’)
export class LazyQuestManager extends Component {

@property([QuestData])
allQuests: QuestData[] = []; // 编辑器里配置所有任务private activeQuestIds: Set<string> = new Set();start() {// 游戏开始:所有任务全开!this.allQuests.forEach(quest => {this.activeQuestIds.add(quest.id);this.showQuest(quest);});console.log(`🎯 已开启${this.allQuests.length}个任务,随便做吧!`);
}onLoad() {// 监听各种完成信号director.on('QUEST_CONDITION_MET', this.onConditionMet, this);
}private onConditionMet(conditionData: any) {if (this.activeQuestIds.has(conditionData.questId)) {console.log(`✅ ${conditionData.questId} 完成了一项`);// 直接显示完成,不用检查进度director.emit('QUEST_COMPLETED', {id: conditionData.questId,title: this.getQuestTitle(conditionData.questId)});// 从激活列表移除this.activeQuestIds.delete(conditionData.questId);}
}private showQuest(quest: QuestData) {director.emit('SHOW_QUEST', {id: quest.id,title: quest.title,description: quest.description});
}

}
方案二:随机挑几个任务开启 🎲
TYPESCRIPT
@ccclass(‘RandomQuestManager’)
export class RandomQuestManager extends Component {

@property([QuestData])
allQuests: QuestData[] = [];@property
maxActiveQuests: number = 3; // 同时最多显示几个任务private activeQuestIds: Set<string> = new Set();start() {// 随机选几个任务开启this.pickRandomQuests();// 每5分钟重新随机一次this.schedule(this.pickRandomQuests, 300);
}private pickRandomQuests() {// 清空当前任务this.activeQuestIds.clear();director.emit('CLEAR_ALL_QUESTS');// 打乱任务数组const shuffled = [...this.allQuests].sort(() => Math.random() - 0.5);// 选取前N个const selected = shuffled.slice(0, this.maxActiveQuests);selected.forEach(quest => {this.activeQuestIds.add(quest.id);this.showQuest(quest);});console.log(`🎲 刷新了${selected.length}个随机任务`);
}private showQuest(quest: QuestData) {director.emit('SHOW_QUEST', {id: quest.id,title: quest.title,description: quest.description,icon: this.getRandomQuestIcon() // 连图标都随机!});
}private getRandomQuestIcon(): string {const icons = ["🔍", "⚔️", "📦", "🏃", "🗺️", "🔧", "💡", "🎯"];return icons[Math.floor(Math.random() * icons.length)];
}

}
对应的极简条件脚本 🎯
TYPESCRIPT
// 所有条件脚本都长这样,超简单!
@ccclass(‘SimpleCondition’)
export class SimpleCondition extends Component {

@property
questId: string = ""; // 对应哪个任务@property
conditionType: string = ""; // 条件类型start() {// 根据类型监听不同事件switch(this.conditionType) {case "COLLECT":director.on('ITEM_COLLECTED', this.onCollect, this);break;case "KILL":director.on('ZOMBIE_KILLED', this.onKill, this);break;case "LOCATION":director.on('PLAYER_MOVED', this.onMove, this);break;}
}private onCollect(itemId: string) {director.emit('QUEST_CONDITION_MET', {questId: this.questId,type: "COLLECT"});
}private onKill(zombieType: string) {director.emit('QUEST_CONDITION_MET', {questId: this.questId, type: "KILL"});
}private onMove(location: string) {director.emit('QUEST_CONDITION_MET', {questId: this.questId,type: "LOCATION" });
}

}
在编辑器中的傻瓜式配置 🛠️
任务数据配置:
TYPESCRIPT
// 在QuestManager里填表:
allQuests: [
{ id: “find_sunscreen”, title: “找到防晒霜”, description: “沙滩上应该还有剩下的防晒霜” },
{ id: “kill_zombies”, title: “清理僵尸”, description: “把海滩上的僵尸赶走” },
{ id: “build_raft”, title: “造个小木筏”, description: “收集材料造个能漂的东西” },
{ id: “find_food”, title: “找点吃的”, description: “饿死了,找点零食” },
{ id: “signal_help”, title: “发求救信号”, description: “让过往船只看到我们” }
// …想加多少加多少
]
条件脚本摆放:
TEXT
场景中的各种节点:
├── Condition_FindSunscreen (SimpleCondition脚本)
│ └── 属性: questId = “find_sunscreen”, conditionType = “COLLECT”
├── Condition_KillZombies (SimpleCondition脚本)
│ └── 属性: questId = “kill_zombies”, conditionType = “KILL”
├── Condition_BuildRaft (SimpleCondition脚本)
│ └── 属性: questId = “build_raft”, conditionType = “COLLECT”
└── Condition_ReachLighthouse (SimpleCondition脚本)
└── 属性: questId = “signal_help”, conditionType = “LOCATION”
极简任务UI 🖥️
TYPESCRIPT
@ccclass(‘SimpleQuestUI’)
export class SimpleQuestUI extends Component {

@property(Label)
questLabel: Label = null!;private activeQuests: string[] = [];onLoad() {director.on('SHOW_QUEST', this.onShowQuest, this);director.on('QUEST_COMPLETED', this.onQuestCompleted, this);director.on('CLEAR_ALL_QUESTS', this.onClearQuests, this);
}private onShowQuest(quest: any) {this.activeQuests.push(quest.title);this.updateDisplay();
}private onQuestCompleted(quest: any) {this.activeQuests = this.activeQuests.filter(title => title !== quest.title);this.updateDisplay();// 显示完成特效this.showCompletionEffect(quest.title);
}private updateDisplay() {this.questLabel.string = "当前任务:\n" + this.activeQuests.join("\n");
}private showCompletionEffect(questTitle: string) {console.log(`🎉 ${questTitle} 完成!`);// 可以加个粒子特效或者音效
}

}
运行效果:
方案一:任务列表一打开哗啦啦一长串,玩家随便做哪个都行
方案二:每次只显示几个随机任务,做完自动换新的
这样的好处:
🚀 零管理成本:不用管任务顺序、依赖关系
🎮 玩家自由:想做什么做什么
🔧 开发省事:配置完就不用管了
♻️ 无限重玩:随机任务每次体验都不同
推荐用方案二,既不会让玩家 overwhelmed,又能保持新鲜感!

tokens used: 75884, model: DeepSeek API (deepseek-chat)

http://www.dtcms.com/a/528295.html

相关文章:

  • 平台网站建设ppt模板下载阿里巴巴的电子商务网站建设
  • GitHub等平台形成的开源文化正在重塑脱离了
  • Linux18--进程间的通信总结
  • 基于脚手架微服务的视频点播系统-脚手架开发部分-FFmpeg,Etcd-SDK的简单使用与二次封装
  • 【教学类-120-01】20251025旋转数字
  • 制作网站多少钱一个有哪些做企业点评的网站
  • 网站会员营销上海注册公司哪家好
  • 【深度学习新浪潮】深入理解Seed3D模型:参数化驱动的下一代3D内容生成技术
  • GitHub等平台形成的开源文化正在重塑和人家
  • 免费网站收录入口有了域名空间服务器怎么做网站
  • 5.go-zero集成gorm 和 go-redis
  • Linux系统入门:System V进程间通信
  • 第一章 蓝图篇 - 全景认知与项目设计
  • mormot.net.server.pas源代码分析
  • 丹阳网站建设价位php网站搭建
  • 【工具分享】另一个免费开源的远程桌面服务-Apache Guacamole
  • RabbitMQ TTL机制详解
  • XSL-FO 对象:深度解析与实际应用
  • 在JavaScript / Node.js / 抖音小游戏中,使用tt.request通信
  • 两学一做网站源码wordpress 柚子皮下载
  • Go slog 日志打印最佳实践指南
  • Go的垃圾回收
  • 珠海网站管理公司国际公司名字
  • 自动化模型学习器——autoGluon
  • 长沙网站建设招聘外贸做那种网站有哪些
  • 浏览器卡顿内存高?傲游浏览器三核加速,网页加载效率提升60%
  • 研发部门验收流程
  • 贪心算法 with Gemini
  • 掌握 Rust:从内存安全到高性能服务的完整技术图谱
  • [Java]重学Java-Java平台