Esempio n. 1
0
        /// <summary>
        /// Spawn an item of the given tier at the position of the given CharacterBody.
        /// </summary>
        /// <param name="src">The body to spawn an item from.</param>
        /// <param name="tier">The tier of item to spawn. Must be within 0 and 5, inclusive (Tier 1, Tier 2, Tier 3, Lunar, Equipment, Lunar Equipment).</param>
        /// <param name="rng">An instance of Xoroshiro128Plus to use for random item selection.</param>
        public static void SpawnItemFromBody(CharacterBody src, int tier, Xoroshiro128Plus rng)
        {
            List <PickupIndex> spawnList;

            switch (tier)
            {
            case 1:
                spawnList = Run.instance.availableTier2DropList;
                break;

            case 2:
                spawnList = Run.instance.availableTier3DropList;
                break;

            case 3:
                spawnList = Run.instance.availableLunarDropList;
                break;

            case 4:
                spawnList = Run.instance.availableNormalEquipmentDropList;
                break;

            case 5:
                spawnList = Run.instance.availableLunarEquipmentDropList;
                break;

            case 0:
                spawnList = Run.instance.availableTier1DropList;
                break;

            default:
                throw new ArgumentOutOfRangeException("tier", tier, "spawnItemFromBody: Item tier must be between 0 and 5 inclusive");
            }
            PickupDropletController.CreatePickupDroplet(spawnList[rng.RangeInt(0, spawnList.Count)], src.transform.position, new Vector3(UnityEngine.Random.Range(-5.0f, 5.0f), 20f, UnityEngine.Random.Range(-5.0f, 5.0f)));
        }
Esempio n. 2
0
 // Token: 0x06001C3C RID: 7228 RVA: 0x0008414C File Offset: 0x0008234C
 public static void ShuffleList <T>(List <T> list, Xoroshiro128Plus rng)
 {
     for (int i = 0; i < list.Count; i++)
     {
         int index = rng.RangeInt(0, list.Count);
         T   value = list[i];
         list[i]     = list[index];
         list[index] = value;
     }
 }
Esempio n. 3
0
 // Token: 0x06001C3E RID: 7230 RVA: 0x000841DC File Offset: 0x000823DC
 public static void ShuffleArray <T>(T[] array, Xoroshiro128Plus rng)
 {
     for (int i = 0; i < array.Length; i++)
     {
         int num = rng.RangeInt(0, array.Length);
         T   t   = array[i];
         array[i]   = array[num];
         array[num] = t;
     }
 }
        /// <summary>
        /// Takes a collection and shuffle sorts it around randomly.
        /// </summary>
        /// <typeparam name="T">The type of the collection</typeparam>
        /// <param name="toShuffle">The collection to shuffle.</param>
        /// <param name="random">The random to shuffle the collection with.</param>
        /// <returns>The shuffled collection.</returns>
        public static IEnumerable <T> Shuffle <T>(this IEnumerable <T> toShuffle, Xoroshiro128Plus random)
        {
            List <T> shuffled = new List <T>();

            foreach (T value in toShuffle)
            {
                shuffled.Insert(random.RangeInt(0, shuffled.Count + 1), value);
            }
            return(shuffled);
        }
Esempio n. 5
0
 public static EquipmentIndex TryGetRandomEquipment(List <PickupIndex> list, Xoroshiro128Plus rng)
 {
     if (list.Count != 0)
     {
         int tries = 0;
         while (tries < 10)
         {
             EquipmentIndex index = PickupCatalog.GetPickupDef(list[rng.RangeInt(0, list.Count)]).equipmentIndex;
             if (index != EquipmentIndex.None)
             {
                 return(index);
             }
             else
             {
                 tries++;
             }
         }
     }
     return(EquipmentIndex.None);
 }
