Ejemplo n.º 1
0
        public static void AddExplosionForce(CharacterMotor body, float explosionForce, Vector3 explosionPosition, float explosionRadius, float upliftModifier = 0, bool useWearoff = false)
        {
            var dir = (body.transform.position - explosionPosition);

            Vector3 baseForce = Vector3.zero;

            if (useWearoff)
            {
                float wearoff = 1 - (dir.magnitude / explosionRadius);
                baseForce = dir.normalized * explosionForce * wearoff;
            }
            else
            {
                baseForce = dir.normalized * explosionForce;
            }
            //baseForce.z = 0;
            body.ApplyForce(baseForce);

            //if (upliftModifier != 0)
            //{
            float   upliftWearoff = 1 - upliftModifier / explosionRadius;
            Vector3 upliftForce   = Vector2.up * explosionForce * upliftWearoff;

            //upliftForce.z = 0;
            body.ApplyForce(upliftForce);
            //}
        }
Ejemplo n.º 2
0
        // Token: 0x06002AE9 RID: 10985 RVA: 0x000B4B1C File Offset: 0x000B2D1C
        private static void PullEnemies(Vector3 position, Vector3 direction, float coneAngle, float maxDistance, float force, TeamIndex excludedTeam)
        {
            float num = Mathf.Cos(coneAngle * 0.5f * 0.017453292f);

            foreach (Collider collider in Physics.OverlapSphere(position, maxDistance))
            {
                Vector3 position2  = collider.transform.position;
                Vector3 normalized = (position - position2).normalized;
                if (Vector3.Dot(-normalized, direction) >= num)
                {
                    TeamComponent component = collider.GetComponent <TeamComponent>();
                    if (component)
                    {
                        TeamIndex teamIndex = component.teamIndex;
                        if (teamIndex != excludedTeam)
                        {
                            CharacterMotor component2 = collider.GetComponent <CharacterMotor>();
                            if (component2)
                            {
                                component2.ApplyForce(normalized * force, false, false);
                            }
                            Rigidbody component3 = collider.GetComponent <Rigidbody>();
                            if (component3)
                            {
                                component3.AddForce(normalized * force, ForceMode.Impulse);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static void CharacterMotor_OnHitGround(On.RoR2.CharacterMotor.orig_OnHitGround orig, CharacterMotor self, CharacterMotor.HitGroundInfo hitGroundInfo)
        {
            bool hasGoombad        = false;
            bool restoreFallDamage = false;

            if (RunArtifactManager.instance.IsArtifactEnabled(GoombaArtifactDef.artifactIndex))
            {
                if (self.body)
                {
                    if (Math.Abs(hitGroundInfo.velocity.y) >= minFallSpeed)
                    {
                        Chat.AddMessage("Speed: " + Math.Abs(hitGroundInfo.velocity.y) + "/" + minFallSpeed);
                        var bodySearch = new BullseyeSearch() //let's just get the nearest player
                        {
                            viewer         = self.body,
                            sortMode       = BullseyeSearch.SortMode.Distance,
                            teamMaskFilter = TeamMask.GetEnemyTeams(self.body.teamComponent.teamIndex),
                        };
                        bodySearch.RefreshCandidates();
                        Debug.Log("Nearest Enemies: " + bodySearch.GetResults().ToList());

                        var nearestBody = bodySearch.GetResults().ToList();

                        // We very likely landed on an enemy.
                        if (nearestBody.Count > 0)
                        {
                            var firstBody = nearestBody.FirstOrDefault();
                            var distance  = Vector3.Distance(hitGroundInfo.position, Helpers.GetHeadPosition(firstBody.healthComponent.body));
                            if (distance <= maxDistance)
                            {
                                goombaDamageInfo.attacker = self.body.gameObject;
                                firstBody.healthComponent.TakeDamage(goombaDamageInfo);
                                if ((self.body.bodyFlags & CharacterBody.BodyFlags.IgnoreFallDamage) == CharacterBody.BodyFlags.None)
                                {
                                    self.body.bodyFlags |= CharacterBody.BodyFlags.IgnoreFallDamage;
                                    restoreFallDamage    = true;
                                }
                                Chat.AddMessage("Goomba!");
                                hasGoombad = true;
                            }
                        }
                    }
                }
            }
            orig(self, hitGroundInfo);
            if (hasGoombad)
            {
                self.Motor.ForceUnground();
                self.ApplyForce(Vector3.up * bounceForce);
            }
            if (restoreFallDamage)
            {
                self.body.bodyFlags &= ~CharacterBody.BodyFlags.IgnoreFallDamage;
            }
        }
Ejemplo n.º 4
0
        private void CharacterMotor_OnHitGroundServer(On.RoR2.CharacterMotor.orig_OnHitGroundServer orig, CharacterMotor self, CharacterMotor.HitGroundInfo hitGroundInfo)
        {
            if (!RunArtifactManager.instance.IsArtifactEnabled(GoombaArtifactDef.artifactIndex))
            {
                orig(self, hitGroundInfo);
                return;
            }

            bool hasGoombad        = false;
            bool restoreFallDamage = false;
            var  goombaComponent   = self.GetComponent <GoombaComponent>();

            if (self.body)
            {
                if (goombaComponent.inGoombaState || Math.Abs(hitGroundInfo.velocity.y) >= minFallSpeed.Value)
                {
                    TeamMask teamMask = TeamMask.GetEnemyTeams(self.body.teamComponent.teamIndex);
                    if (FriendlyFireManager.friendlyFireMode != FriendlyFireManager.FriendlyFireMode.Off && friendlyFire.Value)
                    {
                        teamMask = TeamMask.allButNeutral;
                    }
                    //Chat.AddMessage("Speed: " + Math.Abs(hitGroundInfo.velocity.y) + "/" + minFallSpeed);
                    var enemySearch = new BullseyeSearch()
                    {
                        filterByDistinctEntity = false,
                        filterByLoS            = false,
                        maxDistanceFilter      = maxDistance.Value,
                        minDistanceFilter      = 0f,
                        minAngleFilter         = 0f,
                        maxAngleFilter         = angleCheck.Value,
                        teamMaskFilter         = teamMask,
                        sortMode        = BullseyeSearch.SortMode.Distance,
                        viewer          = self.body,
                        searchDirection = Vector3.down,
                        searchOrigin    = hitGroundInfo.position
                    };
                    enemySearch.RefreshCandidates();
                    var listOfEnemies = enemySearch.GetResults().ToList();

                    /*var str = "Nearest Enemies: ";
                     *
                     * foreach(var enemy in listOfEnemies)
                     * {
                     *  if (enemy)
                     *      str += enemy.healthComponent.body.GetDisplayName() + ", ";
                     * }
                     * Debug.Log(str);*/

                    HurtBox enemyHurtbox = GetValidEnemy(listOfEnemies);
                    if (enemyHurtbox)
                    {
                        //var headPos = Helpers.GetHeadPosition(enemyHurtbox.healthComponent.body);
                        //var distance = Vector3.Distance(hitGroundInfo.position, headPos);
                        //Chat.AddMessage("Distance to enemy is "+ distance);
                        goombaComponent.inGoombaState = true;
                        if (enemyHurtbox.healthComponent != goombaComponent.currentHealthComponent)
                        {
                            goombaComponent.bounces = 1;
                            goombaComponent.currentHealthComponent = enemyHurtbox.healthComponent;
                        }
                        enemyHurtbox.healthComponent.TakeDamage(new DamageInfo()
                        {
                            attacker         = self.body.gameObject,
                            damage           = multiplyDmgPerBounce.Value ? goombaDamage.Value * goombaComponent.bounces : goombaDamage.Value,
                            inflictor        = goombaGameObject,
                            position         = hitGroundInfo.position,
                            damageColorIndex = DamageColorIndex.Bleed
                        });
                        if ((self.body.bodyFlags & CharacterBody.BodyFlags.IgnoreFallDamage) == CharacterBody.BodyFlags.None)
                        {
                            self.body.bodyFlags |= CharacterBody.BodyFlags.IgnoreFallDamage;
                            restoreFallDamage    = true;
                        }
                        if (goombaInChat.Value)
                        {
                            Chat.AddMessage("Goomba!");
                        }
                        hasGoombad = true;
                    }
                }
            }

            orig(self, hitGroundInfo);
            if (hasGoombad)
            {
                self.Motor.ForceUnground();
                self.ApplyForce(Vector3.up * bounceForce.Value);
                goombaComponent.bounces++;
            }
            else
            {
                goombaComponent.ExitGoombaState();
            }
            if (restoreFallDamage)
            {
                self.body.bodyFlags &= ~CharacterBody.BodyFlags.IgnoreFallDamage;
            }
        }