Files
evilsatellites/EvilSatellites/AI.cs
T

148 lines
4.0 KiB
C#
Raw Normal View History

2021-04-24 18:47:51 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SynthySound;
2021-04-24 23:31:43 +02:00
using Microsoft.Xna.Framework;
2021-04-24 18:47:51 +02:00
namespace EvilSatellites
{
public class AI
{
public Synthy Engine;
public Dictionary<string, AIVoiceClip> Clips;
public Random rnd = new Random();
2021-04-24 23:31:43 +02:00
public double LastSpeakTimer;
2021-04-24 18:47:51 +02:00
public AI(Synthy engine)
{
Engine = engine;
Clips = new Dictionary<string, AIVoiceClip>();
2021-04-24 23:31:43 +02:00
LastSpeakTimer = 10000;
2021-04-24 18:47:51 +02:00
SetupClips();
}
public void SetupClips()
{
Clips.Add("GameStart", new AIVoiceClip
{
Name = "GameStart",
NumFiles = 3,
Probability = new int[2] { 1, 1 }
});
Clips.Add("CollectDebris", new AIVoiceClip
{
Name = "CollectDebris",
NumFiles = 3,
Probability = new int[2] { 5, 10 }
});
Clips.Add("DamageBullet", new AIVoiceClip
{
Name = "DamageBullet",
NumFiles = 4,
2021-04-24 23:31:43 +02:00
Probability = new int[2] { 2, 4 }
2021-04-24 18:47:51 +02:00
});
Clips.Add("DamageDebris", new AIVoiceClip
{
Name = "DamageDebris",
NumFiles = 3,
Probability = new int[2] { 2, 4 }
});
Clips.Add("FarMiss", new AIVoiceClip
{
Name = "FarMiss",
NumFiles = 6,
2021-04-24 23:31:43 +02:00
Probability = new int[2] { 5, 30 }
2021-04-24 18:47:51 +02:00
});
Clips.Add("GameOver", new AIVoiceClip
{
Name = "GameOver",
2021-04-24 23:31:43 +02:00
NumFiles = 2,
2021-04-24 18:47:51 +02:00
Probability = new int[2] { 1, 1 }
});
Clips.Add("Hit", new AIVoiceClip
{
Name = "Hit",
NumFiles = 5,
Probability = new int[2] { 5, 20 }
});
Clips.Add("LowHealth", new AIVoiceClip
{
Name = "LowHealth",
NumFiles = 5,
Probability = new int[2] { 1, 3 }
});
Clips.Add("NearMiss", new AIVoiceClip
{
Name = "NearMiss",
NumFiles = 4,
2021-04-24 23:31:43 +02:00
Probability = new int[2] { 5, 30 }
2021-04-24 18:47:51 +02:00
});
Clips.Add("Spinning", new AIVoiceClip
{
Name = "Spinning",
NumFiles = 2,
Probability = new int[2] { 2, 4 }
});
Clips.Add("Still", new AIVoiceClip
{
Name = "Still",
NumFiles = 5,
2021-04-24 23:31:43 +02:00
Probability = new int[2] { 1, 1 }
2021-04-24 18:47:51 +02:00
});
Clips.Add("Void", new AIVoiceClip
{
Name = "Void",
NumFiles = 3,
2021-04-24 23:31:43 +02:00
Probability = new int[2] { 5, 100 }
2021-04-24 18:47:51 +02:00
});
Clips.Add("Wave", new AIVoiceClip
{
Name = "Wave",
NumFiles = 4,
Probability = new int[2] { 1, 2 }
});
}
public void Play(string name)
{
2021-04-24 23:31:43 +02:00
if (GameSettings.EnableAI == false) return;
if (LastSpeakTimer < 4000) return;
2021-04-24 18:47:51 +02:00
if (Clips.ContainsKey(name))
{
var clip = Clips[name];
var prob = rnd.Next(clip.Probability[1]);
if (prob == clip.Probability[0] || (clip.Probability[0] == 1 && clip.Probability[1] == 1))
{
2021-04-24 23:31:43 +02:00
var file = rnd.Next(1, clip.NumFiles+1);
2021-04-24 18:47:51 +02:00
Engine.PlayOneshot(@"sfx/ai/" + name + file.ToString() + ".wav");
2021-04-24 23:31:43 +02:00
LastSpeakTimer = 0;
2021-04-24 18:47:51 +02:00
}
}
}
2021-04-24 23:31:43 +02:00
public void Update(GameTime time)
{
LastSpeakTimer += time.ElapsedGameTime.TotalMilliseconds;
}
2021-04-24 18:47:51 +02:00
}
public struct AIVoiceClip
{
public string Name;
public int NumFiles;
public int[] Probability;
}
}