Esempio n. 6
0
        private void ForceFeedPotion(On.RoR2.CharacterBody.orig_FixedUpdate orig, RoR2.CharacterBody self)
        {
            if (NetworkServer.active)
            {
                var InventoryCount = GetCount(self);
                if (InventoryCount > 0)
                {
                    if (!self.HasBuff(AccursedPotionSipCooldownDebuff) && self.activeBuffsListCount <= maxEffectsAccrued)
                    {
                        BuffIndex ChosenBuff = RoR2.BuffCatalog.buffDefs[random.RangeInt(0, RoR2.BuffCatalog.buffCount - 1)].buffIndex;
                        if (RoR2.BuffCatalog.GetBuffDef(ChosenBuff).iconPath != null && ChosenBuff != BuffIndex.Immune && ChosenBuff != BuffIndex.HiddenInvincibility)
                        {
                            var BuffCount = RoR2.BuffCatalog.GetBuffDef(ChosenBuff).canStack ? InventoryCount : 1;

                            var            randomEffectDuration = random.RangeFloat(10, 20);
                            RoR2.TeamMask  enemyTeams           = RoR2.TeamMask.GetEnemyTeams(self.teamComponent.teamIndex);
                            RoR2.HurtBox[] hurtBoxes            = new RoR2.SphereSearch
                            {
                                radius = baseRadiusGranted + (additionalRadiusGranted * (InventoryCount - 1)),
                                mask   = RoR2.LayerIndex.entityPrecise.mask,
                                origin = self.corePosition
                            }.RefreshCandidates().FilterCandidatesByHurtBoxTeam(enemyTeams).OrderCandidatesByDistance().FilterCandidatesByDistinctHurtBoxEntities().GetHurtBoxes();

                            for (int i = 0; i < hurtBoxes.Length; i++)
                            {
                                var body = hurtBoxes[i].healthComponent.body;
                                if (body)
                                {
                                    AddBuffAndDot(ChosenBuff, randomEffectDuration, BuffCount, body);
                                }
                            }
                            AddBuffAndDot(AccursedPotionSipCooldownDebuff, baseSipCooldownDuration * (float)Math.Pow(additionalStackSipCooldownReductionPercentage, InventoryCount - 1), 1, self);
                            AddBuffAndDot(ChosenBuff, randomEffectDuration, BuffCount, self);
                        }
                    }
                }
            }
            orig(self);
        }
        // Token: 0x06000A25 RID: 2597 RVA: 0x0002C404 File Offset: 0x0002A604
        public GameObject TrySpawnObject([NotNull] DirectorSpawnRequest directorSpawnRequest)
        {
            SpawnCard             spawnCard     = directorSpawnRequest.spawnCard;
            DirectorPlacementRule placementRule = directorSpawnRequest.placementRule;
            Xoroshiro128Plus      rng           = directorSpawnRequest.rng;
            NodeGraph             nodeGraph     = SceneInfo.instance.GetNodeGraph(spawnCard.nodeGraphType);
            GameObject            result        = null;

            switch (placementRule.placementMode)
            {
            case DirectorPlacementRule.PlacementMode.Direct:
                result = spawnCard.DoSpawn(placementRule.spawnOnTarget ? placementRule.spawnOnTarget.position : directorSpawnRequest.placementRule.position, Quaternion.identity, directorSpawnRequest);
                break;

            case DirectorPlacementRule.PlacementMode.Approximate:
            {
                List <NodeGraph.NodeIndex> list = nodeGraph.FindNodesInRangeWithFlagConditions(placementRule.targetPosition, placementRule.minDistance, placementRule.maxDistance, (HullMask)(1 << (int)spawnCard.hullSize), spawnCard.requiredFlags, spawnCard.forbiddenFlags, placementRule.preventOverhead);
                while (list.Count > 0)
                {
                    int index = rng.RangeInt(0, list.Count);
                    NodeGraph.NodeIndex nodeIndex = list[index];
                    Vector3             position;
                    nodeGraph.GetNodePosition(nodeIndex, out position);
                    if (this.CheckPositionFree(nodeGraph, nodeIndex, spawnCard))
                    {
                        result = spawnCard.DoSpawn(position, Quaternion.identity, directorSpawnRequest);
                        if (spawnCard.occupyPosition)
                        {
                            this.AddOccupiedNode(nodeGraph, nodeIndex);
                            break;
                        }
                        break;
                    }
                    else
                    {
                        list.RemoveAt(index);
                    }
                }
                break;
            }

            case DirectorPlacementRule.PlacementMode.ApproximateSimple:
            {
                NodeGraph.NodeIndex nodeIndex2 = nodeGraph.FindClosestNodeWithFlagConditions(placementRule.targetPosition, spawnCard.hullSize, spawnCard.requiredFlags, spawnCard.forbiddenFlags, placementRule.preventOverhead);
                Vector3             position2;
                if (nodeGraph.GetNodePosition(nodeIndex2, out position2))
                {
                    if (this.CheckPositionFree(nodeGraph, nodeIndex2, spawnCard))
                    {
                        result = spawnCard.DoSpawn(position2, Quaternion.identity, directorSpawnRequest);
                        if (spawnCard.occupyPosition)
                        {
                            this.AddOccupiedNode(nodeGraph, nodeIndex2);
                        }
                    }
                    else
                    {
                        Debug.Log("Position not free.");
                    }
                }
                else
                {
                    Debug.Log("Could not find node.");
                }
                break;
            }

            case DirectorPlacementRule.PlacementMode.NearestNode:
            {
                NodeGraph.NodeIndex nodeIndex3 = nodeGraph.FindClosestNodeWithFlagConditions(placementRule.targetPosition, spawnCard.hullSize, spawnCard.requiredFlags, spawnCard.forbiddenFlags, placementRule.preventOverhead);
                Vector3             position3;
                if (nodeGraph.GetNodePosition(nodeIndex3, out position3))
                {
                    result = spawnCard.DoSpawn(position3, Quaternion.identity, directorSpawnRequest);
                    if (spawnCard.occupyPosition)
                    {
                        this.AddOccupiedNode(nodeGraph, nodeIndex3);
                    }
                }
                break;
            }

            case DirectorPlacementRule.PlacementMode.Random:
            {
                List <NodeGraph.NodeIndex> activeNodesForHullMaskWithFlagConditions = nodeGraph.GetActiveNodesForHullMaskWithFlagConditions((HullMask)(1 << (int)spawnCard.hullSize), spawnCard.requiredFlags, spawnCard.forbiddenFlags);
                while (activeNodesForHullMaskWithFlagConditions.Count > 0)
                {
                    int index2 = rng.RangeInt(0, activeNodesForHullMaskWithFlagConditions.Count);
                    NodeGraph.NodeIndex nodeIndex4 = activeNodesForHullMaskWithFlagConditions[index2];
                    Vector3             position4;
                    if (nodeGraph.GetNodePosition(nodeIndex4, out position4) && this.CheckPositionFree(nodeGraph, nodeIndex4, spawnCard))
                    {
                        result = spawnCard.DoSpawn(position4, Quaternion.identity, directorSpawnRequest);
                        if (spawnCard.occupyPosition)
                        {
                            this.AddOccupiedNode(nodeGraph, nodeIndex4);
                            break;
                        }
                        break;
                    }
                    else
                    {
                        activeNodesForHullMaskWithFlagConditions.RemoveAt(index2);
                    }
                }
                break;
            }
            }
            return(result);
        }
        public void BeginRound(GameObject centerPoint)
        {
            //Add monster card to, and activate combat director
            //^ Make directors more powerful if more events are active?
            if (this.roundsStarted >= 5)
            {
                return;
            }
            roundsStarted++;
            if (NetworkServer.active)
            {
                foreach (TeamComponent teamComponent in TeamComponent.GetTeamMembers(TeamIndex.Player))
                {
                    if (teamComponent.body && teamComponent.body.healthComponent)
                    {
                        teamComponent.body.healthComponent.HealFraction(0.75f, new ProcChainMask());
                        teamComponent.body.healthComponent.RechargeShieldFull();
                    }
                }

                if (monsterCards.Count <= 0)
                {
                    Debug.LogWarning("[CRCore3]: CRMissionController.BeginRound - No monsters left to chose from! Attempting to get new SpawnCards...");
                    WeightedSelection <DirectorCard> newCards = Util.CreateReasonableDirectorCardSpawnList(60 * Run.instance.difficultyCoefficient, 6, 2);
                    foreach (var newCardInfo in newCards.choices)
                    {
                        DirectorCard newCard = newCardInfo.value;
                        bool         isUsed  = false;
                        foreach (DirectorCard selectedCard in pickedMonsterCards)
                        {
                            if (selectedCard == newCard)
                            {
                                isUsed = true;
                                break;
                            }
                        }
                        if (!isUsed && newCard != null && newCard.spawnCard)
                        {
                            monsterCards.AddChoice(newCard, newCardInfo.weight);
                            Debug.Log("[CRCore3]: CRMissionController.BeginRound - Found valid SpawnCard " + newCard.spawnCard.name + ". Adding to options.");
                        }
                    }
                }
                if (monsterCards.Count > 0)
                {
                    int selectedIndex = monsterCards.EvaluteToChoiceIndex(this.rng.nextNormalizedFloat);
                    pickedMonsterCards.Add(monsterCards.choices[selectedIndex].value);
                    if (NetworkServer.active)
                    {
                        Chat.SendBroadcastChat(new Chat.SimpleChatMessage {
                            baseToken = "<color=#E6B3FF>[WARNING]: " + Language.GetString(monsterCards.choices[selectedIndex].value.spawnCard.prefab.GetComponent <CharacterMaster>().bodyPrefab.GetComponent <CharacterBody>().baseNameToken) + "s were released from the void!</color>"
                        });
                    }
                    monsterCards.RemoveChoice(selectedIndex);
                }
                else
                {
                    Debug.LogWarning("[CRCore3]: CRMissionController.BeginRound - No monsters left to chose from! Reverting to already selected SpawnCard.");
                    pickedMonsterCards.Add(pickedMonsterCards[this.rng.RangeInt(0, pickedMonsterCards.Count)]);
                }


                if (Run.instance)
                {
                    if (availableTier1DropList == null)
                    {
                        availableTier1DropList = Run.instance.availableTier1DropList.Where(new Func <PickupIndex, bool>(ArenaMissionController.IsPickupAllowedForMonsters)).ToList <PickupIndex>();
                    }
                    if (availableTier2DropList == null)
                    {
                        availableTier2DropList = Run.instance.availableTier2DropList.Where(new Func <PickupIndex, bool>(ArenaMissionController.IsPickupAllowedForMonsters)).ToList <PickupIndex>();
                    }
                    if (availableTier3DropList == null)
                    {
                        availableTier3DropList = Run.instance.availableTier3DropList.Where(new Func <PickupIndex, bool>(ArenaMissionController.IsPickupAllowedForMonsters)).ToList <PickupIndex>();
                    }
                    if (monsterCards == null)
                    {
                        monsterCards = Util.CreateReasonableDirectorCardSpawnList(50 * Run.instance.difficultyCoefficient, 6, 2);
                    }
                }
                else
                {
                    Debug.LogError("[CRCore]: Run.instance does not exist!");
                }

                for (int i = 0; i < pickedMonsterCards.Count; i++)
                {
                    if (i >= directors.Length)
                    {
                        break;
                    }
                    directors[i].OverrideCurrentMonsterCard(pickedMonsterCards[i]);
                    directors[i].monsterCredit      = ((CRCore3.creditsBase.Value + CRCore3.creditMultiplier.Value * this.roundsStarted) * Run.instance.difficultyCoefficient) / pickedMonsterCards.Count;
                    directors[i].creditMultiplier   = CRCore3.creditMultiplier.Value * this.roundsStarted / pickedMonsterCards.Count;
                    directors[i].targetPlayers      = false;
                    directors[i].currentSpawnTarget = centerPoint;
                    if (NetworkServer.active)
                    {
                        directors[i].enabled           = true;
                        directors[i].monsterSpawnTimer = 0;
                    }
                    Debug.Log("[CRCore3]: Updated CombatDirector" + i.ToString() + "'s credits to: " + directors[i].monsterCredit.ToString());
                    Debug.Log("[CRCore3]: Updated CombatDirector" + i.ToString() + "'s multiplier to: " + directors[i].creditMultiplier.ToString());
                }

                //Add items to monster inventory

                List <PickupIndex> list;
                int count;
                switch (roundsStarted)
                {
                default:
                    list  = availableTier1DropList;
                    count = rng.RangeInt(3, 6);
                    break;

                case 3:
                case 4:
                    list  = availableTier2DropList;
                    count = rng.RangeInt(2, 4);
                    break;

                case 5:
                    list  = availableTier3DropList;
                    count = 1;
                    break;
                }
                PickupIndex pickupIndex;
                PickupDef   pickupDef;
                ItemIndex   itemIndex = ItemIndex.None;
                for (int i = 0; i < 25; i++)
                {
                    pickupIndex = this.rng.NextElementUniform <PickupIndex>(list);
                    list.Remove(pickupIndex);
                    pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
                    itemIndex = pickupDef.itemIndex;
                    bool badItem = false;
                    foreach (string itemName in CRCore3.AIBlacklist)
                    {
                        if (ItemCatalog.GetItemDef(itemIndex).name.ToLower().Contains(itemName.ToLower()))
                        {
                            badItem = true;
                            break;
                        }
                    }
                    if (!badItem)
                    {
                        break;
                    }
                    Debug.Log("[CRCore]: Item was blacklisted! Trying again.");
                }
                int dictOut;
                if (CRCore3.itemCountOverrides.ContainsKey(ItemCatalog.GetItemDef(itemIndex).name))
                {
                    CRCore3.itemCountOverrides.TryGetValue(ItemCatalog.GetItemDef(itemIndex).name, out dictOut);
                    inventory.GiveItem(itemIndex, dictOut);
                }
                else
                {
                    inventory.GiveItem(itemIndex, count);
                }

                if (NetworkServer.active)
                {
                    Chat.SendBroadcastChat(new Chat.SimpleChatMessage {
                        baseToken = "<color=#E6B3FF>[WARNING]: " + Language.GetString(ItemCatalog.GetItemDef(itemIndex).nameToken) + " has integrated into the rift!</color>"
                    });
                }

                if (roundsStarted >= 5)
                {
                    if (this.rng.RangeInt(0, 100) <= 10)
                    {
                        if (this.rng.nextBool)
                        {
                            for (int i = 0; i < 25; i++)
                            {
                                pickupIndex = this.rng.NextElementUniform <PickupIndex>(Run.instance.availableBossDropList);
                                list.Remove(pickupIndex);
                                pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
                                itemIndex = pickupDef.itemIndex;
                                bool badItem = false;
                                foreach (string itemName in CRCore3.AIBlacklistBoss)
                                {
                                    if (ItemCatalog.GetItemDef(itemIndex).name.ToLower().Contains(itemName.ToLower()))
                                    {
                                        badItem = true;
                                        break;
                                    }
                                }
                                if (!badItem)
                                {
                                    break;
                                }
                                Debug.Log("[CRCore]: Boss item was blacklisted! Trying again.");
                            }
                            inventory.GiveItem(itemIndex, 1);
                            if (NetworkServer.active)
                            {
                                Chat.SendBroadcastChat(new Chat.SimpleChatMessage {
                                    baseToken = "<color=#E6B3FF>[WARNING]: Rare boss item " + Language.GetString(ItemCatalog.GetItemDef(itemIndex).nameToken) + " has integrated into the rift!</color>"
                                });
                            }
                        }
                        else
                        {
                            for (int i = 0; i < 25; i++)
                            {
                                pickupIndex = this.rng.NextElementUniform <PickupIndex>(Run.instance.availableBossDropList);
                                list.Remove(pickupIndex);
                                pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
                                itemIndex = pickupDef.itemIndex;
                                bool badItem = false;
                                foreach (string itemName in CRCore3.AIBlacklistLunar)
                                {
                                    if (ItemCatalog.GetItemDef(itemIndex).name.ToLower().Contains(itemName.ToLower()))
                                    {
                                        badItem = true;
                                        break;
                                    }
                                }
                                if (!badItem)
                                {
                                    break;
                                }
                                Debug.Log("[CRCore]: Lunar item was blacklisted! Trying again.");
                            }
                            inventory.GiveItem(itemIndex, 1);
                            if (NetworkServer.active)
                            {
                                Chat.SendBroadcastChat(new Chat.SimpleChatMessage {
                                    baseToken = "<color=#E6B3FF>[WARNING]: Rare Lunar item " + Language.GetString(ItemCatalog.GetItemDef(itemIndex).nameToken) + " has integrated into the rift!</color>"
                                });
                            }
                        }
                    }
                }

                foreach (GameObject rift in voidRifts)
                {
                    if (rift.GetComponent <EntityStateMachine>().state is RiftOffState)
                    {
                        (rift.GetComponent <EntityStateMachine>().state as RiftOffState).teleportTarget = centerPoint;
                    }
                }
            }
        }
