using Snxxz.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Text.RegularExpressions;
|
using TableConfig;
|
using UnityEngine;
|
//用于坐骑
|
public class HorseClass
|
{
|
public int Lv;//坐骑等级
|
public int Exp;//经验
|
|
}
|
public enum HorseEnum
|
{
|
HorseDan = 0,//坐骑丹
|
HorseDebris = 1,//坐骑碎片
|
HorseStone = 2,//坐骑魂石
|
}
|
|
public class HorseSkillClass
|
{
|
public int SkillID;//技能ID
|
public int SkillItem;//升级技能所需道具
|
public int HorseID;//坐骑ID
|
public int HorseLV;//所需等级
|
}
|
|
public class PlayerMountDatas : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
public string _HorseIDNow = string.Empty;//获取当前的坐骑ID
|
public int HorseIDNow = 0;
|
public delegate void MountHA301Update(int _HorseID);
|
public static event MountHA301Update Event_MountHA301U;//坐骑的更新
|
public delegate void MountHA301Add(int _HorseID);
|
public static event MountHA301Add Event_MountHA301A;//坐骑的添加
|
public delegate void MountHA339Update(HA339_tagMCAttrFruitEatCntList info);
|
public static event MountHA339Update Event_MountHA339U;//坐骑魂石的刷新
|
|
public Dictionary<int, HorseSkillClass> GetMountSkillAndItem = new Dictionary<int, HorseSkillClass>();//1技能TypeID,所需的消耗物品ID
|
public delegate void OnMountAlteration(string NowMount);//当前坐骑变更
|
public static event OnMountAlteration Event_MountAlteration;
|
public static event Action OnMountUieffectUpLv;//关于坐骑升级时特效播放时的调用
|
public Dictionary<int, HorseClass> _DicHorse = new Dictionary<int, HorseClass>();//当前的坐骑字典
|
public Dictionary<int, int> _DicMountItem = new Dictionary<int, int>();//坐骑魂石的字典
|
public Dictionary<int, Redpoint> mountRedpoint = new Dictionary<int, Redpoint>();//坐骑外观切换红点
|
public Dictionary<int, Redpoint> DeblockingRedPoint = new Dictionary<int, Redpoint>();//激活按钮红点
|
public Dictionary<int, Redpoint> ASingleFeedRedPoint = new Dictionary<int, Redpoint>();//单次喂养红点
|
private List<HorseConfig> SortMount = new List<HorseConfig>();//用于红点排序
|
public int MountStoneItemId = 0;
|
public bool IsOk = false;
|
public bool IsRedPointSingleFeed = true;
|
public List<int> ListEffectSkill = new List<int>();
|
PlayerPackModel _playerPack;
|
PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
public bool HorseRidingBool = false;//用来判断玩家是都在骑马
|
public bool Wait = true;//等待回包(使用坐骑丹)
|
public static Action<int, bool> MultipleEvent;
|
public static event Action PlayerLoginOKData;
|
public override void Init()
|
{
|
ToAddSorting();
|
playerPack.RefreshItemCountAct += OnItemRefreshEvent;
|
MountWin.RedPointMountDan += RedPointMountDan;
|
MountSkillAndItem();
|
MountNumberPreservation();
|
string str = Config.Instance.Get<FuncConfigConfig>("MountSkillEffect").Numerical1;
|
int[] listeffect = ConfigParse.GetMultipleStr<int>(str);
|
ListEffectSkill.Clear();
|
for (int i = 0; i < listeffect.Length; i++)
|
{
|
ListEffectSkill.Add(listeffect[i]);
|
}
|
}
|
|
public override void UnInit()
|
{
|
MountWin.RedPointMountDan -= RedPointMountDan;
|
playerPack.RefreshItemCountAct -= OnItemRefreshEvent;
|
}
|
|
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
IsOk = false;
|
_HorseIDNow = string.Empty;
|
HorseIDNow = 0;
|
_DicHorse.Clear();
|
HorseRidingBool = false;
|
Wait = true;
|
IsRedPointSingleFeed = true;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
GlobalTimeEvent.Instance.secondEvent -= secondEvent;
|
GlobalTimeEvent.Instance.secondEvent += secondEvent;
|
IsOk = true;
|
SinglePackModel singPack = playerPack.GetSinglePackModel(PackType.rptEquip);
|
if (singPack == null) return;
|
foreach (var index in singPack.GetPackModelIndexDict().Keys)
|
{
|
OnItemRefreshEvent(singPack.packType, index, singPack.GetPackModelIndexDict()[index].itemId);
|
}
|
if (PlayerLoginOKData != null)
|
{
|
PlayerLoginOKData();
|
}
|
}
|
|
private DateTime dateTimeA;
|
private void secondEvent()
|
{
|
if (!Wait)
|
{
|
TimeSpan timeS = DateTime.Now - dateTimeA;
|
if (timeS.Seconds >= 2f)
|
{
|
Wait = true;
|
}
|
}
|
else
|
{
|
dateTimeA = DateTime.Now;
|
}
|
}
|
|
private void MountNumberPreservation()//用来对坐骑个数的保存
|
{
|
if (mountRedpoint.Count != 0)
|
return;
|
|
var configs = Config.Instance.GetAllValues<HorseConfig>();
|
int type = 0;
|
foreach (var config in configs)
|
{
|
if (!mountRedpoint.ContainsKey(config.HorseID))
|
{
|
type += 1;
|
int mountID = config.HorseID;
|
int RedPoint_Mountkey = MainRedDot.RedPoint_MountPackKey * 10 + mountID;
|
Redpoint redPointMountStare = new Redpoint(Redpoint_key1, RedPoint_Mountkey);
|
mountRedpoint.Add(mountID, redPointMountStare);
|
|
int RedPoint_Mountkey1 = RedPoint_Mountkey * 10 + type;
|
Redpoint redPointMountStare1 = new Redpoint(RedPoint_Mountkey, RedPoint_Mountkey1);
|
DeblockingRedPoint.Add(mountID, redPointMountStare1);
|
|
int RedPoint_Mountkey2 = RedPoint_Mountkey1 * 10 + type;
|
Redpoint redPointMountStare2 = new Redpoint(RedPoint_Mountkey, RedPoint_Mountkey2);
|
ASingleFeedRedPoint.Add(mountID, redPointMountStare2);
|
}
|
|
}
|
|
}
|
private void MountChangeRedPoint()//坐骑激活红点
|
{
|
foreach (var key in DeblockingRedPoint.Keys)
|
{
|
DeblockingRedPoint[key].state = RedPointState.None;
|
}
|
if (!FuncOpen.Instance.IsFuncOpen(8))
|
{
|
return;
|
}
|
|
var configs = Config.Instance.GetAllValues<HorseConfig>();
|
foreach (var config in configs)
|
{
|
int unlockItemID = config.UnlockItemID;
|
int itemCount = playerPack.GetItemCountByID(PackType.rptItem, unlockItemID);
|
int unlockItemCnt = config.UnlockItemCnt;
|
if (itemCount >= unlockItemCnt && !_DicHorse.ContainsKey(config.HorseID))
|
{
|
DeblockingRedPoint[config.HorseID].state = RedPointState.Simple;
|
}
|
}
|
}
|
|
void MountSkillAndItem()//获取坐骑技能
|
{
|
if (GetMountSkillAndItem.Count != 0)
|
return;
|
var configs = Config.Instance.GetAllValues<HorseUpConfig>();
|
foreach (var config in configs)
|
{
|
for (int i = 0; i < config.SkillID.Length; i++)
|
{
|
int skillID = config.SkillID[i];
|
if (skillID != 0 && !GetMountSkillAndItem.ContainsKey(skillID))
|
{
|
SkillConfig _skillModel = Config.Instance.Get<SkillConfig>(skillID);
|
HorseSkillClass horseSkillClass = new HorseSkillClass();
|
horseSkillClass.SkillID = skillID;
|
horseSkillClass.SkillItem = _skillModel.ExAttr4;
|
horseSkillClass.HorseID = config.HorseID;
|
horseSkillClass.HorseLV = config.LV;
|
GetMountSkillAndItem.Add(skillID, horseSkillClass);
|
}
|
}
|
}
|
}
|
private const int Redpoint_key1 = 1010301;
|
public Redpoint redPointStre1 = new Redpoint(MainRedDot.RedPoint_MountPackKey, Redpoint_key1);//坐骑外观
|
private const int Redpoint_key2 = 1050102;
|
public Redpoint redPointStre2 = new Redpoint(MainRedDot.RedPoint_MountPackKey, Redpoint_key2);//坐骑兽魂
|
private void OnItemRefreshEvent(PackType type, int index, int id)
|
{
|
MountH0704(playerPack.GetItemModelByIndex(type, index));
|
if (type == PackType.rptItem)
|
{
|
if (_DicMountItem.ContainsKey(id))
|
{
|
MountStoneRed();
|
}
|
MountChangeRedPoint();
|
MountDanRed();
|
}
|
}
|
private void MountStoneRed()//坐骑魂石红点
|
{
|
|
redPointStre2.state = RedPointState.None;
|
if (!FuncOpen.Instance.IsFuncOpen(8))
|
return;
|
int type = 0;
|
foreach (var key in _DicMountItem.Keys)
|
{
|
if (_DicMountItem[key] >= Config.Instance.Get<AttrFruitConfig>(key).MaxUseCnt)
|
{
|
continue;
|
}
|
type += playerPack.GetItemCountByID(PackType.rptItem, key);
|
}
|
if (type > 0)
|
{
|
redPointStre2.state = RedPointState.Simple;
|
return;
|
}
|
}
|
|
private void RedPointMountDan()
|
{
|
IsRedPointSingleFeed = false;
|
MountDanRed();
|
}
|
|
private void ToAddSorting()
|
{
|
SortMount.Clear();
|
SortMount = Config.Instance.GetAllValues<HorseConfig>();
|
SortMount.Sort(Compare);
|
}
|
int Compare(HorseConfig x, HorseConfig y)//数组排列
|
{
|
if (x.Sort.CompareTo(y.Sort) != 0)
|
{
|
return x.Sort.CompareTo(y.Sort);
|
}
|
return 1;
|
}
|
private void MountDanRed()//关于坐骑丹红点
|
{
|
foreach (var key in ASingleFeedRedPoint.Keys)
|
{
|
ASingleFeedRedPoint[key].state = RedPointState.None;
|
}
|
if (!FuncOpen.Instance.IsFuncOpen(8) || _DicHorse.Count == 0)
|
{
|
return;
|
}
|
|
int GetMountID = 0;
|
int GetMountLv = 0;
|
for (int i = 0; i < SortMount.Count; i++)
|
{
|
int horseID = SortMount[i].HorseID;
|
if (_DicHorse.ContainsKey(horseID))
|
{
|
var key = horseID;
|
if (GetMountID == 0 && _DicHorse[key].Lv < GetMountSkillMaxLV(key))
|
{
|
GetMountID = key;
|
GetMountLv = _DicHorse[key].Lv;
|
}
|
if (_DicHorse[key].Lv < GetMountLv && _DicHorse[key].Lv < GetMountSkillMaxLV(key))
|
{
|
GetMountID = key;
|
GetMountLv = _DicHorse[key].Lv;
|
}
|
}
|
}
|
FuncConfigConfig _tagfun = Config.Instance.Get<FuncConfigConfig>("HorseUpItem");
|
ItemConfig _tagchine = Config.Instance.Get<ItemConfig>(int.Parse(_tagfun.Numerical1));
|
HorseConfig horsecon = Config.Instance.Get<HorseConfig>(GetMountID);
|
int number = playerPack.GetItemCountByID(PackType.rptItem, _tagchine.ID);
|
if (ASingleFeedRedPoint.ContainsKey(GetMountID) && number > 0 && GetMountLv < horsecon.MaxLV)
|
{
|
if (PlayerDatas.Instance.baseData.LV >= 1500)
|
{
|
if (IsRedPointSingleFeed)
|
{
|
ASingleFeedRedPoint[GetMountID].state = RedPointState.Simple;
|
return;
|
}
|
}
|
else
|
{
|
ASingleFeedRedPoint[GetMountID].state = RedPointState.Simple;
|
return;
|
}
|
|
}
|
}
|
|
public int GetMinLvMount()
|
{
|
int GetMountID = 0;
|
int GetMountLv = 0;
|
for (int i = 0; i < SortMount.Count; i++)
|
{
|
int horseID = SortMount[i].HorseID;
|
if (_DicHorse.ContainsKey(horseID))
|
{
|
var key = horseID;
|
if (GetMountID == 0 && _DicHorse[key].Lv < GetMountSkillMaxLV(key))
|
{
|
GetMountID = key;
|
GetMountLv = _DicHorse[key].Lv;
|
}
|
if (_DicHorse[key].Lv < GetMountLv && _DicHorse[key].Lv < GetMountSkillMaxLV(key))
|
{
|
GetMountID = key;
|
GetMountLv = _DicHorse[key].Lv;
|
}
|
}
|
}
|
return GetMountID;
|
}
|
|
public int GetMountSkillMaxLV(int MountId)//获取灵宠最大技能等级
|
{
|
int SkillLv = 0;
|
foreach (var key in GetMountSkillAndItem.Keys)
|
{
|
if (GetMountSkillAndItem[key].HorseID == MountId)
|
{
|
if (GetMountSkillAndItem[key].HorseLV > SkillLv)
|
{
|
SkillLv = GetMountSkillAndItem[key].HorseLV;
|
}
|
|
}
|
}
|
return SkillLv;
|
}
|
public void MountH0704(ItemModel info)//获取当前的坐骑
|
{
|
|
if (info == null || info.packType != PackType.rptEquip)
|
return;
|
if (info.itemInfo.ItemPlace == (byte)RoleEquipType.mount)//坐骑位置19
|
{
|
var configs = Config.Instance.GetAllValues<HorseConfig>();
|
foreach (var config in configs)
|
{
|
if (config.ItemID == info.itemInfo.ItemID)
|
{
|
HorseIDNow = config.HorseID;
|
_HorseIDNow = config.HorseID.ToString();
|
if (Event_MountAlteration != null && IsOk)
|
{
|
Event_MountAlteration(_HorseIDNow);
|
}
|
|
}
|
}
|
}
|
MountDanRed();
|
MountStoneRed();
|
}
|
|
public void MountHA301(HA301_tagTrainHorseData info)//已拥有的坐骑(获得与刷新)
|
{
|
for (int i = 0; i < info.Num; i++)
|
{
|
|
if (_DicHorse.ContainsKey((int)info.InfoList[i].HorseID))
|
{
|
if ((int)info.InfoList[i].LV > _DicHorse[(int)info.InfoList[i].HorseID].Lv)
|
{
|
if (OnMountUieffectUpLv != null && IsOk)
|
{
|
OnMountUieffectUpLv();
|
}
|
}
|
_DicHorse[(int)info.InfoList[i].HorseID].Lv = (int)info.InfoList[i].LV;//坐骑等级
|
_DicHorse[(int)info.InfoList[i].HorseID].Exp = (int)info.InfoList[i].Exp;//坐骑经验
|
if (Event_MountHA301U != null && IsOk)
|
{
|
Event_MountHA301U((int)info.InfoList[i].HorseID);
|
}
|
|
}
|
else
|
{
|
HorseClass _horseClass = new HorseClass();
|
_horseClass.Lv = (int)info.InfoList[i].LV;//坐骑等级
|
_horseClass.Exp = (int)info.InfoList[i].Exp;//坐骑经验
|
|
_DicHorse.Add((int)info.InfoList[i].HorseID, _horseClass);
|
if (Event_MountHA301A != null && IsOk)
|
{
|
Event_MountHA301A((int)info.InfoList[i].HorseID);
|
}
|
|
}
|
}
|
MountStoneRed();
|
MountChangeRedPoint();
|
MountDanRed();
|
}
|
|
public void MountHA339(HA339_tagMCAttrFruitEatCntList info)//坐骑魂石
|
{
|
for (int i = 0; i < info.count; i++)
|
{
|
var configItem = Config.Instance.Get<ItemConfig>((int)info.EatCntList[i].ItemID);
|
if (configItem == null)
|
{
|
|
continue;
|
}
|
|
if (_DicMountItem.ContainsKey((int)info.EatCntList[i].ItemID))
|
{
|
_DicMountItem[(int)info.EatCntList[i].ItemID] = (int)info.EatCntList[i].EatCnt;
|
if (Event_MountHA339U != null)
|
Event_MountHA339U(info);//坐骑魂石的刷新
|
}
|
else
|
{
|
if (configItem.Type == 22)
|
{
|
_DicMountItem.Add((int)info.EatCntList[i].ItemID, (int)info.EatCntList[i].EatCnt);
|
}
|
}
|
}
|
MountStoneRed();
|
}
|
public int GetAllMountAttack()//得到所有坐骑的攻击
|
{
|
Dictionary<int, int> dicStone = Bonuses();
|
if (_DicHorse.Count == 0)
|
{
|
return dicStone[7];
|
}
|
else
|
{
|
int _AttT = 0;//攻击
|
foreach (int key in _DicHorse.Keys)
|
{
|
HorseUpConfig tagMode = HorseUpConfig.GetHorseIDAndLV(key, _DicHorse[key].Lv);
|
string[] str = ConfigParse.GetMultipleStr(tagMode.AttrValue);
|
if (str.Length != 0)
|
{
|
_AttT += int.Parse(str[1]);
|
}
|
}
|
return _AttT + dicStone[7];
|
}
|
}
|
Dictionary<int, int> Bonuses()//属性加成
|
{
|
Dictionary<int, int> dic = new Dictionary<int, int>();
|
dic.Clear();
|
dic.Add(6, 0);//生命
|
dic.Add(7, 0);//攻击
|
dic.Add(8, 0);//防御
|
foreach (int key in _DicMountItem.Keys)
|
{
|
if (_DicMountItem[key] != 0)
|
{
|
ItemConfig itemModel = Config.Instance.Get<ItemConfig>(key);
|
if (dic.ContainsKey(itemModel.Effect1))
|
{
|
dic[itemModel.Effect1] += itemModel.EffectValueA1 * _DicMountItem[key];
|
}
|
if (dic.ContainsKey(itemModel.Effect2))
|
{
|
dic[itemModel.Effect2] += itemModel.EffectValueA2 * _DicMountItem[key];
|
}
|
if (dic.ContainsKey(itemModel.Effect3))
|
{
|
dic[itemModel.Effect3] += itemModel.EffectValueA3 * _DicMountItem[key];
|
}
|
if (dic.ContainsKey(itemModel.Effect4))
|
{
|
dic[itemModel.Effect4] += itemModel.EffectValueA4 * _DicMountItem[key];
|
}
|
if (dic.ContainsKey(itemModel.Effect5))
|
{
|
dic[itemModel.Effect5] += itemModel.EffectValueA5 * _DicMountItem[key];
|
}
|
}
|
}
|
return dic;
|
}
|
|
public bool IsHint(HorseEnum horseEnum, int id = 0)//True提示,False不提示
|
{
|
bool iSHint = false;
|
switch (horseEnum)
|
{
|
case HorseEnum.HorseDan:
|
foreach (var key in _DicHorse.Keys)
|
{
|
HorseConfig horseConfig = Config.Instance.Get<HorseConfig>(key);
|
if (horseConfig.MaxLV > _DicHorse[key].Lv)
|
{
|
iSHint = true;
|
}
|
}
|
return iSHint;
|
case HorseEnum.HorseDebris:
|
foreach (var value in Config.Instance.GetAllValues<HorseConfig>())
|
{
|
if (value.UnlockItemID == id)
|
{
|
if (!_DicHorse.ContainsKey(value.HorseID))
|
{
|
iSHint = true;
|
}
|
}
|
}
|
return iSHint;
|
case HorseEnum.HorseStone:
|
int _maxuse = Config.Instance.Get<AttrFruitConfig>(id).MaxUseCnt;
|
if (_DicMountItem.ContainsKey(id))
|
{
|
if (_maxuse > _DicMountItem[id])
|
{
|
iSHint = true;
|
}
|
}
|
return iSHint;
|
default:
|
return true;
|
}
|
}
|
|
public void AppearanceSwitch(int HorseID)//坐骑外观切换
|
{
|
CA502_tagPlayerChooseHorse _tagCA502 = new CA502_tagPlayerChooseHorse();
|
_tagCA502.Index = (uint)HorseID;
|
GameNetSystem.Instance.SendInfo(_tagCA502);
|
}
|
|
public void MountDanUse(int HorseID, int Number, bool IsAutoBuy = false)//是否自动购买
|
{
|
CA527_tagCMHorseUp _tagC527 = new CA527_tagCMHorseUp();//向服务端发包坐骑经验单
|
_tagC527.HorseID = (uint)HorseID;
|
_tagC527.UseItemCnt = (byte)Number;
|
if (IsAutoBuy)
|
{
|
_tagC527.IsAutoBuy = 1;
|
}
|
GameNetSystem.Instance.SendInfo(_tagC527);
|
}
|
|
public int IsHorsePanelState()
|
{
|
int Type = 0;
|
foreach (var value in DeblockingRedPoint.Values)
|
{
|
if (value.state == RedPointState.Simple)
|
{
|
Type = 2;
|
return Type;
|
}
|
}
|
if (MainRedDot.Instance.redPointMountFunc.state == RedPointState.Simple)
|
{
|
Type = 1;
|
return Type;
|
}
|
return Type;
|
}
|
|
#region 预览坐骑碎片属性
|
Dictionary<int, int> mountAttrDict = new Dictionary<int, int>();
|
public Dictionary<int, int> GetMountAttrAddDict(int mountCode)
|
{
|
HorseConfig horseConfig = Config.Instance.Get<HorseConfig>(mountCode);
|
mountAttrDict.Clear();
|
if (horseConfig == null) return mountAttrDict;
|
|
int maxRank = horseConfig.MaxLV;
|
HorseUpConfig cost = HorseUpConfig.GetHorseIDAndLV(mountCode, maxRank);
|
if(cost != null)
|
{
|
int[] attrIds = ConfigParse.GetMultipleStr<int>(cost.AttrType);
|
int[] attrValues = ConfigParse.GetMultipleStr<int>(cost.AttrValue);
|
if (attrIds != null)
|
{
|
for (int j = 0; j < attrIds.Length; j++)
|
{
|
if (!mountAttrDict.ContainsKey(attrIds[j]))
|
{
|
mountAttrDict.Add(attrIds[j], attrValues[j]);
|
}
|
else
|
{
|
mountAttrDict[attrIds[j]] += attrValues[j];
|
}
|
}
|
}
|
}
|
return mountAttrDict;
|
}
|
#endregion
|
}
|