148 lines
4.0 KiB
C#
148 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using SynthySound;
|
|
using Microsoft.Xna.Framework;
|
|
|
|
namespace EvilSatellites
|
|
{
|
|
public class AI
|
|
{
|
|
public Synthy Engine;
|
|
public Dictionary<string, AIVoiceClip> Clips;
|
|
public Random rnd = new Random();
|
|
public double LastSpeakTimer;
|
|
public AI(Synthy engine)
|
|
{
|
|
Engine = engine;
|
|
Clips = new Dictionary<string, AIVoiceClip>();
|
|
LastSpeakTimer = 10000;
|
|
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,
|
|
Probability = new int[2] { 2, 4 }
|
|
});
|
|
|
|
Clips.Add("DamageDebris", new AIVoiceClip
|
|
{
|
|
Name = "DamageDebris",
|
|
NumFiles = 3,
|
|
Probability = new int[2] { 2, 4 }
|
|
});
|
|
|
|
Clips.Add("FarMiss", new AIVoiceClip
|
|
{
|
|
Name = "FarMiss",
|
|
NumFiles = 6,
|
|
Probability = new int[2] { 5, 30 }
|
|
});
|
|
|
|
Clips.Add("GameOver", new AIVoiceClip
|
|
{
|
|
Name = "GameOver",
|
|
NumFiles = 2,
|
|
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,
|
|
Probability = new int[2] { 5, 30 }
|
|
});
|
|
|
|
Clips.Add("Spinning", new AIVoiceClip
|
|
{
|
|
Name = "Spinning",
|
|
NumFiles = 2,
|
|
Probability = new int[2] { 2, 4 }
|
|
});
|
|
|
|
Clips.Add("Still", new AIVoiceClip
|
|
{
|
|
Name = "Still",
|
|
NumFiles = 5,
|
|
Probability = new int[2] { 1, 1 }
|
|
});
|
|
|
|
Clips.Add("Void", new AIVoiceClip
|
|
{
|
|
Name = "Void",
|
|
NumFiles = 3,
|
|
Probability = new int[2] { 5, 100 }
|
|
});
|
|
|
|
Clips.Add("Wave", new AIVoiceClip
|
|
{
|
|
Name = "Wave",
|
|
NumFiles = 4,
|
|
Probability = new int[2] { 1, 2 }
|
|
});
|
|
}
|
|
|
|
public void Play(string name)
|
|
{
|
|
if (GameSettings.EnableAI == false) return;
|
|
if (LastSpeakTimer < 4000) return;
|
|
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))
|
|
{
|
|
var file = rnd.Next(1, clip.NumFiles+1);
|
|
Engine.PlayOneshot(@"sfx/ai/" + name + file.ToString() + ".wav");
|
|
LastSpeakTimer = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Update(GameTime time)
|
|
{
|
|
LastSpeakTimer += time.ElapsedGameTime.TotalMilliseconds;
|
|
}
|
|
}
|
|
public struct AIVoiceClip
|
|
{
|
|
public string Name;
|
|
public int NumFiles;
|
|
public int[] Probability;
|
|
}
|
|
}
|