Esempio n. 1
0
        public static void DoDrop(Brain brain, string[] args)
        {
            string item_name = args[0];

            using (var s = Program.SF.OpenSession())
            {
                var e = s.Get<Entity>(brain.EntityID);

                var phy = e.GetFirstComponent<Physical>(s);
                var loc = phy.Location;

                var dest_inv = loc
                    .Entity
                    .GetFirstComponent<Inventory>(s);

                var orig_inv = e
                    .GetFirstComponent<Inventory>(s);

                var item = orig_inv
                    .GetContents(s
                        .CreateCriteria<Item>()
                        .Add(Expression
                            .InsensitiveLike("Keywords", "%" + item_name + "%")
                        )
                    )
                    .FirstOrDefault();

                if (item == null)
                {
                    brain.Write("Drop what?\r\n");
                    return;
                }

                using (var tx = s.BeginTransaction())
                {
                    item.Container = dest_inv;
                    s.Save(item);
                    foreach (var l in loc.Contents<Listen>(s))
                    {
                        if (l.Entity == phy.Entity) continue;
                        Event.AddEvent(s, l.Entity, String.Format("{0} drops {1}.\r\n", phy.Name, item.ShortName));
                    }
                    tx.Commit();
                }

                brain.Write("Dropped {0}.\r\n", item.ShortName);
            }
        }
Esempio n. 2
0
 public static void DoPut(Brain brain, string[] args)
 {
     brain.Write("dur.\r\n");
 }
Esempio n. 3
0
        public static void DoInventory(Brain brain, string[] args)
        {
            using (var s = Program.SF.OpenSession())
            {
                var inv = Entity.GetFirstComponent<Inventory>(s, brain.EntityID);

                StringBuilder sb = new StringBuilder();
                sb.Append("Inventory:\r\n");
                foreach (var item in inv.GetContents(s))
                {
                    sb.AppendFormat("  {0}\r\n", item.ShortName);
                }
                sb.AppendLine();
                brain.Write(sb.ToString());
            }
        }
Esempio n. 4
0
        public static void DoExits(Brain brain, string[] args)
        {
            using (var session = Program.SF.OpenSession())
            {
                List<Exit> exits = new List<Exit>();

                var phy = Entity.GetFirstComponent<Physical>(session, brain.EntityID);

                if (phy == null) return; //whut

                exits.AddRange(phy.Location.Entity.GetComponents<Exit>(session));

                foreach (var p in session.CreateCriteria<Physical>().Add(Expression.Eq("Location", phy.Location)).List<Physical>())
                {
                    exits.AddRange(p.Entity.GetComponents<Exit>(session));
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("Exits:\r\n");
                foreach (var x in exits)
                {
                    sb.AppendFormat("{0}: {1}\r\n",
                        x.Dir,
                        Exit.GetDestination(session, x)
                            .Name
                        );
                }

                sb.Append("\r\n");

                brain.Write(sb.ToString());

            }
        }
Esempio n. 5
0
        static void Do_direction_(Brain brain, Direction dir)
        {
            if (dir == Direction.None) return;

            using (var session = Program.SF.OpenSession())
            {
                var phy = Entity.GetFirstComponent<Physical>(session, brain.EntityID);
                var x = ExitForDirection(session,
                    phy.Location,
                    dir
                    );
                if (x == null)
                {
                    brain.Write("You can't go {0}.\r\n", dir);
                    return;
                }
                useExit(session, phy, x);
            }
            Player.DoLook(brain, new string[] { });
        }
Esempio n. 6
0
        public static void DoTunnel(Brain brain, string[] args)
        {
            // todo: command access restrictions

            if (args.Length == 0 || args.Length > 2)
            {
                brain.Write("Invalid argument count; tunnel <direction> [<destination>]\r\n");
                return;
            }

            using (var s = Program.SF.OpenSession())
            {
                var phy = Entity.GetFirstComponent<Physical>(s, brain.EntityID);
                var loc = phy.Location;
                var dir = DirectionFromName(args[0]);
                var x = ExitForDirection(s, loc, dir);

                if (x != null)
                {
                    brain.Write("Exit already exists in that direction; manual creation is required.\r\n");
                    return;
                }
                using (var tx = s.BeginTransaction())
                {
                    Entity destination = null;

                    if (args.Length == 2)
                    {
                        Guid destId;
                        if (Guid.TryParse(args[1], out destId))
                        {
                            var dloc = s.Get<Location>(destId);
                            if (dloc != null)
                            {
                                destination = dloc.Entity;
                            }
                        }
                    }

                    if (destination == null)
                    {
                        var newloc = Location.CreateLocation(s, "An empty room", "Empty Room");
                        destination = newloc.Entity;
                    }

                    x = new Exit
                    {
                        Entity = loc.Entity,
                        Destination = destination,
                        Dir = dir,
                    };

                    var x2 = new Exit
                    {
                        Entity = destination,
                        Destination = loc.Entity,
                        Dir = InvertDirection(dir)
                    };

                    s.Save(x);
                    s.Save(x2);
                    tx.Commit();
                }
                useExit(s, phy, x);
                Player.DoLook(brain, new string[] { });
            }
        }