public ChestData(ChestBehavior chest) { var stateMachine = chest.GetComponent <EntityStateMachine>(); var purchaseInteraction = chest.GetComponent <PurchaseInteraction>(); name = chest.name.Replace("(Clone)", ""); transform = new SerializableTransform(chest.transform); index = chest.GetFieldValue <PickupIndex>("dropPickup").value; isEquipment = index >= (int)ItemIndex.Count; opened = stateMachine.state.GetType().IsEquivalentTo(typeof(EntityStates.Barrel.Opened)) ? true : false; cost = purchaseInteraction.cost; costType = (int)purchaseInteraction.costType; }
public static void Track_ChestBehavior(On.RoR2.ChestBehavior.orig_Awake orig, ChestBehavior self) { orig(self); InstanceTracker.Add(self); if (!self.GetComponent <InstanceTrackerRemover>()) { self.gameObject.AddComponent <InstanceTrackerRemover>().chestBehavior = self; } }
IEnumerator WaitForStart(ChestBehavior chest) { yield return(null); if (opened) { chest.Open(); chest.GetComponent <PurchaseInteraction>().SetAvailable(false); } chest.transform.position = transform.position.GetVector3(); }
private void ChestBehavior_ItemDrop(On.RoR2.ChestBehavior.orig_ItemDrop orig, ChestBehavior self) { if (NetworkServer.active && self.dropPickup != PickupIndex.none) { var component = self.GetComponent <MysticsItemsOmarHackToolHackingManager>(); if (component) { component.PlayFX(3f); } } orig(self); }
private void ChestBehavior_Open(On.RoR2.ChestBehavior.orig_Open orig, ChestBehavior self) { if (NetworkServer.active) { if (isCurrentStageBazaar()) { bool isCreatingDroplet = false; if (!ModConfig.isShareSuiteLoaded || !ModConfig.isShareSuiteActive()) { isCreatingDroplet = true; } else { if (ModConfig.ShareSuiteItemSharingEnabled.Value) { isCreatingDroplet = true; } } if (isCreatingDroplet) { List <BazaarItem> bazaarItems = bazaar.GetBazaarItems(); for (int i = 0; i < bazaar.GetBazaarItemAmount(); i++) { if (bazaarItems[i].chestBehavior.Equals(self)) { PickupDropletController.CreatePickupDroplet(bazaarItems[i].pickupIndex, self.transform.position + Vector3.up * 1.5f, Vector3.up * 20f + self.transform.forward * 2f); bazaarItems[i].purchaseCount++; if (bazaar.IsChestStillAvailable(bazaarItems[i])) { self.GetComponent <PurchaseInteraction>().SetAvailable(true); } return; } } } } ; } orig(self); }
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); }