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; public class EventPartnerBot { public const char RobotIdentifier = 'R'; private static readonly TbRobot RobotTable = GContext.container.Resolve().TbRobot; private static readonly IUserService UserService = GContext.container.Resolve(); // private static readonly ICustomServerMgr ServerMgr = GContext.container.Resolve(); private static readonly Tables Tables = GContext.container.Resolve(); 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 void AddBot(ScrollViewItemInfo botInfo, int slotId) { if (!botInfo.PlayfabId.EndsWith(RobotIdentifier)) { Debug.Log($"[EventPartner]{botInfo.PlayfabId} is not a robot."); return; } int grade = FtMathUtils.GetRandomIdxFromWeightList(Tables.TbEventPartnerRobot.DataList.Select(r => r.Weight)); var wakeStartTime = ZZTimeHelper.UtcNow(); int wakingSeconds = Random.Range(Tables.TbEventPartnerConfig.RobotDailyActiveTimeWindow[0], Tables.TbEventPartnerConfig.RobotDailyActiveTimeWindow[1]); 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 ; } }