コード例 #1
0
                public void OnReceived()
                {
                    if (NetworkServer.active)
                    {
                        return;
                    }
                    GameObject obj = Util.FindNetworkObject(objID);

                    if (obj)
                    {
                        MysticsItemsSpotterController controller = obj.GetComponent <MysticsItemsSpotterController>();
                        if (controller)
                        {
                            controller.ClearTarget();
                        }
                    }
                }
コード例 #2
0
        public override void OnLoad()
        {
            base.OnLoad();
            itemDef.name = "MysticsItems_Spotter";
            SetItemTierWhenAvailable(ItemTier.Tier2);
            itemDef.tags = new ItemTag[]
            {
                ItemTag.Damage
            };
            MysticsItemsContent.Resources.unlockableDefs.Add(GetUnlockableDef());
            itemDef.pickupModelPrefab = PrepareModel(Main.AssetBundle.LoadAsset <GameObject>("Assets/Items/Spotter/Model.prefab"));
            itemDef.pickupIconSprite  = Main.AssetBundle.LoadAsset <Sprite>("Assets/Items/Spotter/Icon.png");
            Material mat = itemDef.pickupModelPrefab.transform.Find("mdlSpotterBroken").gameObject.GetComponent <MeshRenderer>().sharedMaterial;

            HopooShaderToMaterial.Standard.Apply(mat);
            HopooShaderToMaterial.Standard.Gloss(mat, 0.2f, 1f);
            HopooShaderToMaterial.Standard.Emission(mat, 1f);
            itemDisplayPrefab = PrepareItemDisplayModel(PrefabAPI.InstantiateClone(itemDef.pickupModelPrefab, itemDef.pickupModelPrefab.name + "Display", false));
            MysticsRisky2Utils.Utils.CopyChildren(itemDef.pickupModelPrefab, unlockInteractablePrefab);

            ModelPanelParameters modelPanelParameters = itemDef.pickupModelPrefab.GetComponent <ModelPanelParameters>();

            modelPanelParameters.minDistance = 6f;
            modelPanelParameters.maxDistance = 12f;

            itemDisplayPrefab.transform.localScale    = Vector3.one * 0.2f;
            itemDisplayPrefab.transform.localRotation = Quaternion.Euler(new Vector3(0f, -90f, 0f));
            Rigidbody rigidbody = enemyFollowerPrefab.AddComponent <Rigidbody>();

            rigidbody.useGravity = false;
            enemyFollowerPrefab.AddComponent <GenericOwnership>();
            MysticsItemsSpotterController component = enemyFollowerPrefab.AddComponent <MysticsItemsSpotterController>();

            component.follower = PrefabAPI.InstantiateClone(itemDisplayPrefab, "SpotterFollower", false);
            component.follower.transform.SetParent(enemyFollowerPrefab.transform);
            SimpleLeash leash = component.leash = enemyFollowerPrefab.AddComponent <SimpleLeash>();

            leash.minLeashRadius = 0f;
            leash.maxLeashRadius = Mathf.Infinity;
            leash.smoothTime     = 0.2f;
            SimpleRotateToDirection rotateToDirection = component.rotateToDirection = enemyFollowerPrefab.AddComponent <SimpleRotateToDirection>();

            rotateToDirection.maxRotationSpeed = 720f;
            rotateToDirection.smoothTime       = 0.1f;

            unlockInteractablePrefab.transform.localScale *= 0.4f;
            unlockInteractablePrefab.AddComponent <MysticsItemsSpotterUnlockInteraction>();

            GameObject sparks = PrefabAPI.InstantiateClone(LegacyResourcesAPI.Load <GameObject>("Prefabs/NetworkedObjects/RadarTower").transform.Find("mdlRadar").Find("Sparks").gameObject, "Sparks", false);

            sparks.transform.localPosition = new Vector3(0f, 1f, 0f);
            ParticleSystem.MainModule particleSystem = sparks.GetComponentInChildren <ParticleSystem>().main;
            particleSystem.scalingMode = ParticleSystemScalingMode.Hierarchy;
            sparks.transform.SetParent(unlockInteractablePrefab.transform);

            Highlight highlight = unlockInteractablePrefab.AddComponent <Highlight>();

            highlight.targetRenderer = unlockInteractablePrefab.GetComponentInChildren <Renderer>();
            highlight.highlightColor = Highlight.HighlightColor.interactive;

            PurchaseInteraction purchaseInteraction = unlockInteractablePrefab.AddComponent <PurchaseInteraction>();

            purchaseInteraction.displayNameToken = "MYSTICSITEMS_BROKENSPOTTER_NAME";
            purchaseInteraction.contextToken     = "MYSTICSITEMS_BROKENSPOTTER_CONTEXT";
            purchaseInteraction.costType         = CostTypeIndex.VolatileBattery;
            purchaseInteraction.available        = true;
            purchaseInteraction.cost             = 1;
            purchaseInteraction.automaticallyScaleCostWithDifficulty = false;
            purchaseInteraction.requiredUnlockable = "";
            purchaseInteraction.setUnavailableOnTeleporterActivated = false;

            GameObject entityLocatorHolder = unlockInteractablePrefab.transform.Find("EntityLocatorHolder").gameObject;

            entityLocatorHolder.layer = LayerIndex.pickups.intVal;
            SphereCollider sphereCollider = entityLocatorHolder.AddComponent <SphereCollider>();

            sphereCollider.radius    = 12f;
            sphereCollider.isTrigger = true;
            entityLocatorHolder.AddComponent <EntityLocator>().entity = unlockInteractablePrefab;

            On.RoR2.SceneDirector.PopulateScene += (orig, self) =>
            {
                orig(self);
                if (SceneCatalog.GetSceneDefForCurrentScene().baseSceneName == "rootjungle")
                {
                    GameObject obj = Object.Instantiate(unlockInteractablePrefab, new Vector3(-139.576f, -0.824233f - 1f, 35.42688f), Quaternion.Euler(new Vector3(-29f, 25f, 348f)));
                    NetworkServer.Spawn(obj);
                }
            };

            On.RoR2.CharacterBody.Awake += (orig, self) =>
            {
                orig(self);
                self.onInventoryChanged += delegate()
                {
                    if (NetworkServer.active)
                    {
                        self.AddItemBehavior <MysticsItemsSpotterBehaviour>(self.inventory.GetItemCount(MysticsItemsContent.Items.MysticsItems_Spotter));
                    }
                };
            };

            repairSoundEventDef           = ScriptableObject.CreateInstance <NetworkSoundEventDef>();
            repairSoundEventDef.eventName = "Play_drone_repair";
            MysticsItemsContent.Resources.networkSoundEventDefs.Add(repairSoundEventDef);

            highlightPrefab = Main.AssetBundle.LoadAsset <GameObject>("Assets/Items/Spotter/SpotterTargetHighlight.prefab");
            MysticsItemsSpotterHighlight highlightComponent = highlightPrefab.AddComponent <MysticsItemsSpotterHighlight>();

            highlightComponent.insideViewObject  = highlightPrefab.transform.Find("Pivot").gameObject;
            highlightComponent.outsideViewObject = highlightPrefab.transform.Find("PivotOutsideView").gameObject;
            highlightComponent.textTargetName    = highlightPrefab.transform.Find("Pivot/Rectangle/Enemy Name").gameObject.GetComponent <TextMeshProUGUI>();
            highlightComponent.textTargetName.gameObject.AddComponent <MysticsRisky2Utils.MonoBehaviours.MysticsRisky2UtilsTextMeshUseLanguageDefaultFont>();
            highlightComponent.textTargetHP = highlightPrefab.transform.Find("Pivot/Rectangle/Health").gameObject.GetComponent <TextMeshProUGUI>();
            highlightComponent.textTargetHP.gameObject.AddComponent <MysticsRisky2Utils.MonoBehaviours.MysticsRisky2UtilsTextMeshUseLanguageDefaultFont>();

            RoR2Application.onLateUpdate += MysticsItemsSpotterHighlight.UpdateAll;
        }
