using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Snxxz.UI { [XLua.LuaCallCSharp] public class EquipTrainModel : Model { public readonly LogicInt selectedLevel = new LogicInt(); public readonly LogicInt selectedPlace = new LogicInt(); public readonly LogicInt equipTrainLevel = new LogicInt(); public readonly LogicInt equipTrainMaxLevel = new LogicInt(); public readonly LogicInt material = new LogicInt(); public readonly LogicInt inevitableMaterialCount = new LogicInt(); public readonly LogicEnum operateType = new LogicEnum(TrainOperateType.None); public readonly LogicList candidatePlaces = new LogicList(); public readonly LogicList propertyBars = new LogicList(); static Dictionary trainTypes = new Dictionary(); Dictionary equipTrains = new Dictionary(); EquipStarModel starModel { get { return ModelCenter.Instance.GetModel(); } } PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } EquipModel equipModel { get { return ModelCenter.Instance.GetModel(); } } public override void Init() { ParseConfig(); var levels = equipModel.GetAllEquipSets(); foreach (var level in levels) { equipTrains[level] = new EquipTrainSet(level); } } public override void UnInit() { } public void ResetOperateParams() { selectedLevel.value = 0; selectedPlace.value = 0; equipTrainLevel.value = 0; equipTrainMaxLevel.value = 0; material.value = 0; inevitableMaterialCount.value = 0; operateType.value = TrainOperateType.None; candidatePlaces.Clear(); propertyBars.Clear(); } public void UpdateEquipTrainInfo(HA3BB_tagMCEquipPartXLAttrInfo info) { foreach (var item in info.InfoList) { var clientEquipPlace = EquipSet.ServerPlaceToClientPlace(item.EquipPlace); var trainLevel = item.XLAttrLV; if (equipTrains.ContainsKey(clientEquipPlace.x)) { var equipTrain = equipTrains[clientEquipPlace.x]; var unSavedProperties = Int3.zero; var trainedProperties = Int3.zero; for (int i = 0; i < item.XLAttrList.Length; i++) { var property = item.XLAttrList[i]; trainedProperties[i] = (int)property.XLAttrValue; unSavedProperties[i] = (int)(property.XLAttrChange > 0 ? property.XLAttrChange - property.XLAttrValue : 0); } equipTrain.UpdateEquipTrainLevel(clientEquipPlace.y, trainLevel); equipTrain.UpdateTrainedProperties(clientEquipPlace.y, trainedProperties); equipTrain.UpdateUnSavedProperties(clientEquipPlace.y, unSavedProperties); if (clientEquipPlace.x == selectedLevel.value && clientEquipPlace.y == selectedPlace.value) { equipTrainLevel.value = trainLevel; for (int i = 0; i < propertyBars.Count; i++) { var bar = propertyBars[i]; bar.deltaValue.value = unSavedProperties[i]; bar.propertyValue.value = trainedProperties[i]; } } } } if (selectedLevel.value > 0) { var level = selectedLevel.value; var place = selectedPlace.value; var trainState = GetEquipPlaceTrainState(level, place); equipTrainLevel.value = GetTrainLevel(level, place); equipTrainMaxLevel.value = trainState == TrainState.Empty ? -1 : GetMaxTrainLevel(level, place); material.value = GetTrainMaterial(level, place); operateType.value = CalculateTrainOperateType(level, place); InitTrainableProperties(level, place, operateType.value); } } public void Train(int level, int place, bool[] inevitables) { var code = 0; var inevitableCount = 0; for (int i = 0; i < inevitables.Length; i++) { inevitableCount += inevitables[i] ? 1 : 0; code += inevitables[i] ? MathUtility.Power(2, i) : 0; } var need = GetMaterialNeed(level, place); var itemId = GetTrainMaterial(level, place); var own = packModel.GetItemCountByID(PackType.Item, itemId); if (need > own) { return; } if (inevitableCount > 0) { var trainLevel = GetTrainLevel(level, place); var trainType = GetTrainType(place); var config = EquipWashConfig.Get(trainType, trainLevel + 1); var moneyNeed = config != null ? config.mustCosts[inevitableCount - 1] : 0; var moneyOwn = PlayerDatas.Instance.baseData.diamond; if (moneyNeed > moneyOwn) { return; } } var equipWash = new CA325_tagCMEquipXLAttrChange(); equipWash.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(level, place); equipWash.CheckUseGoldAttr = (byte)code; GameNetSystem.Instance.SendInfo(equipWash); } public void Save(int level, int place) { var result = new CA326_tagCMEquipXLAttrChangeOK(); result.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(level, place); result.IsSave = 1; GameNetSystem.Instance.SendInfo(result); } public void GiveUp(int level, int place) { var result = new CA326_tagCMEquipXLAttrChangeOK(); result.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(level, place); result.IsSave = 0; GameNetSystem.Instance.SendInfo(result); } public void SelectLevel(int level) { selectedLevel.value = level; candidatePlaces.Clear(); var places = GetTrainablePlaces(level); if (places.IsNullOrEmpty()) { SelectPlace(level, 0); } else { for (var i = 0; i < places.Count; i++) { var place = places[i]; candidatePlaces.Add(new EquipTrainCandidate(level, place)); if (i == 0) { SelectPlace(level, place); } } } } public void SelectPlace(int level, int place) { selectedPlace.value = place; selectedPlace.dirty = true; for (int i = 0; i < candidatePlaces.Count; i++) { var candidate = candidatePlaces[i]; candidate.selected.value = candidate.level == level && candidate.place == place; } var trainState = GetEquipPlaceTrainState(level, place); equipTrainLevel.value = GetTrainLevel(level, place); equipTrainMaxLevel.value = trainState == TrainState.Empty ? -1 : GetMaxTrainLevel(level, place); material.value = GetTrainMaterial(level, place); operateType.value = CalculateTrainOperateType(level, place); InitTrainableProperties(level, place, operateType.value); } public void SetInevitable(int index, bool invevitable) { var equipGuid = equipModel.GetEquip(selectedLevel.value, selectedPlace.value); if (string.IsNullOrEmpty(equipGuid)) { SysNotifyMgr.Instance.ShowTip("Wash_NoEquip1"); return; } if (invevitable) { var properties = GetTrainedProperties(selectedLevel.value, selectedPlace.value); var type = GetTrainType(selectedPlace.value); var trainLevel = GetTrainLevel(selectedLevel.value, selectedPlace.value); var data = EquipWashConfig.Get(type, trainLevel); var isPerfect = false; switch (index) { case 1: isPerfect = properties[index - 1] >= data.config.attMax1; break; case 2: isPerfect = properties[index - 1] >= data.config.attMax2; break; case 3: isPerfect = properties[index - 1] >= data.config.attMax3; break; } if (isPerfect) { return; } } if (propertyBars.Count > index) { propertyBars[index].inevitable.value = invevitable; } inevitableMaterialCount.value = CalculateInevitableMaterialCount(); } public int GetTrainLevel(int level, int place) { if (!equipTrains.ContainsKey(level)) { return 0; } return equipTrains[level].GetTrainLevel(place); } public int GetTotalLevel(int level) { if (!equipTrains.ContainsKey(level)) { return 0; } return equipTrains[level].GetTotalLevel(); } public int GetMaterialNeed(int level, int place) { var star = starModel.GetEquipStarLevel(level, place); var type = GetTrainType(place); var data = EquipWashConfig.Get(type, star + 1); return data.config.costCount; } public int GetMaxTrainLevel(int place) { var type = GetTrainType(place); return WashLevelMaxConfig.GetMaxLevel(type); } public int GetMaxTrainLevel(int level, int place) { var star = starModel.GetEquipStarLevel(level, place); var type = GetTrainType(place); var config = WashLevelMaxConfig.Get(type, star); if (config == null) { return 0; } else { return config.levelMax; } } public List GetCandidatePlaces() { return candidatePlaces.Fetch(); } public TrainState GetEquipPlaceTrainState(int level, int place) { var equipGuid = equipModel.GetEquip(level, place); if (string.IsNullOrEmpty(equipGuid)) { return TrainState.Empty; } var equip = packModel.GetItemByGuid(equipGuid); if (equip == null) { return TrainState.Empty; } var type = GetTrainType(place); var currentStarLevel = GetTrainLevel(level, place); var absoluteMax = GetMaxTrainLevel(place); var data = EquipWashConfig.Get(type, Mathf.Clamp(currentStarLevel, 1, absoluteMax)); if (data == null) { return TrainState.Empty; } var properties = GetTrainedProperties(level, place); var isFull = properties.x >= data.config.attMax1 && properties.y >= data.config.attMax2 && properties.z >= data.config.attMax3; if (isFull) { if (currentStarLevel >= absoluteMax) { return TrainState.MaxLevel; } var relativeMax = GetMaxTrainLevel(equip.config.LV, equip.config.EquipPlace); if (currentStarLevel >= relativeMax) { return TrainState.StarLimit; } } return TrainState.Allowable; } public Int3 GetUnSavedProperties(int level, int place) { return equipTrains.ContainsKey(level) ? equipTrains[level].GetUnSavedProperties(place) : Int3.zero; } public Int3 GetTrainedProperties(int level, int place) { return equipTrains.ContainsKey(level) ? equipTrains[level].GetTrainedProperties(place) : Int3.zero; } private List GetTrainablePlaces(int level) { if (level <= 0) { return null; } var equipSet = equipModel.GetEquipSet(level); if (equipSet == null) { return null; } var places = new List(); for (var i = 1; i <= 12; i++) { var unLocked = equipSet.IsSlotUnLocked(i); if (unLocked) { places.Add(i); } } return places; } private void InitTrainableProperties(int level, int place, TrainOperateType operateType) { propertyBars.Clear(); var trainState = GetEquipPlaceTrainState(level, place); var absoluteMax = GetMaxTrainLevel(place); var unSavedProperties = GetUnSavedProperties(level, place); var trainedProperties = GetTrainedProperties(level, place); var trainLevel = GetTrainLevel(level, place); var data = EquipWashConfig.Get(GetTrainType(place), Mathf.Clamp(trainLevel, 1, absoluteMax)); if (data != null) { var propertyBar = new EquipTrainPropertyBar(data.config.attType1, trainState == TrainState.Empty ? 0 : data.config.attMax1, trainState); propertyBar.propertyValue.value = trainedProperties.x; propertyBar.deltaValue.value = unSavedProperties.x; propertyBar.operateType.value = operateType; propertyBars.Add(propertyBar); propertyBar = new EquipTrainPropertyBar(data.config.attType2, trainState == TrainState.Empty ? 0 : data.config.attMax2, trainState); propertyBar.propertyValue.value = trainedProperties.y; propertyBar.deltaValue.value = unSavedProperties.y; propertyBar.operateType.value = operateType; propertyBars.Add(propertyBar); propertyBar = new EquipTrainPropertyBar(data.config.attType3, trainState == TrainState.Empty ? 0 : data.config.attMax3, trainState); propertyBar.propertyValue.value = trainedProperties.z; propertyBar.deltaValue.value = unSavedProperties.z; propertyBar.operateType.value = operateType; propertyBars.Add(propertyBar); } inevitableMaterialCount.value = CalculateInevitableMaterialCount(); } private int GetTrainMaterial(int level, int place) { if (GetEquipPlaceTrainState(level, place) == TrainState.Allowable) { var star = starModel.GetEquipStarLevel(level, place); var type = GetTrainType(place); var data = EquipWashConfig.Get(type, star + 1); return data.config.costItem; } else { return 0; } } private int CalculateInevitableMaterialCount() { var count = 0; for (int i = 0; i < propertyBars.Count; i++) { count += propertyBars[i].inevitable.value ? 1 : 0; } return count; } private TrainOperateType CalculateTrainOperateType(int level, int place) { var unSavedProperties = GetUnSavedProperties(level, place); if (unSavedProperties != Int3.zero) { return TrainOperateType.Save; } var trainState = GetEquipPlaceTrainState(level, place); if (trainState == TrainState.Allowable) { return TrainOperateType.Train; } if (trainState == TrainState.StarLimit || trainState == TrainState.MaxLevel) { return TrainOperateType.Max; } return TrainOperateType.None; } private void ParseConfig() { var config = FuncConfigConfig.Get("EquipWashGroup"); trainTypes = ConfigParse.GetDic(config.Numerical1); } public static int GetTrainType(int equipType) { return trainTypes.ContainsKey(equipType) ? trainTypes[equipType] : 0; } public enum TrainOperateType { None = 0, Train = 1, Forbid = 2, Save = 3, Max = 4, } public enum TrainState { Empty, StarLimit, MaxLevel, Allowable, } } }