/// <summary> /// The current Suitability of the track. /// </summary> /// <param name="world">world information</param> /// <param name="props">the properties of the current track.</param> /// <returns></returns> public float CurrentSuitability(IWorldAccessor world, TrackedPlayerProperties props) { int applied = 0; float suitability = 0; if (PosY != null) { suitability += GameMath.TriangleStep(props.posY, PosY[0], PosY[1]); applied++; } if (Sunlight != null) { suitability += GameMath.TriangleStep(props.sunSlight, Sunlight[0], Sunlight[1]); applied++; } /*foreach (var val in Weather) * { * suitability += GameMath.TriangleStep(props.Weather[(int)val.Key], val.Value[0], val.Value[1]); * applied++; * }*/ if (applied == 0) { return(1); } return(suitability / applied); }
/// <summary> /// Should this current track play? /// </summary> /// <param name="props">Player Properties</param> /// <returns>Should we play the current track?</returns> public virtual bool ShouldPlay(TrackedPlayerProperties props, ClimateCondition conds, BlockPos pos) { if (IsActive) { return(false); } return(true); }
/// <summary> /// Is it cool for the current track to continue playing? /// </summary> /// <param name="dt">Delta Time/Change in time.</param> /// <param name="props">Track properties.</param> /// <returns>Cool or not cool?</returns> public virtual bool ContinuePlay(float dt, TrackedPlayerProperties props) { if (!IsActive) { Sound?.Dispose(); Sound = null; return(false); } return(docontinue); }
/// <summary> /// Should the game play this track? /// </summary> /// <param name="props">The properties of the current track.</param> /// <returns>Do we play this track?</returns> public bool ShouldPlay(TrackedPlayerProperties props, ClimateCondition conds, BlockPos pos) { if (props.sunSlight > 3 || !ShouldPlayCaveMusic) { return(false); } if (capi.World.ElapsedMilliseconds < cooldownUntilMs) { return(false); } return(true); }
/// <summary> /// Is it cool for the current track to continue playing? /// </summary> /// <param name="dt">Delta Time/Change in time.</param> /// <param name="props">Track properties.</param> /// <returns>Cool or not cool?</returns> public bool ContinuePlay(float dt, TrackedPlayerProperties props) { if (!IsActive) { Sound?.Dispose(); Sound = null; SetCooldown(1f); return(false); } if (!ShouldPlayMusic) { FadeOut(3); } return(true); }
/// <summary> /// Begins playing the Music track. /// </summary> /// <param name="props">Player Properties</param> public virtual void BeginPlay(TrackedPlayerProperties props) { loading = true; musicEngine.LoadTrack(Location, (sound) => { if (sound != null) { sound.Start(); if (!loading) { sound.Stop(); sound.Dispose(); } else { Sound = sound; } } loading = false; }); }
/// <summary> /// The current volume of the track. /// </summary> /// <param name="world">world information</param> /// <param name="props">the properties of the current track.</param> /// <returns></returns> public float CurrentVolume(IWorldAccessor world, TrackedPlayerProperties props) { // y = k * x + d // k = (y2 - y1) / (x2 - x1); // d = y1 - k * x1 float x = CurrentSuitability(world, props); if (x == 1) { return(1); } float k = (MaxVolumne - MinVolumne) / (MaxSuitability - MinSuitability); float d = MinVolumne - k * MinSuitability; if (x < MinSuitability) { return(0); } return(GameMath.Min(k * x + d, MaxVolumne)); }
public bool ContinuePlay(float dt, TrackedPlayerProperties props) { // Track should be started /*if (shouldStart) * { * string filename = part.Files[rand.Next(part.Files.Length)]; * part.Sound = musicEngine.StartTrack( * filename, * part.CurrentVolume(world, props) + VolumeRandomization - 2 * rand.Next() * VolumeRandomization, * PitchRandomization - 2 * rand.Next() * PitchRandomization * ); * part.startedMs = world.ElapsedMilliseconds; * quantityPlaying++; * } * * if (isPlaying && shouldPlay && RuntimeRandomizationInterval != null && world.ElapsedMilliseconds - part.startedMs > RuntimeRandomizationInterval * 1000) * { * part.Sound.SetPitch(part.Sound.Params.Pitch + PitchRandomization - 2 * rand.Next() * PitchRandomization); * part.Sound.SetVolume(part.Sound.Params.Volume + VolumeRandomization - 2 * rand.Next() * VolumeRandomization); * }*/ return(false); }
public void BeginPlay(TrackedPlayerProperties props) { }
public bool ShouldPlay(TrackedPlayerProperties props, ClimateCondition conds, BlockPos pos) { return(false); }
/// <summary> /// Should this current track play? /// </summary> /// <param name="props">Player Properties</param> /// <param name="conds"><param> /// <param name="pos"/></param> /// <returns>Should we play the current track?</returns> public bool ShouldPlay(TrackedPlayerProperties props, ClimateCondition conds, BlockPos pos) { if (IsActive || !ShouldPlayMusic) { return(false); } if (capi.World.ElapsedMilliseconds < globalCooldownUntilMs) { return(false); } if (OnPlayList != "*" && !OnPlayLists.Contains(props.PlayListCode)) { return(false); } if (props.sunSlight < MinSunlight) { return(false); } if (musicEngine.LastPlayedTrack == this) { return(false); } if (conds.Temperature > MaxTemperature) { return(false); } if (conds.Rainfall < MinRainFall) { return(false); } float season = capi.World.Calendar.GetSeasonRel(pos); if (season < MinSeason || season > MaxSeason) { return(false); } float latitude = (float)Math.Abs(capi.World.Calendar.OnGetLatitude(pos.Z)); if (latitude < MinLatitude || latitude > MaxLatitude) { return(false); } long trackCoolDownMs; tracksCooldownUntilMs.TryGetValue(Name, out trackCoolDownMs); if (capi.World.ElapsedMilliseconds < trackCoolDownMs) { //capi.Logger.Debug("{0}: On track cooldown ({1}s)", Name, (trackCoolDownMs - capi.World.ElapsedMilliseconds) / 1000); return(false); } if (prevFrequency == 3) { float hour = capi.World.Calendar.HourOfDay / 24f * capi.World.Calendar.HoursPerDay; if (hour < MinHour || hour > MaxHour) { //world.Logger.Debug("{0}: {1} not inside [{2},{3}]", Name, hour, MinHour, MaxHour); return(false); } } else { float hour = capi.World.Calendar.HourOfDay / 24f * capi.World.Calendar.HoursPerDay; if (hour < nowMinHour || hour > nowMaxHour) { //world.Logger.Debug("{0}: {1} not inside [{2},{3}]", Name, hour, MinHour, MaxHour); return(false); } } //world.Logger.Debug("{0}: {1} is inside [{2},{3}]!", Name, hour, MinHour, MaxHour); return(true); }
/// <summary> /// Do we continue playing this track? /// </summary> /// <param name="dt">Delta time or Change in time</param> /// <param name="props">The properties of the current track.</param> /// <returns>Are we still playing or do we stop?</returns> public bool ContinuePlay(float dt, TrackedPlayerProperties props) { if (props.sunSlight > 3 || !ShouldPlayCaveMusic) { FadeOut(3); return(false); } if (activeUntilMs > 0 && capi.World.ElapsedMilliseconds >= activeUntilMs) { // Ok, time to stop. We play the current tracks until the end and stop bool active = IsActive; if (!active) { activeUntilMs = 0; foreach (MusicTrackPart part in Parts) { part.Sound?.Dispose(); } } return(active); } int quantityActive = 0; for (int i = 0; i < Parts.Length; i++) { quantityActive += (Parts[i].IsPlaying || Parts[i].Loading) ? 1: 0; } int beforePlaying = quantityActive; GameMath.Shuffle(rand, PartsShuffled); for (int i = 0; i < PartsShuffled.Length; i++) { MusicTrackPart part = PartsShuffled[i]; if (part.Files.Length == 0) { continue; } bool isPlaying = part.IsPlaying; bool shouldPlay = part.Applicable(capi.World, props); // Part has recently ended if (!isPlaying && part.Sound != null) { part.Sound.Dispose(); part.Sound = null; continue; } // Part should be stopped if (isPlaying && !shouldPlay) { if (!part.Sound.IsFadingOut) { part.Sound.FadeOut(3, (sound) => { part.Sound.Dispose(); part.Sound = null; }); } continue; } bool shouldStart = !isPlaying && shouldPlay && !part.Loading && quantityActive < maxSimultaenousTracks && (quantityActive == 0 || rand.NextDouble() < simultaenousTrackChance) ; if (shouldStart) { AssetLocation location = part.Files[rand.Next(part.Files.Length)]; part.NowPlayingFile = location; part.Loading = true; musicEngine.LoadTrack(location, (sound) => { if (sound != null) { sound.Start(); part.Sound = sound; } part.Loading = false; }); part.StartedMs = capi.World.ElapsedMilliseconds; quantityActive++; } } return(true); }
/// <summary> /// Starts playing the track. /// </summary> /// <param name="props">The properties of the current track.</param> public void BeginPlay(TrackedPlayerProperties props) { activeUntilMs = capi.World.ElapsedMilliseconds + (int)(SessionPlayTime * 1000); }
/// <summary> /// Am I applicable? /// </summary> /// <param name="world">world information</param> /// <param name="props">the properties of the current track.</param> /// <returns></returns> public bool Applicable(IWorldAccessor world, TrackedPlayerProperties props) { return(CurrentSuitability(world, props) > MinSuitability); }