示例#1
0
 public void AddCondition(SmartCondition cond)
 {
     children.Add(cond);
     conditions.Add(cond);
     cond.parent         = this;
     cond.RequestUpdate += ActionRequestUpdateCallback;
 }
示例#2
0
 public void InsertCondition(SmartCondition smartCondition, int index)
 {
     children.Add(smartCondition);
     conditions.Insert(index, smartCondition);
     smartCondition.parent         = this;
     smartCondition.RequestUpdate += ActionRequestUpdateCallback;
     Invalide();
 }
示例#3
0
        public override List <Warning> Validate()
        {
            List <Warning> warnings = base.Validate();

            for (int i = 0; i < conditions.Count; ++i)
            {
                SmartCondition condition = GetCondition(i);
                warnings.AddRange(condition.Validate());
            }
            for (int i = 0; i < actions.Count; ++i)
            {
                SmartAction action = GetAction(i);
                warnings.AddRange(action.Validate());
            }
            return(warnings);
        }
示例#4
0
        public void ReplaceCondition(SmartCondition replace, SmartCondition search)
        {
            replace.Copy(search);

            int index = children.IndexOf(search);

            children.Remove(search);
            children.Insert(index, replace);

            index = conditions.IndexOf(search);
            conditions.Remove(search);
            conditions.Insert(index, replace);

            replace.parent         = this;
            replace.RequestUpdate += ActionRequestUpdateCallback;
            Invalide();
        }
        // @TODO: to rewrite ASAP!! just for test
        // I know, it it TOTAL MESS
        public void LoadFromDB(int entryorguid)
        {
            this.entryorguid = entryorguid;
            DBConnect connect = new DBConnect();
            bool      opened  = connect.OpenConnection();

            if (!opened)
            {
                return;
            }

            events.Clear();

            MySql.Data.MySqlClient.MySqlCommand      cmd        = connect.Query("SELECT * FROM conditions WHERE sourceentry = " + entryorguid + " and sourceid=0 and sourcetypeorreferenceid=22");
            Dictionary <int, List <SmartCondition> > conditions = new Dictionary <int, List <SmartCondition> >();

            using (MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader())
            {
                int prevelsegroup = 0;
                while (reader.Read())
                {
                    int id = Convert.ToInt32(reader["sourcegroup"]) - 1;

                    if (!conditions.ContainsKey(id))
                    {
                        conditions.Add(id, new List <SmartCondition>());
                    }

                    if (Convert.ToInt32(reader["ElseGroup"]) != prevelsegroup)
                    {
                        conditions[id].Add(new CONDITION_LOGICAL_OR());
                    }

                    SmartCondition cond = SmartFactory.GetInstance().ConditionFactory(Convert.ToInt32(reader["ConditionTypeOrReference"]));
                    cond.UpdateParams(0, (Convert.ToInt32(reader["ConditionValue1"])));
                    cond.UpdateParams(1, (Convert.ToInt32(reader["ConditionValue2"])));
                    cond.UpdateParams(2, (Convert.ToInt32(reader["ConditionValue3"])));
                    cond.invert = (Convert.ToInt32(reader["NegativeCondition"]) == 1);


                    conditions[id].Add(cond);
                    prevelsegroup = Convert.ToInt32(reader["ElseGroup"]);
                }
            }

            cmd = connect.Query("SELECT * FROM smart_scripts WHERE source_type = " + (int)Type + " and entryorguid = " + entryorguid + " order by id");
            SmartEvent prev = null;
            bool       keep_legacy_comments       = false;
            bool       keep_lagacy_comments_asked = false;

            using (MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader())
            {
                int next_link = -1;
                while (reader.Read())
                {
                    //(`entryorguid`,`source_type`,`id`,`link`,`event_type`,`event_phase_mask`,`event_chance`,`event_flags`,`event_param1`,`event_param2`,`event_param3`,`event_param4`,`action_type`,`action_param1`,`action_param2`,`action_param3`,`action_param4`,`action_param5`,`action_param6`,`target_type`,`target_param1`,`target_param2`,`target_param3`,`target_x`,`target_y`,`target_z`,`target_o`,`comment`)
                    int         id      = Convert.ToInt32(reader["id"]);
                    int         entry   = Convert.ToInt32(reader["entryorguid"]);
                    string      comment = Convert.ToString(reader["comment"]);
                    SmartAction a       = SmartFactory.GetInstance().ActionFactory(Convert.ToInt32(reader["action_type"]));
                    SmartTarget target  = SmartFactory.GetInstance().TargetFactory(Convert.ToInt32(reader["target_type"]));

                    for (int i = 0; i < 6; i++)
                    {
                        a.UpdateParams(i, Convert.ToInt32(reader["action_param" + (i + 1)]));
                    }

                    for (int i = 0; i < 3; i++)
                    {
                        target.UpdateParams(i, Convert.ToInt32(reader["target_param" + (i + 1)]));
                    }

                    target.position[0] = (float)Convert.ToDouble(reader["target_x"]);
                    target.position[1] = (float)Convert.ToDouble(reader["target_y"]);
                    target.position[2] = (float)Convert.ToDouble(reader["target_z"]);
                    target.position[3] = (float)Convert.ToDouble(reader["target_o"]);

                    a.Target = target;


                    if (comment.IndexOf(" // ") > -1)
                    {
                        a.Comment = comment.Substring(comment.IndexOf(" // ") + 4);
                    }
                    else if (!Properties.Settings.Default.DiscardLegacyComments)
                    {
                        if (!keep_lagacy_comments_asked)
                        {
                            DialogResult res =
                                PSTaskDialog.cTaskDialog.ShowTaskDialogBox("Legacy comments",
                                                                           "Legacy comments",
                                                                           "Visual SAI Studio has detected script you loaded doesn't have comments created with SAI Studio.\n",
                                                                           "",
                                                                           "",
                                                                           "Never propose keeping legacy comments",
                                                                           "",
                                                                           "Keep legacy comments|Discard legacy comments",
                                                                           PSTaskDialog.eTaskDialogButtons.Cancel,
                                                                           PSTaskDialog.eSysIcons.Question, PSTaskDialog.eSysIcons.Information);
                            if (PSTaskDialog.cTaskDialog.VerificationChecked)
                            {
                                Properties.Settings.Default.DiscardLegacyComments = true;
                            }
                            if (PSTaskDialog.cTaskDialog.CommandButtonResult == 0)
                            {
                                keep_legacy_comments = true;
                            }
                            keep_lagacy_comments_asked = true;
                        }

                        if (keep_legacy_comments)
                        {
                            a.Comment = comment;
                        }
                    }

                    if (id == next_link)
                    {
                        prev.AddAction(a);
                    }
                    else
                    {
                        SmartEvent ev = SmartFactory.GetInstance().EventFactory(Convert.ToInt32(reader["event_type"]));
                        ev.chance    = Convert.ToInt32(reader["event_chance"]);
                        ev.flags     = (SmartEventFlag)Convert.ToInt32(reader["event_flags"]);
                        ev.phasemask = (SmartPhaseMask)Convert.ToInt32(reader["event_phase_mask"]);
                        ev.UpdateParams(0, Convert.ToInt32(reader["event_param1"]));
                        ev.UpdateParams(1, Convert.ToInt32(reader["event_param2"]));
                        ev.UpdateParams(2, Convert.ToInt32(reader["event_param3"]));
                        ev.UpdateParams(3, Convert.ToInt32(reader["event_param4"]));
                        if (conditions.ContainsKey(id))
                        {
                            foreach (SmartCondition cond in conditions[id])
                            {
                                ev.AddCondition(cond);
                            }
                        }

                        ev.AddAction(a);
                        events.Add(ev);
                        prev = ev;
                    }


                    next_link = Convert.ToInt32(reader["link"]);
                }
            }
            connect.CloseConnection();
            scratch1.Refresh();
        }
示例#6
0
        public void ReplaceCondition(SmartCondition replace, SmartCondition search)
        {
            replace.Copy(search);

            int index = children.IndexOf(search);
            children.Remove(search);
            children.Insert(index, replace);

            index = conditions.IndexOf(search);
            conditions.Remove(search);
            conditions.Insert(index, replace);

            replace.parent = this;
            replace.RequestUpdate += ActionRequestUpdateCallback;
            Invalide();
        }
示例#7
0
 public void InsertCondition(SmartCondition smartCondition, int index)
 {
     children.Add(smartCondition);
     conditions.Insert(index, smartCondition);
     smartCondition.parent = this;
     smartCondition.RequestUpdate += ActionRequestUpdateCallback;
     Invalide();
 }
示例#8
0
 public void AddCondition(SmartCondition cond)
 {
     children.Add(cond);
     conditions.Add(cond);
     cond.parent = this;
     cond.RequestUpdate += ActionRequestUpdateCallback;
 }