Skip to content

Instantly share code, notes, and snippets.

@v1ld
Last active November 9, 2024 19:28
Show Gist options
  • Save v1ld/49845257b052d855ca6789c33e46e21e to your computer and use it in GitHub Desktop.
Save v1ld/49845257b052d855ca6789c33e46e21e to your computer and use it in GitHub Desktop.
Dark Future Sort Consumables
// Copyright (c) 2024 [email protected]. All Rights Reserved.
//
// Feel free to reuse under the MIT License.
module DarkFutureSortConsumables
// m_sortData is of type ref<UIInventoryItem>
@wrapMethod(NewItemCompareBuilder)
public final func FavouriteItem() -> ref<NewItemCompareBuilder> {
wrappedMethod();
if this.m_compareBuilder.value == 0 && Helper.IsConsumable(this.m_sortData1) && Helper.IsConsumable(this.m_sortData2) {
let sortOrder = Helper.GetConsumableSortOrder(this.m_sortData2) - Helper.GetConsumableSortOrder(this.m_sortData1);
this.m_compareBuilder.value = sortOrder > 0 ? 1 : (sortOrder < 0 ? -1 : 0);
}
return this;
}
class Helper {
public final static func IsConsumable(item: ref<UIInventoryItem>) -> Bool {
if item.m_realItemData.HasTag(n"Consumable") { return true; }
switch item.GetItemType() {
case gamedataItemType.Con_Edible:
case gamedataItemType.Con_LongLasting:
case gamedataItemType.Con_Inhaler:
case gamedataItemType.Con_Injector:
return true;
}
return false;
}
public final static func GetConsumableSortOrder(item: ref<UIInventoryItem>) -> Int32 {
let itemData = item.m_realItemData;
// Lower values sort near the start, higher toward the end
if itemData.HasTag(n"DarkFutureConsumableCombatUseAllowed") { return 20; }
// put energy drinks after nutrition and pure hydration
if itemData.HasTag(n"DarkFutureConsumableEnergy") { return 50; }
if itemData.HasTag(n"DarkFutureConsumableHydration") { return 30; }
if itemData.HasTag(n"DarkFutureConsumableNutrition") { return 40; }
if itemData.HasTag(n"DarkFutureConsumableNerve") { return 60; }
if itemData.HasTag(n"DarkFutureConsumableNerveRestoreDrug") { return 70; }
if itemData.HasTag(n"DarkFutureConsumableAddictionTreatmentDrug") { return 80; }
if itemData.HasTag(n"DarkFutureConsumableSedationDrug") { return 90; }
// Any long lasting item not already classified is usually a booster and should go in front
if (Equals(item.GetItemType(), gamedataItemType.Con_LongLasting)) { return 10; }
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment