// Token: 0x060004C9 RID: 1225 RVA: 0x000132B0 File Offset: 0x000114B0 public static void PayCost(CostTypeDef costTypeDef, CostTypeDef.PayCostContext context) { CostTypeCatalog.LunarItemOrEquipmentCostTypeHelper.< > c__DisplayClass3_0 CS$ < > 8__locals1; CS$ < > 8__locals1.context = context; CS$ < > 8__locals1.inventory = CS$ < > 8__locals1.context.activator.GetComponent <CharacterBody>().inventory; int cost = CS$ < > 8__locals1.context.cost; CS$ < > 8__locals1.itemWeight = 0; CS$ < > 8__locals1.equipmentWeight = 0; for (int i = 0; i < CostTypeCatalog.LunarItemOrEquipmentCostTypeHelper.lunarItemIndices.Length; i++) { ItemIndex itemIndex = CostTypeCatalog.LunarItemOrEquipmentCostTypeHelper.lunarItemIndices[i]; int itemCount = CS$ < > 8__locals1.inventory.GetItemCount(itemIndex); CS$ < > 8__locals1.itemWeight += itemCount; } int j = 0; int equipmentSlotCount = CS$ < > 8__locals1.inventory.GetEquipmentSlotCount(); while (j < equipmentSlotCount) { EquipmentState equipment = CS$ < > 8__locals1.inventory.GetEquipment((uint)j); if (Array.IndexOf <EquipmentIndex>(CostTypeCatalog.LunarItemOrEquipmentCostTypeHelper.lunarEquipmentIndices, equipment.equipmentIndex) != -1) { int equipmentWeight = CS$ < > 8__locals1.equipmentWeight + 1; CS$ < > 8__locals1.equipmentWeight = equipmentWeight; } j++; } CS$ < > 8__locals1.totalWeight = CS$ < > 8__locals1.itemWeight + CS$ < > 8__locals1.equipmentWeight; for (int k = 0; k < cost; k++) { CostTypeCatalog.LunarItemOrEquipmentCostTypeHelper.< PayCost > g__TakeOne | 3_0 (ref CS$ < > 8__locals1); } }
private static void CreateCostDefGurrenSummon() { costTypeDefGurrenSummon = new CostTypeDef(); costTypeDefGurrenSummon.costStringFormatToken = "COST_LUNARCOIN_FORMAT"; costTypeDefGurrenSummon.isAffordable = delegate(CostTypeDef costTypeDef, CostTypeDef.IsAffordableContext context) { CharacterBody characterBody = context.activator.GetComponent <CharacterBody>(); bool result = false; if (characterBody && characterBody.bodyIndex == BodyCatalog.FindBodyIndex("LagannBody")) { var master = characterBody.master; if (master) { var gurrenMinionCache = GurrenMinionCache.GetOrSetGurrenStatusCache(master); NetworkUser networkUser = Util.LookUpBodyNetworkUser(context.activator.gameObject); result = (networkUser && (ulong)networkUser.lunarCoins >= (ulong)((long)context.cost) && !gurrenMinionCache.gurrenMinion); } } return(result); }; costTypeDefGurrenSummon.payCost = delegate(CostTypeDef costTypeDef, CostTypeDef.PayCostContext context) { NetworkUser networkUser = Util.LookUpBodyNetworkUser(context.activator.gameObject); bool flag = networkUser; if (flag) { networkUser.DeductLunarCoins((uint)context.cost); } }; costTypeDefGurrenSummon.colorIndex = ColorCatalog.ColorIndex.LunarCoin; CostTypeDefs.Add(costTypeDefGurrenSummon); }
/// <summary> /// Method to get the interactable tier color from a ping target /// </summary> /// <param name="gameObject">The ping target</param> /// <returns>An Color instance of the tier color</returns> private Color GetTargetTierColor(GameObject gameObject) { Color color = Color.black; ShopTerminalBehavior shopTerminal = gameObject.GetComponent <ShopTerminalBehavior>(); if (shopTerminal) { PickupIndex pickupIndex = shopTerminal.CurrentPickupIndex(); PickupDef pickup = PickupCatalog.GetPickupDef(pickupIndex); if (pickup != null) { color = pickup.baseColor; } } GenericPickupController pickupController = gameObject.GetComponent <GenericPickupController>(); if (pickupController) { PickupDef pickup = PickupCatalog.GetPickupDef(pickupController.pickupIndex); if (pickup != null) { color = pickup.baseColor; } } PurchaseInteraction purchaseInteraction = gameObject.GetComponent <PurchaseInteraction>(); if (purchaseInteraction) { CostTypeDef costType = CostTypeCatalog.GetCostTypeDef(purchaseInteraction.costType); color = ColorCatalog.GetColor(costType.colorIndex); } PickupIndexNetworker pickupIndexNetworker = gameObject.GetComponent <PickupIndexNetworker>(); if (pickupIndexNetworker) { PickupDef pickup = PickupCatalog.GetPickupDef(pickupIndexNetworker.NetworkpickupIndex); if (pickup != null) { color = pickup.baseColor; } } if (color == Color.black) { color = _colors["InteractablePingColor"]; } return(color); }
public override void OnPluginAwake() { riftChest = PrefabAPI.InstantiateClone(Main.AssetBundle.LoadAsset <GameObject>("Assets/Items/Rift Lens/UnstableRift.prefab"), "MysticsItems_UnstableRift", false); riftChest.AddComponent <NetworkIdentity>(); PrefabAPI.RegisterNetworkPrefab(riftChest); riftPositionIndicator = PrefabAPI.InstantiateClone(Main.AssetBundle.LoadAsset <GameObject>("Assets/Items/Rift Lens/UnstableRiftPositionIndicator.prefab"), "MysticsItems_UnstableRiftPositionIndicator", false); OnRiftLensCostTypeRegister += (costTypeIndex) => { riftChest.GetComponent <PurchaseInteraction>().costType = costTypeIndex; riftChest.GetComponent <PurchaseInteraction>().cost = 1; }; //add a custom purchase cost type - we will require the interactor pay with the debuff so that players //without the debuff can't help them open chests faster CostTypeDef costTypeDef = new CostTypeDef(); costTypeDef.costStringFormatToken = "COST_MYSTICSITEMS_RIFTLENSDEBUFF_FORMAT"; costTypeDef.isAffordable = delegate(CostTypeDef costTypeDef2, CostTypeDef.IsAffordableContext context) { CharacterBody body = context.activator.gameObject.GetComponent <CharacterBody>(); if (body) { Inventory inventory = body.inventory; return(inventory ? inventory.GetItemCount(MysticsItemsContent.Items.MysticsItems_RiftLensDebuff) > 0 : false); } return(false); }; costTypeDef.payCost = delegate(CostTypeDef costTypeDef2, CostTypeDef.PayCostContext context) { CharacterBody body = context.activator.gameObject.GetComponent <CharacterBody>(); if (body) { Inventory inventory = body.inventory; if (inventory.GetItemCount(MysticsItemsContent.Items.MysticsItems_RiftLensDebuff) > 0) { inventory.RemoveItem(MysticsItemsContent.Items.MysticsItems_RiftLensDebuff); } } }; costTypeDef.colorIndex = ColorCatalog.ColorIndex.LunarItem; CostTypeCreation.CreateCostType(new CostTypeCreation.CustomCostTypeInfo { costTypeDef = costTypeDef, onRegister = OnRiftLensCostTypeRegister }); NetworkingAPI.RegisterMessageType <MysticsItemsRiftChest.SyncDestroyThingsOnOpen>(); NetworkingAPI.RegisterMessageType <MysticsItemsRiftLensBehaviour.SyncCountdown>(); }
// Token: 0x060004C8 RID: 1224 RVA: 0x000131EC File Offset: 0x000113EC public static bool IsAffordable(CostTypeDef costTypeDef, CostTypeDef.IsAffordableContext context) { CharacterBody component = context.activator.GetComponent <CharacterBody>(); if (!component) { return(false); } Inventory inventory = component.inventory; if (!inventory) { return(false); } int cost = context.cost; int num = 0; for (int i = 0; i < CostTypeCatalog.LunarItemOrEquipmentCostTypeHelper.lunarItemIndices.Length; i++) { int itemCount = inventory.GetItemCount(CostTypeCatalog.LunarItemOrEquipmentCostTypeHelper.lunarItemIndices[i]); num += itemCount; if (num >= cost) { return(true); } } int j = 0; int equipmentSlotCount = inventory.GetEquipmentSlotCount(); while (j < equipmentSlotCount) { EquipmentState equipment = inventory.GetEquipment((uint)j); for (int k = 0; k < CostTypeCatalog.LunarItemOrEquipmentCostTypeHelper.lunarEquipmentIndices.Length; k++) { if (equipment.equipmentIndex == CostTypeCatalog.LunarItemOrEquipmentCostTypeHelper.lunarEquipmentIndices[k]) { num++; if (num >= cost) { return(true); } } } j++; } return(false); }
private CostTypeDef.PayCostResults CostTypeDef_PayCost(On.RoR2.CostTypeDef.orig_PayCost orig, CostTypeDef self, int cost, Interactor activator, GameObject purchasedObject, Xoroshiro128Plus rng, ItemIndex avoidedItemIndex) { var original = orig(self, cost, activator, purchasedObject, rng, avoidedItemIndex); //var copyList = new List<ItemIndex>(original.itemsTaken); if (self.itemTier != ItemTier.NoTier) { CostTypeDef.PayCostResults payCostResults = new CostTypeDef.PayCostResults(); for (int i = 0; i < cost; i++) { payCostResults.itemsTaken.Add(original.itemsTaken[0]); } /*for (int i = 0; i < original.itemsTaken.Count; i++) * { * original.itemsTaken[i] = original.itemsTaken[0]; * }*/ return(payCostResults); } return(original); }
public static void Add(CostTypeDef costTypeDef) { costTypeDefs.Add(costTypeDef); }
public static CostTypeIndex getCostTypeIndex(CostTypeDef costTypeDef) { return((CostTypeIndex)Array.IndexOf(RoR2.CostTypeCatalog.costTypeDefs, costTypeDef)); }
private static bool LunarItemOrEquipmentCostTypeHelper_IsAffordable(On.RoR2.CostTypeCatalog.LunarItemOrEquipmentCostTypeHelper.orig_IsAffordable orig, CostTypeDef costTypeDef, CostTypeDef.IsAffordableContext context) { ignoreFakes = true; var retv = orig(costTypeDef, context); ignoreFakes = false; return(retv); }
private static void LunarItemOrEquipmentCostTypeHelper_PayCost(On.RoR2.CostTypeCatalog.LunarItemOrEquipmentCostTypeHelper.orig_PayCost orig, CostTypeDef costTypeDef, CostTypeDef.PayCostContext context) { ignoreFakes = true; orig(costTypeDef, context); ignoreFakes = false; }
public static int getCostTypeIndex(CostTypeDef costTypeDef) { return(Array.IndexOf <CostTypeDef>(CostTypeCatalog.costTypeDefs, costTypeDef)); }
public static void Init() { CostTypeDef costType_ItemFraction = new CostTypeDef(); costType_ItemFraction.costStringFormatToken = "COST_MYSTICSITEMS_PERCENTAGEITEMS_FORMAT"; costType_ItemFraction.isAffordable = delegate(CostTypeDef costTypeDef2, CostTypeDef.IsAffordableContext context) { CharacterBody body = context.activator.gameObject.GetComponent <CharacterBody>(); if (body) { Inventory inventory = body.inventory; if (inventory) { int totalItemCount = 0; ItemIndex itemIndex = 0; ItemIndex itemCount = (ItemIndex)ItemCatalog.itemCount; while (itemIndex < itemCount) { int thisItemCount = inventory.GetItemCount(itemIndex); if (thisItemCount > 0) { ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex); if (itemDef.canRemove) { totalItemCount += inventory.GetItemCount(itemIndex); } } itemIndex++; int itemsToTake = Mathf.FloorToInt(totalItemCount * Mathf.Clamp01(context.cost / 100f)); if (itemsToTake > 0) { return(true); } } } } return(false); }; costType_ItemFraction.payCost = delegate(CostTypeDef costTypeDef2, CostTypeDef.PayCostContext context) { if (context.activatorBody) { Inventory inventory = context.activatorBody.inventory; if (inventory) { List <ItemIndex> itemsToTake = CollectionPool <ItemIndex, List <ItemIndex> > .RentCollection(); WeightedSelection <ItemIndex> weightedSelection = new WeightedSelection <ItemIndex>(8); WeightedSelection <ItemIndex> weightedSelectionScrap = new WeightedSelection <ItemIndex>(8); int totalItemCount = 0; // Populate weighted selections with items from the inventory (weight is equal to the item count) foreach (ItemIndex itemIndex in ItemCatalog.allItems) { if (itemIndex != context.avoidedItemIndex) { int itemCount = inventory.GetItemCount(itemIndex); if (itemCount > 0) { ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex); if (itemDef.canRemove) { (itemDef.ContainsTag(ItemTag.Scrap) ? weightedSelectionScrap : weightedSelection).AddChoice(itemIndex, (float)itemCount); totalItemCount += itemCount; } } } } int halfTotalItemCount = Mathf.FloorToInt(totalItemCount * Mathf.Clamp01(context.cost / 100f)); // Take choices from the weighted selections and put them into the final list, until we take enough items TakeItemsFromWeightedSelection(weightedSelectionScrap, ref context, ref itemsToTake, halfTotalItemCount); TakeItemsFromWeightedSelection(weightedSelection, ref context, ref itemsToTake, halfTotalItemCount); // Unused shop terminal behaviour? If we didn't take enough items, and the purchasable is a shop terminal choice, add the choice's item index as remaining items to take for (int i = itemsToTake.Count; i < halfTotalItemCount; i++) { itemsToTake.Add(context.avoidedItemIndex); } // Remove the items from the interactor's inventory and add them to the pay context results for (int j = 0; j < itemsToTake.Count; j++) { ItemIndex itemIndex2 = itemsToTake[j]; context.results.itemsTaken.Add(itemIndex2); inventory.RemoveItem(itemIndex2, 1); } CollectionPool <ItemIndex, List <ItemIndex> > .ReturnCollection(itemsToTake); } } }; costType_ItemFraction.colorIndex = ColorCatalog.ColorIndex.Tier1Item; CostTypeCreation.CreateCostType(new CostTypeCreation.CustomCostTypeInfo { costTypeDef = costType_ItemFraction, onRegister = (costTypeIndex) => { if (OnItemFractionCostTypeRegister != null) { OnItemFractionCostTypeRegister(costTypeIndex); } } }); On.RoR2.Language.GetLocalizedFormattedStringByToken += (orig, self, token, args) => { if (token == costType_ItemFraction.costStringFormatToken) { return(orig(self, "COST_ITEM_FORMAT", new object[] { args[0].ToString() + "%" })); } return(orig(self, token, args)); }; }