From 7785f445ec113f1574c43e9406922edae339c84f Mon Sep 17 00:00:00 2001 From: gmriggs Date: Thu, 28 Dec 2023 08:50:11 -0500 Subject: [PATCH] refactoring some quest logic (#4077) --- .../WorldObjects/Player_Inventory.cs | 142 +++++++++++------- 1 file changed, 84 insertions(+), 58 deletions(-) diff --git a/Source/ACE.Server/WorldObjects/Player_Inventory.cs b/Source/ACE.Server/WorldObjects/Player_Inventory.cs index 9c0a8996b1..e541c89280 100644 --- a/Source/ACE.Server/WorldObjects/Player_Inventory.cs +++ b/Source/ACE.Server/WorldObjects/Player_Inventory.cs @@ -1042,69 +1042,13 @@ public void HandleActionPutItemInContainer(uint itemGuid, uint containerGuid, in return; } - if (item.QuestRestriction != null && !QuestManager.HasQuest(item.QuestRestriction)) + if (!VerifyQuest(item, itemRootOwner, out bool questSolve, out bool isFromAPlayerCorpse)) { - QuestManager.HandleNoQuestError(item); + // InventoryServerSaveFailed previously sent in QuestManager EnqueuePickupDone(pickupMotion); return; } - //var questSolve = false; - //var isFromMyCorpse = false; - //var isFromAPlayerCorpse = false; - //var isFromMyHook = false; - //var isFromMyStorage = false; - - //if (itemRootOwner != this && containerRootOwner == this && item.Quest != null) // We're picking up a quest item - //{ - // if ( itemRootOwner != null && (itemRootOwner.WeenieType == WeenieType.Corpse || itemRootOwner.WeenieType == WeenieType.Hook || itemRootOwner.WeenieType == WeenieType.Storage)) - // { - // if (itemRootOwner is Corpse && itemRootOwner.VictimId.HasValue && itemRootOwner.VictimId.Value == Guid.Full) - // isFromMyCorpse = true; - // if (itemRootOwner is Hook && itemRootOwner.HouseOwner.HasValue && itemRootOwner.HouseOwner.Value == Guid.Full) - // isFromMyHook = true; - // if (itemRootOwner is Storage && itemRootOwner.HouseOwner.HasValue && itemRootOwner.HouseOwner.Value == Guid.Full) - // isFromMyStorage = true; - // } - - // if (!QuestManager.CanSolve(item.Quest) && !isFromMyCorpse && !isFromMyHook && !isFromMyStorage) - // { - // QuestManager.HandleSolveError(item.Quest); - // EnqueuePickupDone(pickupMotion); - // return; - // } - // else - // { - // if (!isFromMyCorpse && !isFromMyHook && !isFromMyStorage) - // questSolve = true; - // } - //} - - var itemFoundOnCorpse = itemRootOwner is Corpse; - - var isFromAPlayerCorpse = false; - if (itemFoundOnCorpse && itemRootOwner.Level > 0) - isFromAPlayerCorpse = true; - - var questSolve = false; - if (item.Quest != null) // We're picking up an item with a quest stamp that can also be a timer/limiter - { - var itemFoundOnMyCorpse = itemFoundOnCorpse && (itemRootOwner.VictimId == Guid.Full); - if (item.GeneratorId != null || (itemFoundOnCorpse && !itemFoundOnMyCorpse)) // item is controlled by a generator or is on a corpse that is not my own - { - if (QuestManager.CanSolve(item.Quest)) - { - questSolve = true; - } - else - { - QuestManager.HandleSolveError(item.Quest); - EnqueuePickupDone(pickupMotion); - return; - } - } - } - if (DoHandleActionPutItemInContainer(item, itemRootOwner, itemWasEquipped, container, containerRootOwner, placement)) { Session.Network.EnqueueSend(new GameMessagePrivateUpdatePropertyInt(this, PropertyInt.EncumbranceVal, EncumbranceVal ?? 0)); @@ -1240,6 +1184,72 @@ private bool VerifyContainerOpenStatus(Container itemAsContainer, WorldObject it return true; } + private bool VerifyQuest(WorldObject item, Container itemRootOwner, out bool questSolve, out bool isFromAPlayerCorpse) + { + questSolve = false; + isFromAPlayerCorpse = false; + + if (item.QuestRestriction != null && !QuestManager.HasQuest(item.QuestRestriction)) + { + QuestManager.HandleNoQuestError(item); + return false; + } + + //var questSolve = false; + //var isFromMyCorpse = false; + //var isFromAPlayerCorpse = false; + //var isFromMyHook = false; + //var isFromMyStorage = false; + + //if (itemRootOwner != this && containerRootOwner == this && item.Quest != null) // We're picking up a quest item + //{ + // if ( itemRootOwner != null && (itemRootOwner.WeenieType == WeenieType.Corpse || itemRootOwner.WeenieType == WeenieType.Hook || itemRootOwner.WeenieType == WeenieType.Storage)) + // { + // if (itemRootOwner is Corpse && itemRootOwner.VictimId.HasValue && itemRootOwner.VictimId.Value == Guid.Full) + // isFromMyCorpse = true; + // if (itemRootOwner is Hook && itemRootOwner.HouseOwner.HasValue && itemRootOwner.HouseOwner.Value == Guid.Full) + // isFromMyHook = true; + // if (itemRootOwner is Storage && itemRootOwner.HouseOwner.HasValue && itemRootOwner.HouseOwner.Value == Guid.Full) + // isFromMyStorage = true; + // } + + // if (!QuestManager.CanSolve(item.Quest) && !isFromMyCorpse && !isFromMyHook && !isFromMyStorage) + // { + // QuestManager.HandleSolveError(item.Quest); + // EnqueuePickupDone(pickupMotion); + // return; + // } + // else + // { + // if (!isFromMyCorpse && !isFromMyHook && !isFromMyStorage) + // questSolve = true; + // } + //} + + var itemFoundOnCorpse = itemRootOwner is Corpse; + + if (itemFoundOnCorpse && itemRootOwner.Level > 0) + isFromAPlayerCorpse = true; + + if (item.Quest != null) // We're picking up an item with a quest stamp that can also be a timer/limiter + { + var itemFoundOnMyCorpse = itemFoundOnCorpse && (itemRootOwner.VictimId == Guid.Full); + if (item.GeneratorId != null || (itemFoundOnCorpse && !itemFoundOnMyCorpse)) // item is controlled by a generator or is on a corpse that is not my own + { + if (QuestManager.CanSolve(item.Quest)) + { + questSolve = true; + } + else + { + QuestManager.HandleSolveError(item.Quest); + return false; + } + } + } + return true; + } + private bool DoHandleActionPutItemInContainer(WorldObject item, Container itemRootOwner, bool itemWasEquipped, Container container, Container containerRootOwner, int placement) { //Console.WriteLine($"-> DoHandleActionPutItemInContainer({item.Name}, {itemRootOwner?.Name}, {itemWasEquipped}, {container?.Name}, {containerRootOwner?.Name}, {placement})"); @@ -1573,6 +1583,13 @@ public void HandleActionGetAndWieldItem(uint itemGuid, EquipMask wieldedLocation return; } + if (!VerifyQuest(item, rootOwner, out bool questSolve, out bool isFromAPlayerCorpse)) + { + // InventoryServerSaveFailed previously sent in QuestManager + EnqueuePickupDone(pickupMotion); + return; + } + if (DoHandleActionGetAndWieldItem(item, fromContainer, rootOwner, wasEquipped, wieldedLocation)) { Session.Network.EnqueueSend(new GameMessagePrivateUpdatePropertyInt(this, PropertyInt.EncumbranceVal, EncumbranceVal ?? 0)); @@ -1581,6 +1598,15 @@ public void HandleActionGetAndWieldItem(uint itemGuid, EquipMask wieldedLocation item.EmoteManager.OnPickup(this); item.NotifyOfEvent(RegenerationType.PickUp); + + if (questSolve) + item.EmoteManager.OnQuest(this); + + if (isFromAPlayerCorpse) + { + log.Debug($"[CORPSE] {Name} (0x{Guid}) picked up and wielded {item.Name} (0x{item.Guid}) from {rootOwner.Name} (0x{rootOwner.Guid})"); + item.SaveBiotaToDatabase(); + } } EnqueuePickupDone(pickupMotion); });