Ejemplo n.º 1
0
            static bool Prefix(Projectile __instance)
            {
                if (!Enabled)
                {
                    return(true);
                }

                var projectile = __instance;

                var ticksToImpact         = (int)TicksToImpactField.GetValue(projectile);
                var startingTicksToImpact = (int)StartingTicksToImpactProperty.GetValue(projectile, null);

                var origin      = Common.ToVector2((Vector3)OriginField.GetValue(projectile));
                var destination = Common.ToVector2((Vector3)DestinationField.GetValue(projectile));
                var position    = Vector2.Lerp(origin, destination, 1.0f - ticksToImpact / (float)startingTicksToImpact);

                try
                {
                    if (projectile.def.projectile.flyOverhead)
                    {
                        // the shield has blocked the projectile - invert to get if harmony should allow the original block
                        return(!Mod.ShieldManager.ImpactShield(projectile.Map, position, origin, destination, (shield, vector2) =>
                        {
                            if (shield.Damage(projectile.def.projectile.GetDamageAmount(1f), position))
                            {
                                projectile.Destroy();
                                return true;
                            }
                            return false;
                        }));
                    }

                    var ray = new Ray2D(position, Vector2.Lerp(origin, destination, 1.0f - (ticksToImpact - 1) / (float)startingTicksToImpact));
                    Mod.ShieldManager.ImpactShield(projectile.Map, origin, ray, 1, (shield, point) =>
                    {
                        if (shield.Damage(projectile.def.projectile.GetDamageAmount(1f), point))
                        {
                            DestinationField.SetValue(projectile, Common.ToVector3(point, projectile.def.Altitude));
                            TicksToImpactField.SetValue(projectile, 0);
                            UsedTargetField.SetValue(projectile, null);
                            IntendedTargetField.SetValue(projectile, null);
                            return(true);
                        }
                        return(false);
                    });
                }
                catch (InvalidOperationException) {}
                return(true);
            }