Пример #1
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");
        }
Пример #2
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);
        }
Пример #3
0
        public override void UpdateTask(PlayerTask playerTask, System.Web.Mvc.FormCollection form)
        {
            Player player = Player.Load(playerTask.playerId);

            // data submitted; log it and continue to wait
            if (form["data"] != null)
            {
                playerTask.data = playerTask.data.Split(',')[0] + "," + form["data"];
                playerTask.Save();
                return;
            }

            // all submissions have been made
            string status = GetStatus(playerTask);

            if (status == "")
            {
                return;
            }

            // personal bonus for getting it right
            if (Convert.ToInt32(playerTask.data.Split(',')[1]) == GetProduct())
            {
                player.Rank += 10;
            }
            else
            {
                player.Rank -= 10;
                Notification.CreatePlayer(string.Join(" x ", GetSummitTasks().Select(o => o.data.Split(',')[0])) + " = " + GetProduct() + ". Duh.", player.id);
            }
            player.Save();

            if (IsPrimary(playerTask))
            {
                if (status == "True")
                {
                    foreach (var pt in GetSummitTasks())
                    {
                        pt.GetPlayer.GetTeam.score += 15;
                        pt.GetPlayer.GetTeam.Save();
                    }
                    Newsfeed.Create("The Earth Plutocratic Congress Interagency Technology Summit is once again an overwhelming success.", Newsfeed.Context.success);
                }
                else
                {
                    foreach (var pt in GetSummitTasks())
                    {
                        pt.GetPlayer.GetTeam.score -= 8;
                        pt.GetPlayer.GetTeam.Save();
                    }

                    Newsfeed.Create("Tragedy at the Earth Plutocratic Congress Interagency Technology Summit caused by a simple mathematical error.", Newsfeed.Context.warning);
                }
            }

            playerTask.State = Task.TaskState.Completed;
            playerTask.Save();
        }
Пример #4
0
        public override string Init(Player player)
        {
            string[] commodities = new string[] { "Smithore", "Crystite", "Carbonite", "Dilithium", "Spice", "Adamantine", "Aether", "Byzanium", "Cobalt Thorium G", "Duranium", "Frinkonium", "Ice-nine", "Kryptonite", "Mithril", "Octiron", "Latinum", "Unobtanium", "Verterium Cortenide", "Inaprovaline", "Corbomite " };
            int      price       = HGameApp.Rnd.Next(100, 1000);
            string   commodity   = commodities[HGameApp.Rnd.Next(commodities.Length)];

            Newsfeed.Create("Current trading price of " + commodity + ": $" + price, Newsfeed.Context.success);

            return(commodity + "," + price);
        }
Пример #5
0
        public override void Created(PlayerTask playerTask)
        {
            // other teams
            foreach (Team team in Team.GetAll().Where(o => o.id != playerTask.GetPlayer.teamId))
            {
                var highestRankedAgent = team.GetPlayers.OrderByDescending(o => o.Rank).First();
                if (highestRankedAgent == null)
                {
                    continue;
                }
                PlayerTask.CreateTask("summit", highestRankedAgent.id, _primes[HGameApp.Rnd.Next(_primes.Length)] + ",0");
            }

            Newsfeed.Create("The once-every-century Earth Plutocratic Congress Interagency Technology Summit has commenced. Best of luck to the company representatives.", Newsfeed.Context.success);
        }
Пример #6
0
        /// <summary> Periodically add a new newsfeed item. </summary>
        public static void AddNewsfeedItem()
        {
            Newsfeed mostRecent = Newsfeed.Load();

            if (DateTime.Now.Subtract(mostRecent.created).TotalSeconds > 120)
            {
                var allitems = System.IO.File.ReadAllLines(System.Web.HttpContext.Current.Server.MapPath("/App_Data/newsitems.txt")).Where(o => !string.IsNullOrWhiteSpace(o) && !o.StartsWith("#")).ToList();

                // remove those that have just been displayed
                var lastFew = GetAll().OrderByDescending(o => o.created).Take(7).Select(n => n.body);
                allitems.RemoveAll(o => lastFew.Contains(o.Split('\t')[1]));

                var item = allitems[HGameApp.Rnd.Next(allitems.Count)];
                Newsfeed.Create(item.Split('\t')[1], (Newsfeed.Context)Enum.Parse(typeof(Newsfeed.Context), item.Split('\t')[0]));
            }
        }
