Skip to content

Commit

Permalink
refactoring some quest logic (#4077)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmriggs authored Dec 28, 2023
1 parent 343a8a9 commit 7785f44
Showing 1 changed file with 84 additions and 58 deletions.
142 changes: 84 additions & 58 deletions Source/ACE.Server/WorldObjects/Player_Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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})");
Expand Down Expand Up @@ -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));
Expand All @@ -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);
});
Expand Down

0 comments on commit 7785f44

Please sign in to comment.