private void addTable(TreeNode treeNode)
        {
            NodeCondition nc = ((NodeCondition)treeNode.Tag);

            if (nc.isEmpty)
            {
                treeNode.Nodes.Clear();
                nc.isEmpty = false;
            }
            else
            {
                return;
            }

            NodeCondition ncNew   = new NodeCondition(NodeType.Table, true);
            DataTable     dtTable = DbAccess.GetTables(treeNode.Text);

            foreach (DataRow row in dtTable.Rows)
            {
                TreeNode tnTable = new TreeNode(row[0].ToString(), 3, 3);
                treeNode.Nodes.Add(tnTable);
                tnTable.Tag = ncNew;
                tnTable.Nodes.Add("<empty>");
            }
        }
    public static bool IsBST(Node root)
    {
        if (root == null)
        {
            return(true);
        }
        Stack <NodeCondition> stack = new Stack <NodeCondition>();

        stack.Push(new NodeCondition(root, int.MinValue, int.MaxValue));
        while (stack.Count > 0)
        {
            NodeCondition item = stack.Pop();
            if (item.Node.Value < item.MinValue || item.Node.Value > item.MaxValue)
            {
                return(false);
            }
            if (item.Node.Left != null)
            {
                stack.Push(new NodeCondition(item.Node.Left, item.MinValue, item.Node.Value - 1));
            }
            if (item.Node.Right != null)
            {
                stack.Push(new NodeCondition(item.Node.Right, item.Node.Value + 1, item.MaxValue));
            }
        }
        return(true);
    }
Beispiel #3
0
        public override void OnDisabled()
        {
            foreach (Npc npc in Npc.List)
            {
                npc.Kill(false);
            }

            Harmony.UnpatchAll();

            NavigationNode.Clear();
            NodeCondition.Clear();
            NodeAction.Clear();
            AITarget.Clear();
            TargetFilter.Clear();

            Handlers.Server.RoundStarted      -= EventHandlers.OnRoundStart;
            Handlers.Server.RoundEnded        -= EventHandlers.OnRoundEnd;
            Handlers.Server.WaitingForPlayers -= EventHandlers.OnWaitingForPlayers;
            Handlers.Server.RespawningTeam    -= EventHandlers.OnTeamRespawning;

            Handlers.Player.Dying -= EventHandlers.OnDying;
            Handlers.Player.EnteringPocketDimension -= EventHandlers.OnEnteringPocketDim;
            Handlers.Player.Hurting -= EventHandlers.OnHurt;

            Handlers.Map.ExplodingGrenade -= EventHandlers.OnGrenadeExplosion;
            Handlers.Map.Decontaminating  -= EventHandlers.OnDecontamination;

            Handlers.Warhead.Starting -= EventHandlers.OnWarheadStart;

            EventHandlers = null;
            Random        = null;
            Harmony       = null;
            Instance      = null;
        }
        private void addField(TreeNode treeNode)
        {
            NodeCondition nc = ((NodeCondition)treeNode.Tag);

            if (nc.isEmpty)
            {
                treeNode.Nodes.Clear();
                nc.isEmpty = false;
            }
            else
            {
                return;
            }
            string db = "";

            nc = ((NodeCondition)treeNode.Parent.Tag);
            if (nc.type == NodeType.DB)
            {
                db = treeNode.Parent.Text;
            }
            NodeCondition ncNew   = new NodeCondition(NodeType.Field, true);
            DataTable     dtTable = DbAccess.GetFields(db, treeNode.Text);

            foreach (DataRow row in dtTable.Rows)
            {
                int      i       = (bool)row["PrimaryKey"] ? 6 : 7;
                TreeNode tnTable = new TreeNode(ColumnNameFormat(row), i, i);
                treeNode.Nodes.Add(tnTable);
                tnTable.Tag = ncNew;
            }
        }
