170 lines
8.6 KiB
C#
170 lines
8.6 KiB
C#
public class NetPackageQuestPointGotoSDX : NetPackage
|
|
{
|
|
public NetPackageQuestPointGotoSDX Setup(int _playerId, FastTags<TagGroup.Global> _questTags, int _questCode, NetPackageQuestPointGotoSDX.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("NetPackageQuestPointGotoSDX-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;
|
|
return this;
|
|
}
|
|
|
|
public override void read(PooledBinaryReader _br)
|
|
{
|
|
//Log.Out("NetPackageQuestPointGotoSDX-read");
|
|
this.playerId = _br.ReadInt32();
|
|
this.questCode = _br.ReadInt32();
|
|
this.GotoType = (NetPackageQuestPointGotoSDX.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();
|
|
}
|
|
|
|
public override void write(PooledBinaryWriter _bw)
|
|
{
|
|
//Log.Out("NetPackageQuestPointGotoSDX-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);
|
|
}
|
|
|
|
public override void ProcessPackage(World _world, GameManager _callbacks)
|
|
{
|
|
//Log.Out("NetPackageQuestPointGotoSDX-ProcessPackage");
|
|
if (_world == null)
|
|
{
|
|
return;
|
|
}
|
|
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
|
{
|
|
//Log.Out("NetPackageQuestPointGotoSDX-ProcessPackage-Server");
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
EntityPlayer entityPlayer = GameManager.Instance.World.GetEntity(this.playerId) as EntityPlayer;
|
|
PrefabInstance prefabInstance = null;
|
|
prefabInstance = GameManager.Instance.World.ChunkClusters[0].ChunkProvider.GetDynamicPrefabDecorator().GetRandomPOINearWorldPos(new Vector2(entityPlayer.position.x, entityPlayer.position.z), 100, 4000000, this.questTags, this.difficulty, null, -1, BiomeFilterTypes.AnyBiome, "");
|
|
|
|
new Vector2((float)prefabInstance.boundingBoxPosition.x + (float)prefabInstance.boundingBoxSize.x / 2f, (float)prefabInstance.boundingBoxPosition.z + (float)prefabInstance.boundingBoxSize.z / 2f);
|
|
|
|
float numPlayerX = entityPlayer.position.x;
|
|
float numPlayerZ = entityPlayer.position.z;
|
|
|
|
if (prefabInstance != null)
|
|
{
|
|
Vector2 vector3a = new Vector2((float)prefabInstance.boundingBoxPosition.x + (float)prefabInstance.boundingBoxSize.x / 2f, (float)prefabInstance.boundingBoxPosition.z + (float)prefabInstance.boundingBoxSize.z / 2f);
|
|
|
|
float numPreFabX = (float)vector3a.x;
|
|
float numPreFabZ = (float)vector3a.y;
|
|
|
|
float numDiffXa = Math.Abs(numPreFabX - numPlayerX);
|
|
float numDiffZa = Math.Abs(numPreFabZ - numPlayerZ);
|
|
float numDiffa = Math.Abs(numDiffXa + numDiffZa);
|
|
|
|
//Log.Out("ObjectiveRandomGotoPOISDX-GetPosition-Prefab Name:" + prefabInstance.name);
|
|
|
|
//Log.Out("ObjectiveRandomGotoPOISDX-GetPosition-Original Prefab diffXa:" + numDiffXa + ", diffZa: " + numDiffZa);
|
|
//Log.Out("ObjectiveRandomGotoPOISDX-GetPosition-Original Prefab diff:" + numDiffa);
|
|
|
|
int minDistance = 400;
|
|
int maxDistance = 900;
|
|
|
|
//Log.Out("ObjectiveRandomGotoPOISDX-GetPosition-minDistance: " + minDistance + ", maxDistance: " + maxDistance);
|
|
|
|
for (int j = 0; j < 15; j++)
|
|
{
|
|
PrefabInstance prefabInstance2;
|
|
prefabInstance2 = GameManager.Instance.World.ChunkClusters[0].ChunkProvider.GetDynamicPrefabDecorator().GetRandomPOINearWorldPos(new Vector2(entityPlayer.position.x, entityPlayer.position.z), 100, 4000000, this.questTags, this.difficulty, null, -1, BiomeFilterTypes.AnyBiome, "");
|
|
|
|
Vector2 vector3b = new Vector2((float)prefabInstance2.boundingBoxPosition.x + (float)prefabInstance2.boundingBoxSize.x / 2f, (float)prefabInstance2.boundingBoxPosition.z + (float)prefabInstance2.boundingBoxSize.z / 2f);
|
|
|
|
numPreFabX = (float)vector3b.x;
|
|
numPreFabZ = (float)vector3b.y;
|
|
|
|
float numDiffXb = Math.Abs(numPreFabX - numPlayerX);
|
|
float numDiffZb = Math.Abs(numPreFabZ - numPlayerZ);
|
|
float numDiffb = Math.Abs(numDiffXb + numDiffZb);
|
|
|
|
if (numDiffb < numDiffa)
|
|
{
|
|
if ((numDiffb > minDistance) && (numDiffb < maxDistance))
|
|
{
|
|
prefabInstance = prefabInstance2;
|
|
numDiffa = numDiffb;
|
|
//Log.Out("ObjectiveRandomGotoPOISDX-GetPosition-Prefab Name:" + prefabInstance.name);
|
|
}
|
|
}
|
|
|
|
//Log.Out("ObjectiveRandomGotoPOISDX-GetPosition-New Prefab diffXb:" + numDiffXb + ", diffZb: " + numDiffZb);
|
|
//Log.Out("ObjectiveRandomGotoPOISDX-GetPosition-New Prefab diff:" + numDiffb);
|
|
}
|
|
}
|
|
|
|
if (prefabInstance != null)
|
|
{
|
|
SingletonMonoBehaviour<ConnectionManager>.Instance.SendPackage(NetPackageManager.GetPackage<NetPackageQuestPointGotoSDX>().Setup(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;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
EntityPlayer primaryPlayer = GameManager.Instance.World.GetPrimaryPlayer();
|
|
Quest quest = primaryPlayer.QuestJournal.FindActiveQuest(this.questCode);
|
|
if (quest != null)
|
|
{
|
|
for (int j = 0; j < quest.Objectives.Count; j++)
|
|
{
|
|
if (quest.Objectives[j] is ObjectiveGoto && this.GotoType == NetPackageQuestPointGotoSDX.QuestGotoTypes.Trader)
|
|
{
|
|
((ObjectiveGoto)quest.Objectives[j]).FinalizePoint(new Vector3(this.position.x, primaryPlayer.position.y, this.position.y), this.size);
|
|
}
|
|
else if (quest.Objectives[j] is ObjectiveClosestPOIGoto && this.GotoType == NetPackageQuestPointGotoSDX.QuestGotoTypes.Closest)
|
|
{
|
|
((ObjectiveClosestPOIGoto)quest.Objectives[j]).FinalizePoint(new Vector3(this.position.x, primaryPlayer.position.y, this.position.y), this.size);
|
|
}
|
|
else if (quest.Objectives[j] is ObjectiveRandomGotoPOISDX && this.GotoType == NetPackageQuestPointGotoSDX.QuestGotoTypes.RandomPOI)
|
|
{
|
|
((ObjectiveRandomGotoPOISDX)quest.Objectives[j]).FinalizePoint(new Vector3(this.position.x, primaryPlayer.position.y, this.position.y), this.size);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override int GetLength()
|
|
{
|
|
return 32 + (this.biomeFilter.Length * 2);
|
|
}
|
|
|
|
private int playerId;
|
|
private int questCode;
|
|
private FastTags<TagGroup.Global> questTags;
|
|
private Vector2 position;
|
|
private Vector3 size;
|
|
private byte difficulty;
|
|
public NetPackageQuestPointGotoSDX.QuestGotoTypes GotoType;
|
|
private BiomeFilterTypes biomeFilterType;
|
|
private string biomeFilter;
|
|
public enum QuestGotoTypes
|
|
{
|
|
Trader,
|
|
Closest,
|
|
RandomPOI
|
|
}
|
|
}
|