Merge branch 'inventory_refactor' into develop

# Conflicts:
#	FFXIVClassic Map Server/Database.cs
#	FFXIVClassic Map Server/FFXIVClassic Map Server.csproj
#	FFXIVClassic Map Server/WorldManager.cs
#	FFXIVClassic Map Server/actors/area/Area.cs
#	FFXIVClassic Map Server/actors/area/Zone.cs
#	FFXIVClassic Map Server/actors/chara/Character.cs
#	FFXIVClassic Map Server/actors/chara/npc/Npc.cs
#	FFXIVClassic Map Server/actors/chara/player/Inventory.cs
#	FFXIVClassic Map Server/actors/chara/player/Player.cs
#	FFXIVClassic Map Server/dataobjects/ZoneConnection.cs
#	FFXIVClassic Map Server/lua/LuaEngine.cs
#	FFXIVClassic Map Server/packets/send/Actor/AddActorPacket.cs
#	FFXIVClassic Map Server/packets/send/Actor/DeleteAllActorsPacket.cs
#	FFXIVClassic Map Server/packets/send/Actor/SetActorPropetyPacket.cs
#	FFXIVClassic Map Server/packets/send/Actor/SetActorStatePacket.cs
#	FFXIVClassic Map Server/packets/send/Actor/SetActorStatusAllPacket.cs
#	FFXIVClassic Map Server/packets/send/Actor/SetActorStatusPacket.cs
#	FFXIVClassic Map Server/packets/send/Actor/_0x132Packet.cs
#	FFXIVClassic Map Server/packets/send/Actor/battle/BattleAction.cs
#	FFXIVClassic Map Server/packets/send/Actor/battle/BattleActionX10Packet.cs
#	FFXIVClassic Map Server/packets/send/Actor/battle/BattleActionX18Packet.cs
#	FFXIVClassic Map Server/packets/send/Actor/battle/CommandResultX00Packet.cs
#	FFXIVClassic Map Server/packets/send/Actor/events/SetEmoteEventCondition.cs
#	FFXIVClassic Map Server/packets/send/Actor/inventory/InventoryRemoveX08Packet.cs
#	data/scripts/commands/gm/giveitem.lua
This commit is contained in:
Filip Maj 2019-05-06 15:59:09 -04:00
commit bcb609e4f6
202 changed files with 2713 additions and 1040 deletions

View file

