Ejemplo n.º 1
0
        static void useExit(ISession s, Physical p, Exit x)
        {
            if (x == null) return;
            var origin = p.Location;
            var destination = Exit.GetDestination(s, x);

            // todo: event messages
            using (var tx = s.BeginTransaction())
            {
                foreach (var lis in origin.Contents<Listen>(s))
                {
                    if (lis.Entity != p.Entity)
                    {
                        Event.AddEvent(s, lis.Entity, string.Format("{0} leaves.", p.Name));
                    }
                }
                foreach (var lis in destination.Contents<Listen>(s))
                {
                    if (lis.Entity != p.Entity)
                    {
                        Event.AddEvent(s, lis.Entity, string.Format("{0} enters.", p.Name));
                    }
                }
                MoveToLocation(s, p, destination);
                tx.Commit();
            }
        }
Ejemplo n.º 2
0
        public static Location GetDestination(ISession s, Exit x)
        {
            if (x == null) return null;
            var loc = x.Destination.GetFirstComponent<Location>(s);
            if (loc == null)
            {
                var phy = x.Destination.GetFirstComponent<Physical>(s);
                if (phy == null) return null;
                return phy.Location;

            }
            return loc;
        }
Ejemplo n.º 3
0
 static Components.Exit ExitForDirection(ISession s, Location loc, Exit.Direction dir)
 {
     return GetExit(s, s.CreateCriteria<Exit>().Add(Expression.Eq("Dir", dir)), loc);
 }
Ejemplo n.º 4
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[] { });
            }
        }