using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using vnxbqy.UI;
|
using UnityEngine;
|
|
using System.Collections;
|
|
|
public class SettingEffectMgr : SingletonMonobehaviour<SettingEffectMgr>
|
|
{
|
private bool _isAutoHangUp = false;
|
private FuncConfigConfig _tagFuncModel;
|
private int[] shopIdlist;
|
public List<int> cureDrugItemIDList = new List<int>();
|
public List<int> cureDrugUnUseMapList = new List<int>();
|
|
PetModel m_petModel;
|
PetModel petmodel {
|
get {
|
return m_petModel ?? (m_petModel = ModelCenter.Instance.GetModel<PetModel>());
|
}
|
}
|
|
|
PackModel _playerPack;
|
PackModel playerPack {
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
|
}
|
|
PlayerDeadModel _deadModel;
|
PlayerDeadModel DeadModel {
|
get { return _deadModel ?? (_deadModel = ModelCenter.Instance.GetModel<PlayerDeadModel>()); }
|
}
|
|
StoreModel _storeModel;
|
StoreModel m_storeModel {
|
get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel<StoreModel>()); }
|
}
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
private float delayTime = 2f;
|
private bool isGetNewItem = false;
|
public bool isStartDecompose { get; set; }
|
public bool isStartOneKeySell { get; set; }
|
|
private void Awake()
|
{
|
isGetNewItem = false;
|
delayTime = 2;
|
HeroBehaviour.OnStartHandupAI -= OnStartHandupAI;
|
HeroBehaviour.OnStopHandupAI -= OnStopHandupAI;
|
DeadModel.playerDieEvent -= OnPlayerDie;
|
m_storeModel.RefreshBuyResultEvent -= RefreshBuySuccess;
|
DeadModel.CloseRebornWinEvent -= PlayerRebornSuccess;
|
HeroBehaviour.OnStartHandupAI += OnStartHandupAI;
|
HeroBehaviour.OnStopHandupAI += OnStopHandupAI;
|
DeadModel.playerDieEvent += OnPlayerDie;
|
m_storeModel.RefreshBuyResultEvent += RefreshBuySuccess;
|
DeadModel.CloseRebornWinEvent += PlayerRebornSuccess;
|
playerPack.RefreshDecomAttrAct += DecomposeSuccess;
|
DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent += OneKeySellSuccess;
|
}
|
|
|
public void Begin()
|
{
|
_tagFuncModel = FuncConfigConfig.Get("AutoBuyDrug");
|
shopIdlist = ConfigParse.GetMultipleStr<int>(_tagFuncModel.Numerical1);
|
isStartDecompose = false;
|
isStartOneKeySell = false;
|
cureDrugItemIDList.Clear();
|
for (var i = shopIdlist.Length - 1; i >= 0; i--)
|
{
|
var shopConfig = StoreConfig.Get(shopIdlist[i]);
|
cureDrugItemIDList.Add(shopConfig.ItemID);
|
}
|
|
cureDrugUnUseMapList.Clear();
|
cureDrugUnUseMapList = ConfigParse.GetMultipleStr<int>(_tagFuncModel.Numerical4).ToList();
|
}
|
|
float secondTimer = 0;
|
float halfSecondTimer = 0;
|
float autoSellCoolTimer = 0;
|
float autoDecomposeCoolTimer = 0;
|
private void LateUpdate()
|
{
|
if (!(StageLoad.Instance.currentStage is DungeonStage))
|
{
|
return;
|
}
|
|
secondTimer += Time.deltaTime;
|
halfSecondTimer += Time.deltaTime;
|
if (halfSecondTimer >= 1f)
|
{
|
halfSecondTimer = 0f;
|
if (!DeadModel.playerIsDie)
|
{
|
bool isCool;
|
KnapsackTimeCDMgr.Instance.GetItemCoolByCDType(1, out isCool);
|
if (!isCool)
|
{
|
AutoDrugSetting();
|
}
|
}
|
}
|
|
if (isStartDecompose)
|
{
|
autoDecomposeCoolTimer += Time.deltaTime;
|
if (autoDecomposeCoolTimer >= 5f)
|
{
|
autoDecomposeCoolTimer = 0;
|
isStartDecompose = false;
|
}
|
}
|
|
if (isStartOneKeySell)
|
{
|
autoSellCoolTimer += Time.deltaTime;
|
if (autoSellCoolTimer >= 5f)
|
{
|
autoSellCoolTimer = 0;
|
isStartOneKeySell = false;
|
}
|
}
|
|
if (secondTimer >= 3f)
|
{
|
secondTimer = 0f;
|
RefreshBagItem();
|
}
|
|
}
|
|
private void PlayerRebornSuccess()
|
{
|
StopAllCoroutines();
|
}
|
|
private void OneKeySellSuccess(H0721_tagMakeItemAnswer obj)
|
{
|
if (obj.MakeType != (byte)MakeType.OneKeySell)
|
return;
|
|
isStartOneKeySell = false;
|
}
|
|
private void DecomposeSuccess()
|
{
|
isStartDecompose = false;
|
}
|
|
public bool GetSettingEffect()
|
{
|
return _isAutoHangUp;
|
}
|
|
private void OnStartHandupAI()
|
{
|
DebugEx.Log("OnStartHandupAI");
|
_isAutoHangUp = true;
|
RefreshBagItem();
|
}
|
|
private void OnStopHandupAI()
|
{
|
DebugEx.Log("OnStopHandupAI");
|
_isAutoHangUp = false;
|
}
|
|
private void RefreshBuySuccess(int obj)
|
{
|
if (shopIdlist != null)
|
{
|
if (shopIdlist.Contains(obj))
|
{
|
AutoDrugSetting();
|
}
|
}
|
}
|
|
public void RefreshBagItem()
|
{
|
// if (!_isAutoHangUp)
|
// {
|
// return;
|
// }
|
DealBagItem();
|
}
|
|
/// <summary>
|
/// 背包小于5格处理物品
|
/// </summary>
|
private void DealBagItem()
|
{
|
if (playerPack.GetEmptyGridCount(PackType.Item) < 20 && ItemLogicUtility.Instance.isPackResetOk)
|
{
|
if (HangUpSetModel.Instance.GetBool(HangUpAutoBoolType.isAutoSell)
|
&& !isStartOneKeySell
|
&& ItemLogicUtility.Instance.GetSellItemList().Count > 0)
|
{
|
ItemLogicUtility.Instance.OneKeySell(ItemLogicUtility.Instance.GetSellItemList());
|
return;
|
}
|
|
if (HangUpSetModel.Instance.GetBool(HangUpAutoBoolType.isAutoDevour) && !isStartDecompose &&
|
FuncOpen.Instance.IsFuncOpen(123))
|
{
|
playerPack.SendEquipdevourQuest(true);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 自动吃药和买药的逻辑判断
|
/// </summary>
|
private void AutoDrugSetting()
|
{
|
if (CrossServerUtility.IsCrossServerOneVsOne() || ArenaManager.isArenaClient)
|
{
|
return;
|
}
|
|
var hpPercent = Mathf.RoundToInt((float)PlayerDatas.Instance.baseData.HP / PlayerDatas.Instance.extersion.MaxHP * 100);
|
if (hpPercent <= HangUpSetModel.Instance.GetHpSet())
|
{
|
var singlePack = playerPack.GetSinglePack(PackType.Item);
|
if (singlePack == null)
|
{
|
return;
|
}
|
|
for (var i = shopIdlist.Length - 1; i >= 0; i--)
|
{
|
var shopConfig = StoreConfig.Get(shopIdlist[i]);
|
var itemConfig = ItemConfig.Get(shopConfig.ItemID);
|
if (PlayerDatas.Instance.baseData.LV >= itemConfig.LV)
|
{
|
if (singlePack.GetCountById(itemConfig.ID) > 0)
|
{
|
var list = singlePack.GetItemsById(itemConfig.ID);
|
ItemOperateUtility.Instance.GotoUseItem(list[0].guid);
|
break;
|
}
|
else
|
{
|
if (HangUpSetModel.Instance.GetBool(HangUpAutoBoolType.isAutoBuyDrug) && playerPack.GetEmptyGridCount(PackType.Item) > 0)
|
{
|
if (m_storeModel.MoneyIsEnough(shopConfig.MoneyType, (ulong)shopConfig.MoneyNumber))
|
{
|
m_storeModel.SendBuyShopItem(shopConfig, 1);
|
break;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
private int[] RebornConditions;
|
private int rebornPrice;
|
private void OnPlayerDie()
|
{
|
if (!_isAutoHangUp || !HangUpSetModel.Instance.GetBool(HangUpAutoBoolType.isAutoReborn)
|
|| !DeadModel.IsCanReborn || IsDungeon())
|
return;
|
|
RebornConditions = DeadModel.RebornConditions;
|
rebornPrice = RebornConditions[2];
|
StartCoroutine(PlayerReborn(5));
|
}
|
|
private bool IsDungeon()
|
{
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
var mapConfig = MapConfig.Get(mapId);
|
return mapConfig != null && mapConfig.MapFBType != 0;
|
}
|
|
IEnumerator PlayerReborn(float time)
|
{
|
while (true)
|
{
|
DebugEx.Log("PlayerReborn");
|
time -= 1;
|
if (time <= 0)
|
{
|
if (DeadModel.playerIsDie)
|
{
|
if (DeadModel.IsRebornCoinsEnough())
|
{
|
DeadModel.SendRebornQuest(3);
|
}
|
else
|
{
|
if (DeadModel.IsCanInplaceReborn(rebornPrice))
|
{
|
DeadModel.SendRebornQuest(2);
|
}
|
}
|
}
|
break;
|
}
|
yield return WaitingForSecondConst.WaitMS1000;
|
}
|
}
|
|
|
}
|