2025-06-09 11:29:08 +08:00
|
|
|
using System;
|
2025-04-18 19:18:15 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using GameConfig.giftConfig;
|
|
|
|
using TEngine;
|
|
|
|
using UnityEngine;
|
2025-06-04 09:56:04 +08:00
|
|
|
using static UnityEngine.GraphicsBuffer;
|
2025-04-18 19:18:15 +08:00
|
|
|
|
|
|
|
namespace GameLogic
|
|
|
|
{
|
|
|
|
public class DataDanMuSceneManager : GameBase.Singleton<DataDanMuSceneManager>
|
|
|
|
{
|
|
|
|
public Dictionary<int, string> m_GiftIds = new Dictionary<int, string>();
|
|
|
|
|
|
|
|
public void OnInit()
|
|
|
|
{
|
|
|
|
RegisterEvent();
|
|
|
|
|
|
|
|
// 基于平台初始化该平台下的礼物Id
|
|
|
|
OnGiftConfigInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 初始化流程
|
|
|
|
private void OnGiftConfigInit()
|
|
|
|
{
|
|
|
|
if (EventConts.PlatformType == PlatformType.Dy || EventConts.PlatformType == PlatformType.None || EventConts.PlatformType == PlatformType.DyTest)
|
|
|
|
{
|
|
|
|
foreach (var item in ConfigSystem.Instance.Tables.TbGiftConfig.DataMap)
|
|
|
|
{
|
|
|
|
m_GiftIds.Add(item.Value.Id, item.Value.DyGiftId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log.Error("当前平台没有配置礼物表 : {0}", EventConts.PlatformType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RegisterEvent()
|
|
|
|
{
|
|
|
|
GameEvent.AddEventListener<ProtCustMessageData>(EventConts.MessageInfo, OnMessageInfo);
|
|
|
|
GameEvent.AddEventListener<ProtCustMessageData>(EventConts.GiftInfo, OnGiftInfo);
|
|
|
|
GameEvent.AddEventListener<ProtCustMessageData>(EventConts.LickInfo, OnLickInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RemoveEvent()
|
|
|
|
{
|
|
|
|
GameEvent.RemoveEventListener<ProtCustMessageData>(EventConts.MessageInfo, OnMessageInfo);
|
|
|
|
GameEvent.RemoveEventListener<ProtCustMessageData>(EventConts.GiftInfo, OnGiftInfo);
|
|
|
|
GameEvent.RemoveEventListener<ProtCustMessageData>(EventConts.LickInfo, OnLickInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 事件监听
|
|
|
|
|
|
|
|
private void OnMessageInfo(ProtCustMessageData protCustMessageData)
|
|
|
|
{
|
|
|
|
var data = DataGameSceneManager.Instance.GetUnitPlayerData(protCustMessageData.openId);
|
|
|
|
|
|
|
|
if (data == null)
|
|
|
|
{
|
2025-06-06 16:39:01 +08:00
|
|
|
if (protCustMessageData.content.Contains("加入"))
|
2025-06-04 09:56:04 +08:00
|
|
|
{
|
2025-06-09 11:29:08 +08:00
|
|
|
|
|
|
|
//var number = protCustMessageData.content.Where(c => char.IsDigit(c)).ToArray();
|
|
|
|
var number = protCustMessageData.content.Substring(2);
|
2025-06-04 09:56:04 +08:00
|
|
|
|
2025-06-11 18:18:24 +08:00
|
|
|
if (number.Length > 1)
|
2025-06-06 16:39:01 +08:00
|
|
|
{
|
|
|
|
// 检查是否输入姓氏
|
|
|
|
foreach (var surname in DataGameSceneManager.Instance.m_Strs)
|
2025-06-04 09:56:04 +08:00
|
|
|
{
|
2025-06-06 16:39:01 +08:00
|
|
|
if (protCustMessageData.content.Contains(surname))
|
2025-06-04 09:56:04 +08:00
|
|
|
{
|
2025-06-06 16:39:01 +08:00
|
|
|
int index = DataGameSceneManager.Instance.m_Strs.IndexOf(surname);
|
2025-06-10 20:18:32 +08:00
|
|
|
Log.Debug("玩家输入了姓氏: {0},索引: {1}", surname, index);
|
|
|
|
data = DataGameSceneManager.Instance.CreateUnitPlayerData(protCustMessageData, index + 1);
|
|
|
|
var actor = DataGameSceneManager.Instance.GetTeamActor((index + 1).ToString());
|
2025-06-06 16:39:01 +08:00
|
|
|
//actor.AddUnitPlayer(data);
|
|
|
|
actor.AddPlayer(data);
|
2025-06-04 09:56:04 +08:00
|
|
|
return;
|
|
|
|
}
|
2025-06-11 18:01:35 +08:00
|
|
|
else if (int.TryParse(number, out int index))
|
|
|
|
{
|
|
|
|
// 超过最大数
|
|
|
|
if (index > EventConts.MaxPlayerIds)
|
|
|
|
{
|
|
|
|
index = UnityEngine.Random.Range(2, EventConts.MaxPlayerIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var actor = DataGameSceneManager.Instance.GetTeamActor(index.ToString());
|
|
|
|
//actor.AddUnitPlayer(data);
|
|
|
|
data = DataGameSceneManager.Instance.CreateUnitPlayerData(protCustMessageData, index);
|
|
|
|
actor.AddPlayer(data);
|
2025-06-11 18:18:24 +08:00
|
|
|
return;
|
2025-06-11 18:01:35 +08:00
|
|
|
}
|
2025-06-04 09:56:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2025-06-09 11:29:08 +08:00
|
|
|
int targetId = UnityEngine.Random.Range(2, EventConts.MaxPlayerIds);
|
2025-06-06 16:39:01 +08:00
|
|
|
data = DataGameSceneManager.Instance.CreateUnitPlayerData(protCustMessageData, targetId - 1);
|
|
|
|
// 二次容错
|
|
|
|
if (data == null)
|
2025-06-04 09:56:04 +08:00
|
|
|
{
|
2025-06-06 16:39:01 +08:00
|
|
|
return;
|
2025-06-04 09:56:04 +08:00
|
|
|
}
|
|
|
|
|
2025-06-06 16:39:01 +08:00
|
|
|
var actor = DataGameSceneManager.Instance.GetTeamActor((targetId - 1).ToString());
|
|
|
|
actor.AddPlayer(data);
|
|
|
|
}
|
2025-06-04 09:56:04 +08:00
|
|
|
|
2025-06-06 16:39:01 +08:00
|
|
|
}
|
|
|
|
//else if (protCustMessageData.content.Contains("666"))
|
|
|
|
//{
|
|
|
|
// int targetId = Random.Range(1, EventConts.MaxPlayerIds);
|
|
|
|
// var actor = DataGameSceneManager.Instance.GetTeamActor((targetId - 1).ToString());
|
|
|
|
// if (actor == null)
|
|
|
|
// {
|
|
|
|
// Log.Error("没有获取到实体玩家,tid = {0}", targetId);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// //actor.AddUnitPlayer(data);
|
|
|
|
//}
|
2025-06-09 11:29:08 +08:00
|
|
|
else if (int.TryParse(protCustMessageData.content, out int index))
|
2025-06-06 16:39:01 +08:00
|
|
|
{
|
2025-06-09 11:29:08 +08:00
|
|
|
// 超过最大数
|
|
|
|
if (index > EventConts.MaxPlayerIds)
|
2025-06-06 16:39:01 +08:00
|
|
|
{
|
2025-06-09 11:29:08 +08:00
|
|
|
index = UnityEngine.Random.Range(2, EventConts.MaxPlayerIds);
|
2025-06-06 16:39:01 +08:00
|
|
|
}
|
2025-06-04 09:56:04 +08:00
|
|
|
|
2025-06-06 16:39:01 +08:00
|
|
|
|
2025-06-09 11:29:08 +08:00
|
|
|
var actor = DataGameSceneManager.Instance.GetTeamActor(index.ToString());
|
|
|
|
//actor.AddUnitPlayer(data);
|
|
|
|
data = DataGameSceneManager.Instance.CreateUnitPlayerData(protCustMessageData, index);
|
|
|
|
actor.AddPlayer(data);
|
|
|
|
return;
|
2025-06-04 09:56:04 +08:00
|
|
|
}
|
2025-04-18 19:18:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnGiftInfo(ProtCustMessageData protCustMessageData)
|
|
|
|
{
|
|
|
|
var data = DataGameSceneManager.Instance.GetUnitPlayerData(protCustMessageData.openId);
|
|
|
|
|
|
|
|
if (data == null)
|
|
|
|
{
|
2025-05-09 14:19:01 +08:00
|
|
|
|
2025-06-09 11:29:08 +08:00
|
|
|
int targetId = UnityEngine.Random.Range(2, EventConts.MaxPlayerIds);
|
2025-05-09 14:19:01 +08:00
|
|
|
|
|
|
|
data = DataGameSceneManager.Instance.CreateUnitPlayerData(protCustMessageData, targetId - 1);
|
2025-04-18 19:18:15 +08:00
|
|
|
// 二次容错
|
|
|
|
if (data == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-04-25 14:37:15 +08:00
|
|
|
var actor = DataGameSceneManager.Instance.GetTeamActor((targetId - 1).ToString());
|
|
|
|
if (actor == null)
|
|
|
|
{
|
|
|
|
Log.Error("没有获取到实体玩家,tid = {0}", targetId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
actor.AddPlayer(data);
|
2025-04-18 19:18:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var item in m_GiftIds)
|
|
|
|
{
|
|
|
|
// 对应的礼物效果
|
|
|
|
if (item.Value == protCustMessageData.content)
|
|
|
|
{
|
|
|
|
GiftConfig giftConfig = ConfigSystem.Instance.Tables.TbGiftConfig.Get(item.Key);
|
|
|
|
if (giftConfig == null)
|
|
|
|
{
|
|
|
|
Log.Error("礼物配置表Id异常 {0}", item.Key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-05-26 23:11:35 +08:00
|
|
|
Log.Debug("送礼:" + data.teamId);
|
2025-04-18 19:18:15 +08:00
|
|
|
|
|
|
|
//优化写法
|
|
|
|
DataGameSceneManager.Instance.OnGiftFunc(giftConfig, int.Parse(protCustMessageData.Count), data);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnLickInfo(ProtCustMessageData protCustMessageData)
|
|
|
|
{
|
|
|
|
var data = DataGameSceneManager.Instance.GetUnitPlayerData(protCustMessageData.openId);
|
|
|
|
|
|
|
|
if (data == null)
|
|
|
|
{
|
2025-05-28 14:42:47 +08:00
|
|
|
Log.Error("玩家 {0} 没有加入过阵营,无法点赞", protCustMessageData.openId);
|
2025-04-18 19:18:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2025-05-27 21:05:50 +08:00
|
|
|
// 增加点赞数量
|
|
|
|
data.m_LikeCount += int.Parse(protCustMessageData.Count);
|
|
|
|
|
|
|
|
var actor = DataGameSceneManager.Instance.GetTeamActor(data.teamId);
|
|
|
|
|
|
|
|
if (actor != null)
|
|
|
|
{
|
|
|
|
GiftConfig giftConfig = ConfigSystem.Instance.Tables.TbGiftConfig.Get(1);
|
|
|
|
if (giftConfig == null)
|
|
|
|
{
|
|
|
|
Log.Error("礼物配置表Id异常 {0}", 1);
|
|
|
|
return;
|
|
|
|
}
|
2025-06-04 03:43:13 +08:00
|
|
|
//Log.Debug("点赞:" + data.teamId);
|
2025-05-27 21:05:50 +08:00
|
|
|
DataGameSceneManager.Instance.OnGiftFunc(giftConfig, int.Parse(protCustMessageData.Count), data);
|
2025-06-03 22:32:01 +08:00
|
|
|
|
2025-06-04 06:20:22 +08:00
|
|
|
GameEvent.Send(EventConts.UIDianZan, data.protCustMessageData.nickName);
|
|
|
|
|
2025-06-04 03:43:13 +08:00
|
|
|
if (DataGameSceneManager.Instance.isLiShiShiJian)
|
2025-06-03 22:32:01 +08:00
|
|
|
{
|
2025-06-04 03:43:13 +08:00
|
|
|
DataGameSceneManager.Instance.m_LiShiShiJianLikeCount += int.Parse(protCustMessageData.Count);
|
|
|
|
|
2025-06-03 22:32:01 +08:00
|
|
|
bool isAdd = true;
|
|
|
|
// 检查列表是否存在该玩家
|
|
|
|
foreach (var item in DataGameSceneManager.Instance.sjDatas)
|
|
|
|
{
|
|
|
|
if (item.openId == data.protCustMessageData.openId)
|
|
|
|
{
|
|
|
|
isAdd = false;
|
|
|
|
|
|
|
|
item.count += int.Parse(protCustMessageData.Count);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAdd)
|
|
|
|
{
|
2025-06-04 03:43:13 +08:00
|
|
|
// 给玩家增加贡献
|
|
|
|
data.m_GongXian++;
|
|
|
|
|
2025-06-03 22:32:01 +08:00
|
|
|
SjData sjData = new SjData() { };
|
|
|
|
sjData.openId = data.protCustMessageData.openId;
|
|
|
|
sjData.name = data.protCustMessageData.nickName;
|
|
|
|
sjData.count = int.Parse(protCustMessageData.Count);
|
|
|
|
DataGameSceneManager.Instance.sjDatas.Add(sjData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-05-27 21:05:50 +08:00
|
|
|
}
|
2025-04-18 19:18:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
public void OnDestroy()
|
|
|
|
{
|
|
|
|
RemoveEvent();
|
|
|
|
m_GiftIds.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|