JJBB/Assets/Project/Script/GUI/Pet/PetClearOperaWnd.cs
2024-08-23 15:49:34 +08:00

569 lines
18 KiB
C#

using System.Collections.Generic;
using Games.LogicObj;
using GCGame;
using GCGame.Table;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Games.Fellow;
using Games.Events;
public class PetClearOperaWnd : MonoBehaviour
{
public GameObject IsReCommend; //是否推荐
public ClearChangeAttrItem[] clearChangeAttrItemsAttr;
public ClearChangeAttrItem[] clearChangeAttrItemsAttrZizhi;
public GameObject PayGameObject;
public Image PayQuility;
public Image PayIcon;
public Text PayName;
public Text PayNum;
public Text speedText;
public GameObject LyInfo;
public Text LyPrice;
public Text LyHas;
public Button StartBtn;
public GameObject StartAutoBtn;
public GameObject StopBtn;
public GameObject SpeedBtn;
public Toggle AutoPay;
public GameObject GetBtnObj;
public GameObject ReplaceBtn;
public GameObject Disable_ReplaceBtn;
public GameObject FindSeeWnd;
public InitAptitudeStart OldStart;
public InitAptitudeStart NewStart;
public UIImgText OldPower;
public UIImgText NewPower;
public GameObject PowerDown;
public GameObject PowerUp;
private int StartState = 0;
public void Awake()
{
Hashtable add = new Hashtable();
add["name"] = "PetClearOperaWnd";
Games.Events.MessageEventCallBack call = OnOpen;
add["callFun"] = call;
Games.Events.EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.OpenPetClearWndSuccess,add);
Hashtable add1 = new Hashtable();
add1["name"] = "PetClearOperaWnd_AddNewData";
Games.Events.MessageEventCallBack call1 = AddNewData;
add1["callFun"] = call1;
Games.Events.EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.UpdatePetClearData, add1);
Hashtable add2 = new Hashtable();
add2["name"] = "ReplaceNewClearData";
Games.Events.MessageEventCallBack call2 = ReplaceNewData;
add2["callFun"] = call2;
Games.Events.EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.ReplaceNewClearData, add2);
Hashtable calbackMoveparam4 = new Hashtable();
calbackMoveparam4["name"] = "PetClearOperaPayFresh";
MessageEventCallBack fun3 = PayFresh;
calbackMoveparam4.Add("callFun", fun3);
EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.FRESHSAMEUSETIP, calbackMoveparam4);
}
public void OnDestroy()
{
Games.Events.EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.UpdatePetClearData, "PetClearOperaWnd_AddNewData");
Games.Events.EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.OpenPetClearWndSuccess, "PetClearOperaWnd");
Games.Events.EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.ReplaceNewClearData, "ReplaceNewClearData");
Games.Events.EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.FRESHSAMEUSETIP, "PetClearOperaPayFresh");
}
private bool isAskClearRespond = true;
private bool isAutoClear = false;
private bool isStop = true;
private bool PauseOne = false;
private float speed = 1.0f;
float waitTime = 0.0f;
public void Update()
{
if (isStop)
return;
if (isAutoClear == false)
return;
if (isAskClearRespond == true)
{
waitTime += Time.deltaTime;
if (waitTime >= (1 / speed))
{
AutoStartClear(false);
waitTime = 0.0f;
}
}
}
public void Click_CloseChange()
{
FindSeeWnd.SetActive(false);
}
public void Click_ShowChangeInfo()
{
if (PetMainWnd.CurrentSelectFellowId == Games.GlobeDefine.GlobeVar.INVALID_GUID)
return;
FindSeeWnd.SetActive(true);
}
public void PayFresh(Hashtable addparam, Hashtable sendparam)
{
CostPay();
FreshStartBtn();
}
private void OnEnable()
{
StartBtn.interactable = true;
}
public void ReplaceNewData(Hashtable addparam, Hashtable sendparam)
{
ulong id = (ulong)sendparam["param"];
if (PetMainWnd.CurrentSelectFellowId == id)
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet != null)
{
SetDate(pet);
NewAttrChange(pet);
}
}
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{20152}"));
}
public void SetDate(Fellow pet)
{
if (pet == null || pet.IsValid() == false)
{
IsReCommend.SetActive(false);
ReplaceBtn.SetActive(false);
Disable_ReplaceBtn.SetActive(!ReplaceBtn.activeSelf);
if (clearChangeAttrItemsAttrZizhi.Length >= 5)
{
clearChangeAttrItemsAttrZizhi[0].Clear();
clearChangeAttrItemsAttrZizhi[1].Clear();
clearChangeAttrItemsAttrZizhi[2].Clear();
clearChangeAttrItemsAttrZizhi[3].Clear();
clearChangeAttrItemsAttrZizhi[4].Clear();
}
if (clearChangeAttrItemsAttr.Length >= 6)
{
clearChangeAttrItemsAttr[0].Clear();
clearChangeAttrItemsAttr[1].Clear();
clearChangeAttrItemsAttr[2].Clear();
clearChangeAttrItemsAttr[3].Clear();
clearChangeAttrItemsAttr[4].Clear();
clearChangeAttrItemsAttr[5].Clear();
}
OldPower.text = "";
NewPower.text = "";
PowerUp.SetActive(false);
PowerDown.SetActive(false);
OldStart.InitStart(0);
NewStart.InitStart(0);
return;
}
ReplaceBtn.SetActive(pet.newblood != 0 && pet.newattack != 0 && pet.newavoid != 0);
Disable_ReplaceBtn.SetActive(!ReplaceBtn.activeSelf);
if (clearChangeAttrItemsAttrZizhi.Length >= 5)
{
clearChangeAttrItemsAttrZizhi[0].ShowAttr(pet.Boneatitude, pet.newConstituAptitude, false);
clearChangeAttrItemsAttrZizhi[1].ShowAttr(pet.Forceatitude, pet.newMorfiAptitude, false);
clearChangeAttrItemsAttrZizhi[2].ShowAttr(pet.Poweratitude, pet.newStrengthAptitude, false);
clearChangeAttrItemsAttrZizhi[3].ShowAttr(pet.Smartatitude, pet.newIntellengAptitude, false);
clearChangeAttrItemsAttrZizhi[4].ShowAttr(pet.Agileatitude, pet.newAgileAptitude, false);
}
if(clearChangeAttrItemsAttr.Length>=6)
{
clearChangeAttrItemsAttr[0].ShowAttr(pet.blood,pet.newblood,true);
clearChangeAttrItemsAttr[1].ShowAttr(pet.attack, pet.newattack, true);
clearChangeAttrItemsAttr[2].ShowAttr(pet.physical, pet.newphysical, true);
clearChangeAttrItemsAttr[3].ShowAttr(pet.magic, pet.newmagic, true);
clearChangeAttrItemsAttr[4].ShowAttr(pet.hit, pet.newHit, true);
clearChangeAttrItemsAttr[5].ShowAttr(pet.avoid, pet.newavoid, true);
}
OldPower.text = pet.CombatValue.ToString();
NewPower.text = pet.newtotlepower.ToString();
PowerUp.SetActive(pet.newtotlepower > pet.CombatValue && pet.newtotlepower != 0);
PowerDown.SetActive(pet.newtotlepower < pet.CombatValue && pet.newtotlepower != 0);
IsReCommend.SetActive(pet.RecommonState == 1);
OldStart.InitStart(pet.AptitudeTotle);
NewStart.InitStart(pet.NewAptitudeTotle);
}
public void OnSelectPet()
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
Click_CloseChange();
SetDate(pet);
AutoClear(false);
AutoPay.isOn = false;
CountCost(pet);
CostPay();
NewAttrChange(pet);
if(pet!=null && pet.IsValid())
{
var modelTab = pet.CharModel();
if (modelTab != null)
{
pet.CalculateAptitudeTotle();
}
}
}
public void OnOpen(Hashtable addparam, Hashtable sendparam)
{
if (sendparam.ContainsKey("operator"))
{
int opera = (int)sendparam["operator"];
isAutoClear = (opera == 1);
}
}
int MoneyPay = 0;
int CostItemNum = 0;
int CostItemId = 0;
public bool CostPay()
{
int hasCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(CostItemId);
long MoneyHas = GameManager.gameManager.PlayerDataPool.Money.GetMoney_YuanBao();
if (hasCount < CostItemNum && CostItemId > 0)
{
PayNum.text = string.Format("<color=#ff0000ff>{0}</color>/{1}", hasCount, CostItemNum);
GetBtnObj.SetActive(true);
Button btn = GetBtnObj.GetComponent<Button>();
if (btn != null)
{
if (btn.onClick.GetPersistentEventCount() <= 0)
{
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(delegate ()
{
ItemTooltipsLogic.ShowItemTooltip(CostItemId, ItemTooltipsLogic.ShowType.GetPath, btn.transform.position);
});
}
}
if(isAutoClear == false)
{
AutoClear(false);
}
}
else
{
PayNum.text = string.Format("<color=#00ff00ff>{0}</color>/{1}", hasCount,CostItemNum);
GetBtnObj.SetActive(false);
return false;
}
if (LyHas != null && LyHas.gameObject.activeSelf)
{
LyHas.text = MoneyHas.ToString();
}
if (MoneyPay > 0 && CostItemNum > 0)
{
if (AutoPay.isOn)
{
if (isAutoClear)
{
if (MoneyPay > MoneyHas)
{
AutoClear(false);
return false;
}
}
PayGameObject.SetActive(!AutoPay.isOn || hasCount > 0);
LyInfo.SetActive(AutoPay.isOn && hasCount <= 0);
}
else
{
if (isAutoClear)
{
if (CostItemNum > hasCount)
{
AutoClear(false);
return false;
}
}
}
}
return true;
}
bool CountCost(Fellow pet)
{
if(pet==null || pet.IsValid()==false)
{
LoadAssetBundle.Instance.SetImageSprite(PayQuility, GCGame.Utils.GetItemQualityFrame((int)Games.Item.ItemQuality.QUALITY_WHITE));
PayIcon.gameObject.SetActive(false);
PayName.text = "";
LyPrice.text = "";
CostItemNum = 0;
CostItemId = 0;
return false;
}
long MoneyHas = 0;
Tab_InitFellowGrowth growth = TableManager.GetInitFellowGrowthByID(pet.DataId, 0);
if (growth != null)
{
PayIcon.gameObject.SetActive(true);
Tab_CommonItem item = TableManager.GetCommonItemByID(growth.CostItemId, 0);
if (item != null)
{
LoadAssetBundle.Instance.SetImageSprite(PayQuility, GCGame.Utils.GetItemQualityFrame(item.Quality));
LoadAssetBundle.Instance.SetImageSprite(PayIcon, item.Icon);
if (item.QualityEffect > 0)
{
CommonItemContainerItem.ShowQualityEffect(true, item.QualityEffect, PayIcon.transform);
}
else
{
CommonItemContainerItem.ShowQualityEffect(false, item.QualityEffect, PayIcon.transform);
}
}
PayName.text = item.Name; //<color=#0000ff>
CostItemNum = growth.CostItemNum;
CostItemId = growth.CostItemId;
if (LyPrice != null && LyPrice.gameObject.activeSelf)
{
var shops = TableManager.GetYuanBaoShop().Values;
foreach (var shop in shops)
{
if (shop.MoneyType == 1 && shop.ItemID == growth.CostItemId)
{
MoneyPay = shop.PriceForever;
LyPrice.text = shop.PriceForever.ToString();
}
}
}
}
MoneyHas = GameManager.gameManager.PlayerDataPool.Money.GetMoney_YuanBao();
return true;
}
public void BuyFast()
{
JudgeMoneyLogic.ShowSwitchMoneyPanel(MONEYTYPE.MONEYTYPE_YUANBAO, true);
}
public void NewAttrChange(Fellow pet)
{
if (pet!=null && pet.IsValid() && LyHas != null && LyHas.gameObject.activeSelf)
{
LyHas.text = GameManager.gameManager.PlayerDataPool.Money.GetMoney_YuanBao().ToString();
}
}
public void AddNewData(Hashtable addparam, Hashtable sendparam)
{
isAskClearRespond = true;
ulong id = (ulong)sendparam["param"];
if (PetMainWnd.CurrentSelectFellowId == id)
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if(pet!=null)
{
SetDate(pet);
NewAttrChange(pet);
if (pet.RecommonState == 1 && isAutoClear)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{20122}"));
OnClick_Stop();
}
}
CostPay();
}
FreshStartBtn();
}
private void FreshStartBtn()
{
if (StartState > 0)
StartState--;
if (StartState <= 0)
{
StartBtn.interactable = true;
}
}
public void OnClick_Stop()
{
AutoClear(false);
StartBtn.interactable = true;
StartState = 0;
}
public void AutoClear(bool state)
{
isStop = !state;
isAutoClear = state;
SpeedBtn.SetActive(state);
StopBtn.SetActive(state);
StartAutoBtn.SetActive(!state);
}
private bool CostEnough()
{
int hasCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(CostItemId);
if(hasCount < CostItemNum)
{
if (AutoPay.isOn)
return JudgeMoneyLogic.IsMoneyEnough(MONEYTYPE.MONEYTYPE_YUANBAO, MoneyPay);
else
return false;
}
return true;
}
public bool StartClear()
{
if(CostEnough() == false)
{
OnClick_Stop();
return false;
}
CG_REFINE_FELLOW refine = (CG_REFINE_FELLOW)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REFINE_FELLOW);
refine.SetFellowGuid(PetMainWnd.CurrentSelectFellowId);
refine.SetAutoBuy((AutoPay.isOn ? 1 : 0));
refine.SendPacket();
isStop = false;
if (isAutoClear)
{
isAskClearRespond = false;
}
return true;
}
public bool AutoStartClear(bool isAuto)
{
if (CostEnough() == false)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{21002}"));
return false;
}
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
{
return false;
}
if (pet.RecommonState == 1)
{
AutoClear(false);
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{20147}"), null, delegate()
{
if(isAuto)
{
AutoClear(true);
}
StartClear();
});
return false;
}
return StartClear();
}
public void OnClick_AutoClear()
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null || false == pet.IsValid())
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{20153}"));
return;
}
if (AutoStartClear(true))
{
AutoClear(true);
}
}
public void OnClick_StartClear()
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null || false == pet.IsValid())
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{20153}"));
return;
}
if(AutoStartClear(false))
{
StartState = 2;
StartBtn.interactable = false;
}
AutoClear(false);
}
public void OnClick_ReplaceOld()
{
OnClick_Stop();
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
{
return;
}
ReplaceBtn.SetActive(false);
Disable_ReplaceBtn.SetActive(!ReplaceBtn.activeSelf);
CG_REPLACE_REFINE_DATA refine = (CG_REPLACE_REFINE_DATA)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REPLACE_REFINE_DATA);
refine.SetFellowGuid(PetMainWnd.CurrentSelectFellowId);
refine.SendPacket();
}
public void AddSpeed()
{
speed = speed * 2;
if (speed > 4.0f)
speed = 1.0f;
speedText.text = StrDictionary.GetClientDictionaryString("#{5303}", speed);
}
public void OnClick_AutoPayLY(bool result)
{
int hasCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(CostItemId);
PayGameObject.SetActive(!AutoPay.isOn || hasCount>0);
LyInfo.SetActive(AutoPay.isOn && hasCount <= 0);
if (AutoPay.isOn)
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
return;
CostPay();
}
}
public void OnClick_PauseOne(bool result)
{
PauseOne = result;
}
public void OnClick_Close()
{
UIManager.CloseUI(UIInfo.PetsClearWndPath);
UIManager.ShowUI(UIInfo.PetMainWndPath,delegate(bool bSuccess, object param) {
if(bSuccess && PetMainWnd.Instance!=null)
{
PetMainWnd.Instance.ShowPage(1,PetMainWnd.CurrentSelectFellowId);
}
});
}
}