Example #1
0
        public static Player Create(Team team)
        {
            Guid id = Guid.NewGuid();

            hgameDataContext dc = hgameDataContext.GetDataContext();

            dc.Players.InsertOnSubmit(new Player()
            {
                id = id, teamId = team.id, sessionId = Session.CurrentSessionId, created = DateTime.Now, readNotifications = ""
            });
            dc.SubmitChanges();

            Myriads.Cache.Remove("Player");

            Player p = Player.Load(id);

            Newsfeed.Create("A new agent, <b>" + p.Name + "</b>,  has joined <b>" + p.GetTeam.name + "</b>.", Newsfeed.Context.info);

            Notification.CreateTeam("<b>" + p.Name + "</b> has joined your team.", p.teamId);

            p.ReadNotifications = Notification.GetAllForTeam(team.id).Select(o => o.id).ToList();
            p.Save();

            return(p);
        }
Example #2
0
 /// <summary> All notifications for current session, regardless of recipient. </summary>
 public static List <Notification> GetAll()
 {
     return((List <Notification>) Myriads.Cache.Get("Notifications", Session.CurrentSessionId, delegate() {
         hgameDataContext dc = hgameDataContext.GetDataContext();
         return dc.Notifications.Where(o => o.sessionId == Session.CurrentSessionId).ToList();
     }));
 }
Example #3
0
        /// <summary> Mark any "Waiting" tasks as "Expired" if they are. </summary>
        public static void ExpireTasks()
        {
            List <PlayerTask> expiredTasks = GetAll().Where(o => o.State == Task.TaskState.Waiting && o.Expiration < DateTime.Now).ToList();

            if (expiredTasks.Count == 0)
            {
                return;
            }

            // in additional to the normal expiration functionality, there may be some special tasks
            foreach (PlayerTask pt in expiredTasks)
            {
                pt.GetTask.GetTaskDetail().Expired(pt);
            }

            hgameDataContext dc = hgameDataContext.GetDataContext();

            foreach (PlayerTask playerTaskDb in dc.PlayerTasks.Where(o => expiredTasks.Select(p => p.id).Contains(o.id)))
            {
                playerTaskDb.State = Task.TaskState.Expired;
                Notification.Create("Your task, '" + playerTaskDb.GetTask.name + "', has expired.", null, playerTaskDb.playerId);

                // every expired task results in a loss of rank
                Player player = Player.Load(playerTaskDb.playerId);
                player.Rank -= 9;
                player.Save();
            }
            dc.SubmitChanges();

            Myriads.Cache.Remove("PlayerTask");
        }
Example #4
0
 public static List <Session> GetAll()
 {
     return((List <Session>) Myriads.Cache.Get("Session", "all", delegate() {
         hgameDataContext dc = hgameDataContext.GetDataContext();
         return dc.Sessions.ToList();
     }));
 }
Example #5
0
 public static List <Task> GetAll()
 {
     return((List <Task>) Myriads.Cache.Get("Task", "all", delegate() {
         hgameDataContext dc = hgameDataContext.GetDataContext();
         return dc.Tasks.ToList();
     }));
 }
Example #6
0
 public static List <Item> GetAll()
 {
     return((List <Item>) Myriads.Cache.Get("Item", "all", delegate() {
         hgameDataContext dc = hgameDataContext.GetDataContext();
         return dc.Items.ToList();
     }));
 }
Example #7
0
        public void Save()
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            Task task = dc.Tasks.SingleOrDefault(o => o.id == id);

            if (task == null)
            {
                task = new Task()
                {
                    id = id
                };
                dc.Tasks.InsertOnSubmit(task);
            }

            task.active        = active;
            task.manual        = manual;
            task.name          = name;
            task.duration      = duration;
            task.minPlayerRank = minPlayerRank;
            task.minTechLevel  = minTechLevel;
            dc.SubmitChanges();

            Myriads.Cache.Remove("Task");
        }