@ -1,9 +1,4 @@
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.dataobjects
{

View file

@ -1,73 +1,165 @@
using System;
using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.packets.send.actor.inventory;
using System;
using System.IO;
namespace FFXIVClassic_Map_Server.dataobjects
{
class InventoryItem
{
public const byte DEALINGMODE_NONE = 0;
public const byte DEALINGMODE_REFERENCED = 1;
public const byte DEALINGMODE_PRICED = 2;
public const byte TAG_EXCLUSIVE = 0x3;
public const byte TAG_DEALING = 0xC9;
public const byte TAG_ATTACHED = 0xCA;
public const byte TYPE_SINGLE = 11;
public const byte TYPE_MULTI = 12;
public const byte TYPE_STACK = 13;
public const byte TYPE_SEEK_ITEM = 20;
public const byte TYPE_SEEK_REPAIR = 30;
public ulong uniqueId;
public uint itemId;
public int quantity = 1;
public ushort slot;
public byte itemType;
public byte dealingVal = 0;
public byte dealingMode = DEALINGMODE_NONE;
public uint dealingAttached1 = 0;
public uint dealingAttached2 = 0;
public uint dealingAttached3 = 0;
public byte[] tags = new byte[4];
public byte[] tagValues = new byte[4];
public byte quality = 1;
public int durability = 0;
public ushort spiritbind = 0;
private ulong attachedTo = 0;
public byte materia1 = 0;
public byte materia2 = 0;
public byte materia3 = 0;
public byte materia4 = 0;
public byte materia5 = 0;
public ItemModifier modifiers;
public readonly ItemData itemData;
public Character owner = null;
public ushort slot = 0xFFFF;
public ushort itemPackage = 0xFFFF;
public class ItemModifier
{
public uint durability = 0;
public ushort use = 0;
public uint materiaId = 0;
public uint materiaLife = 0;
public byte mainQuality = 0;
public byte[] subQuality = new byte[3];
public uint polish = 0;
public uint param1 = 0;
public uint param2 = 0;
public uint param3 = 0;
public ushort spiritbind = 0;
public byte[] materiaType = new byte[5];
public byte[] materiaGrade = new byte[5];
public ItemModifier()
{
}
public ItemModifier(MySql.Data.MySqlClient.MySqlDataReader reader)
{
durability = reader.GetUInt32("durability");
mainQuality = reader.GetByte("mainQuality");
subQuality[0] = reader.GetByte("subQuality1");
subQuality[1] = reader.GetByte("subQuality2");
subQuality[2] = reader.GetByte("subQuality3");
param1 = reader.GetUInt32("param1");
param2 = reader.GetUInt32("param2");
param3 = reader.GetUInt32("param3");
spiritbind = reader.GetUInt16("spiritbind");
ushort materia1 = reader.GetUInt16("materia1");
ushort materia2 = reader.GetUInt16("materia2");
ushort materia3 = reader.GetUInt16("materia3");
ushort materia4 = reader.GetUInt16("materia4");
ushort materia5 = reader.GetUInt16("materia5");
materiaType[0] = (byte)(materia1 & 0xFF);
materiaGrade[0] = (byte)((materia1 >> 8) & 0xFF);
materiaType[1] = (byte)(materia2 & 0xFF);
materiaGrade[1] = (byte)((materia2 >> 8) & 0xFF);
materiaType[2] = (byte)(materia3 & 0xFF);
materiaGrade[2] = (byte)((materia3 >> 8) & 0xFF);
materiaType[3] = (byte)(materia4 & 0xFF);
materiaGrade[3] = (byte)((materia4 >> 8) & 0xFF);
materiaType[4] = (byte)(materia5 & 0xFF);
materiaGrade[4] = (byte)((materia5 >> 8) & 0xFF);
}
public void WriteBytes(BinaryWriter binWriter)
{
binWriter.Write((UInt32) durability);
binWriter.Write((UInt16) use);
binWriter.Write((UInt32) materiaId);
binWriter.Write((UInt32) materiaLife);
binWriter.Write((Byte) mainQuality);
binWriter.Write((Byte) subQuality[0]);
binWriter.Write((Byte) subQuality[1]);
binWriter.Write((Byte) subQuality[2]);
binWriter.Write((UInt32) polish);
binWriter.Write((UInt32) param1);
binWriter.Write((UInt32) param2);
binWriter.Write((UInt32) param3);
binWriter.Write((UInt16) spiritbind);
binWriter.Write((Byte) materiaType[0]);
binWriter.Write((Byte) materiaType[1]);
binWriter.Write((Byte) materiaType[2]);
binWriter.Write((Byte) materiaType[3]);
binWriter.Write((Byte) materiaType[4]);
binWriter.Write((Byte) materiaGrade[0]);
binWriter.Write((Byte) materiaGrade[1]);
binWriter.Write((Byte) materiaGrade[2]);
binWriter.Write((Byte) materiaGrade[3]);
binWriter.Write((Byte) materiaGrade[4]);
}
}
//Bare Minimum
public InventoryItem(uint id, uint itemId)
public InventoryItem(uint id, ItemData data)
{
this.uniqueId = id;
this.itemId = itemId;
this.itemId = data.catalogID;
this.itemData = data;
this.quantity = 1;
ItemData gItem = Server.GetItemGamedata(itemId);
itemType = gItem.isExclusive ? (byte)0x3 : (byte)0x0;
tags[1] = gItem.isExclusive ? (byte)0x3 : (byte)0x0;
}
//For check command
public InventoryItem(InventoryItem item, ushort equipSlot)
{
this.uniqueId = item.uniqueId;
this.itemData = item.itemData;
this.itemId = item.itemId;
this.quantity = item.quantity;
this.slot = equipSlot;
this.itemType = item.itemType;
this.tags = item.tags;
this.tagValues = item.tagValues;
this.quality = item.quality;
this.durability = item.durability;
this.spiritbind = item.spiritbind;
this.materia1 = item.materia1;
this.materia2 = item.materia2;
this.materia3 = item.materia3;
this.materia4 = item.materia4;
this.materia5 = item.materia5;
this.modifiers = item.modifiers;
}
public InventoryItem(uint uniqueId, uint itemId, int quantity, byte itemType, byte qualityNumber, int durability, ushort spiritbind, byte materia1, byte materia2, byte materia3, byte materia4, byte materia5)
public InventoryItem(uint uniqueId, ItemData itemData, int quantity, byte qualityNumber, ItemModifier modifiers = null)
{
this.uniqueId = uniqueId;
this.itemId = itemId;
this.itemId = itemData.catalogID;
this.itemData = itemData;
this.quantity = quantity;
this.itemType = itemType;
this.quality = qualityNumber;
this.durability = durability;
this.spiritbind = spiritbind;
this.materia1 = materia1;
this.materia2 = materia2;
this.materia3 = materia3;
this.materia4 = materia4;
this.materia5 = materia5;
this.modifiers = modifiers;
}
public byte[] ToPacketBytes()
@ -83,40 +175,161 @@ namespace FFXIVClassic_Map_Server.dataobjects
binWriter.Write((UInt32)itemId);
binWriter.Write((UInt16)slot);
binWriter.Write((UInt16)0x0001);
binWriter.Write((UInt32)0x00000000);
binWriter.Write((UInt32)0x00000000);
binWriter.Write((UInt32)0x00000000);
binWriter.Write((Byte)dealingVal);
binWriter.Write((Byte)dealingMode);
binWriter.Write((UInt32)itemType);
binWriter.Write((UInt32)dealingAttached1);
binWriter.Write((UInt32)dealingAttached2);
binWriter.Write((UInt32)dealingAttached3);
binWriter.Write((UInt32)0x00000000);
for (int i = 0; i < tags.Length; i++)
binWriter.Write((Byte) tags[i]);
for (int i = 0; i < tagValues.Length; i++)
binWriter.Write((Byte) tagValues[i]);
binWriter.Write((byte)quality);
binWriter.Write((byte)0x01);
binWriter.Write((uint)durability);
binWriter.BaseStream.Seek(0x10-0x06, SeekOrigin.Current);
binWriter.Write((byte)0x01);
binWriter.Write((byte)0x01);
binWriter.Write((byte)0x01);
binWriter.Write((byte)0x01);
binWriter.BaseStream.Seek(0x10, SeekOrigin.Current);
binWriter.Write((ushort)spiritbind);
binWriter.Write((byte)materia1);
binWriter.Write((byte)materia2);
binWriter.Write((byte)materia3);
binWriter.Write((byte)materia4);
binWriter.Write((byte)materia5);
binWriter.Write((Byte)quality);
if (modifiers != null)
{
binWriter.Write((Byte)0x01);
modifiers.WriteBytes(binWriter);
}
}
}
return data;
}
public void SetQuantity(uint quantity)
{
lock (owner.GetItemPackage(itemPackage))
{
this.quantity = (int)quantity;
if (quantity < 0)
quantity = 0;
Database.SetQuantity(uniqueId, this.quantity);
if (owner != null && owner is Player)
owner.GetItemPackage(itemPackage).RefreshItem((Player)owner, this);
}
}
public void ChangeQuantity(int quantityDelta)
{
lock (owner.GetItemPackage(itemPackage))
{
this.quantity += quantityDelta;
if (quantity < 0)
quantity = 0;
if (quantity == 0)
{
owner.RemoveItem(this);
return;
}
Database.SetQuantity(uniqueId, this.quantity);
if (owner != null && owner is Player)
{
((Player)owner).QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId, false));
owner.GetItemPackage(itemPackage).RefreshItem((Player)owner, this);
((Player)owner).QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));
}
}
}
public void RefreshPositioning(Character owner, ushort itemPackage, ushort slot)
{
this.owner = owner;
this.itemPackage = itemPackage;
this.slot = slot;
}
public void SetExclusive(bool isExclusive)
{
tags[1] = isExclusive ? TAG_EXCLUSIVE : (byte)0;
}
public void SetHasAttached(bool isAttached)
{
tags[0] = isAttached ? TAG_ATTACHED : (byte)0;
}
public void SetNormal()
{
for (int i = 0; i < 4; i++)
{
if (tags[i] == TAG_DEALING || tags[i] == TAG_ATTACHED)
{
tags[i] = 0;
tagValues[i] = 0;
attachedTo = 0;
dealingVal = 0;
dealingMode = 0;
dealingAttached1 = 0;
dealingAttached2 = 0;
dealingAttached3 = 0;
}
}
}
public void SetDealing(byte mode, int price)
{
tags[0] = TAG_DEALING;
tagValues[0] = mode;
if (mode == TYPE_SINGLE || mode == TYPE_MULTI || mode == TYPE_STACK)
{
dealingVal = 1;
dealingMode = DEALINGMODE_PRICED;
dealingAttached1 = 1;
dealingAttached2 = (uint) price;
dealingAttached3 = 0;
}
}
public void SetDealingAttached(byte mode, ulong attached)
{
tags[0] = TAG_DEALING;
tagValues[0] = mode;
attachedTo = attached;
}
public ulong GetAttached()
{
return attachedTo;
}
public void SetAttachedIndex(ushort package, ushort index)
{
dealingVal = 1;
dealingMode = DEALINGMODE_REFERENCED;
dealingAttached1 = (uint)((package << 16) | index);
dealingAttached2 = 0;
dealingAttached3 = 0;
}
public ItemData GetItemData()
{
return itemData;
}
public byte GetBazaarMode()
{
for (int i = 0; i < tags.Length; i++)
{
if (tags[i] == 0xC9)
return tagValues[i];
}
return 0;
}
public bool IsSelling()
{
return GetBazaarMode() == TYPE_SINGLE || GetBazaarMode() == TYPE_MULTI || GetBazaarMode() == TYPE_STACK;
}
}
}

View file

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.dataobjects
namespace FFXIVClassic_Map_Server.dataobjects
{
class SeamlessBoundry
{

View file

@ -0,0 +1,3 @@
namespace FFXIVClassic_Map_Server.dataobjects
{
}

View file

@ -4,7 +4,6 @@ using System.Net.Sockets;
using FFXIVClassic.Common;
using System.Collections.Concurrent;
using System.Net;
using System.Collections.Generic;
using FFXIVClassic_Map_Server.packets.WorldPackets.Send;
namespace FFXIVClassic_Map_Server.dataobjects
@ -19,7 +18,7 @@ namespace FFXIVClassic_Map_Server.dataobjects
public void QueuePacket(SubPacket subpacket)
{
if(SendPacketQueue.Count == 1000)
if (SendPacketQueue.Count == SendPacketQueue.BoundedCapacity - 1)
FlushQueuedSendPackets();
SendPacketQueue.Add(subpacket);