示例#1
0
        /*
         * protected override void OnModelCreating(ModelBuilder modelBuilder)
         * {
         *  base.OnModelCreating(modelBuilder);
         *  modelBuilder.Entity<Door>()
         *      .HasOne(x => x.TargetRoom);
         * }
         */

        public void Seed(TextEngineContext context)
        {
            Room r = new Room();

            r.Name        = "default";
            r.Description = "default";
            context.Rooms.Add(r);
            context.Inventories.Add(r.Inventory);
            context.SaveChanges();
        }
示例#2
0
 public static Room ByID(TextEngineContext context, long ID)
 {
     return(context.Rooms
            .Where(r => r.RoomID == ID)
            .Include(r => r.Doors)
            .Include(r => r.Inventory)
            .Include(r => r.Monsters).ThenInclude(m => m.MonsterType)
            .Include(r => r.Monsters).ThenInclude(m => m.Inventory)
            .Include(r => r.Monsters).ThenInclude(m => m.Inventory).ThenInclude(i => i.Items)
            .FirstOrDefault());
 }
示例#3
0
 public static Character GetInstance(TextEngineContext context)
 {
     return(context.Characters
            .Include(c => c.Inventory).ThenInclude(i => i.Items)
            .Include(c => c.CurrentRoom).ThenInclude(r => r.Doors)
            .Include(c => c.CurrentRoom).ThenInclude(r => r.Inventory).ThenInclude(i => i.Items)
            .Include(c => c.CurrentRoom).ThenInclude(r => r.Monsters).ThenInclude(m => m.MonsterType)
            .Include(c => c.CurrentRoom).ThenInclude(r => r.Monsters).ThenInclude(m => m.Inventory)
            .Include(c => c.CurrentRoom).ThenInclude(r => r.Monsters).ThenInclude(m => m.Inventory).ThenInclude(i => i.Items)
            .FirstOrDefault());
 }
示例#4
0
        public static Item FromID(TextEngineContext context, string itemID)
        {
            Item item = null;
            long itemIDLong;
            bool validID = long.TryParse(itemID, out itemIDLong);

            if (validID)
            {
                item = context.Items
                       .Include(i => i.Inventory)
                       .Where(i => i.ItemID == itemIDLong)
                       .FirstOrDefault();
            }
            return(item);
        }
示例#5
0
 public void Die()
 {
     Utility.Print(ConsoleColor.DarkRed, "The " + this.MonsterType.Name + " collapses.");
     Utility.Print(ConsoleColor.Yellow, "The " + this.MonsterType.Name + " drops " + string.Join(", ", this.Inventory.Items));
     using (var context = new TextEngineContext())
     {
         foreach (Item localItem in this.Inventory.Items)
         {
             var item = context.Items.First(i => i.ItemID == localItem.ItemID);
             item.Inventory = Room.ByID(context, Program.character.CurrentRoom.RoomID).Inventory;
         }
         context.SaveChanges();
         Program.RefreshGameState(context);
     }
 }
示例#6
0
        // this method only does anything when a new game is started
        public void SetInitialRoom(TextEngineContext context)
        {
            // set the default room to the first room in the list
            // TODO: maybe change this to 0, 0
            if (this.CurrentRoom == null)
            {
                // TODO: how to make the model do this automatically?
                // ThenInclude: https://github.com/aspnet/EntityFramework/wiki/Design-Meeting-Notes:-January-8,-2015
                var rooms = from r in context.Rooms
                            .Include(r => r.Doors).ThenInclude(d => d.TargetRoom) // this syntax was found in a bug fix
                            .Include(r => r.Inventory)
                            select r;

                this.CurrentRoom = rooms.First();
            }
        }
示例#7
0
        public void Move(Direction direction)
        {
            Door door = null;

            using (var context = new TextEngineContext())
            {
                door = (from d in context.Doors
                        .Include(d => d.TargetRoom).ThenInclude(r => r.Doors)
                        .Include(d => d.DoorItemConditions).ThenInclude(c => c.Item).ThenInclude(i => i.Inventory)
                        .Where(d => d.SourceRoom.RoomID == Program.character.CurrentRoom.RoomID && d.Direction == direction)
                        select d).FirstOrDefault();
                if (door == null)
                {
                    Utility.Print(ConsoleColor.Yellow, "There doesn't appear to be an exit in that direction.");
                    return;
                }
            }

            // are there item conditions?
            bool itemConditionsMet = true;

            foreach (var cond in door.DoorItemConditions)
            {
                if (Program.character.Inventory.Items.FirstOrDefault(x => x.ItemID == cond.Item.ItemID) == null)
                {
                    Utility.Print(ConsoleColor.Yellow, "You must possess the " + cond.Item.Name + " to unlock this door!");
                    itemConditionsMet = false;
                }
                else
                {
                    Utility.Print(ConsoleColor.Yellow, "You successfully unlock the door using the " + cond.Item.Name + "!");
                    Console.WriteLine();
                }
            }

            if (!itemConditionsMet)
            {
                return;
            }

            /*
             * Room TargetRoom = door == null ? null : door.TargetRoom;
             *
             * if (TargetRoom == null)
             * {
             *  var defaultColor = Console.ForegroundColor;
             *  Console.ForegroundColor = ConsoleColor.Yellow;
             *  Console.WriteLine("There is no exit in that direction!");
             *  Console.ForegroundColor = defaultColor;
             *  return;
             * }
             */

            Program.character.CurrentRoom = door.TargetRoom;
            using (var context = new TextEngineContext())
            {
                Character c    = Character.GetInstance(context);
                Room      room = Room.ByID(context, door.TargetRoom.RoomID);
                c.CurrentRoom = room;
                context.SaveChanges();
                Program.RefreshGameState(context);
            }
            Program.character.CurrentRoom.Look();
        }
示例#8
0
        public static Door FromDir(TextEngineContext context, string dir)
        {
            Direction direction = Utility.StringToDirection(dir);

            return(context.Doors.FirstOrDefault(x => x.Direction == direction && x.SourceRoom.RoomID == Program.character.CurrentRoom.RoomID));
        }