Files
7d2dXG/Mods/zzz_REBIRTH__Utils/Scripts/Network/NetPackageQuestNamedPOIGotoRebirth.cs
Nathaniel Cosford 062dfab2cd Patched
2025-05-30 01:04:40 +09:30

133 lines
6.0 KiB
C#

using System.Collections.Generic;
public class NetPackageQuestNamedPOIGotoRebirth : NetPackage
{
public NetPackageQuestNamedPOIGotoRebirth Setup(string _POIName, int _playerId, FastTags<TagGroup.Global> _questTags, int _questCode, NetPackageQuestNamedPOIGotoRebirth.QuestGotoTypes _gotoType, byte _difficulty, int posX = 0, int posZ = -1, float sizeX = 0f, float sizeY = 0f, float sizeZ = 0f, float offset = -1f, BiomeFilterTypes _biomeFilterType = BiomeFilterTypes.AnyBiome, string _biomeFilter = "")
{
////Log.Out("NetPackageQuestNamedPOIGotoRebirth-Setup");
this.playerId = _playerId;
this.questCode = _questCode;
this.GotoType = _gotoType;
this.questTags = _questTags;
this.position = new Vector2((float)posX, (float)posZ);
this.size = new Vector3(sizeX, sizeY, sizeZ);
this.difficulty = _difficulty;
this.biomeFilterType = _biomeFilterType;
this.biomeFilter = _biomeFilter;
this.POIName = _POIName;
return this;
}
public override void read(PooledBinaryReader _br)
{
////Log.Out("NetPackageQuestNamedPOIGotoRebirth-read");
this.playerId = _br.ReadInt32();
this.questCode = _br.ReadInt32();
this.GotoType = (NetPackageQuestNamedPOIGotoRebirth.QuestGotoTypes)_br.ReadByte();
this.questTags = FastTags<TagGroup.Global>.Parse(_br.ReadString());
this.position = new Vector2((float)_br.ReadInt32(), (float)_br.ReadInt32());
this.size = StreamUtils.ReadVector3(_br);
this.difficulty = _br.ReadByte();
this.biomeFilterType = (BiomeFilterTypes)_br.ReadByte();
this.biomeFilter = _br.ReadString();
this.POIName = _br.ReadString();
}
public override void write(PooledBinaryWriter _bw)
{
////Log.Out("NetPackageQuestNamedPOIGotoRebirth-write");
base.write(_bw);
_bw.Write(this.playerId);
_bw.Write(this.questCode);
_bw.Write((byte)this.GotoType);
_bw.Write(this.questTags.ToString());
_bw.Write((int)this.position.x);
_bw.Write((int)this.position.y);
StreamUtils.Write(_bw, this.size);
_bw.Write(this.difficulty);
_bw.Write((byte)this.biomeFilterType);
_bw.Write(this.biomeFilter);
_bw.Write(this.POIName);
}
public override void ProcessPackage(World _world, GameManager _callbacks)
{
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage START");
if (_world == null)
{
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage 1");
return;
}
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
{
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage 2");
for (int i = 0; i < 5; i++)
{
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage i: " + i);
EntityPlayer entityPlayer = GameManager.Instance.World.GetEntity(this.playerId) as EntityPlayer;
//Log.Out("ObjectiveGotoNamedPOIRebirth-GetPosition 3 prefab:" + this.POIName);
List<PrefabInstance> prefabInstances = GameManager.Instance.World.ChunkClusters[0].ChunkProvider.GetDynamicPrefabDecorator().GetDynamicPrefabs().FindAll(instance => instance.name.Contains(this.POIName));
if (prefabInstances.Count == 0)
{
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage 4");
return;
}
PrefabInstance prefabInstance = RebirthUtilities.FindClosesPrefabs(entityPlayer.position, prefabInstances, null, biomeFilterType, biomeFilter);
if (prefabInstance != null)
{
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage 5");
SingletonMonoBehaviour<ConnectionManager>.Instance.SendPackage(NetPackageManager.GetPackage<NetPackageQuestNamedPOIGotoRebirth>().Setup(this.POIName, this.playerId, this.questTags, this.questCode, this.GotoType, this.difficulty, prefabInstance.boundingBoxPosition.x, prefabInstance.boundingBoxPosition.z, (float)prefabInstance.boundingBoxSize.x, (float)prefabInstance.boundingBoxSize.y, (float)prefabInstance.boundingBoxSize.z, -1f, BiomeFilterTypes.AnyBiome, ""), false, this.playerId, -1, -1, null, 192);
return;
}
}
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage 6");
return;
}
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage 7");
EntityPlayer primaryPlayer = GameManager.Instance.World.GetPrimaryPlayer();
Quest quest = primaryPlayer.QuestJournal.FindActiveQuest(this.questCode);
if (quest != null)
{
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage 8");
for (int j = 0; j < quest.Objectives.Count; j++)
{
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage 9");
if (quest.Objectives[j] is ObjectiveGotoNamedPOIRebirth)
{
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage 10");
((ObjectiveGotoNamedPOIRebirth)quest.Objectives[j]).FinalizePoint(new Vector3(this.position.x, primaryPlayer.position.y, this.position.y), this.size);
}
}
}
//Log.Out("NetPackageQuestNamedPOIGotoRebirth-ProcessPackage END");
}
public override int GetLength()
{
return 32 + (this.biomeFilter.Length * 2) + (this.POIName.Length * 2);
}
private string POIName = "";
private int playerId;
private int questCode;
private FastTags<TagGroup.Global> questTags;
private Vector2 position;
private Vector3 size;
private byte difficulty;
public NetPackageQuestNamedPOIGotoRebirth.QuestGotoTypes GotoType;
private BiomeFilterTypes biomeFilterType;
private string biomeFilter;
public enum QuestGotoTypes
{
Trader,
Closest,
RandomPOI
}
}