Some cleanup of contains keys and try get values (#246)

This commit is contained in:
Kamron Batman 2020-09-13 20:20:44 -07:00 • committed by GitHub
parent 9cbb0cfd23
commit a236617ad9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
69 changed files with 3508 additions and 350 deletions

View file

@ -288,7 +288,9 @@ namespace Server.Misc
m_Keywords = value;
m_KeywordHash = new Dictionary<string, string>(m_Keywords.Length, StringComparer.OrdinalIgnoreCase);
for (var i = 0; i < m_Keywords.Length; ++i)
{
m_KeywordHash[m_Keywords[i]] = m_Keywords[i];
}
}
}
@ -307,7 +309,9 @@ namespace Server.Misc
var syllables = new string[syllableCount];
for (var i = 0; i < syllableCount; ++i)
{
syllables[i] = GetRandomSyllable();
}
return string.Concat(syllables);
}
@ -333,33 +337,47 @@ namespace Server.Misc
needUpperCase = true;
if (random > 13)
{
sentance.Append("! ");
}
else
{
sentance.Append(". ");
}
}
}
int syllableCount;
if (Utility.Random(100) < 30)
{
syllableCount = Utility.Random(1, 5);
}
else
{
syllableCount = Utility.Random(1, 3);
}
var word = ConstructWord(syllableCount);
sentance.Append(word);
if (needUpperCase)
{
sentance.Replace(word[0], char.ToUpper(word[0]), sentance.Length - word.Length, 1);
}
needUpperCase = false;
}
if (Utility.RandomMinMax(1, 5) == 1)
{
sentance.Append('!');
}
else
{
sentance.Append('.');
}
return sentance.ToString();
}
@ -380,35 +398,53 @@ namespace Server.Misc
public bool OnSpeech(Mobile mob, Mobile speaker, string text)
{
if ((Flags & IHSFlags.OnSpeech) == 0 || m_Keywords == null || Responses == null || m_KeywordHash == null)
{
return false; // not enabled
}
if (!speaker.Alive)
{
return false;
}
if (!speaker.InRange(mob, 3))
{
return false;
}
if ((speaker.Direction & Direction.Mask) != speaker.GetDirectionTo(mob))
{
return false;
}
if ((mob.Direction & Direction.Mask) != mob.GetDirectionTo(speaker))
{
return false;
}
var split = text.Split(' ');
var keywordsFound = new List<string>();
for (var i = 0; i < split.Length; ++i)
{
if (m_KeywordHash.TryGetValue(split[i], out var keyword))
{
keywordsFound.Add(keyword);
}
}
if (keywordsFound.Count > 0)
{
string responseWord;
if (Utility.RandomBool())
{
responseWord = GetRandomResponseWord(keywordsFound);
}
else
{
responseWord = keywordsFound.RandomElement();
}
var secondResponseWord = GetRandomResponseWord(keywordsFound);
@ -469,9 +505,13 @@ namespace Server.Misc
var maxWords = split.Length / 2 + 1;
if (maxWords < 2)
{
maxWords = 2;
}
else if (maxWords > 6)
{
maxWords = 6;
}
SaySentance(mob, Utility.RandomMinMax(2, maxWords));
mob.Say(response.ToString());
@ -485,10 +525,14 @@ namespace Server.Misc
public void OnDeath(Mobile mob)
{
if ((Flags & IHSFlags.OnDeath) == 0)
{
return; // not enabled
}
if (Utility.Random(100) < 90)
{
return; // 90% chance to do nothing; 10% chance to talk
}
SayRandomTranslate(
mob,
@ -506,16 +550,24 @@ namespace Server.Misc
public void OnMovement(Mobile mob, Mobile mover, Point3D oldLocation)
{
if ((Flags & IHSFlags.OnMovement) == 0)
{
return; // not enabled
}
if (!mover.Player || mover.Hidden && mover.AccessLevel > AccessLevel.Player)
{
return;
}
if (!mob.InRange(mover, 5) || mob.InRange(oldLocation, 5))
{
return; // only talk when they enter 5 tile range
}
if (Utility.Random(100) < 90)
{
return; // 90% chance to do nothing; 10% chance to talk
}
SaySentance(mob, 6);
}
@ -523,12 +575,17 @@ namespace Server.Misc
public void OnDamage(Mobile mob, int amount)
{
if ((Flags & IHSFlags.OnDamaged) == 0)
{
return; // not enabled
}
if (Utility.Random(100) < 90)
{
return; // 90% chance to do nothing; 10% chance to talk
}
if (amount < 5)
{
SayRandomTranslate(
mob,
"Ouch!",
@ -537,7 +594,9 @@ namespace Server.Misc
"Thy blows soft!",
"You bad with weapon!"
);
}
else
{
SayRandomTranslate(
mob,
"Ouch! Me hurt!",
@ -548,6 +607,7 @@ namespace Server.Misc
"Aaah! That hurt...",
"Good blow!"
);
}
}
public void OnConstruct(Mobile mob)