Files
ft/Client/Assets/Scripts/EventPartnerGather/EventPartnerGatherBot.cs
2026-06-29 21:18:33 +08:00

96 lines
3.1 KiB
C#

using System;
using cfg;
using asap.core;
using UnityEngine;
using System.Globalization;
using System.Linq;
using game;
using GameCore;
using Random = UnityEngine.Random;
using ScrollViewItemInfo = EventPartnerScrollViewItem.ScrollViewItemInfo;
namespace EventPartnerGather
{
public class BotResult
{
public int slotId;
public string playfabId;
public int grade;
public DateTime wakeStartTime;
public int wakingSeconds;
}
public class EventPartnerGatherBot
{
public const char RobotIdentifier = 'R';
private static readonly TbRobot RobotTable = GContext.container.Resolve<Tables>().TbRobot;
private static readonly IUserService UserService = GContext.container.Resolve<IUserService>();
private static readonly Tables Tables = GContext.container.Resolve<Tables>();
public static string Idx2Id(int idx)
{
return idx.ToString("X5") + RobotIdentifier;
}
public static int Id2Idx(string id)
{
return int.Parse(id.Trim(RobotIdentifier), NumberStyles.HexNumber);
}
public static void GetBotDisplayInfo(string id, out string avatar, out string displayName)
{
int idx = Id2Idx(id);
var res = RobotTable.DataMap.TryGetValue(idx, out var r);
if (!res)
{
avatar = "";
displayName = UserService.GetDefaultName(id);
return;
}
avatar = r.Avatar;
displayName = LocalizationMgr.GetText(r.Name_l10n_key);
}
public static BotResult AddBot(ScrollViewItemInfo botInfo, int slotId)
{
if (!botInfo.PlayfabId.EndsWith(RobotIdentifier))
{
LogWarning($"AddBotSkipped reason=NotRobot partnerId={botInfo.PlayfabId}");
return null;
}
int grade = FtUtils.GetRandomIdxFromWeightList(Tables.TbEventPartnerRobot.DataList.Select(r => r.Weight));
var wakeStartTime = ZZTimeHelper.UtcNow();
int wakingSeconds = Random.Range(Tables.TbEventPartnerConfig.RobotDailyActiveTimeWindow[0], Tables.TbEventPartnerConfig.RobotDailyActiveTimeWindow[1]);
return new BotResult
{
slotId = slotId,
playfabId = botInfo.PlayfabId,
grade = grade,
wakeStartTime = wakeStartTime,
wakingSeconds = wakingSeconds,
};
// EventPartnerAct.Ctx.Data.Components[slotId].SetComponent(botInfo);
// EventPartnerAct.Ctx.Data.Components[slotId].BotWakeTime = wakeStartTime;
// EventPartnerAct.Ctx.Data.Components[slotId].BotWakingSeconds = wakingSeconds;
// EventPartnerAct.Ctx.Data.Components[slotId].BotGrade = grade;
// return;
}
private static void LogWarning(string message)
{
Debug.LogWarning($"<color=yellow>EventPartnerGatherBot -> {message}</color>");
}
}
}