Renamed the "Item" object to InventoryItem. Began writing the Item object that will be used to store game data items.

This commit is contained in:
Filip Maj 2016-02-21 14:06:23 -05:00
parent c2f0b9d999
commit d2ac603efa
17 changed files with 400 additions and 142 deletions

View File

@ -459,6 +459,7 @@ namespace FFXIVClassic_Lobby_Server
player.getInventory(Inventory.MELDREQUEST).initList(getInventory(player, 0, Inventory.MELDREQUEST)); player.getInventory(Inventory.MELDREQUEST).initList(getInventory(player, 0, Inventory.MELDREQUEST));
player.getInventory(Inventory.LOOT).initList(getInventory(player, 0, Inventory.LOOT)); player.getInventory(Inventory.LOOT).initList(getInventory(player, 0, Inventory.LOOT));
player.getEquipment().SetEquipment(getEquipment(player));
} }
catch (MySqlException e) catch (MySqlException e)
{ Console.WriteLine(e); } { Console.WriteLine(e); }
@ -470,9 +471,115 @@ namespace FFXIVClassic_Lobby_Server
} }
public static List<Item> getInventory(Player player, uint slotOffset, uint type) public static List<Tuple<ushort, InventoryItem>> getEquipment(Player player)
{ {
List<Item> items = new List<Item>(); List<Tuple<ushort, InventoryItem>> equipment = new List<Tuple<ushort, InventoryItem>>();
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
{
try
{
conn.Open();
string query = @"
SELECT
equipSlot,
itemSlot
FROM characters_inventory_equipment
WHERE characterId = @charId ORDER BY equipSlot";
MySqlCommand cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
ushort equipSlot = reader.GetUInt16(0);
ushort itemSlot = reader.GetUInt16(1);
InventoryItem item = player.getInventory(Inventory.NORMAL).getItem(itemSlot);
equipment.Add(new Tuple<ushort, InventoryItem>(equipSlot, item));
}
}
}
catch (MySqlException e)
{ Console.WriteLine(e); }
finally
{
conn.Dispose();
}
}
return equipment;
}
public static void equipItem(Player player, ushort equipSlot, ushort itemSlot)
{
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
{
try
{
conn.Open();
string query = @"
INSERT INTO characters_inventory_equipment
(characterId, equipSlot, itemSlot)
VALUES
(@characterId, @equipSlot, @itemSlot)
ON DUPLICATE KEY UPDATE itemSlot=@itemSlot;
";
MySqlCommand cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@characterId", player.actorId);
cmd.Parameters.AddWithValue("@equipSlot", equipSlot);
cmd.Parameters.AddWithValue("@itemSlot", itemSlot);
cmd.ExecuteNonQuery();
}
catch (MySqlException e)
{ Console.WriteLine(e); }
finally
{
conn.Dispose();
}
}
}
public static void unequipItem(Player player, ushort equipSlot)
{
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
{
try
{
conn.Open();
string query = @"
DELETE FROM characters_inventory_equipment
WHERE characterId = @characterId AND equipSlot = @equipSlot;
";
MySqlCommand cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@characterId", player.actorId);
cmd.Parameters.AddWithValue("@equipSlot", equipSlot);
cmd.ExecuteNonQuery();
}
catch (MySqlException e)
{ Console.WriteLine(e); }
finally
{
conn.Dispose();
}
}
}
public static List<InventoryItem> getInventory(Player player, uint slotOffset, uint type)
{
List<InventoryItem> items = new List<InventoryItem>();
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
{ {
@ -525,7 +632,7 @@ namespace FFXIVClassic_Lobby_Server
byte materia4 = reader.GetByte(11); byte materia4 = reader.GetByte(11);
byte materia5 = reader.GetByte(12); byte materia5 = reader.GetByte(12);
items.Add(new Item(uniqueId, itemId, quantity, slot, isUntradeable, qualityNumber, durability, spiritBind, materia1, materia2, materia3, materia4, materia5)); items.Add(new InventoryItem(uniqueId, itemId, quantity, slot, isUntradeable, qualityNumber, durability, spiritBind, materia1, materia2, materia3, materia4, materia5));
} }
} }
} }
@ -540,9 +647,9 @@ namespace FFXIVClassic_Lobby_Server
return items; return items;
} }
public static Item addItem(Player player, uint itemId, int quantity, byte quality, bool isUntradeable, uint durability, ushort type) public static InventoryItem addItem(Player player, uint itemId, int quantity, byte quality, bool isUntradeable, uint durability, ushort type)
{ {
Item insertedItem = null; InventoryItem insertedItem = null;
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
{ {
@ -581,7 +688,7 @@ namespace FFXIVClassic_Lobby_Server
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
cmd2.ExecuteNonQuery(); cmd2.ExecuteNonQuery();
insertedItem = new Item((uint)cmd.LastInsertedId, itemId, quantity, (ushort)player.getInventory(type).getNextEmptySlot(), isUntradeable, quality, durability, 0, 0, 0, 0, 0, 0); insertedItem = new InventoryItem((uint)cmd.LastInsertedId, itemId, quantity, (ushort)player.getInventory(type).getNextEmptySlot(), isUntradeable, quality, durability, 0, 0, 0, 0, 0, 0);
} }
catch (MySqlException e) catch (MySqlException e)
{ Console.WriteLine(e); } { Console.WriteLine(e); }

View File

@ -98,7 +98,7 @@
<Compile Include="actors\chara\ParameterSave.cs" /> <Compile Include="actors\chara\ParameterSave.cs" />
<Compile Include="actors\chara\player\PlayerWork.cs" /> <Compile Include="actors\chara\player\PlayerWork.cs" />
<Compile Include="dataobjects\DBWorld.cs" /> <Compile Include="dataobjects\DBWorld.cs" />
<Compile Include="dataobjects\Item.cs" /> <Compile Include="dataobjects\InventoryItem.cs" />
<Compile Include="dataobjects\ConnectedPlayer.cs" /> <Compile Include="dataobjects\ConnectedPlayer.cs" />
<Compile Include="dataobjects\RecruitmentDetails.cs" /> <Compile Include="dataobjects\RecruitmentDetails.cs" />
<Compile Include="dataobjects\SearchEntry.cs" /> <Compile Include="dataobjects\SearchEntry.cs" />

View File

@ -1,4 +1,5 @@
using FFXIVClassic_Map_Server.Actors; using FFXIVClassic_Lobby_Server;
using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.dataobjects; using FFXIVClassic_Map_Server.dataobjects;
using FFXIVClassic_Map_Server.packets.send.actor.inventory; using FFXIVClassic_Map_Server.packets.send.actor.inventory;
using FFXIVClassic_Map_Server.packets.send.Actor.inventory; using FFXIVClassic_Map_Server.packets.send.Actor.inventory;
@ -34,7 +35,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
private Player owner; private Player owner;
private ushort inventoryCapacity; private ushort inventoryCapacity;
private ushort inventoryCode; private ushort inventoryCode;
private Item[] list; private InventoryItem[] list;
private Inventory normalInventory; private Inventory normalInventory;
public Equipment(Player ownerPlayer, Inventory normalInventory, ushort capacity, ushort code) public Equipment(Player ownerPlayer, Inventory normalInventory, ushort capacity, ushort code)
@ -42,11 +43,11 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
owner = ownerPlayer; owner = ownerPlayer;
inventoryCapacity = capacity; inventoryCapacity = capacity;
inventoryCode = code; inventoryCode = code;
list = new Item[inventoryCapacity]; list = new InventoryItem[inventoryCapacity];
this.normalInventory = normalInventory; this.normalInventory = normalInventory;
} }
public Item GetItemAtSlot(ushort slot) public InventoryItem GetItemAtSlot(ushort slot)
{ {
if (slot < list.Length) if (slot < list.Length)
return list[slot]; return list[slot];
@ -65,25 +66,27 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
slotsToUpdate.Add(i); slotsToUpdate.Add(i);
} }
SendEquipmentPackets(slotsToUpdate); owner.queuePacket(InventorySetBeginPacket.buildPacket(owner.actorId, inventoryCapacity, inventoryCode));
SendEquipmentPackets(slotsToUpdate);
owner.queuePacket(InventorySetEndPacket.buildPacket(owner.actorId));
} }
public void SetEquipment(List<Tuple<ushort, Item>> toEquip) public void SetEquipment(List<Tuple<ushort, InventoryItem>> toEquip)
{ {
List<ushort> slotsToUpdate = new List<ushort>(); List<ushort> slotsToUpdate = new List<ushort>();
for (int i = 0; i < toEquip.Count; i++) for (int i = 0; i < toEquip.Count; i++)
{ {
slotsToUpdate.Add(toEquip[i].Item1); slotsToUpdate.Add(toEquip[i].Item1);
list[toEquip[i].Item1] = toEquip[i].Item2; list[toEquip[i].Item1] = toEquip[i].Item2;
} }
SendEquipmentPackets(slotsToUpdate);
} }
public void Equip(ushort slot, Item item) public void Equip(ushort slot, InventoryItem item)
{ {
if (slot >= list.Length) if (slot >= list.Length)
return; return;
Database.equipItem(owner, slot, item.slot);
owner.queuePacket(InventoryBeginChangePacket.buildPacket(owner.actorId)); owner.queuePacket(InventoryBeginChangePacket.buildPacket(owner.actorId));
@ -106,6 +109,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
if (slot >= list.Length) if (slot >= list.Length)
return; return;
Database.unequipItem(owner, slot);
owner.queuePacket(InventoryBeginChangePacket.buildPacket(owner.actorId)); owner.queuePacket(InventoryBeginChangePacket.buildPacket(owner.actorId));
normalInventory.RefreshItem(list[slot]); normalInventory.RefreshItem(list[slot]);
@ -119,7 +124,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
list[slot] = null; list[slot] = null;
} }
private void SendEquipmentPackets(ushort equipSlot, Item item) private void SendEquipmentPackets(ushort equipSlot, InventoryItem item)
{ {
if (item == null) if (item == null)
owner.queuePacket(InventoryRemoveX01Packet.buildPacket(owner.actorId, equipSlot)); owner.queuePacket(InventoryRemoveX01Packet.buildPacket(owner.actorId, equipSlot));
@ -129,7 +134,6 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
private void SendEquipmentPackets(List<ushort> slotsToUpdate) private void SendEquipmentPackets(List<ushort> slotsToUpdate)
{ {
owner.queuePacket(InventorySetBeginPacket.buildPacket(owner.actorId, inventoryCapacity, inventoryCode));
int currentIndex = 0; int currentIndex = 0;
@ -145,14 +149,13 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
owner.queuePacket(EquipmentListX08Packet.buildPacket(owner.actorId, list, slotsToUpdate, ref currentIndex)); owner.queuePacket(EquipmentListX08Packet.buildPacket(owner.actorId, list, slotsToUpdate, ref currentIndex));
else if (slotsToUpdate.Count - currentIndex == 1) else if (slotsToUpdate.Count - currentIndex == 1)
{ {
owner.queuePacket(EquipmentListX01Packet.buildPacket(owner.actorId, slotsToUpdate[currentIndex], list[currentIndex].slot)); owner.queuePacket(EquipmentListX01Packet.buildPacket(owner.actorId, slotsToUpdate[currentIndex], list[slotsToUpdate[currentIndex]].slot));
currentIndex++; currentIndex++;
} }
else else
break; break;
} }
owner.queuePacket(InventorySetEndPacket.buildPacket(owner.actorId));
} }
} }

