PSO2SERVER/Server/Packets/Handlers/04-ObjectHandler/04-14-ObjectInteract.cs

104 lines
4.7 KiB
C#
Raw Normal View History

2024-09-10 01:13:20 +08:00
using PSO2SERVER.Database;
using PSO2SERVER.Models;
using PSO2SERVER.Object;
using PSO2SERVER.Packets.PSOPackets;
2024-09-10 00:31:40 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
2024-09-10 01:13:20 +08:00
namespace PSO2SERVER.Packets.Handlers
2024-09-10 00:31:40 +08:00
{
2024-09-16 02:56:02 +08:00
[PacketHandlerAttr(0x04, 0x14)]
2024-09-10 00:31:40 +08:00
class ObjectInteract : PacketHandler
{
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
PacketReader reader = new PacketReader(data);
reader.ReadBytes(12); // Padding MAYBE???????????
ObjectHeader srcObject = reader.ReadStruct<ObjectHeader>();
byte[] someBytes = reader.ReadBytes(4); // Dunno what this is yet.
ObjectHeader dstObject = reader.ReadStruct<ObjectHeader>(); // Could be wrong
reader.ReadBytes(16); // Not sure what this is yet
string command = reader.ReadAscii(0xD711, 0xCA);
PSOObject srcObj;
if(srcObject.EntityType == EntityType.Object)
{
srcObj = ObjectManager.Instance.getObjectByID(context.CurrentZone.Name, srcObject.ID);
}
else if(srcObject.EntityType == EntityType.Player)
{
2024-09-16 15:30:00 +08:00
srcObj = new PSOObject
{
Header = srcObject,
2024-09-20 21:58:37 +08:00
Name = "Account"
2024-09-16 15:30:00 +08:00
};
2024-09-10 00:31:40 +08:00
}
else
{
srcObj = null;
}
Logger.WriteInternal("[OBJ] {0} (ID {1}) <{2}> --> Ent {3} (ID {4})", srcObj.Name, srcObj.Header.ID, command, (EntityType)dstObject.EntityType, dstObject.ID);
// TODO: Delete this code and do this COMPLETELY correctly!!!
if (command == "Transfer" && context.CurrentZone.Name == "lobby")
{
// Try and get the teleport definition for the object...
2024-09-10 01:13:20 +08:00
using (var db = new ServerEf())
2024-09-10 00:31:40 +08:00
{
db.Configuration.AutoDetectChangesEnabled = true;
var teleporterEndpoint = db.Teleports.Find("lobby", (int)srcObject.ID);
if (teleporterEndpoint == null)
{
Logger.WriteError("[OBJ] Teleporter for {0} in {1} does not contain a destination!", srcObj.Header.ID, "lobby");
2024-09-20 21:58:37 +08:00
// Teleport Account to default point
2024-09-10 00:31:40 +08:00
context.SendPacket(new TeleportTransferPacket(srcObj, new PSOLocation(0f, 1f, 0f, -0.000031f, -0.417969f, 0.000031f, 134.375f)));
// Unhide player
context.SendPacket(new ObjectActionPacket(dstObject, srcObject, new ObjectHeader(), new ObjectHeader(), "Forwarded"));
}
else
{
PSOLocation endpointLocation = new PSOLocation()
{
RotX = teleporterEndpoint.RotX,
RotY = teleporterEndpoint.RotY,
RotZ = teleporterEndpoint.RotZ,
RotW = teleporterEndpoint.RotW,
PosX = teleporterEndpoint.PosX,
PosY = teleporterEndpoint.PosY,
PosZ = teleporterEndpoint.PosZ,
};
2024-09-20 21:58:37 +08:00
// Teleport Account
2024-09-10 00:31:40 +08:00
context.SendPacket(new TeleportTransferPacket(srcObj, endpointLocation));
// Unhide player
context.SendPacket(new ObjectActionPacket(dstObject, srcObject, new ObjectHeader(), new ObjectHeader(), "Forwarded"));
}
}
}
if (command == "READY")
{
2024-09-20 21:58:37 +08:00
context.SendPacket(new ObjectActionPacket(new ObjectHeader((uint)context._account.AccountId, EntityType.Player), srcObj.Header, srcObj.Header,
2024-09-10 00:31:40 +08:00
new ObjectHeader(), "FavsNeutral"));
2024-09-20 21:58:37 +08:00
context.SendPacket(new ObjectActionPacket(new ObjectHeader((uint)context._account.AccountId, EntityType.Player), srcObj.Header, srcObj.Header,
2024-09-10 00:31:40 +08:00
new ObjectHeader(), "AP")); // Short for Appear, Thanks Zapero!
}
if (command == "Sit")
{
foreach (var client in Server.Instance.Clients)
{
if (client.Character == null || client == context)
continue;
2024-09-20 21:58:37 +08:00
client.SendPacket(new ObjectActionPacket(new ObjectHeader((uint)client._account.AccountId, EntityType.Player), srcObj.Header,
2024-09-10 00:31:40 +08:00
new ObjectHeader(dstObject.ID, EntityType.Player), new ObjectHeader(), "SitSuccess"));
}
}
}
}
}