using LitJson;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
|
namespace vnxbqy.UI
|
{
|
//仙盟新增功能
|
public class FairyNewModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
public int affairCount { get; private set; } // 已经完成的事务数量
|
public int affairMaxCount { get; private set; }
|
public int freeRefreshCount { get; private set; }
|
public int freeRefreshMaxCount { get; private set; }
|
public int[] payRefresh;
|
public Dictionary<int, int> allAttrsDict = new Dictionary<int, int>();
|
public bool lvUpSuccess = false;
|
public Dictionary<int, AffairStarInfo> affairStarInfo = new Dictionary<int, AffairStarInfo>(); //星级:时间和奖励
|
public Dictionary<int, FamilyAffair> familyAffairDic = new Dictionary<int, FamilyAffair>();
|
public Dictionary<int, List<int>> useItemsDict = new Dictionary<int, List<int>>();
|
public event Action UpdateFamilyAffairEvent;
|
|
public Dictionary<int, Int2> zhenfaInfo = new Dictionary<int, Int2>();
|
public event Action UpdateFamilyZhenfaEvent;
|
public event Action OnSelectZhenfaEvent;
|
private int m_selectZhenfaType = 0; // 选择的阵眼类型索引 需换算为阵眼类型使用
|
public int selectZhenfaType
|
{
|
get
|
{
|
return m_selectZhenfaType;
|
}
|
set
|
{
|
if (m_selectZhenfaType != value)
|
{
|
m_selectZhenfaType = value;
|
OnSelectZhenfaEvent?.Invoke();
|
}
|
}
|
}
|
|
public int selectItemIndex = 0;
|
|
public int sitRound { get; private set; }
|
public int sitMaxRound { get; private set; }
|
public int roundSeconds = 0; // 打坐一轮所需时间
|
public int[] addExpRateInfo; // 打坐加成经验倍率 | 最高经验加成
|
public bool showSitFinishTip = false;
|
public Dictionary<string, int> sitDungeonInfo = new Dictionary<string, int>();
|
|
private Redpoint affairRedpoint = new Redpoint(10701, 1070112); //历练
|
private Redpoint zhenfaRedpoint = new Redpoint(10701, 1070113); //阵法
|
public Redpoint sitRedpoint = new Redpoint(10701, 1070114); //打坐
|
private List<Redpoint> zhanfaredpoints = new List<Redpoint>();
|
Redpoint zbgRedpoint = new Redpoint(10701, 1070115); //珍宝阁
|
|
//珍宝阁
|
public int zhenbaogeCutState = 0;
|
public int zhenbaogeBuyState = 0;
|
public bool needCheckCutCD = false;
|
public event Action UpdateZhenbaogeEvent;
|
public bool isQueryZBGYet = false;
|
public float lastZBGStartTime = 0; //过天刷新用
|
public const int ZBGFamilyActionType = 16;
|
//{id:数据} 砍价行为,value1为玩家ID,特殊约定为1时为家族的数据
|
public Dictionary<int, HA403_tagGCFamilyActionInfo.tagGCFamilyAction> familyZBGActions = new Dictionary<int, HA403_tagGCFamilyActionInfo.tagGCFamilyAction>();
|
public List<int> sortPlayerCut = new List<int>();
|
public event Action<bool> UpdateFamilyActionEvent;
|
public int zbgPriceType;
|
public int zbgOrgPriceValue;
|
public int zbgChangFamilyCD;
|
public List<int> cutCntListForTalk = new List<int>();
|
|
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
|
|
|
public override void Init()
|
{
|
ParseConfig();
|
PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += OnRefreshFairyInfo;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyMine += OnRefreshFairyMine;//退出仙盟
|
GlobalTimeEvent.Instance.minuteEvent += UpdateRedpoint;
|
foreach (int type in useItemsDict.Keys)
|
{
|
zhanfaredpoints.Add(new Redpoint(1070113, 1070113 * 10 + type));
|
}
|
}
|
|
|
public override void UnInit()
|
{
|
GlobalTimeEvent.Instance.minuteEvent -= UpdateRedpoint;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= OnRefreshFairyInfo;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyMine -= OnRefreshFairyMine;//退出仙盟
|
}
|
|
|
void ParseConfig()
|
{
|
var config = FuncConfigConfig.Get("FamilyAffair");
|
affairMaxCount = int.Parse(config.Numerical1);
|
freeRefreshMaxCount = int.Parse(config.Numerical2);
|
payRefresh = ConfigParse.GetMultipleStr<int>(config.Numerical3);
|
var json = JsonMapper.ToObject(config.Numerical4);
|
var keys = json.Keys.ToList();
|
foreach (var key in keys)
|
{
|
var info = new AffairStarInfo();
|
var json2 = JsonMapper.ToObject(json[key].ToJson());
|
info.times = int.Parse(json2[1].ToString());
|
info.items = JsonMapper.ToObject<int[][]>(json2[2].ToJson());
|
affairStarInfo.Add(int.Parse(key), info);
|
}
|
|
useItemsDict = ConfigParse.ParseJsonDict(FuncConfigConfig.Get("FamilyZhenfa").Numerical1);
|
|
config = FuncConfigConfig.Get("FamilySit");
|
int[] sitInfo = ConfigParse.GetMultipleStr<int>(config.Numerical1);
|
roundSeconds = sitInfo[0];
|
sitMaxRound = sitInfo[1];
|
addExpRateInfo = ConfigParse.GetMultipleStr<int>(config.Numerical3);
|
|
config = FuncConfigConfig.Get("Zhenbaoge");
|
zbgPriceType = int.Parse(config.Numerical1);
|
zbgOrgPriceValue = int.Parse(config.Numerical2);
|
zbgChangFamilyCD = int.Parse(config.Numerical3);
|
cutCntListForTalk = JsonMapper.ToObject<List<int>>(config.Numerical4);
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
freeRefreshCount = 0;
|
familyAffairDic.Clear();
|
zhenfaInfo.Clear();
|
allAttrsDict.Clear();
|
lvUpSuccess = false;
|
sitRound = 0;
|
showSitFinishTip = false;
|
sitDungeonInfo.Clear();
|
isQueryZBGYet = false;
|
familyZBGActions.Clear();
|
sortPlayerCut.Clear();
|
zhenbaogeCutState = 0;
|
zhenbaogeBuyState = 0;
|
needCheckCutCD = false;
|
}
|
|
private void OnRefreshFairyInfo()
|
{
|
if (PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
UpdateRedpoint();
|
QueryZBGFamilyInfo();
|
}
|
|
}
|
|
|
void UpdateRedpoint()
|
{
|
affairRedpoint.state = RedPointState.None;
|
if (!PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
return;
|
}
|
if (affairCount >= affairMaxCount) return;
|
|
foreach (var affair in familyAffairDic)
|
{
|
if (affair.Value.State == 0)
|
{
|
affairRedpoint.state = RedPointState.Simple;
|
return;
|
}
|
else if (affair.Value.State == 1 && TimeUtility.AllSeconds - affair.Value.StartSeconds - affair.Value.RemainDuration >= 0)
|
{
|
affairRedpoint.state = RedPointState.Simple;
|
return;
|
}
|
}
|
}
|
|
|
|
public void UpdateFamilyAffairInfo(HA508_tagMCFamilyAffairInfo netPack)
|
{
|
freeRefreshCount = netPack.RefreshFreeCount;
|
for (int i = 0; i < netPack.Count; i++)
|
{
|
familyAffairDic[netPack.AffairInfoList[i].AffairID] = new FamilyAffair()
|
{
|
StartSeconds = TimeUtility.AllSeconds,
|
Star = netPack.AffairInfoList[i].Star,
|
State = netPack.AffairInfoList[i].State,
|
RemainDuration = netPack.AffairInfoList[i].RemainDuration
|
|
};
|
}
|
affairCount = 0;
|
foreach (var item in familyAffairDic)
|
{
|
if (item.Value.State == 2)
|
{
|
affairCount++;
|
}
|
}
|
|
UpdateFamilyAffairEvent?.Invoke();
|
UpdateRedpoint();
|
}
|
|
|
public struct AffairStarInfo
|
{
|
public int times;
|
public int[][] items;
|
}
|
|
public struct FamilyAffair
|
{
|
public int StartSeconds; // 开始时间
|
public int Star; // 星级
|
public int State; // 状态:0-无;1-进行中;2-已完成
|
public int RemainDuration; // 剩余时长,秒,有剩余时间代表进行中
|
}
|
|
|
#region 阵法
|
|
|
|
|
|
public void UpdateFamilyZhenfaInfo(HA509_tagMCFamilyZhenfaInfo netPack)
|
{
|
for (int i = 0; i < netPack.ZhenfaInfoList.Length; i++)
|
{
|
if (zhenfaInfo.ContainsKey(netPack.ZhenfaInfoList[i].ZhenfaType))
|
{
|
if (zhenfaInfo[netPack.ZhenfaInfoList[i].ZhenfaType].x != netPack.ZhenfaInfoList[i].ZhenfaLV)
|
{
|
lvUpSuccess = true;
|
}
|
}
|
else
|
{
|
lvUpSuccess = true;
|
}
|
zhenfaInfo[netPack.ZhenfaInfoList[i].ZhenfaType] = new Int2(netPack.ZhenfaInfoList[i].ZhenfaLV, (int)netPack.ZhenfaInfoList[i].ZhenfaExp);
|
}
|
|
RefreshAllAttrs();
|
|
if (WindowCenter.Instance.IsOpen<FamilyZhenfaWin>())
|
{
|
UpdateZhenfaRedpoint();
|
}
|
|
UpdateFamilyZhenfaEvent?.Invoke();
|
}
|
|
public int GetZhenyanLV(int type)
|
{
|
if (zhenfaInfo.ContainsKey(type))
|
{
|
return zhenfaInfo[type].x;
|
}
|
return 0;
|
}
|
public int GetZhenyanExp(int type)
|
{
|
if (zhenfaInfo.ContainsKey(type))
|
{
|
return zhenfaInfo[type].y;
|
}
|
return 0;
|
}
|
|
public void RefreshAllAttrs()
|
{
|
allAttrsDict.Clear();
|
foreach (var type in zhenfaInfo.Keys)
|
{
|
var config = FamilyZhenfaConfig.GetConfig(type, zhenfaInfo[type].x);
|
for (int i = 0; i < config.LVAttrType.Length; i++)
|
{
|
var attrType = config.LVAttrType[i];
|
if (!allAttrsDict.ContainsKey(attrType))
|
{
|
allAttrsDict[attrType] = 0;
|
}
|
allAttrsDict[attrType] += config.LVAttrValue[i];
|
}
|
}
|
}
|
|
public Dictionary<int, int> GetAttrsByType(int type)
|
{
|
int lv = 0;
|
if (zhenfaInfo.ContainsKey(type))
|
{
|
lv = zhenfaInfo[type].x;
|
}
|
|
Dictionary<int, int> attrs = new Dictionary<int, int>();
|
var config = FamilyZhenfaConfig.GetConfig(type, lv);
|
for (int i = 0; i < config.LVAttrType.Length; i++)
|
{
|
attrs[config.LVAttrType[i]] = config.LVAttrValue[i];
|
}
|
|
return attrs;
|
}
|
|
public Dictionary<int, int> GetNextAttrsByType(int type)
|
{
|
int lv = 0;
|
if (zhenfaInfo.ContainsKey(type))
|
{
|
lv = zhenfaInfo[type].x;
|
}
|
|
Dictionary<int, int> attrs = new Dictionary<int, int>();
|
var config = FamilyZhenfaConfig.GetConfig(type, lv + 1);
|
if (config == null) return attrs;
|
for (int i = 0; i < config.LVAttrType.Length; i++)
|
{
|
attrs[config.LVAttrType[i]] = config.LVAttrValue[i];
|
}
|
|
return attrs;
|
}
|
|
public void UpdateZhenfaRedpoint()
|
{
|
foreach (var point in zhanfaredpoints)
|
{
|
point.state = RedPointState.None;
|
}
|
if (!PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
return;
|
}
|
foreach (var type in useItemsDict.Keys)
|
{
|
for (int i = 0; i < useItemsDict[type].Count; i++)
|
{
|
if (packModel.GetItemCountByID(PackType.Item, useItemsDict[type][i]) > 0)
|
{
|
zhanfaredpoints[type - 1].state = RedPointState.Simple;
|
continue;
|
}
|
}
|
}
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
UpdateZhenfaRedpoint();
|
UpdateSitRedpoint();
|
UpdateZBGRedpoint();
|
|
if (PlayerDatas.Instance.fairyData.HasFairy)
|
QueryZBGFamilyInfo();
|
}
|
|
#endregion
|
|
#region 打坐
|
|
public void UpdateSitInfo(HA511_tagMCFamilySitInfo netPack)
|
{
|
sitRound = netPack.ExpRound;
|
UpdateSitRedpoint();
|
}
|
|
|
//"sitInfo": {"playerCount": 1, "expPoint": 0, "exp": 4108587, "expRound": 75}
|
public void OnReceiveHelpMessage(string _mission)
|
{
|
var json = JsonMapper.ToObject(_mission);
|
if (json != null && json.Keys.Contains("sitInfo"))
|
{
|
sitDungeonInfo = JsonMapper.ToObject<Dictionary<string, int>>(json["sitInfo"].ToJson());
|
}
|
}
|
|
void UpdateSitRedpoint()
|
{
|
sitRedpoint.state = RedPointState.None;
|
if (!PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
return;
|
}
|
if (sitRound >= sitMaxRound)
|
{
|
return;
|
}
|
|
DailyQuestOpenTime openTime;
|
dailyQuestModel.TryGetOpenTime((int)DailyQuestType.default3, out openTime);
|
if (openTime == null)
|
{
|
return;
|
}
|
if (openTime.InOpenTime())
|
{
|
sitRedpoint.state = RedPointState.Simple;
|
}
|
}
|
#endregion
|
|
#region 珍宝阁
|
|
|
public void UpdateZhenbaogeInfo(HA512_tagMCFamilyZhenbaogeInfo netPack)
|
{
|
//砍价状态:仙盟里记录已砍价才是真的已砍价状态,封包中的砍价状态用于判断cd间隔使用
|
needCheckCutCD = netPack.CutState == 1;
|
zhenbaogeBuyState = netPack.BuyState;
|
UpdateZhenbaogeEvent?.Invoke();
|
UpdateZBGRedpoint();
|
}
|
|
|
|
|
//登录后首次打开查询,换新仙盟查询
|
public void QueryZBGFamilyInfo()
|
{
|
if (isQueryZBGYet)
|
return;
|
|
var pack = new CA408_tagCGQueryFamilyAction();
|
pack.ActionType = 16;
|
pack.FamilyID = PlayerDatas.Instance.baseData.FamilyId;
|
GameNetSystem.Instance.SendInfo(pack);
|
isQueryZBGYet = true;
|
}
|
|
private void OnRefreshFairyMine()
|
{
|
if (!PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
isQueryZBGYet = false;
|
zhenbaogeCutState = 0;
|
familyZBGActions.Clear();
|
sortPlayerCut.Clear();
|
WindowCenter.Instance.Close<FamilyZBGWin>();
|
}
|
|
UpdateZBGRedpoint();
|
}
|
|
public void UpdateZBGRedpoint()
|
{
|
zbgRedpoint.state = RedPointState.None;
|
|
if (!PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
return;
|
}
|
|
if (zhenbaogeCutState == 0)
|
{
|
zbgRedpoint.state = RedPointState.Simple;
|
}
|
}
|
|
public void UpdateFamilyAction(HA403_tagGCFamilyActionInfo vNetData)
|
{
|
if (vNetData.ActionType != ZBGFamilyActionType)
|
{
|
return;
|
}
|
if (vNetData.FamilyID != PlayerDatas.Instance.baseData.FamilyId)
|
{
|
return;
|
}
|
|
bool restart = false;
|
if (vNetData.FamilyActionList.Length == 1 && vNetData.FamilyActionList[0].Value1 == 1)
|
{
|
if (familyZBGActions.ContainsKey(1) && familyZBGActions[1].Time != vNetData.FamilyActionList[0].Time)
|
{
|
familyZBGActions.Clear();
|
sortPlayerCut.Clear();
|
restart = true;
|
}
|
}
|
|
for (int i = 0; i < vNetData.FamilyActionList.Length; i++)
|
{
|
int playerID = (int)vNetData.FamilyActionList[i].Value1;
|
familyZBGActions[playerID] = vNetData.FamilyActionList[i];
|
|
}
|
|
if (familyZBGActions.ContainsKey((int)PlayerDatas.Instance.baseData.PlayerID))
|
{
|
//自己是否已砍价 从列表中查找
|
zhenbaogeCutState = 1;
|
}
|
|
|
sortPlayerCut = familyZBGActions.Keys.ToList();
|
if (sortPlayerCut.Contains(1))
|
sortPlayerCut.Remove(1);
|
sortPlayerCut.Sort((a, b) => { return familyZBGActions[a].Time.CompareTo(familyZBGActions[b].Time); });
|
|
UpdateFamilyActionEvent?.Invoke(restart);
|
UpdateZBGRedpoint();
|
}
|
|
//砍价人数
|
public int GetZBGFamilyActionCount()
|
{
|
return Math.Max(0, familyZBGActions.Count - 1);
|
}
|
|
public int GetTalkState()
|
{
|
int cnt = GetZBGFamilyActionCount();
|
for (int i = 0; i < cutCntListForTalk.Count; i++)
|
{
|
if (cnt < cutCntListForTalk[i])
|
{
|
return i;
|
}
|
}
|
return 0;
|
}
|
|
public int[][] GetZBGItems()
|
{
|
if (!familyZBGActions.ContainsKey(1))
|
return null;
|
|
return JsonMapper.ToObject<int[][]>(familyZBGActions[1].UseData);
|
}
|
|
public void OnZhenbaogeOP(byte type)
|
{
|
var pack = new CA616_tagCMZhenbaogeOP();
|
pack.OpType = type;
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
|
public Dictionary <int , PlayerFairyData.FairyMember> tmpNoCutMembers = new Dictionary<int, PlayerFairyData.FairyMember>();
|
|
//未议价成员
|
public void CalcNoCutMembers()
|
{
|
tmpNoCutMembers.Clear();
|
var fairy = PlayerDatas.Instance.fairyData.fairy;
|
if (fairy == null)
|
{
|
return;
|
}
|
|
foreach(var member in fairy.Member)
|
{
|
if (!familyZBGActions.ContainsKey((int)member.PlayerID))
|
{
|
tmpNoCutMembers[(int)member.PlayerID] = member;
|
}
|
}
|
}
|
|
#endregion
|
}
|
}
|