View File

@ -21,11 +21,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
public const ushort CURRANCY = 0x0063; //Max 0x140 public const ushort CURRANCY = 0x0063; //Max 0x140
public const ushort KEYITEMS = 0x0064; //Max 0x500 public const ushort KEYITEMS = 0x0064; //Max 0x500
public const ushort EQUIPMENT = 0x00FE; //Max 0x23 public const ushort EQUIPMENT = 0x00FE; //Max 0x23
public const ushort EQUIPMENT_OTHERPLAYER = 0x00F9; //Max 0x23
private Player owner; private Player owner;
private ushort inventoryCapacity; private ushort inventoryCapacity;
private ushort inventoryCode; private ushort inventoryCode;
private List<Item> list; private List<InventoryItem> list;
public Inventory(Player ownerPlayer, ushort capacity, ushort code) public Inventory(Player ownerPlayer, ushort capacity, ushort code)
{ {
@ -35,12 +36,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
} }
#region Inventory Management #region Inventory Management
public void initList(List<Item> itemsFromDB) public void initList(List<InventoryItem> itemsFromDB)
{ {
list = itemsFromDB; list = itemsFromDB;
} }
public Item getItem(ushort slot) public InventoryItem getItem(ushort slot)
{ {
if (slot < list.Count) if (slot < list.Count)
return list[slot]; return list[slot];
@ -48,21 +49,21 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
return null; return null;
} }
public void RefreshItem(Item item) public void RefreshItem(InventoryItem item)
{ {
owner.queuePacket(InventorySetBeginPacket.buildPacket(owner.actorId, inventoryCapacity, inventoryCode)); owner.queuePacket(InventorySetBeginPacket.buildPacket(owner.actorId, inventoryCapacity, inventoryCode));
sendInventoryPackets(item); sendInventoryPackets(item);
owner.queuePacket(InventorySetEndPacket.buildPacket(owner.actorId)); owner.queuePacket(InventorySetEndPacket.buildPacket(owner.actorId));
} }
public void RefreshItem(params Item[] items) public void RefreshItem(params InventoryItem[] items)
{ {
owner.queuePacket(InventorySetBeginPacket.buildPacket(owner.actorId, inventoryCapacity, inventoryCode)); owner.queuePacket(InventorySetBeginPacket.buildPacket(owner.actorId, inventoryCapacity, inventoryCode));
sendInventoryPackets(items.ToList()); sendInventoryPackets(items.ToList());
owner.queuePacket(InventorySetEndPacket.buildPacket(owner.actorId)); owner.queuePacket(InventorySetEndPacket.buildPacket(owner.actorId));
} }
public void RefreshItem(List<Item> items) public void RefreshItem(List<InventoryItem> items)
{ {
owner.queuePacket(InventorySetBeginPacket.buildPacket(owner.actorId, inventoryCapacity, inventoryCode)); owner.queuePacket(InventorySetBeginPacket.buildPacket(owner.actorId, inventoryCapacity, inventoryCode));
sendInventoryPackets(items); sendInventoryPackets(items);
@ -81,7 +82,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
int quantityCount = quantity; int quantityCount = quantity;
for (int i = 0; i < list.Count; i++) for (int i = 0; i < list.Count; i++)
{ {
Item item = list[i]; InventoryItem item = list[i];
if (item.itemId == itemId && item.quantity < item.maxStack) if (item.itemId == itemId && item.quantity < item.maxStack)
{ {
slotsToUpdate.Add(item.slot); slotsToUpdate.Add(item.slot);
@ -117,7 +118,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
//New item that spilled over //New item that spilled over
while (quantityCount > 0) while (quantityCount > 0)
{ {
Item addedItem = Database.addItem(owner, itemId, Math.Min(quantityCount, 5), quality, false, 100, inventoryCode); InventoryItem addedItem = Database.addItem(owner, itemId, Math.Min(quantityCount, 5), quality, false, 100, inventoryCode);
list.Add(addedItem); list.Add(addedItem);
if (inventoryCode != CURRANCY && inventoryCode != KEYITEMS) if (inventoryCode != CURRANCY && inventoryCode != KEYITEMS)
@ -139,7 +140,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
return; return;
List<ushort> slotsToUpdate = new List<ushort>(); List<ushort> slotsToUpdate = new List<ushort>();
List<Item> itemsToRemove = new List<Item>(); List<InventoryItem> itemsToRemove = new List<InventoryItem>();
List<ushort> slotsToRemove = new List<ushort>(); List<ushort> slotsToRemove = new List<ushort>();
List<SubPacket> addItemPackets = new List<SubPacket>(); List<SubPacket> addItemPackets = new List<SubPacket>();
@ -148,7 +149,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
ushort lowestSlot = 0; ushort lowestSlot = 0;
for (int i = list.Count - 1; i >= 0; i--) for (int i = list.Count - 1; i >= 0; i--)
{ {
Item item = list[i]; InventoryItem item = list[i];
if (item.itemId == itemId) if (item.itemId == itemId)
{ {
int oldQuantity = item.quantity; int oldQuantity = item.quantity;
@ -212,8 +213,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
public void removeItem(ulong itemDBId) public void removeItem(ulong itemDBId)
{ {
ushort slot = 0; ushort slot = 0;
Item toDelete = null; InventoryItem toDelete = null;
foreach (Item item in list) foreach (InventoryItem item in list)
{ {
if (item.uniqueId == itemDBId) if (item.uniqueId == itemDBId)
{ {
@ -304,12 +305,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
owner.queuePacket(InventorySetEndPacket.buildPacket(owner.actorId)); owner.queuePacket(InventorySetEndPacket.buildPacket(owner.actorId));
} }
private void sendInventoryPackets(Item item) private void sendInventoryPackets(InventoryItem item)
{ {
owner.queuePacket(InventoryListX01Packet.buildPacket(owner.actorId, item)); owner.queuePacket(InventoryListX01Packet.buildPacket(owner.actorId, item));
} }
private void sendInventoryPackets(List<Item> items) private void sendInventoryPackets(List<InventoryItem> items)
{ {
int currentIndex = 0; int currentIndex = 0;
@ -403,7 +404,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
int quantityCount = quantity; int quantityCount = quantity;
for (int i = 0; i < list.Count; i++) for (int i = 0; i < list.Count; i++)
{ {
Item item = list[i]; InventoryItem item = list[i];
if (item.itemId == itemId && item.quantity < item.maxStack) if (item.itemId == itemId && item.quantity < item.maxStack)
{ {
quantityCount -= (item.maxStack - item.quantity); quantityCount -= (item.maxStack - item.quantity);
@ -424,7 +425,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
{ {
int count = 0; int count = 0;
foreach (Item item in list) foreach (InventoryItem item in list)
{ {
if (item.itemId == itemId) if (item.itemId == itemId)
count += item.quantity; count += item.quantity;

View File

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.dataobjects
{
class InventoryItem
{
public uint uniqueId;
public uint itemId;
public int quantity = 1;
public ushort slot;
public int maxStack = 99999;
public bool isUntradeable = false;
public byte quality = 1;
public uint durability = 0;
public ushort spiritbind = 0;
public byte materia1 = 0;
public byte materia2 = 0;
public byte materia3 = 0;
public byte materia4 = 0;
public byte materia5 = 0;
//Bare Minimum
public InventoryItem(uint id, uint itemId, ushort slot)
{
this.uniqueId = id;
this.itemId = itemId;
this.quantity = quantity;
this.slot = slot;
}
public InventoryItem(uint uniqueId, uint itemId, int quantity, ushort slot, bool isUntradeable, byte qualityNumber, uint durability, ushort spiritbind, byte materia1, byte materia2, byte materia3, byte materia4, byte materia5)
{
this.uniqueId = uniqueId;
this.itemId = itemId;
this.quantity = quantity;
this.slot = slot;
this.isUntradeable = isUntradeable;
this.quality = qualityNumber;
this.durability = durability;
this.spiritbind = spiritbind;
this.materia1 = materia1;
this.materia2 = materia2;
this.materia3 = materia3;
this.materia4 = materia4;
this.materia5 = materia5;
}
public byte[] toPacketBytes()
{
byte[] data = new byte[0x70];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)uniqueId);
binWriter.Write((UInt32)0x00000000);
binWriter.Write((Int32)quantity);
binWriter.Write((UInt32)itemId);
binWriter.Write((UInt16)slot);
binWriter.Write((UInt16)0x0000);
binWriter.Write((UInt32)0x00000000);
binWriter.Write((UInt32)0x00000000);
binWriter.Write((UInt32)0x00000000);
binWriter.Write(isUntradeable ? (UInt32)0x3 : (UInt32)0x0);
binWriter.Write((UInt32)0x00000000);
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);
}
}
return data;
}
}
}

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -9,99 +8,140 @@ namespace FFXIVClassic_Map_Server.dataobjects
{ {
class Item class Item
{ {
public uint uniqueId; //Basic
public uint itemId; public readonly string id;
public int quantity = 1; public readonly string name;
public ushort slot;
//_item sheet
public readonly string category;
public readonly int maxStack;
public readonly bool isRare;
public readonly bool isExclusive;
public int maxStack = 99999; //itemData sheet
public readonly int durability;
public bool isUntradeable = false; public readonly int icon;
public byte quality = 1; public readonly int king;
public readonly int color;
public uint durability = 0; public readonly int material;
public ushort spiritbind = 0; public readonly int decoration;
public readonly int use;
public byte materia1 = 0; public readonly int mainSkill;
public byte materia2 = 0; public readonly int unknown1;
public byte materia3 = 0; public readonly int level;
public byte materia4 = 0; public readonly int compatibility;
public byte materia5 = 0; public readonly float effectMagnitude;
public readonly float effectRate;
//Bare Minimum public readonly float shieldBlocking;
public Item(uint id, uint itemId, ushort slot) public readonly float effectDuration;
{ public readonly float recastTime;
this.uniqueId = id; public readonly float unknown2;
this.itemId = itemId; public readonly byte recastGroup;
this.quantity = quantity; public readonly int repairSkill;
this.slot = slot; public readonly int repairItem;
} public readonly int repairItemNum;
public readonly int repairLevel;
public Item(uint uniqueId, uint itemId, int quantity, ushort slot, bool isUntradeable, byte qualityNumber, uint durability, ushort spiritbind, byte materia1, byte materia2, byte materia3, byte materia4, byte materia5) public readonly int repairLicense;
{
this.uniqueId = uniqueId;
this.itemId = itemId;
this.quantity = quantity;
this.slot = slot;
this.isUntradeable = isUntradeable;
this.quality = qualityNumber;
this.durability = durability;
this.spiritbind = spiritbind;
this.materia1 = materia1;
this.materia2 = materia2;
this.materia3 = materia3;
this.materia4 = materia4;
this.materia5 = materia5;
}
public byte[] toPacketBytes()
{
byte[] data = new byte[0x70];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)uniqueId);
binWriter.Write((UInt32)0x00000000);
binWriter.Write((Int32)quantity);
binWriter.Write((UInt32)itemId);
binWriter.Write((UInt16)slot);
binWriter.Write((UInt16)0x0000);
binWriter.Write((UInt32)0x00000000);
binWriter.Write((UInt32)0x00000000);
binWriter.Write((UInt32)0x00000000);
binWriter.Write(isUntradeable ? (UInt32)0x3 : (UInt32)0x0);
binWriter.Write((UInt32)0x00000000);
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);
}
}
return data;
}
} }
class EquipmentItem : Item
{
//equipment sheet
public readonly int equipPoint;
public readonly short equipTribe1;
public readonly ushort unknown1;
public readonly short equipTribe2;
public readonly ushort unknown2;
public readonly short equipTribe3;
public readonly ushort unknown3;
public readonly short equipTribe4;
public readonly ushort unknown4;
public readonly int paramBonusType1;
public readonly short paramBonusValue1;
public readonly int paramBonusType2;
public readonly short paramBonusValue2;
public readonly int paramBonusType3;
public readonly short paramBonusValue3;
public readonly int paramBonusType4;
public readonly short paramBonusValue4;
public readonly int paramBonusAtSlotType;
public readonly short paramBonusAtSlotValue;
public readonly int elementalBonusType;
public readonly short elementalBonusValue;
}
class WeaponItem : EquipmentItem
{
//graphics
public readonly int graphicsWeaponId;
public readonly int graphicsEquipId;
public readonly int graphicsVariantId;
public readonly int graphicsColorId;
//weapon sheet
public readonly short attack;
public readonly short magicAttack;
public readonly short craftProcessing;
public readonly short craftMagicProcessing;
public readonly short harvestPotency;
public readonly short harvestLimit;
public readonly byte frequency;
public readonly short rate;
public readonly short magicRate;
public readonly short craftProcessControl;
public readonly short harvestRate;
public readonly short critical;
public readonly short magicCritical;
public readonly short parry;
public readonly int damageAttributeType1;
public readonly float damageAttributeValue1;
public readonly int damageAttributeType2;
public readonly float damageAttributeValue2;
public readonly int damageAttributeType3;
public readonly float damageAttributeValue3;
}
class ArmorItem : EquipmentItem
{
//graphics
public readonly int graphicsArmorId;
public readonly int graphicsEquipId;
public readonly int graphicsVariantId;
public readonly int graphicsColorId;
//armor sheet
public readonly short defence;
public readonly short magicDefence;
public readonly short criticalDefense;
public readonly short evasion;
public readonly short magicResistance;
public readonly int damageDefenseType1;
public readonly short damageDefenseValue1;
public readonly int damageDefenseType2;
public readonly short damageDefenseValue2;
public readonly int damageDefenseType3;
public readonly short damageDefenseValue3;
public readonly int damageDefenseType4;
public readonly short damageDefenseValue4;
}
class AccessoryItem : EquipmentItem
{
//graphics
public readonly int graphicsAccessoryId;
public readonly int graphicsEquipId;
public readonly int graphicsVariantId;
public readonly int graphicsColorId;
//accessory sheet
public readonly byte power;
public readonly byte size;
}
} }

View File

@ -14,7 +14,7 @@ namespace FFXIVClassic_Map_Server.packets.send.Actor.inventory
public const ushort OPCODE = 0x14E; public const ushort OPCODE = 0x14E;
public const uint PACKET_SIZE = 0x58; public const uint PACKET_SIZE = 0x58;
public static SubPacket buildPacket(uint playerActorId, Item[] equipment, List<ushort> slotsToUpdate, ref int listOffset) public static SubPacket buildPacket(uint playerActorId, InventoryItem[] equipment, List<ushort> slotsToUpdate, ref int listOffset)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];

View File

@ -14,7 +14,7 @@ namespace FFXIVClassic_Map_Server.packets.send.Actor.inventory
public const ushort OPCODE = 0x14F; public const ushort OPCODE = 0x14F;
public const uint PACKET_SIZE = 0x80; public const uint PACKET_SIZE = 0x80;
public static SubPacket buildPacket(uint playerActorId, Item[] equipment, List<ushort> slotsToUpdate, ref int listOffset) public static SubPacket buildPacket(uint playerActorId, InventoryItem[] equipment, List<ushort> slotsToUpdate, ref int listOffset)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];

View File

@ -14,7 +14,7 @@ namespace FFXIVClassic_Map_Server.packets.send.Actor.inventory
public const ushort OPCODE = 0x150; public const ushort OPCODE = 0x150;
public const uint PACKET_SIZE = 0xE0; public const uint PACKET_SIZE = 0xE0;
public static SubPacket buildPacket(uint playerActorId, Item[] equipment, List<ushort> slotsToUpdate, ref int listOffset) public static SubPacket buildPacket(uint playerActorId, InventoryItem[] equipment, List<ushort> slotsToUpdate, ref int listOffset)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];

View File

@ -14,7 +14,7 @@ namespace FFXIVClassic_Map_Server.packets.send.Actor.inventory
public const ushort OPCODE = 0x151; public const ushort OPCODE = 0x151;
public const uint PACKET_SIZE = 0x194; public const uint PACKET_SIZE = 0x194;
public static SubPacket buildPacket(uint playerActorId, Item[] equipment, List<ushort> slotsToUpdate, ref int listOffset) public static SubPacket buildPacket(uint playerActorId, InventoryItem[] equipment, List<ushort> slotsToUpdate, ref int listOffset)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];

View File

@ -15,7 +15,7 @@ namespace FFXIVClassic_Map_Server.packets.send.Actor.inventory
public const ushort OPCODE = 0x0149; public const ushort OPCODE = 0x0149;
public const uint PACKET_SIZE = 0x90; public const uint PACKET_SIZE = 0x90;
public static SubPacket buildPacket(uint playerActorID, List<Item> items, ref int listOffset) public static SubPacket buildPacket(uint playerActorID, List<InventoryItem> items, ref int listOffset)
{ {
byte[] data; byte[] data;

View File

@ -15,7 +15,7 @@ namespace FFXIVClassic_Map_Server.packets.send.Actor.inventory
public const ushort OPCODE = 0x014A; public const ushort OPCODE = 0x014A;
public const uint PACKET_SIZE = 0x90; public const uint PACKET_SIZE = 0x90;
public static SubPacket buildPacket(uint playerActorID, List<Item> items, ref int listOffset) public static SubPacket buildPacket(uint playerActorID, List<InventoryItem> items, ref int listOffset)
{ {
byte[] data; byte[] data;

View File

@ -14,7 +14,7 @@ namespace FFXIVClassic_Map_Server.packets.send.actor.inventory
public const ushort OPCODE = 0x0148; public const ushort OPCODE = 0x0148;
public const uint PACKET_SIZE = 0x90; public const uint PACKET_SIZE = 0x90;
public static SubPacket buildPacket(uint playerActorID, Item item) public static SubPacket buildPacket(uint playerActorID, InventoryItem item)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];

View File

@ -14,7 +14,7 @@ namespace FFXIVClassic_Map_Server.packets.send.actor.inventory
public const ushort OPCODE = 0x0149; public const ushort OPCODE = 0x0149;
public const uint PACKET_SIZE = 0x3A8; public const uint PACKET_SIZE = 0x3A8;
public static SubPacket buildPacket(uint playerActorID, List<Item> items, ref int listOffset) public static SubPacket buildPacket(uint playerActorID, List<InventoryItem> items, ref int listOffset)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];

View File

@ -14,7 +14,7 @@ namespace FFXIVClassic_Map_Server.packets.send.actor.inventory
public const ushort OPCODE = 0x014A; public const ushort OPCODE = 0x014A;
public const uint PACKET_SIZE = 0x720; public const uint PACKET_SIZE = 0x720;
public static SubPacket buildPacket(uint playerActorID, List<Item> items, ref int listOffset) public static SubPacket buildPacket(uint playerActorID, List<InventoryItem> items, ref int listOffset)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];

View File

@ -14,7 +14,7 @@ namespace FFXIVClassic_Map_Server.packets.send.actor.inventory
public const ushort OPCODE = 0x014B; public const ushort OPCODE = 0x014B;
public const uint PACKET_SIZE = 0xE20; public const uint PACKET_SIZE = 0xE20;
public static SubPacket buildPacket(uint playerActorID, List<Item> items, ref int listOffset) public static SubPacket buildPacket(uint playerActorID, List<InventoryItem> items, ref int listOffset)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];

View File

@ -14,7 +14,7 @@ namespace FFXIVClassic_Map_Server.packets.send.actor.inventory
public const ushort OPCODE = 0x014C; public const ushort OPCODE = 0x014C;
public const uint PACKET_SIZE = 0x1C20; public const uint PACKET_SIZE = 0x1C20;
public static SubPacket buildPacket(uint playerActorID, List<Item> items, ref int listOffset) public static SubPacket buildPacket(uint playerActorID, List<InventoryItem> items, ref int listOffset)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];