private void PerformInteraction(GameObject interactableObject)
        {
            if (!NetworkServer.active)
            {
                Debug.LogWarning("[Server] function 'System.Void RoR2.Interactor::PerformInteraction(UnityEngine.GameObject)' called on client");
                return;
            }
            if (!interactableObject)
            {
                return;
            }
            bool flag = false;
            bool anyInteractionSucceeded = false;

            foreach (IInteractable interactable in interactableObject.GetComponents <IInteractable>())
            {
                Interactability interactability = interactable.GetInteractability(this);
                if (interactability == Interactability.Available)
                {
                    interactable.OnInteractionBegin(this);
                    GlobalEventManager.instance.OnInteractionBegin(this, interactable, interactableObject);
                    anyInteractionSucceeded = true;
                }
                flag |= (interactability > Interactability.Disabled);
            }
            if (flag)
            {
                this.CallRpcInteractionResult(anyInteractionSucceeded);
            }
        }
Exemplo n.º 2
0
 public InteractabilityResult(string name, Interactability interactability, Transform blocker = null)
 {
     Name            = name;
     Interactability = interactability;
     if (blocker != null)
     {
         BlockerName = blocker.GetPath();
     }
 }
Exemplo n.º 3
0
        private void CheckInteractables()
        {
            if (this.currentStage == null || !this.master.isActiveAndEnabled || this.ai.customTarget.gameObject != null)
            {
                return;
            }

            GameObject closest     = null;
            float      closestDist = 0f;

            // Chests, etc
            for (var i = this.stageCache.interactablesItem.Count - 1; i >= 0; i--)
            {
                BotInteractable <PurchaseInteraction> interactable = this.stageCache.interactablesItem[i];
                Interactability interactability = interactable.Value.GetInteractability(this.bodyInteractor);
                if (interactability == Interactability.Available)
                {
                    if (master.money < interactable.Value.cost)
                    {
                        continue;
                    }
                    float dist = Vector3.Distance(this.master.GetBody().transform.position, interactable.gameObject.transform.position);
                    if (dist <= bodyInteractor.maxInteractionDistance)
                    {
                        bodyInteractor.AttemptInteraction(interactable.gameObject);
                    }
                    if (closest == null || dist < closestDist)
                    {
                        closest     = interactable.gameObject;
                        closestDist = dist;
                    }
                }
                else if (interactability == Interactability.Disabled)
                {
                    this.stageCache.interactablesItem.RemoveAt(i);
                }
            }

            // Teleporter
            if (CheckTeleporter())
            {
                return;
            }

            if (closest)
            {
                this.ai.customTarget.gameObject = closest;
                this.ai.customTarget.Update();
            }
        }
Exemplo n.º 4
0
        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));
        }