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;
|
|
|
|
|
|
|
|
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-05-09 14:19:01 +08:00
|
|
|
//data = DataGameSceneManager.Instance.CreateUnitPlayerData(protCustMessageData);
|
|
|
|
//// 二次容错
|
|
|
|
//if (data == null)
|
|
|
|
//{
|
|
|
|
// return;
|
|
|
|
//}
|
2025-04-18 19:18:15 +08:00
|
|
|
}
|
|
|
|
|
2025-04-24 17:34:34 +08:00
|
|
|
// if (EventConts.gameStateType == GameStateType.团队赛)
|
|
|
|
// {
|
|
|
|
// // 没有加入过阵营
|
|
|
|
// if (data.teamId == "-1")
|
|
|
|
// {
|
|
|
|
// // 指令集操作
|
|
|
|
// if (protCustMessageData.content.Contains("加入"))
|
|
|
|
// {
|
|
|
|
// var number = protCustMessageData.content.Where(c => char.IsDigit(c)).ToArray();
|
|
|
|
|
|
|
|
// if (number.Length == 0)
|
|
|
|
// {
|
|
|
|
// // 检查是否输入姓氏
|
|
|
|
// foreach (var surname in DataGameSceneManager.Instance.m_Strs)
|
|
|
|
// {
|
|
|
|
// if (protCustMessageData.content.Contains(surname))
|
|
|
|
// {
|
|
|
|
// int index = DataGameSceneManager.Instance.m_Strs.IndexOf(surname);
|
|
|
|
// var actor = DataGameSceneManager.Instance.GetTeamActor(index.ToString());
|
|
|
|
// actor.AddUnitPlayer(data);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
|
|
|
|
// int targetId = int.Parse(new string(number));
|
|
|
|
// // 超过最大数
|
|
|
|
// if (targetId > EventConts.MaxPlayerIds)
|
|
|
|
// {
|
|
|
|
// targetId = Random.Range(targetId, EventConts.MaxPlayerIds);
|
|
|
|
// }
|
|
|
|
// var actor = DataGameSceneManager.Instance.GetTeamActor((targetId - 1).ToString());
|
|
|
|
// actor.AddUnitPlayer(data);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
// 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);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
|
|
|
|
// // 直接数字
|
|
|
|
// var number = protCustMessageData.content.Where(c => char.IsDigit(c)).ToArray();
|
|
|
|
|
|
|
|
// if (number.Length == 0)
|
|
|
|
// {
|
|
|
|
// Log.Error("No digits found in content: {0}", protCustMessageData.content);
|
|
|
|
// return; // or handle the error as needed
|
|
|
|
// }
|
|
|
|
// int targetId = -1;
|
|
|
|
|
|
|
|
// if (int.TryParse(new string(number), out targetId))
|
|
|
|
// {
|
|
|
|
// // 超过最大数
|
|
|
|
// if (targetId > EventConts.MaxPlayerIds)
|
|
|
|
// {
|
|
|
|
// targetId = Random.Range(targetId, EventConts.MaxPlayerIds);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// var actor = DataGameSceneManager.Instance.GetTeamActor((targetId - 1).ToString());
|
|
|
|
// actor.AddUnitPlayer(data);
|
|
|
|
|
|
|
|
// Log.Info("玩家 {0} , 进攻 {1}", data.protCustMessageData.nickName, targetId);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// // 加入过阵营
|
|
|
|
// var actor = DataGameSceneManager.Instance.GetTeamActor(data.teamId);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// else if (EventConts.gameStateType == GameStateType.个人赛)
|
|
|
|
// {
|
|
|
|
// var actor = DataGameSceneManager.Instance.GetTeamActor(data.teamId);
|
|
|
|
// if (actor == null)
|
|
|
|
// {
|
|
|
|
// actor = DataGameSceneManager.Instance.CraeteTeamActor(data);
|
|
|
|
// actor.AddUnitPlayer(data);
|
|
|
|
// }
|
|
|
|
// }
|
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
|
|
|
|
|
|
|
int targetId = Random.Range(1, EventConts.MaxPlayerIds);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
|
|
|
//data = DataGameSceneManager.Instance.CreateUnitPlayerData(protCustMessageData);
|
|
|
|
//// 二次容错
|
|
|
|
//if (data == null)
|
|
|
|
//{
|
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
|
|
|
|
//// 随机落座
|
|
|
|
//if (EventConts.gameStateType == GameStateType.团队赛)
|
|
|
|
//{
|
|
|
|
// int targetId = Random.Range(1, EventConts.MaxPlayerIds);
|
|
|
|
// Actor actor1 = DataGameSceneManager.Instance.GetTeamActor((targetId - 1).ToString());
|
|
|
|
// if (actor1 == null)
|
|
|
|
// {
|
|
|
|
// Log.Error("没有获取到实体玩家,tid = {0}", targetId);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// actor1.AddUnitPlayer(data);
|
|
|
|
//}
|
|
|
|
//else if (EventConts.gameStateType == GameStateType.个人赛)
|
|
|
|
//{
|
|
|
|
// var actor2 = DataGameSceneManager.Instance.GetTeamActor(data.teamId);
|
|
|
|
// if (actor2 == null)
|
|
|
|
// {
|
|
|
|
// actor2 = DataGameSceneManager.Instance.CraeteTeamActor(data);
|
|
|
|
// actor2.AddUnitPlayer(data);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2025-04-24 17:34:34 +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;
|
|
|
|
// }
|
|
|
|
// Log.Debug("点赞:" + data.teamId);
|
|
|
|
// DataGameSceneManager.Instance.OnGiftFunc(giftConfig, int.Parse(protCustMessageData.Count), data);
|
|
|
|
|
|
|
|
// var a = GameModule.Resource.LoadAsset<GameObject>("Actor_Item");
|
|
|
|
// var go = GameObject.Instantiate(a, null);
|
|
|
|
// go.gameObject.SetActive(false);
|
|
|
|
// go.GetComponent<ActorItem>().OnInit(data.protCustMessageData.imgURL, actor);
|
|
|
|
// }
|
2025-04-18 19:18:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
public void OnDestroy()
|
|
|
|
{
|
|
|
|
RemoveEvent();
|
|
|
|
m_GiftIds.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|