Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust PetDevice handling #4032

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/ACE.Entity/Enum/Properties/PropertyInstanceId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ public enum PropertyInstanceId : ushort
LimboSource = 40,
Snooper = 41,
TeleportedCharacter = 42,
[ServerOnly][Ephemeral]
Pet = 43,
PetOwner = 44,
[ServerOnly][Ephemeral]
PetDevice = 45,

[ServerOnly]
Expand Down
13 changes: 13 additions & 0 deletions Source/ACE.Server/WorldObjects/Pet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using ACE.DatLoader.FileTypes;
using ACE.Entity;
using ACE.Entity.Enum;
using ACE.Entity.Enum.Properties;
using ACE.Entity.Models;
using ACE.Server.Entity;
using ACE.Server.Managers;
Expand All @@ -23,8 +24,16 @@ public class Pet : Creature
{
public Player P_PetOwner;

public PetDevice P_PetDevice;

private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

public uint? PetDevice
{
get => GetProperty(PropertyInstanceId.PetDevice);
set { if (value.HasValue) SetProperty(PropertyInstanceId.PetDevice, value.Value); else RemoveProperty(PropertyInstanceId.PetDevice); }
}

/// <summary>
/// A new biota be created taking all of its values from weenie.
/// </summary>
Expand Down Expand Up @@ -94,6 +103,10 @@ private void SetEphemeralValues()

player.CurrentActivePet = this;

petDevice.Pet = Guid.Full;
PetDevice = petDevice.Guid.Full;
P_PetDevice = petDevice;

if (IsPassivePet)
nextSlowTickTime = Time.GetUnixTime();

Expand Down
7 changes: 6 additions & 1 deletion Source/ACE.Server/WorldObjects/PetDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using ACE.Server.Entity.Actions;
using ACE.Server.Factories;
using ACE.Server.Managers;
using ACE.Server.Network.GameEvent.Events;
using ACE.Server.Network.GameMessages.Messages;

namespace ACE.Server.WorldObjects
Expand All @@ -30,6 +29,12 @@ public int? PetClass
set { if (value.HasValue) SetProperty(PropertyInt.PetClass, value.Value); else RemoveProperty(PropertyInt.PetClass); }
}

public uint? Pet
{
get => GetProperty(PropertyInstanceId.Pet);
set { if (value.HasValue) SetProperty(PropertyInstanceId.Pet, value.Value); else RemoveProperty(PropertyInstanceId.Pet); }
}

/// <summary>
/// A new biota be created taking all of its values from weenie.
/// </summary>
Expand Down
28 changes: 28 additions & 0 deletions Source/ACE.Server/WorldObjects/Player_Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,13 @@ private bool HandleActionPutItemInContainer_Verify(uint itemGuid, uint container
return false;
}

if (itemRootOwner == this && item is PetDevice petDevice && petDevice.Pet is not null)
{
Session.Network.EnqueueSend(new GameEventCommunicationTransientString(Session, "You must unsummon your pet before you can transfer this item!"));
Session.Network.EnqueueSend(new GameEventInventoryServerSaveFailed(Session, itemGuid, WeenieError.None));
return false;
}

if (containerRootOwner != null && !containerRootOwner.IsOpen)
{
Session.Network.EnqueueSend(new GameEventInventoryServerSaveFailed(Session, itemGuid, WeenieError.TheContainerIsClosed));
Expand Down Expand Up @@ -1356,6 +1363,13 @@ public void HandleActionDropItem(uint itemGuid)
return;
}

if (item is PetDevice petDevice && petDevice.Pet is not null)
{
Session.Network.EnqueueSend(new GameEventCommunicationTransientString(Session, "You must unsummon your pet before you can drop this item!"));
Session.Network.EnqueueSend(new GameEventInventoryServerSaveFailed(Session, itemGuid, WeenieError.None));
return;
}

if (IsTrading && item.IsBeingTradedOrContainsItemBeingTraded(ItemsInTradeWindow))
{
Session.Network.EnqueueSend(new GameEventInventoryServerSaveFailed(Session, item.Guid.Full, WeenieError.TradeItemBeingTraded));
Expand Down Expand Up @@ -3188,6 +3202,13 @@ private void GiveObjectToPlayer(Player target, WorldObject item, Container itemF
return;
}

if (item is PetDevice petDevice && petDevice.Pet is not null)
{
Session.Network.EnqueueSend(new GameEventCommunicationTransientString(Session, "You must unsummon your pet before you can transfer this item!"));
Session.Network.EnqueueSend(new GameEventInventoryServerSaveFailed(Session, item.Guid.Full, WeenieError.AttunedItem));
return;
}

if (IsTrading && item.IsBeingTradedOrContainsItemBeingTraded(ItemsInTradeWindow))
{
Session.Network.EnqueueSend(new GameEventInventoryServerSaveFailed(Session, item.Guid.Full, WeenieError.TradeItemBeingTraded));
Expand Down Expand Up @@ -3303,6 +3324,13 @@ private void GiveObjectToNPC(WorldObject target, WorldObject item, Container ite
return;
}

if (item is PetDevice petDevice && petDevice.Pet is not null)
{
Session.Network.EnqueueSend(new GameEventCommunicationTransientString(Session, "You must unsummon your pet before you can transfer this item!"));
Session.Network.EnqueueSend(new GameEventInventoryServerSaveFailed(Session, item.Guid.Full, WeenieError.AttunedItem));
return;
}

if (IsOlthoiPlayer && target.CreatureType != ACE.Entity.Enum.CreatureType.Olthoi)
{
Session.Network.EnqueueSend(new GameEventInventoryServerSaveFailed(Session, item.Guid.Full));
Expand Down
7 changes: 7 additions & 0 deletions Source/ACE.Server/WorldObjects/Player_Trade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ public void HandleActionAddToTrade(uint itemGuid, uint tradeWindowSlotNumber)
return;
}

if (wo is PetDevice petDevice && petDevice.Pet is not null)
{
Session.Network.EnqueueSend(new GameEventCommunicationTransientString(Session, "You must unsummon your pet before you can trade this item!"));
Session.Network.EnqueueSend(new GameEventTradeFailure(Session, itemGuid, WeenieError.AttunedItem));
return;
}

if (wo.IsUniqueOrContainsUnique && !target.CheckUniques(wo, this))
{
// WeenieError.TooManyUniqueItems / WeenieErrorWithString._CannotCarryAnymore?
Expand Down
10 changes: 8 additions & 2 deletions Source/ACE.Server/WorldObjects/WorldObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,14 @@ public void Destroy(bool raiseNotifyOfDestructionEvent = true, bool fromLandbloc
item.Destroy();
}

if (this is Pet pet && pet.P_PetOwner?.CurrentActivePet == this)
pet.P_PetOwner.CurrentActivePet = null;
if (this is Pet pet)
{
if (pet.P_PetOwner?.CurrentActivePet == this)
pet.P_PetOwner.CurrentActivePet = null;

if (pet.P_PetDevice?.Pet == Guid.Full)
pet.P_PetDevice.Pet = null;
}

if (this is Vendor vendor)
{
Expand Down