public static void ReplaceProjectile(NetCollection <Projectile> projectiles, Projectile original) { //Log.Debug($"RSV: Entered transpiler, woohoo!"); NetCharacterRef firerInfo = Helper.Reflection.GetField <NetCharacterRef>(original, "theOneWhoFiredMe").GetValue(); Monster monster = (Monster)firerInfo.Get(Game1.currentLocation); try { if (monster.modData["RSV_bloomDebuff"] != "true") { projectiles.Add(original); return; } } catch { projectiles.Add(original); return; } float xVelocity = Helper.Reflection.GetField <NetFloat>(original, "xVelocity").GetValue().Value; float yVelocity = Helper.Reflection.GetField <NetFloat>(original, "yVelocity").GetValue().Value; monster.currentLocation.projectiles.Add(new MistProjectile(rotation, xVelocity, yVelocity, monster.Position + new Vector2(0f, -32f), monster.currentLocation, monster)); }
/// <summary>Patch for Rascal slingshot damage increase with travel time.</summary> private static bool BasicProjectileBehaviorOnCollisionWithMonsterPrefix(ref BasicProjectile __instance, ref NetBool ___damagesMonsters, ref NetCharacterRef ___theOneWhoFiredMe, ref int ___travelTime, NPC n, GameLocation location) { try { if (!___damagesMonsters || n is not Monster) { return(true); // run original logic } var who = ___theOneWhoFiredMe.Get(location) is Farmer ? ___theOneWhoFiredMe.Get(location) as Farmer : Game1.player; if (!Utility.SpecificPlayerHasProfession("Rascal", who)) { return(true); // run original logic } AwesomeProfessions.Reflection.GetMethod(__instance, name: "explosionAnimation")?.Invoke(location); var damageToMonster = (int)(__instance.damageToFarmer.Value * Utility.GetRascalBonusDamageForTravelTime(___travelTime)); location.damageMonster(n.GetBoundingBox(), damageToMonster, damageToMonster + 1, isBomb: false, who); return(false); // don't run original logic } catch (Exception ex) { Monitor.Log($"Failed in {nameof(BasicProjectileBehaviorOnCollisionWithMonsterPrefix)}:\n{ex}", LogLevel.Error); return(true); // default to original logic } }
/// <summary>Patch for Rascal chance to recover ammunition.</summary> private static void ProjectileBehaviorOnCollisionPostfix(ref Projectile __instance, ref NetInt ___currentTileSheetIndex, ref NetPosition ___position, ref NetCharacterRef ___theOneWhoFiredMe, GameLocation location) { try { if (__instance is not BasicProjectile) { return; } var firer = ___theOneWhoFiredMe.Get(location) is Farmer ? (Farmer)___theOneWhoFiredMe.Get(location) : Game1.player; if (!Utility.SpecificPlayerHasProfession("Rascal", firer)) { return; } if (Utility.IsMineralAmmunition(___currentTileSheetIndex.Value) && Game1.random.NextDouble() < 0.6 || ___currentTileSheetIndex.Value == SObject.wood + 1 && Game1.random.NextDouble() < 0.3) { location.debris.Add(new Debris(___currentTileSheetIndex.Value - 1, new Vector2((int)___position.X, (int)___position.Y), firer.getStandingPosition())); } } catch (Exception ex) { Monitor.Log($"Failed in {nameof(ProjectileBehaviorOnCollisionPostfix)}:\n{ex}"); } }