Esempio n. 9
0
            static bool Prefix(
                BossGroup __instance,
                DamageReport damageReport,
                ref List <PickupIndex> ___bossDrops,
                ref List <CharacterMaster> ___membersList,
                ref bool ___defeated,
                ref Xoroshiro128Plus ___rng
                )
            {
                if (!NetworkServer.active)
                {
                    Debug.LogWarning("[Server] function 'System.Void RoR2.BossGroup::OnCharacterDeathCallback(RoR2.DamageReport)' called on client");
                    return(false);
                }
                DamageInfo    damageInfo = damageReport.damageInfo;
                GameObject    gameObject = damageReport.victim.gameObject;
                CharacterBody component  = gameObject.GetComponent <CharacterBody>();

                if (!component)
                {
                    return(false);
                }
                CharacterMaster master = component.master;

                if (!master)
                {
                    return(false);
                }
                DeathRewards component2 = gameObject.GetComponent <DeathRewards>();

                if (component2)
                {
                    PickupIndex pickupIndex = (PickupIndex)component2.bossPickup;
                    if (pickupIndex != PickupIndex.none)
                    {
                        ___bossDrops.Add(pickupIndex);
                    }
                }
                GameObject victimMasterGameObject = master.gameObject;
                int        num = ___membersList.FindIndex((CharacterMaster x) => x.gameObject == victimMasterGameObject);

                if (num >= 0)
                {
                    typeof(BossGroup).GetMethod("RemoveMemberAt", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { num });
                    if (!___defeated && ___membersList.Count == 0)
                    {
                        Run.instance.OnServerBossKilled(true);
                        if (component)
                        {
                            int participatingPlayerCount = Run.instance.participatingPlayerCount;
                            if (participatingPlayerCount != 0 && __instance.dropPosition)
                            {
                                ItemIndex  itemIndex = Run.instance.availableTier2DropList[___rng.RangeInt(0, Run.instance.availableTier2DropList.Count)].itemIndex;
                                int        num2      = TeleAwardInVar.Value * participatingPlayerCount * (1 + (TeleporterInteraction.instance ? TeleporterInteraction.instance.shrineBonusStacks : 0));
                                float      angle     = 360f / (float)num2;
                                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 < num2)
                                {
                                    PickupIndex pickupIndex2 = new PickupIndex(itemIndex);
                                    if (___bossDrops.Count > 0 && ___rng.nextNormalizedFloat <= __instance.bossDropChance)
                                    {
                                        pickupIndex2 = ___bossDrops[___rng.RangeInt(0, ___bossDrops.Count)];
                                    }
                                    PickupDropletController.CreatePickupDroplet(pickupIndex2, __instance.dropPosition.position, vector);
                                    i++;
                                    vector = rotation * vector;
                                }
                            }
                        }
                        ___defeated = true;
                        typeof(BossGroup).Raise("onBossGroupDefeatedServer", __instance);
                        return(false);
                    }
                    else
                    {
                        Run.instance.OnServerBossKilled(false);
                    }
                }
                return(false);
            }
