Play different sound if the object is up, left, etc.
parent
2b59c6759d
commit
b9a10e6039
|
@ -39,6 +39,7 @@ namespace stardew_access.Game
|
||||||
|
|
||||||
public async void run()
|
public async void run()
|
||||||
{
|
{
|
||||||
|
MainClass.monitor.Log($"\n\nRead Tile started", StardewModdingAPI.LogLevel.Debug);
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
Vector2 currPosition = Game1.player.getTileLocation();
|
Vector2 currPosition = Game1.player.getTileLocation();
|
||||||
int limit = 5;
|
int limit = 5;
|
||||||
|
@ -48,6 +49,7 @@ namespace stardew_access.Game
|
||||||
npcs.Clear();
|
npcs.Clear();
|
||||||
findTile(currPosition, currPosition, limit);
|
findTile(currPosition, currPosition, limit);
|
||||||
|
|
||||||
|
MainClass.monitor.Log($"\nRead Tile stopped\n\n", StardewModdingAPI.LogLevel.Debug);
|
||||||
await Task.Delay(3000);
|
await Task.Delay(3000);
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +195,7 @@ namespace stardew_access.Game
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playSoundAt(Vector2 position, String? searchQuery)
|
public void playSoundAt(Vector2 position, String? searchQuery, bool isNPC = false)
|
||||||
{
|
{
|
||||||
// Skip if player is directly looking at the tile
|
// Skip if player is directly looking at the tile
|
||||||
if (CurrentPlayer.getNextTile().Equals(position))
|
if (CurrentPlayer.getNextTile().Equals(position))
|
||||||
|
@ -204,7 +206,47 @@ namespace stardew_access.Game
|
||||||
if(MainClass.radarDebug)
|
if(MainClass.radarDebug)
|
||||||
MainClass.monitor.Log($"Object:{searchQuery.ToLower().Trim()}\tPosition: X={position.X} Y={position.Y}", StardewModdingAPI.LogLevel.Debug);
|
MainClass.monitor.Log($"Object:{searchQuery.ToLower().Trim()}\tPosition: X={position.X} Y={position.Y}", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
|
||||||
Game1.currentLocation.localSoundAt("sa_poi", position);
|
int px = (int)Game1.player.getTileX(); // Player's X postion
|
||||||
|
int py = (int)Game1.player.getTileY(); // Player's Y postion
|
||||||
|
|
||||||
|
int ox = (int)position.X; // Object's X postion
|
||||||
|
int oy = (int)position.Y; // Object's Y postion
|
||||||
|
|
||||||
|
int dx = ox - px; // Distance of object's X position
|
||||||
|
int dy = oy - py; // Distance of object's Y position
|
||||||
|
|
||||||
|
if(dy < 0 && (Math.Abs(dy) >= Math.Abs(dx))) // Object is at top
|
||||||
|
{
|
||||||
|
if (isNPC)
|
||||||
|
Game1.currentLocation.localSoundAt("npc_top", position);
|
||||||
|
else
|
||||||
|
Game1.currentLocation.localSoundAt("obj_top", position);
|
||||||
|
MainClass.monitor.Log($"Top", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if (dx > 0 && (Math.Abs(dx) >= Math.Abs(dy))) // Object is at right
|
||||||
|
{
|
||||||
|
if (isNPC)
|
||||||
|
Game1.currentLocation.localSoundAt("npc_right", position);
|
||||||
|
else
|
||||||
|
Game1.currentLocation.localSoundAt("obj_right", position);
|
||||||
|
MainClass.monitor.Log($"Right", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if (dx < 0 && (Math.Abs(dx) > Math.Abs(dy))) // Object is at left
|
||||||
|
{
|
||||||
|
if (isNPC)
|
||||||
|
Game1.currentLocation.localSoundAt("npc_left", position);
|
||||||
|
else
|
||||||
|
Game1.currentLocation.localSoundAt("obj_left", position);
|
||||||
|
MainClass.monitor.Log($"Left", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
|
else if (dy > 0 && (Math.Abs(dy) > Math.Abs(dx))) // Object is at bottom
|
||||||
|
{
|
||||||
|
if (isNPC)
|
||||||
|
Game1.currentLocation.localSoundAt("npc_bottom", position);
|
||||||
|
else
|
||||||
|
Game1.currentLocation.localSoundAt("obj_bottom", position);
|
||||||
|
MainClass.monitor.Log($"Bottom", StardewModdingAPI.LogLevel.Debug);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
using StardewModdingAPI;
|
using StardewModdingAPI;
|
||||||
using StardewValley;
|
using StardewValley;
|
||||||
using StardewValley.Locations;
|
using StardewValley.Locations;
|
||||||
|
|
|
@ -357,21 +357,108 @@ namespace stardew_access
|
||||||
collidingCueDef.SetSound(collidingAudio, Game1.audioEngine.GetCategoryIndex("Sound"), false);
|
collidingCueDef.SetSound(collidingAudio, Game1.audioEngine.GetCategoryIndex("Sound"), false);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region POI sound
|
#region Nearby NPCs sound
|
||||||
CueDefinition poiCueDef = new CueDefinition();
|
// Npc top
|
||||||
poiCueDef.name = "sa_poi";
|
CueDefinition npcTopCD = new CueDefinition();
|
||||||
SoundEffect poiAudio;
|
npcTopCD.name = "npc_top";
|
||||||
string poiFilePath = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/sound1.wav");
|
SoundEffect npcTopSE;
|
||||||
using (FileStream stream = new(poiFilePath, FileMode.Open))
|
string npcTopFP = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/npc_top.wav");
|
||||||
|
using (FileStream stream = new(npcTopFP, FileMode.Open))
|
||||||
{
|
{
|
||||||
poiAudio = SoundEffect.FromStream(stream);
|
npcTopSE = SoundEffect.FromStream(stream);
|
||||||
}
|
}
|
||||||
poiCueDef.SetSound(poiAudio, Game1.audioEngine.GetCategoryIndex("Footsteps"), false);
|
npcTopCD.SetSound(npcTopSE, Game1.audioEngine.GetCategoryIndex("Footsteps"), false);
|
||||||
|
|
||||||
|
// Npc left
|
||||||
|
CueDefinition npcLeftCD = new CueDefinition();
|
||||||
|
npcLeftCD.name = "npc_left";
|
||||||
|
SoundEffect npcLeftSE;
|
||||||
|
string npcLeftFP = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/npc_left.wav");
|
||||||
|
using (FileStream stream = new(npcLeftFP, FileMode.Open))
|
||||||
|
{
|
||||||
|
npcLeftSE = SoundEffect.FromStream(stream);
|
||||||
|
}
|
||||||
|
npcLeftCD.SetSound(npcLeftSE, Game1.audioEngine.GetCategoryIndex("Footsteps"), false);
|
||||||
|
|
||||||
|
// Npc right
|
||||||
|
CueDefinition npcRightCD = new CueDefinition();
|
||||||
|
npcRightCD.name = "npc_right";
|
||||||
|
SoundEffect npcRightSE;
|
||||||
|
string npcRightFP = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/npc_right.wav");
|
||||||
|
using (FileStream stream = new(npcRightFP, FileMode.Open))
|
||||||
|
{
|
||||||
|
npcRightSE = SoundEffect.FromStream(stream);
|
||||||
|
}
|
||||||
|
npcRightCD.SetSound(npcRightSE, Game1.audioEngine.GetCategoryIndex("Footsteps"), false);
|
||||||
|
|
||||||
|
// Npc bottom
|
||||||
|
CueDefinition npcBottomCD = new CueDefinition();
|
||||||
|
npcBottomCD.name = "npc_bottom";
|
||||||
|
SoundEffect npcBottomSE;
|
||||||
|
string npcBottomFP = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/npc_bottom.wav");
|
||||||
|
using (FileStream stream = new(npcBottomFP, FileMode.Open))
|
||||||
|
{
|
||||||
|
npcBottomSE = SoundEffect.FromStream(stream);
|
||||||
|
}
|
||||||
|
npcBottomCD.SetSound(npcBottomSE, Game1.audioEngine.GetCategoryIndex("Footsteps"), false);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Nearby objects sound
|
||||||
|
// Object top
|
||||||
|
CueDefinition objTopCD = new CueDefinition();
|
||||||
|
objTopCD.name = "obj_top";
|
||||||
|
SoundEffect objTopSE;
|
||||||
|
string objTopFP = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/obj_top.wav");
|
||||||
|
using (FileStream stream = new(objTopFP, FileMode.Open))
|
||||||
|
{
|
||||||
|
objTopSE = SoundEffect.FromStream(stream);
|
||||||
|
}
|
||||||
|
objTopCD.SetSound(objTopSE, Game1.audioEngine.GetCategoryIndex("Footsteps"), false);
|
||||||
|
|
||||||
|
// Object left
|
||||||
|
CueDefinition objLeftCD = new CueDefinition();
|
||||||
|
objLeftCD.name = "obj_left";
|
||||||
|
SoundEffect objLeftSE;
|
||||||
|
string objLeftFP = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/obj_left.wav");
|
||||||
|
using (FileStream stream = new(objLeftFP, FileMode.Open))
|
||||||
|
{
|
||||||
|
objLeftSE = SoundEffect.FromStream(stream);
|
||||||
|
}
|
||||||
|
objLeftCD.SetSound(objLeftSE, Game1.audioEngine.GetCategoryIndex("Footsteps"), false);
|
||||||
|
|
||||||
|
// Object right
|
||||||
|
CueDefinition objRightCD = new CueDefinition();
|
||||||
|
objRightCD.name = "obj_right";
|
||||||
|
SoundEffect objRightSE;
|
||||||
|
string objRightFP = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/obj_right.wav");
|
||||||
|
using (FileStream stream = new(objRightFP, FileMode.Open))
|
||||||
|
{
|
||||||
|
objRightSE = SoundEffect.FromStream(stream);
|
||||||
|
}
|
||||||
|
objRightCD.SetSound(objRightSE, Game1.audioEngine.GetCategoryIndex("Footsteps"), false);
|
||||||
|
|
||||||
|
// Object bottom
|
||||||
|
CueDefinition objBottomCD = new CueDefinition();
|
||||||
|
objBottomCD.name = "obj_bottom";
|
||||||
|
SoundEffect objBottomSE;
|
||||||
|
string objBottomFP = Path.Combine(Path.Combine(this.Helper.DirectoryPath), "sounds/obj_bottom.wav");
|
||||||
|
using (FileStream stream = new(objBottomFP, FileMode.Open))
|
||||||
|
{
|
||||||
|
objBottomSE = SoundEffect.FromStream(stream);
|
||||||
|
}
|
||||||
|
objBottomCD.SetSound(objBottomSE, Game1.audioEngine.GetCategoryIndex("Footsteps"), false);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
Game1.soundBank.AddCue(dropItemCueDef);
|
Game1.soundBank.AddCue(dropItemCueDef);
|
||||||
Game1.soundBank.AddCue(collidingCueDef);
|
Game1.soundBank.AddCue(collidingCueDef);
|
||||||
Game1.soundBank.AddCue(poiCueDef);
|
Game1.soundBank.AddCue(objTopCD);
|
||||||
|
Game1.soundBank.AddCue(objLeftCD);
|
||||||
|
Game1.soundBank.AddCue(objRightCD);
|
||||||
|
Game1.soundBank.AddCue(objBottomCD);
|
||||||
|
Game1.soundBank.AddCue(npcTopCD);
|
||||||
|
Game1.soundBank.AddCue(npcLeftCD);
|
||||||
|
Game1.soundBank.AddCue(npcRightCD);
|
||||||
|
Game1.soundBank.AddCue(npcBottomCD);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,6 @@ using stardew_access.Game;
|
||||||
using StardewModdingAPI;
|
using StardewModdingAPI;
|
||||||
using StardewValley;
|
using StardewValley;
|
||||||
using StardewValley.Menus;
|
using StardewValley.Menus;
|
||||||
using StardewValley.TerrainFeatures;
|
|
||||||
|
|
||||||
namespace stardew_access.Patches
|
namespace stardew_access.Patches
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue