2021-08-08 20:04:15 +01:00
|
|
|
|
using QSB.CampfireSync.WorldObjects;
|
|
|
|
|
using QSB.ClientServerStateSync;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.Events;
|
2020-12-14 16:28:03 +00:00
|
|
|
|
using QSB.Messaging;
|
2021-02-08 20:04:14 +00:00
|
|
|
|
using QSB.QuantumSync;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.TranslationSync.WorldObjects;
|
2021-08-08 20:04:15 +01:00
|
|
|
|
using QSB.TranslationSync;
|
2020-08-22 20:21:13 +01:00
|
|
|
|
using QSB.Utility;
|
2020-12-11 22:42:21 +00:00
|
|
|
|
using QSB.WorldSync;
|
2021-08-08 20:04:15 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-08-15 14:22:56 +01:00
|
|
|
|
using System.Linq;
|
2021-08-08 20:04:15 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
using OWML.Utils;
|
2020-08-10 14:40:06 +01:00
|
|
|
|
|
2020-11-03 21:33:48 +00:00
|
|
|
|
namespace QSB.Player.Events
|
2020-08-10 14:40:06 +01:00
|
|
|
|
{
|
2021-08-08 20:04:15 +01:00
|
|
|
|
// Can be sent by any client (including host) to signal they want latest worldobject, player, and server infomation
|
|
|
|
|
public class RequestStateResyncEvent : QSBEvent<PlayerMessage>
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-08-08 20:04:15 +01:00
|
|
|
|
public override EventType Type => EventType.RequestStateResync;
|
2020-08-10 14:40:06 +01:00
|
|
|
|
|
2021-08-08 20:04:15 +01:00
|
|
|
|
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBRequestStateResync, Handler);
|
|
|
|
|
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBRequestStateResync, Handler);
|
2020-08-15 20:32:58 +01:00
|
|
|
|
|
2021-08-08 20:04:15 +01:00
|
|
|
|
private void Handler()
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"Sending QSBRequestStateResync");
|
|
|
|
|
SendEvent(CreateMessage());
|
|
|
|
|
}
|
2020-08-15 21:52:43 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private PlayerMessage CreateMessage() => new PlayerMessage
|
|
|
|
|
{
|
2021-08-08 20:04:15 +01:00
|
|
|
|
AboutId = LocalPlayerId
|
2020-12-02 21:23:01 +00:00
|
|
|
|
};
|
2020-08-10 18:17:54 +02:00
|
|
|
|
|
2021-08-08 20:04:15 +01:00
|
|
|
|
public override void OnReceiveRemote(bool isHost, PlayerMessage message)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-08-08 20:04:15 +01:00
|
|
|
|
DebugLog.DebugWrite($"OnReceiveRemote RequestStateResyncEvent");
|
2020-12-11 22:42:21 +00:00
|
|
|
|
|
2021-08-08 20:04:15 +01:00
|
|
|
|
// if host, send worldobject and server states
|
|
|
|
|
|
|
|
|
|
if (isHost)
|
2020-12-19 10:56:25 +00:00
|
|
|
|
{
|
2021-08-08 20:04:15 +01:00
|
|
|
|
DebugLog.DebugWrite($"SENDING SERVER STATE");
|
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBServerState, ServerStateManager.Instance.GetServerState());
|
|
|
|
|
|
|
|
|
|
DebugLog.DebugWrite($"SENDING PLAYER INFORMATION");
|
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBPlayerInformation);
|
|
|
|
|
|
|
|
|
|
SendWorldObjectInfo();
|
|
|
|
|
|
2020-12-19 10:56:25 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 20:04:15 +01:00
|
|
|
|
// if client, send player and client states
|
|
|
|
|
|
|
|
|
|
DebugLog.DebugWrite($"SENDING PLAYER INFORMATION");
|
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBPlayerInformation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SendWorldObjectInfo()
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"SENDING WORLDOBJECT INFORMATION");
|
|
|
|
|
|
2021-07-07 23:04:00 +01:00
|
|
|
|
QSBWorldSync.DialogueConditions.ForEach(condition
|
2021-07-07 09:05:39 +01:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.DialogueCondition, condition.Key, condition.Value));
|
2020-12-31 12:10:55 +00:00
|
|
|
|
|
2021-07-07 23:04:00 +01:00
|
|
|
|
QSBWorldSync.ShipLogFacts.ForEach(fact
|
2021-07-07 09:05:39 +01:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBRevealFact, fact.Id, fact.SaveGame, false));
|
2021-07-07 09:02:23 +01:00
|
|
|
|
|
2020-12-31 12:10:55 +00:00
|
|
|
|
foreach (var wallText in QSBWorldSync.GetWorldObjects<QSBWallText>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
|
2021-07-07 09:05:39 +01:00
|
|
|
|
{
|
2021-07-07 23:04:00 +01:00
|
|
|
|
wallText.GetTranslatedIds().ForEach(id
|
2021-07-07 09:05:39 +01:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.WallText, wallText.ObjectId, id));
|
|
|
|
|
}
|
2020-12-31 12:10:55 +00:00
|
|
|
|
|
|
|
|
|
foreach (var computer in QSBWorldSync.GetWorldObjects<QSBComputer>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
|
2021-07-07 09:05:39 +01:00
|
|
|
|
{
|
2021-07-07 23:04:00 +01:00
|
|
|
|
computer.GetTranslatedIds().ForEach(id
|
2021-07-07 09:05:39 +01:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.Computer, computer.ObjectId, id));
|
|
|
|
|
}
|
2020-12-31 12:10:55 +00:00
|
|
|
|
|
|
|
|
|
foreach (var vesselComputer in QSBWorldSync.GetWorldObjects<QSBVesselComputer>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
|
2021-07-07 09:05:39 +01:00
|
|
|
|
{
|
2021-07-07 23:04:00 +01:00
|
|
|
|
vesselComputer.GetTranslatedIds().ForEach(id
|
2021-07-07 09:05:39 +01:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.VesselComputer, vesselComputer.ObjectId, id));
|
|
|
|
|
}
|
2021-02-08 20:04:14 +00:00
|
|
|
|
|
|
|
|
|
var list = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().ToList();
|
|
|
|
|
for (var i = 0; i < list.Count; i++)
|
2021-07-07 09:05:39 +01:00
|
|
|
|
{
|
2021-02-10 19:34:41 +00:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, i, list[i].ControllingPlayer);
|
2021-07-07 09:05:39 +01:00
|
|
|
|
}
|
2021-03-29 23:41:12 +01:00
|
|
|
|
|
2021-07-07 23:04:00 +01:00
|
|
|
|
QSBWorldSync.GetWorldObjects<QSBCampfire>().ForEach(campfire
|
2021-07-07 09:05:39 +01:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState()));
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-08 20:04:15 +01:00
|
|
|
|
}
|