Example #1
0
        public static void PushToAllPlayers <T>(StatDef statDef, T value)
        {
            foreach (NetworkUser user in NetworkUser.readOnlyInstancesList)
            {
                var body = user.GetCurrentBody();
                if (!body)
                {
                    continue;
                }
                switch (statDef.dataType)
                {
                case StatDataType.Double:
                {
                    Double?val = value as double?;
                    if (val.HasValue)
                    {
                        PlayerStatsComponent.FindBodyStatSheet(body).PushStatValue(statDef, val.GetValueOrDefault());
                    }
                } break;

                case StatDataType.ULong:
                {
                    ulong?val = value as ulong?;
                    if (val.HasValue)
                    {
                        PlayerStatsComponent.FindBodyStatSheet(body).PushStatValue(statDef, val.GetValueOrDefault());
                    }
                } break;
                }
            }
        }
Example #2
0
 private void PlayerStatsComponent_ServerFixedUpdate(On.RoR2.Stats.PlayerStatsComponent.orig_ServerFixedUpdate orig, PlayerStatsComponent self)
 {
     orig(self);
     if (Run.instance && Run.instance.isRunStopwatchPaused && self.characterMaster && self.characterMaster.GetBody())
     {
         PlayerStatsComponent.FindBodyStatSheet(self.characterMaster.GetBody()).PushStatValue(Definition, UnityEngine.Time.fixedDeltaTime);
     }
 }
Example #3
0
 private void hook(On.RoR2.HealthComponent.orig_TakeDamage orig, RoR2.HealthComponent self, RoR2.DamageInfo damageInfo)
 {
     orig(self, damageInfo);
     if (damageInfo.rejected)
     {
         PlayerStatsComponent.FindBodyStatSheet(self.body).PushStatValue(Definition, 1);
     }
 }
Example #4
0
 private void GenericCharacterMain_ApplyJumpVelocity(On.EntityStates.GenericCharacterMain.orig_ApplyJumpVelocity orig, CharacterMotor characterMotor, CharacterBody characterBody, float horizontalBonus, float verticalBonus)
 {
     orig(characterMotor, characterBody, horizontalBonus, verticalBonus);
     if (characterBody.isPlayerControlled)
     {
         PlayerStatsComponent.FindBodyStatSheet(characterBody).PushStatValue(Definition, 1);
     }
 }
Example #5
0
        private void hook(HealthComponent healthComponent, float amount)
        {
            var body = healthComponent.body;

            if (body.isPlayerControlled)
            {
                PlayerStatsComponent.FindBodyStatSheet(body).PushStatValue(Definition, Convert.ToDouble(amount));
            }
        }
Example #6
0
        private void HealthDamageHook(On.RoR2.HealthComponent.orig_TakeDamage orig, RoR2.HealthComponent self, RoR2.DamageInfo damageInfo)
        {
            orig.Invoke(self, damageInfo);
            float dmg = damageInfo.damage;

            if (!self.body || !self.body.isPlayerControlled)
            {
                return; //Ignore if it's not a player.
            }
            if (damageInfo.damageType.HasFlag(DamageType.NonLethal) || damageInfo.rejected || !self.alive)
            {
                return;                              //Ignore if it's fall damage, blocked, or we just straight up died.
            }
            if (dmg > self.fullCombinedHealth * 0.9) //the big Damage
            {
#if DEBUG
                PlayerStatsComponent.FindBodyStatSheet(self.body).PushStatValue(this.testDef, 1UL);
#endif
                if (self.combinedHealthFraction <= 0.12) //Are we barely alive?
                {
                    PlayerStatsComponent.FindBodyStatSheet(self.body).PushStatValue(this.ourStatDef, 1UL);
                }
            }
        }