Пример #7
0
        public override void UpdateTask(PlayerTask playerTask, System.Web.Mvc.FormCollection form)
        {
            Player player = Player.Load(playerTask.playerId);

            if (form["check"] != null)
            {
                playerTask.data = form["check"];
                playerTask.Save();
                return;
            }

            if (form["data"] == null)
            {
                return;
            }

            Player recommendedPlayer = Player.Load(form["data"]);

            if (recommendedPlayer == null)
            {
                return;
            }

            recommendedPlayer.Rank += 15;
            recommendedPlayer.Save();
            Notification.CreatePlayer("The <b>" + player.GetTeam.name + "</b> is happy to present you with this coveted Award of Recognition and a commensurate increase in your role within the company. Finally.", recommendedPlayer.id);
            recommendedPlayer.GenerateNewAgentCode();

            player.Rank += 7;
            player.Save();

            playerTask.State = Task.TaskState.Completed;
            playerTask.Save();

            Newsfeed.Create("<b>" + player.GetTeam.name + "</b> has issued an Award of Recognition to <b>" + recommendedPlayer.Name + "</b>. Thanks for all your hard work!", Newsfeed.Context.success);
        }
Пример #8
0
        public static string Combine(int item1Id, int item2Id)
        {
            // combined items in alphabetical order (by item id)
            List <PlayerItem> combinedItems = new List <PlayerItem> {
                PlayerItem.Load(item1Id), PlayerItem.Load(item2Id)
            };

            combinedItems = combinedItems.OrderBy(o => o.itemId).ToList();
            Player player = combinedItems[0].GetPlayer;

            if (combinedItems[0].playerId != combinedItems[1].playerId)
            {
                return(null);                                                                    // this should never happen - can only combine items from a single player's inventory
            }
            // the ids of the items in alphabetical order
            string bothItems = string.Join(",", combinedItems.Select(o => o.itemId));

            // 27b/6
            if (combinedItems.Any(o => o.itemId == "27b6"))
            {
                PlayerItem t27b6Item = combinedItems.First(o => o.itemId == "27b6");
                PlayerItem otherItem = combinedItems.Where(o => o.id != t27b6Item.id).First();
                return("You apply the <b>" + t27b6Item.GetItem.name + "</b> to the <b>" + otherItem.GetItem.name + "</b> but realize that the <b>" + t27b6Item.GetItem.name + "</b> doesn't have the necessary stamp from Information Retreival.");
            }

            // acid destroys the both things
            if (combinedItems.Any(o => o.itemId == "acid"))
            {
                PlayerItem acidItem  = combinedItems.First(o => o.itemId == "acid");
                PlayerItem otherItem = combinedItems.Where(o => o.id != acidItem.id).First();                 // could also be acid!

                // both acid! let's make a thing!
                if (otherItem.itemId == "acid")
                {
                    acidItem.Delete();
                    otherItem.Delete();
                    PlayerItem sentienceItem = player.AddItem("sentience");
                    return("You pour the two <b>" + acidItem.GetItem.name + "s</b> together and, after a violent conflagration of acrid smoke, discover that you've created <b>" + sentienceItem.GetItem.name + "</b>.");
                }

                // not unique items
                if (otherItem.GetItem.unique)
                {
                    acidItem.Delete();
                    return("The <b>" + acidItem.GetItem.name + "</b> drips off the <b>" + otherItem.GetItem.name + "</b> leaving it completely unmarred. Fascinating.");
                }

                // dissolves whatever
                acidItem.Delete();
                otherItem.Delete();
                return("You immersed the <b>" + otherItem.GetItem.name + "</b> in the <b>" + acidItem.GetItem.name + "</b> and it completely dissolves.");
            }

            // normal research tree construction
            if (bothItems == "electronics,sentience")
            {
                if (player.GetTeam.TechLevel < 1)
                {
                    return(InsufficientTech(combinedItems));
                }
                combinedItems[0].Delete();
                combinedItems[1].Delete();
                PlayerItem newItem = player.AddItem("stabilizer");
                return("The <b>" + combinedItems[1].GetItem.name + "</b> fuses with some of the <b>" + combinedItems[0].GetItem.name + "</b> and creates an <b>" + newItem.GetItem.name + "</b>.");
            }

            if (bothItems == "electronics,essence")
            {
                if (player.GetTeam.TechLevel < 1)
                {
                    return(InsufficientTech(combinedItems));
                }
                combinedItems[0].Delete();
                combinedItems[1].Delete();
                PlayerItem newItem = player.AddItem("chronotons");
                return("The <b>" + combinedItems[1].GetItem.name + "</b> absorbs some of the <b>" + combinedItems[0].GetItem.name + "</b> and creates a <b>" + newItem.GetItem.name + "</b>.");
            }

            if (bothItems == "electronics,photonic")
            {
                if (player.GetTeam.TechLevel < 1)
                {
                    return(InsufficientTech(combinedItems));
                }
                combinedItems[0].Delete();
                combinedItems[1].Delete();
                PlayerItem newItem = player.AddItem("fluxcapacitor");
                return("You enhance the <b>" + combinedItems[1].GetItem.name + "</b> with some <b>" + combinedItems[0].GetItem.name + "</b> and assemble a <b>" + newItem.GetItem.name + "</b>.");
            }

            if (bothItems == "essence,photonic")
            {
                if (player.GetTeam.TechLevel < 1)
                {
                    return(InsufficientTech(combinedItems));
                }
                combinedItems[0].Delete();
                combinedItems[1].Delete();
                PlayerItem newItem = player.AddItem("separator");
                return("You route the output of the <b>" + combinedItems[1].GetItem.name + "</b> through the <b>" + combinedItems[0].GetItem.name + "</b> and devise a make-shift <b>" + newItem.GetItem.name + "</b>.");
            }

            // second level research
            if (bothItems == "albumen,stabilizer")
            {
                if (player.GetTeam.TechLevel < 2)
                {
                    return(InsufficientTech(combinedItems));
                }
                combinedItems[0].Delete();
                combinedItems[1].Delete();
                PlayerItem newItem = player.AddItem("converter");
                Newsfeed.Create("<b>" + player.GetTeam.name + "</b> makes great strides in developing the strange alien technology.", Newsfeed.Context.success);
                return("You inject the <b>" + combinedItems[0].GetItem.name + "</b> into the <b>" + combinedItems[1].GetItem.name + "</b> and invent an <b>" + newItem.GetItem.name + "</b>.");
            }

            if (bothItems == "albumen,chronotons")
            {
                if (player.GetTeam.TechLevel < 2)
                {
                    return(InsufficientTech(combinedItems));
                }
                combinedItems[0].Delete();
                combinedItems[1].Delete();
                PlayerItem newItem = player.AddItem("manifold");
                Newsfeed.Create("<b>" + player.GetTeam.name + "</b> continues to uncover the secrets of the strange alien technology.", Newsfeed.Context.success);
                return("You integrate the <b>" + combinedItems[0].GetItem.name + "</b> with the <b>" + combinedItems[1].GetItem.name + "</b> and realize you now have a <b>" + newItem.GetItem.name + "</b>.");
            }

            if (bothItems == "fluxcapacitor,separator")
            {
                if (player.GetTeam.TechLevel < 2)
                {
                    return(InsufficientTech(combinedItems));
                }
                combinedItems[0].Delete();
                combinedItems[1].Delete();
                PlayerItem newItem = player.AddItem("compensator");
                Newsfeed.Create("<b>" + player.GetTeam.name + "</b> publishes ground-breaking paper detailing the strange alien technology.", Newsfeed.Context.success);
                return("You hurridly tape the <b>" + combinedItems[0].GetItem.name + "</b> to the front of the <b>" + combinedItems[1].GetItem.name + "</b> because you need a <b>" + newItem.GetItem.name + "</b>.");
            }

            // generic nothing event
            return("You tried to combine <b>" + combinedItems[0].GetItem.name + "</b> with <b>" + combinedItems[1].GetItem.name + "</b>, but nothing happened.");
        }