Esempio n. 10
0
        public void ShrineRestackInventory([NotNull] Xoroshiro128Plus rng)
        {
            if (!NetworkServer.active)
            {
                Debug.LogWarning("[Server] function 'System.Void RoR2.Inventory::ShrineRestackInventory(Xoroshiro128Plus)' called on client");
                return;
            }
            List <ItemIndex> list  = new List <ItemIndex>();
            List <ItemIndex> list2 = new List <ItemIndex>();
            List <ItemIndex> list3 = new List <ItemIndex>();
            List <ItemIndex> list4 = new List <ItemIndex>();
            List <ItemIndex> list5 = new List <ItemIndex>();

            new List <ItemIndex>();
            int num  = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;
            int num5 = 0;

            for (int i = 0; i < this.itemStacks.Length; i++)
            {
                ItemIndex itemIndex = (ItemIndex)i;
                if (this.itemStacks[i] > 0)
                {
                    switch (ItemCatalog.GetItemDef(itemIndex).tier)
                    {
                    case ItemTier.Tier1:
                        num += this.itemStacks[i];
                        list.Add(itemIndex);
                        break;

                    case ItemTier.Tier2:
                        num2 += this.itemStacks[i];
                        list2.Add(itemIndex);
                        break;

                    case ItemTier.Tier3:
                        num3 += this.itemStacks[i];
                        list3.Add(itemIndex);
                        break;

                    case ItemTier.Lunar:
                        num4 += this.itemStacks[i];
                        list4.Add(itemIndex);
                        break;

                    case ItemTier.Boss:
                        num5 += this.itemStacks[i];
                        list5.Add(itemIndex);
                        break;
                    }
                }
                this.ResetItem(itemIndex);
            }
            ItemIndex itemIndex2 = (list.Count == 0) ? ItemIndex.None : list[rng.RangeInt(0, list.Count)];
            ItemIndex itemIndex3 = (list2.Count == 0) ? ItemIndex.None : list2[rng.RangeInt(0, list2.Count)];
            ItemIndex itemIndex4 = (list3.Count == 0) ? ItemIndex.None : list3[rng.RangeInt(0, list3.Count)];
            ItemIndex itemIndex5 = (list4.Count == 0) ? ItemIndex.None : list4[rng.RangeInt(0, list4.Count)];
            ItemIndex itemIndex6 = (list5.Count == 0) ? ItemIndex.None : list5[rng.RangeInt(0, list5.Count)];

            this.itemAcquisitionOrder.Clear();
            base.SetDirtyBit(8u);
            this.GiveItem(itemIndex2, num);
            this.GiveItem(itemIndex3, num2);
            this.GiveItem(itemIndex4, num3);
            this.GiveItem(itemIndex5, num4);
            this.GiveItem(itemIndex6, num5);
        }
