using asap.core; using cfg; using UnityEngine; using System.Linq; using System.Collections.Generic; using GameCore; using System; using ScrollViewItemInfo = EventPartnerScrollViewItem.ScrollViewItemInfo; using EScrollViewType = EventPartnerScrollViewItem.EScrollViewType; using game; using EventPartner; public class EventPartnerStatueTableContext : ITableContext { public int EventId { get; set; } public int RedirectId, CycleId; private Tables _tables = GContext.container.Resolve(); private EventPartnerStatueMain _tbMain; private TbEventPartnerStatueSpinPoints _tbSpinPoints; private TbEventPartnerStatueCombine _tbCombination; private TbEventPartnerStatueDice _tbDice; private TbEventPartnerConfig _tbConfig; private PlayerItemData _playerItemData = GContext.container.Resolve(); private FriendService _friendService = GContext.container.Resolve(); private const string DiceTypeMore = "More"; private const string DiceTypeFree = "Free"; public int ActiveFriendCountThreshold => _tables.TbEventPartnerConfig.FriendRecommendParam1[0]; public int RecommendCount => _tables.TbEventPartnerConfig.FriendRecommendParam2[_friendService.FriendList.Count < ActiveFriendCountThreshold ? 0 : 1]; public int RecommendTriggerCount => _tables.TbEventPartnerConfig.RobotRecommendTriggerCount; public float RobotRecommendRatio => _tables.TbEventPartnerConfig.RobotRecommendCount; public EventPartnerStatueTableContext(int eventId) { EventId = eventId; var tbEvent = _tables.TbFishingEvent[eventId]; CycleId = tbEvent.RedirectID; var tbCycle = _tables.TbFishingEventCycleItem[CycleId]; RedirectId = tbCycle.RedirectID; _tbMain = _tables.TbEventPartnerStatueMain[CycleId]; _tbSpinPoints = _tables.TbEventPartnerStatueSpinPoints; _tbCombination = _tables.TbEventPartnerStatueCombine; _tbDice = _tables.TbEventPartnerStatueDice; _tbConfig = _tables.TbEventPartnerConfig; } public int GetInitGift() { return _tables.TbFishingEventCycleItem.GetOrDefault(CycleId)?.WelcomeGift ?? 0; } public int GetTicketId() { return _tables.TbFishingEventCycleItem.GetOrDefault(CycleId)?.ItemId ?? 0; } #if UNITY_EDITOR public void InitTest() { bool res; EventId = 114514; RedirectId = 41001; CycleId = 41001; _tbSpinPoints = _tables.TbEventPartnerStatueSpinPoints; _tbCombination = _tables.TbEventPartnerStatueCombine; _tbDice = _tables.TbEventPartnerStatueDice; _tbConfig = _tables.TbEventPartnerConfig; res = _tables.TbEventPartnerStatueMain.DataMap.TryGetValue(CycleId, out _tbMain); if (!res) { Debug.LogError($"CycleId {CycleId} not found in EventPartnerStatueMain."); return; } } #endif public (int point, (int c1, int c2, int c3)) GenerateSpinResult() { var spinList = _tbMain.PointList.Select(x => _tbSpinPoints[x]).ToList(); var spin = FtUtils.PickRandomItemWithWeight(spinList, x => spinList[x].Weight); var arc = GContext.container.Resolve(); arc.EventTrackingSystem.RollPointType = spin.PointID; var point = spin.Point; var displayId = spin.Display[UnityEngine.Random.Range(0, spin.Display.Count)]; var combination = _tbCombination[displayId].SpinResult; return (point, (combination[0], combination[1], combination[2])); } public (float percentage, int durationInSeconds) GetBonusBuffData() { var buffDice = _tbMain.DiceList.Select(id => _tbDice[id]).FirstOrDefault(dice => dice.Type == DiceTypeMore); if (buffDice == null) return (0, 0); var param = buffDice.SpinPointParam as MoreSpinPoint; return (param.BonusPercent, param.BonusDuration); } public (int c1, int c2, int c3) GetMoreDisplayCombination() { var buffDice = _tbMain.DiceList.Select(id => _tbDice[id]).FirstOrDefault(dice => dice.Type == DiceTypeMore); if (buffDice == null) return (-1, -1, -1); return (buffDice.Face, buffDice.Face, buffDice.Face); } public (int c1, int c2, int c3) GetFreeDisplayCombination() { var buffDice = _tbMain.DiceList.Select(id => _tbDice[id]).FirstOrDefault(dice => dice.Type == DiceTypeFree); if (buffDice == null) return (-1, -1, -1); return (buffDice.Face, buffDice.Face, buffDice.Face); } public int GetMaxPartnerCount() { return _tbConfig.InvitationCount[2]; } public List GetScoreStageList() { return _tbMain.StagePoint; } public int GetMaxScore() { return GetScoreStageList().Last(); } public int GetStageFromTotalScore(int score) { var scoreStageList = GetScoreStageList(); if (score >= scoreStageList.Last()) return scoreStageList.Count; // return _tbMain.StagePoint.FindIndex(x => x >= score) + 1; return _tbMain.StagePoint.FindIndex(x => x > score); } public float GetPercentageWithinStage(int score) { var scoreStageList = GetScoreStageList(); if (score <= 0) return 0; if (score >= scoreStageList.Last()) return 1; var stage = GetStageFromTotalScore(score); if (stage == 0) return (float)score / scoreStageList[0]; return (float)(score - scoreStageList[stage - 1]) / (scoreStageList[stage] - scoreStageList[stage - 1]); } public float GetPercentage(int score) { return (float)score / GetMaxScore(); } public ItemData GetNextRewardFromScore(int score) { var arc = GContext.container.Resolve(); var stage = GetStageFromTotalScore(score); var scoreStageList = GetScoreStageList(); var stageRewardList = _tbMain.StageReward; if (scoreStageList.Count != stageRewardList.Count) { Debug.LogError($"[EventPartner]StageRewardList count {stageRewardList.Count} != StagePointList count {scoreStageList.Count}"); return null; } var dropId = stage >= scoreStageList.Count ? stageRewardList.Last() : stageRewardList[stage]; return _playerItemData.GetItemDataByDropIdAndTypeLureInflation(arc.Model.LureInflationRate, dropId)[0]; } public int GetRewardDropIdFromStage(int stage) { stage = Mathf.Clamp(stage, 0, GetScoreStageList().Count); if (stage == 0) return -1; return _tbMain.StageReward[stage - 1]; } public (DateTime StartTime, DateTime EndTime) GetEventTimeLimit() { try { return FtUtils.GetEventTimeLimit(EventId); } catch (Exception e) { Debug.LogError($"[EventPartner]GetEventTimeLimit error: {e}"); return (DateTime.MinValue, DateTime.MinValue); } } public List GetFinalRewardList() { var arc = GContext.container.Resolve(); return _playerItemData.GetItemDataByDropIdAndTypeLureInflation(arc.Model.LureInflationRate, _tbMain.Reward); } public int GetFinalRewardDropId() { return _tbMain.Reward; } public HashSet GetBotRecommendList(int count, HashSet partnerIdSet) { var botTable = GContext.container.Resolve().TbRobot; var recommendList = new HashSet(); while (recommendList.Count < count) { var randomBot = botTable.DataList[UnityEngine.Random.Range(0, botTable.DataList.Count)]; if (partnerIdSet.Contains(EventPartner.RobotDataManager.Idx2Id(randomBot.ID))) continue; recommendList.Add(new ScrollViewItemInfo { Type = EScrollViewType.Recommendation, AvatarUrl = randomBot.Avatar, DisplayName = randomBot.Name, PlayfabId = EventPartner.RobotDataManager.Idx2Id(randomBot.ID), Level = UnityEngine.Random.Range(60, 120), }); // Debug.Log($"Robot: No.{randomBot.ID} {randomBot.Name}"); } return recommendList; } public HashSet GetBotRecommendIdList(int count) { var botTable = GContext.container.Resolve().TbRobot; var arc = GContext.container.Resolve(); var recommendList = new HashSet(); var partnerIdSet = arc.Model.PartnerIdSet; while (recommendList.Count < count) { var randomBot = botTable.DataList[UnityEngine.Random.Range(0, botTable.DataList.Count)]; if (partnerIdSet.Contains(EventPartner.RobotDataManager.Idx2Id(randomBot.ID))) continue; var botFakeHexId = EventPartner.RobotDataManager.Idx2Id(randomBot.ID); recommendList.Add(botFakeHexId); arc.PlayerInfoPool.Add(new PlayerInfo { PlayFabId = botFakeHexId, AvatarUrl = randomBot.Avatar, DisplayName = randomBot.Name, Level = UnityEngine.Random.Range(60, 120), }); // Debug.Log($"Robot: No.{randomBot.ID} {randomBot.Name}"); } return recommendList; } public PlayerInfo GetBotInfo(string fakeBotId) { if (!RobotDataManager.IsRobot(fakeBotId)) return null; var botTable = GContext.container.Resolve().TbRobot; var bot = botTable[RobotDataManager.Id2Idx(fakeBotId)]; return new PlayerInfo { PlayFabId = fakeBotId, AvatarUrl = bot.Avatar, DisplayName = bot.Name, Level = UnityEngine.Random.Range(60, 120), }; } public List GetMaskUrlList(int idx) { return idx == 0 ? _tbMain.Statue1Mask : _tbMain.Statue2Mask; } public List GetMultiplierList() { return _tbMain.SpinMag; } public EEventPartnerStatueDiceFace GetDiceFace(int faceIndex) { return (EEventPartnerStatueDiceFace)faceIndex; } public int GetTargetScoreByStage(int stage) { stage = Mathf.Clamp(stage, 0, _tbMain.StagePoint.Count); return _tbMain.StagePoint[stage]; } public int GetMinSpinPoint() { return _tbMain.PointList.Select(x => _tbSpinPoints[x]).Min(sp => sp.Point); } public List GetRewardList() { var arc = GContext.container.Resolve(); return _tbMain.StageReward .Select(x => _playerItemData.GetItemDataByDropIdAndTypeLureInflation(arc.Model.LureInflationRate, x)[0]) .ToList(); } public string GetEntranceIconUrl() { return _tbMain.Icon; } public string GetMainPanelUrl() { return _tbMain.UIPanel; } public string GetBuildPanelUrl() { return _tbMain.GamePanel; } public string GetInfoPanelUrl() { return _tbMain.InfoPanel; } public string GetPackPanelUrl() { return _tbMain.PackPanel; } public async void ShowFestPack() { try { var packData = new EventNeoNormalPackData { EventId = EventId, PackId = _tbMain.PackId, Panel = _tbMain.PackPanel }; await EventNeoNormalPackPanel.TryShowAsync(packData); } catch (Exception e) { Debug.LogError($"[EventPartner]ShowFestPack error: {e}"); } } public string GetActUrl() { return _tbMain.Act; } public List GetAddressableArray() { return _tbMain.Addressable; } public float GetToolAnimationDuration(int face) { return _tbDice[face].AnimationTime; } public float GetToolAnimationFxDelay(int face) { return _tbDice[face].FxDelay; } public float GetSumToolAnimationDuration((int c1, int c2, int c3) c) { // return Mathf.Max(new float[] { GetToolAnimationDuration(c.c1), GetToolAnimationDuration(c.c2), GetToolAnimationDuration(c.c3) }); return GetToolAnimationDuration(c.c1) + GetToolAnimationDuration(c.c2) + GetToolAnimationDuration(c.c3); } // public int GetRushId() // { // return _tbMain.RushID; // } public string GetTokenName() { var tokenKey = _tables.TbItem[_tbMain.ItemID].Name_l10n_key; return LocalizationMgr.GetText(tokenKey); } #region TokenExchange public int GetTokenExchangeId() { return _tbMain.TokenExchangeId; } public int GetTokenExchangeItemId() { var tokenExchangeId = GetTokenExchangeId(); return GContext.container.Resolve().TbEventPartnerTokenExchange[tokenExchangeId].TokenItem; } #endregion } public interface ITableContext { public int EventId { get; } public int GetStageFromTotalScore(int score); public int GetTargetScoreByStage(int stage); public int GetMinSpinPoint(); public HashSet GetBotRecommendIdList(int count); public PlayerInfo GetBotInfo(string fakeBotId); } public struct EventPartnerStatueDiceCombination { public List Combination { get; set; } }