using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
using System;
|
using System.Linq;
|
using vnxbqy.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
|
public class MagicianModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
public event Action onSelectUpdate;
|
|
PackModel packModel
|
{
|
get { return ModelCenter.Instance.GetModel<PackModel>(); }
|
}
|
|
bool serverInited = false;
|
|
public override void Init()
|
{
|
ParseConfig();
|
packModel.refreshItemCountEvent += RefreshPackItem;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
|
}
|
|
private void OnFuncStateChangeEvent(int func)
|
{
|
if (func == (int)FuncOpenEnum.GodWeapon)
|
{
|
UpdateRedPoint();
|
}
|
}
|
|
private void RefreshPackItem(PackType packType, int index, int id)
|
{
|
if (packType != PackType.Item)
|
{
|
return;
|
}
|
UpdateRedPoint();
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
|
{
|
if (refreshType == PlayerDataType.LV)
|
{
|
UpdateRedPoint();
|
}
|
}
|
|
public override void UnInit()
|
{
|
packModel.refreshItemCountEvent -= RefreshPackItem;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
serverInited = false;
|
foreach (var godWeapon in godWeaponInfoDict.Values)
|
{
|
godWeapon.level = 0;
|
godWeapon.exp = 0;
|
}
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
serverInited = true;
|
UpdateRedPoint();
|
}
|
|
private Dictionary<int, int[]> godWeaponLevelUpCost = new Dictionary<int, int[]>();
|
public List<int> godWeaponTypes { get; private set; }
|
public Dictionary<int, int> godWeaponBoxDict { get; private set; } //key 神兵石礼包 value 神兵类型
|
public Dictionary<int, string> godWeaponIcons { get; private set; }
|
public Dictionary<int, Dictionary<int, int>> godWeaponSkillDict = new Dictionary<int, Dictionary<int, int>>();
|
Dictionary<int, List<GodWeaponCondition>> godWeaponConditions = new Dictionary<int, List<GodWeaponCondition>>();
|
Dictionary<int, int> playerLevelConditions = new Dictionary<int, int>();
|
public List<int> godWeaponSorts = new List<int>();
|
Dictionary<int, AutoHammerCost> autoHammerCostDict = new Dictionary<int, AutoHammerCost>();
|
Dictionary<int, int> exteriorPowerDict = new Dictionary<int, int>();
|
Dictionary<int, int> godWeaponSkillEffect = new Dictionary<int, int>();
|
Dictionary<int, int> singleHarmmerExp = new Dictionary<int, int>();
|
int[] autoHammerExpArea { get; set; }
|
int[] autoHammerCount { get; set; }
|
|
int m_SelectType = 0;
|
public int selectType
|
{
|
get { return m_SelectType; }
|
set
|
{
|
if (m_SelectType != value)
|
{
|
m_SelectType = value;
|
if (onSelectUpdate != null)
|
{
|
onSelectUpdate();
|
}
|
}
|
}
|
}
|
|
public int selectItemIndex = 0;
|
public int gotoType = 0;
|
|
public int autoHammerLevel { get; set; }
|
|
public int hammerAudioId { get; private set; }
|
public int audioLength { get; private set; }
|
void ParseConfig()
|
{
|
var godWeaponBox = FuncConfigConfig.Get("GodWeaponBox");
|
godWeaponBoxDict = ConfigParse.GetDic<int, int>(godWeaponBox.Numerical1);
|
|
godWeaponTypes = GodWeaponConfig.GetGodWeaponType();
|
for (int i = 0; i < godWeaponTypes.Count; i++)
|
{
|
GodWeaponInfo godWeapon = new GodWeaponInfo()
|
{
|
exp = 0,
|
level = 0,
|
type = godWeaponTypes[i],
|
};
|
godWeaponInfoDict.Add(godWeapon.type, godWeapon);
|
|
if (!redpointDict.ContainsKey(godWeapon.type))
|
{
|
Redpoint redpoint = new Redpoint(MAGICAIN_REDPOINT, MAGICAIN_REDPOINT * MAGICAIN_INTERVAL + godWeapon.type);
|
redpointDict.Add(godWeapon.type, redpoint);
|
redpoint.state = RedPointState.None;
|
}
|
|
var config = FuncConfigConfig.Get(string.Format("GodWeapon{0}", godWeaponTypes[i]));
|
int[] itemarray = ConfigParse.GetMultipleStr<int>(config.Numerical1);
|
godWeaponLevelUpCost.Add(godWeaponTypes[i], itemarray);
|
}
|
|
godWeaponIcons = new Dictionary<int, string>();
|
var _cfg = FuncConfigConfig.Get("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 = GodWeaponConfig.GetValues();
|
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);
|
}
|
}
|
|
var conditionConfig = FuncConfigConfig.Get("GodWeaponActive");
|
var json = LitJson.JsonMapper.ToObject(conditionConfig.Numerical2);
|
foreach (var key in json.Keys)
|
{
|
var type = int.Parse(key);
|
List<GodWeaponCondition> list;
|
if (!godWeaponConditions.TryGetValue(type, out list))
|
{
|
list = new List<GodWeaponCondition>();
|
godWeaponConditions.Add(type, list);
|
}
|
int[][] conditions = LitJson.JsonMapper.ToObject<int[][]>(json[key].ToJson());
|
for (int i = 0; i < conditions.Length; i++)
|
{
|
var condition = conditions[i];
|
list.Add(new GodWeaponCondition()
|
{
|
type = condition[0],
|
level = condition[1],
|
});
|
}
|
}
|
|
json = LitJson.JsonMapper.ToObject(conditionConfig.Numerical3);
|
foreach (var key in json.Keys)
|
{
|
var type = int.Parse(key);
|
playerLevelConditions.Add(type, int.Parse(json[key].ToString()));
|
}
|
|
var sortConfig = FuncConfigConfig.Get("GodWeaponSort");
|
godWeaponSorts.AddRange(ConfigParse.GetMultipleStr<int>(sortConfig.Numerical1));
|
|
var autoHammerConfig = FuncConfigConfig.Get("GodWeaponAutoHammer");
|
if (autoHammerConfig != null)
|
{
|
autoHammerExpArea = ConfigParse.GetMultipleStr<int>(autoHammerConfig.Numerical1);
|
autoHammerCount = ConfigParse.GetMultipleStr<int>(autoHammerConfig.Numerical2);
|
singleHarmmerExp = ConfigParse.GetDic<int, int>(autoHammerConfig.Numerical3);
|
}
|
|
var funcConfig = FuncConfigConfig.Get("GodMagicExp");
|
json = LitJson.JsonMapper.ToObject(funcConfig.Numerical1);
|
foreach (var key in json.Keys)
|
{
|
var type = int.Parse(key);
|
var array = LitJson.JsonMapper.ToObject<int[]>(json[key].ToJson());
|
autoHammerCostDict.Add(type, new AutoHammerCost()
|
{
|
cost = array[0],
|
exp = array[1],
|
});
|
}
|
|
funcConfig = FuncConfigConfig.Get("MagicExterior");
|
json = LitJson.JsonMapper.ToObject(funcConfig.Numerical1);
|
foreach (var key in json.Keys)
|
{
|
var type = int.Parse(key);
|
var power = int.Parse(json[key].ToString());
|
exteriorPowerDict.Add(type, power);
|
}
|
|
funcConfig = FuncConfigConfig.Get("Godvideo");
|
hammerAudioId = int.Parse(funcConfig.Numerical1);
|
audioLength = int.Parse(funcConfig.Numerical2);
|
}
|
|
public int[] GetLevelUpItemByType(int type)
|
{
|
return godWeaponLevelUpCost[type];
|
}
|
|
public bool TryGetMagicType(int itemId,out int type)
|
{
|
type = 0;
|
foreach(var key in godWeaponLevelUpCost.Keys)
|
{
|
var costlist = godWeaponLevelUpCost[key];
|
if(costlist.Contains(itemId))
|
{
|
type = key;
|
return true;
|
}
|
}
|
|
if(godWeaponBoxDict.ContainsKey(itemId))
|
{
|
type = godWeaponBoxDict[itemId];
|
return true;
|
}
|
return false;
|
}
|
|
#region 红点
|
public const int MAGICAIN_REDPOINT = 10102;
|
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()
|
{
|
foreach (var redpoint in redpointDict.Values)
|
{
|
redpoint.state = RedPointState.None;
|
}
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.GodWeapon))
|
{
|
return;
|
}
|
foreach (var key in redpointDict.Keys)
|
{
|
if (IsGodWeaponMaxLevel(key))
|
{
|
continue;
|
}
|
if (!IsGodWeaponUnlock(key) && ContainsCondition(key))
|
{
|
if (SatisfyUnlockCondition(key))
|
{
|
redpointDict[key].state = RedPointState.Simple;
|
}
|
continue;
|
}
|
int[] items = GetLevelUpItemByType((int)key);
|
for (int i = 0; i < items.Length; i++)
|
{
|
if (packModel.GetItemCountByID(PackType.Item, items[i]) > 0)
|
{
|
redpointDict[key].state = RedPointState.Simple;
|
break;
|
}
|
}
|
}
|
}
|
|
public bool GetRedpointLightByType(int _type)
|
{
|
if (redpointDict.ContainsKey(_type))
|
{
|
return redpointDict[_type].state == RedPointState.Simple;
|
}
|
return false;
|
}
|
#endregion
|
|
public void HammerGodWeapon(int type)
|
{
|
GodWeaponInfo godWeaponInfo = GetGodWeaponInfo(type);
|
if (godWeaponInfo == null)
|
{
|
return;
|
}
|
if (IsGodWeaponMaxLevel(type))
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("L1054"));
|
return;
|
}
|
int[] items = GetLevelUpItemByType(type);
|
if (selectItemIndex >= items.Length)
|
{
|
return;
|
}
|
var itemId = items[selectItemIndex];
|
ItemConfig itemConfig = ItemConfig.Get(itemId);
|
var count = packModel.GetItemCountByID(PackType.Item, itemId);
|
if (count < 1)
|
{
|
ItemTipUtility.Show(itemId);
|
return;
|
}
|
CA555_tagCMGodWeaponPlus pak = new CA555_tagCMGodWeaponPlus();
|
pak.WeaponType = (uint)type;
|
pak.ItemID = (uint)itemId;
|
pak.ItemCount = 1;
|
pak.IsAutoBuy = 0;
|
GameNetSystem.Instance.SendInfo(pak);
|
PlayHammerAudio();
|
}
|
|
DateTime lastAudioTime = DateTime.Now;
|
public void PlayHammerAudio()
|
{
|
var seconds = (float)audioLength / 1000;
|
if ((DateTime.Now - lastAudioTime).TotalSeconds < seconds)
|
{
|
return;
|
}
|
lastAudioTime = DateTime.Now;
|
SoundPlayer.Instance.PlayUIAudio(hammerAudioId);
|
}
|
|
public event Action godWeaponUpdate;
|
private Dictionary<int, GodWeaponInfo> godWeaponInfoDict = new Dictionary<int, GodWeaponInfo>();
|
public void UpdateGodWeaponInfo(HA31D_tagMCGodWeaponLVList package)
|
{
|
for (byte i = 0; i < package.WeaponNum; i++)
|
{
|
HA31D_tagMCGodWeaponLVList.tagMCGodWeaponLVInfo data = package.WeaponInfoList[i];
|
GodWeaponInfo godWeaponInfo = GetGodWeaponInfo(data.WeaponType);
|
if (godWeaponInfo != null)
|
{
|
var beforeLevel = godWeaponInfo.level;
|
godWeaponInfo.exp = data.WeaponExp;
|
godWeaponInfo.level = data.WeaponLV;
|
CheckActivate(godWeaponInfo.type, beforeLevel, data.WeaponLV);
|
}
|
}
|
UpdateRedPoint();
|
if (godWeaponUpdate != null)
|
{
|
godWeaponUpdate();
|
}
|
}
|
|
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.IsOpen<MagicianWin>()
|
&& !NewBieCenter.Instance.inGuiding)
|
{
|
if (WindowCenter.Instance.IsOpen<HowToPlayWin>())
|
{
|
WindowCenter.Instance.Close<HowToPlayWin>();
|
}
|
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 bool TryGetGodWeaponSkills(int type, out Dictionary<int, int> skills)
|
{
|
return godWeaponSkillDict.TryGetValue(type, out skills);
|
}
|
|
public GodWeaponInfo GetGodWeaponInfo(int type)
|
{
|
GodWeaponInfo data = null;
|
godWeaponInfoDict.TryGetValue(type, out data);
|
return data;
|
}
|
|
public bool IsGodWeaponMaxLevel(int _type)
|
{
|
var _data = GetGodWeaponInfo(_type);
|
var config = GodWeaponConfig.GetConfig(_type, _data.level + 1);
|
return config == null;
|
}
|
|
public bool IsGodWeaponHammerItem(int _type,int _itemId)
|
{
|
var items = GetLevelUpItemByType(_type);
|
if (items == null)
|
{
|
return false;
|
}
|
for (int i = 0; i < items.Length; i++)
|
{
|
if (items[i] == _itemId)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool IsGodWeaponUnlock(int type)
|
{
|
var godWeaponInfo = GetGodWeaponInfo(type);
|
if (godWeaponInfo != null && godWeaponInfo.level >= 1)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
public bool SatisfyUnlockCondition(int type)
|
{
|
if (!playerLevelConditions.ContainsKey(type)
|
&& !godWeaponConditions.ContainsKey(type))
|
{
|
return true;
|
}
|
List<GodWeaponCondition> list;
|
bool satisfyCondition = false;
|
if (godWeaponConditions.TryGetValue(type, out list))
|
{
|
bool satisfy = true;
|
for (int i = 0; i < list.Count; i++)
|
{
|
var godWeaponInfo = GetGodWeaponInfo(list[i].type);
|
if (godWeaponInfo == null || godWeaponInfo.level < list[i].level)
|
{
|
satisfy = false;
|
break;
|
}
|
}
|
if (satisfy)
|
{
|
satisfyCondition = true;
|
}
|
}
|
var playerLevelLimit = 0;
|
if (TryGetPlayerLevelCondition(type, out playerLevelLimit))
|
{
|
if (PlayerDatas.Instance.baseData.LV >= playerLevelLimit)
|
{
|
satisfyCondition = true;
|
}
|
}
|
return satisfyCondition;
|
}
|
|
public int GetAutoHammerCount(int type)
|
{
|
ulong totalExp = 0;
|
var godWeaponInfo = GetGodWeaponInfo(type);
|
if (godWeaponInfo == null || autoHammerExpArea == null || autoHammerCount == null)
|
{
|
return 1;
|
}
|
var config = GodWeaponConfig.GetConfig(type, godWeaponInfo.level);
|
totalExp = (ulong)config.NeedExp;
|
var index = 0;
|
for (int i = 0; i < autoHammerExpArea.Length; i++)
|
{
|
if (totalExp < (ulong)autoHammerExpArea[i])
|
{
|
index = i;
|
break;
|
}
|
else
|
{
|
index++;
|
}
|
}
|
if (index < autoHammerCount.Length)
|
{
|
return autoHammerCount[index];
|
}
|
return autoHammerCount[autoHammerCount.Length - 1];
|
}
|
|
public int GetAutoHammerCount(int type, int index)
|
{
|
var items = GetLevelUpItemByType(type);
|
var moneyCount = GetAutoHammerCount(type);
|
AutoHammerCost autoHammerCost;
|
var totalExp = 0;
|
if (TryGetAutoHammerCost(type, out autoHammerCost))
|
{
|
totalExp = moneyCount * autoHammerCost.exp;
|
}
|
else if (singleHarmmerExp.ContainsKey(type))
|
{
|
totalExp = moneyCount * singleHarmmerExp[type];
|
}
|
var itemId = items[index];
|
var itemConfig = ItemConfig.Get(itemId);
|
var expCount = Mathf.CeilToInt((float)totalExp / itemConfig.EffectValueA1);
|
var packCount = packModel.GetItemCountByID(PackType.Item, itemId);
|
return Mathf.Min(expCount, packCount);
|
}
|
|
public bool ContainsCondition(int type)
|
{
|
return godWeaponConditions.ContainsKey(type) || playerLevelConditions.ContainsKey(type);
|
}
|
|
public bool TryGetConditions(int type, out List<GodWeaponCondition> list)
|
{
|
return godWeaponConditions.TryGetValue(type, out list);
|
}
|
|
public bool TryGetPlayerLevelCondition(int type,out int level)
|
{
|
return playerLevelConditions.TryGetValue(type, out level);
|
}
|
|
public bool IsGodWeaponMaxLevelByItem(int _itemId)
|
{
|
foreach (var _key in godWeaponLevelUpCost.Keys)
|
{
|
for (int i = 0; i < godWeaponLevelUpCost[_key].Length; i++)
|
{
|
if (godWeaponLevelUpCost[_key][i] == _itemId)
|
{
|
return IsGodWeaponMaxLevel(_key);
|
}
|
}
|
}
|
return false;
|
}
|
|
public bool TryGetAutoHammerCost(int type,out AutoHammerCost autoHammerCost)
|
{
|
return autoHammerCostDict.TryGetValue(type, out autoHammerCost);
|
}
|
|
public bool TryGetExteriorPower(int type, out int power)
|
{
|
return exteriorPowerDict.TryGetValue(type, out power);
|
}
|
|
public List<int> TryGetDisplaySkillLevels(int type)
|
{
|
List<int> displaySkillLevels = new List<int>();
|
Dictionary<int, int> dict;
|
if (TryGetGodWeaponSkills(type, out dict))
|
{
|
displaySkillLevels.AddRange(dict.Keys);
|
}
|
displaySkillLevels.Sort();
|
return displaySkillLevels;
|
}
|
}
|
|
public class GodWeaponInfo
|
{
|
public int type;
|
public int level;
|
public uint exp;
|
}
|
|
public struct GodWeaponCondition
|
{
|
public int type;
|
public int level;
|
}
|
|
public struct AutoHammerCost
|
{
|
public int cost;
|
public int exp;
|
}
|
}
|
|