Example #8
0
        /// <summary> Assign this task to the specified player, ignoring dependencies and slots. If you specify a data string neither Init() nor Created() will be called on this player task. </summary>
        public static PlayerTask CreateTask(string taskId, Guid playerId, string data = null)
        {
            Task task = Task.Load(taskId);

            try {
                hgameDataContext dc = hgameDataContext.GetDataContext();
                dc.PlayerTasks.InsertOnSubmit(new PlayerTask()
                {
                    playerId = playerId, taskId = taskId, state = Task.TaskState.Waiting.ToString(), assigned = DateTime.Now,
                    data     = (data == null ? task.GetTaskDetail().Init(Player.Load(playerId)) : data)
                });
                dc.SubmitChanges();

                Myriads.Cache.Remove("PlayerTask");

                PlayerTask lastTask = GetLastTask(playerId);
                if (data == null)
                {
                    lastTask.GetTask.GetTaskDetail().Created(lastTask);
                }
                return(lastTask);
            } catch { }             // sometimes things don't work out

            return(null);
        }
Example #9
0
        public static void StartNewSession()
        {
            var previousSessionCodes = GetAll().Select(o => o.Code).ToList();

            // theoretically, this could turn into an infinite loop - but only once there 10,000 sessions have been created
            Session newSession = new Session();

            do
            {
                newSession = new Session()
                {
                    id = Guid.NewGuid(), start = DateTime.Now, state = SessionState.Running.ToString(), lastModified = DateTime.Now
                };
            } while (previousSessionCodes.Contains(newSession.Code));

            hgameDataContext dc = hgameDataContext.GetDataContext();

            dc.Sessions.InsertOnSubmit(newSession);
            dc.SubmitChanges();

            foreach (Team team in Team.GetAll())
            {
                team.score = 0;
                team.Save();
            }

            CurrentSessionId = newSession.id;
            TimeWarpLevel    = 0;

            Newsfeed.Create("Strange new alien technology discovered! Who will be the first to develop it?", Newsfeed.Context.success);

            Myriads.Cache.Remove("Session");
        }
Example #10
0
        public void Delete()
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            dc.PlayerTasks.DeleteOnSubmit(dc.PlayerTasks.SingleOrDefault(o => o.id == id));
            dc.SubmitChanges();

            Myriads.Cache.Remove("PlayerTask");
        }
Example #11
0
        public void Delete()
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            dc.Notifications.DeleteOnSubmit(dc.Notifications.SingleOrDefault(o => o.id == id));
            dc.SubmitChanges();

            Myriads.Cache.Remove("Notifications");
        }
Example #12
0
        /// <summary> Returns all tasks for all players (or the specified player) in the current game session, regardless of task state. </summary>
        public static List <PlayerTask> GetAll(Guid?playerId = null)
        {
            List <PlayerTask> all = (List <PlayerTask>) Myriads.Cache.Get("PlayerTask", "all", delegate() {
                hgameDataContext dc = hgameDataContext.GetDataContext();
                return(dc.PlayerTasks.Where(o => o.Player.sessionId == Session.CurrentSessionId).ToList());
            });

            return(all.Where(o => !playerId.HasValue || o.playerId == playerId.Value).ToList());
        }
Example #13
0
        public void Delete()
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            dc.Teams.DeleteOnSubmit(dc.Teams.SingleOrDefault(o => o.id.ToLower() == id.ToLower()));
            dc.SubmitChanges();

            Myriads.Cache.Remove("Team");
        }
Example #14
0
        public static List <Player> GetAll(bool allSessions = false)
        {
            List <Player> all = (List <Player>) Myriads.Cache.Get("Player", "all", delegate() {
                hgameDataContext dc = hgameDataContext.GetDataContext();
                return(dc.Players.ToList());
            });

            return(all.Where(o => allSessions || o.sessionId == Session.CurrentSessionId).ToList());
        }
