using System.Collections; using System.Collections.Generic; using UnityEngine; using System; namespace vnxbqy.UI { public class EquipStarModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize { public readonly LogicInt selectedLevel = new LogicInt(); public readonly LogicInt selectedPlace = new LogicInt(); public readonly LogicInt equipStarLevel = new LogicInt(); public readonly LogicInt equipMaxStarLevel = new LogicInt(); public readonly LogicList candidatePlaces = new LogicList(); public readonly LogicList stars = new LogicList(); public readonly LogicInt specialMaterial = new LogicInt(); public readonly LogicInt specialMaterial2 = new LogicInt(); public readonly LogicInt starResultEffect = new LogicInt(); public readonly LogicInt autoBuy = new LogicInt(); public Int2 jumpEquipPos = Int2.zero; public List useStarMaterials = new List(); //可用于升星的装备 public string biggestRateMaterial = string.Empty; //低境界非红装的最高概率一件 Dictionary equipStars = new Dictionary(); public Dictionary EquipStars { get { return equipStars; } } Redpoint redpoint = new Redpoint(106, 1720000); bool redpointDirty = false; LogicUpdate logicUpdate = new LogicUpdate(1); PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } EquipModel equipModel { get { return ModelCenter.Instance.GetModel(); } } public static List StarList = new List { 0, 3, 6, 9, 12, 15, 18 }; public override void Init() { ParseConfig(); logicUpdate.Start(OnUpdate); packModel.refreshItemCountEvent += OnItemCountRefresh; DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent += OnGetUpgradeStarResult; autoBuy.value = -1; } public override void UnInit() { packModel.refreshItemCountEvent -= OnItemCountRefresh; DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent -= OnGetUpgradeStarResult; } public void OnBeforePlayerDataInitialize() { foreach (var equipStar in equipStars) { equipStar.Value.ResetStarLevel(); } } public void OnPlayerLoginOk() { } public void UpdateStarLevels(HA3B1_tagMCEquipPartStarInfo info) { var selectedEquipOldStar = GetEquipStarLevel(new Int2(selectedLevel.value, selectedPlace.value)); for (var i = 0; i < info.InfoList.Length; i++) { var equipPosition = EquipSet.ServerPlaceToClientPlace(info.InfoList[i].EquipPackIndex); var level = equipPosition.x; if (equipStars.ContainsKey(level)) { equipStars[level].UpdateEquipStarLevel(equipPosition.y, info.InfoList[i].Star); } } var starLevel = GetEquipStarLevel(new Int2(selectedLevel.value, selectedPlace.value)); equipStarLevel.value = starLevel; selectedPlace.dirty = true; var maxStarLevel = GetMaxStarLevel(selectedLevel.value); UpdateSelelctedEquipStars(selectedEquipOldStar, starLevel, maxStarLevel); for (int i = 0; i < candidatePlaces.Count; i++) { var candidate = candidatePlaces[i]; candidate.starLevel.value = GetEquipStarLevel(candidate.equipPosition); } redpointDirty = true; } void OnGetUpgradeStarResult(H0721_tagMakeItemAnswer info) { if (info.MakeType == (byte)MakeType.EquipStarUpgrade) { var equipPosition = new Int2(selectedLevel.value, selectedPlace.value); AutoAddMaterials(equipPosition); if (info.Result == 1) { var successModel = ModelCenter.Instance.GetModel(); successModel.Show(equipPosition, GetStarLevel(equipPosition)); starResultEffect.value = 1; } else { EffectMgr.Instance.PlayUIEffect(7066, 2500, WindowCenter.Instance.uiRoot.tipsCanvas, false); SysNotifyMgr.Instance.ShowTip("StarLevelUpFail"); starResultEffect.value = -1; } } } //装备已填充100%后,客户端自己计算升星石价格 public int GetItemsMoney(Int2 equipPosition, int starLevel) { var config = EquipStarConfig.Get(equipPosition.x, equipPosition.y, starLevel); if (config == null) { return 0; } int itemID = config.CostItemDict[0].x; int count = config.CostItemDict[0].y; if (itemID <= 0 || count <= 0) return 0; var shopConfig = StoreConfig.GetStoreCfg(itemID, 2, 5); if (shopConfig == null) return 0; int hasCnt = packModel.GetItemCountByID(PackType.Item, config.CostItemDict[0].x); int needCnt = count >= hasCnt ? count - hasCnt : 0; return needCnt * shopConfig.MoneyNumber; } public void DoStarUpgrade(Int2 equipPosition, int starLevel, int auto=0) { if (!equipStars.ContainsKey(equipPosition.x)) { return; } var equip = packModel.GetItemByGuid(equipModel.GetEquip(equipPosition)); if (equip == null) { return; } if (equip.config.ItemColor < 4) { SysNotifyMgr.Instance.ShowTip("StarLevelUp4"); return; } var maxLevel = GetMaxStarLevel(equipPosition.x); if (starLevel > maxLevel) { SysNotifyMgr.Instance.ShowTip("StarLevelUp1"); return; } var config = EquipStarConfig.Get(equipPosition.x, equipPosition.y, starLevel); if (config == null) { return; } if (config.CostItemDict[0].x > 0 && specialMaterial.value == 0 && auto == 0) { SysNotifyMgr.Instance.ShowTip("StarLevelUp2", config.CostItemDict[0].x); ItemTipUtility.Show(config.CostItemDict[0].x); return; } if (config.CostItemDict.Length > 1 && config.CostItemDict[1].x > 0 && specialMaterial2.value == 0 ) { SysNotifyMgr.Instance.ShowTip("StarLevelUp2", config.CostItemDict[1].x); ItemTipUtility.Show(config.CostItemDict[1].x); return; } if (config.CostItemDict[0].x > 0 && packModel.GetItemCountByID(PackType.Item, config.CostItemDict[0].x) < config.CostItemDict[0].y && auto == 0) { SysNotifyMgr.Instance.ShowTip("StarLevelUp2", config.CostItemDict[0].x); ItemTipUtility.Show(config.CostItemDict[0].x); return; } LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(2, config.CostItemDict[0].x, config.CostItemDict[0].y, 1, 0); LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(2, config.CostItemDict[1].x, config.CostItemDict[1].y, 1, 0); if (config.CostItemDict.Length > 1 && config.CostItemDict[1].x > 0 && packModel.GetItemCountByID(PackType.Item, config.CostItemDict[1].x) < config.CostItemDict[1].y) { SysNotifyMgr.Instance.ShowTip("StarLevelUp2", config.CostItemDict[1].x); ItemTipUtility.Show(config.CostItemDict[1].x); return; } var materialIndexs = new List(); var materialItemIds = new List(); Action sendInfo = () => { var info = new CA5C5_tagCMEquipPartStarUp(); info.EquipPackIndex = (ushort)EquipSet.ClientPlaceToServerPlace(equipPosition); info.CostEquipIndex = materialIndexs.ToArray(); info.CostEquipID = materialItemIds.ToArray(); info.CostEquipCnt = (byte)materialIndexs.Count; info.AutoBuy = (byte)auto; GameNetSystem.Instance.SendInfo(info); }; sendInfo(); } public void ResetOperateParams() { if (autoBuy.value == -2) autoBuy.value = -1; selectedLevel.value = 0; selectedPlace.value = 0; equipStarLevel.value = 0; equipMaxStarLevel.value = 0; starResultEffect.value = 0; stars.Clear(); } public Int2 GetRecommendEquipPosition() { foreach (var starSet in equipStars.Values) { var level = starSet.level; for (var place = 1; place <= 12; place++) { var isRedpoint = starSet.GetRedpointState(place) != RedPointState.None; if (isRedpoint) { return new Int2(level, place); } } } foreach (var starSet in equipStars.Values) { var level = starSet.level; for (var i = 1; i <= 12; i++) { var equipPosition = new Int2(level, i); var item = packModel.GetItemByGuid(equipModel.GetEquip(equipPosition)); if (item == null) { continue; } var starLevel = GetStarLevel(equipPosition); var maxStarLevel = GetMaxStarLevel(item.config.ItemColor, item.config.LV); if (starLevel >= maxStarLevel) { continue; } } } return new Int2(1, 1); } public void SelectLevel(int level) { selectedLevel.value = level; candidatePlaces.Clear(); if (level > 0) { // int equipCnt = level < 2 ? 8 : 12; for (var i = 1; i <= 12; i++) { var place = i; var equipPosition = new Int2(level, place); var candidate = new EquipStarUpgradeCandidate(equipPosition); candidate.starLevel.value = GetEquipStarLevel(equipPosition); candidatePlaces.Add(candidate); } candidatePlaces.Sort(EquipStarUpgradeCandidateCompare); SelectPlace(candidatePlaces[0].equipPosition); } else { SelectPlace(Int2.zero); } } public void SelectPlace(Int2 equipPosition) { selectedPlace.value = equipPosition.y; selectedPlace.dirty = true; if (equipPosition.x > 0 && equipPosition.y >= 1 && equipPosition.y <= 12) { for (int i = 0; i < candidatePlaces.Count; i++) { var candidate = candidatePlaces[i]; candidate.selected.value = candidate.equipPosition == equipPosition; } var starLevel = GetEquipStarLevel(equipPosition); var maxStarLevel = GetMaxStarLevel(equipPosition.x); equipStarLevel.value = starLevel; equipMaxStarLevel.value = maxStarLevel; UpdateSelelctedEquipStars(starLevel, starLevel, maxStarLevel); AutoAddMaterials(equipPosition); } } //是否可升星 public bool IsEquipPlaceUpgradable(string equipGuid) { if (string.IsNullOrEmpty(equipGuid)) { return false; } var equip = packModel.GetItemByGuid(equipGuid); if (equip == null) { return false; } var maxStarLevel = GetMaxStarLevel(equip.config.ItemColor, equip.config.LV); var currentStarLevel = GetEquipStarLevel(new Int2(equip.config.LV, equip.config.EquipPlace)); return currentStarLevel < maxStarLevel; } public static int GetMaxStarLevel(int quality, int level) { var max = 0; if (GeneralDefine.equipStarLimit.ContainsKey(quality)) { var itemLevelStars = GeneralDefine.equipStarLimit[quality]; if (itemLevelStars.ContainsKey(level)) { max = itemLevelStars[level]; } } return max; } public static int GetMaxStarLevel(int level) { var max = 0; foreach (var itemLevelStars in GeneralDefine.equipStarLimit.Values) { if (itemLevelStars.ContainsKey(level)) { if (itemLevelStars[level] > max) { max = itemLevelStars[level]; } } } return max; } public int GetEquipPositionMaxStarLevel(Int2 equipPosition) { var equipGuid = equipModel.GetEquip(equipPosition); if (equipGuid == null) { return 0; } var equip = packModel.GetItemByGuid(equipGuid); if (equip == null) { return 0; } return GetMaxStarLevel(equip.config.ItemColor, equip.config.LV); } public int GetTotalStarLevel(int level) { if (!equipStars.ContainsKey(level)) { return 0; } return equipStars[level].GetTotalStarLevel(); } /// /// 这是指已经装备位置已经升级到的星级,不考虑当前穿戴的装备 /// /// /// public int GetStarLevel(Int2 equipPosition) { if (!equipStars.ContainsKey(equipPosition.x)) { return 0; } return equipStars[equipPosition.x].GetEquipStarLevel(equipPosition.y); } /// /// 这是指受当前装备限制的星级,比如当前装备位已经升级到了9星,但是穿戴的装备最高可升级到6星,那么返回的值是6 /// /// /// public int GetEquipStarLevel(Int2 equipPosition) { var starLevel = GetStarLevel(equipPosition); var maxLevel = GetEquipPositionMaxStarLevel(equipPosition); return Mathf.Min(starLevel, maxLevel); } public List GetMaterialGetWays(Int2 equipPosition, int starLevel) { var config = EquipStarConfig.Get(equipPosition.x, equipPosition.y, starLevel); if (config == null) { return null; } var getWays = new List(); foreach (int place in config.CostEquipPlace) { var equipControlConfig = EquipControlConfig.Get(equipPosition.x, place); foreach (int getWay in equipControlConfig.getWays) { if (!getWays.Contains(getWay)) { getWays.Add(getWay); } } } return getWays; } //1、可提升战力装备不显示. //2、红装排最后 //3、境界,小于等级自身的优先显示 //4、特殊处理概率【最高】的一件低境界非红装显示在第一件 //筛选可用于升星的装备材料 public List GetMaterials(Int2 equipPosition, int starLevel) { var config = EquipStarConfig.Get(equipPosition.x, equipPosition.y, starLevel); if (config == null) { return null; } var equipGuid = equipModel.GetEquip(equipPosition); var equip = packModel.GetItemByGuid(equipGuid); if (equip == null) { return null; } var expcetMaterials = packModel.GetItems(PackType.Item, new SinglePack.FilterParams() { qualitys = new List(config.CostEquipColor), equipTypes = new List(config.CostEquipPlace), jobs = config.IsJobLimit == 1 ? new List() { PlayerDatas.Instance.baseData.Job } : null, }); float rate = 0; var materialGuids = new List(); foreach (var item in expcetMaterials) { if (ItemLogicUtility.Instance.IsFightUpEx(item.itemId, item.score, item.config.RealmLimit) == -1) { //4、特殊处理概率【最高】的一件低境界非红装显示在第一件 if (item.config.ItemColor <= 4 && item.config.RealmLimit <= PlayerDatas.Instance.baseData.realmLevel) { var tmpRate = GetMaterialSuccessRate(equipPosition, item.guid); if (rate < tmpRate) { biggestRateMaterial = item.guid; rate = tmpRate; } } //不显示更高战力的装备 materialGuids.Add(item.guid); } } materialGuids.Remove(biggestRateMaterial); return materialGuids; } private void AutoAddMaterials(Int2 equipPosition) { var equipGuid = equipModel.GetEquip(equipPosition); var upgradable = IsEquipPlaceUpgradable(equipGuid); if (upgradable) { var config = EquipStarConfig.Get(equipPosition.x, equipPosition.y, GetEquipStarLevel(equipPosition) + 1); if (config.CostItemDict.Length > 0 && config.CostItemDict[0].x > 0) { var itemId = config.CostItemDict[0].x; specialMaterial.value = itemId; } else { specialMaterial.value = 0; } if (config.CostItemDict.Length > 1) { var itemId = config.CostItemDict[1].x; specialMaterial2.value = itemId; } else { specialMaterial2.value = 0; } } } public float GetMaterialSuccessRate(Int2 equipPosition, string guid) { if (string.IsNullOrEmpty(guid)) { return 0f; } var item = packModel.GetItemByGuid(guid); if (item == null) { return 0f; } var currentStarLevel = GetEquipStarLevel(equipPosition); var config = EquipStarConfig.Get(equipPosition.x, equipPosition.y, currentStarLevel + 1); if (config == null) { return 0f; } var amendLevel = item.config.LV - equipPosition.x; var amendRate = 1f; if (amendLevel > 0) { amendRate = 1 + amendLevel * GeneralDefine.equipStarUpAmendFactor * 0.01f; } else { amendRate = 1 + amendLevel * GeneralDefine.equipStarDownAmendFactor * 0.01f; } var successRate = 0.5f; var isSuit = item.config.SuiteiD > 0; if (isSuit) { successRate = Mathf.Clamp(Mathf.CeilToInt((float)Math.Round(config.SuitRate * amendRate, 2)), GeneralDefine.suitEquipStarUpgradeRateFloor, GeneralDefine.suitEquipStarUpgradeRateCeiling); } else { successRate = Mathf.Clamp(Mathf.CeilToInt((float)Math.Round(config.UnSuitRate * amendRate, 2)), GeneralDefine.normalEquipStarUpgradeRateFloor, GeneralDefine.normalEquipStarUpgradeRateCeiling); } return successRate * 0.01f; } private void UpdateSelelctedEquipStars(int oldStarLevel, int newStarLevel, int maxStarLevel) { stars.Clear(); for (var i = 1; i <= maxStarLevel; i++) { stars.Add(new Star() { actived = i <= newStarLevel, newGet = i <= newStarLevel && i > oldStarLevel, }); } } private void OnItemCountRefresh(PackType type, int index, int itemId) { switch (type) { case PackType.Item: //if (ItemLogicUtility.Instance.IsRealmEquip(itemId)) //{ // redpointDirty = true; //} var itemConfig = ItemConfig.Get(itemId); if (itemConfig.Type == 34) { redpointDirty = true; } else if (itemId == 633) { redpointDirty = true; } break; case PackType.Equip: var clientEquipPosition = EquipSet.ServerPlaceToClientPlace(index); if (clientEquipPosition.x > 0) { redpointDirty = true; } break; } } private void UpdateStarRedpoint() { var targetEquipPosition = Int2.zero; var minStarLevel = 999; foreach (var trainSet in equipStars.Values) { var level = trainSet.level; for (var place = 1; place <= 12; place++) { var equipPosition = new Int2(level, place); var item = packModel.GetItemByGuid(equipModel.GetEquip(equipPosition)); if (item == null) { continue; } //达到最大星级 var maxStarLevel = GetMaxStarLevel(item.config.ItemColor, item.config.LV); var starLevel = GetStarLevel(new Int2(level, place)); if (starLevel >= maxStarLevel) { continue; } //不是候选者中星级最小的 if (targetEquipPosition != Int2.zero && starLevel >= minStarLevel) { continue; } var config = EquipStarConfig.Get(level, place, starLevel + 1); if (config == null) { continue; } //固定材料不足 if (config.CostItemDict[0].x > 0 && packModel.GetItemCountByID(PackType.Item, config.CostItemDict[0].x) < config.CostItemDict[0].y) { continue; } if (config.CostItemDict.Length > 1 && config.CostItemDict[1].x > 0 && packModel.GetItemCountByID(PackType.Item, config.CostItemDict[1].x) < config.CostItemDict[1].y) { continue; } //var materials = packModel.GetItems(PackType.Item, new SinglePack.FilterParams() //{ // qualitys = new List(config.CostEquipColor), // equipTypes = new List(config.CostEquipPlace), // levels = new List() { item.config.LV }, // jobs = config.IsJobLimit == 1 ? new List() { PlayerDatas.Instance.baseData.Job } : null, //}); //for (int j = materials.Count - 1; j >= 0; j--) //{ // var material = materials[j]; // if (ItemLogicUtility.Instance.IsFightUp(material.itemId, material.score) == 1) // { // materials.RemoveAt(j); // } //} //var successRate = 0f; //foreach (var material in materials) //{ // successRate += GetMaterialSuccessRate(equipPosition, material.guid); // if (successRate >= 0.5f) // { // break; // } //} //if (successRate < 0.5f) //{ // continue; //} minStarLevel = starLevel; targetEquipPosition = new Int2(level, place); } } foreach (var starSet in equipStars.Values) { var level = starSet.level; if (!equipModel.IsLevelUnLocked(level)) { continue; } for (var place = 1; place <= 12; place++) { var isRedpoint = level == targetEquipPosition.x && place == targetEquipPosition.y; starSet.UpdateRedpoint(place, isRedpoint ? RedPointState.Simple : RedPointState.None); } } } private void OnUpdate() { if (redpointDirty && FuncOpen.Instance.IsFuncOpen(172)) { redpointDirty = false; UpdateStarRedpoint(); } } private int EquipStarUpgradeCandidateCompare(EquipStarUpgradeCandidate x, EquipStarUpgradeCandidate y) { var guidX = equipModel.GetEquip(x.equipPosition); var guidY = equipModel.GetEquip(y.equipPosition); if (!string.IsNullOrEmpty(guidX) && string.IsNullOrEmpty(guidY)) { return -1; } if (string.IsNullOrEmpty(guidX) && !string.IsNullOrEmpty(guidY)) { return 1; } return x.equipPosition.y.CompareTo(y.equipPosition.y); //var factorX = x.equipPosition.x * 100 + x.equipPosition.y; //var factorY = y.equipPosition.x * 100 + y.equipPosition.y; //if (string.IsNullOrEmpty(guidX) && string.IsNullOrEmpty(guidY)) //{ // return factorX.CompareTo(factorY); //} //var equipX = packModel.GetItemByGuid(guidX); //var equipY = packModel.GetItemByGuid(guidY); //var canUpgradeStarLevelX = GetMaxStarLevel(equipX.config.ItemColor, equipX.config.LV) - GetStarLevel(x.equipPosition); //var canUpgradeStarLevelY = GetMaxStarLevel(equipY.config.ItemColor, equipY.config.LV) - GetStarLevel(y.equipPosition); //var compareResult = canUpgradeStarLevelX.CompareTo(canUpgradeStarLevelY); //if (compareResult != 0) //{ // return -compareResult; //} //return factorX.CompareTo(factorY); } private void ParseConfig() { var configs = EquipStarConfig.GetValues(); foreach (var config in configs) { if (!equipStars.ContainsKey(config.Level)) { equipStars[config.Level] = new EquipSetStar(config.Level); } } } public struct Star { public bool actived; public bool newGet; } } }