Beispiel #5
0
 public override void OnReloaded()
 {
     NavigationNode.Clear();
     NodeCondition.Clear();
     NodeAction.Clear();
     AITarget.Clear();
     TargetFilter.Clear();
 }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NodeUpdate"/> class.
        /// </summary>
        /// <param name="condition">The condition for the node, which determines its role within the load balancer. If this value is <see langword="null"/>, the existing value for the node is not changed.</param>
        /// <param name="type">The node type. If this value is <see langword="null"/>, a provider-specific default value will be used. If this value is <see langword="null"/>, the existing value for the node is not changed.</param>
        /// <param name="weight">The weight of the node. If this value is <see langword="null"/>, the existing value for the node is not changed.</param>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="weight"/> is less than or equal to 0.</exception>
        public NodeUpdate(NodeCondition condition = null, NodeType type = null, int? weight = null)
        {
            if (weight <= 0)
                throw new ArgumentOutOfRangeException("weight");

            _condition = condition;
            _type = type;
            _weight = weight;
        }
        private void addDB(TreeNode treeNode, bool isSystemDB)
        {
            DataTable     dtDBName = DbAccess.GetDBNamen(isSystemDB);
            NodeCondition nc       = new NodeCondition(NodeType.DB, true);

            foreach (DataRow row in dtDBName.Rows)
            {
                TreeNode tnDB = new TreeNode(row[0].ToString(), 2, 2);
                treeNode.Nodes.Add(tnDB);
                tnDB.Tag = nc;
                tnDB.Nodes.Add("<empty>");
            }
        }
        public void ObjectExplorerActualisieren()
        {
            treeViewStruct.Nodes.Clear();
            TreeNode      tnSRV = new TreeNode(Properties.Settings.Default.ServernameText, 0, 0);
            NodeCondition nc    = new NodeCondition(NodeType.Server, false);

            treeViewStruct.Nodes.Add(tnSRV);

            tnSRV.Tag = nc;
            addServerGroup(tnSRV);
            toolStripButtonAktualisieren.Enabled = true;
            toolStripButtonTrennen.Enabled       = true;
            tnSRV.Expand();
        }
        private void treeViewStruct_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            NodeCondition nc = ((NodeCondition)e.Node.Tag);

            switch (nc.type)
            {
            case NodeType.DB:
                addTable(e.Node);
                break;

            case NodeType.Table:
                addField(e.Node);
                break;
            }
            currentDBName = GetCurrentDBName(e.Node);
        }
        private string GetCurrentDBName(TreeNode e)
        {
            NodeCondition nc = ((NodeCondition)e.Tag);

            switch (nc.type)
            {
            case NodeType.Server:
            case NodeType.Folder:
                return("master");

            case NodeType.DB:
                return(e.Text);

            default: return(currentDBName);
            }
        }
        private void addServerGroup(TreeNode treeNode)
        {
            NodeCondition nc   = new NodeCondition(NodeType.Folder, false);
            TreeNode      tnDB = new TreeNode("Datenbanken", 1, 1);

            treeNode.Nodes.Add(tnDB);

            tnDB.Tag = nc;
            TreeNode tnSysDB = new TreeNode("Systemdatenbanken", 1, 1);

            tnDB.Nodes.Add(tnSysDB);
            tnSysDB.Tag = nc;
            addDB(tnSysDB, true);
            addDB(tnDB, false);
            tnDB.Expand();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NodeConfiguration"/> class.
        /// </summary>
        /// <param name="address">The IP address of the node.</param>
        /// <param name="port">The port number for the load balanced service.</param>
        /// <param name="condition">The condition for the node, which determines its role within the load balancer.</param>
        /// <param name="type">The node type. If this value is <see langword="null"/>, a provider-specific default value will be used.</param>
        /// <param name="weight">The weight of the node.</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="address"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="condition"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If <paramref name="port"/> is less than 0 or greater than 65535.
        /// <para>-or-</para>
        /// <para>If <paramref name="weight"/> is less than or equal to 0.</para>
        /// </exception>
        public NodeConfiguration(IPAddress address, int port, NodeCondition condition, NodeType type, int? weight)
        {
            if (address == null)
                throw new ArgumentNullException("address");
            if (condition == null)
                throw new ArgumentNullException("condition");
            if (port < 0 || port > 65535)
                throw new ArgumentOutOfRangeException("port");
            if (weight <= 0)
                throw new ArgumentOutOfRangeException("weight");

            _address = address.ToString();
            _port = port;
            _condition = condition;
            _type = type;
            _weight = weight;
        }
Beispiel #13
0
    public void createCondition()
    {
        List <Control> prevSelected = new List <Control>(selectedNodes);

        deselectAll();
        prevSelected.ForEach(
            c =>
        {
            DialoguePath path  = (c is NodeDialogue)
                    ? path     = ((NodeDialogue)c).path
                    : path     = ((Node)c).data.path;
            NodeCondition node = Managers.Node.createNodeCondition(path);
            select(node, true);
        }
            );
        if (prevSelected.Count == 0)
        {
            //If nothing is selected, make a new dialogue path
            //(which will auto-create a new quote too)
            DialoguePath path = createDialoguePath();
            Managers.Node.createNodeCondition(path);
        }
    }
Beispiel #14
0
 /// <summary>
 /// 遍历树
 /// </summary>
 /// <param name="rootNode"></param>
 /// <param name="IsTrue"></param>
 /// <param name="condition"></param>
 public static void TraversalTree(ColumnNode rootNode, IsTrueHandler IsTrue, NodeCondition condition)
 {
     rootNode.Children = new List <object>();
     foreach (XmlNode node in rootNode.CorrespondXmlNode.ChildNodes)
     {
         if (IsTrue(condition, node))
         {
             rootNode.Children.Add(
                 new ColumnNode
             {
                 CorrespondXmlNode = node,
                 Title             = node.Attributes["title"].Value,
                 Name  = node.Attributes["name"].Value,
                 Level = rootNode.Level + 1
             });
         }
     }
     foreach (object node in rootNode.Children)
     {
         TraversalTree((ColumnNode)node, IsTrue, condition);
     }
     //如果只有一个子节点,则去除该节点,去除节点的子节点上移
     if (rootNode.Children.Count == 1)
     {
         rootNode.Children = ((ColumnNode)rootNode.Children[0]).Children;
         foreach (object node in rootNode.Children)
         {
             ((ColumnNode)node).Level = rootNode.Level + 1;
             TraversalTree((ColumnNode)node, IsTrue, condition);
         }
     }
     foreach (object node in rootNode.Children)
     {
         rootNode.ColSpan += ((ColumnNode)node).ColSpan;
     }
     rootNode.ColSpan = rootNode.ColSpan == 0 ? 1 : rootNode.ColSpan;
 }
Beispiel #15
0
        public override void OnEnabled()
        {
            try
            {
                Log.Info("Started plugin initialization...");

                Instance = this;

                Random = new Random();


                foreach (MethodBase bas in Evs.Events.Instance.Harmony.GetPatchedMethods())
                {
                    if (bas.Name.Equals("TransmitData"))
                    {
                        Exiled.Events.Events.DisabledPatchesHashSet.Add(bas);
                    }
                    else if (bas.DeclaringType.Name.Equals("RoundSummary") && bas.Name.Equals("Start"))
                    {
                        Exiled.Events.Events.DisabledPatchesHashSet.Add(bas);
                    }
                    else if (bas.Name.Equals("BanUser"))
                    {
                        Exiled.Events.Events.DisabledPatchesHashSet.Add(bas);
                    }
                    else if (bas.Name.Equals("CallCmdShoot"))
                    {
                        Exiled.Events.Events.DisabledPatchesHashSet.Add(bas);
                    }
                }

                Evs.Events.Instance.ReloadDisabledPatches();


                Harmony = new HarmonyLib.Harmony($"gamehunt.cnpcs.{reloads}");
                reloads++;

                Harmony.PatchAll();

                EventHandlers = new EventHandlers();

                Handlers.Server.RoundStarted      += EventHandlers.OnRoundStart;
                Handlers.Server.RoundEnded        += EventHandlers.OnRoundEnd;
                Handlers.Server.WaitingForPlayers += EventHandlers.OnWaitingForPlayers;
                Handlers.Server.RespawningTeam    += EventHandlers.OnTeamRespawning;

                Handlers.Player.Dying += EventHandlers.OnDying;
                Handlers.Player.EnteringPocketDimension += EventHandlers.OnEnteringPocketDim;
                Handlers.Player.Hurting += EventHandlers.OnHurt;

                Handlers.Map.ExplodingGrenade += EventHandlers.OnGrenadeExplosion;
                Handlers.Map.Decontaminating  += EventHandlers.OnDecontamination;

                Handlers.Warhead.Starting += EventHandlers.OnWarheadStart;

                if (!Directory.Exists(Config.NPCs_root_path))
                {
                    Directory.CreateDirectory(Config.NPCs_root_path);
                }
                if (!Directory.Exists(Config.NPCs_nodes_path))
                {
                    Directory.CreateDirectory(Config.NPCs_nodes_path);
                }
                if (!Directory.Exists(Config.NPCs_mappings_path))
                {
                    Directory.CreateDirectory(Config.NPCs_mappings_path);
                }
                if (!File.Exists(Config.NPCs_nav_mappings_path))
                {
                    StreamWriter sw = File.CreateText(Config.NPCs_nav_mappings_path);
                    sw.Write(Config.DefaultNavMappings);
                    sw.Close();
                }
                if (!File.Exists(Path.Combine(Config.NPCs_nodes_path, "default_node.yml")))
                {
                    StreamWriter sw = File.CreateText(Path.Combine(Config.NPCs_nodes_path, "default_node.yml"));
                    sw.Write(Config.DefaultNodeContents);
                    sw.Close();
                }
                if (!File.Exists(Path.Combine(Config.NPCs_root_path, "default_npc.yml")))
                {
                    StreamWriter sw = File.CreateText(Path.Combine(Config.NPCs_root_path, "default_npc.yml"));
                    sw.Write(Config.DefaultNPCContents);
                    sw.Close();
                }

                Log.Info("Registering conditions...");

                NodeCondition.Register(new RoleCondition());
                NodeCondition.Register(new HasItemCondition());
                NodeCondition.Register(new HasntItemCondition());
                NodeCondition.Register(new HealthCondition());
                NodeCondition.Register(new ArtificalHealthCondition());
                NodeCondition.Register(new HasEffectCondition());
                NodeCondition.Register(new HasntEffectCondition());
                NodeCondition.Register(new PermissionCondition());
                NodeCondition.Register(new RoundTimeCondition());
                NodeCondition.Register(new NukeStateCondition());
                NodeCondition.Register(new HeldItemCondition());
                NodeCondition.Register(new RoleExistsCondition());
                NodeCondition.Register(new RoleNotExistsCondition());
                NodeCondition.Register(new RandomCondition());

                Log.Info("Registering actions...");

                NodeAction.Register(new Actions.DieAction());
                NodeAction.Register(new Actions.GiveItemAction());
                NodeAction.Register(new Actions.RetrieveItemAction());
                NodeAction.Register(new Actions.GiveHealthAction());
                NodeAction.Register(new Actions.ConsumeHealthAction());
                NodeAction.Register(new Actions.EnableEffectAction());
                NodeAction.Register(new Actions.DisableEffectAction());
                NodeAction.Register(new Actions.BroadcastAction());
                NodeAction.Register(new Actions.HeldItemAction());
                NodeAction.Register(new Actions.BlackoutAction());
                NodeAction.Register(new Actions.ChangeRoleAction());
                NodeAction.Register(new Actions.ChangeSelfRoleAction());
                NodeAction.Register(new Actions.NukeStartAction());
                NodeAction.Register(new Actions.NukeStopAction());
                NodeAction.Register(new Actions.StartDecontaminationAction());
                NodeAction.Register(new Actions.SwitchGodAction());
                NodeAction.Register(new Actions.MoveAction());
                NodeAction.Register(new Actions.RotationAction());
                NodeAction.Register(new Actions.RoundEndAction());
                NodeAction.Register(new Actions.CassieAction());
                NodeAction.Register(new Actions.RoomTeleportAction());
                NodeAction.Register(new Actions.RoomSelfTeleportAction());
                NodeAction.Register(new Actions.DropItemAction());
                NodeAction.Register(new Actions.NavEnqueueAction());
                NodeAction.Register(new Actions.NavClearAction());
                NodeAction.Register(new Actions.FollowAction());
                NodeAction.Register(new Actions.StopFollowAction());
                NodeAction.Register(new Actions.FireEventAction());
                NodeAction.Register(new Actions.ShootAction());
                NodeAction.Register(new Actions.GoToRoomAction());
                NodeAction.Register(new Actions.ControlDoorAction());
                NodeAction.Register(new Actions.ToggleAIAction());

                Log.Info("Registering AI targets...");

                AITarget.Register(new AITestTarget());
                AITarget.Register(new AIFindPlayerTarget());
                AITarget.Register(new AIAttackTarget());
                AITarget.Register(new AINavigateToRoom());
                AITarget.Register(new AIFollowTarget());
                AITarget.Register(new AIFindItemTarget());
                AITarget.Register(new AIConditionalJump());
                //AITarget.Register(new AIRunAwayTarget());
                //AITarget.Register(new AIFindAmmoTarget());
                AITarget.Register(new AIStop());

                Log.Info("Registering targets filters...");

                TargetFilter.Register(new CommonTargetFilter());
                TargetFilter.Register(new Scp939TargetFilter());
                TargetFilter.Register(new Scp096TargetFilter());

                Log.Info($"CustomNPCs plugin loaded. @gamehunt");
            }
            catch (Exception e)
            {
                Log.Error($"There was an error loading the plugin: {e}");
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NodeConfiguration"/> class.
        /// </summary>
        /// <param name="hostDomain">The domain name of the node.</param>
        /// <param name="port">The port number for the load balanced service.</param>
        /// <param name="condition">The condition for the node, which determines its role within the load balancer.</param>
        /// <param name="type">The node type. If this value is <see langword="null"/>, a provider-specific default value will be used.</param>
        /// <param name="weight">The weight of the node.</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="hostDomain"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="condition"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentException">If <paramref name="hostDomain"/> is empty.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If <paramref name="port"/> is less than 0 or greater than 65535.
        /// <para>-or-</para>
        /// <para>If <paramref name="weight"/> is less than or equal to 0.</para>
        /// </exception>
        public NodeConfiguration(string hostDomain, int port, NodeCondition condition, NodeType type, int? weight)
        {
            if (hostDomain == null)
                throw new ArgumentNullException("hostDomain");
            if (condition == null)
                throw new ArgumentNullException("condition");
            if (string.IsNullOrEmpty(hostDomain))
                throw new ArgumentException("hostDomain cannot be empty");
            if (port < 0 || port > 65535)
                throw new ArgumentOutOfRangeException("port");
            if (weight <= 0)
                throw new ArgumentOutOfRangeException("weight");

            _address = hostDomain;
            _port = port;
            _condition = condition;
            _type = type;
            _weight = weight;
        }
Beispiel #17
0
        /// <summary>
        /// 根据节点信息构造表格的头部,并返回数据绑定列
        /// </summary>
        /// <param name="rootNode"></param>
        /// <param name="IsTrue"></param>
        /// <param name="condition"></param>
        /// <param name="dataColumns"></param>
        /// <returns></returns>
        public static string BuildTableHead(ColumnNode rootNode, IsTrueHandler IsTrue, NodeCondition condition, out List <ColumnNode> dataColumns)
        {
            //遍历模板树,构造一棵符合条件的树,用于生成表
            TraversalTree(rootNode, IsTrue, condition);
            //根据树得到头部列表
            List <List <ColumnNode> > headRows = new List <List <ColumnNode> >();

            dataColumns = new List <ColumnNode>();
            ConvertTreeToList(rootNode, headRows, dataColumns);
            StringBuilder htmlBuilder = new StringBuilder();

            htmlBuilder.Append("<thead>");
            for (int i = 1; i < headRows.Count; i++)
            {
                htmlBuilder.Append("<tr style=\"text-align:center;\">");
                for (int j = 0; j < headRows[i].Count; j++)
                {
                    //如果没有子节点,行数=总行数-当前的层级
                    int rowSpan = headRows[i][j].Children.Count == 0 ? headRows.Count - headRows[i][j].Level : 1;
                    htmlBuilder.AppendFormat("<th colspan=\"{0}\" rowspan=\"{1}\">{2}</th>", headRows[i][j].ColSpan, rowSpan, headRows[i][j].Title);
                }
                htmlBuilder.Append("</tr>");
            }
            htmlBuilder.Append("</thead>");
            return(htmlBuilder.ToString());
        }