286 lines
11 KiB
C#
286 lines
11 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using GCGame.Table;
|
|
using Games.Events;
|
|
using Games.Item;
|
|
|
|
namespace Games.LogicObj
|
|
{
|
|
public partial class Obj_Fellow : Obj_Character
|
|
{
|
|
public enum FellowDialogType
|
|
{
|
|
GetGameItem = 1, //主人获得物品
|
|
ChangeScene = 2, //切换场景的冒泡
|
|
MonsterCheck = 3, //周边怪物检测
|
|
NoConditionCheck = 4, //无条件触发
|
|
EnemyInTeam = 5, //队伍里有非好友玩家
|
|
OtherPlayerCheck = 6, //周边玩家检测
|
|
}
|
|
|
|
struct DialogInfo
|
|
{
|
|
public string dialogStr;
|
|
public int type;
|
|
public int typeIndex;
|
|
public int dialogIndex;
|
|
public bool m_otherCansee;
|
|
public float m_ContinueTime;
|
|
}
|
|
|
|
//private List<DialogInfo> m_dialogInfos = new List<DialogInfo>();
|
|
private float lastShowTime = 0;
|
|
private float lastCanShowTime = 0;
|
|
|
|
private void InitFellowDialog()
|
|
{
|
|
Hashtable calbackMoveparam1 = new Hashtable();
|
|
calbackMoveparam1["name"] = "StartCheck";
|
|
MessageEventCallBack fun1 = StartCheck;
|
|
calbackMoveparam1.Add("callFun", fun1);
|
|
EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.FellowDialogEvent, calbackMoveparam1);
|
|
CheckSceneChange();
|
|
StopCoroutine(CheckNoCondition(0));
|
|
Tab_FellowDialog fellowDialog = TableManager.GetFellowDialogByID((int)FellowDialogType.NoConditionCheck, 0);
|
|
if(fellowDialog!=null)
|
|
{
|
|
int timeCheck = -1;
|
|
int.TryParse(fellowDialog.GetParambyIndex(0), out timeCheck);
|
|
if (timeCheck <= 0)
|
|
return;
|
|
StartCoroutine(CheckNoCondition(timeCheck));
|
|
}
|
|
}
|
|
|
|
public override void DestroyObj()
|
|
{
|
|
base.DestroyObj();
|
|
if(IsOwnedByMainPlayer())
|
|
EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.FellowDialogEvent, "StartCheck");
|
|
}
|
|
|
|
//服务器广播的其它宠物的冒泡
|
|
public void AddOtherFellowDialog(int dialogType,int typeIndex, int dialogIndex)
|
|
{
|
|
Tab_FellowDialog tabDialog = TableManager.GetFellowDialogByID(dialogType, typeIndex);
|
|
if (tabDialog == null)
|
|
return;
|
|
if (Time.time - lastShowTime < lastCanShowTime)
|
|
return;
|
|
DialogInfo dialogInfo = new DialogInfo();
|
|
dialogInfo.m_otherCansee = false;
|
|
dialogInfo.m_ContinueTime = tabDialog.Continue / 1000;
|
|
dialogInfo.dialogStr = tabDialog.GetDialogbyIndex(dialogIndex);
|
|
dialogInfo.dialogIndex = dialogIndex;
|
|
dialogInfo.type = dialogType;
|
|
dialogInfo.typeIndex = typeIndex;
|
|
ShowNextDialog(dialogInfo);
|
|
lastCanShowTime = (tabDialog.Continue + tabDialog.CDTime) / 1000;
|
|
lastShowTime = Time.time;
|
|
}
|
|
|
|
public bool AddDialogText(Tab_FellowDialog tabDialog,int index)
|
|
{
|
|
if (tabDialog == null)
|
|
return false;
|
|
if (Time.time - lastShowTime < lastCanShowTime)
|
|
return false;
|
|
Tab_SceneClass sceneClass = TableManager.GetSceneClassByID(GameManager.gameManager.RunningScene, 0);
|
|
if (sceneClass == null)
|
|
return false;
|
|
if (((1 << sceneClass.Type) & tabDialog.SceneType) == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
float random = Random.Range(1, 10000);
|
|
if (random > tabDialog.ShowChance)
|
|
return false;
|
|
List<int> ids = new List<int>();
|
|
for(int i=0;i<tabDialog.getDialogCount();i++)
|
|
{
|
|
string dialogTipStr = tabDialog.GetDialogbyIndex(i);
|
|
if (dialogTipStr != "-1" && string.IsNullOrEmpty(dialogTipStr) == false)
|
|
{
|
|
ids.Add(i);
|
|
}
|
|
}
|
|
if (ids.Count <= 0)
|
|
return false;
|
|
int randomIndex = Random.Range(0, ids.Count);
|
|
|
|
string dialogStr = tabDialog.GetDialogbyIndex(ids[randomIndex]);
|
|
if (string.IsNullOrEmpty(dialogStr))
|
|
return false;
|
|
|
|
DialogInfo dialogInfo = new DialogInfo();
|
|
dialogInfo.m_otherCansee = tabDialog.OtherCanSee;
|
|
dialogInfo.m_ContinueTime = tabDialog.Continue / 1000;
|
|
dialogInfo.dialogStr = dialogStr;
|
|
dialogInfo.dialogIndex = ids[randomIndex];
|
|
dialogInfo.type = tabDialog.Id;
|
|
dialogInfo.typeIndex = index;
|
|
ShowNextDialog(dialogInfo);
|
|
lastCanShowTime = (tabDialog.Continue + tabDialog.CDTime) / 1000;
|
|
lastShowTime = Time.time;
|
|
return true;
|
|
}
|
|
|
|
private void ShowNextDialog(DialogInfo dialogInfo)
|
|
{
|
|
Games.ChatHistory.ChatHistoryItem histroy = new Games.ChatHistory.ChatHistoryItem();
|
|
histroy.ChatInfo = dialogInfo.dialogStr;
|
|
histroy.Duration = dialogInfo.m_ContinueTime;
|
|
histroy.EChannel = GC_CHAT.CHATTYPE.CHAT_TYPE_INVALID;
|
|
ShowChatBubble(histroy);
|
|
|
|
if (dialogInfo.m_otherCansee)
|
|
{
|
|
SendDialogToOther(dialogInfo);
|
|
}
|
|
}
|
|
|
|
void SendDialogToOther(DialogInfo dialogInfo)
|
|
{
|
|
CG_FELLOW_BUBBLE send = (CG_FELLOW_BUBBLE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_FELLOW_BUBBLE);
|
|
send.SetFellowObjId(ServerID);
|
|
send.SetPlayerObjId(Singleton<ObjManager>.Instance.MainPlayer.ServerID);
|
|
send.SetSituationIndex(dialogInfo.type);
|
|
send.SetSituationChildIndex(dialogInfo.typeIndex);
|
|
send.SetBubbleIndex(dialogInfo.dialogIndex);
|
|
send.SendPacket();
|
|
}
|
|
|
|
//开启冒泡检测
|
|
public void StartCheck(Hashtable addparam, Hashtable sendparam)
|
|
{
|
|
if (sendparam == null || sendparam.ContainsKey("type") == false)
|
|
return;
|
|
FellowDialogType type = (FellowDialogType)sendparam["type"];
|
|
switch(type)
|
|
{
|
|
case FellowDialogType.GetGameItem:
|
|
{
|
|
int dataid = (int)sendparam["dataID"];
|
|
CheckItemChange(dataid);
|
|
}
|
|
break;
|
|
case FellowDialogType.MonsterCheck:
|
|
{
|
|
int roleBassId = (int)sendparam["roleBassId"];
|
|
CheckMonster(roleBassId);
|
|
}
|
|
break;
|
|
case FellowDialogType.EnemyInTeam:
|
|
{
|
|
int index = (int)sendparam["index"];
|
|
CheckFriend(index);
|
|
}
|
|
break;
|
|
case FellowDialogType.OtherPlayerCheck:
|
|
{
|
|
int profession = (int)sendparam["profession"];
|
|
CheckOtherPlayer(profession);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
bool CheckSceneChange()
|
|
{
|
|
List<Tab_FellowDialog> fellowDialogs = TableManager.GetFellowDialogByID((int)FellowDialogType.ChangeScene);
|
|
for(int i=0;i< fellowDialogs.Count;i++)
|
|
{
|
|
Tab_FellowDialog fellowDialog = fellowDialogs[i];
|
|
int sceneId = 0;
|
|
|
|
int.TryParse(fellowDialog.GetParambyIndex(0), out sceneId);
|
|
if (sceneId == GameManager.gameManager.RunningScene)
|
|
{
|
|
return AddDialogText(fellowDialog,i);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool CheckFriend(int index)
|
|
{
|
|
if ((GameManager.gameManager.PlayerDataPool.TeamInfo.teamMember[index].IsValid() && GameManager.gameManager.PlayerDataPool.FriendList.IsExist(GameManager.gameManager.PlayerDataPool.TeamInfo.teamMember[index].Guid) == false))
|
|
{
|
|
Tab_FellowDialog fellowDialog = TableManager.GetFellowDialogByID((int)FellowDialogType.EnemyInTeam,0);
|
|
return AddDialogText(fellowDialog,0);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool CheckItemChange(int dataid)
|
|
{
|
|
Tab_CommonItem line = TableManager.GetCommonItemByID(dataid, 0);
|
|
if (line == null)
|
|
{
|
|
return false;
|
|
}
|
|
List<Tab_FellowDialog> fellowDialogs = TableManager.GetFellowDialogByID((int)FellowDialogType.GetGameItem);
|
|
for (int i = 0; i < fellowDialogs.Count; i++)
|
|
{
|
|
Tab_FellowDialog fellowDialog = fellowDialogs[i];
|
|
int itemQua = -1;
|
|
int.TryParse(fellowDialog.GetParambyIndex(1), out itemQua);
|
|
if (line.Quality >= itemQua)
|
|
{
|
|
return AddDialogText(fellowDialog,i);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool CheckMonster(int roleBassId)
|
|
{
|
|
List<Tab_FellowDialog> fellowDialogs = TableManager.GetFellowDialogByID((int)FellowDialogType.MonsterCheck);
|
|
for (int i = 0; i < fellowDialogs.Count; i++)
|
|
{
|
|
Tab_FellowDialog fellowDialog = fellowDialogs[i];
|
|
int roleId = -1;
|
|
int.TryParse(fellowDialog.GetParambyIndex(0), out roleId);
|
|
if (roleId == roleBassId)
|
|
{
|
|
return AddDialogText(fellowDialog,i);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool CheckOtherPlayer(int profession)
|
|
{
|
|
List<Tab_FellowDialog> fellowDialogs = TableManager.GetFellowDialogByID((int)FellowDialogType.OtherPlayerCheck);
|
|
for (int i = 0; i < fellowDialogs.Count; i++)
|
|
{
|
|
Tab_FellowDialog fellowDialog = fellowDialogs[i];
|
|
int professionTab = -1;
|
|
int.TryParse(fellowDialog.GetParambyIndex(0), out professionTab);
|
|
if (profession == professionTab)
|
|
{
|
|
return AddDialogText(fellowDialog,i);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
IEnumerator CheckNoCondition(float checkTime)
|
|
{
|
|
while(true)
|
|
{
|
|
yield return new WaitForSeconds(checkTime);
|
|
Tab_FellowDialog fellowDialog = TableManager.GetFellowDialogByID((int)FellowDialogType.NoConditionCheck, 0);
|
|
if (fellowDialog == null)
|
|
yield break;
|
|
AddDialogText(fellowDialog,0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|