Files
7d2dXG/Mods/zzz_REBIRTH__Utils/Harmony/Harmony_ObjectiveFetch.cs
Nathaniel Cosford e06f2bd282 Add All Mods
2025-05-29 23:33:28 +09:30

164 lines
11 KiB
C#

namespace Harmony.ObjectiveFetchKeepPatches
{
public class SetupObjectivePatchClass
{
[HarmonyPatch(typeof(ObjectiveFetch))]
[HarmonyPatch("SetupDisplay")]
public class SetupDisplayPatch
{
public static bool Prefix(ObjectiveFetch __instance)
{
//Log.Out("ObjectiveFetchKeepPatches-SetupDisplay __instance.keyword: " + __instance.keyword);
string localizedName = "";
if (__instance.expectedItemClass != null)
{
localizedName = __instance.expectedItemClass.GetLocalizedItemName();
}
else
{
// Seems necessary when using the Contrband Collection Custom job is you exit before completing the job
//Log.Out("ObjectiveFetchKeepPatches-SetupDisplay expectedItemClass == null");
}
//Log.Out("ObjectiveFetchKeepPatches-SetupDisplay __instance.expectedItemClass.GetLocalizedItemName(): " + localizedName);
//Log.Out("ObjectiveFetchKeepPatches-SetupDisplay __instance.currentCount: " + __instance.currentCount);
//Log.Out("ObjectiveFetchKeepPatches-SetupDisplay __instance.itemCount: " + __instance.itemCount);
__instance.Description = string.Format(__instance.keyword, localizedName);
__instance.StatusText = string.Format("{0}/{1}", __instance.currentCount, __instance.itemCount);
return false;
}
}
[HarmonyPatch(typeof(ObjectiveFetch))]
[HarmonyPatch("Refresh")]
public class RefreshPatch
{
public static bool Prefix(ObjectiveFetch __instance,
int ___itemCount,
ref int ___currentCount,
ItemValue ___expectedItem
)
{
if (__instance.Complete)
{
//Log.Out("SetupObjectivePatchClass-Refresh 1");
return false;
}
if (___expectedItem.ItemClass == null)
{
//Log.Out("SetupObjectivePatchClass-Refresh ___expectedItem.ItemClass == null");
return false;
}
//Log.Out("SetupObjectivePatchClass-Refresh ___expectedItem: " + ___expectedItem.ItemClass.GetItemName());
XUiM_PlayerInventory playerInventory = LocalPlayerUI.GetUIForPlayer(__instance.OwnerQuest.OwnerJournal.OwnerPlayer).xui.PlayerInventory;
//Log.Out("SetupObjectivePatchClass-Refresh A ___currentCount: " + ___currentCount);
if (___expectedItem.ItemClass.GetItemName() == "FuriousRamsayAnimalChicken001Spawn")
{
int backpackCount = 0;
backpackCount = playerInventory.Backpack.GetItemCount(ItemClass.GetItem("FuriousRamsayAnimalChicken001Spawn", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("FuriousRamsayAnimalChicken002Spawn", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("FuriousRamsayAnimalChicken003Spawn", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("FuriousRamsayAnimalChicken004Spawn", false), -1, -1, false);
//Log.Out("SetupObjectivePatchClass-Refresh B backpackCount: " + backpackCount);
int toolbeltCount = 0;
toolbeltCount = playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("FuriousRamsayAnimalChicken001Spawn", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("FuriousRamsayAnimalChicken002Spawn", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("FuriousRamsayAnimalChicken003Spawn", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("FuriousRamsayAnimalChicken004Spawn", false), false, -1, -1);
//Log.Out("SetupObjectivePatchClass-Refresh B toolbeltCount: " + toolbeltCount);
___currentCount = backpackCount + toolbeltCount;
//Log.Out("SetupObjectivePatchClass-Refresh B ___currentCount: " + ___currentCount);
}
else if (___expectedItem.ItemClass.GetItemName() == "FuriousRamsayCardboardBox")
{
//Log.Out("SetupObjectivePatchClass-Refresh 2");
int backpackCount = 0;
backpackCount = playerInventory.Backpack.GetItemCount(ItemClass.GetItem("FuriousRamsayCardboardBox", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("palletBrownBoxesTile_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("palletBrownBoxesBase_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("palletBrownBoxesTop_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("palletBrownBoxesLoose_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("cntLootCrateMoPowerElectronics_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("cntLootCrateCarParts_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("cntStorageGenericPOI_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("cntLootCrateLabEquipment_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("cntLootCrateSavageCountry_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("cntLootCrateShamway_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("cntLootCrateShotgunMessiah_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("cntLootCrateWorkingStiffs_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("cntLootCrateConstructionSupplies_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("cntLootCrateBookstore_PickedUp", false), -1, -1, false);
backpackCount += playerInventory.Backpack.GetItemCount(ItemClass.GetItem("cntLootCrateHero_PickedUp", false), -1, -1, false);
//Log.Out("SetupObjectivePatchClass-Refresh C backpackCount: " + backpackCount);
int toolbeltCount = 0;
toolbeltCount = playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("FuriousRamsayCardboardBox", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("palletBrownBoxesTile_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("palletBrownBoxesBase_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("palletBrownBoxesTop_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("palletBrownBoxesLoose_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("cntLootCrateMoPowerElectronics_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("cntLootCrateCarParts_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("cntStorageGenericPOI_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("cntLootCrateLabEquipment_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("cntLootCrateSavageCountry_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("cntLootCrateShamway_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("cntLootCrateShotgunMessiah_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("cntLootCrateWorkingStiffs_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("cntLootCrateConstructionSupplies_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("cntLootCrateBookstore_PickedUp", false), false, -1, -1);
toolbeltCount += playerInventory.Toolbelt.GetItemCount(ItemClass.GetItem("cntLootCrateHero_PickedUp", false), false, -1, -1);
//Log.Out("SetupObjectivePatchClass-Refresh C toolbeltCount: " + toolbeltCount);
___currentCount = backpackCount + toolbeltCount;
//Log.Out("SetupObjectivePatchClass-Refresh C ___currentCount: " + ___currentCount);
}
else
{
//Log.Out("SetupObjectivePatchClass-Refresh 3");
___currentCount = playerInventory.Backpack.GetItemCount(___expectedItem, -1, -1, false);
___currentCount += playerInventory.Toolbelt.GetItemCount(___expectedItem, false, -1, -1);
//Log.Out("SetupObjectivePatchClass-Refresh D ___currentCount: " + ___currentCount);
}
if (___currentCount > ___itemCount)
{
//Log.Out("SetupObjectivePatchClass-Refresh 4");
___currentCount = ___itemCount;
}
__instance.SetupDisplay();
if (___currentCount != (int)__instance.CurrentValue)
{
//Log.Out("SetupObjectivePatchClass-Refresh 5");
__instance.CurrentValue = (byte)___currentCount;
}
__instance.Complete = (___currentCount >= ___itemCount && __instance.OwnerQuest.CheckRequirements());
if (__instance.Complete)
{
//Log.Out("SetupObjectivePatchClass-Refresh 6");
__instance.OwnerQuest.RefreshQuestCompletion(QuestClass.CompletionTypes.AutoComplete, null, true);
}
return false;
}
}
}
}