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

591 lines
19 KiB
C#

using System;
using System.Collections.Generic;
using System.Runtime.Remoting.Lifetime;
using Games.GlobeDefine;
using Games.LogicObj;
using Games.SkillModle;
using GCGame;
using GCGame.Table;
using Module.Log;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Games.MountModule;
using Games.Fellow;
using Games.Events;
public class PetMainAttrWnd : MonoBehaviour
{
public GameObject SleepPet;
public GameObject CallPet;
public GameObject HelpBtn;
public GameObject FightBtn;
public GameObject BaseAttrWnd; //基础属性
public GameObject DetailAttrWnd; //详细属性
public Toggle BaseAttrToggle;
public Toggle DetailAttrToggle;
public InitAptitudeStart baseAptitudeStart;
public InitAptitudeStart detailAptitudeStart;
//弹出框
public GameObject PopWnd;
public GameObject FightSet;
public UIContainerBase FightSetting;
public GameObject ChangePetName;
//基础属性
public Text grow; //成长
public Text attack;//攻击
public Text blood; //气血
public Text physical; //物理防御
public Text cultivation; //修为
public Text magic; //法术防御
public Text sawy; //悟性
public Text nature; //性格
public Text style; //类型
public GameObject expObj;
public Text exp; //经验值
public Slider expSlider;
public GameObject liftObj;
public Text lift; //寿命值
public Slider liftSlider;
//详细属性
public Text Boneatitude; //根骨资质
public Text Forceatitude; //精力资质
public Text Poweratitude; //力量资质
public Text Smartatitude; //智力资质
public Text Agileatitude; //敏捷资质
public Text bone; //根骨
public Text force; //精力
public Text power; //力量
public Text smart; //智力
public Text agile; //敏捷
public Text hit; //命中
public Text avoid; //闪避
public Text detailattack;//攻击
public Text detailblood; //气血
public Text detailphysical; //物理防御
public Text detailmagic; //法术防御
public GameObject[] skillIcons = new GameObject[8];
public void ClearInfo(bool state)
{
detailphysical.gameObject.SetActive(state);
detailblood.gameObject.SetActive(state);
detailattack.gameObject.SetActive(state);
detailmagic.gameObject.SetActive(state);
magic.gameObject.SetActive(state);
cultivation.gameObject.SetActive(state);
physical.gameObject.SetActive(state);
blood.gameObject.SetActive(state);
attack.gameObject.SetActive(state);
grow.gameObject.SetActive(state);
nature.gameObject.SetActive(state);
style.gameObject.SetActive(state);
sawy.gameObject.SetActive(state);
exp.gameObject.SetActive(state);
lift.gameObject.SetActive(state);
Boneatitude.gameObject.SetActive(state);
Forceatitude.gameObject.SetActive(state);
Poweratitude.gameObject.SetActive(state);
Smartatitude.gameObject.SetActive(state);
Agileatitude.gameObject.SetActive(state);
bone.gameObject.SetActive(state);
force.gameObject.SetActive(state);
power.gameObject.SetActive(state);
smart.gameObject.SetActive(state);
agile.gameObject.SetActive(state);
hit.gameObject.SetActive(state);
avoid.gameObject.SetActive(state);
baseAptitudeStart.ClearInfo(state);
detailAptitudeStart.ClearInfo(state);
expObj.gameObject.SetActive(state);
liftObj.gameObject.SetActive(state);
for (int i = 0; i < skillIcons.Length; i++)
{
AddStudySkill(null, -1, i);
}
}
public void Awake()
{
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.UPDATA_PET_CALLFIGHTINFO, UpdateCallBtn);
Hashtable calbackMoveparam2 = new Hashtable();
calbackMoveparam2["name"] = "MainAttr";
MessageEventCallBack fun2 = UpdateFelllowAttr;
calbackMoveparam2.Add("callFun", fun2);
Games.Events.EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.UpdatePetInfo, calbackMoveparam2);
}
public void OnDestroy()
{
Games.Events.EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.UpdatePetInfo, "MainAttr");
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.UPDATA_PET_CALLFIGHTINFO, UpdateCallBtn);
}
public void UpdateCallBtn(object obj)
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
return;
if(GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level>=70)
{
HelpBtn.SetActive(false);
CallPet.SetActive(false);
FightBtn.SetActive(((!pet.Called) && (!pet.Helped)));
}
else
{
HelpBtn.SetActive(((!pet.Called) && (!pet.Helped)));
CallPet.SetActive(((!pet.Called) && (!pet.Helped)));
FightBtn.SetActive(false);
}
if (FightSet != null && FightSet.activeInHierarchy)
{
OnClick_FightPetReSet();
}
if (pet.Attached)
FightBtn.SetActive(false);
SleepPet.SetActive(pet.Called || pet.Helped || pet.Attached);
}
public void UpdateFelllowAttr(Hashtable addparam, Hashtable sendparam)
{
if (sendparam.ContainsKey("guid") == false)
return;
ulong fellowGuid = (ulong)sendparam["guid"];
if(fellowGuid== PetMainWnd.CurrentSelectFellowId)
{
OPenBaseAttrWnd(false);
OPenDetailWnd(false);
}
}
public void OnSelectPet()
{
if (GameManager.gameManager.PlayerDataPool.FellowContainer==null)
return;
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
return;
BaseAttrToggle.isOn = true;
DetailAttrToggle.isOn = false;
OPenBaseAttrWnd();
UpdateCallBtn(null);
for (int i = 0; i < skillIcons.Length; i++)
{
if (i == 0)
{
AddStudySkill(pet, pet.GY_skillid, i);
continue;
}
if (i == 1)
{
AddStudySkill(pet, pet.MW_skillid, i);
continue;
}
AddStudySkill(pet, pet.GetOwnSkillId(i - 2), i);
}
}
//宠物改名弹窗
public void OnClick_ChangePetName()
{
if (PopWnd == null)
return;
if (FightSet == null)
return;
PopWnd.SetActive(true);
ChangePetName.SetActive(true);
InputField input = ChangePetName.GetComponentInChildren<InputField>();
if (input != null)
{
input.text = "";
}
}
public void OnClick_ChangeNameCancel()
{
if (PopWnd == null)
return;
if (FightSet == null)
return;
PopWnd.SetActive(false);
ChangePetName.SetActive(false);
}
public void OnClick_ChangeNameOK()
{
if (PopWnd == null)
return;
if (FightSet == null)
return;
if (ChangePetName == null)
return;
InputField input = ChangePetName.GetComponentInChildren<InputField>();
if (input == null)
return;
CG_FELLOW_CHANGE_NAME send = (CG_FELLOW_CHANGE_NAME)PacketDistributed.CreatePacket(MessageID.PACKET_CG_FELLOW_CHANGE_NAME);
send.Fellowguid = PetMainWnd.CurrentSelectFellowId;
send.Name = input.text;
send.SendPacket();
PopWnd.SetActive(false);
ChangePetName.SetActive(false);
}
public void OnClickBaseAttr()
{
OPenBaseAttrWnd();
}
public void OnClickDetailAttr()
{
OPenDetailWnd();
}
// 显示宠物技能图标
public void AddStudySkill(Fellow fellow, int id, int index)
{
if (index > skillIcons.Length)
return;
GameObject skillHas = skillIcons[index];
if (skillHas == null)
return;
Transform child = skillHas.transform.Find("Child");
Tab_FellowSkill skillInfo = TableManager.GetFellowSkillByID(id, 0);
if (skillInfo == null)
{
if (child != null)
child.gameObject.SetActive(false);
return;
}
if (fellow.IsHaveSkillId(id) == false)
{
if (child != null)
child.gameObject.SetActive(false);
return;
}
child.gameObject.SetActive(true);
Transform skillIcon = skillHas.transform.Find("Child/Icon");
Transform level = skillHas.transform.Find("Child/Level");
Button Btn = skillHas.GetComponentInChildren<Button>();
if (skillIcon != null)
{
Image icon = skillIcon.gameObject.GetComponent<Image>();
if (icon != null)
{
LoadAssetBundle.Instance.SetImageSprite(icon, skillInfo.SkillIcon);
}
}
if (level != null)
{
Text levelText = level.gameObject.GetComponent<Text>();
if (levelText != null)
{
levelText.text = "Lv." + skillInfo.Level.ToString();
}
}
if (Btn != null)
{
Btn.onClick.RemoveAllListeners();
Btn.onClick.AddListener(delegate ()
{
OnClickSkillIcon(skillInfo, Btn.transform);
});
}
}
public void OnClickSkillIcon(Tab_FellowSkill skill,Transform pos)
{
FellowSkillTooltip.ShowSkillToolTips(skill.Id,pos.position);
}
public void FellowAttachInfo()
{
if(FightSet!=null && FightSet.activeInHierarchy)
{
OnClick_FightPetReSet();
}
UpdateCallBtn(null);
}
//打开上阵调整窗
public void OnClick_FightPetReSet()
{
if (PopWnd == null)
return;
if (FightSet == null)
return;
PopWnd.SetActive(true);
FightSet.SetActive(true);
Dictionary<int, Tab_FellowAttached> infos = TableManager.GetFellowAttached();
List<int> keys = new List<int>(infos.Keys);
keys.Insert(0,-1);//出战宠物
keys.Insert(1, -2);//助战宠物
FightSetting.InitContentItem(keys, null);
}
public void OnClick_CloseFigthSet()
{
if (PopWnd == null)
return;
if (FightSet == null)
return;
PopWnd.SetActive(false);
FightSet.SetActive(false);
}
//基础属性
public void OPenBaseAttrWnd(bool state = true)
{
if (GameManager.gameManager.PlayerDataPool.FellowContainer ==null)
return;
if(state)
{
BaseAttrWnd.SetActive(true);
DetailAttrWnd.SetActive(false);
}
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
return;
nature.text = pet.GetNature;
style.text = pet.GetStyle;
grow.text = pet.grow.ToString();
attack.text = pet.attack.ToString();
blood.text = pet.blood.ToString();
physical.text = pet.physical.ToString();
cultivation.text = pet.cultivation.ToString();
magic.text = pet.magic.ToString();
sawy.text = (pet.sawy * 1.0f / 100.0f).ToString();
Tab_LevelUp levelup = TableManager.GetLevelUpByID(pet.Level, 0);
if(levelup!=null)
{
exp.text = string.Format("{0}/{1}", pet.Exp, levelup.FellowExpNeed);
expSlider.value = pet.Exp * 1.0f / long.Parse(levelup.FellowExpNeed);
}
Tab_FellowBase fellowBase = TableManager.GetFellowBaseByID(pet.DataId,0);
if(fellowBase!=null)
{
lift.text = string.Format("{0}/{1}", pet.lift, fellowBase.MaxLife);
liftSlider.value = pet.lift * 1.0f / fellowBase.MaxLife;
}
if(baseAptitudeStart != null)
{
baseAptitudeStart.InitStart(pet.AptitudeTotle);
}
}
//助戰
public void OnHelpFight()
{
if(GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level<70)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{20141}"));
return;
}
Fellow fellow = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (fellow == null)
return;
if(fellow.lift<=0)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{20160}"));
return;
}
CG_SET_HELPER_FELLOW callFellow = (CG_SET_HELPER_FELLOW)PacketDistributed.CreatePacket(MessageID.PACKET_CG_SET_HELPER_FELLOW);
callFellow.SetGuid(PetMainWnd.CurrentSelectFellowId);
callFellow.SendPacket();
PopWnd.SetActive(false);
FightSet.SetActive(false);
}
//出戰
public void OnCallClick()
{
Fellow fellow = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (fellow == null)
return;
if (fellow.lift <= 0)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{20160}"));
return;
}
CG_CALL_FELLOW callFellow = (CG_CALL_FELLOW)PacketDistributed.CreatePacket(MessageID.PACKET_CG_CALL_FELLOW);
callFellow.SetGuid(PetMainWnd.CurrentSelectFellowId);
callFellow.SendPacket();
//播放音效
//GameManager.gameManager.SoundManager.PlaySoundEffect(30); //pet_call
PopWnd.SetActive(false);
FightSet.SetActive(false);
}
//召回伙伴
public void OnUnCallClick()
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
return;
if (pet.Called == false && pet.Helped == false && pet.Attached==false)
return;
if(pet.Attached)
{
CG_PET_SET_ATTACHED cG_PET_SET_ATTACHED = (CG_PET_SET_ATTACHED)PacketDistributed.CreatePacket(MessageID.PACKET_CG_PET_SET_ATTACHED);
cG_PET_SET_ATTACHED.AttachedId = pet.attachId;
cG_PET_SET_ATTACHED.Guid = (long)pet.Guid;
cG_PET_SET_ATTACHED.Opty = 1;
cG_PET_SET_ATTACHED.SendPacket();
return;
}
CG_UNCALL_FELLOW uncallFellow = (CG_UNCALL_FELLOW)PacketDistributed.CreatePacket(MessageID.PACKET_CG_UNCALL_FELLOW);
uncallFellow.SetGuid(PetMainWnd.CurrentSelectFellowId);
if (pet.Called)
uncallFellow.SetUncallType(1);
if(pet.Helped)
uncallFellow.SetUncallType(2);
uncallFellow.SendPacket();
PopWnd.SetActive(false);
FightSet.SetActive(false);
}
//伙伴加锁
public void OnLockClick()
{
CG_LOCK_FELLOW lockFellow = (CG_LOCK_FELLOW)PacketDistributed.CreatePacket(MessageID.PACKET_CG_LOCK_FELLOW);
lockFellow.SetGuid(1001);
lockFellow.SendPacket();
}
//伙伴解锁
public void OnUnLockClick()
{
CG_UNLOCK_FELLOW unlockFellow = (CG_UNLOCK_FELLOW)PacketDistributed.CreatePacket(MessageID.PACKET_CG_UNLOCK_FELLOW);
unlockFellow.SetGuid(0);
unlockFellow.SendPacket();
}
//放生
public void LetFreeClick()
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
return;
if (pet.Attached)
{
GUIData.AddNotifyData(GCGame.Table.StrDictionary.GetClientDictionaryString("#{20188}"));
return;
}
if (pet.Called || pet.Helped )
{
GUIData.AddNotifyData(GCGame.Table.StrDictionary.GetClientDictionaryString("#{20112}"));
return;
}
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{20113}", 3000), "", AskLetFree);
}
public void AskLetFree()
{
if (JudgeMoneyLogic.IsMoneyEnough(MONEYTYPE.MONEYTYPE_COIN_BIND, 3000))
{
CG_RESOLVE_FELLOW send = (CG_RESOLVE_FELLOW)PacketDistributed.CreatePacket(MessageID.PACKET_CG_RESOLVE_FELLOW);
send.SetGuid(PetMainWnd.CurrentSelectFellowId);
send.SendPacket();
}
}
//详细属性
public void OPenDetailWnd(bool state = true)
{
if (GameManager.gameManager.PlayerDataPool.FellowContainer == null)
return;
if(state)
{
BaseAttrWnd.SetActive(false);
DetailAttrWnd.SetActive(true);
}
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
return;
Tab_PromoteCultivation atitudeData = TableManager.GetPromoteCultivationByID(pet.cultivation,0);
if (atitudeData == null)
return;
int sawyID = pet.sawy / 10;
Tab_PromoteSavvy Savvy = TableManager.GetPromoteSavvyByID(sawyID, 0);
if (Savvy == null)
return;
float addRate1 = Savvy.AddAptitude * 1.0f / 100.0f;
float addRate = atitudeData.AddAptitudePer * 1.0f / 100.0f;
Boneatitude.text = string.Format("{0}<color=#721fadff>(+{1}%)</color>", pet.Boneatitude, addRate1+addRate);
Forceatitude.text = string.Format("{0}<color=#721fadff>(+{1}%)</color>", pet.Forceatitude, addRate1+addRate);
Poweratitude.text = string.Format("{0}<color=#721fadff>(+{1}%)</color>", pet.Poweratitude, addRate1+addRate);
Smartatitude.text = string.Format("{0}<color=#721fadff>(+{1}%)</color>", pet.Smartatitude, addRate1+addRate);
Agileatitude.text = string.Format("{0}<color=#721fadff>(+{1}%)</color>", pet.Agileatitude, addRate1+addRate);
bone.text = pet.bone.ToString();
force.text = pet.force.ToString();
power.text = pet.power.ToString();
smart.text = pet.smart.ToString();
agile.text = pet.agile.ToString();
hit.text = pet.hit.ToString();
avoid.text = pet.avoid.ToString();
detailattack.text = pet.attack.ToString();
detailblood.text = pet.blood.ToString();
detailphysical.text = pet.physical.ToString();
detailmagic.text = pet.magic.ToString();
if (detailAptitudeStart!=null)
{
detailAptitudeStart.InitStart(pet.AptitudeTotle);
}
}
public void ShowAddExpItem()
{
/*
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
{
return;
}*/
ShowItemSameUseTip.ShowToolTips((int)Games.Item.ItemClass.FELLOW,(int)Games.Item.FellowSubClass.EEP,Vector3.zero);
}
public void ShowAddLiftItem()
{
/*Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
{
return;
}*/
ShowItemSameUseTip.ShowToolTips((int)Games.Item.ItemClass.FELLOW, (int)Games.Item.FellowSubClass.LIFT, Vector3.zero);
}
public void OnClick_SkillTip()
{
MessageHelpLogic.ShowHelpMessage(14);
}
}