using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
|
|
public class FashionDressModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
Dictionary<int, FashionDress> fashionDressDict = new Dictionary<int, FashionDress>();
|
Dictionary<int, int> fashionDressLevelDict = new Dictionary<int, int>();
|
Dictionary<int, Dictionary<int, int>> cabinetPropertyDict = new Dictionary<int, Dictionary<int, int>>();
|
Dictionary<int, List<int>> fashionDressTypeDict = new Dictionary<int, List<int>>();
|
Dictionary<int, List<int>> fashionDressSuitTypeDict = new Dictionary<int, List<int>>();
|
Dictionary<int, Dictionary<int, List<int>>> fashionDressQualityDict = new Dictionary<int, Dictionary<int, List<int>>>();
|
|
const int FASHIONDRESS_REDPOINT_BASE = 10105;
|
const int FASHIONDRESS_FUNC_ID = 160;
|
|
readonly List<int> fashionDressTypeSort = new List<int>() { 1, 2, 3 };
|
readonly List<int> fashionDressQualitySort = new List<int>() { 0, 1, 2 };
|
|
public readonly Redpoint redpoint = new Redpoint(101, FASHIONDRESS_REDPOINT_BASE);
|
public readonly Redpoint levelUpRedpoint = new Redpoint(FASHIONDRESS_REDPOINT_BASE, 1010501);
|
|
public int cabinetLevel { get; private set; }
|
public int cabinetExp { get; private set; }
|
public int cabinetMaxLevel { get; private set; }
|
public bool serverInited { get; private set; }
|
public int jumpFashionDress { get; set; }
|
public int fashoinDressCount
|
{
|
get
|
{
|
return fashionDressDict.Count;
|
}
|
}
|
|
public Dictionary<int, int> fashionDressSelectDict { get; private set; }
|
public Dictionary<int, int> fashionDressEquipDict { get; private set; }
|
public List<int> fashionDressLevelUpItems { get; private set; }
|
public List<int> fashionDressTypes { get; private set; }
|
public Dictionary<int, int> fashionTypeMapPlaceDict { get; private set; }
|
|
int m_SelectType = 1;
|
public int selectType
|
{
|
get { return m_SelectType; }
|
set
|
{
|
if (m_SelectType != value)
|
{
|
m_SelectType = value;
|
if (selectTypeRefresh != null)
|
{
|
selectTypeRefresh();
|
}
|
}
|
}
|
}
|
|
int m_SelectQuality = 0;
|
public int selectQuality
|
{
|
get { return m_SelectQuality; }
|
set
|
{
|
if (m_SelectQuality != value)
|
{
|
m_SelectQuality = value;
|
if (selectQualityRefresh != null)
|
{
|
selectQualityRefresh();
|
}
|
}
|
}
|
}
|
|
public event Action selectTypeRefresh;
|
public event Action selectQualityRefresh;
|
public event Action cabinetRefresh;
|
public event Action<int> fashionDressRefresh;
|
public event Action<int> selectFashionDressRefresh;
|
public event Action<int> virtualEquipRefresh;
|
|
PackModel packModel
|
{
|
get { return ModelCenter.Instance.GetModel<PackModel>(); }
|
}
|
|
public override void Init()
|
{
|
ParseConfig();
|
fashionDressSelectDict = new Dictionary<int, int>();
|
fashionDressEquipDict = new Dictionary<int, int>();
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
packModel.refreshItemCountEvent += RefreshItemCountAct;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
fashionDressLevelDict.Clear();
|
cabinetLevel = 0;
|
cabinetExp = 0;
|
serverInited = false;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
UpdateRedpoint();
|
serverInited = true;
|
}
|
|
public override void UnInit()
|
{
|
}
|
|
private void OnFuncStateChangeEvent(int id)
|
{
|
if (id == FASHIONDRESS_FUNC_ID)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
private void RefreshItemCountAct(PackType packType, int arg2, int itemId)
|
{
|
if (packType == PackType.Item)
|
{
|
if (fashionDressLevelUpItems.Contains(itemId))
|
{
|
UpdateRedpoint();
|
}
|
}
|
}
|
|
void ParseConfig()
|
{
|
{
|
fashionDressSuitTypeDict.Clear();
|
var configs = FashionDressConfig.GetValues();
|
fashionDressLevelUpItems = new List<int>();
|
foreach (var config in configs)
|
{
|
fashionDressDict[config.CoatID] = new FashionDress(config);
|
{
|
List<int> list;
|
if (!fashionDressTypeDict.TryGetValue(config.type, out list))
|
{
|
list = new List<int>();
|
fashionDressTypeDict.Add(config.type, list);
|
}
|
list.Add(config.CoatID);
|
}
|
|
if (!fashionDressSuitTypeDict.ContainsKey(config.FashionSuitType))
|
{
|
var list = new List<int>();
|
list.Add(config.CoatID);
|
fashionDressSuitTypeDict.Add(config.FashionSuitType, list);
|
}
|
else
|
{
|
fashionDressSuitTypeDict[config.FashionSuitType].Add(config.CoatID);
|
}
|
|
if (!fashionDressLevelUpItems.Contains(config.UnlockItemID))
|
{
|
fashionDressLevelUpItems.Add(config.UnlockItemID);
|
}
|
|
{
|
Dictionary<int, List<int>> dict;
|
if (!fashionDressQualityDict.TryGetValue(config.type, out dict))
|
{
|
dict = new Dictionary<int, List<int>>();
|
fashionDressQualityDict.Add(config.type, dict);
|
}
|
List<int> list;
|
if (!dict.TryGetValue(config.quality, out list))
|
{
|
list = new List<int>();
|
dict.Add(config.quality, list);
|
}
|
list.Add(config.CoatID);
|
}
|
}
|
}
|
|
{
|
var configs = FashionDressCabinetConfig.GetValues();
|
foreach (var config in configs)
|
{
|
cabinetPropertyDict.Add(config.LV, ConfigParse.GetDic<int, int>(config.Attr));
|
if (config.LV > cabinetMaxLevel)
|
{
|
cabinetMaxLevel = config.LV;
|
}
|
}
|
}
|
|
{
|
var config = FuncConfigConfig.Get("FashionDressType");
|
if (config != null)
|
{
|
fashionTypeMapPlaceDict = ConfigParse.GetDic<int, int>(config.Numerical1);
|
}
|
fashionDressTypes = fashionTypeMapPlaceDict.Keys.ToList();
|
}
|
|
}
|
|
public int GetFashionDressLevel(int id)
|
{
|
if (fashionDressLevelDict.ContainsKey(id))
|
{
|
return fashionDressLevelDict[id];
|
}
|
return 0;
|
}
|
|
public int GetFashionDressEquipId(int type)
|
{
|
if (fashionTypeMapPlaceDict.ContainsKey(type)
|
&& fashionDressTypeDict.ContainsKey(type))
|
{
|
var equipType = fashionTypeMapPlaceDict[type];
|
var equipPlace = EquipPlaceMapConfig.GetServerPlace(0, equipType);
|
var itemModel = packModel.GetItemByIndex(PackType.Equip, (int)equipPlace);
|
var list = fashionDressTypeDict[type];
|
if (itemModel != null)
|
{
|
var index = list.FindIndex((id) =>
|
{
|
FashionDress fashionDress;
|
if (TryGetFashionDress(id, out fashionDress))
|
{
|
return fashionDress.GetEquipItemId() == itemModel.itemId;
|
}
|
return false;
|
});
|
if (index != -1)
|
{
|
return list[index];
|
}
|
}
|
}
|
return 0;
|
}
|
|
public int GetSelectFashionDress(int type)
|
{
|
if (fashionDressSelectDict.ContainsKey(type))
|
{
|
return fashionDressSelectDict[type];
|
}
|
return 0;
|
}
|
|
public int GetVirtualEquipFashionDress(int type)
|
{
|
if (fashionDressEquipDict.ContainsKey(type))
|
{
|
return fashionDressEquipDict[type];
|
}
|
return 0;
|
}
|
|
public bool IsFashionDressUnlock(int id)
|
{
|
var level = GetFashionDressLevel(id);
|
return level > 0;
|
}
|
|
public bool TryGetFashionDress(int id, out FashionDress fashionDress)
|
{
|
return fashionDressDict.TryGetValue(id, out fashionDress);
|
}
|
|
public bool TryGetFashionDresses(int type, int quality, out List<int> list)
|
{
|
list = null;
|
if (fashionDressQualityDict.ContainsKey(type))
|
{
|
return fashionDressQualityDict[type].TryGetValue(quality, out list);
|
}
|
return false;
|
}
|
|
public bool TryGetFashionDresses(int type, out List<int> list)
|
{
|
return fashionDressTypeDict.TryGetValue(type, out list);
|
}
|
|
public bool TryGetFashionIds(int suitType, out List<int> list)
|
{
|
return fashionDressSuitTypeDict.TryGetValue(suitType, out list);
|
}
|
|
public bool TryGetFashionDressProperty(int id, int level, out Dictionary<int, int> dict)
|
{
|
dict = null;
|
if (fashionDressDict.ContainsKey(id))
|
{
|
return fashionDressDict[id].TryGetProperty(level, out dict);
|
}
|
return false;
|
}
|
|
public bool TryGetCabinetProperty(int level, out Dictionary<int, int> dict)
|
{
|
return cabinetPropertyDict.TryGetValue(level, out dict);
|
}
|
|
public bool TryGetSatisfyResolves(ref List<int> list)
|
{
|
if (list == null)
|
{
|
list = new List<int>();
|
}
|
list.Clear();
|
foreach (var fashionDress in fashionDressDict.Values)
|
{
|
var level = GetFashionDressLevel(fashionDress.id);
|
if (level < fashionDress.maxLevel)
|
{
|
continue;
|
}
|
var count = packModel.GetItemCountByID(PackType.Item, fashionDress.requireLevelUpItem);
|
if (count > 0 && !list.Contains(fashionDress.requireLevelUpItem))
|
{
|
list.Add(fashionDress.requireLevelUpItem);
|
}
|
}
|
return list != null && list.Count > 0;
|
}
|
|
public bool TryGetActiveFashionDress(out List<int> list)
|
{
|
list = new List<int>();
|
foreach (var fashionDress in fashionDressDict.Values)
|
{
|
var level = GetFashionDressLevel(fashionDress.id);
|
if (level > 0)
|
{
|
list.Add(fashionDress.id);
|
}
|
}
|
return list.Count > 0;
|
}
|
|
|
public bool TryLevelUp(int id, out int error)
|
{
|
error = 0;
|
FashionDress fashionDress;
|
if (TryGetFashionDress(id, out fashionDress))
|
{
|
var level = GetFashionDressLevel(id);
|
if (level >= fashionDress.maxLevel)
|
{
|
return false;
|
}
|
var count = packModel.GetItemCountByID(PackType.Item, fashionDress.requireLevelUpItem);
|
var levelUpRequireCount = fashionDress.GetLevelUpRequireCount(level);
|
if (count < levelUpRequireCount)
|
{
|
error = 1;
|
return false;
|
}
|
}
|
return true;
|
}
|
|
public void DisplayLevelUpError(int error)
|
{
|
switch (error)
|
{
|
case 1:
|
SysNotifyMgr.Instance.ShowTip("FashionDressLevelUpError_1");
|
break;
|
}
|
}
|
|
public void SetSelectFashionDress(int type, int id)
|
{
|
fashionDressSelectDict[type] = id;
|
if (selectFashionDressRefresh != null)
|
{
|
selectFashionDressRefresh(type);
|
}
|
}
|
|
public void SetVirtualEquipFashionDress(int type, int id)
|
{
|
fashionDressEquipDict[type] = id;
|
if (virtualEquipRefresh != null)
|
{
|
virtualEquipRefresh(type);
|
}
|
}
|
|
public void ReceivePackage(HB102_tagMCClothesCoatSkinState package)
|
{
|
cabinetLevel = (int)package.CoatChestLV;
|
cabinetExp = (int)package.CoatChestExp;
|
if (cabinetRefresh != null)
|
{
|
cabinetRefresh();
|
}
|
for (int i = 0; i < package.CoatNum; i++)
|
{
|
var id = (int)package.CoatInfoList[i].CoatIndex;
|
var level = (int)package.CoatInfoList[i].CoatLV;
|
fashionDressLevelDict[id] = level;
|
if (fashionDressRefresh != null)
|
{
|
fashionDressRefresh(id);
|
}
|
if (level == 1)
|
{
|
HandleFashionDressUnlock(id);
|
}
|
}
|
UpdateRedpoint();
|
}
|
|
public void HandleFashionDressUnlock(int id)
|
{
|
if (serverInited)
|
{
|
if (WindowCenter.Instance.IsOpen<FashionDressWin>())
|
{
|
FashionDress fashionDress;
|
if (TryGetFashionDress(id, out fashionDress))
|
{
|
if (selectType == fashionDress.fashionDressType)
|
{
|
var virtualEquipId = GetVirtualEquipFashionDress(selectType);
|
if (virtualEquipId != 0)
|
{
|
SetSelectFashionDress(selectType, virtualEquipId);
|
}
|
else
|
{
|
SetVirtualEquipFashionDress(selectType, id);
|
SetSelectFashionDress(selectType, id);
|
}
|
}
|
}
|
}
|
}
|
}
|
|
public void SendLevelUp(int id)
|
{
|
CA50B_tagCMCoatUp pak = new CA50B_tagCMCoatUp();
|
pak.CoatIndex = (uint)id;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
public void TryEquip()
|
{
|
foreach (var type in fashionDressEquipDict.Keys)
|
{
|
var equipId = GetFashionDressEquipId(type);
|
var virtualEquipId = fashionDressEquipDict[type];
|
var index = fashionTypeMapPlaceDict[type];
|
if (virtualEquipId != 0)
|
{
|
if (IsFashionDressUnlock(virtualEquipId)
|
&& virtualEquipId != equipId)
|
{
|
SendEquipPackage((int)PackType.InterimPack, virtualEquipId,
|
(int)PackType.Equip, EquipPlaceMapConfig.GetServerPlace(0, index));
|
}
|
}
|
else
|
{
|
if (equipId != 0)
|
{
|
SendEquipPackage((int)PackType.Equip, EquipPlaceMapConfig.GetServerPlace(0, index), (int)PackType.InterimPack, 0);
|
}
|
}
|
}
|
}
|
|
void SendEquipPackage(int srcpackType, int scrIndex, int destpackType, int destIndex)
|
{
|
C073D_tagCPackItemExchange pak = new C073D_tagCPackItemExchange();
|
pak.SrcBackpack = (byte)srcpackType;
|
pak.SrcIndex = (ushort)scrIndex;
|
pak.DesBackPack = (byte)destpackType;
|
pak.DestIndex = (ushort)destIndex;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
#region 时装详情
|
public int viewFashionDressId { get; private set; }
|
public void ViewFashionDressDetails(int id)
|
{
|
viewFashionDressId = id;
|
WindowCenter.Instance.Open<FashionDetailsWin>();
|
}
|
#endregion
|
|
#region 红点
|
public int fashionDressRedpointId { get; private set; }
|
void UpdateRedpoint()
|
{
|
levelUpRedpoint.state = RedPointState.None;
|
if (!FuncOpen.Instance.IsFuncOpen(FASHIONDRESS_FUNC_ID))
|
{
|
return;
|
}
|
foreach (var type in fashionDressTypeSort)
|
{
|
foreach (var quality in fashionDressQualitySort)
|
{
|
List<int> list;
|
if (TryGetFashionDresses(type, quality, out list))
|
{
|
foreach (var id in list)
|
{
|
FashionDress fashionDress;
|
if (TryGetFashionDress(id, out fashionDress))
|
{
|
var level = GetFashionDressLevel(fashionDress.id);
|
if (level >= fashionDress.maxLevel)
|
{
|
continue;
|
}
|
var levelUpRequireCount = fashionDress.GetLevelUpRequireCount(level);
|
var count = packModel.GetItemCountByID(PackType.Item, fashionDress.requireLevelUpItem);
|
if (count >= levelUpRequireCount)
|
{
|
fashionDressRedpointId = fashionDress.id;
|
levelUpRedpoint.state = RedPointState.Simple;
|
return;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
#endregion
|
}
|
|
public class FashionDress
|
{
|
public int id { get; private set; }
|
public int requireLevelUpItem { get; private set; }
|
public int maxLevel { get; private set; }
|
public int equipPlace { get; private set; }
|
public int fashionDressType { get; private set; }
|
|
List<int> equipItems = new List<int>();
|
List<int> requireLevelUpCounts = new List<int>();
|
Dictionary<int, Dictionary<int, int>> propertys = new Dictionary<int, Dictionary<int, int>>();
|
public FashionDress(FashionDressConfig config)
|
{
|
id = config.CoatID;
|
requireLevelUpItem = config.UnlockItemID;
|
maxLevel = config.MaxLV;
|
fashionDressType = config.type;
|
requireLevelUpCounts.AddRange(config.CostItemCnt);
|
var json = LitJson.JsonMapper.ToObject(config.StarAttr);
|
foreach (var starKey in json.Keys)
|
{
|
var star = int.Parse(starKey);
|
Dictionary<int, int> dict = new Dictionary<int, int>();
|
propertys.Add(star, dict);
|
foreach (var propertyKey in json[starKey].Keys)
|
{
|
var property = int.Parse(propertyKey);
|
dict.Add(property, int.Parse(json[starKey][propertyKey].ToString()));
|
}
|
}
|
equipItems.AddRange(config.EquipItemID);
|
var equipItemConfig = ItemConfig.Get(equipItems[0]);
|
equipPlace = equipItemConfig.EquipPlace;
|
}
|
|
public int GetEquipItemId(int job = 0)
|
{
|
if (job == 0)
|
{
|
job = PlayerDatas.Instance.baseData.Job;
|
}
|
var index = job - 1;
|
if (index < equipItems.Count)
|
{
|
return equipItems[index];
|
}
|
return 0;
|
}
|
|
public bool TryGetProperty(int level, out Dictionary<int, int> dict)
|
{
|
return propertys.TryGetValue(level, out dict);
|
}
|
|
public int GetLevelUpRequireCount(int level)
|
{
|
var index = level;
|
if (index < requireLevelUpCounts.Count)
|
{
|
return requireLevelUpCounts[index];
|
}
|
return 0;
|
}
|
}
|
}
|
|