Added retainer inventory code. Renamed CURRENCY inv type to CURRENCY_CRYSTALS so I don't forget.

This commit is contained in:
Filip Maj
2017-09-09 14:11:35 -04:00
parent 52c707d66e
commit 64006d2351
5 changed files with 251 additions and 70 deletions

View File

@@ -12,45 +12,50 @@ namespace FFXIVClassic_Map_Server.actors.chara.npc
{
class Retainer : Npc
{
Player player;
public const int MAXSIZE_INVENTORY_NORMAL = 150;
public const int MAXSIZE_INVENTORY_CURRANCY = 320;
public const int MAXSIZE_INVENTORY_BAZAAR = 10;
public Retainer(string retainerName, ActorClass actorClass, Player player, float posX, float posY, float posZ, float rot)
: base(0, actorClass, "myretainer", player.GetZone(), posX, posY, posZ, rot, 0, 0, retainerName)
private uint retainerId;
private Player ownerPlayer;
private Dictionary<ushort, Inventory> inventories = new Dictionary<ushort, Inventory>();
public Retainer(uint retainerId, ActorClass actorClass, Player player, float posX, float posY, float posZ, float rot)
: base(0, actorClass, "myretainer", player.GetZone(), posX, posY, posZ, rot, 0, 0, null)
{
this.player = player;
this.retainerId = retainerId;
this.ownerPlayer = player;
this.actorName = String.Format("_rtnre{0:x7}", actorId);
inventories[Inventory.NORMAL] = new Inventory(this, MAXSIZE_INVENTORY_NORMAL, Inventory.NORMAL);
inventories[Inventory.CURRENCY_CRYSTALS] = new Inventory(this, MAXSIZE_INVENTORY_CURRANCY, Inventory.CURRENCY_CRYSTALS);
inventories[Inventory.BAZAAR] = new Inventory(this, MAXSIZE_INVENTORY_BAZAAR, Inventory.BAZAAR);
inventories[Inventory.NORMAL].InitList(Database.GetInventory(this, Inventory.NORMAL));
inventories[Inventory.CURRENCY_CRYSTALS].InitList(Database.GetInventory(this, Inventory.CURRENCY_CRYSTALS));
inventories[Inventory.BAZAAR].InitList(Database.GetInventory(this, Inventory.BAZAAR));
}
public void SendBazaarItems(Player player)
public Inventory GetInventory(ushort type)
{
Inventory bazaar = new Inventory(this, 150, (ushort)0);
bazaar.AddItem(1000001);
bazaar.AddItem(3020517);
player.QueuePacket(InventoryBeginChangePacket.BuildPacket(actorId));
bazaar.SendFullInventory(player);
player.QueuePacket(InventoryEndChangePacket.BuildPacket(actorId));
if (inventories.ContainsKey(type))
return inventories[type];
else
return null;
}
public void SendStorageItems(Player player)
{
Inventory storage = new Inventory(this, 10, Inventory.CURRENCY);
storage.AddItem(1000001);
storage.AddItem(3020519);
public void SendFullRetainerInventory(Player player)
{
player.QueuePacket(InventoryBeginChangePacket.BuildPacket(actorId));
storage.SendFullInventory(player);
inventories[Inventory.NORMAL].SendFullInventory(player);
inventories[Inventory.CURRENCY_CRYSTALS].SendFullInventory(player);
inventories[Inventory.BAZAAR].SendFullInventory(player);
player.QueuePacket(InventoryEndChangePacket.BuildPacket(actorId));
}
public void SendHuhItems(Player player)
public uint getRetainerId()
{
Inventory storage = new Inventory(this, 20, 7);
storage.AddItem(1000003);
storage.AddItem(1000016);
player.QueuePacket(InventoryBeginChangePacket.BuildPacket(actorId));
storage.SendFullInventory(player);
player.QueuePacket(InventoryEndChangePacket.BuildPacket(actorId));
return retainerId;
}
}
}

View File

@@ -13,19 +13,16 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
{
class Inventory
{
public const ushort NORMAL = 0x0000; //Max 0xC8
public const ushort TRADE = 0x0001; //Max 0x96
public const ushort LOOT = 0x0004; //Max 0xA
public const ushort MELDREQUEST = 0x0005; //Max 0x04
public const ushort BAZAAR = 0x0007; //Max 0x0A
public const ushort RETAINER_BAZAAR = 0x0008; //????
public const ushort CURRENCY = 0x0063; //Max 0x140
public const ushort KEYITEMS = 0x0064; //Max 0x500
public const ushort EQUIPMENT = 0x00FE; //Max 0x23
public const ushort EQUIPMENT_OTHERPLAYER = 0x00F9; //Max 0x23
private int endOfListIndex = 0;
public const ushort NORMAL = 0; //Max 0xC8
public const ushort TRADE = 1; //Max 0x96
public const ushort LOOT = 4; //Max 0xA
public const ushort MELDREQUEST = 5; //Max 0x04
public const ushort BAZAAR = 7; //Max 0x0A
public const ushort CURRENCY_CRYSTALS = 99; //Max 0x140
public const ushort KEYITEMS = 100; //Max 0x500
public const ushort EQUIPMENT = 0x00FE; //Max 0x23
public const ushort EQUIPMENT_OTHERPLAYER = 0x00F9; //Max 0x23
private Character owner;
private ushort inventoryCapacity;
private ushort inventoryCode;
@@ -33,6 +30,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
private InventoryItem[] list;
private bool[] isDirty;
private int endOfListIndex = 0;
public Inventory(Character ownerPlayer, ushort capacity, ushort code, bool temporary = false)
{
owner = ownerPlayer;
@@ -281,7 +280,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
DoDatabaseQuantity(list[slot].uniqueId, list[slot].quantity);
isDirty[slot] = true;
SendUpdatePackets((Player)owner);
SendUpdatePackets();
}
}
@@ -431,9 +430,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
if (owner is Player)
Database.AddItem((Player)owner, addedItem, inventoryCode);
else if (owner is Retainer)
{
}
Database.AddItem((Retainer)owner, addedItem, inventoryCode);
}
private void DoDatabaseQuantity(ulong itemDBId, int quantity)
@@ -444,9 +441,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
if (owner is Player)
Database.SetQuantity((Player)owner, itemDBId, inventoryCode);
else if (owner is Retainer)
{
}
Database.SetQuantity((Retainer)owner, itemDBId, inventoryCode);
}
private void DoDatabaseRemove(ulong itemDBId)
@@ -457,18 +452,18 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
if (owner is Player)
Database.RemoveItem((Player)owner, itemDBId);
else if (owner is Retainer)
{
}
Database.RemoveItem((Retainer)owner, itemDBId);
}
private void SendUpdatePackets()
{
if (owner is Player)
SendUpdatePackets((Player)owner);
{
SendUpdatePackets((Player)owner, true);
}
}
private void SendUpdatePackets(Player player)
public void SendUpdatePackets(Player player, bool doneImmediate = false)
{
List<InventoryItem> items = new List<InventoryItem>();
List<ushort> slotsToRemove = new List<ushort>();
@@ -487,7 +482,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
slotsToRemove.Add((ushort)i);
}
Array.Clear(isDirty, 0, isDirty.Length);
if (doneImmediate)
DoneSendUpdate();
player.QueuePacket(InventoryBeginChangePacket.BuildPacket(owner.actorId));
player.QueuePacket(InventorySetBeginPacket.BuildPacket(owner.actorId, inventoryCapacity, inventoryCode));
@@ -498,6 +494,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
player.QueuePacket(InventorySetEndPacket.BuildPacket(owner.actorId));
player.QueuePacket(InventoryEndChangePacket.BuildPacket(owner.actorId));
}
public void DoneSendUpdate()
{
Array.Clear(isDirty, 0, isDirty.Length);
}
#endregion
#region Inventory Utils

