//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, December 04, 2018 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class TrialSweepResultWin : Window { [SerializeField] RectTransform m_ContainerReward1; [SerializeField] RectTransform m_ContainerReward2; [SerializeField] ItemBehaviour[] m_ItemBehaviours1; [SerializeField] ItemBehaviour[] m_ItemBehaviours2; [SerializeField] Text m_FairyCoin; [SerializeField] Text m_VipPrivilege; [SerializeField] TrialSweepAssistPlayerBehaviour[] m_AssistPlayers; [SerializeField] Button m_Close; [SerializeField] Button m_Func; [SerializeField] UIEffect m_Effect; DungeonModel model { get { return ModelCenter.Instance.GetModel(); } } DungeonAssistModel dungeonAssistModel { get { return ModelCenter.Instance.GetModel(); } } DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel(); } } PackModel playerPack { get { return ModelCenter.Instance.GetModel(); } } #region Built-in protected override void BindController() { } protected override void AddListeners() { m_Close.onClick.AddListener(CloseClick); m_Func.onClick.AddListener(OnFunc); } protected override void OnPreOpen() { model.getDungeonResultEvent += GetDungeonResultEvent; Display(); } protected override void OnAfterOpen() { m_Effect.Play(); } protected override void OnPreClose() { model.getDungeonResultEvent -= GetDungeonResultEvent; } protected override void OnAfterClose() { } #endregion void Display() { DisplayItems(); DisplayExtension(); DisplayAssistPlayers(); } void DisplayItems() { var serveritems = model.dungeonResult.itemInfo; var items = new List(); for (int i = 0; i < serveritems.Length; i++) { var serverItem = serveritems[i]; items.Add(new Item(serverItem.ItemID, serverItem.Count)); } items.Sort(Compare); m_ContainerReward1.SetActive(items.Count > 0); for (int i = 0; i < m_ItemBehaviours1.Length; i++) { var behaviour = m_ItemBehaviours1[i]; if (i < items.Count) { behaviour.SetActive(true); var reward = items[i]; behaviour.SetItem(reward); } else { behaviour.SetActive(false); } } if (items.Count > m_ItemBehaviours1.Length) { m_ContainerReward2.SetActive(true); var startIndex = m_ItemBehaviours1.Length; for (int i = 0; i < m_ItemBehaviours2.Length; i++) { var behaviour = m_ItemBehaviours2[i]; if (i + startIndex < items.Count) { behaviour.SetActive(true); var reward = items[i + startIndex]; behaviour.SetItem(reward); } else { behaviour.SetActive(false); } } } else { m_ContainerReward2.SetActive(false); } } void DisplayExtension() { var dungeonResult = model.dungeonResult; var coin = 0; if (dungeonResult.xianyuanCoin != null && dungeonResult.xianyuanCoin.Length > 0) { coin = dungeonResult.xianyuanCoin[0]; } m_FairyCoin.text = Language.Get("AssistSweepGainCoin", coin); var vipAddRatio = string.Empty; if (dungeonAssistModel.TryGetCurVipAddRatio(out vipAddRatio)) { m_VipPrivilege.text = StringUtility.Contact(Language.Get("AssistSweepVipPrivilege"), vipAddRatio); } else { m_VipPrivilege.text = StringUtility.Contact(Language.Get("AssistSweepVipPrivilege"), Language.Get("Market_Text_33")); } } void DisplayAssistPlayers() { var dungeonResult = model.dungeonResult; var index = 0; if (dungeonResult.helpPlayer != null) { foreach (var key in dungeonResult.helpPlayer.Keys) { var id = int.Parse(key); var player = dungeonResult.helpPlayer[key]; if (index < m_AssistPlayers.Length) { m_AssistPlayers[index].SetActive(true); var name = player.Name; if (id <= 100) { var npcConfig = NPCConfig.Get(dungeonAssistModel.assistRobotId); name = npcConfig.charName; } m_AssistPlayers[index].Display(id,player.Face,player.FacePic,player.Job, name, player.Relation); } index++; } } for (int i = index; i < m_AssistPlayers.Length; i++) { m_AssistPlayers[i].SetActive(false); } } private void OnFunc() { var error = 0; if (TestSweep(out error)) { model.RequestSweep(model.currentDungeon); } else { switch (error) { case 1: WindowCenter.Instance.Open(); break; case 2: SysNotifyMgr.Instance.ShowTip("Multiple_Finish"); break; case 3: var tickets = model.GetTicketCost(model.currentDungeon.mapId, model.currentDungeon.lineId); ItemTipUtility.Show(tickets.id); break; case 4: var cost = model.GetSweepCost(model.currentDungeon); var itemOwn = playerPack.GetItemCountByID(PackType.Item, cost.id); var moneyNeed = GeneralDefine.autoBuyItemPrices[0] * (cost.count - itemOwn); ConfirmCancel.ShowPopConfirm( Language.Get("Mail101"), Language.Get("MultipleSweep_Text3", cost.count - itemOwn, moneyNeed), (bool _ok) => { if (_ok) { var moneyOwn = PlayerDatas.Instance.baseData.diamond; if (moneyNeed > moneyOwn) { WindowCenter.Instance.Open(); } else { model.RequestSweep(model.currentDungeon); } } } ); break; case 5: SysNotifyMgr.Instance.ShowTip("SweepFB_1"); break; } } } private bool TestSweep(out int error) { var dataMapId = model.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID); if (dataMapId == model.currentDungeon.mapId) { error = 5; return false; } var dailyQuestId = dailyQuestModel.GetDailyQuestIdByDataMapId(model.currentDungeon.mapId); if (dailyQuestId != 0) { var state = dailyQuestModel.GetQuestState(dailyQuestId); if (state == DailyQuestModel.DailyQuestState.CanBuyTimes) { error = 1; return false; } if (state == DailyQuestModel.DailyQuestState.Completed) { error = 2; return false; } } var tickets = model.GetTicketCost(model.currentDungeon.mapId, model.currentDungeon.lineId); var ticketsOwn = playerPack.GetItemCountByID(PackType.Item, tickets.id); if (ticketsOwn < tickets.count) { error = 3; return false; } var sweepCost = model.GetSweepCost(model.currentDungeon); var itemOwn = playerPack.GetItemCountByID(PackType.Item, sweepCost.id); if (itemOwn < sweepCost.count) { error = 4; return false; } error = 0; return true; } protected int Compare(Item x, Item y) { var config_x = ItemConfig.Get(x.id); var config_y = ItemConfig.Get(y.id); bool equip_x = ItemLogicUtility.Instance.IsRealmEquip(x.id); bool equip_y = ItemLogicUtility.Instance.IsRealmEquip(y.id); if (equip_x.CompareTo(equip_y) != 0) { return equip_x.CompareTo(equip_y); } if (!equip_x && !equip_y) { bool type_13_x = config_x.Type == 13; bool type_13_y = config_y.Type == 13; if (type_13_x.CompareTo(type_13_y) != 0) { return -type_13_x.CompareTo(type_13_y); } if (config_x.ItemColor.CompareTo(config_y.ItemColor) != 0) { return -config_x.ItemColor.CompareTo(config_y.ItemColor); } return x.id.CompareTo(y.id); } else { if (config_x.ItemColor.CompareTo(config_y.ItemColor) != 0) { return -config_x.ItemColor.CompareTo(config_y.ItemColor); } if (config_x.StarLevel.CompareTo(config_y.StarLevel) != 0) { return -config_x.StarLevel.CompareTo(config_y.StarLevel); } if (config_x.LV.CompareTo(config_y.LV) != 0) { return -config_x.LV.CompareTo(config_y.LV); } return x.id.CompareTo(y.id); } } private void GetDungeonResultEvent() { Display(); m_Effect.Play(); } } }