//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, August 21, 2018 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; using System; using TableConfig; //神兽强化(神兽属性展示) namespace Snxxz.UI { public class GodBeastAttributes : MonoBehaviour { [SerializeField] ItemCell m_ItemCell; [SerializeField] GameObject m_FrameNull; [SerializeField] GameObject m_FullLevel; [SerializeField] GameObject m_BottomDisplay; [SerializeField] Text m_LvNowText; [SerializeField] Text m_LvNextText; [SerializeField] IntensifySmoothSlider m_ExpSlider; [SerializeField] Text m_ExpNum; [SerializeField] Text m_TextAttributes1; [SerializeField] Text m_TextAttributesAdd1; [SerializeField] Text m_TextAttributes2; [SerializeField] Text m_TextAttributesAdd2; [SerializeField] GodBeastSlidingList m_GodBeastSlidingList; [SerializeField] Toggle m_DoubleToggle; [SerializeField] Button m_StrengthenBtn; [SerializeField] UIAlphaTween m_UIAlphaTween; [SerializeField] Slider m_Slider; DogzModel Dogz_model; DogzModel dogz_model { get { return Dogz_model ?? (Dogz_model = ModelCenter.Instance.GetModel()); } } private Dictionary QualityLimit = new Dictionary(); PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } ItemTipsModel _itemTipsModel; ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel()); } } GodBeastModel godBeastModel { get { return ModelCenter.Instance.GetModel(); } } private int GodBeastNumber = 0;//神兽编号 private int GodBeastPart = 0;//神兽装备ID private int DogZLv = 0;//获取神兽等级 private int DogZExp = 0;//熟练度 private ItemModel m_DogZItemModel = null; private int SingleProficiency = 0;//单倍熟练度 private int DoubleProficiency = 0;//双倍熟练度 private int NeedFairyJade = 0;//所需仙玉 private void Start() { m_DoubleToggle.onValueChanged.AddListener(OnClickToggle); m_StrengthenBtn.AddListener(OnClickStrengthBtn); } private void OnEnable() { if (m_DoubleToggle.isOn) { m_DoubleToggle.isOn = false; } GodBeastReinforcementWin.ChooseToModify += ChooseToModify; godBeastModel.AbsorbEvent += AbsorbEvent; } private void OnDisable() { GodBeastReinforcementWin.ChooseToModify -= ChooseToModify; godBeastModel.AbsorbEvent -= AbsorbEvent; } public void Init() { if (QualityLimit.Count <= 0) { string DogzAssist = Config.Instance.Get("DogzAssist").Numerical4;//获取不同品质的神兽强化上限 QualityLimit = ConfigParse.GetDic(DogzAssist); } } public void Unit() { } private void OnClickToggle(bool Isbool) { AttributeAssignment(); } private void OnClickStrengthBtn() { Dictionary DicAb = godBeastModel.Absorption_Dic; List List = new List(); foreach (var key in DicAb.Keys) { List.Add(key); } if (m_DoubleToggle.isOn) { dogz_model.SendDogzEquipStrength(m_DogZItemModel.itemInfo.ItemPlace, List,1); } else { dogz_model.SendDogzEquipStrength(m_DogZItemModel.itemInfo.ItemPlace, List, 0); } } private void ChooseToModify(int locationMarker) { GetGodBeastLocationMarker(locationMarker); } private void AbsorbEvent()//选中取消的数据刷新 { GetDogZLevelAndExp(); AttributeAssignment(); } public void GetGodBeastLocationMarker(int LocationMarker)//获取神兽装备的标记信息 { if (LocationMarker != 0) { m_ItemCell.gameObject.SetActive(true); GodBeastNumber = LocationMarker % 100;//神兽编号 GodBeastPart = LocationMarker / 100;//神兽装备位ID List itemModel = dogz_model.GetDogzEquips(GodBeastNumber); if (itemModel != null) { for (int i = 0; i < itemModel.Count; i++) { if (itemModel[i].EquipPlace == GodBeastPart) { ItemCellModel ItemModel = new ItemCellModel(itemModel[i].itemId, true, 0, itemModel[i].itemInfo.IsBind); m_ItemCell.Init(ItemModel); m_ItemCell.cellBtn.RemoveAllListeners(); int type = i; m_ItemCell.cellBtn.AddListener(() => { itemTipsModel.SetItemTipsModel(PackType.rptDogzEquip, itemModel[type].itemInfo.ItemGUID); }); } } } m_FrameNull.SetActive(true); m_FullLevel.SetActive(false); GetDogZLevelAndExp(); AttributeAssignment(); } else { m_ItemCell.gameObject.SetActive(false); m_ExpSlider.stage = 0; m_ExpSlider.delay = 0f; m_ExpSlider.ResetStage(); m_ExpSlider.value = 0; m_ExpNum.text = "0/0"; m_FrameNull.SetActive(false); m_FullLevel.SetActive(false); } } public void AttributeAssignment() { if (m_DogZItemModel == null) { return; } GainProficiency();//获取熟练度 var IudetDogzEquipPlus = m_DogZItemModel.GetUseDataModel((int)ItemUseDataKey.Def_IudetDogzEquipPlus); if (IudetDogzEquipPlus != null) { int lv = QualityLimit[m_DogZItemModel.chinItemModel.ItemColor]; var DogzEquipConfig = DogzEquipPlusConfig.GetEquipplaceAndLevel(GodBeastPart, lv); if (DogZLv >= lv) { m_FrameNull.SetActive(false); m_FullLevel.SetActive(true); m_ExpSlider.stage = lv; m_ExpSlider.delay = 0f; m_ExpSlider.ResetStage(); m_ExpSlider.value = 1; m_Slider.gameObject.SetActive(false); m_ExpNum.text = DogzEquipConfig.upExpTotal + "/" + DogzEquipConfig.upExpTotal; } else { if (m_DoubleToggle.isOn) { PropertySetting(DogZExp, DoubleProficiency); } else { PropertySetting(DogZExp, SingleProficiency); } } } else { if (m_DoubleToggle.isOn) { PropertySetting(0, DoubleProficiency); } else { PropertySetting(0, SingleProficiency); } } } private void GainProficiency()//选中装备的获取熟练度 { SingleProficiency = 0; DoubleProficiency = 0; NeedFairyJade = 0; Dictionary DicAb = godBeastModel.Absorption_Dic; foreach (var key in DicAb.Keys) { ItemModel itemModel = playerPack.GetItemModelByIndex(PackType.rptDogzItem, key); if (itemModel != null) { if (itemModel.chinItemModel.Effect1 == 235) { var IudetDogzEquipPlus = itemModel.GetUseDataModel((int)ItemUseDataKey.Def_IudetDogzEquipPlus); SingleProficiency += itemModel.chinItemModel.EffectValueA1 * DicAb[key]; if (IudetDogzEquipPlus != null) { SingleProficiency += IudetDogzEquipPlus[1]; DoubleProficiency += itemModel.chinItemModel.EffectValueA1; } else { DoubleProficiency += itemModel.chinItemModel.EffectValueA1 * 2 * DicAb[key]; NeedFairyJade += itemModel.chinItemModel.Effect2 * DicAb[key]; } } } } } private void PropertySetting(int ExpTotalNow, int ToExpTotal)//属性设置 { m_FrameNull.gameObject.SetActive(true); m_FullLevel.SetActive(false); int toLv = ToLv(ToExpTotal); m_LvNowText.text = "+" + DogZLv.ToString(); if (toLv <= DogZLv) { m_LvNextText.text = "+" + (DogZLv + 1).ToString(); toLv = DogZLv + 1; } else { m_LvNextText.text = "+" + toLv.ToString(); } var DogzEquipConfig = DogzEquipPlusConfig.GetEquipplaceAndLevel(GodBeastPart, DogZLv); int[] AttType = ConfigParse.GetMultipleStr(DogzEquipConfig.attType); int[] AttValue = ConfigParse.GetMultipleStr(DogzEquipConfig.attValue); if (ToExpTotal == 0) { m_Slider.gameObject.SetActive(false); m_TextAttributesAdd1.gameObject.SetActive(false); m_TextAttributesAdd2.gameObject.SetActive(false); m_ExpNum.text = DogZExp + "/" + DogzEquipConfig.upExpTotal; float value = (float)DogZExp / DogzEquipConfig.upExpTotal; SetExperienceBar(DogZLv, value); if (AttType.Length > 1) { m_TextAttributes1.gameObject.SetActive(true); m_TextAttributes2.gameObject.SetActive(true); string StrName1 = Config.Instance.Get(AttType[0]).Name; string StrName2 = Config.Instance.Get(AttType[1]).Name; m_TextAttributes1.text = StrName1 + ":" + AttValue[0]; m_TextAttributes2.text = StrName2 + ":" + AttValue[1]; } else { m_TextAttributes2.gameObject.SetActive(false); string StrName1 = Config.Instance.Get(AttType[0]).Name; m_TextAttributes1.text = StrName1 + ":" + AttValue[0]; } } else { m_Slider.gameObject.SetActive(true); if (DogZExp + ToExpTotal >= DogzEquipConfig.upExpTotal) { m_Slider.value = 1f; } else { m_Slider.value = (float)(DogZExp + ToExpTotal) / (float)(DogzEquipConfig.upExpTotal); } m_UIAlphaTween.Play(); var DogzEquipToConfig = DogzEquipPlusConfig.GetEquipplaceAndLevel(GodBeastPart, toLv); int[] AttTypeTo = ConfigParse.GetMultipleStr(DogzEquipToConfig.attType); int[] AttValueTo = ConfigParse.GetMultipleStr(DogzEquipToConfig.attValue); string strColor = string.Format(Language.Get("DogzGreenText"), ToExpTotal); m_ExpNum.text = DogZExp + strColor + "/" + DogzEquipConfig.upExpTotal; float value= (float)DogZExp / DogzEquipConfig.upExpTotal; SetExperienceBar(DogZLv, value); if (AttType.Length > 1) { m_TextAttributes1.gameObject.SetActive(true); m_TextAttributes2.gameObject.SetActive(true); m_TextAttributesAdd1.gameObject.SetActive(true); m_TextAttributesAdd2.gameObject.SetActive(true); string StrName1 = Config.Instance.Get(AttType[0]).Name; string StrName2 = Config.Instance.Get(AttType[1]).Name; m_TextAttributes1.text = StrName1 + ":" + AttValue[0]; m_TextAttributes2.text = StrName2 + ":" + AttValue[1]; m_TextAttributesAdd1.text = "+" + (AttValueTo[0] - AttValue[0]); m_TextAttributesAdd2.text = "+" + (AttValueTo[1] - AttValue[1]); } else { m_TextAttributes1.gameObject.SetActive(true); m_TextAttributesAdd1.gameObject.SetActive(true); m_TextAttributes2.gameObject.SetActive(false); m_TextAttributesAdd2.gameObject.SetActive(false); string StrName1 = Config.Instance.Get(AttType[0]).Name; m_TextAttributes1.text = StrName1 + ":" + AttValue[0]; m_TextAttributesAdd1.text = "+" + (AttValueTo[0] - AttValue[0]); } } if (ToExpTotal == 0) { m_StrengthenBtn.interactable = false; } else { m_StrengthenBtn.interactable = true; } } private int ToLv(int ToExpTotal)//获取等到达的熟练度等级 { int DogzLv = 0; if (m_DogZItemModel == null) { return DogzLv; } int lv = QualityLimit[m_DogZItemModel.chinItemModel.ItemColor]; for (int i = lv; i >= 0; i--) { var DogzEquipConfig = DogzEquipPlusConfig.GetEquipplaceAndLevel(GodBeastPart, i); if (ToExpTotal < DogzEquipConfig.upExpTotal) { DogzLv = DogzEquipConfig.level; } } var DogzEquipMaxConfig = DogzEquipPlusConfig.GetEquipplaceAndLevel(GodBeastPart, lv); if (ToExpTotal >= DogzEquipMaxConfig.upExpTotal) { DogzLv = DogzEquipMaxConfig.level; } return DogzLv; } private void GetDogZLevelAndExp()//获取当前所选选择神兽的等级和熟练度 { DogZLv = 0; DogZExp = 0; m_DogZItemModel = null; List itemModel = dogz_model.GetDogzEquips(GodBeastNumber); ItemModel ItemModel = null; if (itemModel != null) { for (int i = 0; i < itemModel.Count; i++) { if (itemModel[i].EquipPlace == GodBeastPart) { ItemModel = itemModel[i]; } } } if (ItemModel == null) { return; } m_DogZItemModel = ItemModel; var IudetDogzEquipPlus = ItemModel.GetUseDataModel((int)ItemUseDataKey.Def_IudetDogzEquipPlus); if (IudetDogzEquipPlus != null) { DogZLv = IudetDogzEquipPlus[0]; DogZExp = IudetDogzEquipPlus[1]; } } int GodBeast_Number = 0; int GodBeast_Part = 0; private void SetExperienceBar(int lv,float value)//设置经验条 { if (GodBeast_Number != GodBeastNumber || GodBeast_Part != GodBeastPart) { GodBeast_Number = GodBeastNumber; GodBeast_Part = GodBeastPart; m_ExpSlider.stage = lv; m_ExpSlider.delay = 0f; m_ExpSlider.ResetStage(); m_ExpSlider.value = value; } else { m_ExpSlider.delay = 0.1f; m_ExpSlider.stage = lv; m_ExpSlider.value = value; } } } }