Exemplo n.º 1
0
        public static bool Postfix(bool __result, Projectile __instance, GameLocation location)
        {
            bool damagesMonsters = ModEntry.BRGame.ModHelper.Reflection.GetField <NetBool>(__instance, "damagesMonsters").GetValue().Value;

            if (!__result && (!(__instance is BasicProjectile bp) || bp.damageToFarmer.Value < 20))
            {
                Rectangle r = __instance.getBoundingBox();
                foreach (Farmer farmer in location.farmers.Where(x => x != null))
                {
                    var bounds = SlingshotPatch5.GetFarmerBounds(farmer);


                    if (bounds.Intersects(r))
                    {
                        Console.WriteLine("Collide with farmer");
                        //__result = true;
                        return(true);
                    }
                }
            }

            if (!__result)
            {
                //  x / Game1.tileSize, y / Game1.tileSize
                var center     = __instance.getBoundingBox().Center;
                var centerTile = new Vector2((int)(center.X / Game1.tileSize), (int)(center.Y / Game1.tileSize));
                if (location.objects.TryGetValue(centerTile, out StardewValley.Object obj) && obj.Name.ToLower().Contains("fence"))
                {
                    //__result = true;
                    return(true);
                }
            }

            return(__result);
        }
Exemplo n.º 2
0
        public static bool Prefix(BasicProjectile __instance, GameLocation location, Farmer player)
        {
            bool damagesMonsters = ModEntry.BRGame.ModHelper.Reflection.GetField <NetBool>(__instance, "damagesMonsters").GetValue().Value;

            Console.WriteLine($"damage, m = {damagesMonsters}");
            if (!damagesMonsters || true && SlingshotPatch5.GetFarmerBounds(player).Intersects(__instance.getBoundingBox()))            //TODO: remove?
            {
                //TODO: modify slingshot damage here?
                int damage = __instance.damageToFarmer.Value;
                damage = Math.Min(damage, 10);

                if (player == Game1.player)
                {
                    Console.WriteLine("sending slingshot damage to self");
                    ModEntry.BRGame.TakeDamage(damage);
                }
                else
                {
                    Console.WriteLine("sending slingshot damage to other player");
                    NetworkUtility.SendDamageToPlayer(damage, player, Game1.player.UniqueMultiplayerID);
                }

                try
                {
                    if (!HitShaker.IsPlayerFlashing(player.UniqueMultiplayerID))
                    {
                        var r = ModEntry.BRGame.ModHelper.Reflection;
                        r.GetMethod(__instance, "explosionAnimation", false)?.Invoke(location);
                    }
                }
                catch (Exception) { }
            }
            return(false);
        }