Ejemplo n.º 1
0
        public static bool PressedButton(T __instance, string buttonText, int buttonPrice)
        {
            ObjectInteraction interaction = RogueLibsInteractions.GetObjectInteraction(buttonText);

            if (interaction == null && buttonText != "HackExplode" && buttonText != "CollectPart")
            {
                Debug.LogError("Unknown interaction \"" + buttonText + "\" for " + typeof(T).Name);
                __instance.StopInteraction();
                return(true);
            }

            MethodInfo baseMethod = AccessTools.DeclaredMethod(__instance.GetType().BaseType, "PressedButton", new Type[] { typeof(string), typeof(int) });

            baseMethod.GetMethodWithoutOverrides <Action <string, int> >(__instance).Invoke(buttonText, buttonPrice);

            if (interaction.Action?.Invoke(__instance.interactingAgent, __instance) ?? false)
            {
                __instance.StopInteraction();
            }
            else
            {
                __instance.RefreshButtons();
            }
            return(false);
        }
Ejemplo n.º 2
0
        public override void Patch()
        {
            base.Patch();

            ObjectInteraction reduceAmmoPrices = RogueLibsInteractions.CreateOriginalInteraction("ReduceAmmoPrices", InteractionType.Button,
                                                                                                 (agent, obj) => obj is AmmoDispenser a && !a.isBrokenShowButtons() && agent.interactionHelper.interactingFar && a.hacked == 0);

            reduceAmmoPrices.Action = (agent, obj) =>
            {
                obj.gc.audioHandler.Play(agent, "Success");
                ((AmmoDispenser)obj).ReduceAmmoPrices(agent);
                return(true);
            };

            ObjectInteraction hackExplode = RogueLibsInteractions.CreateOriginalInteraction("HackExplode", InteractionType.Button,
                                                                                            (agent, obj) => obj is AmmoDispenser a && !a.isBrokenShowButtons() && agent.interactionHelper.interactingFar && ((agent.oma.superSpecialAbility && agent.agentName == "Hacker") || agent.statusEffects.hasTrait("HacksBlowUpObjects")));
            // action is defined in ObjectReal.PressedButton

            ObjectInteraction refillGun = RogueLibsInteractions.CreateOriginalInteraction("RefillGun", InteractionType.Button,
                                                                                          (agent, obj) => obj is AmmoDispenser a && !a.isBrokenShowButtons() && !agent.interactionHelper.interactingFar && agent.inventory.InvItemList.Any(i => i.itemType == "WeaponProjectile"));

            refillGun.Action = (_, obj) =>
            {
                obj.ShowUseOn("RefillGun");
                return(false);
            };

            ObjectInteraction giveMechOil = RogueLibsInteractions.CreateOriginalInteraction("GiveMechOil", InteractionType.Button,
                                                                                            (agent, obj) =>
            {
                if (!(obj is AmmoDispenser a) || a.isBrokenShowButtons() || !agent.statusEffects.hasTrait("OilRestoresHealth"))
                {
                    return(false);
                }

                InvItem invItem = new InvItem
                {
                    invItemName  = "OilContainer",
                    invItemCount = 1
                };
                invItem.ItemSetup(false);
                float num = 1.5f;
                if (agent.statusEffects.hasTrait("OilRestoresMoreHealth") || agent.oma.superSpecialAbility)
                {
                    num = 3f;
                }

                invItem.itemValue = (int)(invItem.itemValue / num);
                float num2        = agent.health / invItem.initCount * invItem.itemValue;
                int num3          = Mathf.Max(obj.determineMoneyCost((int)(agent.healthMax / invItem.initCount * invItem.itemValue - num2), "AmmoDispenser"), 0);
                return(num3 > 0);
            });
Ejemplo n.º 3
0
        internal static ObjectInteraction CreateObjectInteractionInternal(string id, InteractionType type, CustomNameInfo?buttonName, Func <Agent, PlayfieldObject, bool> condition, bool orig)
        {
            ObjectInteraction objectInteraction = GetObjectInteraction(id);

            if (objectInteraction != null)
            {
                string message = string.Concat("An ObjectInteraction with Id \"", id, "\" already exists!");
                Logger.LogError(message);
                throw new ArgumentException(message, nameof(id));
            }
            ObjectInteractions.Add(objectInteraction = new ObjectInteraction(id, type,
                                                                             buttonName.HasValue ? RogueLibs.CreateCustomName(id, "Interface", buttonName.Value) : null, orig));
            objectInteraction.Condition = condition;

            Logger.LogDebug(string.Concat("An ObjectInteraction with Id \"", id, "\" (", type.ToString(), ") was created."));

            return(objectInteraction);
        }
Ejemplo n.º 4
0
        public override void Patch()
        {
            base.Patch();

            ObjectInteraction makeOferring = RogueLibsInteractions.CreateOriginalInteraction("MakeOffering", InteractionType.Button,
                                                                                             (agent, obj) => obj is Altar a && !agent.interactionHelper.interactingFar);

            makeOferring.Action = (_, obj) =>
            {
                Altar altar = (Altar)obj;
                if (altar.offeringsMade >= altar.offeringLimit)
                {
                    altar.gc.audioHandler.Play(altar, "CantDo");
                    return(true);
                }
                altar.interactingAgent.SayDialogue("OfferingMustBeInBuilding");
                altar.commander = altar.interactingAgent;
                altar.interactingAgent.mainGUI.invInterface.ShowTarget(altar, "MakeOffering");
                IEnumerator enumerator = (IEnumerator)AccessTools.Method(typeof(Altar), "MakingOffer").Invoke(altar, new object[0]);
                altar.StartCoroutine(enumerator);
                return(false);
            };
        }