Example #7
0
        protected void LoadBehavior()
        {
            Playername   = new List <CharacterBody>();
            counter      = new List <int>();
            currentStage = 0;

            statsLostItems = null;
            statsGainItems = null;

            statsLostItems = StatDef.Register("Lostitems", StatRecordType.Sum, StatDataType.ULong, 0, null);
            statsGainItems = StatDef.Register("Gainitems", StatRecordType.Sum, StatDataType.ULong, 0, null);

            On.RoR2.UI.GameEndReportPanelController.Awake += (orig, self) =>
            {
                orig(self);
                if (!Networking._instance.IsArtifactEnabled)
                {
                    return;
                }
                string[] information = new string[self.statsToDisplay.Length + 2];
                self.statsToDisplay.CopyTo(information, 0);
                information[information.Length - 2] = "Lostitems";
                information[information.Length - 1] = "Gainitems";
                self.statsToDisplay = information;
            };
            On.RoR2.PreGameController.StartRun += (orig, self) =>
            {
                orig(self);
            };

            On.RoR2.SceneDirector.PopulateScene += (orig, self) =>
            {
                orig(self);

                currentStage = Run.instance.stageClearCount + 1;


                if (Run.instance.selectedDifficulty == DifficultyIndex.Easy)
                {
                    timeForBuff = ArtifactOfDoomConfig.timeAfterHitToNotLoseItemDrizzly.Value;
                }
                if (Run.instance.selectedDifficulty == DifficultyIndex.Normal)
                {
                    timeForBuff = ArtifactOfDoomConfig.timeAfterHitToNotLoseItemRainstorm.Value;
                }
                if (Run.instance.selectedDifficulty == DifficultyIndex.Hard)
                {
                    timeForBuff = ArtifactOfDoomConfig.timeAfterHitToNotLoseItemMonsoon.Value;
                }
                if (timeForBuff == -1.0)
                {
                    List <Difficulty> characters = ArtifactOfDoomConfig.timeAfterHitToNotLoseItemOtherDifficulty.Value.FromJson <List <Difficulty> >();
                    foreach (var element in characters)
                    {
                        if (Run.instance.selectedDifficulty == (DifficultyIndex)element.DifficultyIndex)
                        {
                            timeForBuff = element.time;
                        }
                    }
                    if (timeForBuff == -1.0)
                    {
                        Debug.LogWarning("Didn't find valid Configuration for Selected Difficulty. Falling back to 0.1 seconds for Buff. If you want a own definition fill out timeAfterHitToNotLoseItemOtherDifficulty in the Config. DifficultyIndex=" + Run.instance.selectedDifficulty);
                        timeForBuff = 0.1;
                    }
                }
                QueueLostItemSprite   = new Dictionary <uint, Queue <ItemDef> >();
                QueueGainedItemSprite = new Dictionary <uint, Queue <ItemDef> >();
                Playername            = new List <CharacterBody>();
                counter = new List <int>();
                LockNetworkUser.Clear();
            };
            On.RoR2.Run.Awake += (orig, self) =>
            {
                orig(self);
                //Debug.LogWarning("NetworkClass.SpawnNetworkObject();");
            };
            On.RoR2.Run.Start += (orig, self) =>
            {
                orig(self);
            };
            On.RoR2.CharacterBody.OnInventoryChanged += (orig, self) =>
            {
                orig(self);


                if (!Networking._instance.IsArtifactEnabled)
                {
                    return;
                }
                if (!self.isPlayerControlled)
                {
                    return;
                }

                NetworkUser tempNetworkUser = getNetworkUserOfCharacterBody(self);
                int         calculatesEnemyCountToTrigger = calculateEnemyCountToTrigger(self.inventory);

                if (!Playername.Contains(self))
                {
                    Playername.Add(self);
                    counter.Add(0);
                }
                if (tempNetworkUser != null)
                {
                    string tempString = counter[Playername.IndexOf(self)] + "," + calculatesEnemyCountToTrigger;
                    if (NetworkServer.active)
                    {
                        Networking.ServerEnsureNetworking();
                        Networking._instance.TargetUpdateProgressBar(tempNetworkUser.connectionToClient, tempString);
                    }
                }
            };
            On.RoR2.GlobalEventManager.OnCharacterDeath += (orig, self, damageReport) =>
            {
                //try
                //{
                orig(self, damageReport);
                Networking._instance.IsArtifactEnabled      = RunArtifactManager.instance.IsArtifactEnabled(ArtifactOfDoom.Transmutation.artifactIndex);
                Networking._instance.IsCalculationSacrifice = ArtifactOfDoomConfig.useArtifactOfSacrificeCalculation.Value;

                if (!Networking._instance.IsArtifactEnabled)
                {
                    return;
                }
                if (Run.instance.isGameOverServer)
                {
                    return;
                }
                if (damageReport.victimBody.isPlayerControlled)
                {
                    return;
                }
                if (damageReport.attackerBody == null)
                {
                    return;
                }
                if (damageReport.attackerBody.inventory == null)
                {
                    return;
                }
                if (damageReport.victimBody.inventory == null)
                {
                    return;
                }

                if (damageReport.attackerOwnerMaster != null)
                {
                    if (!Playername.Contains(damageReport.attackerBody))
                    {
                        Playername.Add(damageReport.attackerOwnerMaster.GetBody());
                        counter.Add(0);
                    }
                }
                if (!Playername.Contains(damageReport.attackerBody))
                {
                    Playername.Add(damageReport.attackerBody);
                    counter.Add(0);
                }

                CharacterBody currentBody;
                if (damageReport.attackerOwnerMaster != null)
                {
                    currentBody = damageReport.attackerOwnerMaster.GetBody();
                }
                else
                {
                    currentBody = damageReport.attackerBody;
                }
                if (!currentBody.isPlayerControlled)
                {
                    return;
                }

                uint pos = 0;

                int  calculatesEnemyCountToTrigger = calculateEnemyCountToTrigger(currentBody.inventory);
                bool enemyTrigger = getEnemyDropRate(damageReport);
                if (counter[Playername.IndexOf(currentBody)] <= calculatesEnemyCountToTrigger && !ArtifactOfDoomConfig.useArtifactOfSacrificeCalculation.Value)
                {
                    counter[Playername.IndexOf(currentBody)]++;

                    NetworkUser tempNetworkUser = getNetworkUserOfDamageReport(damageReport, true);
                    string      temp            = counter[Playername.IndexOf(currentBody)] + "," + calculatesEnemyCountToTrigger;
                    //Debug.LogWarning("tempNetworkUser: "******"temp: " + temp);
                    if (NetworkServer.active)
                    {
                        Networking.ServerEnsureNetworking();
                        Networking._instance.TargetUpdateProgressBar(tempNetworkUser.connectionToClient, temp);
                    }
                }
                else
                {
                    if (ArtifactOfDoomConfig.useArtifactOfSacrificeCalculation.Value && !enemyTrigger)
                    {
                        return;
                    }
                    CharacterBody body;

                    if (damageReport.attackerOwnerMaster != null)
                    {
                        body = damageReport.attackerOwnerMaster.GetBody();

                        double chanceToTrigger = getCharacterSpezificBuffLengthMultiplier(body.baseNameToken);
                        chanceToTrigger *= 100;
                        var rand = new System.Random();
                        while (chanceToTrigger > rand.Next(0, 99))
                        {
                            ItemIndex addedItem = GiveAndReturnRandomItem(body.inventory);
                            if (ArtifactOfDoomConfig.enableChatItemOutput.Value)
                            {
                                var pickupDef   = ItemCatalog.GetItemDef(addedItem);
                                var pickupName  = Language.GetString(pickupDef.nameToken);
                                var playerColor = damageReport.attackerOwnerMaster.GetBody().GetColoredUserName();
                                var itemCount   = damageReport.attackerOwnerMaster.GetBody().inventory.GetItemCount(pickupDef.itemIndex);
                                Chat.SendBroadcastChat(new Chat.SimpleChatMessage
                                {
                                    baseToken =
                                        damageReport.attackerOwnerMaster.GetBody().GetColoredUserName() + $"<color=#{GrayColor}> gained</color> " +
                                        $"{pickupName ?? "???"} ({itemCount})</color> <color=#{GrayColor}></color>"
                                });
                            }
                            PlayerStatsComponent.FindBodyStatSheet(body).PushStatValue(statsGainItems, 1UL);
                            if (QueueGainedItemSprite.ContainsKey(body.netId.Value))
                            {
                                pos = body.netId.Value;
                            }
                            else
                            {
                                QueueGainedItemSprite.Add(body.netId.Value, new Queue <ItemDef>());
                                pos = body.netId.Value;
                            }
                            QueueGainedItemSprite[pos].Enqueue(ItemCatalog.GetItemDef(addedItem));
                            chanceToTrigger -= 100;
                        }
                    }
                    else
                    {
                        body = damageReport.attackerBody;
                        double chanceToTrigger = getCharacterSpezificItemCount(body.baseNameToken);
                        chanceToTrigger *= 100;
                        var rand = new System.Random();
                        while (chanceToTrigger > rand.Next(0, 99))
                        {
                            ItemIndex addedItem = GiveAndReturnRandomItem(body.inventory);
                            if (ArtifactOfDoomConfig.enableChatItemOutput.Value)
                            {
                                var pickupDef   = ItemCatalog.GetItemDef(addedItem);
                                var pickupName  = Language.GetString(pickupDef.nameToken);
                                var playerColor = body.GetColoredUserName();
                                var itemCount   = body.inventory.GetItemCount(pickupDef.itemIndex);
                                Chat.SendBroadcastChat(new Chat.SimpleChatMessage
                                {
                                    baseToken =
                                        body.GetColoredUserName() + $"<color=#{GrayColor}> gained</color> " +
                                        $"{pickupName ?? "???"} ({itemCount})</color> <color=#{GrayColor}></color>"
                                });
                            }
                            PlayerStatsComponent.FindBodyStatSheet(body).PushStatValue(statsGainItems, 1UL);
                            if (QueueGainedItemSprite.ContainsKey(body.netId.Value))
                            {
                                pos = body.netId.Value;
                            }
                            else
                            {
                                try
                                {
                                    QueueGainedItemSprite.Add(body.netId.Value, new Queue <ItemDef>());
                                    pos = body.netId.Value;
                                }
                                catch (Exception)
                                {
                                    Debug.LogError("[SirHamburger ArtifactOfDoom] Error while excecuting : QueueGainedItemSprite.Add(body.netId.Value, new Queue<Sprite>()); (line 203)");
                                }
                            }
                            QueueGainedItemSprite[pos].Enqueue(ItemCatalog.GetItemDef(addedItem));
                            chanceToTrigger -= 100;
                        }
                    }

                    if (QueueGainedItemSprite[pos].Count > 10)
                    {
                        QueueGainedItemSprite[pos].Dequeue();
                    }
                    string temp = "";
                    foreach (var element in QueueGainedItemSprite[pos])
                    {
                        temp += element.name + " ";
                    }

                    NetworkUser tempNetworkUser = getNetworkUserOfDamageReport(damageReport, true);

                    if (!LockItemGainNetworkUser.ContainsKey(tempNetworkUser))
                    {
                        LockItemGainNetworkUser.Add(tempNetworkUser, false);
                    }
                    counter[Playername.IndexOf(currentBody)]++;


                    if (!LockItemGainNetworkUser[tempNetworkUser])
                    {
                        LockItemGainNetworkUser[tempNetworkUser] = false;

                        LockItemGainNetworkUser[tempNetworkUser] = false;
                        string tempString = counter[Playername.IndexOf(currentBody)] + "," + calculatesEnemyCountToTrigger;
                        if (NetworkServer.active)
                        {
                            Networking._instance.TargetAddGainedItemsToPlayers(tempNetworkUser.connectionToClient, temp);
                            Networking.ServerEnsureNetworking();
                            Networking._instance.TargetUpdateProgressBar(tempNetworkUser.connectionToClient, tempString);
                        }
                    }

                    counter[Playername.IndexOf(currentBody)] = 0;
                }
            };
            On.RoR2.HealthComponent.TakeDamage += (orig, self, damageinfo) =>
            {
                //For adding possibility to dont loose items for some time: characterBody.AddTimedBuff(BuffIndex.Immune, duration);
                orig(self, damageinfo);
                //BuffIndex buff = new BuffIndex();
                //Debug.LogError("buffindex " +buff );
//
                //BuffCatalog.FindBuffIndex("ArtifactOfDoomDidLoseItem");
                //                Debug.LogError("buffindex " +buff );


                if (!Networking._instance.IsArtifactEnabled)
                {
                    return;
                }

                if (damageinfo.rejected)
                {
                    //Debug.Log("Teddie?");
                    return;
                }

                if (debug)
                {
                    Debug.LogWarning("Line 336");
                }

                if (self.body == null)
                {
                    if (debug)
                    {
                        Debug.LogWarning("self.body == null)");
                    }
                    return;
                }

                if (self.body.inventory == null)
                {
                    if (debug)
                    {
                        Debug.LogWarning("self.body.inventory == null)");
                    }
                    return;
                }

                if (Run.instance.isGameOverServer)
                {
                    if (debug)
                    {
                        Debug.LogWarning("RoR2.Run.instance.isGameOverServer)");
                    }
                    return;
                }

                if (damageinfo == null)
                {
                    if (debug)
                    {
                        Debug.LogWarning("damageinfo == null)");
                    }
                    return;
                }

                if (damageinfo.attacker == null)
                {
                    if (debug)
                    {
                        Debug.LogWarning("damageinfo.attacker.name==null)");
                    }
                    return;
                }
                if (self.body.HasBuff(ArtifactOfDoomConfig.ArtifactOfDoomBuff))
                {
                    if (debug)
                    {
                        Debug.LogWarning("you did lose an item not long ago so you don't lose one now");
                    }
                    return;
                }

                int totalItems = getTotalItemCountOfPlayer(self.body.inventory);
                if (self.body.isPlayerControlled && (totalItems > 0) && self.name != damageinfo.attacker.name)
                {
                    Dictionary <ItemIndex, int> lstItemIndex = new Dictionary <ItemIndex, int>();
                    List <ItemIndex>            index        = new List <ItemIndex>();
                    foreach (var element in ItemCatalog.allItems)
                    {
                        if (self.body.inventory.GetItemCount(element) > 0)
                        {
                            lstItemIndex.Add(element, self.body.inventory.GetItemCount(element));
                            index.Add(element);
                        }
                    }

                    double chanceToTrigger = 100.0;
                    if (totalItems <= (ArtifactOfDoomConfig.minItemsPerStage.Value * currentStage))
                    {
                        //chanceToTrigger = 1.0 - (double)(ArtifactOfDoomConfig.minItemsPerStage.Value * currentStage - totalItems) / ((double)ArtifactOfDoomConfig.minItemsPerStage.Value * currentStage);
                        chanceToTrigger  = (double)Math.Sqrt((double)totalItems / ((double)currentStage * (double)ArtifactOfDoomConfig.minItemsPerStage.Value));
                        chanceToTrigger *= 100;
                    }
                    //Debug.LogError("ChanceToTriggerLoose_Item"+ chanceToTrigger);

                    var rand = new System.Random();

                    for (int i = 0; i < self.body.inventory.GetItemCount(RoR2.RoR2Content.Items.Clover) + 1; i++)
                    {
                        int randomValue = rand.Next(1, 100);

                        if (chanceToTrigger < randomValue)
                        {
                            return;
                        }
                    }

                    chanceToTrigger = 100.0;

                    if (totalItems > (ArtifactOfDoomConfig.maxItemsPerStage.Value * currentStage))
                    {
                        chanceToTrigger  = Math.Pow((double)(totalItems) / ((double)ArtifactOfDoomConfig.maxItemsPerStage.Value * currentStage), ArtifactOfDoomConfig.exponentailFactorToCalculateSumOfLostItems.Value);
                        chanceToTrigger *= 100;
                    }

                    int lostItems = 0;

                    uint pos = 50000;

                    while (chanceToTrigger > 0)
                    {
                        if (QueueLostItemSprite.ContainsKey(self.body.netId.Value))
                        {
                            pos = self.body.netId.Value;
                        }
                        else
                        {
                            try
                            {
                                QueueLostItemSprite.Add(self.body.netId.Value, new Queue <ItemDef>());
                                pos = self.body.netId.Value;
                            }
                            catch (Exception)
                            {
                                Debug.Log($"[SirHamburger ArtifactOfDoom] Error in Line 311");
                            }
                        }
                        if (chanceToTrigger < rand.Next(0, 99))
                        {
                            break;
                        }
                        lostItems++;
                        int       randomPosition = rand.Next(0, lstItemIndex.Count - 1);
                        ItemIndex itemToRemove   = index[randomPosition];
                        while ((lstItemIndex[itemToRemove] == 0))
                        {
                            randomPosition = rand.Next(0, lstItemIndex.Count - 1);
                            itemToRemove   = index[randomPosition];
                        }
                        lstItemIndex[itemToRemove]--;

                        if (!ItemCatalog.lunarItemList.Contains(itemToRemove) && (ItemCatalog.GetItemDef(itemToRemove).tier != ItemTier.NoTier && itemToRemove != RoR2.RoR2Content.Items.CaptainDefenseMatrix.itemIndex))
                        {
                            self.body.inventory.RemoveItem(itemToRemove, 1);

                            //Chat.AddPickupMessage(self.body,itemToRemove,self.body.GetColoredUserName,PickupCatalog.GetPickupDef(itemToRemove).)

                            if (ArtifactOfDoomConfig.enableChatItemOutput.Value)
                            {
                                var pickupDef   = ItemCatalog.GetItemDef(itemToRemove);
                                var pickupName  = Language.GetString(pickupDef.nameToken);
                                var playerColor = self.body.GetColoredUserName();
                                var itemCount   = self.body.inventory.GetItemCount(pickupDef.itemIndex);
                                Chat.SendBroadcastChat(new Chat.SimpleChatMessage
                                {
                                    baseToken =
                                        self.body.GetColoredUserName() + $"<color=#{GrayColor}> lost</color> " +
                                        $"{pickupName ?? "???"} ({itemCount})</color> <color=#{GrayColor}></color>"

                                        //baseToken = self.body.GetColoredUserName() + " lost " + Language.GetString(ItemCatalog.GetItemDef(itemToRemove).pickupToken)
                                });
                            }
                            PlayerStatsComponent.FindBodyStatSheet(self.body).PushStatValue(statsLostItems, 1UL);


                            QueueLostItemSprite[pos].Enqueue(ItemCatalog.GetItemDef(itemToRemove));
                            if (QueueLostItemSprite[pos].Count > 10)
                            {
                                QueueLostItemSprite[pos].Dequeue();
                            }

                            double buffLengthMultiplier = getCharacterSpezificBuffLengthMultiplier(self.body.baseNameToken);
                            self.body.AddTimedBuff(ArtifactOfDoomConfig.ArtifactOfDoomBuff, (float)(timeForBuff * (float)buffLengthMultiplier));
                        }

                        chanceToTrigger -= 100;
                    }

                    string temp = "";
                    foreach (var element in ArtifactOfDoom.QueueLostItemSprite[pos])
                    {
                        temp += element.name + " ";
                    }
                    NetworkUser tempNetworkUser = getNetworkUserOfCharacterBody(self.body);

                    if (tempNetworkUser == null)
                    {
                        Debug.LogError("--------------------------------tempNetworkUser(lostitems)==null---------------------------");
                    }
                    if (!LockNetworkUser.ContainsKey(tempNetworkUser))
                    {
                        LockNetworkUser.Add(tempNetworkUser, false);
                    }
                    if (LockNetworkUser[tempNetworkUser] == false)
                    {
                        LockNetworkUser[tempNetworkUser] = false;
                        int    calculatesEnemyCountToTrigger = calculateEnemyCountToTrigger(self.body.inventory);
                        string tempString = counter[Playername.IndexOf(self.body)] + "," + calculatesEnemyCountToTrigger;
                        if (NetworkServer.active)
                        {
                            Networking._instance.TargetAddLostItemsOfPlayers(tempNetworkUser.connectionToClient, temp);
                            Networking.ServerEnsureNetworking();
                            Networking._instance.TargetUpdateProgressBar(tempNetworkUser.connectionToClient, tempString);
                        }
                    }
                }
            };
        }