示例#1
0
        private static string SerializeRecursive(ResearchNode node, string text, ApplicationDbContext db, ActionModel model)
        {
            text += "<tr>";
            text += "<td>" + node.Name + "</td>";

            string pre = "";
            node.GetPrerequisiteNodes(db).ToList().ForEach(n => pre += n.Name + ", ");
            text += "<td>" + pre + "</td>";

            string nextNodes = "";
            node.GetNextNodes(db).ToList().ForEach(n => nextNodes += n.Name + ", ");
            text += "<td>" + nextNodes + "</td>";

            text += "<td>" + node.RDCost + "</td>";

            text += "<td>" + node.CashCost + "</td>";

            var activeNodes =
                db.ActiveResearchNodes.Where(arn => arn.Corporation.Id == model.Corporation.Id).Select(n => n.ResearchNode.Name).ToList();

            if (model.DataCache.LearnedResearchNodes.Select(n => n.Name).Contains(node.Name))
            {
                text += "<td><button disabled class='btn btn-default'>Learned</button></td>";
            }
            else if (activeNodes.Contains(node.Name))
            {
                text += "<td><button class='btn btn-default' data-toggle='button' type='button' onclick='addSingleAction(&quot;" +
                    ActionService.GetActionStringForView(Constants.Constants.ActionTypeResearch, "Action="+Constants.Constants.CancelActiveResearch + ":" + node.Name,
                        Constants.Constants.Empty) + @";&quot;, this)'>Cancel</button></td>";
            }
            else
            {
                var cashEnabledText = model.DataCache.Corporation.Cash >= node.CashCost && node.Enabled ? "enabled" : "disabled";

                text +=
                    @"<td><button " + cashEnabledText +
                    " class='btn btn-default' type='button' data-toggle='button' onclick='addSingleAction(&quot;" +
                    ActionService.GetActionStringForView(Constants.Constants.ActionTypeResearch, node.Script,
                        Constants.Constants.LearnByCash) + @";&quot;, this)'>Cash ("+node.CashCost+")</button>";

                var researchEnabledText = node.Enabled ? "enabled" : "disabled"; ;

                text +=
                    @"<button " + researchEnabledText + " data-toggle='button' class='btn btn-default' type='button' onclick='addSingleAction(&quot;" +
                    ActionService.GetActionStringForView(Constants.Constants.ActionTypeResearch, node.Script,
                        Constants.Constants.SetActiveResearch) + @";&quot;, this)'>Set Active Research (" +
                    node.GetTurnsToResearch(model.Corporation.RD) + ")</button></td>";
            }

            text += "</tr>";

            if (node.GetNextNodes(db).Any()) node.GetNextNodes(db).ToList().ForEach(n => text = SerializeRecursive(n, text, db, model));
            return text;
        }
示例#2
0
        public static void CreateTestTreeInDB(ApplicationDbContext db, Corporation corp)
        {
            var node1 = new ResearchNode
            {
                Name = "Basic Rocketry",
                Description = "The basics.",
                RDCost = 10,
                CashCost = 50000,
                Script = "Action=LearnResearch:Basic Rocketry;Unlocks=Intermediate Rocketry;"
            };

            var node2 = new ResearchNode
            {
                Name = "Intermediate Rocketry",
                Description = "Werner von Braun would be delighted.",
                RDCost = 30,
                CashCost = 400000,
                Script = "Action=LearnResearch:Intermediate Rocketry;Prereq=Basic Rocketry;Unlocks=Advanced Rocketry"
            };

            var node3 = new ResearchNode
            {
                Name = "Advanced Rocketry",
                Description = "Einstein ain't got shit on these badass rockets.",
                RDCost = 75,
                CashCost = 4000000,
                Script = "Action=LearnResearch:Advanced Rocketry;Prereq=Intermediate Rocketry&Basic Rocketry;"
            };

            var learnedNode1 = new LearnedResearchNode()
            {
                Corporation = corp,
                ResearchNode = node1
            };

            db.Add(node1);
            db.Add(node2);
            db.Add(node3);
            db.Add(learnedNode1);
            db.SaveChanges();
        }