Ejemplo n.º 1
0
Archivo: Room.cs Proyecto: leafi/Light
        public void Join(Player joining)
        {
            lock (Everyone)
                Everyone.Add(joining);

            throw new NotImplementedException();
        }
Ejemplo n.º 2
0
 public void Join(Player p)
 {
     lock (this)
     {
         var po = new BufferBlock<string>();
         pmscp.Add(p, new MultiplayerScriptContextPlayer(p, po, OnJoin(p)));
     }
 }
Ejemplo n.º 3
0
 public void Part(Player p)
 {
     lock (this)
     {
         playerToScriptInput[p].Complete();
         playerToScriptInput.Remove(p);
     }
 }
Ejemplo n.º 4
0
        public void Join(Player p)
        {
            lock (this)
            {
                var bb = new BufferBlock<string>();
                playerToScriptInput.Add(p, bb);

                script(p, bb).Start();
            }
        }
Ejemplo n.º 5
0
        protected override async Task script(Player p, BufferBlock<string> input)
        {
            // todo: what happens if the player quits during chargen? do we get an exception?

            // todo: ignore input when not expecting it

            p.Tell(@"Welcome to Chargen.
            Your GUID is {0}.", p.Guid);

            var name = "";

            while (name == "")
            {
                p.Tell("\nWhat is your name? >");

                string s = (await input.ReceiveAsync()).Trim();
                Action<string> e = (m => p.Tell(m, "'" + s + "'"));
                
                // TODO: check if name is already in use and the user would like to disambiguate?

                // One-character names are allowed if they're not some English alphabet character, basically.
                // Otherwise, names must be at least two characters after trimming.
                // The name must also contain at least one unicode 'letter'.

                if (s.Length < 1)
                    e("{0} is too short.  Please choose a name at least two characters in length.");
                else if (((s[0] >= 'a' && s[0] <= 'z') || (s[0] >= 'A' && s[0] <= 'Z')) && s.Length == 1)
                    e("{0} is too short.  Please choose a name at least two characters in length.");
                else if (s.Length > 16)
                    e("That name's pretty long!  Could you squeeze it down to no more than 16 characters?!");
                else if (s.All(c => !Char.IsLetter(c)))
                    e("{0} doesn't contain any letters.  Chuck one in for us, would you?");
                else if (s.Contains("'") || s.Contains('"') || s.EndsWith(".") || s.EndsWith(",") || s.EndsWith(";") || s.EndsWith(">"))
                    e("{0} contains a ' or a \" or ends with a '.', ',', '>', or ';'.  You can't do this - sorry.  It'd make the game look odd.");
                else if ((s.Count(c => c == '(') != s.Count(c => c == ')')) || (s.Count(c => c == '[') != s.Count(c => c == ']'))
                    || (s.Count(c => c == '{') != s.Count(c => c == '}')) || (s.Count(c => c == '<') != s.Count(c => c == '>')))
                    e("{0} contains mismatched brackets, a real pet hate of mine.  Please make sure there's the same number of open as close brackets for each bracket type.");
                else
                {
                    p.Tell("You entered your name as '{0}'.  Is this the handle you wish to use?  y/n >", s);
                    string yn = (await input.ReceiveAsync()).Trim().ToLower();

                    if (yn.StartsWith("y") || new List<string> { "yes", "y", "yep", "you bet", "of course", "absolutely",
                        "very yes", "very much so", "indubitably", "hell yes", "hell yeah", "yea", "ye" }.Contains(yn))
                        name = s;
                    else
                        p.Tell("Okay.  Let's have another go.");
                }
            }

            p.Tell("That's all I needed to know.  Let's begin!");

            // actually set the properties
            p.Name = name;
        }
Ejemplo n.º 6
0
            async Task playerScriptWrapper(Player player, BufferBlock<string> po, PlayerScript initialScript)
            {
                var csd = new Action<PlayerScript>(setNextScript);

                this.ContextPlayerData = new Dictionary<string, object>();
                this.Player = player;
                this.PlayerOutput = po;
                this.nextScript = initialScript;
                
                while (true)
                {
                    lock (this)
                        if (nextScript != null)
                        {
                            playerScript = nextScript;
                            nextScript = null;
                        }
                        else
                            break;

                    await nextScript(this, csd);
                }
            }
Ejemplo n.º 7
0
 public void Parse(Player from, string message)
 {
     lock (this)
         pmscp[from].PlayerOutput.Post(message);
 }
Ejemplo n.º 8
0
 public void Part(Player p)
 {
     lock (this)
     {
         pmscp[p].PlayerOutput.Complete();
         pmscp.Remove(p);
     }
 }
Ejemplo n.º 9
0
 protected abstract PlayerScript OnJoin(Player p);
Ejemplo n.º 10
0
 internal MultiplayerScriptContextPlayer(Player player, BufferBlock<string> playerOutput, PlayerScript initialScript)
 {
     playerScriptWrapper(player, playerOutput, initialScript).Start();
 }
Ejemplo n.º 11
0
 // See CharGenContext for an example impl of this.
 protected abstract Task script(Player p, BufferBlock<string> input);
Ejemplo n.º 12
0
 public void Parse(Player from, string message)
 {
     lock (this)
         playerToScriptInput[from].Post(message);
 }
Ejemplo n.º 13
0
Archivo: Room.cs Proyecto: leafi/Light
 internal virtual void OnPartScript(Player p)
 {
 }
Ejemplo n.º 14
0
Archivo: Room.cs Proyecto: leafi/Light
 internal abstract void OnJoinScript(Player p);
Ejemplo n.º 15
0
Archivo: Room.cs Proyecto: leafi/Light
 public void Part(Player parting)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
Archivo: Room.cs Proyecto: leafi/Light
 public void Parse(Player from, string message)
 {
     throw new NotImplementedException();
 }