备份CatanBuilding瘦身独立工程
This commit is contained in:
62
Assets/Scripts/UI/PartnerFishBowl/EventPartnerBot.cs
Normal file
62
Assets/Scripts/UI/PartnerFishBowl/EventPartnerBot.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
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<Tables>().TbRobot;
|
||||
private static readonly IUserService UserService = GContext.container.Resolve<IUserService>();
|
||||
// private static readonly ICustomServerMgr ServerMgr = GContext.container.Resolve<ICustomServerMgr>();
|
||||
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 void AddBot(ScrollViewItemInfo botInfo, int slotId)
|
||||
{
|
||||
if (!botInfo.PlayfabId.EndsWith(RobotIdentifier))
|
||||
{
|
||||
Debug.Log($"<color=#c191ff>[EventPartner]{botInfo.PlayfabId} is not a robot.</color>");
|
||||
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 ;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user