Example #1
0
        private void BtnDeleteActionClick(object sender, EventArgs e)
        {
            if (AI == null)
            {
                MessageBox.Show(Resources.NullAI + Resources.DeleteAction);
                return;
            }

            if (listController.SelectedIndex == -1)
                return;

            var cNdx = listController.SelectedIndex;
            var aNdx = listActionSet.SelectedIndex;
            var aCnt = AI.ActionController[cNdx].ActionSetsCount;

            if (aNdx == -1)
            {
                MessageBox.Show(Resources.NoAction);
                return;
            }

            var actionSet = new ActionSet[aCnt - 1];

            for (var i = 0; i < aCnt - 1; i++)
            {
                if (i < aNdx) actionSet[i] = AI.ActionController[cNdx].ActionSet[i];
                if (i >= aNdx) actionSet[i] = AI.ActionController[cNdx].ActionSet[i + 1];
            }

            AI.ActionController[cNdx].ActionSetsCount = AI.ActionController[cNdx].ActionSetsCount - 1;
            AI.ActionController[cNdx].ActionSet = actionSet;

            listActionSet.Items.Clear();

            foreach (var t in AI.ActionController[cNdx].ActionSet)
                listActionSet.Items.Add("[" + t.ID.ToString(CultureInfo.InvariantCulture) + "] " + t.Name);

            txtCondition.Clear();
            listProcedure.Items.Clear();
        }
Example #2
0
        private void BtnAddActionClick(object sender, EventArgs e)
        {
            if (AI == null)
            {
                MessageBox.Show(Resources.NullAI + Resources.AddActionSet);
                return;
            }

            if (listController.SelectedIndex == -1) return;

            if (txtActionName.Text == "")
            {
                MessageBox.Show(Resources.EnterActionName);
                return;
            }

            var cNdx = listController.SelectedIndex;
            var aNdx = listActionSet.SelectedIndex;
            var aCnt = AI.ActionController[cNdx].ActionSetsCount;
            var actionID = 0;

            if (StringType.IsNumber(txtActionID.Text))
            {
                actionID = Convert.ToInt32(txtActionID.Text);

                for (var i = 0; i < aCnt; i++)
                {
                    if (actionID != AI.ActionController[cNdx].ActionSet[i].ID) continue;

                    MessageBox.Show(Resources.ActionWithID + actionID + Resources.Exists);
                    return;
                }
            }

            if (aNdx == -1)
                aNdx = aCnt;

            var actionSet = new ActionSet[aCnt + 1];

            for (var j = 0; j <= aCnt; j++)
            {
                if (j < aNdx) actionSet[j] = AI.ActionController[cNdx].ActionSet[j];
                if (j > aNdx) actionSet[j] = AI.ActionController[cNdx].ActionSet[j - 1];
            }

            actionSet[aNdx] = new ActionSet();
            actionSet[aNdx].Version = 11;

            if (txtActionID.Text == "")
            {
                var asCount = aCnt;

                for (var k = 0; k < aCnt; k++)
                    if (asCount < AI.ActionController[cNdx].ActionSet[k].ID)
                        asCount = AI.ActionController[cNdx].ActionSet[k].ID;

                for (var x = 0; x <= asCount; x++)
                {
                    for (var y = 0; y < aCnt; y++)
                        if (x == AI.ActionController[cNdx].ActionSet[y].ID)
                            actionSet[aNdx].ID = -1;

                    if (actionSet[aNdx].ID != -1)
                    {
                        actionSet[aNdx].ID = x;
                        break;
                    }

                    actionSet[aNdx].ID = x;
                }
            }
            else
                actionSet[aNdx].ID = actionID;

            var tmpFlags = new byte[3];
            tmpFlags[0] = 1;

            var flags = tmpFlags;

            actionSet[aNdx].Flags = flags;
            actionSet[aNdx].Name = txtActionName.Text;

            actionSet[aNdx].Condition = new Condition();
            actionSet[aNdx].Condition.OperID = 3;
            actionSet[aNdx].Condition.ArgBytes = 4;

            var value = new byte[] { 0, 0, 128, 63 };

            actionSet[aNdx].Condition.Value = value;
            actionSet[aNdx].Condition.SubNodeL = 0;
            actionSet[aNdx].Condition.SubNodeR = 0;
            actionSet[aNdx].Condition.ConditionType = 3;

            actionSet[aNdx].ProcedureCount = 1;

            actionSet[aNdx].Procedure = new Procedure[1];
            actionSet[aNdx].Procedure[0] = new Procedure();

            actionSet[aNdx].Procedure[0].Type = 2;

            var unicode = Encoding.Unicode;
            var rageMsg = unicode.GetBytes("RaGEZONE Forums - http://Forum.RaGEZONE.com");
            var msgSize = rageMsg.Length + 2;
            var mess = new byte[msgSize];

            Array.Copy(rageMsg, mess, rageMsg.Length);
            mess[rageMsg.Length] = 0;
            mess[rageMsg.Length + 1] = 0;

            var parameter = new object[] { msgSize, mess };

            actionSet[aNdx].Procedure[0].Parameter = parameter;
            actionSet[aNdx].Procedure[0].Target = 0;

            AI.ActionController[cNdx].ActionSetsCount = AI.ActionController[cNdx].ActionSetsCount + 1;
            AI.ActionController[cNdx].ActionSet = actionSet;

            listActionSet.Items.Clear();

            foreach (var t in AI.ActionController[cNdx].ActionSet)
                listActionSet.Items.Add("[" + t.ID.ToString(CultureInfo.InvariantCulture) + "] " + t.Name);

            txtCondition.Clear();
            listProcedure.Items.Clear();
        }