feat: 新增天赋系统界面及数据模型
- 添加 TalentsComp 组件实现天赋系统界面,包含等级展示、天赋列表和升级功能 - 在 GameUIConfig 中注册天赋界面配置 - 扩展 SingletonModuleComp 数据结构以支持玩家等级、经验和天赋点存储 - 新增天赋系统设计文档和界面预制体资源 - 启用角色控制器中的天赋界面节点
This commit is contained in:
@@ -67,8 +67,8 @@
|
|||||||
"__type__": "cc.RealCurve",
|
"__type__": "cc.RealCurve",
|
||||||
"_times": [
|
"_times": [
|
||||||
0,
|
0,
|
||||||
0.3333333333333333,
|
0.3333333432674408,
|
||||||
0.6666666666666666
|
0.6666666865348816
|
||||||
],
|
],
|
||||||
"_values": [
|
"_values": [
|
||||||
{
|
{
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
"__type__": "cc.RealKeyframeValue",
|
"__type__": "cc.RealKeyframeValue",
|
||||||
"interpolationMode": 0,
|
"interpolationMode": 0,
|
||||||
"tangentWeightMode": 0,
|
"tangentWeightMode": 0,
|
||||||
"value": 1.1,
|
"value": 1.100000023841858,
|
||||||
"rightTangent": 0,
|
"rightTangent": 0,
|
||||||
"rightTangentWeight": 1,
|
"rightTangentWeight": 1,
|
||||||
"leftTangent": 0,
|
"leftTangent": 0,
|
||||||
@@ -127,8 +127,8 @@
|
|||||||
"__type__": "cc.RealCurve",
|
"__type__": "cc.RealCurve",
|
||||||
"_times": [
|
"_times": [
|
||||||
0,
|
0,
|
||||||
0.3333333333333333,
|
0.3333333432674408,
|
||||||
0.6666666666666666
|
0.6666666865348816
|
||||||
],
|
],
|
||||||
"_values": [
|
"_values": [
|
||||||
{
|
{
|
||||||
@@ -149,7 +149,7 @@
|
|||||||
"__type__": "cc.RealKeyframeValue",
|
"__type__": "cc.RealKeyframeValue",
|
||||||
"interpolationMode": 0,
|
"interpolationMode": 0,
|
||||||
"tangentWeightMode": 0,
|
"tangentWeightMode": 0,
|
||||||
"value": 1.1,
|
"value": 1.100000023841858,
|
||||||
"rightTangent": 0,
|
"rightTangent": 0,
|
||||||
"rightTangentWeight": 1,
|
"rightTangentWeight": 1,
|
||||||
"leftTangent": 0,
|
"leftTangent": 0,
|
||||||
@@ -187,8 +187,8 @@
|
|||||||
"__type__": "cc.RealCurve",
|
"__type__": "cc.RealCurve",
|
||||||
"_times": [
|
"_times": [
|
||||||
0,
|
0,
|
||||||
0.3333333333333333,
|
0.3333333432674408,
|
||||||
0.6666666666666666
|
0.6666666865348816
|
||||||
],
|
],
|
||||||
"_values": [
|
"_values": [
|
||||||
{
|
{
|
||||||
|
|||||||
1646
assets/resources/gui/element/prefab_talent_item.prefab
Normal file
1646
assets/resources/gui/element/prefab_talent_item.prefab
Normal file
File diff suppressed because it is too large
Load Diff
13
assets/resources/gui/element/prefab_talent_item.prefab.meta
Normal file
13
assets/resources/gui/element/prefab_talent_item.prefab.meta
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.1.50",
|
||||||
|
"importer": "prefab",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "a0cdb31c-0abb-4e12-9dfe-0bd9e8cd7272",
|
||||||
|
"files": [
|
||||||
|
".json"
|
||||||
|
],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {
|
||||||
|
"syncNodeName": "prefab_talent_item"
|
||||||
|
}
|
||||||
|
}
|
||||||
2212
assets/resources/gui/element/talents.prefab
Normal file
2212
assets/resources/gui/element/talents.prefab
Normal file
File diff suppressed because it is too large
Load Diff
13
assets/resources/gui/element/talents.prefab.meta
Normal file
13
assets/resources/gui/element/talents.prefab.meta
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.1.50",
|
||||||
|
"importer": "prefab",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "b0c70366-b71c-4ccd-b0fd-90af5149be5e",
|
||||||
|
"files": [
|
||||||
|
".json"
|
||||||
|
],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {
|
||||||
|
"syncNodeName": "talents"
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -19118,7 +19118,7 @@
|
|||||||
"__id__": 1109
|
"__id__": 1109
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"_active": false,
|
"_active": true,
|
||||||
"_components": [
|
"_components": [
|
||||||
{
|
{
|
||||||
"__id__": 1126
|
"__id__": 1126
|
||||||
|
|||||||
@@ -17,8 +17,11 @@ interface GameDate{
|
|||||||
fight_hero:number,
|
fight_hero:number,
|
||||||
collection?: {
|
collection?: {
|
||||||
talents: Record<number, number>,
|
talents: Record<number, number>,
|
||||||
skills: {uuid:0,count:0},
|
player_level: number,
|
||||||
friend:{uuid:0,count:0},
|
player_exp: number,
|
||||||
|
talent_points: number,
|
||||||
|
skills?: {uuid:0,count:0},
|
||||||
|
friend?: {uuid:0,count:0},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
interface CloudData {
|
interface CloudData {
|
||||||
@@ -126,6 +129,13 @@ export class SingletonModuleComp extends ecs.Comp {
|
|||||||
} as GameScoreStats,
|
} as GameScoreStats,
|
||||||
|
|
||||||
gold: 0, // 金币数据(MVVM绑定字段)
|
gold: 0, // 金币数据(MVVM绑定字段)
|
||||||
|
|
||||||
|
collection: {
|
||||||
|
talents: {}, // 存储各个天赋的等级: { talent_id: level }
|
||||||
|
player_level: 1, // 玩家等级
|
||||||
|
player_exp: 0, // 玩家当前经验
|
||||||
|
talent_points: 0, // 当前可用天赋点
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export enum UIID {
|
|||||||
Notity,
|
Notity,
|
||||||
Ranks,
|
Ranks,
|
||||||
Heros,
|
Heros,
|
||||||
|
Talents,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 打开界面方式的配置数据 */
|
/** 打开界面方式的配置数据 */
|
||||||
@@ -31,4 +32,5 @@ export var UIConfigData: { [key: number]: UIConfig } = {
|
|||||||
[UIID.Notity]: { layer: LayerType.UI, prefab: "gui/element/notity" },
|
[UIID.Notity]: { layer: LayerType.UI, prefab: "gui/element/notity" },
|
||||||
[UIID.Ranks]: { layer: LayerType.UI, prefab: "gui/element/ranks" },
|
[UIID.Ranks]: { layer: LayerType.UI, prefab: "gui/element/ranks" },
|
||||||
[UIID.Heros]: { layer: LayerType.UI, prefab: "gui/element/heros" },
|
[UIID.Heros]: { layer: LayerType.UI, prefab: "gui/element/heros" },
|
||||||
|
[UIID.Talents]: { layer: LayerType.UI, prefab: "gui/element/talents" },
|
||||||
}
|
}
|
||||||
180
assets/script/game/common/config/talent-system.md
Normal file
180
assets/script/game/common/config/talent-system.md
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
# 天赋系统设计 — Draftmaster Arena
|
||||||
|
|
||||||
|
*Created: 2026-04-26*
|
||||||
|
*Updated: 2026-04-26*
|
||||||
|
*Status: Draft*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
局外成长系统。通过每局获取的经验值提升玩家等级,获得天赋点数,用于升级天赋。升级即激活,无需单独激活步骤。看广告可重置所有天赋等级并退还天赋点。
|
||||||
|
|
||||||
|
**设计原则**:天赋提供小幅加成,不改变核心策略体验。高评分 = 更多经验 = 更快升级,但天赋不是胜利的决定性因素。
|
||||||
|
|
||||||
|
**成长闭环**:评分 → 经验 → 等级 → 天赋点 → 天赋升级 → 下一局更强 → 更高评分
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 经验与等级
|
||||||
|
|
||||||
|
### 经验获取
|
||||||
|
|
||||||
|
每局结束根据评分获得经验值:
|
||||||
|
|
||||||
|
| 评分区间 | 经验值 |
|
||||||
|
|---------|-------|
|
||||||
|
| 0 - 1,000 | 50 |
|
||||||
|
| 1,001 - 2,500 | 100 |
|
||||||
|
| 2,501 - 4,000 | 150 |
|
||||||
|
| 4,001 - 6,000 | 200 |
|
||||||
|
| 6,001+ | 300 |
|
||||||
|
|
||||||
|
### 升级经验
|
||||||
|
|
||||||
|
| 等级区间 | 每级所需经验 |
|
||||||
|
|---------|------------|
|
||||||
|
| 1-10级 | 100 |
|
||||||
|
| 11-20级 | 150 |
|
||||||
|
| 21-30级 | 200 |
|
||||||
|
|
||||||
|
**最高30级 = 30个天赋点**
|
||||||
|
|
||||||
|
### 升级速度估算
|
||||||
|
|
||||||
|
| 玩家水平 | 平均经验/局 | 升满30级约需 |
|
||||||
|
|---------|-----------|------------|
|
||||||
|
| 高手(6,001+) | 300 | ~20局 |
|
||||||
|
| 中等(2,501-4,000) | 150 | ~40局 |
|
||||||
|
| 新手(0-1,000) | 50 | ~120局 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 天赋列表
|
||||||
|
|
||||||
|
### 战斗属性类(全局加成)
|
||||||
|
|
||||||
|
| 天赋 | 每级效果 | 5级总效果 |
|
||||||
|
|------|---------|----------|
|
||||||
|
| **攻击强化** | 所有英雄 ATK +3% | +15% |
|
||||||
|
| **生命强化** | 所有英雄 HP +5% | +25% |
|
||||||
|
| **暴击强化** | 所有英雄暴击率 +2% | +10% |
|
||||||
|
| **风怒强化** | 所有英雄风怒率 +2% | +10% |
|
||||||
|
| **冰冻强化** | 所有英雄冰冻率 +2% | +10% |
|
||||||
|
| **穿刺强化** | 所有英雄穿刺 +0.2 | +1 |
|
||||||
|
| **护盾强化** | 所有护盾效果 +5% | +25% |
|
||||||
|
|
||||||
|
### 经济类(金币减免/补贴)
|
||||||
|
|
||||||
|
| 天赋 | 每级效果 | 5级总效果 |
|
||||||
|
|------|---------|----------|
|
||||||
|
| **采购优惠** | 购买英雄 -1金 | -5金(10→5) |
|
||||||
|
| **刷新优惠** | 刷新重抽 -0.5金 | -2.5金(3→0.5) |
|
||||||
|
| **出售补贴** | 出售英雄返还 +10%金币 | +50% |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 天赋升级费用
|
||||||
|
|
||||||
|
| 天赋等级 | 消耗天赋点 | 累计 |
|
||||||
|
|---------|-----------|------|
|
||||||
|
| 1级 | 1点 | 1 |
|
||||||
|
| 2级 | 1点 | 2 |
|
||||||
|
| 3级 | 2点 | 4 |
|
||||||
|
| 4级 | 2点 | 6 |
|
||||||
|
| 5级 | 3点 | 9 |
|
||||||
|
|
||||||
|
**一个天赋升满 = 9点**
|
||||||
|
|
||||||
|
30个天赋点的分配选择:
|
||||||
|
- 专精:升满3个天赋(27点)+ 3点分散
|
||||||
|
- 均衡:6-7个天赋各1-2级
|
||||||
|
- 经济:采购+刷新+出售全满(27点)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 核心规则
|
||||||
|
|
||||||
|
### 升级即激活
|
||||||
|
|
||||||
|
- 消耗天赋点升级天赋 → 立即生效
|
||||||
|
- 无需单独"激活"步骤
|
||||||
|
- 所有已升级的天赋在下一局同时生效
|
||||||
|
- 没有激活数量上限(天赋点本身就是限制)
|
||||||
|
|
||||||
|
### 重置(看广告)
|
||||||
|
|
||||||
|
- 观看广告 → **所有天赋等级归零**
|
||||||
|
- **退还全部天赋点**(30点内已消耗的)
|
||||||
|
- 玩家等级不变(经验永久累积)
|
||||||
|
- 重新自由分配天赋点
|
||||||
|
- 每次看广告重置1次
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 分配策略示例
|
||||||
|
|
||||||
|
**暴击流专精**(27点):
|
||||||
|
```
|
||||||
|
暴击强化 Lv5(9) + 攻击强化 Lv5(9) + 采购优惠 Lv5(9) = 27点
|
||||||
|
→ 全局暴击+10%, ATK+15%, 买卡-5金
|
||||||
|
```
|
||||||
|
|
||||||
|
**护盾流专精**(27点):
|
||||||
|
```
|
||||||
|
护盾强化 Lv5(9) + 生命强化 Lv5(9) + 冰冻强化 Lv5(9) = 27点
|
||||||
|
→ 护盾+25%, HP+25%, 冰冻+10%
|
||||||
|
```
|
||||||
|
|
||||||
|
**经济流**(27点):
|
||||||
|
```
|
||||||
|
采购优惠 Lv5(9) + 刷新优惠 Lv5(9) + 出售补贴 Lv5(9) = 27点
|
||||||
|
→ 买卡5金, 刷新0.5金, 出售+50%返还
|
||||||
|
```
|
||||||
|
|
||||||
|
**均衡新手**(26点):
|
||||||
|
```
|
||||||
|
攻击 Lv3(4) + 生命 Lv3(4) + 采购 Lv3(4) +
|
||||||
|
暴击 Lv2(2) + 护盾 Lv2(2) + 刷新 Lv2(2) +
|
||||||
|
风怒 Lv2(2) + 冰冻 Lv2(2) = 22点 + 4点备用
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 界面布局
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────┐
|
||||||
|
│ Lv.12 ████████░░ 150/200│
|
||||||
|
│ 天赋点: 4/30 │
|
||||||
|
├─────────────────────────┤
|
||||||
|
│ │
|
||||||
|
│ ⚔️ 攻击强化 Lv.3 ███░░ │
|
||||||
|
│ ATK +9% [+1点] │
|
||||||
|
│ │
|
||||||
|
│ ❤️ 生命强化 Lv.2 ██░░░ │
|
||||||
|
│ HP +10% [+2点] │
|
||||||
|
│ │
|
||||||
|
│ 🔥 暴击强化 Lv.1 █░░░░ │
|
||||||
|
│ 暴击 +2% [+1点] │
|
||||||
|
│ │
|
||||||
|
│ ⚡ 风怒强化 Lv.0 ░░░░░ │
|
||||||
|
│ 风怒 +0% [+1点] │
|
||||||
|
│ │
|
||||||
|
│ ❄️ 冰冻强化 Lv.0 ░░░░░ │
|
||||||
|
│ 冰冻 +0% [+1点] │
|
||||||
|
│ │
|
||||||
|
│ 🛡️ 护盾强化 Lv.0 ░░░░░ │
|
||||||
|
│ 🗡️ 穿刺强化 Lv.0 ░░░░░ │
|
||||||
|
│ 🛒 采购优惠 Lv.2 ██░░░ │
|
||||||
|
│ 🔄 刷新优惠 Lv.0 ░░░░░ │
|
||||||
|
│ 💰 出售补贴 Lv.0 ░░░░░ │
|
||||||
|
│ │
|
||||||
|
│ [🎬 看广告重置天赋] │
|
||||||
|
│ [← 返回] │
|
||||||
|
└─────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*与评分系统联动:评分 → 经验 → 等级 → 天赋点 → 天赋 → 下一局更强 → 更高评分 → 更多经验*
|
||||||
11
assets/script/game/common/config/talent-system.md.meta
Normal file
11
assets/script/game/common/config/talent-system.md.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.0.1",
|
||||||
|
"importer": "text",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "2ce819ee-ce1b-4e09-af8f-c5f0a296e96d",
|
||||||
|
"files": [
|
||||||
|
".json"
|
||||||
|
],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
301
assets/script/game/map/TalentsComp.ts
Normal file
301
assets/script/game/map/TalentsComp.ts
Normal file
@@ -0,0 +1,301 @@
|
|||||||
|
/**
|
||||||
|
* @file TalentsComp.ts
|
||||||
|
* @description 战斗结算弹窗组件(UI 视图层)
|
||||||
|
*
|
||||||
|
* 职责:
|
||||||
|
* 1. 在战斗结束时弹出,展示结算信息(得分、奖励)。
|
||||||
|
* 2. 根据传入参数判断是否可复活,切换"下一步"或"复活"按钮。
|
||||||
|
* 3. 计算单局总分并存储到 smc.vmdata.scores.score。
|
||||||
|
* 4. 提供"重新开始"和"退出"两个操作入口。
|
||||||
|
*
|
||||||
|
* 关键设计:
|
||||||
|
* - onAdded(args) 接收战斗结果参数(Talents / rewards / game_data / can_revive)。
|
||||||
|
* - calculateTotalScore() 根据 ScoreWeights 配置加权计算各项得分。
|
||||||
|
* - restart() 和 Talents_end() 通过分发 MissionEnd / MissionStart 事件驱动游戏状态切换。
|
||||||
|
*
|
||||||
|
* 依赖:
|
||||||
|
* - smc.vmdata.scores —— 全局战斗统计数据
|
||||||
|
* - ScoreWeights(ScoreSet)—— 得分权重配置
|
||||||
|
* - GameEvent.MissionEnd / MissionStart —— 游戏生命周期事件
|
||||||
|
*/
|
||||||
|
import { _decorator, Node, Label, Button, ProgressBar, instantiate, Prefab } 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 { mLogger } from "../common/Logger";
|
||||||
|
import { smc } from "../common/SingletonModuleComp";
|
||||||
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||||
|
|
||||||
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 天赋系统配置数据
|
||||||
|
*/
|
||||||
|
export const TalentConfig = {
|
||||||
|
// 升级所需经验配置
|
||||||
|
expRequirements: [
|
||||||
|
{ maxLevel: 10, expPerLevel: 100 },
|
||||||
|
{ maxLevel: 20, expPerLevel: 150 },
|
||||||
|
{ maxLevel: 30, expPerLevel: 200 }
|
||||||
|
],
|
||||||
|
// 天赋升级消耗点数
|
||||||
|
costPerLevel: [1, 1, 2, 2, 3], // 第1到第5级消耗
|
||||||
|
|
||||||
|
// 天赋列表
|
||||||
|
talents: [
|
||||||
|
{ id: 1, name: "攻击强化", desc: "所有英雄 ATK +3%", maxLevel: 5 },
|
||||||
|
{ id: 2, name: "生命强化", desc: "所有英雄 HP +5%", maxLevel: 5 },
|
||||||
|
{ id: 3, name: "暴击强化", desc: "所有英雄暴击率 +2%", maxLevel: 5 },
|
||||||
|
{ id: 4, name: "风怒强化", desc: "所有英雄风怒率 +2%", maxLevel: 5 },
|
||||||
|
{ id: 5, name: "冰冻强化", desc: "所有英雄冰冻率 +2%", maxLevel: 5 },
|
||||||
|
{ id: 6, name: "穿刺强化", desc: "所有英雄穿刺 +0.2", maxLevel: 5 },
|
||||||
|
{ id: 7, name: "护盾强化", desc: "所有护盾效果 +5%", maxLevel: 5 },
|
||||||
|
{ id: 8, name: "采购优惠", desc: "购买英雄 -1金", maxLevel: 5 },
|
||||||
|
{ id: 9, name: "刷新优惠", desc: "刷新重抽 -0.5金", maxLevel: 5 },
|
||||||
|
{ id: 10, name: "出售补贴", desc: "出售英雄返还 +10%金币", maxLevel: 5 }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TalentsComp —— 天赋系统界面组件
|
||||||
|
*
|
||||||
|
* 职责:
|
||||||
|
* 1. 展示玩家等级、当前经验、进度条、可用天赋点。
|
||||||
|
* 2. 展示天赋列表及每个天赋的当前等级。
|
||||||
|
* 3. 处理天赋升级点击事件,扣除天赋点并保存。
|
||||||
|
* 4. 处理重置天赋(看广告)功能。
|
||||||
|
*/
|
||||||
|
@ccclass('TalentsComp')
|
||||||
|
@ecs.register('Talents', false)
|
||||||
|
export class TalentsComp extends CCComp {
|
||||||
|
|
||||||
|
@property({ type: Node, tooltip: "标题节点" })
|
||||||
|
title_node: Node = null!;
|
||||||
|
|
||||||
|
@property({ type: Label, tooltip: "玩家等级文本,例如 'Lv.12'" })
|
||||||
|
lbl_level: Label = null!;
|
||||||
|
|
||||||
|
@property({ type: Label, tooltip: "经验文本,例如 '150/200'" })
|
||||||
|
lbl_exp: Label = null!;
|
||||||
|
|
||||||
|
@property({ type: ProgressBar, tooltip: "经验进度条" })
|
||||||
|
pb_exp: ProgressBar = null!;
|
||||||
|
|
||||||
|
@property({ type: Label, tooltip: "当前可用天赋点数文本,例如 '4/30'" })
|
||||||
|
lbl_points: Label = null!;
|
||||||
|
|
||||||
|
@property({ type: Node, tooltip: "天赋列表容器,用于动态添加天赋项" })
|
||||||
|
talents_content: Node = null!;
|
||||||
|
|
||||||
|
@property({ type: Prefab, tooltip: "天赋项预制体\n预制体结构要求:\n- 根节点\n - lbl_name (Label): 天赋名称\n - lbl_desc (Label): 天赋描述\n - lbl_level (Label): 当前等级\n - lbl_cost (Label): 升级消耗\n - btn_upgrade (Button): 升级按钮\n - pb_level (ProgressBar或一组节点): 等级进度展示(可选)" })
|
||||||
|
prefab_talent_item: Prefab = null!;
|
||||||
|
|
||||||
|
@property({ type: Button, tooltip: "看广告重置天赋按钮" })
|
||||||
|
btn_reset: Button = null!;
|
||||||
|
|
||||||
|
@property({ type: Button, tooltip: "返回按钮" })
|
||||||
|
btn_close: Button = null!;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** 调试日志开关 */
|
||||||
|
debugMode: boolean = false;
|
||||||
|
|
||||||
|
/** 最大玩家等级 */
|
||||||
|
private readonly MAX_PLAYER_LEVEL = 30;
|
||||||
|
|
||||||
|
protected onLoad(): void {
|
||||||
|
// 绑定按钮事件
|
||||||
|
if (this.btn_reset) {
|
||||||
|
this.btn_reset.node.on(Button.EventType.CLICK, this.onResetClicked, this);
|
||||||
|
}
|
||||||
|
if (this.btn_close) {
|
||||||
|
this.btn_close.node.on(Button.EventType.CLICK, this.onCloseClicked, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onAdded(args: any) {
|
||||||
|
this.refreshUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 刷新整体界面 */
|
||||||
|
private refreshUI() {
|
||||||
|
this.updatePlayerInfo();
|
||||||
|
this.updateTalentList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新玩家等级、经验、天赋点信息 */
|
||||||
|
private updatePlayerInfo() {
|
||||||
|
const collection = smc.vmdata.collection;
|
||||||
|
let level = collection.player_level || 1;
|
||||||
|
let exp = collection.player_exp || 0;
|
||||||
|
let points = collection.talent_points || 0;
|
||||||
|
|
||||||
|
// 限制最大等级
|
||||||
|
if (level > this.MAX_PLAYER_LEVEL) {
|
||||||
|
level = this.MAX_PLAYER_LEVEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.lbl_level) this.lbl_level.string = `Lv.${level}`;
|
||||||
|
if (this.lbl_points) this.lbl_points.string = `天赋点: ${points}/${this.MAX_PLAYER_LEVEL}`;
|
||||||
|
|
||||||
|
// 计算当前等级升级所需经验
|
||||||
|
let expRequired = this.getExpRequirement(level);
|
||||||
|
|
||||||
|
if (level >= this.MAX_PLAYER_LEVEL) {
|
||||||
|
if (this.lbl_exp) this.lbl_exp.string = "已满级";
|
||||||
|
if (this.pb_exp) this.pb_exp.progress = 1;
|
||||||
|
} else {
|
||||||
|
if (this.lbl_exp) this.lbl_exp.string = `${exp}/${expRequired}`;
|
||||||
|
if (this.pb_exp) this.pb_exp.progress = exp / expRequired;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取对应等级的升级所需经验 */
|
||||||
|
private getExpRequirement(level: number): number {
|
||||||
|
for (let config of TalentConfig.expRequirements) {
|
||||||
|
if (level <= config.maxLevel) {
|
||||||
|
return config.expPerLevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TalentConfig.expRequirements[TalentConfig.expRequirements.length - 1].expPerLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 动态生成或更新天赋列表 */
|
||||||
|
private updateTalentList() {
|
||||||
|
if (!this.talents_content || !this.prefab_talent_item) return;
|
||||||
|
|
||||||
|
const collection = smc.vmdata.collection;
|
||||||
|
if (!collection.talents) collection.talents = {};
|
||||||
|
|
||||||
|
// 如果内容为空,则实例化预制体
|
||||||
|
if (this.talents_content.children.length === 0) {
|
||||||
|
TalentConfig.talents.forEach(talentInfo => {
|
||||||
|
let itemNode = instantiate(this.prefab_talent_item);
|
||||||
|
this.talents_content.addChild(itemNode);
|
||||||
|
this.updateTalentItem(itemNode, talentInfo, collection.talents[talentInfo.id] || 0);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 否则直接更新现有节点
|
||||||
|
TalentConfig.talents.forEach((talentInfo, index) => {
|
||||||
|
let itemNode = this.talents_content.children[index];
|
||||||
|
if (itemNode) {
|
||||||
|
this.updateTalentItem(itemNode, talentInfo, collection.talents[talentInfo.id] || 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新单个天赋项的显示 */
|
||||||
|
private updateTalentItem(itemNode: Node, talentInfo: any, currentLevel: number) {
|
||||||
|
let lblName = itemNode.getChildByName("lbl_name")?.getComponent(Label);
|
||||||
|
let lblDesc = itemNode.getChildByName("lbl_desc")?.getComponent(Label);
|
||||||
|
let lblLevel = itemNode.getChildByName("lbl_level")?.getComponent(Label);
|
||||||
|
let lblCost = itemNode.getChildByName("lbl_cost")?.getComponent(Label);
|
||||||
|
let btnUpgradeNode = itemNode.getChildByName("btn_upgrade");
|
||||||
|
let btnUpgrade = btnUpgradeNode?.getComponent(Button);
|
||||||
|
|
||||||
|
if (lblName) lblName.string = talentInfo.name;
|
||||||
|
if (lblDesc) lblDesc.string = talentInfo.desc;
|
||||||
|
if (lblLevel) lblLevel.string = `Lv.${currentLevel}`;
|
||||||
|
|
||||||
|
let isMax = currentLevel >= talentInfo.maxLevel;
|
||||||
|
let cost = isMax ? 0 : TalentConfig.costPerLevel[currentLevel];
|
||||||
|
let points = smc.vmdata.collection.talent_points || 0;
|
||||||
|
|
||||||
|
if (lblCost) {
|
||||||
|
lblCost.string = isMax ? "已满级" : `消耗: ${cost}点`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (btnUpgrade) {
|
||||||
|
btnUpgrade.interactable = !isMax && points >= cost;
|
||||||
|
// 清除旧的监听,避免重复绑定
|
||||||
|
btnUpgradeNode?.off(Button.EventType.CLICK);
|
||||||
|
btnUpgradeNode?.on(Button.EventType.CLICK, () => {
|
||||||
|
this.onUpgradeClicked(talentInfo.id, currentLevel, cost);
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 点击升级按钮 */
|
||||||
|
private onUpgradeClicked(talentId: number, currentLevel: number, cost: number) {
|
||||||
|
const collection = smc.vmdata.collection;
|
||||||
|
let points = collection.talent_points || 0;
|
||||||
|
|
||||||
|
if (points >= cost && currentLevel < 5) {
|
||||||
|
// 扣除天赋点
|
||||||
|
collection.talent_points -= cost;
|
||||||
|
// 增加天赋等级
|
||||||
|
collection.talents[talentId] = currentLevel + 1;
|
||||||
|
|
||||||
|
// 同步到云端
|
||||||
|
smc.updateCloudData();
|
||||||
|
|
||||||
|
// 刷新界面
|
||||||
|
this.refreshUI();
|
||||||
|
|
||||||
|
oops.gui.toast("天赋升级成功");
|
||||||
|
} else {
|
||||||
|
oops.gui.toast("天赋点不足或已满级");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 点击重置按钮 */
|
||||||
|
private onResetClicked() {
|
||||||
|
// 看广告回调(预留)
|
||||||
|
this.watch_ad().then(success => {
|
||||||
|
if (success) {
|
||||||
|
const collection = smc.vmdata.collection;
|
||||||
|
// 计算已消耗的天赋点总和
|
||||||
|
let refundedPoints = 0;
|
||||||
|
for (let id in collection.talents) {
|
||||||
|
let level = collection.talents[id];
|
||||||
|
for (let i = 0; i < level; i++) {
|
||||||
|
refundedPoints += TalentConfig.costPerLevel[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置天赋等级并返还点数
|
||||||
|
collection.talents = {};
|
||||||
|
collection.talent_points += refundedPoints;
|
||||||
|
|
||||||
|
// 限制不超过最大点数(30)
|
||||||
|
if (collection.talent_points > this.MAX_PLAYER_LEVEL) {
|
||||||
|
collection.talent_points = this.MAX_PLAYER_LEVEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 同步到云端
|
||||||
|
smc.updateCloudData();
|
||||||
|
|
||||||
|
// 刷新界面
|
||||||
|
this.refreshUI();
|
||||||
|
oops.gui.toast("天赋已重置,点数已返还");
|
||||||
|
} else {
|
||||||
|
oops.gui.toast("广告观看失败,无法重置");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 模拟看广告回调,实际项目中需要替换为真实的广告SDK调用 */
|
||||||
|
private watch_ad(): Promise<boolean> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
// 模拟广告播放延迟
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve(true);
|
||||||
|
}, 500);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 点击返回按钮 */
|
||||||
|
private onCloseClicked() {
|
||||||
|
oops.gui.removeByNode(this.node); //
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onDestroy(): void {
|
||||||
|
mLogger.log(this.debugMode, 'TalentsComp', "释放界面");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ECS 组件移除时销毁节点 */
|
||||||
|
reset() {
|
||||||
|
this.node.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
1
assets/script/game/map/TalentsComp.ts.meta
Normal file
1
assets/script/game/map/TalentsComp.ts.meta
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"ver":"4.0.24","importer":"typescript","imported":true,"uuid":"52d81495-7526-43fe-91d8-3ba1d4c3fc89","files":[],"subMetas":{},"userData":{}}
|
||||||
Reference in New Issue
Block a user