using System.Collections.Generic;
|
using System.Linq;
|
using LitJson;
|
using System;
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
public class BlessedLandModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
#region 功能配置表相关变量
|
public int refreshItemCount; //每个福地刷新物品个数
|
public int[] itemLevelMaxWorkersArr; //物品等级可用的最大工人数列表 [1级最大人数, 2级, ...]
|
public int[] workerFatigueStaminaArr; //工人疲劳状态体力列表 [充沛体力, 正常, 虚弱, 枯竭],总体力=所有体力相加 状态值 0-充沛;1-正常;2-虚弱;3-枯竭
|
public int hiredWorkerItemID; //雇佣工人所需道具物品ID
|
public int[] hiredWorkerItemQuantityArr; //雇佣工人所需道具物品个数列表[第1个所需个数, ...]
|
public Dictionary<int, List<int>> refreshTypeCostCurrencyValueDict; //刷新类型消耗货币类型|货币值 {"刷新类型":[货币类型, 货币值], ...}
|
public Dictionary<int, int> refreshTypeDailyLimitDict; //刷新类型每日次数上限,0不限 {"刷新类型":次数上限, ...}
|
public int superRefreshDefaultSpecialItemOutputDurationSeconds; //超级刷新默认产出1个特殊物品有效时长秒,时间到后没有采集则消失 特殊物品设定 - 满级物品,默认自己可采,取消后消失,时间到没采也消失
|
public int surroundCooldownS; //刷新周围福地CD,秒
|
public int allyHelpCooldownS; //仙盟摇人CD,秒
|
public int friendHelpCooldownS; //好友摇人CD,秒
|
public int[][] rechargeIDListForActivatingTreasureBowlArr; //可激活聚宝盆充值ID列表 [[类型0充值ID], ...] ,配空[]的默认激活
|
public int[][][] rewardForFullProgressInTreasureBowlArr; //聚宝盆满进度时对应奖励 [[[类型0奖励物品ID,个数,是否拍品], ...], [[类型1奖励物品ID,个数,是否拍品], ...], ...]
|
public Dictionary<int, string> TreasureBowlNameDict; //聚宝盆名称
|
public int[] TreasureBowlSchedule; //聚宝盆进度
|
public int[] TreasureBowlRebate; //聚宝盆返利
|
public int maxHelpCount; //每日可获得帮助奖励次数
|
public int[][] helpAwardArr; //帮助成功奖励物品列表 [[物品ID,个数,是否拍品], ...]
|
#endregion
|
#region 封包相关变量
|
//封包相关
|
//B030玩家福地相关信息
|
public int WorkerCount; // 已雇佣工人数
|
public int EnergyUsed; // 今日已消耗体力
|
public int RefreshCount; // 今日福地刷新物品次数 - 普通刷新
|
public int RefreshCountSuper; // 今日福地刷新物品次数 - 超级刷新
|
public int TreasureCount; // 聚宝盆类型个数,对应类型 0~n
|
public int[] TreasureState; // 聚宝盆是否已激活列表,[类型0是否已激活, ...]
|
public int[] TreasureAward; // 聚宝盆奖励是否已领取列表,[类型0是否已领取, ...]
|
public int[] TreasureProgress; // 聚宝盆进度值列表,[类型0进度值, ...],满进度100
|
public int HelpAwardCount; // 今日已帮助别人奖励次数
|
//B032 福地物品拉预览结果
|
public uint PlayerID; // 福地所属玩家ID,0默认自己
|
public byte ItemIndex; // 物品所在位置索引0~n
|
public byte WorkerPreviewCount; // 上工人预览人数
|
public uint NeedSeconds; // 预计需要时间,秒
|
//B033 福地详细信息
|
//最新福地详细信息 玩家ID 福地详细信息
|
public Dictionary<uint, MineAreaInfo> newAreaDataDict = new Dictionary<uint, MineAreaInfo>();
|
//type :playerids
|
public Dictionary<int, List<uint>> typeToPlayerIDs = new Dictionary<int, List<uint>>();
|
//B034奖励结算相关信息
|
public byte AwardType; // 0-通知有奖励,前端下次进入福地可请求进行结算;1-结算奖励结果通知
|
public byte AwardLen;
|
public string AwardInfo; //奖励信息 [物品ID,个数,是否拍品], ...]
|
//B035 福地记录信息
|
public List<MineAreaRecord> mineAreaRecordList = new List<MineAreaRecord>();
|
#endregion
|
|
public uint showPlayerId; //当前展示福地的PlayerId
|
public int cornucopiaIndex = 0; //当前展示的是哪个聚宝盆 默认展示第0个
|
public byte detailsIndex = 0; //显示指定index的资源详情
|
public uint helpType = 0; //驱赶界面显示状态 0 自己主动驱逐 1 帮助别人驱逐
|
public uint helpPlayerId; //要帮助谁
|
public uint robPlayerId; //要驱赶谁
|
public uint helpItemIndex; //帮助目标的物品索引
|
public uint myPlayerId; //我的playerId
|
public bool isWin = false;
|
public bool isStart = false;
|
public bool isSkipLv4Tip = false; //本次登录是否跳过存在四级物品二次确认窗口
|
public bool isSkipRefreshTip = false; //本次登录是否跳过普通刷新二次确认窗口
|
public int lastSurroundRefreshTime; //上次点击寻觅刷新按钮的时间
|
public int lastAllyHelpRefreshTime; //上次点击仙盟摇人按钮的时间
|
public int lastFriendHelpRefreshTime; //上次点击好友摇人按钮的时间
|
public event Action<List<uint>> UpdateNewAreaData;
|
public event Action UpdateOtherAreaData;
|
public event Action UpdateFellowAndSurroundAreaData;
|
public event Action UpdateFindAreaData;
|
public event Action UpdateRecordInfo;
|
public event Action UpdatePullPreviewMine;
|
public Action UpdateMineAreaData;
|
public event Action UpdateTurnFightStateInfo;
|
Redpoint mainRedPoint = new Redpoint(MainRedDot.FAIRY_REDPOINT_KEY2, MainRedDot.BlessedLandRedpoint); //福地入口红点
|
Redpoint manageRedPoint = new Redpoint(MainRedDot.BlessedLandRedpoint, MainRedDot.BlessedLandRedpoint * 10 + 1); //管理按钮红点
|
Redpoint employRedPoint = new Redpoint(MainRedDot.BlessedLandRedpoint * 10 + 1, MainRedDot.BlessedLandRedpoint * 10 + 2); //雇佣按钮红点
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
public override void Init()
|
{
|
#region 读取功能配置表中福地相关数据
|
refreshItemCount = int.Parse(FuncConfigConfig.Get("MineAreaBase").Numerical1);
|
itemLevelMaxWorkersArr = JsonMapper.ToObject<int[]>(FuncConfigConfig.Get("MineAreaBase").Numerical3);
|
workerFatigueStaminaArr = JsonMapper.ToObject<int[]>(FuncConfigConfig.Get("MineAreaWorker").Numerical1);
|
hiredWorkerItemID = int.Parse(FuncConfigConfig.Get("MineAreaWorker").Numerical2);
|
hiredWorkerItemQuantityArr = JsonMapper.ToObject<int[]>(FuncConfigConfig.Get("MineAreaWorker").Numerical3);
|
refreshTypeCostCurrencyValueDict = new Dictionary<int, List<int>>();
|
refreshTypeDailyLimitDict = new Dictionary<int, int>();
|
var jsonData = JsonMapper.ToObject(FuncConfigConfig.Get("MineAreaRefresh").Numerical1);
|
List<string> keyList = jsonData.Keys.ToList();
|
for (int i = 0; i < keyList.Count; i++)
|
{
|
refreshTypeCostCurrencyValueDict.Add(int.Parse(keyList[i]), JsonMapper.ToObject<List<int>>(jsonData[keyList[i]].ToJson()));
|
}
|
jsonData = JsonMapper.ToObject(FuncConfigConfig.Get("MineAreaRefresh").Numerical2);
|
keyList = jsonData.Keys.ToList();
|
for (int i = 0; i < keyList.Count; i++)
|
{
|
refreshTypeDailyLimitDict[int.Parse(keyList[i])] = int.Parse(jsonData[keyList[i]].ToString());
|
}
|
superRefreshDefaultSpecialItemOutputDurationSeconds = int.Parse(FuncConfigConfig.Get("MineAreaSuperItem").Numerical1);
|
surroundCooldownS = int.Parse(FuncConfigConfig.Get("MineAreaRob").Numerical3);
|
allyHelpCooldownS = int.Parse(FuncConfigConfig.Get("MineAreaRob").Numerical4);
|
friendHelpCooldownS = int.Parse(FuncConfigConfig.Get("MineAreaRob").Numerical5);
|
rechargeIDListForActivatingTreasureBowlArr = JsonMapper.ToObject<int[][]>(FuncConfigConfig.Get("MineAreaTreasure").Numerical1);
|
rewardForFullProgressInTreasureBowlArr = JsonMapper.ToObject<int[][][]>(FuncConfigConfig.Get("MineAreaTreasure").Numerical3);
|
jsonData = JsonMapper.ToObject(FuncConfigConfig.Get("MineAreaTreasure").Numerical4);
|
keyList = jsonData.Keys.ToList();
|
TreasureBowlNameDict = new Dictionary<int, string>();
|
for (int i = 0; i < keyList.Count; i++)
|
{
|
TreasureBowlNameDict[int.Parse(keyList[i])] = jsonData[keyList[i]].ToString();
|
}
|
TreasureBowlSchedule = JsonMapper.ToObject<int[]>(FuncConfigConfig.Get("MineAreaTreasure").Numerical2);
|
TreasureBowlRebate = JsonMapper.ToObject<int[]>(FuncConfigConfig.Get("MineAreaTreasure").Numerical5);
|
maxHelpCount = int.Parse(FuncConfigConfig.Get("MineAreaHelp").Numerical1);
|
helpAwardArr = JsonMapper.ToObject<int[][]>(FuncConfigConfig.Get("MineAreaHelp").Numerical2);
|
#endregion
|
packModel.refreshItemCountEvent += OnRefreshItem;
|
RoleParticularModel.OnRevPackage += OnRevPackage;
|
}
|
|
public override void UnInit()
|
{
|
packModel.refreshItemCountEvent -= OnRefreshItem;
|
RoleParticularModel.OnRevPackage -= OnRevPackage;
|
}
|
|
void OnRefreshItem(PackType packType, int index, int itemID)
|
{
|
if (packType == PackType.Item && itemID == hiredWorkerItemID)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
void OnRevPackage(int viewType, int playerID, RoleParticularModel.ViewPlayerData data)
|
{
|
if (viewType != (int)ViewPlayerType.viewCrossPlayerDataBlessedLand)
|
{
|
return;
|
}
|
|
if (!WindowCenter.Instance.IsOpen<BlessedLandPKWin>())
|
{
|
WindowJumpMgr.Instance.WindowJumpToEx("BlessedLandPKWin");
|
}
|
}
|
|
void UpdateRedpoint()
|
{
|
mainRedPoint.state = RedPointState.None;
|
manageRedPoint.state = RedPointState.None;
|
employRedPoint.state = RedPointState.None;
|
int haveCount = packModel.GetItemCountByID(PackType.Item, hiredWorkerItemID);
|
int needCount = WorkerCount > hiredWorkerItemQuantityArr.Length - 1 ? hiredWorkerItemQuantityArr.Length - 1 : hiredWorkerItemQuantityArr[WorkerCount];
|
mainRedPoint.state = WorkerCount - GetWorkingCount() == 0 ? RedPointState.None : RedPointState.Simple;
|
employRedPoint.state = WorkerCount >= hiredWorkerItemQuantityArr.Length ? RedPointState.None : haveCount >= needCount ? RedPointState.Simple : RedPointState.None;
|
}
|
|
//获得超级刷新还能用几次
|
public int GetResdueSuperRefreshCount()
|
{
|
return refreshTypeDailyLimitDict[1] - RefreshCountSuper;
|
}
|
|
//将HB033转化为Dictionary<uint, MineAreaInfo>类型的字典 type 0 在先有字典上更新 1 重头生成
|
public Dictionary<uint, MineAreaInfo> ProcessHB033(HB033_tagGCMineAreaInfo source, Dictionary<uint, MineAreaInfo> tempDict, int type)
|
{
|
for (int i = 0; i < source.AreaList.Length; i++)
|
{
|
var area = source.AreaList[i];
|
// 检查是否已存在该PlayerID的MineAreaInfo
|
if (tempDict.ContainsKey(area.PlayerID))
|
{
|
// 更新现有的MineAreaInfo对象
|
var existingAreaInfo = tempDict[area.PlayerID];
|
existingAreaInfo.PlayerName = area.PlayerName;
|
existingAreaInfo.Job = area.Job;
|
existingAreaInfo.Face = area.Face;
|
existingAreaInfo.FacePic = area.FacePic;
|
existingAreaInfo.MineCount = area.MineCount;
|
|
// 更新字典的MineItems
|
for (int j = 0; j < area.MineItemList.Length; j++)
|
{
|
var item = area.MineItemList[j];
|
var itemInfo = new MineItemInfo
|
{
|
Index = item.Index,
|
MineID = item.MineID,
|
MineType = item.MineType,
|
UpdTime = item.UpdTime,
|
Position = item.Position,
|
MoveSpeed = item.MoveSpeed,
|
EndTime = item.EndTime,
|
WorkerCount = item.WorkerCount,
|
RobPlayerID = item.RobPlayerID,
|
RobWorkerCount = item.RobWorkerCount,
|
RobPlayerName = item.RobPlayerName,
|
RobFace = item.RobFace,
|
RobJob = item.RobJob,
|
RobFacePic = item.RobFacePic,
|
};
|
// 使用Index作为键值
|
existingAreaInfo.MineItems[item.Index] = itemInfo;
|
}
|
}
|
else
|
{
|
// 创建新的MineAreaInfo对象
|
var newAreaInfo = new MineAreaInfo
|
{
|
PlayerID = area.PlayerID,
|
PlayerName = area.PlayerName,
|
Job = area.Job,
|
Face = area.Face,
|
FacePic = area.FacePic,
|
MineCount = area.MineCount,
|
MineItems = new Dictionary<int, MineItemInfo>()
|
};
|
|
for (int k = 0; k < area.MineItemList.Length; k++)
|
{
|
var item = area.MineItemList[k];
|
var itemInfo = new MineItemInfo
|
{
|
Index = item.Index,
|
MineID = item.MineID,
|
MineType = item.MineType,
|
UpdTime = item.UpdTime,
|
Position = item.Position,
|
MoveSpeed = item.MoveSpeed,
|
EndTime = item.EndTime,
|
WorkerCount = item.WorkerCount,
|
RobPlayerID = item.RobPlayerID,
|
RobWorkerCount = item.RobWorkerCount,
|
RobPlayerName = item.RobPlayerName,
|
RobFace = item.RobFace,
|
RobJob = item.RobJob,
|
RobFacePic = item.RobFacePic,
|
};
|
// 使用Index作为键值
|
newAreaInfo.MineItems.Add(item.Index, itemInfo);
|
}
|
tempDict.Add(area.PlayerID, newAreaInfo);
|
}
|
}
|
return tempDict;
|
}
|
|
|
public List<uint> ProcessHB033PlayerIDs(HB033_tagGCMineAreaInfo source)
|
{
|
List<uint> tmpList = new List<uint>();
|
for (int i = 0; i < source.AreaList.Length; i++)
|
{
|
var area = source.AreaList[i];
|
tmpList.Add(area.PlayerID);
|
}
|
return tmpList;
|
}
|
|
//获得自己福地当前Cell的显示状态
|
//0 无物品 1 有物品-超级物品-无人拉 2 有物品-超级物品-自己拉
|
//3 有物品-普通物品-无人拉 4 有物品-普通物品-自己拉 5 有物品-普通物品-对方拉
|
//6 有物品-普通物品-双方拉-向自己移动 7 有物品-普通物品-双方拉-向对方移动
|
public int GetMyBlessedLandCellState(int index)
|
{
|
MineItemInfo mineItem = newAreaDataDict[myPlayerId].MineItems[index];
|
|
if (mineItem.MineID == 0) //没有物品
|
return 0;
|
|
if (mineItem.MineType == 1) //是超级物品
|
return mineItem.WorkerCount > 0 ? 2 : 1; //自己是否拉取
|
|
if (mineItem.WorkerCount > 0) //自己有拉普通物品
|
{
|
if (mineItem.RobWorkerCount > 0)//有抢夺者
|
{
|
return mineItem.WorkerCount >= mineItem.RobWorkerCount ? 6 : 7; //移动方向
|
}
|
else
|
{
|
return 4;
|
}
|
}
|
else
|
{
|
return mineItem.RobWorkerCount > 0 ? 5 : 3;
|
}
|
}
|
|
//获得他人福地当前Cell的显示状态
|
//0 无物品 1 有物品-超级物品-无人拉 2 有物品-超级物品-房主拉
|
//3 有物品-普通物品-无人拉 4 有物品-普通物品-房主拉 5 有物品-普通物品-玩家拉 6 有物品-普通物品-别人拉
|
//7 有物品-普通物品-房主和玩家抢-向房主移动 8 有物品-普通物品-房主和玩家抢-向玩家移动
|
//9 有物品-普通物品-房主和别人抢-向房主移动 10 有物品-普通物品-房主和别人抢-向别人移动
|
public int GetOtherBlessedLandCellState(int index)
|
{
|
MineItemInfo mineItems = newAreaDataDict[showPlayerId].MineItems[index];
|
if (mineItems.MineID == 0) // 无物品
|
return 0;
|
if (mineItems.MineType == 1) //是超级物品
|
return mineItems.WorkerCount > 0 ? 2 : 1; //房主是否拉取
|
|
if (mineItems.WorkerCount > 0) //房主拉普通物品
|
{
|
if (mineItems.RobWorkerCount > 0) //有抢夺者
|
{
|
if (mineItems.RobPlayerID == myPlayerId) //抢夺者是玩家
|
{
|
return mineItems.WorkerCount >= mineItems.RobWorkerCount ? 7 : 8; //移动方向
|
}
|
else
|
{
|
return mineItems.WorkerCount >= mineItems.RobWorkerCount ? 9 : 10;
|
}
|
}
|
else
|
{
|
return 4;
|
}
|
}
|
else
|
{
|
if (mineItems.RobWorkerCount > 0) //有抢夺者
|
{
|
return mineItems.RobPlayerID == myPlayerId ? 5 : 6;//抢夺者是玩家
|
}
|
else
|
{
|
return 3;
|
}
|
}
|
}
|
|
//获得福地管理当前Cell的显示状态
|
//1 自己福地-有超级物品-自己拉 2 自己福地-有普通物品-自己拉
|
//3 自己福地-有普通物品-自己和其他玩家抢-向自己移动 4 自己福地-有普通物品-自己和其他玩家抢-向对方移动
|
//5 别人福地-有普通物品-自己抢
|
//6 别人福地-有普通物品-房主和玩家抢-向房主移动 7 别人福地-有普通物品-房主和玩家抢-向玩家移动
|
public int GetManageCellState(int playerId, int index)
|
{
|
var mineItems = newAreaDataDict[(uint)playerId].MineItems[index];
|
if (playerId == myPlayerId)
|
{
|
if (mineItems.MineType == 1)
|
return 1;
|
|
if (mineItems.RobWorkerCount > 0)//有抢夺者
|
{
|
return mineItems.WorkerCount >= mineItems.RobWorkerCount ? 3 : 4; //移动方向
|
}
|
else
|
{
|
return 2;
|
}
|
}
|
else
|
{
|
if (mineItems.WorkerCount > 0) //房主有防守
|
{
|
return mineItems.WorkerCount >= mineItems.RobWorkerCount ? 6 : 7; //移动方向
|
}
|
else
|
{
|
return 5;
|
}
|
}
|
}
|
|
//获得福地记录当前Cell的显示状态 0 自己拉自己的 1 自己拉别人的 2 别人抢我的
|
public int GetRecordState(int index)
|
{
|
if (mineAreaRecordList[index].RecordType == 2)
|
return 2;
|
if (mineAreaRecordList[index].TagPlayerID == myPlayerId)
|
return 0;
|
return 1;
|
}
|
|
//获得当前聚宝盆的显示状态 0 未激活 1 已激活-不能领 2 已激活-可领取 3已激活-已领取
|
public int GetCornucopiaState()
|
{
|
if (TreasureState[cornucopiaIndex] == 1) //是否激活
|
{
|
if (TreasureAward[cornucopiaIndex] == 1) //是否获得
|
{
|
return 3;
|
}
|
else
|
{
|
return TreasureProgress[cornucopiaIndex] == 100 ? 2 : 1; //是否可领
|
}
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
|
//自己的福地当前能否进行刷新 0普通刷新 1超级刷新
|
public bool IsRefresh(int type)
|
{
|
if (type == 0)
|
{
|
//需要的货币不够
|
if (UIHelper.GetMoneyCnt(refreshTypeCostCurrencyValueDict[0][0]) < (ulong)refreshTypeCostCurrencyValueDict[0][1])
|
return false;
|
return true;
|
}
|
else
|
{
|
//超级刷新超出了每日刷新次数上限
|
if (RefreshCountSuper >= refreshTypeDailyLimitDict[1])
|
return false;
|
|
//需要的货币不够
|
if (UIHelper.GetMoneyCnt(refreshTypeCostCurrencyValueDict[1][0]) < (ulong)refreshTypeCostCurrencyValueDict[1][1])
|
return false;
|
return true;
|
}
|
}
|
|
//得到冷却结束时间 0 寻觅刷新按钮 1 仙盟摇人按钮 2 好友摇人按钮
|
public int GetCoolDownEndTime(int type)
|
{
|
DateTime overTime;
|
if (type == 0)
|
{
|
if (lastSurroundRefreshTime == 0)
|
return 0;
|
overTime = TimeUtility.GetTime((uint)(lastSurroundRefreshTime + surroundCooldownS));
|
}
|
else if (type == 1)
|
{
|
if (lastAllyHelpRefreshTime == 0)
|
return 0;
|
overTime = TimeUtility.GetTime((uint)(lastAllyHelpRefreshTime + allyHelpCooldownS));
|
}
|
else if (type == 2)
|
{
|
if (lastFriendHelpRefreshTime == 0)
|
return 0;
|
overTime = TimeUtility.GetTime((uint)(lastFriendHelpRefreshTime + friendHelpCooldownS));
|
}
|
else
|
{
|
return 0;
|
}
|
if (TimeUtility.ServerNow > overTime)
|
return 0;
|
return (int)(overTime - TimeUtility.ServerNow).TotalSeconds;
|
}
|
//记录时间显示 如果是当天的显示时:分 昨天的显示昨天 前天的显示前天 更早的显示x天前
|
public string GetTimeDisplay(uint recordTime)
|
{
|
// 使用TimeUtility中定义的OriginalTime
|
DateTime recordDateTime = TimeUtility.OriginalTime.AddSeconds(recordTime);
|
TimeSpan timeDifference = TimeUtility.ServerNow.Date - recordDateTime.Date;
|
int daysDifference = timeDifference.Days;
|
|
if (daysDifference == 0) // 今天
|
{
|
return recordDateTime.ToString("H:mm"); // 显示时:分
|
}
|
else if (daysDifference == 1) // 昨天
|
{
|
return Language.Get("BlessedLand029");
|
}
|
else if (daysDifference == 2) // 前天
|
{
|
return Language.Get("BlessedLand030");
|
}
|
else // 更早
|
{
|
return Language.Get("BlessedLand031", daysDifference);
|
}
|
}
|
//当前有多少工作中的工人
|
public int GetWorkingCount()
|
{
|
int result = 0;
|
List<uint> KeyList = newAreaDataDict.Keys.ToList();
|
for (int i = 0; i < KeyList.Count; i++)
|
{
|
uint key = KeyList[i];
|
MineAreaInfo originalMineAreaInfo = newAreaDataDict[key];
|
if (originalMineAreaInfo.PlayerID == myPlayerId)
|
{
|
List<int> itemKeys = originalMineAreaInfo.MineItems.Keys.ToList();
|
for (int j = 0; j < itemKeys.Count; j++)
|
{
|
int itemKey = itemKeys[j];
|
MineItemInfo originalMineItemInfo = originalMineAreaInfo.MineItems[itemKey];
|
result += originalMineItemInfo.WorkerCount;
|
}
|
}
|
else
|
{
|
List<int> itemKeys = originalMineAreaInfo.MineItems.Keys.ToList();
|
for (int j = 0; j < itemKeys.Count; j++)
|
{
|
int itemKey = itemKeys[j];
|
MineItemInfo originalMineItemInfo = originalMineAreaInfo.MineItems[itemKey];
|
if (originalMineAreaInfo.MineItems[itemKey].RobPlayerID == myPlayerId)
|
{
|
result += originalMineItemInfo.RobWorkerCount;
|
}
|
}
|
}
|
}
|
return result;
|
}
|
|
//当前福地的指定资源当前有多少派遣中的工人
|
public int GetItemWorkingCount(uint playerId, int index)
|
{
|
if (playerId == myPlayerId)
|
{
|
return newAreaDataDict[playerId].MineItems[index].WorkerCount;
|
}
|
else
|
{
|
if (newAreaDataDict[playerId].MineItems[index].RobPlayerID == myPlayerId)
|
{
|
return newAreaDataDict[playerId].MineItems[index].RobWorkerCount;
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
}
|
|
//在当前这个人福地是否除了当前选中的资源以外是否有在当前这个人其他资源
|
public bool IsSnatchItem()
|
{
|
var mineItems = newAreaDataDict[showPlayerId].MineItems;
|
for (int i = 0; i < mineItems.Count; i++)
|
{
|
if (mineItems[i].RobPlayerID == myPlayerId)
|
{
|
if (mineItems[i].Index == detailsIndex)
|
continue;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
//将byte[]转成int[]
|
int[] ConvertByteArrayToIntArray(byte[] byteArray)
|
{
|
int[] intArray = new int[byteArray.Length];
|
for (int i = 0; i < byteArray.Length; i++)
|
{
|
intArray[i] = byteArray[i];
|
}
|
return intArray;
|
}
|
|
//返回假人名字
|
public string GetNameForPlayerId(int playerId)
|
{
|
if (playerId == 0)
|
return StringUtility.Contact(RandomNameConfig.Get(1).RandomName1, RandomNameConfig.Get(1).RandomName2);
|
return StringUtility.Contact(RandomNameConfig.Get(playerId % 797).RandomName1, RandomNameConfig.Get(playerId % 1793).RandomName2);
|
}
|
|
//返回假人头像
|
public AvatarModel GetModelForPlayerId(int playerId)
|
{
|
int[] numbers = { 1, 2 };
|
return AvatarHelper.GetDefaultAvatarModel(numbers[playerId % 2]);
|
}
|
|
//获得工人体力一共有多少
|
public int GetTotalEnergy()
|
{
|
int totalEnergy = 0;
|
for (int i = 0; i < workerFatigueStaminaArr.Length; i++)
|
{
|
totalEnergy += workerFatigueStaminaArr[i];
|
}
|
return totalEnergy;
|
}
|
|
//检查当前我的福地上是否存在大于等于4级的物品且没有被我方拉取
|
public bool IsGreaterLv4Item()
|
{
|
if (!newAreaDataDict.ContainsKey(myPlayerId))
|
return false;
|
var MineItems = newAreaDataDict[myPlayerId].MineItems;
|
var keyList = MineItems.Keys.ToList();
|
for (int i = 0; i < keyList.Count; i++)
|
{
|
|
int mineID = MineItems[keyList[i]].MineID;
|
if (mineID == 0 || !MineAreaItemConfig.GetKeys().Contains(mineID.ToString()))
|
continue;
|
int itemLV = MineAreaItemConfig.Get(mineID).ItemLV;
|
if (itemLV >= 4)
|
{
|
if (MineItems[keyList[i]].WorkerCount > 0 && MineItems[keyList[i]].WorkerCount >= MineItems[keyList[i]].RobWorkerCount)
|
return false;
|
return true;
|
}
|
|
}
|
return false;
|
}
|
|
public void SendCA504Pack(byte rewardType, uint dataEx, byte dataExStrLen = 0, string dataExStr = "")
|
{
|
var pack = new CA504_tagCMPlayerGetReward()
|
{
|
RewardType = rewardType,
|
DataEx = dataEx,
|
DataExStrLen = dataExStrLen,
|
DataExStr = dataExStr
|
};
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
public void SendCB030Pack(uint playerId, byte itemIndex, byte workerCount, byte isPreview)
|
{
|
var pak = new CB030_tagCMMineItemPull
|
{
|
PlayerID = playerId,
|
ItemIndex = itemIndex,
|
WorkerCount = workerCount,
|
IsPreview = isPreview
|
};
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
public void SendCB031Pack(byte isSuper)
|
{
|
var pack = new CB031_tagCMMineItemRefresh()
|
{
|
IsSuper = isSuper
|
};
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
public void SendCB032Pack()
|
{
|
var pack = new CB032_tagCMMineWorkerEmploy();
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
public void SendCB033Pack(byte queryType, uint queryValue = 0)
|
{
|
var pack = new CB033_tagCGMineAreaView()
|
{
|
QueryType = queryType,
|
QueryValue = queryValue
|
};
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
public void SendCB034Pack()
|
{
|
var pack = new CB034_tagCGMineAreaAwardGet();
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
public void SendCB410Pack(uint mapID, ushort funcLineID, byte tagType, uint tagID, uint[] valueList)
|
{
|
var pack = new CB410_tagCMTurnFight();
|
pack.MapID = mapID;
|
pack.FuncLineID = funcLineID;
|
pack.TagType = tagType;
|
pack.TagID = tagID;
|
pack.ValueCount = (byte)valueList.Length;
|
pack.ValueList = valueList;
|
GameNetSystem.Instance.SendInfo(pack);
|
//TurnFightModel.Instance.StartTurnFight((int)mapID, funcLineID, 1, (int)playerID, valueList);
|
}
|
|
public void UpdateDetailedBlessedLandPullPreviewRet(HB032_tagGCMineItemPullPreviewRet vNetData)
|
{
|
PlayerID = vNetData.PlayerID;
|
ItemIndex = vNetData.ItemIndex;
|
WorkerPreviewCount = vNetData.WorkerCount;
|
NeedSeconds = vNetData.NeedSeconds;
|
UpdatePullPreviewMine?.Invoke();
|
}
|
|
public void UpdateMineAreaRecordInfo(HB035_tagGCMineAreaRecordInfo vNetData)
|
{
|
mineAreaRecordList.Clear();
|
var vNetList = vNetData.AreaRecordList;
|
for (int i = 0; i < vNetList.Length; i++)
|
{
|
MineAreaRecord tempMineAreaRecord = new MineAreaRecord();
|
tempMineAreaRecord.RecordType = vNetList[i].RecordType;
|
tempMineAreaRecord.TagPlayerID = vNetList[i].TagPlayerID;
|
tempMineAreaRecord.RecordTime = vNetList[i].RecordTime;
|
tempMineAreaRecord.MineID = vNetList[i].MineID;
|
tempMineAreaRecord.TagPlayerName = vNetList[i].TagPlayerName;
|
tempMineAreaRecord.TagJob = vNetList[i].TagJob;
|
tempMineAreaRecord.TagFace = vNetList[i].TagFace;
|
tempMineAreaRecord.TagFacePic = vNetList[i].TagFacePic;
|
mineAreaRecordList.Add(tempMineAreaRecord);
|
}
|
UpdateRecordInfo?.Invoke();
|
|
}
|
|
public void UpdateMineAreaAwardInfo(HB034_tagGCMineAreaAwardInfo vNetData)
|
{
|
AwardType = vNetData.AwardType;
|
AwardLen = vNetData.AwardLen;
|
AwardInfo = vNetData.AwardInfo;
|
|
if (AwardType == 0)
|
{
|
//必须在任意福地窗口打开的前提下才能领取奖励
|
if (WindowCenter.Instance.IsOpen<BlessedLandCornucopiaWin>() || WindowCenter.Instance.IsOpen<BlessedLandDetailsWin>() ||
|
WindowCenter.Instance.IsOpen<BlessedLandManageWin>() || WindowCenter.Instance.IsOpen<BlessedLandOtherWin>() ||
|
WindowCenter.Instance.IsOpen<BlessedLandPKWin>() || WindowCenter.Instance.IsOpen<BlessedLandRecordWin>() ||
|
WindowCenter.Instance.IsOpen<BlessedLandSeekWin>() || WindowCenter.Instance.IsOpen<BlessedLandWin>())
|
{
|
SendCB034Pack();
|
}
|
}
|
else if (AwardType == 1)
|
{
|
List<Item> itemList = new List<Item>();
|
int[][] AwardArr = JsonMapper.ToObject<int[][]>(vNetData.AwardInfo);
|
if (AwardArr.IsNullOrEmpty())
|
return;
|
itemList.Clear();
|
for (int i = 0; i < AwardArr.Length; i++)
|
{
|
itemList.Add(new Item(AwardArr[i][0], AwardArr[i][1]));
|
}
|
ItemLogicUtility.Instance.ShowGetItem(itemList, "", 5, "", () =>
|
{
|
LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(28, hiredWorkerItemID, hiredWorkerItemQuantityArr[Mathf.Min(WorkerCount, hiredWorkerItemQuantityArr.Length - 1)], 1, 0);
|
}, true);
|
}
|
|
}
|
|
public void UpdatePlayerTerritoryBlessedLandInformation(HB030_tagMCPlayerMineAreaInfo info)
|
{
|
WorkerCount = info.WorkerCount;
|
EnergyUsed = info.EnergyUsed;
|
RefreshCount = (int)info.RefreshCount;
|
RefreshCountSuper = info.RefreshCountSuper;
|
TreasureCount = info.TreasureCount;
|
TreasureState = ConvertByteArrayToIntArray(info.TreasureState);
|
TreasureAward = ConvertByteArrayToIntArray(info.TreasureAward);
|
TreasureProgress = ConvertByteArrayToIntArray(info.TreasureProgress);
|
HelpAwardCount = info.HelpAwardCount;
|
UpdateMineAreaData?.Invoke();
|
UpdateRedpoint();
|
}
|
|
public void UpdateDetailedBlessedLandInformation(HB033_tagGCMineAreaInfo source)
|
{
|
int QueryType = source.QueryType;
|
List<uint> playerIdList = new List<uint>();
|
for (int i = 0; i < source.AreaList.Length; i++)
|
{
|
uint playerId = source.AreaList[i].PlayerID;
|
if (!playerIdList.Contains(playerId))
|
{
|
playerIdList.Add(playerId);
|
}
|
}
|
|
newAreaDataDict = ProcessHB033(source, newAreaDataDict, 0);
|
|
switch (source.QueryType)
|
{
|
case 0:
|
UpdateNewAreaData?.Invoke(playerIdList);
|
UpdateRedpoint();
|
break;
|
case 1:
|
UpdateNewAreaData?.Invoke(playerIdList);
|
UpdateFindAreaData?.Invoke();
|
break;
|
case 2:
|
typeToPlayerIDs[2] = ProcessHB033PlayerIDs(source);
|
UpdateFellowAndSurroundAreaData?.Invoke();
|
break;
|
case 3:
|
typeToPlayerIDs[3] = ProcessHB033PlayerIDs(source);
|
UpdateFellowAndSurroundAreaData?.Invoke();
|
break;
|
}
|
}
|
|
//0 寻觅刷新按钮 1 仙盟摇人按钮 2 好友摇人按钮
|
public void SetTime(int type)
|
{
|
if (type == 0)
|
{
|
lastSurroundRefreshTime = TimeUtility.AllSeconds;
|
}
|
else if (type == 1)
|
{
|
lastAllyHelpRefreshTime = TimeUtility.AllSeconds;
|
}
|
else if (type == 2)
|
{
|
lastFriendHelpRefreshTime = TimeUtility.AllSeconds;
|
}
|
}
|
|
public void SaveAllTime()
|
{
|
int[] arr = new int[3];
|
arr[0] = lastSurroundRefreshTime;
|
arr[1] = lastAllyHelpRefreshTime;
|
arr[2] = lastFriendHelpRefreshTime;
|
LocalSave.SetIntArray(StringUtility.Contact("xshl_", myPlayerId), arr);
|
}
|
|
public void LoadAllTime()
|
{
|
int[] arr = LocalSave.GetIntArray(StringUtility.Contact("xshl_", myPlayerId));
|
if (arr != null && arr.Length == 3)
|
{
|
lastSurroundRefreshTime = arr[0];
|
lastAllyHelpRefreshTime = arr[1];
|
lastFriendHelpRefreshTime = arr[2];
|
}
|
else
|
{
|
lastSurroundRefreshTime = 0;
|
lastAllyHelpRefreshTime = 0;
|
lastFriendHelpRefreshTime = 0;
|
}
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
WorkerCount = 0;
|
EnergyUsed = 0;
|
RefreshCount = 0;
|
RefreshCountSuper = 0;
|
TreasureCount = 0;
|
TreasureState = null;
|
TreasureAward = null;
|
TreasureProgress = null;
|
HelpAwardCount = 0;
|
PlayerID = 0;
|
ItemIndex = 0;
|
WorkerPreviewCount = 0;
|
NeedSeconds = 0;
|
newAreaDataDict.Clear();
|
typeToPlayerIDs.Clear();
|
|
AwardType = 0;
|
AwardLen = 0;
|
AwardInfo = null;
|
mineAreaRecordList.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
myPlayerId = PlayerDatas.Instance.PlayerId;
|
showPlayerId = myPlayerId;
|
LoadAllTime();
|
}
|
|
public void UpdateTurnFightState(HB420_tagMCTurnFightState vNetData)
|
{
|
if (vNetData.MapID == 1 && vNetData.TagType == 1 && vNetData.TagID == robPlayerId && vNetData.State == 4)
|
{
|
JsonData Data = JsonMapper.ToObject(vNetData.Msg);
|
isWin = int.Parse(Data["isWin"].ToString()) == 1;
|
UpdateTurnFightStateInfo?.Invoke();
|
}
|
}
|
}
|
}
|
|
|
public class MineItemInfo
|
{
|
public byte Index; // 矿物所在福地位置索引,0~n
|
public ushort MineID; // 矿物ID,对应福地采集表中ID,0代表该索引位置没有矿物
|
public byte MineType; // 矿物类型:0-常规;1-超级
|
public uint UpdTime; // 最后一次更新时间戳
|
public byte PosLen;
|
public string Position; // 最后一次更新时所在位置百分比,0~100,支持小数,下0上100,可认为分为100格,速度为 x格/秒
|
public byte SpeedLen;
|
public string MoveSpeed; // 移动速度,x格/秒,支持小数
|
public uint EndTime; // 拉取结束时间戳
|
public byte WorkerCount; // 工人个数,为0时代表福地玩家没有使用工人拉回
|
public uint RobPlayerID; // 抢夺玩家ID,为0时代表没人抢夺
|
public byte RobWorkerCount; // 抢夺工人个数
|
public string RobPlayerName;
|
public byte RobJob;
|
public uint RobFace;
|
public uint RobFacePic;
|
}
|
public class MineAreaInfo
|
{
|
public uint PlayerID; // 福地所属玩家ID,可能是自己或其他玩家ID,当ID小于10000时为假人
|
public string PlayerName; // 可能为空,如自己或假人
|
public byte Job;
|
public uint Face;
|
public uint FacePic;
|
public byte MineCount;
|
public Dictionary<int, MineItemInfo> MineItems = new Dictionary<int, MineItemInfo>();
|
}
|
|
public class MineAreaRecord
|
{
|
public byte RecordType; // 记录类型;1-自己拉物品;2-物品被人抢
|
public uint TagPlayerID; // 目标玩家ID,等于自己玩家ID时代表拉自己的,反之为抢别人的
|
public uint RecordTime; // 记录时间戳
|
public ushort MineID; // 矿物ID,对应福地采集表中ID
|
public string TagPlayerName;
|
public byte TagJob;
|
public uint TagFace;
|
public uint TagFacePic;
|
}
|