IEnumerator WaitForStart(ChestBehavior chest) { yield return(null); if (opened) { chest.Open(); chest.GetComponent <PurchaseInteraction>().SetAvailable(false); } chest.transform.position = transform.position.GetVector3(); }
private void action() { if (playerInputs.action) { // If near ladder and have enough gold, win. if (Vector2.Distance(GameObject.FindGameObjectWithTag("Ladder").transform.position, transform.position) <= searchRadius) { if (gold >= 100) { win(); } else { soundController.playErrorSound(); } return; } // Otherwise if near closed chest, open it. ChestBehavior chestBehavior = findNearbyClosedChest(); if (chestBehavior != null) { chestBehavior.Open(); return; } // Otherwise, if near kindling, pick it up. KindlingBehavior kindlingBehavior = findNearbyUnlitKindling(); if (kindlingBehavior != null) { // if (kindling == 0) { // torchLightFg.intensity = startingFgIntensity; // torchLightBg.intensity = startingBgIntensity; // globalLight.intensity = startingGIntensity; // material.color = startingColor; // } soundController.playPickupSound(); kindling++; kindlingText.text = kindling.ToString(); Destroy(kindlingBehavior.gameObject); return; } // Otherwise, if have kindling, drop it. if (kindling > 0) { dropKindling(); } } }
private void ChestBehavior_ItemDrop(On.RoR2.ChestBehavior.orig_ItemDrop orig, ChestBehavior self) { if (!NetworkServer.active) { Debug.LogWarning("[Server] function 'System.Void RoR2.ChestBehavior::ItemDrop()' called on client"); return; } var chestName = self.gameObject.name.ToLower(); if (chestName.StartsWith("lunarchest")) { orig(self); return; } FieldInfo dropPickup = self.GetType().GetField("dropPickup", BindingFlags.Instance | BindingFlags.NonPublic); var dropPickupValue = (PickupIndex)dropPickup.GetValue(self); if (dropPickupValue != PickupIndex.none) { if (!DropItems && (chestName.StartsWith("chest") || chestName.StartsWith("goldchest"))) { var pickupController = gameObject.GetComponent <GenericPickupController>(); if (pickupController == null) { pickupController = this.gameObject.AddComponent <GenericPickupController>(); } var characterBody = LocalUserManager.GetFirstLocalUser().cachedBody; characterBody.inventory.GiveItem(dropPickupValue.itemIndex, 1); pickupController.GetType().GetMethod("SendPickupMessage", BindingFlags.Static | BindingFlags.NonPublic) .Invoke(pickupController, new object[] { characterBody.inventory.GetComponent <CharacterMaster>(), dropPickupValue }); dropPickup.SetValue(self, PickupIndex.none); return; } orig(self); return; } // Steal opening sound from timed chest without changing to a problematic state EntityStateMachine component = self.GetComponent <EntityStateMachine>(); if (component) { component.SetNextState(EntityState.Instantiate(new SerializableEntityStateType(typeof(EntityStates.TimedChest.Opening)))); } // Generate list of 3 random item indexes var randomItemList = new List <PickupIndex>(); randomItemList.Add(RollVoteItem(self)); randomItemList.Add(RollVoteItem(self)); randomItemList.Add(RollVoteItem(self)); // Create a new vote, by passing valid poll options and vote duration var vote = new Vote(new List <string>(new string[] { "1", "2", "3" }), VoteDuration); vote.StartEventHandler += (_, __) => { var characterBody = LocalUserManager.GetFirstLocalUser().cachedBody; var notificationQueue = characterBody.gameObject.GetComponent <VoteNotificationQueue>(); if (notificationQueue == null) { notificationQueue = characterBody.gameObject.AddComponent <VoteNotificationQueue>(); } notificationQueue.OnVoteStart(randomItemList, VoteDuration); // Notify the event in chat SendChatMessage( string.Format("Vote for the next item! (1) {0} | (2) {1} | (3) {2}", Language.GetString(randomItemList[0].GetPickupNameToken()), Language.GetString(randomItemList[1].GetPickupNameToken()), Language.GetString(randomItemList[2].GetPickupNameToken()) ) ); }; vote.EndEventHandler += (_, e) => { var votedItemName = Language.GetString(randomItemList[e.VotedIndex].GetPickupNameToken()); float totalVotesCount = 1f; int winnerCount = 1; if (e.VoteCounter.Keys.Count > 0) { totalVotesCount = e.VoteCounter.Sum(el => el.Value); winnerCount = e.VoteCounter[(e.VotedIndex + 1).ToString()]; } SendChatMessage( string.Format( "({0}) {1} won! ({2})", e.VotedIndex + 1, votedItemName, (winnerCount / totalVotesCount).ToString("P1", CultureInfo.InvariantCulture).Replace(" %", "%") ) ); var votedItem = randomItemList[e.VotedIndex]; dropPickup.SetValue(self, votedItem); self.Open(); }; VoteManager.AddVote(vote); }