Example #15
0
        public void Save()
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            PlayerItem PlayerItem = dc.PlayerItems.Single(o => o.id == id);

            // we don't actually have any variables here, yet.
            dc.SubmitChanges();

            Myriads.Cache.Remove("PlayerItem");
        }
Example #16
0
        public void Save()
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            PlayerTask PlayerTask = dc.PlayerTasks.Single(o => o.id == id);

            PlayerTask.state = state;
            PlayerTask.data  = data;
            dc.SubmitChanges();

            Myriads.Cache.Remove("PlayerTask");
        }
Example #17
0
        public void SetState(SessionState newState)
        {
            State = newState;

            hgameDataContext dc = hgameDataContext.GetDataContext();
            var session         = dc.Sessions.SingleOrDefault(o => o.id == id);

            session.state        = state;
            session.lastModified = DateTime.Now;
            dc.SubmitChanges();

            Myriads.Cache.Remove("Session");
        }
Example #18
0
        public static Notification Create(string message, string teamId = null, Guid?playerId = null)
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            dc.Notifications.InsertOnSubmit(new Notification()
            {
                sessionId = Session.CurrentSessionId, created = DateTime.Now, message = message, recipientTeamId = teamId, recipientPlayerId = playerId
            });
            dc.SubmitChanges();

            Myriads.Cache.Remove("Notifications");

            return(Load());
        }
Example #19
0
        public static PlayerItem AddItem(string itemId, Guid playerId)
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            dc.PlayerItems.InsertOnSubmit(new PlayerItem()
            {
                playerId = playerId, itemId = itemId
            });
            dc.SubmitChanges();

            Myriads.Cache.Remove("PlayerItem");

            return(GetAll().Where(o => o.playerId == playerId && o.itemId == itemId).OrderByDescending(o => o.id).First());
        }
Example #20
0
        public static Newsfeed Create(string body, Context context)
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            dc.Newsfeeds.InsertOnSubmit(new Newsfeed()
            {
                sessionId = Session.CurrentSessionId, created = DateTime.Now, body = body, context = context.ToString()
            });
            dc.SubmitChanges();

            Myriads.Cache.Remove("Newsfeeds");

            return(Load());
        }
Example #21
0
        public void Save()
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            Team team = dc.Teams.SingleOrDefault(o => o.id == id);

            if (team == null)
            {
                team = new Team()
                {
                    id = id
                };
                dc.Teams.InsertOnSubmit(team);
            }

            team.name        = name;
            team.score       = score;
            team.description = description;
            team.goal        = goal;
            dc.SubmitChanges();

            Myriads.Cache.Remove("Team");
        }
Example #22
0
        public void Save()
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            Item item = dc.Items.SingleOrDefault(o => o.id == id);

            if (item == null)
            {
                item = new Item()
                {
                    id = id
                };
                dc.Items.InsertOnSubmit(item);
            }

            item.name        = name;
            item.description = description;
            item.size        = size;
            item.unique      = unique;
            dc.SubmitChanges();

            Myriads.Cache.Remove("Item");
        }
Example #23
0
        public void Save()
        {
            hgameDataContext dc = hgameDataContext.GetDataContext();

            Player player = dc.Players.SingleOrDefault(o => o.id == id);

            if (player == null)
            {
                player = new Player()
                {
                    id = id, created = DateTime.Now
                };
                dc.Players.InsertOnSubmit(player);
            }

            player.teamId            = teamId;
            player.sessionId         = sessionId;
            player.rank              = rank;
            player.idle              = idle;
            player.readNotifications = string.Join(",", ReadNotifications);
            dc.SubmitChanges();

            Myriads.Cache.Remove("Player");
        }
Example #24
0
        public static hgameDataContext GetDataContext()
        {
            var dc = new hgameDataContext();

            return(new hgameDataContext(new StackExchange.Profiling.Data.ProfiledDbConnection(dc.Connection, MiniProfiler.Current)));
        }