void DropRewards(On.RoR2.BossGroup.orig_DropRewards orig, BossGroup bossGroup) { System.Reflection.FieldInfo info = typeof(BossGroup).GetField("bossDrops", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); ICollection collection = info.GetValue(bossGroup) as ICollection; List <PickupIndex> bossDrops = new List <PickupIndex>(); List <PickupIndex> bossDropsAdjusted = new List <PickupIndex>(); foreach (object bossDrop in collection) { PickupIndex pickupIndex = (PickupIndex)bossDrop; bossDrops.Add(pickupIndex); if (PickupCatalog.GetPickupDef(pickupIndex).itemIndex != ItemIndex.None && playerItems.Contains(pickupIndex)) { bossDropsAdjusted.Add(pickupIndex); } } int normalCount = Run.instance.availableTier2DropList.Count; if (bossGroup.forceTier3Reward) { normalCount = Run.instance.availableTier3DropList.Count; } if (normalCount != 0 || bossDropsAdjusted.Count != 0) { float bossDropChanceOld = bossGroup.bossDropChance; if (normalCount == 0) { DropList.SetDropLists(new List <PickupIndex>(), new List <PickupIndex>(), new List <PickupIndex>(), new List <PickupIndex>()); bossGroup.bossDropChance = 1; } else if (bossDropsAdjusted.Count == 0) { bossGroup.bossDropChance = 0; } info.SetValue(bossGroup, bossDropsAdjusted); orig(bossGroup); info.SetValue(bossGroup, bossDrops); bossGroup.bossDropChance = bossDropChanceOld; if (normalCount == 0) { DropList.RevertDropLists(); } } }
private static void SetPickupPickerControllerAspectOptions(PickupPickerController controller, PickupDef pickupDef) { List <PickupPickerController.Option> options = new List <PickupPickerController.Option>(); if (pickupDef.itemIndex != ItemIndex.None) { foreach (ItemIndex itemIndex in Catalog.aspectItemIndexes) { bool valid = !Catalog.disabledItemIndexes.Contains(itemIndex); bool available = !Run.instance.IsItemExpansionLocked(itemIndex); if (valid && available) { PickupIndex pickupIndex = PickupCatalog.FindPickupIndex(itemIndex); options.Add(new PickupPickerController.Option { available = true, pickupIndex = pickupIndex }); } } } else if (pickupDef.equipmentIndex != EquipmentIndex.None) { foreach (EquipmentIndex equipIndex in Catalog.aspectEquipIndexes) { bool available = !Run.instance.IsEquipmentExpansionLocked(equipIndex); if (available) { PickupIndex pickupIndex = PickupCatalog.FindPickupIndex(equipIndex); options.Add(new PickupPickerController.Option { available = true, pickupIndex = pickupIndex }); } } } else { options.Add(new PickupPickerController.Option { available = true, pickupIndex = pickupDef.pickupIndex }); } controller.SetOptionsServer(options.ToArray()); }
private void DropRewards() { int participatingPlayerCount = Run.instance.participatingPlayerCount; if (participatingPlayerCount != 0 && symbolTransform) { List <PickupIndex> list = new List <PickupIndex>(); if (MoreShrines.itemRarityBasedOnSpeed.Value) { list = weightedTierPickSpeed(); } else { list = weightedTierPick(); } PickupIndex pickupIndex = MoreShrines.EvaRng.NextElementUniform <PickupIndex>(list); int num = 1; if (MoreShrines.dropItemForEveryPlayer.Value) { if (!BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey("com.funkfrog_sipondo.sharesuite") && !BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey("com.funkfrog_sipondo.sharesuite-r2")) { num *= participatingPlayerCount; } } num += MoreShrines.extraItemCount.Value; float angle = 360f / (float)num; Vector3 vector = Quaternion.AngleAxis((float)UnityEngine.Random.Range(0, 360), Vector3.up) * (Vector3.up * 40f + Vector3.forward * 5f); Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.up); int i = 0; while (i < num) { PickupDropletController.CreatePickupDroplet(pickupIndex, symbolTransform.position, vector); i++; vector = rotation * vector; } } }
private PickupTier PickupIndexToPickupTier(PickupIndex pickupIndex) { var isEquipment = PickupCatalog.GetPickupDef(pickupIndex).equipmentIndex == EquipmentIndex.None ? false : true; if (!isEquipment) { var tier = ItemCatalog.GetItemDef((PickupCatalog.GetPickupDef(pickupIndex).itemIndex)).tier; switch (tier) { case ItemTier.Tier1: return(PickupTier.Tier1); case ItemTier.Tier2: return(PickupTier.Tier2); case ItemTier.Tier3: return(PickupTier.Tier3); case ItemTier.Boss: return(PickupTier.Boss); case ItemTier.Lunar: return(PickupTier.Lunar); default: return(PickupTier.None); } } else { var isLunar = EquipmentCatalog.GetEquipmentDef((PickupCatalog.GetPickupDef(pickupIndex).equipmentIndex)).isLunar; if (isLunar) { return(PickupTier.LunarEquipment); } else { //if (EquipmentCatalog.GetEquipmentDef((PickupCatalog.GetPickupDef(pickupIndex).equipmentIndex)).isBoss) // Debug.LogWarning("WAS A BOSS EQUIP!!? " + PickupCatalog.GetPickupDef(pickupIndex).nameToken); return(PickupTier.Equipment); } } }
private void CombatSquad_onMemberDefeatedServer(CharacterMaster arg1, DamageReport damageReport) { if (!damageReport.victimMaster) { return; } if (damageReport.attackerTeamIndex == damageReport.victimTeamIndex && damageReport.victimMaster.minionOwnership.ownerMaster) { return; } if (UnityEngine.Random.Range(1, 100) < 15) { PickupIndex pickupIndex = PickupCatalog.itemIndexToPickupIndex[(int)wispItem.itemIndex]; if (pickupIndex != PickupIndex.none) { PickupDropletController.CreatePickupDroplet(pickupIndex, damageReport.victimBody.corePosition, Vector3.up * 20f); } } }
private static PickupIndex?GetRandomItemOfTier(ItemTier tier, PickupIndex orDefault) { switch (tier) { case ItemTier.Tier1: return(PickRandomOf(BlackList.AvailableTier1DropList)); case ItemTier.Tier2: return(PickRandomOf(BlackList.AvailableTier2DropList)); case ItemTier.Tier3: return(PickRandomOf(BlackList.AvailableTier3DropList)); case ItemTier.Lunar: if (ShareSuite.LunarItemsRandomized.Value) { return(PickRandomOf(BlackList.AvailableLunarDropList)); } break; case ItemTier.Boss: if (ShareSuite.BossItemsRandomized.Value) { return(PickRandomOf(BlackList.AvailableBossDropList)); } break; default: break; } var pickupDef = PickupCatalog.GetPickupDef(orDefault); if (BlackList.HasItem(pickupDef.itemIndex)) { return(null); } else { return(orDefault); } }
public static bool IsValidItemPickup(PickupIndex pickup) { var pickupdef = PickupCatalog.GetPickupDef(pickup); if (pickupdef.itemIndex != ItemIndex.None) { var itemdef = ItemCatalog.GetItemDef(pickupdef.itemIndex); switch (itemdef.tier) { case ItemTier.Tier1: return(ShareSuite.WhiteItemsShared.Value); case ItemTier.Tier2: return(ShareSuite.GreenItemsShared.Value); case ItemTier.Tier3: return(ShareSuite.RedItemsShared.Value); case ItemTier.Lunar: return(ShareSuite.LunarItemsShared.Value); case ItemTier.Boss: return(ShareSuite.BossItemsShared.Value); case ItemTier.NoTier: break; default: return(false); } } if (pickupdef.equipmentIndex != EquipmentIndex.None) { // var equipdef = EquipmentCatalog.GetEquipmentDef(pickupdef.equipmentIndex); // Optional further checks ... return(false); } return(false); }
public static string EquipmentMessage(PickupIndex pickupIdx) { EquipmentDef equipDef = EquipmentCatalog.GetEquipmentDef(pickupIdx.equipmentIndex); string displayName = $"{Language.GetString(pickupIdx.GetPickupNameToken())}"; string description; string tierColor = $"#{ColorUtility.ToHtmlStringRGB(pickupIdx.GetPickupColor())}"; string tierColorDark = $"#{ColorUtility.ToHtmlStringRGB(pickupIdx.GetPickupColorDark())}"; if (equipDef.descriptionToken != null && UnosMods.InfoOnPing.InfoOnPing.UseLongDescription.Value) // If config is set to show long description and object has valid long description { description = Language.GetString(equipDef.descriptionToken); } else { description = Language.GetString(equipDef.pickupToken) ?? Language.GetString(equipDef.descriptionToken); // Null checking because why not? } string message = $"<color={tierColor}>{displayName}: <color={tierColorDark}>{description}</color>"; return(message); }
public static void CreateTerminals(On.RoR2.MultiShopController.orig_CreateTerminals orig, MultiShopController self, ItemTierShopConfig itemTierConfig) { // Boss Items and Equipment can not be part of multi shops by default, so needs a special case List <PickupIndex> otherItemsList = new List <PickupIndex>(); if (itemTierConfig.itemTier == ItemTier.Boss) { var itemIndexList = R2API.ItemDropAPI.GetDefaultDropList(ItemTier.Boss); foreach (var itemIndex in itemIndexList) { otherItemsList.Add(new PickupIndex(itemIndex)); } } else if (itemTierConfig.itemTier == ItemTier.NoTier && itemTierConfig.isEquipment) { var itemIndexList = R2API.ItemDropAPI.GetDefaultEquipmentDropList(); foreach (var itemIndex in itemIndexList) { otherItemsList.Add(new PickupIndex(itemIndex)); } } if (otherItemsList.Count > 0) { self.SetFieldValue("terminalGameObjects", new GameObject[self.terminalPositions.Length]); for (int i = 0; i < self.terminalPositions.Length; i++) { PickupIndex newPickupIndex = PickupIndex.none; Xoroshiro128Plus treasureRng = Run.instance.treasureRng; newPickupIndex = treasureRng.NextElementUniform <PickupIndex>(otherItemsList); bool newHidden = Run.instance.treasureRng.nextNormalizedFloat < 0.2f; GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(self.terminalPrefab, self.terminalPositions[i].position, self.terminalPositions[i].rotation); self.GetFieldValue <GameObject[]>("terminalGameObjects")[i] = gameObject; gameObject.GetComponent <ShopTerminalBehavior>().SetPickupIndex(newPickupIndex, newHidden); NetworkServer.Spawn(gameObject); } return; } orig(self); }
private void RollSpawnChance(CharacterBody victimBody, CharacterBody attackerBody) { // Roll percent chance has a base value of 7% (configurable), multiplied by 1 + .3 per player above 1. float percentChance = baseDropChance * (1f + ((NetworkUser.readOnlyInstancesList.Count - 1f) * playerScaling)); if (reverseScaling) { percentChance /= Run.instance.difficultyCoefficient * reverseScalingRate; } WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(5); // This is done this way because elite bosses are possible, and should have the option to drop reds than their standard boss counterparts. if (victimBody.isElite) { AddDropWeights(weightedSelection, eliteDropWeights); } if (victimBody.isBoss) { AddDropWeights(weightedSelection, bossDropWeights); } // If the enemy in question is dead, then chances shoulder be the default for chests + some equipment item drop chances. else if (!victimBody.isElite) { AddDropWeights(weightedSelection, normalDropWeights); } // Item to drop is generated before the item pick up is generated for a future update. List <PickupIndex> list = weightedSelection.Evaluate(Run.instance.spawnRng.nextNormalizedFloat); PickupIndex pickupIndex = list[Run.instance.spawnRng.RangeInt(0, list.Count)]; CharacterMaster master = attackerBody.master; float luck = (master && cloverRerollDrops) ? master.luck : 0f; if (Util.CheckRoll(percentChance, luck, null)) { // Drop an item. PickupDropletController.CreatePickupDroplet( pickupIndex, victimBody.transform.position, new Vector3(UnityEngine.Random.Range(-5.0f, 5.0f), 20f, UnityEngine.Random.Range(-5.0f, 5.0f))); } }
private static void CommandGroupInterceptHook(On.RoR2.Artifacts.CommandArtifactManager.orig_OnDropletHitGroundServer orig, ref GenericPickupController.CreatePickupInfo createPickupInfo, ref bool shouldSpawn) { if (!shouldSpawn) { return; } PickupIndex pickupIndex = createPickupInfo.pickupIndex; if (pickupIndex != PickupIndex.none) { PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex); if (pickupDef != null) { if (pickupDef.itemIndex != ItemIndex.None && Catalog.aspectItemIndexes.Contains(pickupDef.itemIndex)) { if (Configuration.AspectWorldUnique.Value && Configuration.AspectCommandGroupItems.Value) { AspectCommandDroplet(pickupDef, createPickupInfo.position, createPickupInfo.rotation, ref shouldSpawn); } } if (pickupDef.equipmentIndex != EquipmentIndex.None && Catalog.aspectEquipIndexes.Contains(pickupDef.equipmentIndex)) { if (Configuration.AspectCommandGroupEquip.Value) { AspectCommandDroplet(pickupDef, createPickupInfo.position, createPickupInfo.rotation, ref shouldSpawn); } } } } if (!shouldSpawn) { return; } orig(ref createPickupInfo, ref shouldSpawn); }
//Chance Shrine private static void ShrineChanceBehavior_AddShrineStack(On.RoR2.ShrineChanceBehavior.orig_AddShrineStack orig, ShrineChanceBehavior self, Interactor activator) { orig(self, activator); var characterBody = activator.GetComponent <CharacterBody>(); if (characterBody) { var inv = characterBody.inventory; if (inv) { if (inv.GetItemCount(ExtraShrineRollItemIndex) > 0 && Util.CheckRoll(ItemProcChance * inv.GetItemCount(ExtraShrineRollItemIndex), characterBody.master)) { Xoroshiro128Plus rng = new Xoroshiro128Plus(Run.instance.treasureRng.nextUlong); PickupIndex none = PickupIndex.none; PickupIndex value = rng.NextElementUniform <PickupIndex>(Run.instance.availableTier1DropList); PickupIndex value2 = rng.NextElementUniform <PickupIndex>(Run.instance.availableTier2DropList); PickupIndex value3 = rng.NextElementUniform <PickupIndex>(Run.instance.availableTier3DropList); PickupIndex value4 = rng.NextElementUniform <PickupIndex>(Run.instance.availableEquipmentDropList); WeightedSelection <PickupIndex> weightedSelection = new WeightedSelection <PickupIndex>(8); weightedSelection.AddChoice(none, self.failureWeight); weightedSelection.AddChoice(value, self.tier1Weight); weightedSelection.AddChoice(value2, self.tier2Weight); weightedSelection.AddChoice(value3, self.tier3Weight); weightedSelection.AddChoice(value4, self.equipmentWeight); PickupIndex pickupIndex = weightedSelection.Evaluate(rng.nextNormalizedFloat); bool flag = pickupIndex == PickupIndex.none; if (flag) { Chat.AddMessage("<color=\"green\">Lucky Default Sphere <style=cShrine>has rolled the shrine an additional time for:</style><color=\"white\"> Nothing."); } else { Chat.AddMessage($"<color=\"green\">Lucky Default Sphere <style=cShrine>has rolled the shrine an additional time for:</style><color=\"white\"> {Language.GetString(PickupCatalog.GetPickupDef(pickupIndex).nameToken)}"); PickupDropletController.CreatePickupDroplet(pickupIndex, self.dropletOrigin.position, self.dropletOrigin.forward * 20f); } } } } }
private void GiveRandomRed(On.RoR2.CharacterBody.orig_OnInventoryChanged orig, CharacterBody self) //ripped from harbcrate, i did credit though. { orig(self); var amount = GetCount(self); if (amount > 1) { self.inventory.RemoveItem(catalogIndex); PickupIndex loot = Run.instance.treasureRng.NextElementUniform(Run.instance.availableTier3DropList); if (self.isPlayerControlled) { PickupDropletController.CreatePickupDroplet(loot, self.corePosition, Vector3.up * 5); } else { PickupDef def = PickupCatalog.GetPickupDef(loot); self.inventory.GiveItem(def.itemIndex); var lootCount = self.inventory.GetItemCount(def.itemIndex); Chat.AddPickupMessage(self, def.nameToken, ColorCatalog.GetColor(ItemCatalog.GetItemDef(def.itemIndex).colorIndex), (uint)lootCount); } } }
// Making sure nothing custom items related get saved to the UserProfile so if the user decide to remove the custom items he doesn't get a corrupted profile // TODO: Somehow find a way to make all of this UserProfile securing cleaner. By having a custom serialized file only for custom items etc // Disable DiscoveredPickups field in UserProfile for custom items private static void SaveFieldAttributeOnSetupPickupsSet(On.RoR2.UserProfile.SaveFieldAttribute.orig_SetupPickupsSet orig, UserProfile.SaveFieldAttribute self, FieldInfo fieldInfo) { self.getter = delegate(UserProfile userProfile) { bool[] pickupsSet = (bool[])fieldInfo.GetValue(userProfile); var result = new StringBuilder(""); for (int i = 0; i < OriginalItemCount + OriginalEquipmentCount + 1; i++) { var pickupIndex = PickupIndex.allPickups.ToList()[i]; if (pickupsSet[pickupIndex.value] && !IsCustomItemOrEquipment(pickupIndex)) { result.Append(pickupIndex.ToString()); result.Append(" "); } } return(result.ToString()); }; self.setter = delegate(UserProfile userProfile, string valueString) { bool[] array = (bool[])fieldInfo.GetValue(userProfile); Array.Clear(array, 0, 0); string[] array2 = valueString.Split(' '); foreach (var name in array2) { PickupIndex pickupIndex = PickupIndex.Find(name); if (pickupIndex.isValid && !IsCustomItemOrEquipment(pickupIndex)) { array[pickupIndex.value] = true; } } }; self.copier = delegate(UserProfile srcProfile, UserProfile destProfile) { Array sourceArray = (bool[])fieldInfo.GetValue(srcProfile); bool[] array = (bool[])fieldInfo.GetValue(destProfile); Array.Copy(sourceArray, array, array.Length); }; }
public void Start() { holdoutZoneController = GetComponent <HoldoutZoneController>(); if (NetworkServer.active) { ShouldBeActive = false; rng = new Xoroshiro128Plus(Run.instance.treasureRng.nextUlong); if (dropTable) { dropPickup = dropTable.GenerateDrop(rng); } } else { new RequestZoneShouldBeActive(gameObject.GetComponent <NetworkIdentity>().netId).Send(NetworkDestination.Server); } holdoutZoneController.onCharged = new HoldoutZoneController.HoldoutZoneControllerChargedUnityEvent(); holdoutZoneController.onCharged.AddListener(zone => Unearth()); instance = this; }
private static PickupIndex GetRandomItemOfTier(ItemTier tier, PickupIndex orDefault) { switch (tier) { case ItemTier.Tier1: return(PickRandomOf(Run.instance.availableTier1DropList)); case ItemTier.Tier2: return(PickRandomOf(Run.instance.availableTier2DropList)); case ItemTier.Tier3: return(PickRandomOf(Run.instance.availableTier3DropList)); case ItemTier.Lunar: return(PickRandomOf(Run.instance.availableLunarDropList)); case ItemTier.Boss: return(orDefault); // no boss item list, and also probably better anyway default: return(orDefault); } }
private void BuildNotification(PickupIndex pickupIndex, RoR2.UI.PingIndicator pingIndicator) { LocalUser localUser = LocalUserManager.GetFirstLocalUser(); if (localUser.currentNetworkUser.userName == Util.GetBestMasterName(pingIndicator.pingOwner.GetComponent <CharacterMaster>())) { if (localUser.userProfile.HasDiscoveredPickup(pickupIndex)) { PickupDef pickup = PickupCatalog.GetPickupDef(pickupIndex); ItemDef item = ItemCatalog.GetItemDef(pickup.itemIndex); EquipmentDef equip = EquipmentCatalog.GetEquipmentDef(pickup.equipmentIndex); ArtifactDef artifact = ArtifactCatalog.GetArtifactDef(pickup.artifactIndex); GenericNotification notification = Object .Instantiate(Resources.Load <GameObject>("Prefabs/NotificationPanel2")) .GetComponent <GenericNotification>(); if (item != null) { notification.SetItem(item); } else if (equip != null) { notification.SetEquipment(equip); } else if (artifact != null) { notification.SetArtifact(artifact); } notification.transform.SetParent(RoR2Application.instance.mainCanvas.transform, false); notification.transform.position = new Vector3(notification.transform.position.x + 2, 95, 0); } } }
private void ArenaMissionController_EndRound(On.RoR2.ArenaMissionController.orig_EndRound orig, ArenaMissionController self) { GameObject cachedRewardPosition = self.rewardSpawnPosition; self.rewardSpawnPosition = null; int participatingPlayerCount = Run.instance.participatingPlayerCount; if (participatingPlayerCount != 0 && self.rewardSpawnPosition) { List <PickupIndex> list = Run.instance.availableTier1DropList; if (self.currentRound > 4) { list = Run.instance.availableTier2DropList; } if (self.currentRound == self.totalRoundsMax) { list = Run.instance.availableTier3DropList; } if (list.Count > 0) { PickupIndex pickupIndex = self.rng.NextElementUniform <PickupIndex>(list); int num = participatingPlayerCount; float angle = 360f / (float)num; Vector3 vector = Quaternion.AngleAxis((float)UnityEngine.Random.Range(0, 360), Vector3.up) * (Vector3.up * 40f + Vector3.forward * 5f); Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.up); int k = 0; while (k < num) { PickupDropletController.CreatePickupDroplet(pickupIndex, self.rewardSpawnPosition.transform.position, vector); k++; vector = rotation * vector; } } } orig(self); self.rewardSpawnPosition = cachedRewardPosition; }
/// <summary> /// Lifted straight from <seealso cref="RoR2.Inventory.GiveRandomItems"/>, which seems to currenlty have a bug with /// only giving tier 1 void items. At some point i'll remove this and point directly at the internal give random items method /// </summary> /// <param name="count">Number of items to give</param> /// <param name="lunarEnabled">When enabled will add lunar items to the list to picked from</param> /// <param name="voidEnabled">When enabled will add void items to the list picked from</param> private static void GiveRandomItems(Inventory inventory, int count, bool lunarEnabled, bool voidEnabled) { if (count > 0) { WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(); weightedSelection.AddChoice(Run.instance.availableTier1DropList, 100f); weightedSelection.AddChoice(Run.instance.availableTier2DropList, 60f); weightedSelection.AddChoice(Run.instance.availableTier3DropList, 4f); if (lunarEnabled) { weightedSelection.AddChoice(Run.instance.availableLunarItemDropList, 4f); } if (voidEnabled) { weightedSelection.AddChoice(Run.instance.availableVoidTier1DropList, 4f); weightedSelection.AddChoice(Run.instance.availableVoidTier2DropList, 2.39999986f); weightedSelection.AddChoice(Run.instance.availableVoidTier3DropList, 0.16f); } for (int i = 0; i < count; i++) { try { List <PickupIndex> tierDropList = weightedSelection.Evaluate(UnityEngine.Random.value); PickupIndex itemPickupIndex = tierDropList.ElementAtOrDefault(UnityEngine.Random.Range(0, tierDropList.Count)); ItemIndex itemIndex = PickupCatalog.GetPickupDef(itemPickupIndex)?.itemIndex ?? ItemIndex.None; inventory.GiveItem(itemIndex); } catch (Exception ex) { Debug.LogException(ex); Logger.LogError(ex); Logger.LogMessage("Exception occured giving player an item"); } } } }
public static void DropItem(Transform charTransform, Inventory inventory, PickupIndex pickupIndex) { if (pickupIndex.equipmentIndex != EquipmentIndex.None) { if (inventory.GetEquipmentIndex() != pickupIndex.equipmentIndex) { return; } inventory.SetEquipmentIndex(EquipmentIndex.None); } else { if (inventory.GetItemCount(pickupIndex.itemIndex) <= 0) { return; } inventory.RemoveItem(pickupIndex.itemIndex, 1); } PickupDropletController.CreatePickupDroplet(pickupIndex, charTransform.position, Vector3.up * 20f + charTransform.forward * 10f); }
private string constructItemsLostString(List <ItemCount> difference) { string result = "<color=#8296ae>You gave up "; for (int i = 0; i < difference.Count; i++) { ItemCount diffItem = difference[i]; PickupIndex pickupIndex = new PickupIndex(diffItem.itemIndex); string itemName = Language.GetString(ItemCatalog.GetItemDef(diffItem.itemIndex).nameToken); string hexColor = "#" + ColorUtility.ToHtmlStringRGB(pickupIndex.GetPickupColor()); result += "x" + diffItem.count + " " + "<color=" + hexColor + ">" + itemName + "</color>"; if (i + 1 < difference.Count) { result += ", "; } else { result += "</color>"; } } return(result); }
// Token: 0x06002C78 RID: 11384 RVA: 0x000BBA48 File Offset: 0x000B9C48 private void GrantPickupServer(PickupIndex pickupIndex, int countToGrant) { PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex); if (pickupDef == null) { return; } ItemIndex itemIndex = pickupDef.itemIndex; if (ItemCatalog.GetItemDef(itemIndex) == null) { return; } base.characterBody.inventory.GiveItem(itemIndex, countToGrant); Chat.SendBroadcastChat(new Chat.PlayerPickupChatMessage { subjectAsCharacterBody = base.characterBody, baseToken = "MONSTER_PICKUP", pickupToken = pickupDef.nameToken, pickupColor = pickupDef.baseColor, pickupQuantity = (uint)this.itemsToGrant }); }
public static bool Prefix(ChestBehavior __instance) { if (!NetworkServer.active) { return(false); } PickupIndex dropPickup = Traverse.Create(__instance).Field("dropPickup").GetValue <PickupIndex>(); if (dropPickup == PickupIndex.none) { return(false); } for (int i = 0; i < configDropCount.Value; i++) { dropPickup = Traverse.Create(__instance).Field("dropPickup").GetValue <PickupIndex>(); PickupDropletController.CreatePickupDroplet(dropPickup, __instance.dropTransform.position + Vector3.up * 1.5f, Vector3.up * __instance.dropUpVelocityStrength + __instance.dropTransform.forward * __instance.dropForwardVelocityStrength); if (configRandom.Value) { __instance.RollItem(); } } Traverse.Create(__instance).Field("dropPickup").SetValue(PickupIndex.none); return(false); }
public static int GetPickupCount(PickupIndex pickupIndex, int userID = 0) { Inventory inv = GetLocalBody(userID)?.inventory; return(GetPickupCount(inv, pickupIndex)); }
public static int GetPickupCount(this CharacterBody body, PickupIndex pickupIndex) { Inventory inv = body?.inventory; return(inv.GetPickupCount(pickupIndex)); }
public void Awake() { noRefresh = Config.Wrap("Shrine of Chance", "NoCooldown", "When enabled, this gets rid of the 2 second cooldown between purchases. Default = false", false); maximumPurchase = Config.Wrap("Shrine of Chance", "MaxPurchase", "The maximum number of purchases you can make before the shrine is disabled. Default = 2", 2); chatMessages = Config.Wrap("Chat", "ChatMessages", "When enabled, you will get a message in the chat letting you know you have increased odds. Default = true", true); //init failure count int failureCount = 0; On.RoR2.ShrineChanceBehavior.AddShrineStack += (orig, self, activator) => { //set maximum purchase count self.maxPurchaseCount = maximumPurchase.Value; /* * everything is default the first 2 tries. * if you fail 2 times in a row, on the third try, the weights change to be more favorable for a tier 2 item or equipment * if you fail 5 times in a row, on the sixth try, the weights change to be more favorable for a tier 3 item * if you fail 8 times in a row, on the ninth try, you are guaranteed a tier 3 item */ if (failureCount >= 0 && failureCount < 2) { self.tier1Weight = 8; self.tier2Weight = 2; self.tier3Weight = 0.2f; self.equipmentWeight = 2; self.failureWeight = 10.1f; } else if (failureCount >= 2 && failureCount < 5) { if (chatMessages.Value) { Chat.AddMessage("Increased chances for tier 2 item or equipment"); } self.tier1Weight = -100; self.tier2Weight = 4; self.tier3Weight = 0.2f; self.equipmentWeight = 2; self.failureWeight = 10.1f; } else if (failureCount >= 5 && failureCount < 8) { if (chatMessages.Value) { Chat.AddMessage("Increased chances for tier 3 item"); } self.tier1Weight = -100; self.tier2Weight = 2; self.tier3Weight = 4; self.equipmentWeight = -100; self.failureWeight = 10.1f; } else if (failureCount >= 8) { if (chatMessages.Value) { Chat.AddMessage("Guaranteed Legendary. You've earned it."); } self.tier1Weight = -100; self.tier2Weight = -100; self.tier3Weight = 1000; self.equipmentWeight = -100; self.failureWeight = -100; } if (!NetworkServer.active) { Debug.LogWarning("[Server] function 'System.Void RoR2.ShrineChanceBehavior::AddShrineStack(RoR2.Interactor)' called on client"); return; } Xoroshiro128Plus rng = self.GetFieldValue <Xoroshiro128Plus>("rng"); PickupIndex none = PickupIndex.none; PickupIndex value = rng.NextElementUniform <PickupIndex>(Run.instance.availableTier1DropList); PickupIndex value2 = rng.NextElementUniform <PickupIndex>(Run.instance.availableTier2DropList); PickupIndex value3 = rng.NextElementUniform <PickupIndex>(Run.instance.availableTier3DropList); PickupIndex value4 = rng.NextElementUniform <PickupIndex>(Run.instance.availableEquipmentDropList); WeightedSelection <PickupIndex> weightedSelection = new WeightedSelection <PickupIndex>(8); weightedSelection.AddChoice(none, self.failureWeight); weightedSelection.AddChoice(value, self.tier1Weight); weightedSelection.AddChoice(value2, self.tier2Weight); weightedSelection.AddChoice(value3, self.tier3Weight); weightedSelection.AddChoice(value4, self.equipmentWeight); PickupIndex pickupIndex = weightedSelection.Evaluate(rng.nextNormalizedFloat); bool flag = pickupIndex == PickupIndex.none; if (flag) { Chat.SubjectFormatChatMessage formatChatMessage = new Chat.SubjectFormatChatMessage(); formatChatMessage.subjectAsCharacterBody = activator.GetComponent <CharacterBody>(); formatChatMessage.baseToken = "SHRINE_CHANCE_FAIL_MESSAGE"; Chat.SendBroadcastChat((Chat.ChatMessageBase)formatChatMessage); //on failure, increment failure count failureCount++; } else { self.SetFieldValue <int>("successfulPurchaseCount", self.GetFieldValue <int>("successfulPurchaseCount") + 1); //this.successfulPurchaseCount++; PickupDropletController.CreatePickupDroplet(pickupIndex, self.dropletOrigin.position, self.dropletOrigin.forward * 20f); Chat.SubjectFormatChatMessage formatChatMessage = new Chat.SubjectFormatChatMessage(); formatChatMessage.subjectAsCharacterBody = activator.GetComponent <CharacterBody>(); formatChatMessage.baseToken = "SHRINE_CHANCE_SUCCESS_MESSAGE"; Chat.SendBroadcastChat((Chat.ChatMessageBase)formatChatMessage); //on success, reset failure count to 0 failureCount = 0; } //Action<bool, Interactor> action = ShrineChanceBehavior.onShrineChancePurchaseGlobal; Action <bool, Interactor> action = typeof(ShrineChanceBehavior).GetFieldValue <Action <bool, Interactor> >("onShrineChancePurchaseGlobal"); if (action != null) { action(flag, activator); } self.SetFieldValue <bool>("waitingForRefresh", true); //this.waitingForRefresh = true; if (noRefresh.Value) { self.SetFieldValue <float>("refreshTimer", 0f); } else { self.SetFieldValue <float>("refreshTimer", 2f); } //this.refreshTimer = 2f; EffectManager.instance.SpawnEffect(Resources.Load <GameObject>("Prefabs/Effects/ShrineUseEffect"), new EffectData { origin = base.transform.position, rotation = Quaternion.identity, scale = 1f, color = self.shrineColor }, true); if (self.GetFieldValue <int>("successfulPurchaseCount") >= self.maxPurchaseCount) { self.symbolTransform.gameObject.SetActive(false); } }; }
// Token: 0x0600278E RID: 10126 RVA: 0x000B869D File Offset: 0x000B689D public static void _WritePickupIndex_None(NetworkWriter writer, PickupIndex value) { writer.WritePackedUInt32((uint)value.value); }
public static bool IsCustomItemOrEquipment(PickupIndex pickupIndex) { var pickupDef = PickupCatalog.GetPickupDef(pickupIndex); return((int)pickupDef.itemIndex >= OriginalItemCount || (int)pickupDef.equipmentIndex >= OriginalEquipmentCount); }
private static void PageBuilderOnAddSimplePickup(On.RoR2.UI.LogBook.PageBuilder.orig_AddSimplePickup orig, PageBuilder self, PickupIndex pickupIndex) { if (IsCustomItemOrEquipment(pickupIndex)) { ItemIndex itemIndex = pickupIndex.itemIndex; EquipmentIndex equipmentIndex = pickupIndex.equipmentIndex; string token = null; if (itemIndex != ItemIndex.None) { ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex); self.AddDescriptionPanel(Language.GetString(itemDef.descriptionToken)); token = itemDef.loreToken; //ulong statValueULong = get from custom file; //ulong statValueULong2 = get from custom file; string stringFormatted = Language.GetStringFormatted("GENERIC_PREFIX_FOUND", "Unknown"); // param arg being the value from custom file string stringFormatted2 = Language.GetStringFormatted("ITEM_PREFIX_STACKCOUNT", "Unknown"); self.AddSimpleTextPanel(stringFormatted, stringFormatted2); } else if (equipmentIndex != EquipmentIndex.None) { EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(equipmentIndex); self.AddDescriptionPanel(Language.GetString(equipmentDef.descriptionToken)); token = equipmentDef.loreToken; // this.statSheet.GetStatDisplayValue(PerEquipmentStatDef.totalTimeHeld.FindStatDef(equipmentIndex)) get from custom file instead // this.statSheet.GetStatDisplayValue(PerEquipmentStatDef.totalTimesFired.FindStatDef(equipmentIndex)) string stringFormatted3 = Language.GetStringFormatted("EQUIPMENT_PREFIX_TOTALTIMEHELD", "Unknown"); string stringFormatted4 = Language.GetStringFormatted("EQUIPMENT_PREFIX_USECOUNT", "Unknown"); self.AddSimpleTextPanel(stringFormatted3, stringFormatted4); } // ReSharper disable once AssignNullToNotNullAttribute self.AddNotesPanel(Language.IsTokenInvalid(token) ? Language.GetString("EARLY_ACCESS_LORE") : Language.GetString(token)); } else { orig(self, pickupIndex); } }
private static void UserProfileOnDiscoverPickup(On.RoR2.UserProfile.orig_DiscoverPickup orig, UserProfile self, PickupIndex pickupIndex) { if (IsCustomItemOrEquipment(pickupIndex)) { return; } orig(self, pickupIndex); }