Create the file /home/user/things/Frog.cs
:
using BaseLib;
using BaseLib.Events.Speech;
using BaseLib.Impl.Behaviours;
using System;
using System.Linq;
namespace TestLib
{
public class Frog : NPC
{
public Frog()
{
AddClassification("thing.animal.frog");
AddClassification("colour.green");
Nouns = new string[] { "tree frog" };
Plurals = new string[] {"tree frogs" };
ShortDescription = "green tree frog";
PluralDescription = "green tree frogs";
LongDescription = "A cute green tree frog. It walks around and does simple maths.";
Weight = 3f;
RandomWalk rw = new RandomWalk(this);
AddNumbers an = new AddNumbers(this);
an.ShouldRun = () => {
return an.Running || RecentEvents.Any( e => {
var ev = e as SayEvent;
return ev != null && ev.Message.ToLower().Contains("math");
});
};
BehaviourList bl = new BehaviourList(this);
bl.AddBehaviour(an);
bl.AddBehaviour(rw);
this.Brain = new Brain(bl);
this.Brain.Start();
}
private class AddNumbers : Behaviour {
public bool Running { get; set; }
public AddNumbers(NPC npc) : base(npc)
{
Running = false;
}
public override void Run ()
{
npc.RecentEvents.Clear();
Running = true;
Sleep(.5);
npc.Say("I like to add things! Tell me a number!");
int firstNumber = 0;
var say = WaitForEvent<SayEvent>( ev => {
return int.TryParse(ev.Message, out firstNumber);
}, 15);
if(say == null) {
npc.Say("Fine then, don't tell me a number...");
Sleep(.5);
npc.Emote("sighs");
Running = false;
return;
}
Sleep(.5);
npc.Say("Great! Now tell me another number!");
int secondNumber = 0;
say = WaitForEvent<SayEvent>( ev => {
return int.TryParse(ev.Message, out secondNumber);
}, 15);
if(say == null) {
npc.Say("Aww, I really wanted you to tell me another number!");
Sleep(.5);
npc.Emote("pouts");
Running = false;
return;
}
Sleep(1);
npc.Emote("thinks");
Sleep(3);
int total = firstNumber + secondNumber;
npc.Say("If you add both numbers together, you get " + total + "!");
Sleep(.5);
npc.Emote("cheers");
Running = false;
}
public override void OnStop ()
{
Running = false;
}
}
}
}
To compile it once saved:
compile /home/user/things/Frog.cs
To create it once compiled:
create User.Things.Frog