Beispiel #1
0
        private void GenerateSphereSearch(CharacterBody origin, bool getSameTeam = false)
        {
            List <HurtBox> hurtBoxesList = new List <HurtBox>();
            TeamMask       enemyTeams    = TeamMask.GetEnemyTeams(origin.teamComponent.teamIndex);
            SphereSearch   sphereSearch  = new RoR2.SphereSearch()
            {
                mask   = LayerIndex.entityPrecise.mask,
                origin = origin.transform.position,
                queryTriggerInteraction = QueryTriggerInteraction.Collide,
                radius = sphereSearchRadius
            };

#if DEBUG
            TurboEdition._logger.LogWarning(EquipmentName + ": generated " + sphereSearch + " with radius " + sphereSearchRadius + " and origin " + origin.transform);
#endif
            if (!getSameTeam)
            {
#if DEBUG
                TurboEdition._logger.LogWarning(EquipmentName + ": filtering the sphereSearch by enemy teams.");
#endif
                sphereSearch.RefreshCandidates().FilterCandidatesByHurtBoxTeam(enemyTeams).FilterCandidatesByDistinctHurtBoxEntities().GetHurtBoxes(hurtBoxesList);
            }
            else
            {
#if DEBUG
                TurboEdition._logger.LogWarning(EquipmentName + ": filtering the sphereSearch by SAME TEAM as origin.");
#endif
                TeamMask selfdestructionguaranteed = new TeamMask();
                selfdestructionguaranteed.AddTeam(origin.teamComponent.teamIndex);
                sphereSearch.RefreshCandidates().FilterCandidatesByHurtBoxTeam(selfdestructionguaranteed).FilterCandidatesByDistinctHurtBoxEntities().GetHurtBoxes(hurtBoxesList);
            }

            for (int i = 0, j = 0; i < hurtBoxesList.Count && j < sphereLinkCount; i++)
            {
                var hc = hurtBoxesList[i].healthComponent;
                if (hc)
                {
                    var body = hc.body;
                    if (body)
                    {
                        var linkGameObject = body.GetComponentInChildren <LinkComponent>()?.gameObject;
#if DEBUG
                        TurboEdition._logger.LogWarning(EquipmentName + ": adding linkedBuff to someone, theres " + (i + 1) + " out of " + hurtBoxesList.Count + " hurtboxes with max " + sphereLinkCount);
#endif
                        body.AddTimedBuff(linkedBuff, linkedBuffDuration);
                        if (!linkGameObject)
                        {
                            //If they dont have a component that means they are brand new and unique
                            //If they do, this doesn't get executed and they just get their debuff updated
                            j++;
                        }
                    }
                }
            }
        }
 public void FixedUpdate()
 {
     if (!Body.HasBuff(EliteBuffIndex))
     {
         UnityEngine.Object.Destroy(Overlay);
         UnityEngine.Object.Destroy(this);
     }
     if (PulseTimer > 0)
     {
         PulseTimer -= Time.fixedDeltaTime;
         if (PulseTimer <= 0)
         {
             RoR2.TeamMask  enemyTeams = RoR2.TeamMask.GetEnemyTeams(Body.teamComponent.teamIndex);
             RoR2.HurtBox[] hurtBoxes  = new RoR2.SphereSearch
             {
                 radius = 40,
                 mask   = RoR2.LayerIndex.entityPrecise.mask,
                 origin = Body.corePosition
             }.RefreshCandidates().FilterCandidatesByHurtBoxTeam(enemyTeams).OrderCandidatesByDistance().FilterCandidatesByDistinctHurtBoxEntities().GetHurtBoxes();
             foreach (RoR2.HurtBox enemyHurtbox in hurtBoxes)
             {
                 var enemyHealthComponent = enemyHurtbox.healthComponent;
                 if (enemyHealthComponent)
                 {
                     var enemyBody = enemyHealthComponent.body;
                     if (enemyBody)
                     {
                         RaycastHit raycastHit;
                         var        rayCast = RoR2.Util.CharacterRaycast(Body.gameObject, new Ray(Body.corePosition, enemyBody.corePosition - Body.corePosition), out raycastHit, 40, RoR2.LayerIndex.entityPrecise.mask | RoR2.LayerIndex.world.mask, QueryTriggerInteraction.Ignore);
                         if (rayCast && raycastHit.collider)
                         {
                             var hurtbox = raycastHit.collider.GetComponent <RoR2.HurtBox>();
                             if (hurtbox && hurtbox.healthComponent)
                             {
                                 var body = hurtbox.healthComponent.body;
                                 if (body == enemyBody)
                                 {
                                     if (NetworkServer.active)
                                     {
                                         RoR2.EffectManager.SimpleEffect(Resources.Load <GameObject>("Prefabs/Effects/ImpactEffects/IgniteExplosionVFX"), enemyBody.corePosition, RoR2.Util.QuaternionSafeLookRotation(Body.corePosition - enemyBody.corePosition), true);
                                     }
                                     RoR2.DotController.InflictDot(enemyBody.gameObject, Body.gameObject, RoR2.DotController.DotIndex.Burn, 2);
                                 }
                             }
                         }
                     }
                 }
             }
             PulseTimer = 1;
         }
     }
 }
        /// <summary>
        /// Returns a point above a hit enemy at the distance specified. If it collides with the world before that point, it returns that point instead.
        /// </summary>
        /// <param name="damageInfo"></param>
        /// <param name="distanceAboveTarget"></param>
        /// <returns></returns>
        public static Vector3?AboveTargetVectorFromDamageInfo(DamageInfo damageInfo, float distanceAboveTarget)
        {
            if (damageInfo.rejected || !damageInfo.attacker)
            {
                return(null);
            }


            var attackerBody = damageInfo.attacker.GetComponent <CharacterBody>();

            if (attackerBody)
            {
                RoR2.TeamMask enemyTeams = RoR2.TeamMask.GetEnemyTeams(attackerBody.teamComponent.teamIndex);
                HurtBox       hurtBox    = new RoR2.SphereSearch
                {
                    radius = 1,
                    mask   = RoR2.LayerIndex.entityPrecise.mask,
                    origin = damageInfo.position
                }.RefreshCandidates().FilterCandidatesByHurtBoxTeam(enemyTeams).OrderCandidatesByDistance().FilterCandidatesByDistinctHurtBoxEntities().GetHurtBoxes().FirstOrDefault();

                if (hurtBox)
                {
                    if (hurtBox.healthComponent && hurtBox.healthComponent.body)
                    {
                        var body = hurtBox.healthComponent.body;

                        var closestPointOnBounds = body.mainHurtBox.collider.ClosestPointOnBounds(body.transform.position + new Vector3(0, 10000, 0));

                        var raycastPoint = RaycastToDirection(closestPointOnBounds, distanceAboveTarget, Vector3.up, LayerIndex.world.mask);
                        if (raycastPoint.HasValue)
                        {
                            return(raycastPoint.Value);
                        }
                        else
                        {
                            return(closestPointOnBounds + (Vector3.up * distanceAboveTarget));
                        }
                    }
                }
            }

            return(null);
        }
        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);
        }