예제 #1
0
 public Monster Get(int monsterId)
 {
     using (var context = new DigsiteContext())
     {
         return(context.Monster.Find(monsterId));
     }
 }
예제 #2
0
        public void PauseAllDigging()
        {
            var context = new DigsiteContext();

            context.DigState.ToList().ForEach(d => d.IsPaused = (byte)1);
            context.SaveChanges();
        }
예제 #3
0
        private void RemoveDeletedPlayerItems(DigsiteContext context, GameState gameState, List <int> currentPlayerItemIds)
        {
            var existingItems = context.PlayerItem.Where(pi => pi.PlayerId == gameState.PlayerId).ToList();
            var itemsToDelete = existingItems.Where(ei => !currentPlayerItemIds.Any(pi => pi == ei.PlayerItemId)).ToList();

            context.PlayerItem.RemoveRange(itemsToDelete);
        }
예제 #4
0
 public Item Get(int itemId)
 {
     using (var context = new DigsiteContext())
     {
         return(context.Item.Find(itemId));
     }
 }
예제 #5
0
 private void RemoveDeleted(DigsiteContext context, GameState gameState, List <int> currentPlayerItemIds)
 {
     RemoveDeletedPlayerItems(context, gameState, currentPlayerItemIds);
     RemoveDeletedNearbyMonsters(context, gameState);
     RemoveDeletedDigState(context, gameState);
     RemoveDeletedPlayerBuffs(context, gameState);
     RemoveDeletedNearbyMonsterBuffs(context, gameState);
 }
예제 #6
0
        private void RemoveDeletedDigState(DigsiteContext context, GameState gameState)
        {
            // Need to use this variable because a null gamestate.digstate turns into not null when attached by the parent function
            var gameStateDigIsNull = gameState.Player.DigState == null;
            var contextDigState    = context.DigState.SingleOrDefault(ds => ds.PlayerId == gameState.PlayerId);

            if (contextDigState != null && gameStateDigIsNull)
            {
                context.DigState.Remove(contextDigState);
            }
        }
예제 #7
0
        private void RemoveDeletedNearbyMonsters(DigsiteContext context, GameState gameState)
        {
            if (gameState.Player.DigState == null)
            {
                return;
            }
            var existingMonsters = context.NearbyMonster.Where(nm => nm.DigState.PlayerId == gameState.PlayerId);
            var monstersToDelete = existingMonsters.Where(em => !gameState.Player.DigState.NearbyMonster.Any(nm => nm.NearbyMonsterId == em.NearbyMonsterId));

            context.NearbyMonster.RemoveRange(monstersToDelete);
        }
예제 #8
0
        public async Task SaveGameState(GameState gameState)
        {
            var currentPlayerItemIds = gameState.Player.PlayerItem.Select(pi => pi.PlayerItemId).ToList();

            using (var context = new DigsiteContext())
            {
                context.Attach(gameState);
                RemoveDeleted(context, gameState, currentPlayerItemIds);
                IEnumerable <EntityEntry> unchangedEntities = context.ChangeTracker.Entries().Where(x => x.State == EntityState.Unchanged);

                foreach (EntityEntry ee in unchangedEntities)
                {
                    ee.State = EntityState.Modified;
                }

                await context.SaveChangesAsync();
            }
        }
예제 #9
0
 public async Task <GameState> GetGameState(int playerId)
 {
     using (var context = new DigsiteContext())
     {
         return(await context.GameState
                .Include(gs => gs.Player)
                .Include(gs => gs.Player.PlayerState)
                .Include(gs => gs.Player.DigState)
                .Include(gs => gs.Player.PlayerItem)
                .ThenInclude(pi => pi.Item)
                .ThenInclude(i => i.ItemSlot)
                .Include(gs => gs.Player.DigState.NearbyMonster)
                .ThenInclude(nm => nm.Monster)
                .Include(gs => gs.Player.DigState.NearbyMonster)
                .ThenInclude(nm => nm.NearbyMonsterBuff)
                .SingleAsync(gs => gs.PlayerId == playerId));
     }
 }
예제 #10
0
        private void EnsureTestUserExists()
        {
            var testUserId = 1001;
            var context    = new DigsiteContext();

            if (context.Player.Count(p => p.PlayerId == testUserId) == 0)
            {
                context.Player.Add(new Player
                {
                    PlayerId  = 1001,
                    GameState = new GameState()
                    {
                        IsDigging = 0
                    },
                    PlayerState = new PlayerState()
                    {
                        Money = 0
                    }
                });
            }
            context.SaveChanges();
        }
예제 #11
0
 private void RemoveDeletedNearbyMonsterBuffs(DigsiteContext context, GameState gameState)
 {
 }
예제 #12
0
 private void RemoveDeletedPlayerBuffs(DigsiteContext context, GameState gameState)
 {
 }