using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using TableConfig;
|
using System;
|
using System.Linq;
|
using Snxxz.UI;
|
|
namespace Snxxz.UI
|
{
|
public class MagicianModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
PlayerPackModel _playerPack;
|
PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
|
bool serverInited = false;
|
|
public override void Init()
|
{
|
ParseConfig();
|
playerPack.RefreshItemCountAct += RefreshPackItem;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
}
|
|
private void OnFuncStateChangeEvent(int func)
|
{
|
if (func == (int)FuncOpenEnum.Magician)
|
{
|
UpdateRedPoint();
|
}
|
}
|
|
private void RefreshPackItem(PackType packType, int index, int id)
|
{
|
if (packType != PackType.rptItem)
|
{
|
return;
|
}
|
UpdateRedPoint();
|
}
|
|
public override void UnInit()
|
{
|
playerPack.RefreshItemCountAct -= RefreshPackItem;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
serverInited = false;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
serverInited = true;
|
}
|
|
private Dictionary<int, int[]> godWeaponLvUpItem = new Dictionary<int, int[]>();
|
public int[] GetLvUpItemByType(int type)
|
{
|
return godWeaponLvUpItem[type];
|
}
|
public List<int> magicianTypes { get; private set; }
|
public Dictionary<int, string> godWeaponIcons { get; private set; }
|
public Dictionary<int, Dictionary<int, int>> godWeaponSkillDict = new Dictionary<int, Dictionary<int, int>>();
|
public int selectType = 0;
|
public int selectItemIndex = 0;
|
public int gotoType = 0;
|
void ParseConfig()
|
{
|
magicianTypes = GodWeaponConfig.GetGodWeaponType();
|
for (int i = 0; i < magicianTypes.Count; i++)
|
{
|
FuncConfigConfig _funcCfg = Config.Instance.Get<FuncConfigConfig>(string.Format("GodWeapon{0}", magicianTypes[i]));
|
int[] itemarray = ConfigParse.GetMultipleStr<int>(_funcCfg.Numerical1);
|
godWeaponLvUpItem.Add(magicianTypes[i], itemarray);
|
}
|
godWeaponIcons = new Dictionary<int, string>();
|
var _cfg = Config.Instance.Get<FuncConfigConfig>("GodModel");
|
var _godWeaponJson = LitJson.JsonMapper.ToObject(_cfg.Numerical2);
|
foreach (var _key in _godWeaponJson.Keys)
|
{
|
var _godWeaponType = int.Parse(_key);
|
if (!godWeaponIcons.ContainsKey(_godWeaponType))
|
{
|
godWeaponIcons.Add(_godWeaponType, _godWeaponJson[_key].ToString());
|
}
|
}
|
|
var configs = Config.Instance.GetAllValues<GodWeaponConfig>();
|
for (int i = 0; i < configs.Count; i++)
|
{
|
if (configs[i].SkillID != 0)
|
{
|
Dictionary<int, int> _dict = null;
|
if (!godWeaponSkillDict.TryGetValue(configs[i].Type, out _dict))
|
{
|
_dict = new Dictionary<int, int>();
|
godWeaponSkillDict.Add(configs[i].Type, _dict);
|
}
|
_dict.Add(configs[i].Lv, configs[i].SkillID);
|
}
|
}
|
}
|
#region 红点
|
public const int MAGICAIN_REDPOINT = 10104;
|
public const int MAGICAIN_INTERVAL = 100;
|
public Dictionary<int, Redpoint> redpointDict = new Dictionary<int, Redpoint>();
|
Redpoint magicianPoint = new Redpoint(101, MAGICAIN_REDPOINT);
|
public Redpoint magicianRedpoint { get { return magicianPoint; } }
|
public void UpdateRedPoint()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Magician))
|
{
|
return;
|
}
|
foreach (var key in redpointDict.Keys)
|
{
|
int[] items = GetLvUpItemByType((int)key);
|
redpointDict[key].state = RedPointState.None;
|
for (int i = 0; i < items.Length; i++)
|
{
|
if (playerPack.GetItemCountByID(PackType.rptItem, items[i]) > 0)
|
{
|
MagicianData data = null;
|
if (magicianDict.TryGetValue(key, out data))
|
{
|
var _godWeaponCfg = Config.Instance.Get<GodWeaponConfig>(data.level + 1);
|
if (_godWeaponCfg == null)
|
{
|
redpointDict[key].state = RedPointState.None;
|
break;
|
}
|
}
|
redpointDict[key].state = RedPointState.Simple;
|
break;
|
}
|
}
|
}
|
}
|
public bool CanTemperMagician()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Magician))
|
{
|
return false;
|
}
|
foreach (var key in redpointDict.Keys)
|
{
|
if (redpointDict[key].state == RedPointState.Simple)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
public bool GetRedpointLightByType(int _type)
|
{
|
if (redpointDict.ContainsKey(_type))
|
{
|
return redpointDict[_type].state == RedPointState.Simple;
|
}
|
return false;
|
}
|
#endregion
|
public void TemperMagician(int type)
|
{
|
MagicianData data = GetMagicianData(type);
|
if (data != null)
|
{
|
if (IsGodWeaponMaxLevel(type))
|
{
|
MessageWin.Inst.ShowFixedTip(Language.Get("L1054"));
|
return;
|
}
|
}
|
int[] items = GetLvUpItemByType(type);
|
if (selectItemIndex >= items.Length)
|
{
|
return;
|
}
|
ItemConfig itemCfg = Config.Instance.Get<ItemConfig>(items[selectItemIndex]);
|
var _itemCnt = playerPack.GetItemCountByID(PackType.rptItem, itemCfg.ID);
|
if (_itemCnt < 1)
|
{
|
ModelCenter.Instance.GetModel<GetItemPathModel>().SetChinItemModel(itemCfg.ID);
|
if (!IsGodWeaponTemperItem(3, itemCfg.ID) && !NewBieCenter.Instance.completeGuidesBuf.Contains(85))
|
{
|
NewBieCenter.Instance.StartNewBieGuide(85);
|
}
|
return;
|
}
|
CA555_tagCMGodWeaponPlus _pak = new CA555_tagCMGodWeaponPlus();
|
_pak.WeaponType = (uint)type;
|
_pak.ItemID = (uint)items[selectItemIndex];
|
GameNetSystem.Instance.SendInfo(_pak);
|
}
|
public event Action OnRefresh;
|
private Dictionary<int, MagicianData> magicianDict = new Dictionary<int, MagicianData>();
|
public void OnMagicianChange(HA31D_tagMCGodWeaponLVList vNetData)
|
{
|
for (byte i = 0; i < vNetData.WeaponNum; i++)
|
{
|
HA31D_tagMCGodWeaponLVList.tagMCGodWeaponLVInfo _sData = vNetData.WeaponInfoList[i];
|
MagicianData data = null;
|
magicianDict.TryGetValue(_sData.WeaponType, out data);
|
if (data == null)
|
{
|
data = new MagicianData();
|
magicianDict.Add(_sData.WeaponType, data);
|
}
|
|
CheckActivate((int)data.type, data.level, _sData.WeaponLV);
|
|
data.exp = _sData.WeaponExp;
|
data.level = _sData.WeaponLV;
|
data.type = _sData.WeaponType;
|
if (!redpointDict.ContainsKey((int)data.type))
|
{
|
Redpoint redpoint = new Redpoint(MAGICAIN_REDPOINT, MAGICAIN_REDPOINT * MAGICAIN_INTERVAL + (int)data.type);
|
redpointDict.Add((int)data.type, redpoint);
|
redpoint.state = RedPointState.None;
|
}
|
}
|
UpdateRedPoint();
|
if (OnRefresh != null)
|
{
|
OnRefresh();
|
}
|
}
|
|
void CheckActivate(int _type, int _beforeLv, int _nowLv)
|
{
|
var _skillId = 0;
|
if (serverInited && _beforeLv != _nowLv
|
&& (_beforeLv == 0 || TryGetUnlockSkill(_type, _beforeLv, _nowLv, out _skillId)))
|
{
|
if (WindowCenter.Instance.CheckOpen<MagicianWin>()
|
&& !NewBieCenter.Instance.inGuiding)
|
{
|
ActivateShow.GodWeaponActivate(_type, _nowLv, _beforeLv);
|
}
|
}
|
}
|
|
public bool TryGetUnlockSkill(int _type, int _beforeLv, int _nowLv,out int _skillid)
|
{
|
_skillid = 0;
|
if (godWeaponSkillDict.ContainsKey(_type))
|
{
|
var _dict = godWeaponSkillDict[_type];
|
foreach (var _lv in _dict.Keys)
|
{
|
if (_beforeLv < _lv && _lv <= _nowLv)
|
{
|
_skillid = _dict[_lv];
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
|
public MagicianData GetMagicianData(int type)
|
{
|
MagicianData data = null;
|
magicianDict.TryGetValue(type, out data);
|
return data;
|
}
|
|
public bool IsGodWeaponMaxLevel(int _type)
|
{
|
var _data = GetMagicianData(_type);
|
var config = Config.Instance.Get<GodWeaponConfig>(_data.level + 1);
|
return config == null;
|
}
|
|
public bool IsGodWeaponTemperItem(int _type,int _itemId)
|
{
|
var items = GetLvUpItemByType(_type);
|
if (items == null)
|
{
|
return false;
|
}
|
for (int i = 0; i < items.Length; i++)
|
{
|
if (items[i] == _itemId)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool IsGodWeaponMaxLevelByItem(int _itemId)
|
{
|
foreach (var _key in godWeaponLvUpItem.Keys)
|
{
|
for (int i = 0; i < godWeaponLvUpItem[_key].Length; i++)
|
{
|
if (godWeaponLvUpItem[_key][i] == _itemId)
|
{
|
return IsGodWeaponMaxLevel(_key);
|
}
|
}
|
}
|
return false;
|
}
|
|
}
|
|
public class MagicianData
|
{
|
public uint type;
|
public int level;
|
public uint exp;
|
}
|
}
|
|