using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
|
public class GuardModel : Model, IAfterPlayerDataInitialize, IPlayerLoginOk
|
{
|
List<int> fairyLandGuardItems = new List<int>();
|
|
public bool fairyLandGuard { get; set; }
|
public ItemModel fairyLandItemModel { get; private set; }
|
|
public event Action onDungeonEquipGuardEvent;
|
|
PackModel pack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
public override void Init()
|
{
|
ParseConfig();
|
StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
|
pack.refreshItemCountEvent += RefreshItemCountAct;
|
KnapsackTimeCDMgr.Instance.RefreshItemOverdueAct += RefreshItemOverdueTimeAct;
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
SnxxzGame.Instance.StartCoroutine(Co_LoadGuard());
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
IEnumerator Co_LoadGuard()
|
{
|
yield return null;
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
if (_hero == null)
|
{
|
yield break;
|
}
|
var equipIndex = EquipSet.ClientPlaceToServerPlace(new Int2(0, (int)RoleEquipType.Guard));
|
var _itemModel = pack.GetItemByIndex(PackType.Equip, equipIndex);
|
if (_itemModel != null && _itemModel.itemInfo != null)
|
{
|
_hero.SwitchGuard((uint)_itemModel.itemId);
|
}
|
}
|
|
private void RefreshItemCountAct(PackType type, int arg2, int _id)
|
{
|
if (fairyLandGuard)
|
{
|
if (type == PackType.Equip || fairyLandGuardItems.Contains(_id))
|
{
|
CheckFairyLandGuard();
|
}
|
}
|
}
|
|
IEnumerator Co_DungeonDuardCheck()
|
{
|
yield return WaitingForSecondConst.WaitMS500;
|
CheckFairyLandGuard();
|
}
|
|
private void OnStageLoadFinish()
|
{
|
var _mapId = dungeonModel.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID);
|
if (_mapId == 31080)
|
{
|
SnxxzGame.Instance.StartCoroutine(Co_DungeonDuardCheck());
|
}
|
}
|
|
private void RefreshItemOverdueTimeAct(string _guid)
|
{
|
if (fairyLandGuard)
|
{
|
var itemModel = pack.GetItemByGuid(_guid);
|
if (itemModel != null && fairyLandItemModel != null && itemModel.itemId == fairyLandItemModel.itemId)
|
{
|
CheckFairyLandGuard();
|
}
|
}
|
}
|
|
private void CheckFairyLandGuard()
|
{
|
fairyLandGuard = false;
|
var equipPlace = EquipPlaceMapConfig.GetServerPlace(0, (int)RoleEquipType.Guard);
|
var itemModel = pack.GetItemByIndex(PackType.Equip, equipPlace);
|
if (itemModel == null || !fairyLandGuardItems.Contains(itemModel.itemId))
|
{
|
for (int i = 0; i < fairyLandGuardItems.Count; i++)
|
{
|
var list = pack.GetSinglePack(PackType.Item).GetItemsById(fairyLandGuardItems[i]);
|
if (list != null && list.Count > 0)
|
{
|
for (int k = 0; k < list.Count; k++)
|
{
|
bool isOverdue = ItemLogicUtility.Instance.IsOverdue(list[k].guid);
|
|
if (!isOverdue)
|
{
|
fairyLandGuard = true;
|
fairyLandItemModel = list[k];
|
if (onDungeonEquipGuardEvent != null)
|
{
|
onDungeonEquipGuardEvent();
|
return;
|
}
|
}
|
}
|
}
|
}
|
}
|
if (onDungeonEquipGuardEvent != null)
|
{
|
onDungeonEquipGuardEvent();
|
}
|
}
|
|
#region 配置
|
public float speed { get; private set; }
|
public float pickUpViewRange { get; private set; }
|
public float pickUpAreaRange { get; private set; }
|
public float traceRange { get; private set; }
|
public float impendRange { get; private set; }
|
public float idleTimeMin { get; private set; }
|
public float idleTimeMax { get; private set; }
|
public float stopAnimationSpeed { get; private set; }
|
public float height { get; private set; }
|
public float pickUpSfxSpeed { get; private set; }
|
public float resetDistance { get; private set; }
|
|
void ParseConfig()
|
{
|
var config = FuncConfigConfig.Get("XjmjGuardian");
|
fairyLandGuardItems.AddRange(ConfigParse.GetMultipleStr<int>(config.Numerical1));
|
fairyLandGuardItems.Sort(Compare);
|
|
config = FuncConfigConfig.Get("GuardianSpeed");
|
speed = float.Parse(config.Numerical1);
|
stopAnimationSpeed = float.Parse(config.Numerical2);
|
pickUpSfxSpeed = float.Parse(config.Numerical3);
|
|
config = FuncConfigConfig.Get("GuardianPickupRange");
|
pickUpViewRange = float.Parse(config.Numerical1);
|
pickUpAreaRange = float.Parse(config.Numerical2);
|
|
config = FuncConfigConfig.Get("GuardianTraceRange");
|
traceRange = float.Parse(config.Numerical1);
|
resetDistance = float.Parse(config.Numerical2);
|
|
config = FuncConfigConfig.Get("GuardianImpendRange");
|
impendRange = float.Parse(config.Numerical1);
|
|
config = FuncConfigConfig.Get("GuardianRandomIdle");
|
idleTimeMin = float.Parse(config.Numerical1);
|
idleTimeMax = float.Parse(config.Numerical2);
|
|
config = FuncConfigConfig.Get("GuardianHigh");
|
height = float.Parse(config.Numerical1);
|
}
|
#endregion
|
|
int Compare(int x, int y)
|
{
|
return x.CompareTo(y);
|
}
|
}
|
}
|
|
|