640 lines
18 KiB
C#
640 lines
18 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Games.Item;
|
|
using GCGame.Table;
|
|
using Module.Log;
|
|
/// <summary>
|
|
/// 装备洗练根
|
|
/// </summary>
|
|
public class EquipXilianRoot : UIControllerBase<EquipXilianRoot>
|
|
{
|
|
void OnEnable()
|
|
{
|
|
isTarget = false;
|
|
IsEquipUpdate = true;
|
|
IsOptSucess = true;
|
|
SetInstance(this);
|
|
|
|
GUIData.delMoneyChanged += UpdateOwnMoney;
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
SetInstance(null);
|
|
|
|
GUIData.delMoneyChanged -= UpdateOwnMoney;
|
|
}
|
|
|
|
private bool IsEquipUpdate = false;
|
|
private bool IsOptSucess = false;
|
|
|
|
public void UpdateEquip()
|
|
{
|
|
IsEquipUpdate = true;
|
|
|
|
_EquipItemSlot.InitItem(_SelectedItem);
|
|
UpdateCost();
|
|
|
|
UpdateXilianAttr();
|
|
|
|
UpdateAutoResult();
|
|
}
|
|
|
|
public void OptResult(GC_EQUIP_PROPBAR_BAPTIZE packet)
|
|
{
|
|
GUIData.AddNotifyData("#{1451}");
|
|
if (packet.Success > 0)
|
|
{
|
|
IsOptSucess = true;
|
|
}
|
|
}
|
|
|
|
public void CloseWindow()
|
|
{
|
|
UIManager.CloseUI(UIInfo.EquipXilian);
|
|
UIManager.ShowUI(UIInfo.EquipEnhance);
|
|
if(EquipEnhanceXilian.Instance() != null)
|
|
{
|
|
EquipEnhanceXilian.Instance().OnXilianPage(0);
|
|
}
|
|
}
|
|
|
|
#region show
|
|
|
|
|
|
public static void Show(GameItem selectedItem, bool isAuto)
|
|
{
|
|
Hashtable hash = new Hashtable();
|
|
hash.Add("SelectedItem", selectedItem);
|
|
hash.Add("IsAuto", isAuto);
|
|
|
|
UIManager.ShowUI(UIInfo.EquipXilian, EquipXilianRoot.ShowUIOver, hash);
|
|
}
|
|
|
|
static void ShowUIOver(bool bSuccess, object param)
|
|
{
|
|
if (bSuccess)
|
|
{
|
|
Hashtable hash = param as Hashtable;
|
|
if (EquipXilianRoot.Instance() != null)
|
|
{
|
|
EquipXilianRoot.Instance().ShowInner((GameItem)hash["SelectedItem"], (bool)hash["IsAuto"]);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ShowInner(GameItem selectedItem, bool isAuto)
|
|
{
|
|
if (!isAuto)
|
|
InitEquipSingle(selectedItem);
|
|
else
|
|
InitEquipAuto(selectedItem);
|
|
|
|
InitTarget();
|
|
}
|
|
|
|
private void InitTarget()
|
|
{
|
|
var xilianTargetTab = TableManager.GetEquipBaptizeTargetByID(_SelectedItem.GetSubClass());
|
|
foreach(var item in xilianTargetTab)
|
|
{
|
|
if (item.Quality == (int)_SelectedItem.GetQuality() && item.Profession == GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession)
|
|
{
|
|
_EquipBaptizeTab = item;
|
|
for (int i = 0; i < _TargetToggles.Length; ++i)
|
|
{
|
|
_TargetToggles[i].gameObject.SetActive(false);
|
|
_TargetToggles[i].isOn = false;
|
|
|
|
if (item.getTargetCount() < i)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
int propID = item.GetTargetbyIndex(i);
|
|
if (propID < 0)
|
|
continue;
|
|
|
|
_TargetToggles[i].isOn = true;
|
|
_TargetToggles[i].gameObject.SetActive(true);
|
|
if (i == 0)
|
|
{
|
|
_TargetText[i].text = StrDictionary.GetClientDictionaryString("{#20006}");
|
|
}
|
|
else if (i == 1)
|
|
{
|
|
_TargetText[i].text = StrDictionary.GetClientDictionaryString("{#20007}");
|
|
}
|
|
else if (i == 2)
|
|
{
|
|
_TargetText[i].text = StrDictionary.GetClientDictionaryString("{#20008}");
|
|
}
|
|
else if (i == 3)
|
|
{
|
|
_TargetText[i].text = StrDictionary.GetClientDictionaryString("{#20009}");
|
|
}
|
|
else if (i == 4)
|
|
{
|
|
_TargetText[i].text = StrDictionary.GetClientDictionaryString("{#20010}");
|
|
}
|
|
else
|
|
{
|
|
_TargetText[i].text = PropID.GetAttrName((PropID.PropertyID)propID, -1, -1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region single
|
|
|
|
public UIContainerBase _PropOrg;
|
|
public UIContainerBase _PropNew;
|
|
public UIImgText _PropCombatValueOrg;
|
|
public UIImgText _PropCombatValueNew;
|
|
public CommonItemEquipItem _EquipItemSlot;
|
|
public CommonItemMaterialSlot _MaterialSlot;
|
|
public Toggle _UseYuanbao;
|
|
public GameObject _SinglePanel;
|
|
public GameObject _AutoPanel;
|
|
public GameObject _MaterialPanel;
|
|
public GameObject _YuanbaoPanel;
|
|
public UICurrencyItem _CostYuanbao;
|
|
public UICurrencyItem _OwnYuanbao;
|
|
public Text _XilianPoint;
|
|
public Button _BtnReplace;
|
|
public GameObject _Disable_BtnReplace;
|
|
public EquipXilianAttrItem xilianBaseAttrDeltaItem;
|
|
public GameObject upImg;
|
|
public GameObject downImg;
|
|
|
|
private GameItem _SelectedItem;
|
|
|
|
public void InitEquipSingle(GameItem equipItem)
|
|
{
|
|
_SelectedItem = equipItem;
|
|
|
|
_SinglePanel.SetActive(true);
|
|
_AutoPanel.SetActive(false);
|
|
|
|
_EquipItemSlot.InitItem(_SelectedItem);
|
|
UpdateCost();
|
|
|
|
UpdateXilianAttr();
|
|
}
|
|
|
|
private void UpdateXilianAttr()
|
|
{
|
|
Hashtable equipHash = new Hashtable();
|
|
equipHash.Add("EquipItem", _SelectedItem);
|
|
_PropOrg.InitContentItem(_SelectedItem.ExAttrs, null, equipHash);
|
|
List<EquipXilianAttr> newAttrList = new List<EquipXilianAttr>(_SelectedItem.ExAttrsNew);
|
|
int xilianBaseAttrDelta = _SelectedItem.GetXilianBasetAttrDelta();
|
|
|
|
if (xilianBaseAttrDelta != 0)
|
|
{
|
|
xilianBaseAttrDeltaItem.gameObject.SetActive(true);
|
|
Hashtable param = new Hashtable();
|
|
param["InitObj"] = new EquipXilianAttr() { IsBaseAttr = true, XilianValue = xilianBaseAttrDelta, IsFixedImg = false };
|
|
param["EquipItem"] = _SelectedItem;
|
|
xilianBaseAttrDeltaItem.Show(param);
|
|
}
|
|
else
|
|
{
|
|
xilianBaseAttrDeltaItem.gameObject.SetActive(false);
|
|
}
|
|
|
|
_PropNew.InitContentItem(newAttrList, null, equipHash);
|
|
if (_SelectedItem.ExAttrsNew.Count > 0)
|
|
{
|
|
_BtnReplace.gameObject.SetActive(true);
|
|
_Disable_BtnReplace.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_BtnReplace.gameObject.SetActive(false);
|
|
_Disable_BtnReplace.SetActive(true);
|
|
}
|
|
|
|
_XilianPoint.text = _SelectedItem.XilianPoint.ToString();
|
|
|
|
int oldCombat = CombatValue.CalculateEquipSingle(_SelectedItem);
|
|
int newCombat = 0;
|
|
_PropCombatValueOrg.text = oldCombat.ToString();
|
|
if (_SelectedItem.ExAttrsNew.Count > 0)
|
|
{
|
|
newCombat = CombatValue.CalculateEquipXilianNew(_SelectedItem);
|
|
}
|
|
else
|
|
{
|
|
_PropCombatValueNew.text = "0";
|
|
}
|
|
|
|
if (newCombat == 0)
|
|
{
|
|
upImg.gameObject.SetActive(false);
|
|
downImg.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
upImg.gameObject.SetActive(newCombat > oldCombat);
|
|
downImg.gameObject.SetActive(newCombat < oldCombat);
|
|
}
|
|
|
|
_PropCombatValueNew.text = newCombat.ToString();
|
|
//_OwnYuanbao.ShowCurrency(MONEYTYPE.MONEYTYPE_YUANBAO, GameManager.gameManager.PlayerDataPool.GetIntPropty((int)CONSUM_TYPE.MONEY, (int)MONEYTYPE.MONEYTYPE_YUANBAO));
|
|
}
|
|
|
|
public void UpdateOwnMoney()
|
|
{
|
|
_OwnYuanbao.ShowCurrency(MONEYTYPE.MONEYTYPE_YUANBAO, GameManager.gameManager.PlayerDataPool.GetLongPropty((int)CONSUM_TYPE.MONEY, (int)MONEYTYPE.MONEYTYPE_YUANBAO));
|
|
}
|
|
|
|
public void IsUseYuanbao(bool isUse)
|
|
{
|
|
UpdateCost();
|
|
}
|
|
|
|
private void UpdateCost()
|
|
{
|
|
var consumeTabs = TableManager.GetEquipPropBarBaptizeConsume().Values;
|
|
int equipLevel = _SelectedItem.GetMinLevelRequire();
|
|
int equipQuality = (int)_SelectedItem.GetQuality();
|
|
Tab_EquipPropBarBaptizeConsume tabConsume = null;
|
|
foreach (var consumeTab in consumeTabs)
|
|
{
|
|
if (consumeTab.MaxLevel >= equipLevel && consumeTab.Quality == equipQuality)
|
|
{
|
|
tabConsume = consumeTab;
|
|
_MaterialSlot.InitMaterial(consumeTab.ConsumeSubType, consumeTab.ConsumeNum);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!_MaterialSlot.IsMaterialEnough() && _UseYuanbao.isOn)
|
|
{
|
|
int itemCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(_MaterialSlot._ItemDataID);
|
|
var shopItems = TableManager.GetYuanBaoShop().Values;
|
|
foreach (var shopItem in shopItems)
|
|
{
|
|
if (shopItem.ItemID == tabConsume.ConsumeSubType)
|
|
{
|
|
_CostYuanbao.ShowCurrency(MONEYTYPE.MONEYTYPE_YUANBAO, shopItem.PriceForever * (tabConsume.ConsumeNum - itemCount));
|
|
break;
|
|
}
|
|
}
|
|
|
|
_OwnYuanbao.ShowCurrency(MONEYTYPE.MONEYTYPE_YUANBAO, GameManager.gameManager.PlayerDataPool.GetLongPropty((int)CONSUM_TYPE.MONEY, (int)MONEYTYPE.MONEYTYPE_YUANBAO));
|
|
|
|
_MaterialPanel.SetActive(false);
|
|
_YuanbaoPanel.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
_MaterialPanel.SetActive(true);
|
|
_YuanbaoPanel.SetActive(false);
|
|
}
|
|
|
|
}
|
|
|
|
public void OnXilianClick()
|
|
{
|
|
if (!IsEquipUpdate)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
if (isTarget)
|
|
{
|
|
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{5419}"), null,
|
|
() =>
|
|
{
|
|
isTarget = false;
|
|
OnXilianClick();
|
|
});
|
|
|
|
return;
|
|
}
|
|
|
|
if (_MaterialPanel.activeSelf)
|
|
{
|
|
if (!_MaterialSlot.IsMaterialEnough())
|
|
{
|
|
GUIData.AddNotifyData("#{5322}");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!JudgeMoneyLogic.IsMoneyEnough(MONEYTYPE.MONEYTYPE_YUANBAO, _CostYuanbao.CurrencyIntValue))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
CG_EQUIP_PROPBAR_BAPTIZE packet = (CG_EQUIP_PROPBAR_BAPTIZE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_EQUIP_PROPBAR_BAPTIZE);
|
|
if (_SelectedItem.IsPlayerEquiped())
|
|
{
|
|
packet.Packtype = (int)GameItemContainer.Type.TYPE_EQUIPPACK;
|
|
}
|
|
else
|
|
{
|
|
packet.Packtype = (int)GameItemContainer.Type.TYPE_BACKPACK;
|
|
}
|
|
packet.Equipguid = _SelectedItem.Guid;
|
|
if (_MaterialPanel.activeSelf)
|
|
{
|
|
packet.Isautopament = 0;
|
|
}
|
|
else
|
|
{
|
|
packet.Isautopament = 1;
|
|
}
|
|
|
|
IsEquipUpdate = false;
|
|
packet.SendPacket();
|
|
|
|
LogModule.DebugLog("OnXilianClick");
|
|
}
|
|
|
|
public static int isReplace = 0;
|
|
public void OnXilianReplaceClick()
|
|
{
|
|
if (EquipXilianAttrItem.xilianList.Count != 0)
|
|
PlayerPrefs.SetInt("entryUp", EquipXilianAttrItem.xilianList[0]);
|
|
isReplace = 1;
|
|
PlayerPrefs.SetInt("isReplace", isReplace);
|
|
LogModule.DebugLog("OnXilianReplaceClick");
|
|
isTarget = false;
|
|
if (_SelectedItem.ExAttrsNew.Count == 0)
|
|
return;
|
|
|
|
_AutoOpt.StopAuto();
|
|
if (!_SelectedItem.IsPlayerEquiped())
|
|
{
|
|
OnXilianReplaceClickOk();
|
|
return;
|
|
}
|
|
|
|
int decLevel = 0;
|
|
foreach (var exAttr in _SelectedItem.ExAttrs)
|
|
{
|
|
if (exAttr.XilianTab.PropID == (int)PropID.PropertyID.EQUIP_XILIAN_EQUIPLEVEL)
|
|
{
|
|
decLevel += exAttr.XilianValue;
|
|
}
|
|
}
|
|
foreach (var exAttr in _SelectedItem.ExAttrsNew)
|
|
{
|
|
if (exAttr.XilianTab.PropID == (int)PropID.PropertyID.EQUIP_XILIAN_EQUIPLEVEL)
|
|
{
|
|
decLevel -= exAttr.XilianValue;
|
|
}
|
|
}
|
|
if (decLevel > 0)
|
|
{
|
|
if (_SelectedItem.EquipUseLevel + decLevel > GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level)
|
|
{
|
|
MessageBoxLogic.OpenOKCancelBox(5373, -1, OnXilianReplaceClickOk);
|
|
}
|
|
else
|
|
{
|
|
OnXilianReplaceClickOk();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
OnXilianReplaceClickOk();
|
|
}
|
|
}
|
|
|
|
public void OnXilianReplaceClickOk()
|
|
{
|
|
CG_EQUIP_PROPBAR_BAPTIZE_PROP_REPLACE packet = (CG_EQUIP_PROPBAR_BAPTIZE_PROP_REPLACE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_EQUIP_PROPBAR_BAPTIZE_PROP_REPLACE);
|
|
if (_SelectedItem.IsPlayerEquiped())
|
|
{
|
|
packet.Packtype = (int)GameItemContainer.Type.TYPE_EQUIPPACK;
|
|
}
|
|
else
|
|
{
|
|
packet.Packtype = (int)GameItemContainer.Type.TYPE_BACKPACK;
|
|
}
|
|
packet.Equipguid = _SelectedItem.Guid;
|
|
packet.SendPacket();
|
|
|
|
//isReplace = true;
|
|
//int entryUp = EquipXilianAttrItem.xilianList[0];
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region auto
|
|
|
|
public GameObject _AutoTargetPanel;
|
|
public Toggle[] _TargetToggles;
|
|
public Text[] _TargetText;
|
|
public EquipAutoOpt _AutoOpt;
|
|
|
|
private int _TargetLevel;
|
|
private int _SpeedIdx;
|
|
|
|
private bool isTarget = false;
|
|
|
|
private Tab_EquipBaptizeTarget _EquipBaptizeTab;
|
|
|
|
public void InitEquipAuto(GameItem selectedItem)
|
|
{
|
|
InitEquipSingle(selectedItem);
|
|
|
|
_SinglePanel.SetActive(false);
|
|
_AutoPanel.SetActive(true);
|
|
|
|
_UseYuanbao.isOn = false;
|
|
|
|
_SelectedItem = selectedItem;
|
|
}
|
|
|
|
public void OnShowAutoTarget()
|
|
{
|
|
_AutoTargetPanel.SetActive(true);
|
|
}
|
|
|
|
public void OnHideAutoTarget()
|
|
{
|
|
_AutoTargetPanel.SetActive(false);
|
|
LogModule.DebugLog("_TargetLevel:" + _TargetLevel);
|
|
}
|
|
|
|
public void OnAutoXilianStart()
|
|
{
|
|
IsEquipUpdate = true;
|
|
IsOptSucess = true;
|
|
}
|
|
|
|
public void OnAutoXilian()
|
|
{
|
|
if(!IsEquipUpdate)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (isTarget)
|
|
{
|
|
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{5419}"), null,
|
|
() =>
|
|
{
|
|
isTarget = false;
|
|
OnAutoXilian();
|
|
},
|
|
() =>
|
|
{
|
|
_AutoOpt.StopAuto();
|
|
});
|
|
|
|
return;
|
|
}
|
|
|
|
if (_MaterialPanel.activeSelf)
|
|
{
|
|
if (!_MaterialSlot.IsMaterialEnough())
|
|
{
|
|
GUIData.AddNotifyData("#{5322}");
|
|
_AutoOpt.StopAuto();
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!JudgeMoneyLogic.IsMoneyEnough(MONEYTYPE.MONEYTYPE_YUANBAO, _CostYuanbao.CurrencyIntValue))
|
|
{
|
|
_AutoOpt.StopAuto();
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!IsEquipUpdate || !IsOptSucess)
|
|
{
|
|
//LogModule.DebugLog("异常:结果未返回,请重试");
|
|
return;
|
|
}
|
|
IsEquipUpdate = false;
|
|
IsOptSucess = false;
|
|
|
|
CG_EQUIP_PROPBAR_BAPTIZE packet = (CG_EQUIP_PROPBAR_BAPTIZE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_EQUIP_PROPBAR_BAPTIZE);
|
|
if (_SelectedItem.IsPlayerEquiped())
|
|
{
|
|
packet.Packtype = (int)GameItemContainer.Type.TYPE_EQUIPPACK;
|
|
}
|
|
else
|
|
{
|
|
packet.Packtype = (int)GameItemContainer.Type.TYPE_BACKPACK;
|
|
}
|
|
packet.Equipguid = _SelectedItem.Guid;
|
|
if (_MaterialPanel.activeSelf)
|
|
{
|
|
packet.Isautopament = 0;
|
|
}
|
|
else
|
|
{
|
|
packet.Isautopament = 1;
|
|
}
|
|
|
|
packet.SendPacket();
|
|
|
|
//TestProp();
|
|
}
|
|
|
|
private void UpdateAutoResult()
|
|
{
|
|
for (int i = 0; i < _TargetToggles.Length; ++i)
|
|
{
|
|
if (!_TargetToggles[i].isOn)
|
|
continue;
|
|
|
|
//int prop = _EquipBaptizeTab.GetTargetbyIndex(i);
|
|
if (IsTargetPropGet(i))
|
|
{
|
|
isTarget = true;
|
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{5323}"));
|
|
if (_AutoOpt.gameObject.activeInHierarchy)
|
|
{
|
|
_AutoOpt.StopAuto();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool IsTargetPropGet(int idx)
|
|
{
|
|
switch (idx)
|
|
{
|
|
case 0:
|
|
if (_SelectedItem.ExAttrsNew.Count >= 6)
|
|
return true;
|
|
break;
|
|
case 1:
|
|
if (_SelectedItem.ExAttrsNew.Count >= 7)
|
|
return true;
|
|
break;
|
|
case 2:
|
|
if (_SelectedItem.ExAttrsNew.Count >= 8)
|
|
return true;
|
|
break;
|
|
case 3:
|
|
if (_SelectedItem.ExAttrsNew.Count >= 9)
|
|
return true;
|
|
break;
|
|
case 4:
|
|
if (_SelectedItem.ExAttrsNew.Count >= 10)
|
|
return true;
|
|
break;
|
|
default:
|
|
var equipAttrTab = TableManager.GetEquipBaptizeByID((int)_SelectedItem.GetQuality(), 0);
|
|
|
|
int prop = _EquipBaptizeTab.GetTargetbyIndex(idx);
|
|
var findAttr = _SelectedItem.ExAttrsNew.FindLast((exAttr) =>
|
|
{
|
|
if (exAttr.XilianTab.PropID == prop)
|
|
return true;
|
|
return false;
|
|
});
|
|
|
|
if (findAttr != null)
|
|
{
|
|
int attrIdx = _SelectedItem.ExAttrsNew.IndexOf(findAttr);
|
|
if(attrIdx >= equipAttrTab.PropBarFixedNumber)
|
|
return true;
|
|
}
|
|
|
|
break;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void TestProp()
|
|
{
|
|
|
|
_SelectedItem.ExAttrsNew.Add(_SelectedItem.GetXilianAttr(20, -1, 10));
|
|
|
|
UpdateEquip();
|
|
}
|
|
|
|
private void TestReplace()
|
|
{
|
|
_SelectedItem.ExAttrs.Clear();
|
|
foreach (var newAttr in _SelectedItem.ExAttrsNew)
|
|
{
|
|
_SelectedItem.ExAttrs.Add(newAttr);
|
|
}
|
|
_SelectedItem.ExAttrsNew.Clear();
|
|
|
|
UpdateEquip();
|
|
}
|
|
#endregion
|
|
}
|