using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class EquipTrainModel : Model, IBeforePlayerDataInitialize
|
{
|
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 LogicInt3 material = new LogicInt3();
|
public readonly LogicInt inevitableMaterialCount = new LogicInt();
|
public readonly LogicEnum<TrainOperateType> operateType = new LogicEnum<TrainOperateType>(TrainOperateType.None);
|
public readonly LogicList<EquipTrainCandidate> candidatePlaces = new LogicList<EquipTrainCandidate>();
|
public readonly LogicList<EquipTrainPropertyBar> propertyBars = new LogicList<EquipTrainPropertyBar>();
|
public readonly LogicBool trainLimit = new LogicBool();
|
|
static Dictionary<int, int> trainTypes = new Dictionary<int, int>();
|
Dictionary<int, EquipTrainSet> equipTrains = new Dictionary<int, EquipTrainSet>();
|
|
EquipStarModel starModel { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
|
|
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 OnBeforePlayerDataInitialize()
|
{
|
foreach (var train in equipTrains.Values)
|
{
|
train.Reset();
|
}
|
}
|
|
public void ResetOperateParams()
|
{
|
selectedLevel.value = 0;
|
selectedPlace.value = 0;
|
equipTrainLevel.value = 0;
|
equipTrainMaxLevel.value = 0;
|
material.value = Int3.zero;
|
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 equipPosition = new Int2(selectedLevel.value, selectedPlace.value);
|
var trainState = GetEquipPlaceTrainState(equipPosition);
|
equipTrainLevel.value = GetTrainLevel(equipPosition);
|
equipTrainMaxLevel.value = trainState == TrainState.Empty ? -1 : GetMaxTrainLevel(equipPosition);
|
material.value = GetTrainMaterial(equipPosition);
|
|
operateType.value = CalculateTrainOperateType(equipPosition);
|
InitTrainableProperties(equipPosition, operateType.value);
|
UpdateTrainLimitState(equipPosition);
|
}
|
|
if (candidatePlaces.Count > 0)
|
{
|
for (int i = 0; i < candidatePlaces.Count; i++)
|
{
|
candidatePlaces[i].trainLevel.value = GetTrainLevel(candidatePlaces[i].equipPosition);
|
}
|
}
|
}
|
|
public void Train(Int2 equipPosition, bool[] inevitables)
|
{
|
var maxLevel = GetMaxTrainLevel(equipPosition);
|
if (maxLevel < 1)
|
{
|
SysNotifyMgr.Instance.ShowTip("WashStarRequirement");
|
return;
|
}
|
|
var material = GetTrainMaterial(equipPosition);
|
if (material.z > material.y)
|
{
|
SysNotifyMgr.Instance.ShowTip("WashStone1");
|
return;
|
}
|
|
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;
|
}
|
|
if (inevitableCount > 0)
|
{
|
var trainLevel = GetTrainLevel(equipPosition);
|
var trainType = GetTrainType(equipPosition.y);
|
var config = EquipWashConfig.Get(trainType, trainLevel);
|
|
var inevitableNeed = config != null ? config.mustCosts[inevitableCount - 1] : 0;
|
var inevitableOwn = packModel.GetItemCountByID(PackType.Item, GeneralDefine.equipTrainMustItemId);
|
|
var diamondNeed = (inevitableNeed - inevitableOwn) * GetInevitableMaterialPrice();
|
var diamondOwn = PlayerDatas.Instance.baseData.diamond;
|
|
if (diamondNeed > diamondOwn)
|
{
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
return;
|
}
|
|
if (diamondNeed > 0)
|
{
|
if (!DayRemind.Instance.GetDayRemind(DayRemind.EQUIPTRAIN_COSTDIAMOND))
|
{
|
ConfirmCancel.ToggleConfirmCancel(Language.Get("Mail101"),
|
Language.Get("EquipWash103", inevitableNeed - inevitableOwn, diamondNeed),
|
Language.Get("TodayNoNotify"), (bool ok, bool isToggle) =>
|
{
|
if (isToggle)
|
{
|
DayRemind.Instance.SetDayRemind(DayRemind.EQUIPTRAIN_COSTDIAMOND, true);
|
}
|
|
if (!ok)
|
{
|
return;
|
}
|
});
|
}
|
}
|
}
|
|
var equipWash = new CA325_tagCMEquipXLAttrChange();
|
equipWash.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition);
|
equipWash.CheckUseGoldAttr = (byte)code;
|
GameNetSystem.Instance.SendInfo(equipWash);
|
}
|
|
public void Save(Int2 equipPosition)
|
{
|
var result = new CA326_tagCMEquipXLAttrChangeOK();
|
result.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition);
|
result.IsSave = 1;
|
GameNetSystem.Instance.SendInfo(result);
|
}
|
|
public void GiveUp(Int2 equipPosition)
|
{
|
var result = new CA326_tagCMEquipXLAttrChangeOK();
|
result.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition);
|
result.IsSave = 0;
|
GameNetSystem.Instance.SendInfo(result);
|
}
|
|
public void UpdateLevel(Int2 equipPosition)
|
{
|
var result = new CA326_tagCMEquipXLAttrChangeOK();
|
result.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition);
|
result.IsSave = 2;
|
GameNetSystem.Instance.SendInfo(result);
|
}
|
|
public void SelectLevel(int level)
|
{
|
selectedLevel.value = level;
|
candidatePlaces.Clear();
|
|
var places = GetTrainablePlaces(level);
|
if (places.IsNullOrEmpty())
|
{
|
SelectPlace(new Int2(level, 0));
|
}
|
else
|
{
|
for (var i = 0; i < places.Count; i++)
|
{
|
var place = places[i];
|
var equipPosition = new Int2(level, place);
|
|
var trainCandidate = new EquipTrainCandidate(equipPosition);
|
trainCandidate.trainLevel.value = GetTrainLevel(equipPosition);
|
trainCandidate.equipGuid.value = equipModel.GetEquip(equipPosition);
|
trainCandidate.starLevel.value = starModel.GetEquipStarLevel(equipPosition);
|
candidatePlaces.Add(trainCandidate);
|
}
|
|
candidatePlaces.Sort((EquipTrainCandidate x, EquipTrainCandidate y) =>
|
{
|
var stateX = GetEquipPlaceTrainState(x.equipPosition);
|
var stateY = GetEquipPlaceTrainState(y.equipPosition);
|
|
if (stateX == TrainState.Allowable && stateY != TrainState.Allowable)
|
{
|
return -1;
|
}
|
else if (stateX != TrainState.Allowable && stateY == TrainState.Allowable)
|
{
|
return 1;
|
}
|
else if (stateX == TrainState.Allowable && stateY == TrainState.Allowable)
|
{
|
return x.trainLevel.value.CompareTo(y.trainLevel.value);
|
}
|
else if (stateX == TrainState.StarLimit && stateY != TrainState.StarLimit)
|
{
|
return -1;
|
}
|
else if (stateX != TrainState.StarLimit && stateY == TrainState.StarLimit)
|
{
|
return 1;
|
}
|
else if (stateX == TrainState.Empty && stateY != TrainState.Empty)
|
{
|
return -1;
|
}
|
else if (stateX != TrainState.Empty && stateY == TrainState.Empty)
|
{
|
return 1;
|
}
|
else
|
{
|
return 0;
|
}
|
});
|
SelectPlace(candidatePlaces[0].equipPosition);
|
}
|
}
|
|
public void SelectPlace(Int2 equipPosition)
|
{
|
selectedPlace.value = equipPosition.y;
|
selectedPlace.dirty = true;
|
for (int i = 0; i < candidatePlaces.Count; i++)
|
{
|
var candidate = candidatePlaces[i];
|
candidate.selected.value = candidate.equipPosition == equipPosition;
|
}
|
|
var trainState = GetEquipPlaceTrainState(equipPosition);
|
equipTrainLevel.value = GetTrainLevel(equipPosition);
|
equipTrainMaxLevel.value = trainState == TrainState.Empty ? -1 : GetMaxTrainLevel(equipPosition);
|
equipTrainMaxLevel.dirty = true;
|
material.value = GetTrainMaterial(equipPosition);
|
|
operateType.value = CalculateTrainOperateType(equipPosition);
|
InitTrainableProperties(equipPosition, operateType.value);
|
UpdateTrainLimitState(equipPosition);
|
}
|
|
public void SetInevitable(int index, bool invevitable)
|
{
|
var equipPosition = new Int2(selectedLevel.value, selectedPlace.value);
|
var state = GetEquipPlaceTrainState(equipPosition);
|
|
var unsavedProperties = GetUnSavedProperties(equipPosition);
|
if (unsavedProperties != Int3.zero)
|
{
|
SysNotifyMgr.Instance.ShowTip("WashUnSavedTip");
|
return;
|
}
|
|
var maxLevel = GetMaxTrainLevel(equipPosition);
|
if (maxLevel < 1)
|
{
|
SysNotifyMgr.Instance.ShowTip("WashStarRequirement");
|
return;
|
}
|
|
if (state == TrainState.Empty)
|
{
|
SysNotifyMgr.Instance.ShowTip("Wash_NoEquip1");
|
return;
|
}
|
|
if (state == TrainState.StarLimit)
|
{
|
SysNotifyMgr.Instance.ShowTip("WashStarRequirement");
|
return;
|
}
|
|
if (invevitable)
|
{
|
var properties = GetTrainedProperties(equipPosition);
|
var type = GetTrainType(selectedPlace.value);
|
var trainLevel = GetTrainLevel(equipPosition);
|
var data = EquipWashConfig.Get(type, trainLevel);
|
var isPerfect = false;
|
switch (index)
|
{
|
case 0:
|
isPerfect = properties[index] >= data.config.attMax1;
|
break;
|
case 1:
|
isPerfect = properties[index] >= data.config.attMax2;
|
break;
|
case 2:
|
isPerfect = properties[index] >= data.config.attMax3;
|
break;
|
}
|
|
if (isPerfect)
|
{
|
SysNotifyMgr.Instance.ShowTip("WashOperateTip1");
|
return;
|
}
|
}
|
|
if (propertyBars.Count > index)
|
{
|
propertyBars[index].inevitable.value = invevitable;
|
}
|
|
inevitableMaterialCount.value = CalculateInevitableMaterialCount(equipPosition);
|
}
|
|
public int GetTrainLevel(Int2 equipPosition)
|
{
|
var equip = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equip))
|
{
|
return 0;
|
}
|
|
if (!equipTrains.ContainsKey(equipPosition.x))
|
{
|
return 0;
|
}
|
|
var maxLevel = GetMaxTrainLevel(equipPosition);
|
return Mathf.Min(maxLevel, equipTrains[equipPosition.x].GetTrainLevel(equipPosition.y));
|
}
|
|
public int GetTotalLevel(int level)
|
{
|
if (!equipTrains.ContainsKey(level))
|
{
|
return 0;
|
}
|
|
return equipTrains[level].GetTotalLevel();
|
}
|
|
public int GetMaterialNeed(Int2 equipPosition)
|
{
|
var level = GetTrainLevel(equipPosition);
|
var type = GetTrainType(equipPosition.y);
|
var data = EquipWashConfig.Get(type, level);
|
|
return data.config.costCount;
|
}
|
|
public int GetMaxTrainLevel(int place)
|
{
|
var type = GetTrainType(place);
|
return WashLevelMaxConfig.GetMaxLevel(type);
|
}
|
|
public int GetMaxTrainLevel(Int2 equipPosition)
|
{
|
var equip = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equip))
|
{
|
return 0;
|
}
|
|
var star = starModel.GetEquipStarLevel(equipPosition);
|
var type = GetTrainType(equipPosition.y);
|
var config = WashLevelMaxConfig.Get(type, star);
|
if (config == null)
|
{
|
return 0;
|
}
|
else
|
{
|
return config.levelMax;
|
}
|
}
|
|
public TrainState GetEquipPlaceTrainState(Int2 equipPosition)
|
{
|
var equipGuid = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equipGuid))
|
{
|
return TrainState.Empty;
|
}
|
|
var equip = packModel.GetItemByGuid(equipGuid);
|
if (equip == null)
|
{
|
return TrainState.Empty;
|
}
|
|
var type = GetTrainType(equipPosition.y);
|
var currentTrainLevel = GetTrainLevel(equipPosition);
|
var absoluteMax = GetMaxTrainLevel(equipPosition.y);
|
var data = EquipWashConfig.Get(type, Mathf.Clamp(currentTrainLevel, 1, absoluteMax));
|
if (data == null)
|
{
|
return TrainState.Empty;
|
}
|
|
var relativeMax = GetMaxTrainLevel(new Int2(equip.config.LV, equip.config.EquipPlace));
|
if (relativeMax == 0)
|
{
|
return TrainState.StarLimit;
|
}
|
|
var properties = GetTrainedProperties(equipPosition);
|
var isFull = properties.x >= data.config.attMax1
|
&& properties.y >= data.config.attMax2
|
&& properties.z >= data.config.attMax3;
|
if (isFull)
|
{
|
if (currentTrainLevel >= absoluteMax)
|
{
|
return TrainState.MaxLevel;
|
}
|
|
if (currentTrainLevel >= relativeMax)
|
{
|
return TrainState.StarLimit;
|
}
|
}
|
|
return TrainState.Allowable;
|
}
|
|
public Int3 GetUnSavedProperties(Int2 equipPosition)
|
{
|
return equipTrains.ContainsKey(equipPosition.x) ? equipTrains[equipPosition.x].GetUnSavedProperties(equipPosition.y) : Int3.zero;
|
}
|
|
public Int3 GetTrainedProperties(Int2 equipPosition)
|
{
|
var equip = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equip))
|
{
|
return Int3.zero;
|
}
|
|
if (!equipTrains.ContainsKey(equipPosition.x))
|
{
|
return Int3.zero;
|
}
|
|
var maxLevel = GetMaxTrainLevel(equipPosition);
|
var trainedProperties = equipTrains[equipPosition.x].GetTrainedProperties(equipPosition.y);
|
var type = GetTrainType(equipPosition.y);
|
var data = EquipWashConfig.Get(type, maxLevel);
|
|
var property1 = 0;
|
var property2 = 0;
|
var property3 = 0;
|
if (data != null)
|
{
|
property1 = Mathf.Min(trainedProperties.x, data.config.attMax1);
|
property2 = Mathf.Min(trainedProperties.y, data.config.attMax2);
|
property3 = Mathf.Min(trainedProperties.z, data.config.attMax3);
|
}
|
|
return new Int3(property1, property2, property3);
|
}
|
|
private List<int> GetTrainablePlaces(int level)
|
{
|
if (level <= 0)
|
{
|
return null;
|
}
|
|
var equipSet = equipModel.GetEquipSet(level);
|
if (equipSet == null)
|
{
|
return null;
|
}
|
|
var places = new List<int>();
|
for (var i = 1; i <= 12; i++)
|
{
|
var unLocked = equipSet.IsSlotUnLocked(i);
|
if (unLocked)
|
{
|
places.Add(i);
|
}
|
}
|
|
return places;
|
}
|
|
private void InitTrainableProperties(Int2 equipPosition, TrainOperateType operateType)
|
{
|
propertyBars.Clear();
|
var trainState = GetEquipPlaceTrainState(equipPosition);
|
var absoluteMax = GetMaxTrainLevel(equipPosition.y);
|
|
var unSavedProperties = GetUnSavedProperties(equipPosition);
|
var trainedProperties = GetTrainedProperties(equipPosition);
|
var trainLevel = GetTrainLevel(equipPosition);
|
var data = EquipWashConfig.Get(GetTrainType(equipPosition.y), Mathf.Clamp(trainLevel, 1, absoluteMax));
|
|
if (data != null)
|
{
|
var propertyBar = new EquipTrainPropertyBar(data.config.attType1, 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, 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, data.config.attMax3, trainState);
|
propertyBar.propertyValue.value = trainedProperties.z;
|
propertyBar.deltaValue.value = unSavedProperties.z;
|
propertyBar.operateType.value = operateType;
|
propertyBars.Add(propertyBar);
|
}
|
|
inevitableMaterialCount.value = CalculateInevitableMaterialCount(equipPosition);
|
}
|
|
private Int3 GetTrainMaterial(Int2 equipPosition)
|
{
|
if (GetEquipPlaceTrainState(equipPosition) == TrainState.Allowable)
|
{
|
var type = GetTrainType(equipPosition.y);
|
var level = GetTrainLevel(equipPosition);
|
var data = EquipWashConfig.Get(type, level);
|
var count = packModel.GetItemCountByID(PackType.Item, data.config.costItem);
|
var need = GetMaterialNeed(equipPosition);
|
return new Int3(data.config.costItem, count, need);
|
}
|
else
|
{
|
return Int3.zero;
|
}
|
}
|
|
public int GetInevitableMaterialPrice()
|
{
|
var config = StoreConfig.GetStoreCfg(GeneralDefine.equipTrainMustItemId, 1);
|
return config != null ? config.MoneyNumber : 0;
|
}
|
|
private int CalculateInevitableMaterialCount(Int2 equipPosition)
|
{
|
var count = 0;
|
for (int i = 0; i < propertyBars.Count; i++)
|
{
|
count += propertyBars[i].inevitable.value ? 1 : 0;
|
}
|
|
if (count > 0)
|
{
|
var type = GetTrainType(equipPosition.y);
|
var trainLevel = GetTrainLevel(equipPosition);
|
var config = EquipWashConfig.Get(type, trainLevel);
|
|
return config.mustCosts[count - 1];
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
|
private TrainOperateType CalculateTrainOperateType(Int2 equipPosition)
|
{
|
var trainState = GetEquipPlaceTrainState(equipPosition);
|
if (trainState == TrainState.StarLimit || trainState == TrainState.MaxLevel)
|
{
|
return TrainOperateType.Max;
|
}
|
|
var properties = GetTrainedProperties(equipPosition);
|
var equip = packModel.GetItemByGuid(equipModel.GetEquip(equipPosition));
|
if (equip == null)
|
{
|
return TrainOperateType.None;
|
}
|
|
var type = GetTrainType(equip.config.EquipPlace);
|
var trainLevel = GetTrainLevel(equipPosition);
|
|
var data = EquipWashConfig.Get(type, trainLevel);
|
if (properties.x >= data.config.attMax1 && properties.y >= data.config.attMax2 && properties.z >= data.config.attMax3)
|
{
|
return TrainOperateType.LevelUp;
|
}
|
|
var unSavedProperties = GetUnSavedProperties(equipPosition);
|
if (unSavedProperties != Int3.zero)
|
{
|
return TrainOperateType.Save;
|
}
|
|
if (trainState == TrainState.Allowable)
|
{
|
return TrainOperateType.Train;
|
}
|
|
return TrainOperateType.None;
|
}
|
|
private void UpdateTrainLimitState(Int2 equipPosition)
|
{
|
var type = GetTrainType(equipPosition.y);
|
var currentLevel = GetTrainLevel(equipPosition);
|
var data = EquipWashConfig.Get(type, currentLevel);
|
if (data == null)
|
{
|
trainLimit.value = false;
|
}
|
else
|
{
|
var properties = GetTrainedProperties(equipPosition);
|
var isFull = properties.x >= data.config.attMax1
|
&& properties.y >= data.config.attMax2
|
&& properties.z >= data.config.attMax3;
|
|
var trainState = GetEquipPlaceTrainState(equipPosition);
|
trainLimit.value = isFull && (trainState == TrainState.StarLimit || trainState == TrainState.MaxLevel);
|
}
|
}
|
|
private void ParseConfig()
|
{
|
var config = FuncConfigConfig.Get("EquipWashGroup");
|
trainTypes = ConfigParse.GetDic<int, int>(config.Numerical1);
|
}
|
|
public static int GetTrainType(int place)
|
{
|
return trainTypes.ContainsKey(place) ? trainTypes[place] : 0;
|
}
|
|
public enum TrainOperateType
|
{
|
None = 0,
|
Train = 1,
|
Forbid = 2,
|
Save = 3,
|
LevelUp = 4,
|
Max = 5,
|
}
|
|
public enum TrainState
|
{
|
Empty,
|
StarLimit,
|
MaxLevel,
|
Allowable,
|
}
|
}
|
}
|