コード例 #3
0
            public void FixedUpdate()
            {
                if (NetworkServer.active)
                {
                    while (enemyFollowers.Count < stack)
                    {
                        GameObject enemyFollower = Object.Instantiate(enemyFollowerPrefab, body.corePosition, Quaternion.identity);
                        enemyFollower.GetComponent <GenericOwnership>().ownerObject = gameObject;
                        NetworkServer.Spawn(enemyFollower);
                        enemyFollowers.Add(enemyFollower.GetComponent <MysticsItemsSpotterController>());
                    }
                    while (enemyFollowers.Count > stack)
                    {
                        MysticsItemsSpotterController enemyFollower = enemyFollowers.Last();
                        NetworkServer.UnSpawn(enemyFollower.gameObject);
                        Object.Destroy(enemyFollower.gameObject);
                        enemyFollowers.Remove(enemyFollower);
                    }
                }
                cooldown -= Time.fixedDeltaTime;
                if (cooldown <= 0f)
                {
                    cooldown = cooldownMax;

                    if (NetworkServer.active)
                    {
                        bullseyeSearch.teamMaskFilter = TeamMask.allButNeutral;
                        bullseyeSearch.teamMaskFilter.RemoveTeam(body.teamComponent.teamIndex);
                        Ray ray = CameraRigController.ModifyAimRayIfApplicable(new Ray
                        {
                            origin    = body.inputBank.aimOrigin,
                            direction = body.inputBank.aimDirection
                        }, body.gameObject, out _);
                        bullseyeSearch.searchOrigin      = ray.origin;
                        bullseyeSearch.searchDirection   = ray.direction;
                        bullseyeSearch.viewer            = body;
                        bullseyeSearch.maxDistanceFilter = 200f;
                        bullseyeSearch.RefreshCandidates();
                        bullseyeSearch.FilterOutGameObject(body.gameObject);
                        List <HurtBox> enemies = bullseyeSearch.GetResults().ToList();

                        foreach (MysticsItemsSpotterController enemyFollower in enemyFollowers)
                        {
                            enemyFollower.ClearTarget();
                        }

                        if (enemies.Count > 0)
                        {
                            Util.PlaySound("Play_item_proc_spotter", gameObject);
                            foreach (MysticsItemsSpotterController enemyFollower in enemyFollowers)
                            {
                                GameObject newTarget = null;
                                while (newTarget == null && enemies.Count > 0)
                                {
                                    int     index            = Mathf.FloorToInt(enemies.Count * (Random.value * 0.99f));
                                    HurtBox newTargetHurtBox = enemies.ElementAt(index);
                                    enemies.RemoveAt(index);
                                    if (newTargetHurtBox.healthComponent && newTargetHurtBox.healthComponent.body)
                                    {
                                        CharacterBody newTargetBody = newTargetHurtBox.healthComponent.body;
                                        if (!newTargetBody.HasBuff(buffDef))
                                        {
                                            newTarget = newTargetBody.gameObject;
                                        }
                                    }
                                }
                                if (newTarget)
                                {
                                    enemyFollower.SetTarget(newTarget);
                                }
                                else
                                {
                                    enemyFollower.ClearTarget();
                                }
                            }
                        }
                        else
                        {
                            cooldown = cooldownIfNoEnemiesFound;
                        }
                    }
                }
            }