using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System.Linq;
|
|
namespace Snxxz.UI
|
{
|
public class EquipStarModel : Model
|
{
|
public readonly LogicString selectedEquip = new LogicString();
|
public readonly LogicInt equipStarLevel = new LogicInt();
|
public readonly LogicInt operateMaterialIndex = new LogicInt();
|
public readonly Dictionary<int, LogicString> materials = new Dictionary<int, LogicString>();
|
public readonly LogicInt starUpgradeProbability = new LogicInt();
|
|
Dictionary<int, EquipSetStar> equipStars = new Dictionary<int, EquipSetStar>();
|
Dictionary<string, CandidateEquip> candidateEquips = new Dictionary<string, CandidateEquip>();
|
Dictionary<int, int> maxStarLevels = new Dictionary<int, int>();
|
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
|
|
public override void Init()
|
{
|
ParseConfig();
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
public void DoStarUpgrade(int level, int place, int starLevel)
|
{
|
if (!equipStars.ContainsKey(level))
|
{
|
return;
|
}
|
|
var maxLevel = GetMaxStarLevel(level);
|
if (starLevel > maxLevel)
|
{
|
//已经是最大星级,无法升星
|
return;
|
}
|
|
var config = EquipStarConfig.Get(level, place, starLevel);
|
var specialMaterial = packModel.GetItemByGuid(materials[6].value);
|
if (config.CostItemDict.x > 0 && (specialMaterial == null || specialMaterial.config.ID != config.CostItemDict.x))
|
{
|
//请放入正确的特殊材料
|
return;
|
}
|
|
var materialIndexs = new List<ushort>();
|
var materialItemIds = new List<uint>();
|
foreach (var material in materials.Values)
|
{
|
if (!string.IsNullOrEmpty(material.value))
|
{
|
var item = packModel.GetItemByGuid(material.value);
|
materialIndexs.Add((ushort)item.itemPlace);
|
materialItemIds.Add((uint)item.itemId);
|
}
|
}
|
|
if (materialIndexs.Count < (config.CostEquipCnt + config.CostItemDict.x > 0 ? 1 : 0))
|
{
|
//材料不足
|
return;
|
}
|
|
var info = new CA5C5_tagCMEquipPartStarUp();
|
info.EquipPackIndex = (ushort)EquipSet.ClientPlaceToServerPlace(level, place);
|
info.CostEquipIndex = materialIndexs.ToArray();
|
info.CostEquipID = materialItemIds.ToArray();
|
info.CostEquipCnt = (byte)materialIndexs.Count;
|
|
GameNetSystem.Instance.SendInfo(info);
|
}
|
|
public void FiltrateCandidateEquips(int level)
|
{
|
candidateEquips.Clear();
|
var equips = GetStarUpgradableEquips(level);
|
for (var i = 0; i < equips.Count; i++)
|
{
|
var guid = equips[i];
|
candidateEquips[guid] = new CandidateEquip(guid);
|
|
if (i == 0)
|
{
|
SelectTargetEquip(guid);
|
}
|
}
|
}
|
|
public void UpdateStarLevels(HA3B1_tagMCEquipPartStarInfo info)
|
{
|
for (var i = 0; i < info.InfoList.Length; i++)
|
{
|
var clientInfo = EquipSet.ServerPlaceToClientPlace(info.InfoList[i].EquipPackIndex);
|
var level = clientInfo.x;
|
if (equipStars.ContainsKey(level))
|
{
|
equipStars[level].UpdateEquipStarLevel(clientInfo.y, info.InfoList[i].Star);
|
}
|
}
|
}
|
|
public int GetSuitLevel(int level, EquipSuitType type)
|
{
|
if (!equipStars.ContainsKey(level))
|
{
|
return 0;
|
}
|
|
return equipStars[level].GetSuitLevel(type);
|
}
|
|
private List<string> GetStarUpgradableEquips(int level)
|
{
|
var equipSet = equipModel.GetEquipSet(level);
|
if (equipSet == null)
|
{
|
return null;
|
}
|
|
var equips = new List<string>();
|
for (var i = 1; i <= 12; i++)
|
{
|
var equipGuid = equipSet.GetEquip(i);
|
if (!string.IsNullOrEmpty(equipGuid))
|
{
|
equips.Add(equipGuid);
|
}
|
}
|
|
return equips;
|
}
|
|
public List<string> GetCandidateEquips()
|
{
|
return new List<string>(candidateEquips.Keys);
|
}
|
|
public CandidateEquip GetCandidateEquip(string equipGuid)
|
{
|
if (candidateEquips.ContainsKey(equipGuid))
|
{
|
return candidateEquips[equipGuid];
|
}
|
else
|
{
|
return null;
|
}
|
}
|
|
public void SelectTargetEquip(string equipGuid)
|
{
|
selectedEquip.value = equipGuid;
|
foreach (var candidate in candidateEquips.Values)
|
{
|
candidate.selected.value = candidate.guid == equipGuid;
|
}
|
|
var item = packModel.GetItemByGuid(equipGuid);
|
if (item != null)
|
{
|
equipStarLevel.value = GetEquipStarLevel(item.config.LV, item.config.EquipPlace);
|
}
|
}
|
|
public int GetMaxStarLevel(int level)
|
{
|
if (maxStarLevels.ContainsKey(level))
|
{
|
return maxStarLevels[level];
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
|
public int GetTotalStarLevel(int level)
|
{
|
if (!equipStars.ContainsKey(level))
|
{
|
return 0;
|
}
|
|
return equipStars[level].GetTotalStarLevel();
|
}
|
|
public int GetEquipStarLevel(int level, int place)
|
{
|
if (!equipStars.ContainsKey(level))
|
{
|
return 0;
|
}
|
|
return equipStars[level].GetEquipStarLevel(place);
|
}
|
|
public int GetEquipCountWhichStarLevelLq(int level, int standard)
|
{
|
if (!equipStars.ContainsKey(level))
|
{
|
return 0;
|
}
|
|
return equipStars[level].GetEquipCountWhichStarLevelLq(standard);
|
}
|
|
public List<ItemModel> GetMaterials(int level, int place, int starLevel)
|
{
|
var config = EquipStarConfig.Get(level, place, starLevel);
|
if (config == null)
|
{
|
return null;
|
}
|
|
var equipGuid = equipModel.GetEquipSet(level).GetEquip(place);
|
var equip = packModel.GetItemByGuid(equipGuid);
|
if (equip == null)
|
{
|
return null;
|
}
|
|
var expcetMaterials = packModel.GetItems(new SinglePack.FilterParams()
|
{
|
level = 0,
|
quality = 0,
|
equipType = 0,
|
itemType = 0
|
});
|
|
for (var i = expcetMaterials.Count - 1; i >= 0; i--)
|
{
|
var item = expcetMaterials[i];
|
if (item.config.RealmLimit != equip.config.RealmLimit)
|
{
|
expcetMaterials.RemoveAt(i);
|
}
|
else if (!config.CostEquipPlace.Contains(item.config.EquipPlace))
|
{
|
expcetMaterials.RemoveAt(i);
|
}
|
else if (!config.CostEquipColor.Contains(item.config.ItemColor))
|
{
|
expcetMaterials.RemoveAt(i);
|
}
|
}
|
|
for (var i = 1; i <= 6; i++)
|
{
|
var placedMaterialGuid = GetMaterialLogicStringByIndex(i).value;
|
var materialItem = packModel.GetItemByGuid(placedMaterialGuid);
|
if (materialItem != null)
|
{
|
expcetMaterials.Remove(materialItem);
|
}
|
}
|
|
return expcetMaterials;
|
}
|
|
public void AddMaterial(int index, string itemGuid)
|
{
|
GetMaterialLogicStringByIndex(index).value = itemGuid;
|
}
|
|
public void RemoveMaterial(int index)
|
{
|
GetMaterialLogicStringByIndex(index).value = string.Empty;
|
}
|
|
private void CalculateStarUpgradeProbability()
|
{
|
var probability = 0f;
|
var selectedItem = packModel.GetItemByGuid(selectedEquip.value);
|
var config = EquipStarConfig.Get(selectedItem.config.LV, selectedItem.config.EquipPlace, equipStarLevel.value + 1);
|
var singleItemRate = (float)config.SuitTotalRate / config.CostEquipCnt;
|
for (var i = 1; i <= 5; i++)
|
{
|
var itemGuid = GetMaterialLogicStringByIndex(i).value;
|
var item = packModel.GetItemByGuid(itemGuid);
|
probability += item.config.SuiteiD > 0 ? singleItemRate : singleItemRate * 0.5f;
|
}
|
|
starUpgradeProbability.value = Mathf.RoundToInt(probability * 100);
|
}
|
|
public LogicString GetMaterialLogicStringByIndex(int index)
|
{
|
return materials.ContainsKey(index - 1) ? materials[index - 1] : null;
|
}
|
|
private void ParseConfig()
|
{
|
var configs = EquipStarConfig.GetValues();
|
foreach (var config in configs)
|
{
|
var currentStar = materials.ContainsKey(config.Level) ? maxStarLevels[config.Level] : 0;
|
if (currentStar > config.Star)
|
{
|
maxStarLevels[config.Level] = config.Star;
|
}
|
}
|
|
}
|
|
}
|
}
|