using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
[XLua.Hotfix]
|
[XLua.LuaCallCSharp]
|
public class GatherSoulComposeModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
Dictionary<int, Compose> composeDict = new Dictionary<int, Compose>();
|
public List<ComposeCategory> composeCategories { get; private set; }
|
public Dictionary<ComposeCategory, List<int>> categoryDict { get; private set; }
|
|
public event Action onSelectComposeItemChange;
|
public event Action onSelectCategoryChange;
|
|
ComposeCategory m_SelectCategory;
|
public ComposeCategory selectCategory
|
{
|
get { return m_SelectCategory; }
|
set
|
{
|
if (!value.Equals(m_SelectCategory))
|
{
|
m_SelectCategory = value;
|
if (onSelectCategoryChange != null)
|
{
|
onSelectCategoryChange();
|
}
|
}
|
}
|
}
|
|
int m_SelectItemId = 0;
|
public int selectItemId
|
{
|
get { return m_SelectItemId; }
|
set
|
{
|
if (value != m_SelectItemId)
|
{
|
m_SelectItemId = value;
|
if (onSelectComposeItemChange != null)
|
{
|
onSelectComposeItemChange();
|
}
|
}
|
}
|
}
|
|
public VirtualItem jumpGatherSoulItem { get; set; }
|
|
GatheringSoulModel soulModel
|
{
|
get { return ModelCenter.Instance.GetModel<GatheringSoulModel>(); }
|
}
|
|
public override void Init()
|
{
|
ParseConfig();
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
}
|
|
public override void UnInit()
|
{
|
}
|
|
void ParseConfig()
|
{
|
categoryDict = new Dictionary<ComposeCategory, List<int>>();
|
composeCategories = new List<ComposeCategory>();
|
var configs = GatherSoulComposeConfig.GetValues();
|
for (int i = 0; i < configs.Count; i++)
|
{
|
composeDict.Add(configs[i].TagItemID, new Compose(configs[i]));
|
|
var itemConfig = ItemConfig.Get(configs[i].TagItemID);
|
var gatherSoulConfig = GatherSoulConfig.Get(configs[i].TagItemID);
|
if (gatherSoulConfig == null)
|
{
|
continue;
|
}
|
var propertyCount = gatherSoulConfig.AttrType.Length;
|
var quality = itemConfig.ItemColor;
|
var category = new ComposeCategory()
|
{
|
category = configs[i].category,
|
propertyCount = propertyCount,
|
quality = quality,
|
};
|
if (!composeCategories.Contains(category))
|
{
|
composeCategories.Add(category);
|
}
|
|
List<int> list;
|
if (!categoryDict.TryGetValue(category, out list))
|
{
|
list = new List<int>();
|
categoryDict.Add(category, list);
|
}
|
list.Add(configs[i].TagItemID);
|
}
|
}
|
|
public bool ExistInComposeMat(int itemId, out Compose outCompose)
|
{
|
outCompose = null;
|
foreach (var compose in composeDict.Values)
|
{
|
if (compose.requireItems.Contains(itemId))
|
{
|
outCompose = compose;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool TryGetCompose(int itemId, out Compose compose)
|
{
|
return composeDict.TryGetValue(itemId, out compose);
|
}
|
|
public class Compose
|
{
|
public int itemId;
|
public List<int> requireItems;
|
public int requireLevel;
|
public int requireSoulSplinters;
|
public int requireSoulCore;
|
public int category;
|
|
public Compose(GatherSoulComposeConfig config)
|
{
|
itemId = config.TagItemID;
|
requireItems = new List<int>(config.NeedItem);
|
requireLevel = config.NeedLV;
|
requireSoulSplinters = config.NeedSoulSplinters;
|
requireSoulCore = config.NeedSoulCore;
|
category = config.category;
|
}
|
}
|
|
public struct ComposeCategory
|
{
|
public int category;
|
public int quality;
|
public int propertyCount;
|
|
public override bool Equals(object obj)
|
{
|
var compare = (ComposeCategory)obj;
|
return this.category == compare.category && this.quality == compare.quality
|
&& this.propertyCount == compare.propertyCount;
|
}
|
|
public override int GetHashCode()
|
{
|
return (category * 100 + quality * 10 + propertyCount).GetHashCode();
|
}
|
}
|
}
|
}
|
|