using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System;
|
|
namespace vnxbqy.UI
|
{
|
|
public class EquipTrainModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize
|
{
|
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();
|
public readonly LogicInt trainEffect = new LogicInt();
|
|
static Dictionary<int, int> trainTypes = new Dictionary<int, int>();
|
Dictionary<int, EquipTrainSet> equipTrains = new Dictionary<int, EquipTrainSet>();
|
|
Redpoint redpoint = new Redpoint(106, 910000);
|
bool redpointDirty = false;
|
LogicUpdate logicUpdate = new LogicUpdate(1);
|
|
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 bool autoTrain = false;
|
|
public int limitLevel;
|
|
public override void Init()
|
{
|
ParseConfig();
|
|
var levels = equipModel.GetAllEquipSets();
|
foreach (var level in levels)
|
{
|
if (level < limitLevel) continue;
|
equipTrains[level] = new EquipTrainSet(level);
|
}
|
|
logicUpdate.Start(OnUpdate);
|
|
packModel.refreshItemCountEvent += OnItemCountRefresh;
|
autoTrain = false;
|
}
|
|
public override void UnInit()
|
{
|
packModel.refreshItemCountEvent -= OnItemCountRefresh;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
foreach (var train in equipTrains.Values)
|
{
|
train.Reset();
|
}
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
redpointDirty = true;
|
}
|
|
public void ResetOperateParams()
|
{
|
selectedLevel.value = 0;
|
selectedPlace.value = 0;
|
equipTrainLevel.value = 0;
|
equipTrainMaxLevel.value = 0;
|
material.value = Int3.zero;
|
inevitableMaterialCount.value = 0;
|
trainEffect.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);
|
}
|
}
|
|
redpointDirty = true;
|
}
|
|
|
public void Train(Int2 equipPosition, bool[] inevitables)
|
{
|
var maxLevel = GetMaxTrainLevel(equipPosition);
|
if (maxLevel < 0)
|
{
|
SysNotifyMgr.Instance.ShowTip("WashStarRequirement");
|
return;
|
}
|
|
var material = GetTrainMaterial(equipPosition);
|
if (material.z > material.y)
|
{
|
|
SysNotifyMgr.Instance.ShowTip("WashStone1");
|
return;
|
}
|
|
LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(3, material.x, material.z, 1, 0);
|
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;
|
}
|
|
Action processTrain = () =>
|
{
|
trainEffect.dirty = true;
|
trainEffect.value = code > 0 ? 2 : 1;
|
|
var equipWash = new CA325_tagCMEquipXLAttrChange();
|
equipWash.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition);
|
equipWash.CheckUseGoldAttr = (byte)code;
|
GameNetSystem.Instance.SendInfo(equipWash);
|
autoTrain = true;
|
|
};
|
|
if (inevitableCount == 0)
|
{
|
processTrain();
|
return;
|
}
|
|
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);
|
|
if (inevitableOwn >= inevitableNeed)
|
{
|
processTrain();
|
return;
|
}
|
|
var diamondNeed = (inevitableNeed - inevitableOwn) * GetInevitableMaterialPrice();
|
var diamondOwn = PlayerDatas.Instance.baseData.diamond;
|
LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(52, 1, diamondNeed, 2, 0);
|
|
if (diamondNeed > diamondOwn)
|
{
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
return;
|
}
|
if (DayRemind.Instance.GetDayRemind(DayRemind.EQUIPTRAIN_COSTDIAMOND))
|
{
|
processTrain();
|
return;
|
}
|
autoTrain = false;
|
ConfirmCancel.ToggleConfirmCancel(Language.Get("Mail101"),
|
Language.Get("EquipWash103", inevitableNeed - inevitableOwn, diamondNeed),
|
Language.Get("TodayNoNotify"), (bool ok, bool isToggle) =>
|
{
|
|
if (ok)
|
{
|
processTrain();
|
}
|
if (isToggle)
|
{
|
DayRemind.Instance.SetDayRemind(DayRemind.EQUIPTRAIN_COSTDIAMOND, true);
|
}
|
else
|
{
|
autoTrain = false;
|
}
|
});
|
|
}
|
|
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;
|
selectedLevel.dirty = true;
|
candidatePlaces.Clear();
|
|
if (level > 0)
|
{
|
for (var i = 1; i <= 12; i++)
|
{
|
var place = 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(EquipTrainCandidateCompare);
|
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 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 < 0)
|
{
|
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);
|
inevitableMaterialCount.dirty = true; //相同值不改变的情况下无法刷新 会是锁定状态
|
}
|
|
public Int2 GetRecommendEquipPosition()
|
{
|
foreach (var trainSet in equipTrains.Values)
|
{
|
var level = trainSet.level;
|
for (var i = 1; i <= 12; i++)
|
{
|
var isRedpoint = trainSet.GetRedpointState(i) != RedPointState.None;
|
if (isRedpoint)
|
{
|
return new Int2(level, i);
|
}
|
}
|
}
|
|
return new Int2(limitLevel, 1);
|
}
|
|
public int GetTrainLevel(Int2 equipPosition)
|
{
|
var equip = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equip))
|
{
|
return -1;
|
}
|
|
if (!equipTrains.ContainsKey(equipPosition.x))
|
{
|
return -1;
|
}
|
|
var maxLevel = GetMaxTrainLevel(equipPosition);
|
return Mathf.Min(maxLevel, equipTrains[equipPosition.x].GetTrainLevel(equipPosition.y));
|
}
|
|
public int GetTrainLevelEx(Int2 equipPosition)
|
{
|
var equip = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equip))
|
{
|
return 0;
|
}
|
|
if (!equipTrains.ContainsKey(equipPosition.x))
|
{
|
return 0;
|
}
|
|
return equipTrains[equipPosition.x].GetTrainLevel(equipPosition.y);
|
}
|
|
|
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 -1;
|
}
|
|
var star = starModel.GetEquipStarLevel(equipPosition);
|
var type = GetTrainType(equipPosition.y);
|
var config = WashLevelMaxConfig.Get(type, star);
|
if (config == null)
|
{
|
return -1;
|
}
|
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, 0, absoluteMax));
|
if (data == null)
|
{
|
return TrainState.Empty;
|
}
|
|
var relativeMax = GetMaxTrainLevel(new Int2(equip.config.LV, equip.config.EquipPlace));
|
if (relativeMax == -1)
|
{
|
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 void InitTrainableProperties(Int2 equipPosition, TrainOperateType operateType)
|
{
|
//此段代码特殊处理,因为 propertyBars.Clear();
|
bool ison1 = false;
|
bool ison2 = false;
|
bool ison3 = false;
|
if (propertyBars.Count == 3)
|
{
|
ison1 = propertyBars[0].inevitable.value;
|
ison2 = propertyBars[1].inevitable.value;
|
ison3 = propertyBars[2].inevitable.value;
|
}
|
///=============================
|
|
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, 0, absoluteMax));
|
|
if (data != null)
|
{
|
var propertyBar = new EquipTrainPropertyBar(data.config.attType1, data.config.attMax1, data.config.attCostMoney1, trainState);
|
propertyBar.propertyValue.value = trainedProperties.x;
|
propertyBar.deltaValue.value = unSavedProperties.x;
|
propertyBar.operateType.value = operateType;
|
propertyBar.inevitable.value = ison1;
|
propertyBars.Add(propertyBar);
|
|
propertyBar = new EquipTrainPropertyBar(data.config.attType2, data.config.attMax2, data.config.attCostMoney2, trainState);
|
propertyBar.propertyValue.value = trainedProperties.y;
|
propertyBar.deltaValue.value = unSavedProperties.y;
|
propertyBar.operateType.value = operateType;
|
propertyBar.inevitable.value = ison2;
|
propertyBars.Add(propertyBar);
|
|
propertyBar = new EquipTrainPropertyBar(data.config.attType3, data.config.attMax3, data.config.attCostMoney3, trainState);
|
propertyBar.propertyValue.value = trainedProperties.z;
|
propertyBar.deltaValue.value = unSavedProperties.z;
|
propertyBar.operateType.value = operateType;
|
propertyBar.inevitable.value = ison3;
|
propertyBars.Add(propertyBar);
|
}
|
|
inevitableMaterialCount.value = CalculateInevitableMaterialCount(equipPosition);
|
inevitableMaterialCount.dirty = true; //相同值不改变的情况下无法刷新 会是锁定状态
|
}
|
|
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);
|
if (config == null)
|
return 0;
|
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 OnItemCountRefresh(PackType type, int index, int itemId)
|
{
|
switch (type)
|
{
|
case PackType.Item:
|
if (itemId == 5303)
|
{
|
redpointDirty = true;
|
}
|
break;
|
case PackType.Equip:
|
var clientEquipPosition = EquipSet.ServerPlaceToClientPlace(index);
|
if (clientEquipPosition.x > 0)
|
{
|
redpointDirty = true;
|
}
|
break;
|
}
|
}
|
|
private void UpdateTrainRedpoint()
|
{
|
var ownTrainMaterial = packModel.GetItemCountByID(PackType.Item, 5303);
|
var targetEquipPosition = Int2.zero;
|
if (ownTrainMaterial != 0)
|
{
|
var minTrainLevel = 999;
|
foreach (var trainSet in equipTrains.Values)
|
{
|
var level = trainSet.level;
|
for (var i = 1; i <= 12; i++)
|
{
|
var trainState = GetEquipPlaceTrainState(new Int2(level, i));
|
if (trainState != TrainState.Allowable)
|
{
|
continue;
|
}
|
|
var needMaterial = GetMaterialNeed(new Int2(level, i));
|
if (needMaterial > ownTrainMaterial)
|
{
|
continue;
|
}
|
|
var tranLevel = trainSet.GetTrainLevel(i);
|
if (tranLevel < minTrainLevel)
|
{
|
minTrainLevel = tranLevel;
|
targetEquipPosition = new Int2(level, i);
|
}
|
}
|
}
|
}
|
|
foreach (var trainSet in equipTrains.Values)
|
{
|
var level = trainSet.level;
|
for (var i = 1; i <= 12; i++)
|
{
|
var isRedpoint = level == targetEquipPosition.x && i == targetEquipPosition.y;
|
trainSet.UpdateRedpoint(i, isRedpoint ? RedPointState.Simple : RedPointState.None);
|
}
|
}
|
|
}
|
|
private void OnUpdate()
|
{
|
if (redpointDirty && FuncOpen.Instance.IsFuncOpen(91))
|
{
|
redpointDirty = false;
|
UpdateTrainRedpoint();
|
}
|
}
|
|
private int EquipTrainCandidateCompare(EquipTrainCandidate x, EquipTrainCandidate y)
|
{
|
var stateX = GetEquipPlaceTrainState(x.equipPosition);
|
var stateY = GetEquipPlaceTrainState(y.equipPosition);
|
|
if (stateX == TrainState.Allowable && stateY != TrainState.Allowable)
|
{
|
return -1;
|
}
|
|
if (stateX != TrainState.Allowable && stateY == TrainState.Allowable)
|
{
|
return 1;
|
}
|
|
if (stateX == TrainState.Allowable && stateY == TrainState.Allowable)
|
{
|
var compareResult = x.trainLevel.value.CompareTo(y.trainLevel.value);
|
if (compareResult == 0)
|
{
|
var factorX = x.equipPosition.x * 100 + x.equipPosition.y;
|
var factorY = y.equipPosition.x * 100 + y.equipPosition.y;
|
compareResult = factorX.CompareTo(factorY);
|
}
|
|
return compareResult;
|
}
|
|
if (stateX == TrainState.StarLimit && stateY != TrainState.StarLimit)
|
{
|
return -1;
|
}
|
else if (stateX != TrainState.StarLimit && stateY == TrainState.StarLimit)
|
{
|
return 1;
|
}
|
else if (stateX == TrainState.MaxLevel && stateY != TrainState.MaxLevel)
|
{
|
return -1;
|
}
|
else if (stateX != TrainState.MaxLevel && stateY == TrainState.MaxLevel)
|
{
|
return 1;
|
}
|
else if (stateX == TrainState.Empty && stateY != TrainState.Empty)
|
{
|
return -1;
|
}
|
else if (stateX != TrainState.Empty && stateY == TrainState.Empty)
|
{
|
return 1;
|
}
|
else
|
{
|
return x.equipPosition.y.CompareTo(y.equipPosition.y);
|
}
|
}
|
|
private void ParseConfig()
|
{
|
var config = FuncConfigConfig.Get("EquipWashGroup");
|
trainTypes = ConfigParse.GetDic<int, int>(config.Numerical1);
|
|
if (equipModel.EquipLevelFuncID == null)
|
equipModel.ParseEquipLevelFuncID();
|
limitLevel = equipModel.EquipLevelFuncID[91];
|
}
|
|
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,
|
}
|
}
|
}
|