Esempio n. 11
0
        private void TryGrantItem(MasterSummon.MasterSummonReport summonReport)
        {
            var master      = summonReport.leaderMasterInstance;
            var servant     = summonReport.summonMasterInstance;
            var servantBody = servant.GetBody();

            var InventoryCount = GetCount(master);

            if (InventoryCount > 0)
            {
                if (servantBody && (servantBody.bodyFlags & CharacterBody.BodyFlags.Mechanical) > CharacterBody.BodyFlags.None || servantBody.name == "SquidTurretBody")
                {
                    //if (!squidAllowed) return;
                    inFlightOrbs = new List <RoR2.Orbs.ItemTransferOrb>();
                    int itemStack = InventoryCount * itemAddStack;
                    int itemGiven = InventoryCount * itemsToGive;
#if DEBUG
                    TurboEdition._logger.LogWarning(ItemName + " Calculated numbers, itemStack: " + itemStack + " itemGiven: " + itemGiven);
#endif
                    if (itemStackingCap != -1)
                    {
                        itemStack = Mathf.Min(itemStack, itemStackingCap);
                    }
                    if (itemGivingCap != -1)
                    {
                        itemGiven = Mathf.Min(itemGiven, itemGivingCap);
                    }

#if DEBUG
                    TurboEdition._logger.LogWarning(ItemName + " Re-calculated numbers, itemStack: " + itemStack + " itemGiven: " + itemGiven);
#endif
                    var  itemList = master.inventory.itemAcquisitionOrder;
                    int  randomIndex;
                    bool foundBlacklisted;
                    if (cappedByInventory)
                    {
                        itemGiven = Mathf.Min(itemGiven, itemList.Count);
                    }
                    ;                                                                             //Let's not give more items than what the player has
                    for (int i = 0; i < itemGiven; i++)
                    {
                        //Get a delayer here PLEASE, game shits itself with high item count or when summoning multiple at the same time i.e reinforcement!
                        //Would let the player know which items the drones are getting too!
                        do
                        {
                            foundBlacklisted = false;
                            randomIndex      = random.RangeInt(0, itemList.Count);
                            if (ItemCatalog.GetItemDef(itemList[randomIndex]).ContainsTag(ItemTag.CannotCopy))
                            {
                                foundBlacklisted = true;
                            }

                            foreach (ItemDef item in itemBlacklist)
                            {
                                if (ItemCatalog.GetItemDef(itemList[randomIndex]) == item)
                                {
#if DEBUG
                                    Chat.AddMessage("Turbo Edition: " + ItemName + " Found a blacklisted item (" + item + ") when giving items to a summon, rerolling.");
#endif
                                    foundBlacklisted = true;
                                }
                            }
                        } while (foundBlacklisted);

                        itemStack = Mathf.Min(itemStack, master.inventory.GetItemCount(itemList[randomIndex]));
#if DEBUG
                        TurboEdition._logger.LogWarning(ItemName + " Getting either max item count or max item stack, itemStack: " + itemStack);
#endif
                        if (useOrbs)
                        {
                            RoR2.Orbs.ItemTransferOrb item = RoR2.Orbs.ItemTransferOrb.DispatchItemTransferOrb(master.GetBody().transform.position, servant.inventory, itemList[randomIndex], itemStack, delegate(RoR2.Orbs.ItemTransferOrb orb)
                            {
#if DEBUG
                                TurboEdition._logger.LogWarning(ItemName + " Gave " + itemList[randomIndex] + " via orbs to " + servant + " " + itemStack + " times. Item " + i + " out of " + itemGiven);
#endif
                                servant.inventory.GiveItem(orb.itemIndex, orb.stack);
                                this.inFlightOrbs.Remove(orb);
                            }, servant.networkIdentity);
                            this.inFlightOrbs.Add(item);
                        }
                        else
                        {
#if DEBUG
                            TurboEdition._logger.LogWarning(ItemName + " Gave " + itemList[randomIndex] + " directly to " + servant + " " + itemStack + " times. Item " + i + " out of " + itemGiven);
#endif
                            servant.inventory.GiveItem(itemList[randomIndex], itemStack);
                        }
                    }
                }
            }
        }
        public void Awake()
        {
            var quipsEnabled =
                Config.Bind(new ConfigDefinition("Drop Gold On Death", "Quips Enabled"), true, new ConfigDescription("Enables quips, which are fun little messages appended to the message in chat after death.", null, Array.Empty <object>())).Value;
            var goldMultiplier = Config.Bind(
                new ConfigDefinition("Drop Gold On Death", "Gold Multiplier"), 1f,
                new ConfigDescription("Gold multiplier applied to gold split among players.", null,
                                      Array.Empty <object>())).Value;

            // For some reason, we were unable to get languages to properly add via Zio, thus they are
            // added directly via hooking onto the onCurrentLanguageChanged event. This isn't awful,
            // but it does add some extra code that can be avoided. Pull requests that shift this to
            // Zio and local files are welcome.
            Language.onCurrentLanguageChanged += () =>
            {
                var list = new List <KeyValuePair <string, string> >();
                if (Language.currentLanguageName == "en")
                {
                    list.Add(new KeyValuePair <string, string>("DGOD_DEATH_MESSAGE", "<color=#00FF80>{0}</color> gave everyone <color=#e2b00b>{1} gold</color> from the grave! {2}"));
                    list.Add(new KeyValuePair <string, string>("DGOD_DEATH_MESSAGE_WITHOUT_QUIP", "<color=#00FF80>{0}</color> gave everyone <color=#e2b00b>{1} gold</color>!"));

                    list.Add(new KeyValuePair <string, string>("QUIP_1", "Don't forget to thank them for dying!"));
                    list.Add(new KeyValuePair <string, string>("QUIP_2", "Everybody point and laugh!"));
                    list.Add(new KeyValuePair <string, string>("QUIP_3", "How kind of them!"));
                    list.Add(new KeyValuePair <string, string>("QUIP_4", "Maybe next time..."));
                    list.Add(new KeyValuePair <string, string>("QUIP_5", "Someone needs more health LOL"));
                    list.Add(new KeyValuePair <string, string>("QUIP_6", "What were they thinking?!"));
                }
                Language.currentLanguage.SetStringsByTokens(list);
            };

            // Subscribe to the pre-existing event, we were being a bad boy and hooking onto the GlobalEventManager before
            GlobalEventManager.onCharacterDeathGlobal += (damageReport) =>
            {
                var component   = damageReport.victimBody;
                var networkUser = component.master.playerCharacterMasterController.networkUser;

                // Bail early if user is not in multiplayer
                if (!networkUser || !IsMultiplayer())
                {
                    return;
                }

                // Bail if ShareSuite is detected
                // ShareSuite uses a shared pool of gold already, thus defeating the purpose.
                if (HasShareSuite())
                {
                    UnityEngine.Debug.Log("DropGoldOnDeath: ShareSuite detected, no changes to gold");
                    return;
                }

                // Bail if BiggerBazaar is detected and a Newt Altar has been activated
                // For more context, BiggerBazaar allows you to retain your money after the stage when a
                // newt altar is active. In this case, don't split the gold among everyone and allow the
                // dead players to spend the money they did have.
                if (HasBiggerBazaar() && IsNewtAltarActive())
                {
                    return;
                }

                // Bail if the user has an unused Dio's Best Friend
                if (component.master.inventory.GetItemCount(RoR2Content.Items.ExtraLife) > 0)
                {
                    return;
                }

                if (component.master.money <= 0)
                {
                    return;
                }

                // Pick a random quip to add a little humor
                var rand  = new Xoroshiro128Plus(Run.instance.stageRng.nextUlong);
                int index = rand.RangeInt(0, Quips.Length);

                // Get players alive and gold count
                var  aliveLists = AliveList(component.master);
                uint money      = component.master.money;
                uint count      = Convert.ToUInt32(aliveLists.Count);

                // Return if there is no more alive players
                if (count < 1)
                {
                    return;
                }

                // Zero the victim's gold and distribute it
                uint split = money / count;
                component.master.money = 0;
                foreach (var player in aliveLists)
                {
                    player.money += (uint)(split * goldMultiplier);
                }

                // Broadcast drop message
                if (quipsEnabled)
                {
                    Chat.SendBroadcastChat(new Chat.SimpleChatMessage
                    {
                        baseToken   = "DGOD_DEATH_MESSAGE",
                        paramTokens = new [] { networkUser.userName, split.ToString(), Language.GetString(Quips[index]) }
                    });
                }
                else
                {
                    Chat.SendBroadcastChat(new Chat.SimpleChatMessage
                    {
                        baseToken   = "DGOD_DEATH_MESSAGE_WITHOUT_QUIP",
                        paramTokens = new [] { networkUser.userName, split.ToString(), Language.GetString(Quips[index]) }
                    });
                }
            };
        }
Esempio n. 13
0
 public static bool GenerateDropPrefix(ref Xoroshiro128Plus rng, ref PickupIndex __result)
 {
     __result = ScrapChestsPlugin._cachedItemLists[3][rng.RangeInt(0, ScrapChestsPlugin._cachedItemLists[3].Count)];
     return(false);
 }
Esempio n. 14
0
            public override PickupIndex GenerateDrop(Xoroshiro128Plus rng)
            {
                var items = Run.instance.availableLunarDropList.Where(x => PickupCatalog.GetPickupDef(x).itemIndex != ItemIndex.None).ToArray();

                return(items[rng.RangeInt(0, items.Count())]);
            }