using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System;
|
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class EquipModel : Model
|
{
|
public int showedUnLockLevel {
|
get { return LocalSave.GetInt(StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "EquipSetUnLockHasShowed"), 1); }
|
set { LocalSave.SetInt(StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "EquipSetUnLockHasShowed"), value); }
|
}
|
|
public int showedUnLockSlot {
|
get { return LocalSave.GetInt(StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "EquipSlotUnLockHasShowed"), 1); }
|
set { LocalSave.SetInt(StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "EquipSlotUnLockHasShowed"), value); }
|
}
|
|
public readonly LogicInt selectedLevel = new LogicInt();
|
public readonly LogicInt selectedPlace = new LogicInt();
|
public readonly LogicString selectedEquip = new LogicString();
|
public readonly LogicInt selectedStarLevel = new LogicInt();
|
public readonly LogicStruct<EquipAppearance> appearance = new LogicStruct<EquipAppearance>();
|
public readonly LogicList<CandidateEquip> candidateEquips = new LogicList<CandidateEquip>();
|
|
Dictionary<int, EquipSet> equipSets = new Dictionary<int, EquipSet>();
|
List<int> sortedLevels = new List<int>();
|
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
EquipStarModel starModel { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
|
|
public event Action appearanceChangeEvent;
|
|
public override void Init()
|
{
|
ParseConfig();
|
packModel.refrechPackEvent += OnItemPackRefresh;
|
packModel.refreshItemCountEvent += OnItemCountRefresh;
|
PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefresh;
|
}
|
|
public override void UnInit()
|
{
|
packModel.refrechPackEvent -= OnItemPackRefresh;
|
packModel.refreshItemCountEvent -= OnItemCountRefresh;
|
PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefresh;
|
}
|
|
public int GetLastestUnLockEquipSet()
|
{
|
for (int i = sortedLevels.Count - 1; i >= 0; i--)
|
{
|
var level = sortedLevels[i];
|
if (equipSets[level].unLocked)
|
{
|
return level;
|
}
|
}
|
|
return 1;
|
}
|
|
public void SelectSet(int level, int place)
|
{
|
selectedLevel.value = level;
|
selectedPlace.value = place;
|
if (selectedLevel.dirty)
|
{
|
selectedPlace.dirty = true;
|
selectedStarLevel.value = 0;
|
selectedStarLevel.dirty = true;
|
|
appearance.value = GetAppearance(selectedLevel.value);
|
}
|
|
if (selectedLevel.dirty || selectedPlace.dirty)
|
{
|
selectedEquip.value = string.Empty;
|
RefreshCandidateEquips(selectedLevel.value, selectedPlace.value);
|
}
|
|
foreach (var item in equipSets.Values)
|
{
|
item.selected.value = item.level == selectedLevel.value;
|
}
|
|
if (equipSets.ContainsKey(level))
|
{
|
equipSets[level].SelectPlace(place);
|
}
|
}
|
|
public void ResetOperateParams()
|
{
|
selectedLevel.value = 0;
|
selectedPlace.value = 0;
|
selectedEquip.value = string.Empty;
|
selectedStarLevel.value = 0;
|
appearance.value = default(EquipAppearance);
|
candidateEquips.Clear();
|
}
|
|
private void RefreshCandidateEquips(int level, int place)
|
{
|
candidateEquips.Clear();
|
var items = packModel.GetItems(PackType.Item, new SinglePack.FilterParams()
|
{
|
levels = level == 0 ? null : new List<int>() { level },
|
equipTypes = place == 0 ? new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } : new List<int>() { place }
|
});
|
|
if (items != null)
|
{
|
foreach (var item in items)
|
{
|
if (!item.isAuction)
|
{
|
candidateEquips.Add(new CandidateEquip(item.guid));
|
}
|
}
|
}
|
}
|
|
public void SelectCandidateEquip(string equipGuid)
|
{
|
for (int i = 0; i < candidateEquips.Count; i++)
|
{
|
var candidateEquip = candidateEquips[i];
|
candidateEquip.selected.value = candidateEquip.guid == equipGuid;
|
}
|
}
|
|
public List<int> GetAllEquipSets()
|
{
|
return new List<int>(equipSets.Keys);
|
}
|
|
public List<int> GetViewableEquipSets()
|
{
|
var sets = new List<int>();
|
var index = 0;
|
for (index = 0; index < sortedLevels.Count; index++)
|
{
|
var level = sortedLevels[index];
|
var set = equipSets[level];
|
if (set.unLocked)
|
{
|
sets.Add(set.level);
|
}
|
else
|
{
|
break;
|
}
|
}
|
|
if (index <= sortedLevels.Count - 1)
|
{
|
sets.Add(equipSets[sortedLevels[index]].level);
|
}
|
|
return sets;
|
}
|
|
public List<int> GetUnLockedEquipSets()
|
{
|
var sets = new List<int>();
|
for (var i = 0; i < sortedLevels.Count; i++)
|
{
|
var level = sortedLevels[i];
|
var set = equipSets[level];
|
if (set.unLocked)
|
{
|
sets.Add(set.level);
|
}
|
else
|
{
|
break;
|
}
|
}
|
|
return sets;
|
}
|
|
public EquipSet GetEquipSet(int level)
|
{
|
if (!equipSets.ContainsKey(level))
|
{
|
return null;
|
}
|
|
return equipSets[level];
|
}
|
|
public string GetEquip(int level, int place)
|
{
|
var set = GetEquipSet(level);
|
if (set == null)
|
{
|
return string.Empty;
|
}
|
|
return set.GetEquip(place);
|
}
|
|
public bool IsDressedInSuit(int level, int place)
|
{
|
var equipGuid = GetEquip(level, place);
|
var equip = packModel.GetItemByGuid(equipGuid);
|
return equip != null && equip.config.SuiteiD > 0;
|
}
|
|
public void SetAppearance(int level)
|
{
|
if (!equipSets.ContainsKey(level))
|
{
|
return;
|
}
|
|
var pak = new C032F_tagCRequestEquipShowHide();
|
pak.EquipShowSwitch = (uint)(level * 10 + GetSuitLevel(level, EquipSuitType.EightSuit) >= 0 ? 1 : 0);
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
public EquipAppearance GetAppearance()
|
{
|
var level = PlayerDatas.Instance.baseData.equipShowSwitch / 10;
|
var isSuit = PlayerDatas.Instance.baseData.equipShowSwitch % 10 > 0;
|
|
var appearance = GetAppearance((int)level);
|
appearance.isSuit = isSuit;
|
return appearance;
|
}
|
|
public EquipAppearance GetAppearance(int level)
|
{
|
if (!equipSets.ContainsKey(level))
|
{
|
return default(EquipAppearance);
|
}
|
|
var appearance = equipSets[level].GetAppearance();
|
|
var wings = packModel.GetItemByIndex(PackType.Equip, EquipSet.ClientPlaceToServerPlace(0, (int)RoleEquipType.Wing));
|
appearance.wings = wings == null ? 0 : wings.itemId;
|
|
var mount = packModel.GetItemByIndex(PackType.Equip, EquipSet.ClientPlaceToServerPlace(0, (int)RoleEquipType.Mount));
|
appearance.mount = mount == null ? 0 : mount.itemId;
|
|
var guard1 = packModel.GetItemByIndex(PackType.Equip, EquipSet.ClientPlaceToServerPlace(0, (int)RoleEquipType.Guard1));
|
appearance.guard1 = guard1 == null ? 0 : guard1.itemId;
|
|
var guard2 = packModel.GetItemByIndex(PackType.Equip, EquipSet.ClientPlaceToServerPlace(0, (int)RoleEquipType.Guard2));
|
appearance.guard2 = guard2 == null ? 0 : guard2.itemId;
|
|
var fashionClothes = packModel.GetItemByIndex(PackType.Equip, EquipSet.ClientPlaceToServerPlace(0, (int)RoleEquipType.FashionClothes));
|
appearance.fashionClothes = fashionClothes == null ? 0 : fashionClothes.itemId;
|
|
var fashWeapon = packModel.GetItemByIndex(PackType.Equip, EquipSet.ClientPlaceToServerPlace(0, (int)RoleEquipType.FashionWeapon));
|
appearance.mount = fashWeapon == null ? 0 : fashWeapon.itemId;
|
|
var fashionSecondary = packModel.GetItemByIndex(PackType.Equip, EquipSet.ClientPlaceToServerPlace(0, (int)RoleEquipType.FashionWeapon2));
|
appearance.fashionSecondary = fashionSecondary == null ? 0 : fashionSecondary.itemId;
|
|
return appearance;
|
}
|
|
public int GetSuitLevel(int level, EquipSuitType type)
|
{
|
if (!equipSets.ContainsKey(level))
|
{
|
return -1;
|
}
|
|
var targetCount = (int)type;
|
var maxLevel = starModel.GetTotalStarLevel(level) / targetCount;
|
for (var targetStar = maxLevel; targetStar >= 0; targetStar--)
|
{
|
var count = 0;
|
for (int place = 1; place <= 8; place++)
|
{
|
var isSuit = IsDressedInSuit(level, place);
|
var star = starModel.GetEquipStarLevel(level, place);
|
if (isSuit && star >= targetStar)
|
{
|
count++;
|
if (count >= targetCount)
|
{
|
return targetStar;
|
}
|
}
|
}
|
}
|
|
return -1;
|
}
|
|
public int GetFightPoint(int level)
|
{
|
if (!equipSets.ContainsKey(level))
|
{
|
return 0;
|
}
|
|
return equipSets[level].GetFightPoint();
|
}
|
|
public List<int> GetGetWays(int level, int place)
|
{
|
if (level == 0)
|
{
|
return null;
|
}
|
|
if (place != 0)
|
{
|
var config = EquipControlConfig.Get(level, place);
|
return new List<int>(config.getWays);
|
}
|
else
|
{
|
var getWays = new List<int>();
|
for (int i = 1; i <= 12; i++)
|
{
|
var config = EquipControlConfig.Get(level, i);
|
foreach (int getWay in config.getWays)
|
{
|
if (!getWays.Contains(getWay))
|
{
|
getWays.Add(getWay);
|
}
|
}
|
}
|
|
return getWays;
|
}
|
}
|
|
public void PutOn(string equipGuid)
|
{
|
var item = packModel.GetItemByGuid(equipGuid);
|
if (item == null)
|
{
|
return;
|
}
|
|
var level = item.config.LV;
|
if (!equipSets.ContainsKey(level))
|
{
|
return;
|
}
|
|
var set = equipSets[level];
|
if (!set.unLocked)
|
{
|
return;
|
}
|
|
set.PutOn(equipGuid);
|
}
|
|
public void TakeOff(int level, int place)
|
{
|
if (!equipSets.ContainsKey(level))
|
{
|
return;
|
}
|
|
var slot = equipSets[level];
|
slot.TakeOff(place);
|
}
|
|
public int CompareToCurrent(string equipGuid)
|
{
|
var item = packModel.GetItemByGuid(equipGuid);
|
if (item == null)
|
{
|
return 0;
|
}
|
|
var level = item.config.LV;
|
if (!equipSets.ContainsKey(level))
|
{
|
return 0;
|
}
|
|
var set = equipSets[level];
|
return set.CompareToCurrent(equipGuid);
|
}
|
|
public EquipSuitPropertyEntry GetEquipSuitEntry(int level, int star, EquipSuitType type)
|
{
|
var configs = EquipSuitConfig.GetConfigs(PlayerDatas.Instance.baseData.Job, level, type);
|
var suitLevel = GetSuitLevel(level, type);
|
var actived = suitLevel >= star;
|
var properties = new List<Int2>();
|
foreach (var item in configs)
|
{
|
if (item.star == star)
|
{
|
properties.AddRange(item.attr);
|
break;
|
}
|
}
|
|
var entry = new EquipSuitPropertyEntry()
|
{
|
actived = actived,
|
type = type,
|
properties = properties
|
};
|
|
return entry;
|
}
|
|
private void OnPlayerDataRefresh(PlayerDataType type)
|
{
|
switch (type)
|
{
|
case PlayerDataType.RealmLevel:
|
var lastUnLockRealm = 1;
|
UpdateRedpoint(lastUnLockRealm);
|
break;
|
default:
|
break;
|
}
|
}
|
|
private void OnItemPackRefresh(PackType type)
|
{
|
switch (type)
|
{
|
case PackType.Item:
|
UpdateRedpoints();
|
break;
|
case PackType.Equip:
|
foreach (var set in equipSets.Values)
|
{
|
for (var i = 1; i <= 12; i++)
|
{
|
set.UpdateEquipSlot(i, string.Empty);
|
}
|
}
|
|
var items = packModel.GetItems(PackType.Equip, new SinglePack.FilterParams() { });
|
foreach (var item in items)
|
{
|
var clientPlace = EquipSet.ServerPlaceToClientPlace(item.gridIndex);
|
equipSets[clientPlace.x].UpdateEquipSlot(clientPlace.y, item.guid);
|
}
|
|
if (selectedLevel.value > 0)
|
{
|
appearance.value = GetAppearance(selectedLevel.value);
|
RefreshCandidateEquips(selectedLevel.value, selectedPlace.value);
|
}
|
break;
|
default:
|
break;
|
}
|
}
|
|
private void OnItemCountRefresh(PackType type, int index, int itemId)
|
{
|
var dirty = false;
|
switch (type)
|
{
|
case PackType.Item:
|
var config = ItemConfig.Get(itemId);
|
var level = config.LV;
|
if (equipSets.ContainsKey(level))
|
{
|
var item = packModel.GetItemByIndex(PackType.Item, index);
|
if (item != null)
|
{
|
equipSets[level].UpdateRedPoint(item.guid);
|
}
|
|
if (selectedLevel.value > 0)
|
{
|
dirty = true;
|
}
|
}
|
break;
|
case PackType.Equip:
|
var equip = packModel.GetItemByIndex(PackType.Equip, index);
|
var clientPlace = EquipSet.ServerPlaceToClientPlace(index);
|
equipSets[clientPlace.x].UpdateEquipSlot(clientPlace.y, equip == null ? string.Empty : equip.guid);
|
|
appearance.value = GetAppearance(selectedLevel.value);
|
|
if (clientPlace.x == PlayerDatas.Instance.baseData.equipShowSwitch / 10)
|
{
|
if (appearanceChangeEvent != null)
|
{
|
appearanceChangeEvent();
|
}
|
}
|
|
break;
|
}
|
|
if (dirty)
|
{
|
RefreshCandidateEquips(selectedLevel.value, selectedPlace.value);
|
}
|
}
|
|
private void UpdateRedpoints()
|
{
|
var hints = new Dictionary<int, bool>();
|
foreach (var item in equipSets)
|
{
|
if (item.Value.unLocked)
|
{
|
hints[item.Key] = false;
|
}
|
}
|
|
var items = packModel.GetItems(PackType.Item, new SinglePack.FilterParams()
|
{
|
equipTypes = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 },
|
});
|
|
foreach (var equip in items)
|
{
|
var level = equip.config.LV;
|
if (hints.ContainsKey(level) && !hints[level])
|
{
|
if (CompareToCurrent(equip.guid) > 0)
|
{
|
hints[level] = true;
|
}
|
}
|
}
|
|
foreach (var level in hints.Keys)
|
{
|
equipSets[level].redpoint.state = hints[level] ? RedPointState.Simple : RedPointState.None;
|
}
|
}
|
|
private void UpdateRedpoint(int level)
|
{
|
var items = packModel.GetItems(PackType.Item, new SinglePack.FilterParams()
|
{
|
levels = new List<int>() { level },
|
equipTypes = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 },
|
});
|
|
var set = equipSets[level];
|
set.redpoint.state = RedPointState.None;
|
foreach (var equip in items)
|
{
|
if (set.redpoint.state != RedPointState.None)
|
{
|
break;
|
}
|
|
if (CompareToCurrent(equip.guid) > 0)
|
{
|
set.redpoint.state = RedPointState.Simple;
|
}
|
}
|
|
}
|
|
private void ParseConfig()
|
{
|
var configs = EquipControlConfig.GetValues();
|
var setLevelToRealms = new Dictionary<int, int>();
|
foreach (var item in configs)
|
{
|
var level = item.level;
|
var currentRealm = setLevelToRealms.ContainsKey(level) ? setLevelToRealms[level] : 9999;
|
if (item.realm < currentRealm)
|
{
|
setLevelToRealms[level] = item.realm;
|
}
|
}
|
|
foreach (var item in setLevelToRealms)
|
{
|
equipSets[item.Key] = new EquipSet(item.Key, item.Value);
|
sortedLevels.Add(item.Key);
|
}
|
|
sortedLevels.Sort((int a, int b) => { return a.CompareTo(b); });
|
}
|
|
public static int GetItemServerEquipPlace(int itemId)
|
{
|
var config = ItemConfig.Get(itemId);
|
if (config == null)
|
{
|
return -1;
|
}
|
|
var serverEquipPlace = -1;
|
switch ((RoleEquipType)config.EquipPlace)
|
{
|
case RoleEquipType.Weapon:
|
case RoleEquipType.Weapon2:
|
case RoleEquipType.Hat:
|
case RoleEquipType.Clothes:
|
case RoleEquipType.Belt:
|
case RoleEquipType.Trousers:
|
case RoleEquipType.Shoes:
|
case RoleEquipType.Neck:
|
case RoleEquipType.FairyCan1:
|
case RoleEquipType.FairyCan2:
|
case RoleEquipType.Glove:
|
case RoleEquipType.Jade:
|
serverEquipPlace = EquipSet.ClientPlaceToServerPlace(config.LV, config.EquipPlace);
|
break;
|
case RoleEquipType.Wing:
|
case RoleEquipType.Guard1:
|
case RoleEquipType.Guard2:
|
case RoleEquipType.PeerlessWeapon1:
|
case RoleEquipType.PeerlessWeapon2:
|
serverEquipPlace = EquipSet.ClientPlaceToServerPlace(0, config.EquipPlace);
|
break;
|
}
|
|
return serverEquipPlace;
|
}
|
|
}
|
|
public struct EquipSuitPropertyEntry
|
{
|
public EquipSuitType type;
|
public bool actived;
|
public List<Int2> properties;
|
}
|
|
}
|