This commit is contained in:
2026-07-19 17:39:31 +08:00
parent fc3bc322a5
commit baf1620a35
3 changed files with 109 additions and 45 deletions
@@ -83,6 +83,7 @@
using Assets.MyGame.Scripts.Net;
using Assets.MyGame.Scripts.Net.API;
using Assets.MyGame.Scripts.Net.API.UserData_SubClass;
using Assets.MyGame.Scripts.Net.APIResponses.Enum;
using Assets.MyGame.Scripts.Net.WebResponses;
using DG.Tweening;
@@ -151,6 +152,10 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
public float currBingFengTime = 0f;
private Dictionary<Component, float> _frozenAnimSpeeds = new Dictionary<Component, float>();
// ⭐ 暴走/冰封本地数量:因为暂无扣减 API,激活时本地 -1,避免被 OnUserDataChanged 覆盖回服务端旧值
private int _localBaoZouCount = -1; // -1 表示尚未初始化
private int _localBingFengCount = -1;
[Header("Skillleft")]
public Button btn_GuaGuaKa;
public TextMeshProUGUI tmp_GGKCount;
@@ -295,8 +300,6 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
var user = GameManager.Instance.user;
var props = user?.props;
int ggkCount = 0;
int baoZouCount = 0;
int bingFengCount = 0;
if (props != null)
{
@@ -304,19 +307,14 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
{
if (p.number == "40005" && p.count > 0)
ggkCount = p.count;
else if (p.number == "40006" && p.count > 0)
baoZouCount = p.count;
else if (p.number == "40007" && p.count > 0)
bingFengCount = p.count;
}
}
if (tmp_GGKCount != null)
tmp_GGKCount.text = ggkCount.ToString();
if (tmp_BaoZouCount != null)
tmp_BaoZouCount.text = baoZouCount.ToString();
if (tmp_BingFengCount != null)
tmp_BingFengCount.text = bingFengCount.ToString();
// 同步刷新暴走/冰封本地计数(仅首次或服务端数据变化时同步)
RefreshSkillPropsCount(props);
// 同步更新游戏内金币显示(刮刮卡领奖、邮件领取等都会触发)
if (currSitData != null && user?.assets != null)
@@ -326,6 +324,42 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
currSitData.tMP_GoldNum.text = user.assets.gold.ToString();
}
}
/// <summary>
/// 刷新暴走/冰封道具数量显示
/// 策略:本地计数未初始化(_localXxxCount == -1)时从服务端 props 读取;
/// 之后由激活扣减本地维护,避免 OnUserDataChanged 把本地扣减值覆盖回服务端旧值
/// </summary>
private void RefreshSkillPropsCount(List<BaseProductCount> props)
{
int serverBaoZou = 0;
int serverBingFeng = 0;
if (props != null)
{
foreach (var p in props)
{
if (p.number == "40006" && p.count > 0) serverBaoZou = p.count;
else if (p.number == "40007" && p.count > 0) serverBingFeng = p.count;
}
}
// 首次初始化,或服务端数量比本地少(说明服务端已扣减,比如其他端使用)→ 以服务端为准
if (_localBaoZouCount < 0 || serverBaoZou < _localBaoZouCount)
_localBaoZouCount = serverBaoZou;
if (_localBingFengCount < 0 || serverBingFeng < _localBingFengCount)
_localBingFengCount = serverBingFeng;
UpdateSkillPropsUI();
}
/// <summary>仅更新 UI 文本</summary>
private void UpdateSkillPropsUI()
{
if (tmp_BaoZouCount != null)
tmp_BaoZouCount.text = Mathf.Max(0, _localBaoZouCount).ToString();
if (tmp_BingFengCount != null)
tmp_BingFengCount.text = Mathf.Max(0, _localBingFengCount).ToString();
}
protected override void OnHide()
{
base.OnHide();
@@ -339,6 +373,9 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
// 清除场景加载标记,下次进入可重新加载
Assets.MyGame.Scripts.Net.WebSocketReponseList.ClearLoadedGameScene(sceneName);
WebSocketManager.Instance.Close(SocketType.game);
// ⭐ 重置本地道具计数,下次进入房间重新从服务端读取
_localBaoZouCount = -1;
_localBingFengCount = -1;
}
#endregion
@@ -504,7 +541,16 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
// UI 开关只是触发,但最终状态以 currGameType 为准
CreateFishManager.Instance.currGameType.isFrenzy = on;
SetFrenzy(on);
if (on) currFrenzyTime = frenzyDuration;
if (on)
{
currFrenzyTime = frenzyDuration;
// ⭐ 激活时本地扣减一张(暂无扣减 API,仅 UI 显示)
if (_localBaoZouCount > 0)
{
_localBaoZouCount--;
UpdateSkillPropsUI();
}
}
});
toggle_SkillAuto.onValueChanged.AddListener(on =>
{
@@ -520,6 +566,12 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
{
// 开始冰冻
currBingFengTime = bingFengDuration;
// ⭐ 激活时本地扣减一张(暂无扣减 API,仅 UI 显示)
if (_localBingFengCount > 0)
{
_localBingFengCount--;
UpdateSkillPropsUI();
}
if (bingFengEffect != null)
{
if (_bingFengInstance == null)