private void Interactor_PerformInteraction(On.RoR2.Interactor.orig_PerformInteraction orig, Interactor self, GameObject interactableObject) { PurchaseInteraction purchaseInteraction = interactableObject.GetComponent <PurchaseInteraction>(); if (purchaseInteraction) { TrustyLockpicksComponent component = interactableObject.GetComponent <TrustyLockpicksComponent>(); if (!component || (component && !component.failed)) { CharacterBody characterBody = self.GetComponent <CharacterBody>(); if (characterBody) { Inventory inventory = characterBody.inventory; if (inventory) { int InventoryCount = characterBody.inventory.GetItemCount(catalogIndex); if (InventoryCount > 0) { purchaseInteraction.GetInteractability(self); if (purchaseInteraction.isShrine == false && purchaseInteraction.available && purchaseInteraction.costType == CostTypeIndex.Money) //if not shrine, is available, and is not a lunar pod { purchaseInteraction.SetAvailable(false); purchaseInteraction.Networkavailable = false; purchaseInteraction.gameObject.GetComponent <ChestBehavior>().Open(); //purchaseInteraction.cost = 0; //purchaseInteraction.Networkcost = 0; purchaseInteraction.onPurchase.Invoke(self); purchaseInteraction.lastActivator = self; inventory.RemoveItem(catalogIndex); } } } } } } orig(self, interactableObject); }
private Interactability PurchaseInteraction_GetInteractability(On.RoR2.PurchaseInteraction.orig_GetInteractability orig, PurchaseInteraction self, Interactor activator) { var gameObject = self.gameObject; Highlight highlight = gameObject.GetComponent <Highlight>(); //if (!highlight) return orig(self, activator); TrustyLockpicksComponent component = gameObject.GetComponent <TrustyLockpicksComponent>(); //if (attempted) return orig(self, activator); if (component && component.failed) { if (highlight) { highlight.highlightColor = Highlight.HighlightColor.teleporter; } return(orig(self, activator)); } PurchaseInteraction purchaseInteraction = gameObject.GetComponent <PurchaseInteraction>(); if (!component) { component = gameObject.AddComponent <TrustyLockpicksComponent>(); } CharacterBody characterBody = activator.GetComponent <CharacterBody>(); if (characterBody) { Inventory inventory = characterBody.inventory; if (inventory) { if (self.isShrine == false && self.available && self.costType == CostTypeIndex.Money) //if not shrine, is available, and is not a lunar pod { EquipmentIndex equipmentIndex = inventory.GetEquipmentIndex(); if (equipmentIndex == catalogIndex) { if (inventory.GetEquipmentRestockableChargeCount(0) > 0) { if (highlight) { highlight.highlightColor = Highlight.HighlightColor.pickup; } } if (purchaseInteraction) { var resultContext = (prefix + purchaseInteraction.contextToken); if (component.oldContext == "") { component.oldContext = purchaseInteraction.contextToken; } if (purchaseInteraction.contextToken == component.oldContext) { purchaseInteraction.contextToken = resultContext; } } return(Interactability.Available); } } } } if (highlight) { highlight.highlightColor = Highlight.HighlightColor.interactive; } if (component && component.oldContext != "") { purchaseInteraction.contextToken = component.oldContext; } return(orig(self, activator)); }
private Interactability PurchaseInteraction_GetInteractability(On.RoR2.PurchaseInteraction.orig_GetInteractability orig, PurchaseInteraction self, Interactor activator) { var gameObject = self.gameObject; TrustyLockpicksComponent component = gameObject.GetComponent <TrustyLockpicksComponent>(); if (!component) { component = gameObject.AddComponent <TrustyLockpicksComponent>(); } Highlight highlight = gameObject.GetComponent <Highlight>(); PurchaseInteraction purchaseInteraction = gameObject.GetComponent <PurchaseInteraction>(); CharacterBody characterBody = activator.GetComponent <CharacterBody>(); Interactability Result(HighlightColor highlightColor, string contextTokenType = "", Interactability interactability = Interactability.Available) { //var resultContext = (prefix + purchaseInteraction.contextToken); if (highlight) { highlight.highlightColor = highlightColor; } if (purchaseInteraction) { string context; switch (contextTokenType.ToLower()) { case "key": context = prefix + purchaseInteraction.contextToken + "_KEY"; break; case "lockpick": context = prefix + purchaseInteraction.contextToken + "_LOCKPICK"; break; case "both": context = prefix + purchaseInteraction.contextToken + "_BOTH"; break; default: context = component.oldContext; break; } if (purchaseInteraction.contextToken == component.oldContext) { purchaseInteraction.contextToken = context; } Debug.Log("Context + " + context + ""); } return(interactability); } // If it's been picked and failed before // if (component && component.failed) { Result(red); return(orig(self, activator)); } if (characterBody) { Inventory inventory = characterBody.inventory; if (inventory) { if (self.isShrine == false && self.available && self.costType == CostTypeIndex.Money) //if not shrine, is available, and is not a lunar pod { bool HasKey = characterBody.inventory.GetItemCount(catalogIndex) > 0; bool LockpicksActive = inventory.GetEquipmentIndex() == TrustyLockpicks.instance.catalogIndex; //bool EquipmentReady = inventory.GetEquipmentRestockableChargeCount(0) > 0; bool LockpicksReady = LockpicksActive; if (component.oldContext == "") { component.oldContext = purchaseInteraction.contextToken; //Stores the default context once } if (HasKey) //a { if (LockpicksReady) { return(Result(yellow, "both")); //a b : has both } else { return(Result(white, "key")); //a !b : only has key } } else //!a { if (LockpicksReady) { return(Result(yellow, "lockpick")); //!a b : only lockpicks } if (component && component.oldContext != "") { purchaseInteraction.contextToken = component.oldContext; } Result(yellow); //!a !b :has neither return(orig(self, activator)); } } } } if (component && component.oldContext != "") { purchaseInteraction.contextToken = component.oldContext; } Result(yellow); return(orig(self, activator)); }
private bool AttemptUnlock(GameObject chestObject, InteractionDriver interactionDriver, float UnlockChance) { Highlight highlight = chestObject.GetComponent <Highlight>(); PurchaseInteraction purchaseInteraction = chestObject.GetComponent <PurchaseInteraction>(); if (!highlight) { return(false); } if (!purchaseInteraction) { return(false); } TrustyLockpicksComponent component = chestObject.GetComponent <TrustyLockpicksComponent>(); if (component && component.failed) { return(false); } if (!interactionDriver) { return(false); } GameObject selectedEffect; Vector3 offset = Vector3.up * 1f; if (!purchaseInteraction.isShrine && purchaseInteraction.available && purchaseInteraction.costType == CostTypeIndex.Money) { Interactor interactor = interactionDriver.interactor; //interactionDriver.interactor.AttemptInteraction(chestObject); if (Util.CheckRoll(UnlockChance)) { purchaseInteraction.SetAvailable(false); purchaseInteraction.Networkavailable = false; purchaseInteraction.gameObject.GetComponent <ChestBehavior>().Open(); //purchaseInteraction.cost = 0; //purchaseInteraction.Networkcost = 0; purchaseInteraction.onPurchase.Invoke(interactor); purchaseInteraction.lastActivator = interactor; Util.PlaySound(unlockSound, interactor.gameObject); EffectManager.SimpleEffect(UnlockEffect, chestObject.transform.position + offset, Quaternion.identity, true); } else { //var displaynamecomponent = chestObject.GetComponent<GenericDisplayNameProvider>(); //if (displaynamecomponent) displaynamecomponent.displayToken = prefix + displaynamecomponent.displayToken; if (TrustyLockpicks_KillChest) { purchaseInteraction.costType = CostTypeIndex.None; purchaseInteraction.SetAvailable(false); selectedEffect = Fail_DestroyEffect; } else { purchaseInteraction.cost = Mathf.CeilToInt(purchaseInteraction.cost * TrustyLockpicks_PriceHike); purchaseInteraction.Networkcost = purchaseInteraction.cost; selectedEffect = Fail_LockEffect; } purchaseInteraction.displayNameToken = (prefix + purchaseInteraction.displayNameToken); chestObject.AddComponent <TrustyLockpicksComponent>().failed = true; //does this even work? lol EffectManager.SimpleEffect(selectedEffect, chestObject.transform.position + offset, Quaternion.identity, true); } return(true); } else { return(false); } }