-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHandleFall.cs
More file actions
50 lines (44 loc) · 1.7 KB
/
HandleFall.cs
File metadata and controls
50 lines (44 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.IO;
using BattleTech;
namespace CharlesB
{
public class HandleFall
{
private static List<string> phrases = new List<string>();
private static bool fileLoaded; // for memoizing the phrases
/// <summary>
/// displays a pithy floatie message over the supplied mech
/// </summary>
/// <param name="mech"></param>
public static void Say(Mech mech)
{
if (!Settings.EnableKnockdownPhrases) return;
if (!mech.IsFlaggedForKnockdown) return;
if (!fileLoaded)
try
{
var phraseFile = Path.Combine(Core.ModDirectory, "phrases.txt");
if (!File.Exists(phraseFile))
{
Logger.Error(new FileNotFoundException($"Unable to locate {phraseFile}"));
}
phrases = new List<string>();
var reader = new StreamReader(phraseFile);
using (reader)
{
while (!reader.EndOfStream) phrases.Add(reader.ReadLine());
}
fileLoaded = true;
}
catch (Exception e)
{
Logger.Error(e);
}
var knockdownMessage = phrases[UnityEngine.Random.Range(0, phrases.Count - 1)];
mech.Combat.MessageCenter.PublishMessage(new AddSequenceToStackMessage(
new ShowActorInfoSequence(mech, knockdownMessage, FloatieMessage.MessageNature.Debuff, false))); // false leaves camera unlocked from floatie
}
}
}