Files

364 lines
12 KiB
C#
Raw Permalink Normal View History

2024-08-23 15:49:34 +08:00

using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
using Games.GlobeDefine;
using GCGame.Table;
using GCGame;
public class Master
{
public Master()
{ }
#region relation
public RelationDataProto _MyMaster = null;
public List<RelationDataProto> _MyApprentices = new List<RelationDataProto>();
public void InitMasterInfo(GC_SYC_PREACH_LIST packet)
{
if (packet.HasMasterData)
{
_MyMaster = packet.MasterData;
}
else
{
_MyMaster = null;
}
_MyApprentices = new List<RelationDataProto>(packet.apprenticeDataList);
_MyApprentices.Sort((relationDataA, relationDataB) =>
{
if (relationDataA.Timeinfo > relationDataB.Timeinfo)
return 1;
else if (relationDataA.Timeinfo < relationDataB.Timeinfo)
return -1;
return 0;
});
_MyMasterMatchInfo.Clear();
if (packet.MasterOrder > 0)
{
_MyMasterMatchInfo.Add(0);
}
_MyApprenticesMatchInfo.Clear();
if (packet.ApprenticeOrder > 0)
{
_MyApprenticesMatchInfo.Add(0);
}
}
public string GetApprenticeCalling(RelationDataProto apprentice)
{
string calling = "";
var idx = _MyApprentices.IndexOf(apprentice) + 1;
switch (idx)
{
case 1:
calling = StrDictionary.GetClientDictionaryString("#{36200}");
break;
case 2:
calling = StrDictionary.GetClientDictionaryString("#{36201}");
break;
case 3:
calling = StrDictionary.GetClientDictionaryString("#{36202}");
break;
case 4:
calling = StrDictionary.GetClientDictionaryString("#{36203}");
break;
case 5:
calling = StrDictionary.GetClientDictionaryString("#{36204}");
break;
}
if (string.IsNullOrEmpty(calling))
return calling;
calling += StrDictionary.GetClientDictionaryString("#{7303}");
return calling;
}
#endregion
#region master match
private List<int> _MyMasterMatchInfo = new List<int>();
private List<int> _MyApprenticesMatchInfo = new List<int>();
private bool _IsMatchMaster = true;
private string _MatchTitleStr = "";
private class MatchInfo
{
public string Question;
public string[] Answers;
public bool LastAnswerAllRight;
public MatchInfo(string q, string[] a, bool lastARight = false)
{
Question = q;
Answers = a;
LastAnswerAllRight = lastARight;
}
}
private List<MatchInfo> _MatchQuestions = new List<MatchInfo>();
private void InitMatchQuestions(bool isMaster)
{
_MatchQuestions.Clear();
if (isMaster)
{
_MatchQuestions.Add(new MatchInfo(StrDictionary.GetClientDictionaryString("#{7203}"), new string[2] { StrDictionary.GetClientDictionaryString("#{7204}"), StrDictionary.GetClientDictionaryString("#{7205}") }));
_MatchQuestions.Add(new MatchInfo(StrDictionary.GetClientDictionaryString("#{7206}"), new string[3] { StrDictionary.GetClientDictionaryString("#{7204}"), StrDictionary.GetClientDictionaryString("#{7205}"), StrDictionary.GetClientDictionaryString("#{7207}") }, true));
_MatchQuestions.Add(new MatchInfo(StrDictionary.GetClientDictionaryString("#{7208}"), new string[3] { StrDictionary.GetClientDictionaryString("#{7209}"), StrDictionary.GetClientDictionaryString("#{7210}"), StrDictionary.GetClientDictionaryString("#{7211}") }, true));
_MatchQuestions.Add(new MatchInfo(StrDictionary.GetClientDictionaryString("#{7212}"), new string[3] { StrDictionary.GetClientDictionaryString("#{7213}"), StrDictionary.GetClientDictionaryString("#{7214}"), StrDictionary.GetClientDictionaryString("#{7215}") }));
}
else
{
_MatchQuestions.Add(new MatchInfo(StrDictionary.GetClientDictionaryString("#{7203}"), new string[2] { StrDictionary.GetClientDictionaryString("#{7204}"), StrDictionary.GetClientDictionaryString("#{7205}") }));
_MatchQuestions.Add(new MatchInfo(StrDictionary.GetClientDictionaryString("#{7224}"), new string[3] { StrDictionary.GetClientDictionaryString("#{7204}"), StrDictionary.GetClientDictionaryString("#{7205}"), StrDictionary.GetClientDictionaryString("#{7207}") }, true));
_MatchQuestions.Add(new MatchInfo(StrDictionary.GetClientDictionaryString("#{7225}"), new string[3] { StrDictionary.GetClientDictionaryString("#{7209}"), StrDictionary.GetClientDictionaryString("#{7210}"), StrDictionary.GetClientDictionaryString("#{7211}") }, true));
_MatchQuestions.Add(new MatchInfo(StrDictionary.GetClientDictionaryString("#{7226}"), new string[3] { StrDictionary.GetClientDictionaryString("#{7213}"), StrDictionary.GetClientDictionaryString("#{7214}"), StrDictionary.GetClientDictionaryString("#{7215}") }));
}
}
public void SelectMatchInfo(bool isMaster)
{
if (isMaster)
{
if (_MyApprentices.Count >= 4)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{7246}"));
return;
}
if (Singleton<ObjManager>.GetInstance().MainPlayer.BaseAttr.Level < 60)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{7245}"));
return;
}
}
else
{
if (_MyMaster != null)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{7247}"));
return;
}
}
_IsMatchMaster = isMaster;
if ((isMaster && _MyMasterMatchInfo.Count > 0) || (!isMaster && _MyApprenticesMatchInfo.Count > 0))
{
CG_REQ_PREACH_ORDER_FITLIST packet = (CG_REQ_PREACH_ORDER_FITLIST)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_PREACH_ORDER_FITLIST);
packet.SetType(_IsMatchMaster ? 2 : 1);
packet.SendPacket();
return;
}
_MyMasterMatchInfo.Clear();
InitMatchQuestions(isMaster);
if (_IsMatchMaster)
{
_MatchTitleStr = StrDictionary.GetClientDictionaryString("#{7201}");
}
else
{
_MatchTitleStr = StrDictionary.GetClientDictionaryString("#{7202}");
}
ShowMathcSelect(0);
}
private void ShowMathcSelect(int questionIdx)
{
MessageSelectLogic.ShowMessageSelect(
StrDictionary.GetClientDictionaryString("#{7200}"),
_MatchTitleStr,
_MatchQuestions[questionIdx].Question,
_MatchQuestions[questionIdx].Answers,
MatchSelectCallBack,
MatchSelectCancel
);
}
public void MatchSelectCallBack(int select)
{
if (_IsMatchMaster)
{
_MyMasterMatchInfo.Add(select);
if (_MyMasterMatchInfo.Count == 4)
{
MessageSelectLogic.ShowMessageResult(
StrDictionary.GetClientDictionaryString("#{7200}"),
_MatchTitleStr,
StrDictionary.GetClientDictionaryString("#{7216}", GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.RoleName),
new string[4] {
_MatchQuestions[0].Question + " " + _MatchQuestions[0].Answers[_MyMasterMatchInfo[0]],
_MatchQuestions[1].Question + " " + _MatchQuestions[1].Answers[_MyMasterMatchInfo[1]],
_MatchQuestions[2].Question + " " + _MatchQuestions[2].Answers[_MyMasterMatchInfo[2]],
_MatchQuestions[3].Question + " " + _MatchQuestions[3].Answers[_MyMasterMatchInfo[3]],
},
MatchResultOk,
MatchSelectCancel
);
}
else
{
ShowMathcSelect(_MyMasterMatchInfo.Count);
}
}
else
{
_MyApprenticesMatchInfo.Add(select);
if (_MyApprenticesMatchInfo.Count == 4)
{
MessageSelectLogic.ShowMessageResult(
StrDictionary.GetClientDictionaryString("#{7200}"),
_MatchTitleStr,
StrDictionary.GetClientDictionaryString("#{7216}", GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.RoleName),
new string[4] {
_MatchQuestions[0].Question + " " + _MatchQuestions[0].Answers[_MyApprenticesMatchInfo[0]],
_MatchQuestions[1].Question + " " + _MatchQuestions[1].Answers[_MyApprenticesMatchInfo[1]],
_MatchQuestions[2].Question + " " + _MatchQuestions[2].Answers[_MyApprenticesMatchInfo[2]],
_MatchQuestions[3].Question + " " + _MatchQuestions[3].Answers[_MyApprenticesMatchInfo[3]],
},
MatchResultOk,
MatchSelectCancel
);
}
else
{
ShowMathcSelect(_MyApprenticesMatchInfo.Count);
}
}
}
public void MatchSelectCancel()
{
MatchResultOk(false);
}
public void MatchResultOk(bool isOk)
{
if (!isOk)
{
if (_IsMatchMaster)
{
_MyMasterMatchInfo.Clear();
}
else
{
_MyApprenticesMatchInfo.Clear();
}
return;
}
Module.Log.LogModule.DebugLog("Is MatchResult Ok:" + isOk);
CG_POST_PREACH_ORDER packet = (CG_POST_PREACH_ORDER)PacketDistributed.CreatePacket(MessageID.PACKET_CG_POST_PREACH_ORDER);
PreachOrderProto matchInfo = new PreachOrderProto();
matchInfo.SetType(_IsMatchMaster ? 2:1);
if (_IsMatchMaster)
{
for (int i = 0; i < _MyMasterMatchInfo.Count; ++i)
{
if (_MatchQuestions[i].LastAnswerAllRight)
{
matchInfo.AddClaims(-1);
}
else
{
matchInfo.AddClaims(_MyMasterMatchInfo[i]);
}
}
}
else
{
for (int i = 0; i < _MyApprenticesMatchInfo.Count; ++i)
{
if (_MatchQuestions[i].LastAnswerAllRight)
{
matchInfo.AddClaims(-1);
}
else
{
matchInfo.AddClaims(_MyApprenticesMatchInfo[i]);
}
}
}
packet.OrderData = matchInfo;
packet.SendPacket();
}
#endregion
#region relieve relation
private ulong _RelieveGuid;
public void MasterRelieve(ulong guid, string name)
{
_RelieveGuid = guid;
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{7217}", name), "", OnRelieveOk);
}
public void OnRelieveOk()
{
Module.Log.LogModule.DebugLog("Relieve Relation:" + _RelieveGuid);
UIManager.CloseUI(UIInfo.MasterRelieveRoot);
CG_USER_BREAK_PREACH_RELATION packet = (CG_USER_BREAK_PREACH_RELATION)PacketDistributed.CreatePacket(MessageID.PACKET_CG_USER_BREAK_PREACH_RELATION);
packet.SetGuid(_RelieveGuid);
packet.SendPacket();
}
#endregion
#region
public void MasterPlayer(ulong guid, string name, int pro, int level)
{
UIManager.CloseUI(UIInfo.MasterRelieveRoot);
GameManager.gameManager.PlayerDataPool.ChatHistory.AddFriendChat(guid, name, Utils.GetProfessionSpriteName(pro), level, guid, 0, 0, null);
//未打开过则创建
FriendAndMailRoot.ShowFriendChat(guid, name);
}
#endregion
// 判断guid是否为师傅
public bool IsGuidisMaster(ulong guid)
{
if(_MyMaster != null && _MyMaster.HasGuid == true && _MyMaster.Guid == guid)
{
return true;
}
return false;
}
// 判断guid是否为徒弟
public bool IsGuidisApprentice(ulong guid)
{
if(_MyApprentices.Count > 0)
{
foreach(var item in _MyApprentices)
{
if(item.Guid == guid)
{
return true;
}
}
return false;
}
return false;
}
}