View File

@@ -161,7 +161,7 @@ namespace FFXIVClassic_Map_Server.Actors
inventories[Inventory.NORMAL] = new Inventory(this, MAXSIZE_INVENTORY_NORMAL, Inventory.NORMAL);
inventories[Inventory.KEYITEMS] = new Inventory(this, MAXSIZE_INVENTORY_KEYITEMS, Inventory.KEYITEMS);
inventories[Inventory.CURRENCY] = new Inventory(this, MAXSIZE_INVENTORY_CURRANCY, Inventory.CURRENCY);
inventories[Inventory.CURRENCY_CRYSTALS] = new Inventory(this, MAXSIZE_INVENTORY_CURRANCY, Inventory.CURRENCY_CRYSTALS);
inventories[Inventory.MELDREQUEST] = new Inventory(this, MAXSIZE_INVENTORY_MELDREQUEST, Inventory.MELDREQUEST);
inventories[Inventory.BAZAAR] = new Inventory(this, MAXSIZE_INVENTORY_BAZAAR, Inventory.BAZAAR);
inventories[Inventory.LOOT] = new Inventory(this, MAXSIZE_INVENTORY_LOOT, Inventory.LOOT);
@@ -535,7 +535,7 @@ namespace FFXIVClassic_Map_Server.Actors
#region Inventory & Equipment
QueuePacket(InventoryBeginChangePacket.BuildPacket(actorId));
inventories[Inventory.NORMAL].SendFullInventory(this);
inventories[Inventory.CURRENCY].SendFullInventory(this);
inventories[Inventory.CURRENCY_CRYSTALS].SendFullInventory(this);
inventories[Inventory.KEYITEMS].SendFullInventory(this);
inventories[Inventory.BAZAAR].SendFullInventory(this);
inventories[Inventory.MELDREQUEST].SendFullInventory(this);
@@ -1048,8 +1048,8 @@ namespace FFXIVClassic_Map_Server.Actors
public int GetCurrentGil()
{
if (GetInventory(Inventory.CURRENCY).HasItem(1000001))
return GetInventory(Inventory.CURRENCY).GetItemByCatelogId(1000001).quantity;
if (GetInventory(Inventory.CURRENCY_CRYSTALS).HasItem(1000001))
return GetInventory(Inventory.CURRENCY_CRYSTALS).GetItemByCatelogId(1000001).quantity;
else
return 0;
}
@@ -1745,20 +1745,16 @@ namespace FFXIVClassic_Map_Server.Actors
public Retainer SpawnMyRetainer(Npc bell, int retainerIndex)
{
Tuple<uint, uint, string> retainerData = Database.GetRetainer(this, retainerIndex);
ActorClass actorClass = Server.GetWorldManager().GetActorClass(retainerData.Item2);
if (actorClass == null)
return null;
Retainer retainer = Database.LoadRetainer(this, retainerIndex);
float distance = (float)Math.Sqrt(((positionX - bell.positionX) * (positionX - bell.positionX)) + ((positionZ - bell.positionZ) * (positionZ - bell.positionZ)));
float posX = bell.positionX - ((-1.0f * (bell.positionX - positionX)) / distance);
float posZ = bell.positionZ - ((-1.0f * (bell.positionZ - positionZ)) / distance);
Retainer retainer = new Retainer(retainerData.Item3, actorClass, this, posX, bell.positionY, positionZ, (float)Math.Atan2(positionX - posX, positionZ - posZ));
retainer.LoadEventConditions(actorClass.eventConditions);
retainer.positionX = posX;
retainer.positionY = positionY;
retainer.positionZ = posZ;
retainer.rotation = (float)Math.Atan2(positionX - posX, positionZ - posZ);
retainerMeetingGroup = new RetainerMeetingRelationGroup(5555, this, retainer);
retainerMeetingGroup.SendGroupPackets(playerSession);