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

576 lines
21 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using Games.GlobeDefine;
using GCGame.Table;
using Games.LogicObj;
using Games.Events;
using Games.Scene;
public class ReliveLogic : MonoBehaviour
{
public struct reliveTimeDownData
{
public int overTime;
public string name;
public int delayTime;
public ZYButton btn;
}
public struct ReLiveData
{
public float retTime; //倒计时
public int skillId; //被动技能复活的技能ID
public string Objname; //让自己复活的友方名字
public int type; //复活类型 0被被人主动复活 1被动复活 -1原地复活
public string killername; //被谁杀死的
public ReLiveData(int time,int skill,string name,int rtype,string killer)
{
retTime = time;
skillId = skill;
Objname = name;
type = rtype;
killername = killer;
}
public void ClearUp()
{
retTime = -1;
skillId = -1;
Objname = "";
type = -1;
killername = "";
}
}
//货币的文字描述
public static Dictionary<int, int> MoneytypeNamesTableId = new Dictionary<int, int>()
{
{(int)MONEYTYPE.MONEYTYPE_COIN ,6003},
{(int)MONEYTYPE.MONEYTYPE_YUANBAO ,6001},
{(int)MONEYTYPE.MONEYTYPE_YUANBAO_BIND ,6002},
{(int)MONEYTYPE.MONEYTYPE_COIN_BIND ,6004},
};
public GameObject SimpleRelive; //原地复活等一般的复活方式界面
public GameObject OtherRelive; //玩家被动技能或者友方技能等的特殊技能复活方式界面
public GameObject ViewToOtherPlayer; //视角切换相关的
public Button OkBtn;
public Text killerName; //凶手名称描述
public Text otherRelive; //其它方式复活的描述
public GameObject ReliveBtnClone;
public bool isZiJin = true;
private Dictionary<int, GameObject> reliveBtns = new Dictionary<int, GameObject>();
void Start()
{
InvokeRepeating("UpdateBtnInfo", 1, 1);
}
public void RemoveListen()
{
EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.FreshReLiveData, "ReliveLogicFreshUI");
EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.FreshReLiveKillerName, "FreshReLiveKillerName");
EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.MainCameraFocusValid, "ReliveLogic");
}
public void AddListen()
{
Hashtable calbackparam = new Hashtable();
calbackparam["name"] = "ReliveLogicFreshUI";
MessageEventCallBack fun = FreshUI;
calbackparam["callFun"] = fun;
EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.FreshReLiveData, calbackparam);
Hashtable calbackparam1 = new Hashtable();
calbackparam1["name"] = "FreshReLiveKillerName";
MessageEventCallBack fun1 = ReLiveKillerName;
calbackparam1["callFun"] = fun1;
EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.FreshReLiveKillerName, calbackparam1);
Hashtable calbackparam2 = new Hashtable();
calbackparam2["name"] = "ReliveLogic";
MessageEventCallBack fun2 = ChangeOtherView;
calbackparam2["callFun"] = fun2;
EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.MainCameraFocusValid, calbackparam2);
}
public void ReLiveKillerName(Hashtable add, Hashtable send)
{
if (SimpleRelive != null && SimpleRelive.activeSelf)
{
killerName.text = StrDictionary.GetClientDictionaryString("#{33002}", GameManager.gameManager.PlayerDataPool.ReliveData.killername);
if (isZiJin == true && GameManager.gameManager.m_RunningScene == 658)
{
killerName.text = StrDictionary.GetClientDictionaryString("#{33002}", "");
}
}
}
bool IsOpenOtherLook()
{
Tab_SceneClass sceneinfo = TableManager.GetSceneClassByID(GameManager.gameManager.RunningScene, 0);
if (sceneinfo == null)
return false;
for (int i = 0; i < sceneinfo.getReliveIDCount(); i++)
{
int typeId = sceneinfo.GetReliveIDbyIndex(i);
Tab_Relive relive = TableManager.GetReliveByID(typeId, 0);
if (relive != null && typeId != 4) //只有技能复活的场景特殊处理 死亡后切换到队友的视角
{
return false;
}
}
return true;
}
public void FreshUI(Hashtable add,Hashtable send)
{
if(GameManager.gameManager.PlayerDataPool.ReliveData.type == -1)
{
CameraGrayOn();
OPenSimple();
}
else
{
CameraGrayOn();
OpenOther();
}
}
bool SimpleInit = false;
Dictionary<int, reliveTimeDownData> reliveTimeDowns = new Dictionary<int, reliveTimeDownData>();
public void OPenSimple()
{
SimpleRelive.SetActive(true);
OtherRelive.SetActive(false);
if(string.IsNullOrEmpty(GameManager.gameManager.PlayerDataPool.ReliveData.killername))
{
killerName.gameObject.SetActive(false);
}
else
{
killerName.gameObject.SetActive(true);
killerName.text = StrDictionary.GetClientDictionaryString("#{33003}", GameManager.gameManager.PlayerDataPool.ReliveData.killername);
if (isZiJin == true && GameManager.gameManager.m_RunningScene == 658)
{
killerName.text = StrDictionary.GetClientDictionaryString("#{79519}");
}
}
if (SimpleInit)
return;
Tab_SceneClass sceneinfo = TableManager.GetSceneClassByID(GameManager.gameManager.RunningScene, 0);
if(sceneinfo!=null)
{
List<int> keys = new List<int>(reliveBtns.Keys);
for(int i=0;i<keys.Count;i++)
{
reliveBtns[keys[i]].SetActive(false);
}
for(int i=0;i<sceneinfo.getReliveIDCount();i++)
{
int typeId = sceneinfo.GetReliveIDbyIndex(i);
Tab_Relive relive = TableManager.GetReliveByID(typeId, 0);
if (relive == null)
continue;
if (relive.IsNeedShowBtn != 1)
continue;
GameObject newReliveBtn = null;
if (reliveBtns.TryGetValue(relive.ReliveID,out newReliveBtn)==false)
{
newReliveBtn = Object.Instantiate(ReliveBtnClone) as GameObject;
}
if(newReliveBtn!=null)
{
reliveBtns[relive.ReliveID] = newReliveBtn;
newReliveBtn.transform.SetParent(ReliveBtnClone.transform.parent);
newReliveBtn.transform.localPosition = ReliveBtnClone.transform.localPosition;
newReliveBtn.transform.localScale = ReliveBtnClone.transform.localScale;
newReliveBtn.SetActive(true);
string btnName = relive.ReliveBtnName;
Transform childCost = newReliveBtn.transform.Find("ReliveCost");
if (childCost != null)
{
Text costText = childCost.gameObject.GetComponent<Text>();
if (costText != null)
{
ConsumData(relive.ConsumeId, costText, btnName);
}
}
ZYButton btn = newReliveBtn.GetComponentInChildren<ZYButton>();
if (btn != null)
{
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(delegate ()
{
SimpleAsk(relive.ReliveID);
});
}
reliveTimeDownData data;
data.btn = btn;
data.overTime = 0;
data.delayTime = (relive.LimitTime > 0 ? relive.LimitTime : 0);
if (relive.RetTime < 0)
{
if (data.delayTime > 0)
{
data.name = btnName;
data.delayTime = data.delayTime + (int)Time.realtimeSinceStartup;
data.btn.BtnName = string.Format("{0}({1}s)", StrDictionary.GetClientDictionaryString("#{1035}"), data.delayTime - (int)Time.realtimeSinceStartup);
reliveTimeDowns[relive.ReliveID] = data;
}
else
{
data.btn.BtnName = btnName;
}
}
else
{
if (GameManager.gameManager.PlayerDataPool.ReliveEntryTime > 0)
data.delayTime = 0;
data.overTime = (int)(Time.realtimeSinceStartup + relive.RetTime + data.delayTime);
if (GameManager.gameManager.PlayerDataPool.ReliveEntryTime < relive.RetTime)
{
data.overTime = (int)(Time.realtimeSinceStartup + relive.RetTime - GameManager.gameManager.PlayerDataPool.ReliveEntryTime);
}
data.name = btnName;
if (data.delayTime > 0)
{
data.delayTime = data.delayTime + (int)Time.realtimeSinceStartup;
data.btn.BtnName = string.Format("{0}({1}s)", StrDictionary.GetClientDictionaryString("#{1035}"), data.delayTime - (int)Time.realtimeSinceStartup);
}
else
data.btn.BtnName = string.Format("{0}({1}s)", btnName, data.overTime - (int)Time.realtimeSinceStartup);
reliveTimeDowns[relive.ReliveID] = data;
}
data.btn.interactable = (data.delayTime <= 0 && data.overTime <= 0);
}
}
SimpleInit = true;
}
}
public void SimpleAsk(int reliveID)
{
foreach (var reliveTimeDown in reliveTimeDowns)
{
if(reliveID == reliveTimeDown.Key)
{
if(reliveTimeDown.Value.delayTime - Time.realtimeSinceStartup >0)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{1027}"));
return;
}
}
}
Tab_Relive relive = TableManager.GetReliveByID(reliveID, 0);
if (relive == null)
return;
Tab_Consum consum = SweepConSumTab(GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level, relive.ConsumeId);
if (consum != null && GCGame.Utils.VipFreeLiveLeave() <= 0)
{
for (int j = 0; j < consum.getConsumeTypeCount(); j++)
{
int gettype = consum.GetConsumeTypebyIndex(j);
int type = (int)CONSUM_TYPE.MONEY;
if (gettype == type)
{
if (GameManager.gameManager.PlayerDataPool.Money.GetMoneyByType((MONEYTYPE)consum.GetConsumeIdbyIndex(j)) < consum.GetConsumeValbyIndex(j))
{
string tip = StrDictionary.GetClientDictionaryString("#{39512}");
if((MONEYTYPE)consum.GetConsumeIdbyIndex(j) == MONEYTYPE.MONEYTYPE_YUANBAO_BIND)
tip = StrDictionary.GetClientDictionaryString("#{41009}");
MessageBoxLogic.OpenOKCancelBox(tip, null, delegate ()
{
JudgeMoneyLogic.ShowSwitchMoneyPanel((MONEYTYPE)consum.GetConsumeIdbyIndex(j), true);
}, null);
return;
}
}
}
}
AskRelive(reliveID);
}
public void AskNotSkillRelive()
{
CG_REFUSE_RELIVE packet = (CG_REFUSE_RELIVE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REFUSE_RELIVE);
packet.Nilparam = 0;
packet.SendPacket();
if(IsOpenOtherLook())
{
OpenChangeView();
}
else
OPenSimple();
}
public Tab_Consum SweepConSumTab(int level,int consumId)
{
var consums = TableManager.GetConsum().Values;
foreach (var item in consums)
{
if(item.Level == level
&& item.ConsumId== consumId)
{
return item;
}
}
return null;
}
public void ConsumData(int consumId,Text relivePay,string reliveName)
{
Tab_Consum consum = SweepConSumTab(GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level,consumId);
if(consum!=null)
{
string tip = StrDictionary.GetClientDictionaryString("#{33004}", reliveName);
string typeNames = "";
string values = "";
for (int j = 0; j < consum.getConsumeTypeCount(); j++)
{
int gettype = consum.GetConsumeTypebyIndex(j);
int type = (int)CONSUM_TYPE.MONEY;
if (gettype == type)
{
if (MoneytypeNamesTableId.ContainsKey(consum.GetConsumeIdbyIndex(j)))
{
int id = MoneytypeNamesTableId[consum.GetConsumeIdbyIndex(j)];
Tab_StrDictionary TabStrDictionary = TableManager.GetStrDictionaryByID(id, 0);
if (TabStrDictionary != null)
{
typeNames += TabStrDictionary.StrDictionary + "/";
}
values += consum.GetConsumeValbyIndex(j) + "/";
}
}
}
if (typeNames.Length > 1)
typeNames = typeNames.Remove(typeNames.Length - 1);
if (values.Length > 1)
values = values.Remove(values.Length - 1);
relivePay.text = string.Format("{0}{1}:{2}", tip, typeNames, values);
}
else
{
if(relivePay!=null)
{
relivePay.transform.gameObject.SetActive(false);
}
}
}
public void UpdateBtnInfo()
{
if(SimpleRelive.activeSelf)
{
List<int> removeList = new List<int>();
foreach (var reliveTimeDown in reliveTimeDowns)
{
if(reliveTimeDown.Value.delayTime > 0 && reliveTimeDown.Value.delayTime - (int)Time.realtimeSinceStartup > 0 )
{
reliveTimeDown.Value.btn.BtnName = string.Format("{0}({1}s)", StrDictionary.GetClientDictionaryString("#{1035}"), reliveTimeDown.Value.delayTime - (int)Time.realtimeSinceStartup);
continue;
}
reliveTimeDown.Value.btn.interactable = true;
if (reliveTimeDown.Value.overTime > 0 && reliveTimeDown.Value.overTime - Time.realtimeSinceStartup < 0)
{
reliveTimeDowns.Clear();
if (SimpleRelive.activeSelf)
AskRelive(reliveTimeDown.Key);
return;
}
if(reliveTimeDown.Value.overTime > 0)
{
reliveTimeDown.Value.btn.BtnName = string.Format("{0}({1}s)", reliveTimeDown.Value.name, reliveTimeDown.Value.overTime - (int)Time.realtimeSinceStartup);
continue;
}
reliveTimeDown.Value.btn.BtnName = reliveTimeDown.Value.name;
removeList.Add(reliveTimeDown.Key);
}
for(int i=0;i<removeList.Count;i++)
{
reliveTimeDowns.Remove(removeList[i]);
}
}
else
{
if (GameManager.gameManager.PlayerDataPool.ReliveData.retTime > 0 && Time.realtimeSinceStartup - GameManager.gameManager.PlayerDataPool.ReliveData.retTime >= 0)
{
GameManager.gameManager.PlayerDataPool.ReliveData.retTime = 0;
OPenSimple();
}
}
}
public void OpenOther()
{
ViewToOtherPlayer.SetActive(false);
SimpleRelive.SetActive(false);
OtherRelive.SetActive(true);
if(GameManager.gameManager.PlayerDataPool.ReliveData.type == 0)
{
otherRelive.text = StrDictionary.GetClientDictionaryString("#{33000}", GameManager.gameManager.PlayerDataPool.ReliveData.Objname);
OkBtn.onClick.RemoveAllListeners();
OkBtn.onClick.AddListener(delegate ()
{
AskRelive((int)GameDefine_Globe.RELIVE_TYPE.RELIVE_OTHER);
});
}
else
{
Tab_SkillEx skill = TableManager.GetSkillExByID(GameManager.gameManager.PlayerDataPool.ReliveData.skillId, 0);
if (skill!=null)
{
Tab_SkillBase skillbase = TableManager.GetSkillBaseByID(skill.BaseId, 0);
if(skillbase != null)
{
otherRelive.text = StrDictionary.GetClientDictionaryString("#{33001}", skillbase.Name);
OkBtn.onClick.RemoveAllListeners();
OkBtn.onClick.AddListener(delegate ()
{
AskRelive((int)GameDefine_Globe.RELIVE_TYPE.RELIVE_SKILL);
});
}
}
}
}
public void OpenChangeView()
{
ViewToOtherPlayer.SetActive(true);
SimpleRelive.SetActive(false);
OtherRelive.SetActive(false);
Click_ChangeToNextView();
}
IEnumerator OpenRelifeWnd()
{
if(IsOpenOtherLook()==true)
{
yield return new WaitForSeconds(1f);
CameraGrayOff();
OpenChangeView();
yield break;
}
CameraGrayOn();
yield return new WaitForSeconds(1.5f);
FreshUI(null, null);
}
void OnEnable()
{
ViewToOtherPlayer.SetActive(false);
SimpleRelive.SetActive(false);
OtherRelive.SetActive(false);
AddListen();
StartCoroutine(OpenRelifeWnd());
}
public void ChangeOtherView(Hashtable add,Hashtable send)
{
Click_ChangeToNextView();
}
public void Click_ChangeToNextView()
{
for (int i = 0; i < GameManager.gameManager.PlayerDataPool.TeamInfo.teamMember.Length; i++)
{
TeamMember member = GameManager.gameManager.PlayerDataPool.TeamInfo.teamMember[i];
if (GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid == member.Guid)
continue;
var sceneCopy = TableManager.GetFubenByID(member.SceneClassID, 0);
if (sceneCopy == null)
continue;
if (sceneCopy.GetSceneIdbyIndex(0) != GameManager.gameManager.RunningScene || member.SceneInstID != SceneData.SceneInst)
{
continue;
}
if (member.HP <= 0)
continue;
CG_COMPETITION_OPTION send = (CG_COMPETITION_OPTION)PacketDistributed.CreatePacket(MessageID.PACKET_CG_COMPETITION_OPTION);
send.SetOptiontype((int)CG_COMPETITION_OPTION.COMPETITION_TYPE.WATCH);
send.SetGuid(member.Guid);
send.SetParam(1);
send.SendPacket();
return;
}
}
void OnDisable()
{
SimpleInit = false;
CameraGrayOff();
RemoveListen();
reliveTimeDowns.Clear();
}
public void CloseWindow()
{
UIManager.CloseUI(UIInfo.Relive);
}
public void RliveCityOK()
{
if (Singleton<ObjManager>.Instance.MainPlayer == null || Singleton<ObjManager>.Instance.MainPlayer.IsDie() == false)
{
CloseWindow();
return;
}
CG_ASK_RELIVE packet = (CG_ASK_RELIVE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_ASK_RELIVE);
packet.SetType((int)GameDefine_Globe.RELIVE_TYPE.RELIVE_CITY);
packet.SendPacket();
}
public void AskRelive(int reliveType)
{
if(Singleton<ObjManager>.Instance.MainPlayer==null || Singleton<ObjManager>.Instance.MainPlayer.IsDie()==false)
{
CloseWindow();
return;
}
CG_ASK_RELIVE packet = (CG_ASK_RELIVE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_ASK_RELIVE);
packet.SetType(reliveType);
packet.SendPacket();
}
#region deathEffect
public Material _GrayMaterial;
private void CameraGrayOn()
{
if (SceneLogic.CameraController != null)
{
var grayEffect = SceneLogic.CameraController.AddCameraEffect<CameraGrayEffect>();
grayEffect.mat = _GrayMaterial;
}
}
private void CameraGrayOff()
{
if (SceneLogic.CameraController != null)
SceneLogic.CameraController.RemoveCameraEffect<CameraGrayEffect>();
}
#endregion
}