Example #1
0
        /// <summary>
        /// 更新多个NPC动作
        /// </summary>
        /// <param name="mapName">地图名</param>        
        /// <param name="templateID">模板ID</param>
        private void MultiUpdate(string mapName, int templateID)
        {
            List<string> selectedNpcList = new List<string>();            
            logText = new StringBuilder();
            this.mapName = mapName;
            updateSuccessIDList.Clear();

            string sqlString = "SELECT * FROM npc";
            DataTable representTable = helper.GetDataTable(conn, sqlString);

            DataTable npcTable = null;
            if (templateID == 0) // 更新多个npc
            {
                sqlString = string.Format("SELECT ID, Name, RepresentID1 FROM NpcTemplate WHERE MapName = '{0}'", mapName);
                npcTable = helper.GetDataTable(conn, sqlString);
            }
            else // 更新单个npc
            {
                sqlString = string.Format("SELECT ID, Name, RepresentID1 FROM NpcTemplate WHERE ID = '{0}'", templateID.ToString());
                npcTable = helper.GetDataTable(conn, sqlString);
            }            

            sqlString = string.Format("SELECT * FROM npc_animation_record WHERE MapName = '{0}'", mapName);
            DataTable npcRecordTable = helper.GetDataTable(conn, sqlString);

            Hashtable representID1Table = new Hashtable();

            foreach(DataRow dataRow in npcTable.Rows)
            {
                string representID1 = dataRow["RepresentID1"].ToString();
                string npcName = dataRow["Name"].ToString();
                string npcID = dataRow["ID"].ToString();
                representID1Table[npcID] = representID1;

                if (representID1 != "" && representID1 != "0")
                {
                    DataRow[] rows = npcRecordTable.Select(string.Format("ID = '{0}'", npcID));

                    if (rows.Length > 0)
                    {
                        DataRow row = rows[0];

                        if (row["IsSpecific"].ToString() == "True") // 是特殊NPC
                        {
                            selectedNpcList.Add(string.Format("{0} ({1})    [特殊]", npcName, npcID));
                        }
                        else
                        {
                            if (CheckAnimationIntegrity(representID1)) // 动作完整
                            {
                                selectedNpcList.Add(string.Format("{0} ({1})", npcName, npcID));
                            }
                            else
                            {
                                selectedNpcList.Add(string.Format("{0} ({1})    [动作不完整]", npcName, npcID));
                            } 
                        }
                    }
                    else
                    {
                        if (CheckAnimationIntegrity(representID1)) // 动作完整
                        {
                            selectedNpcList.Add(string.Format("{0} ({1})", npcName, npcID));
                        }
                        else
                        {
                            selectedNpcList.Add(string.Format("{0} ({1})    [动作不完整]", npcName, npcID));
                        }                        
                    }                   
                }                
            }

            MultiUpdateForm mForm = new MultiUpdateForm(selectedNpcList, conn, mapName);

            if (mForm.ShowDialog() == DialogResult.OK)
            {
                DataRow[] rows;
                DataRow row;   
                bool updateExistAnimation = mForm.UpdateExistAnimation;
                bool updateCommonStandbyAnimation = mForm.UpdateCommonStandbyAnimation;
                
                // 更新动作
                List<string> successNpcList = new List<string>();
                List<string> failNpcList = new List<string>();
                this.mapName = mapName;                

                foreach (string s in selectedNpcList)
                {
                    npcDisplayName = s;
                    int npcID = GetNpcID(npcDisplayName);
                    string representID1 = representID1Table[npcID.ToString()] as string;

                    if (!string.IsNullOrEmpty(representID1) && representID1 != "0")
                    {
                        rows = representTable.Select(string.Format("RepresentID = '{0}'", representID1));                    

                        if (rows.Length > 0)
                        {
                            row = rows[0];
                            this.npcModel = row["MainModelFile"].ToString();
                            this.leftHandMesh = row["S_LH_MeshFile"].ToString();
                            this.rightHandMesh = row["S_RH_MeshFile"].ToString();
                            this.faceMesh = row["S_Face_MeshFile"].ToString();
                            this.hatMesh = row["S_Hat_MeshFile"].ToString();
                            this.lhMesh = row["S_LH_MeshFile"].ToString();
                            this.lpMesh = row["S_LP_MeshFile"].ToString();
                            this.lcMesh = row["S_LC_MeshFile"].ToString();
                            this.rhMesh = row["S_RH_MeshFile"].ToString();
                            this.rpMesh = row["S_RP_MeshFile"].ToString();
                            this.rcMesh = row["S_RC_MeshFile"].ToString();
                            this.longMesh = row["S_Long_MeshFile"].ToString();
                            this.spineMesh = row["S_Spine_MeshFile"].ToString();
                            this.spine2Mesh = row["S_Spine2_MeshFile"].ToString();
                            this.leftHandMaterial = row["S_LH_MaterialFile"].ToString();
                            this.rightHandMaterial = row["S_RH_MaterialFile"].ToString();
                            this.faceMaterial = row["S_Face_MaterialFile"].ToString();
                            this.hatMaterial = row["S_Hat_MaterialFile"].ToString();
                            this.lhMaterial = row["S_LH_MaterialFile"].ToString();
                            this.lpMaterial = row["S_LP_MaterialFile"].ToString();
                            this.lcMaterial = row["S_LC_MaterialFile"].ToString();
                            this.rhMaterial = row["S_RH_MaterialFile"].ToString();
                            this.rpMaterial = row["S_RP_MaterialFile"].ToString();
                            this.rcMaterial = row["S_RC_MaterialFile"].ToString();
                            this.longMaterial = row["S_Long_MaterialFile"].ToString();
                            this.spineMaterial = row["S_Spine_MaterialFile"].ToString();
                            this.spine2Material = row["S_Spine2_MaterialFile"].ToString();
                            this.longRangeWeaponType = row["LongRangeWeaponType"].ToString();
                            this.npcRepresentID = int.Parse(representID1);                        
                            this.npcTemplateID = npcID;

                            // 替换数据
                            if (this.leftHandMesh == "")
                            {
                                this.leftHandMesh = row["LeftHandMesh"].ToString();

                                if (this.leftHandMaterial == "")
                                {
                                    this.leftHandMaterial = row["LeftHandMaterial"].ToString();
                                }
                            }

                            if (this.rightHandMesh == "")
                            {
                                this.rightHandMesh = row["RightHandMesh"].ToString();

                                if (this.rightHandMaterial == "")
                                {
                                    this.rightHandMaterial = row["RightHandMaterial"].ToString();
                                }
                            }

                            string modelScaleString = row["ModelScale"].ToString();
                            if (modelScaleString != "" && modelScaleString != "0")
                            {
                                modelScale = float.Parse(modelScaleString);
                            }
                            else
                            {
                                modelScale = 1;
                            }

                            bool success = AutoCreateActions(false, updateExistAnimation, updateCommonStandbyAnimation);

                            // 记录成功失败日志                                                                              
                            if (success)
                            {
                                successNpcList.Add(npcDisplayName);
                            }
                            else
                            {
                                failNpcList.Add(npcDisplayName);
                            }                                                
                        }
                    }                    
                }

                UpdateResultForm rForm = new UpdateResultForm(successNpcList, failNpcList);
                rForm.LogText = logText.ToString();
                rForm.Init();
                rForm.ShowDialog();
            }
        }
Example #2
0
        /// <summary>
        /// 批量更新技能
        /// </summary>
        /// <param name="templateID">模板ID</param>
        /// <param name="mapName">地图名</param>        
        public void MultiUpdateSkills(int templateID, string mapName)
        {            
            List<string> npcInfoList = new List<string>();
            List<string> updateSuccessNpcList = new List<string>();
            List<string> updateFailNpcList = new List<string>();
            logText = new StringBuilder();
            DataRow[] rows;
            DataRow row;
            string npcID;
            string npcName;
            string skillID2;

            string sqlString = string.Format("SELECT * FROM npc_skill_record");
            DataTable recordTable = helper.GetDataTable(conn, sqlString);

            sqlString = string.Format("SELECT RepresentID, SkillID FROM dic_npc_skill_caster_npc");
            DataTable skillTable = helper.GetDataTable(conn, sqlString);

            if (templateID == 0) // 更新多个npc
            {
                rows = npcGlobeTable.Select(string.Format("MapName = '{0}'", mapName));
            }
            else // 更新单个npc
            {
                rows = npcGlobeTable.Select(string.Format("ID = {0}", templateID.ToString()));
            }

            foreach(DataRow dataRow in rows)
            {
                npcID = dataRow["ID"].ToString();
                npcName = dataRow["Name"].ToString();
                skillID2 = dataRow["SkillID2"].ToString();

                DataRow[] dataRows = recordTable.Select(string.Format("ID = '{0}'", npcID));
                if (dataRows.Length > 0) // 有更新记录
                {
                    if (dataRows[0]["IsSpecific"].ToString() == "True") // 特殊npc优先
                    {
                        npcInfoList.Add(string.Format("{0} ({1})    [特殊]", npcName, npcID));
                    }
                    else
                    {
                        if (skillID2 == "" || skillID2 == "0") // 未填第二技能
                        {
                            npcInfoList.Add(string.Format("{0} ({1})    [未填第二技能]", npcName, npcID));
                        }
                        else
                        {
                            npcInfoList.Add(string.Format("{0} ({1})", npcName, npcID));                            
                        }
                    }
                }
                else
                {
                    if (skillID2 == "" || skillID2 == "0") // 未填第二技能
                    {                       
                        npcInfoList.Add(string.Format("{0} ({1})    [未填第二技能]", npcName, npcID));
                    }
                    else
                    {
                        npcInfoList.Add(string.Format("{0} ({1})", npcName, npcID));
                    }
                }
            }

            MultiUpdateSkillForm mForm = new MultiUpdateSkillForm(conn, npcInfoList);
            if (mForm.ShowDialog() == DialogResult.OK)
            {
                List<string> selectedNpcInfoList = mForm.SelectedNpcInfoList;
                
                // 更新技能
                foreach(string s in selectedNpcInfoList)
                {
                    bool updateSuccess = false;
                    npcID = GetNpcID(s).ToString();
                    npcName = GetNpcName(s);
                    logText.AppendLine(string.Format("开始为ID为{0}的NPC更新技能...", npcID));

                    rows = npcGlobeTable.Select(string.Format("ID = {0}", npcID));
                    if (rows.Length > 0)
                    {
                        row = rows[0];
                        npcTemplateID = npcID;
                        npcRepresentID = row["RepresentID1"].ToString();                        

                        if (npcRepresentID != "" && npcRepresentID != "0")
                        {
                            // 获取第二技能ID
                            DataRow[] dataRows = skillTable.Select(string.Format("RepresentID = '{0}' AND SkillID <> 28", npcRepresentID));
                            if (dataRows.Length > 0) 
                            {
                                currentSkillID2 = dataRows[0]["SkillID"].ToString();
                            }
                            else
                            {
                                currentSkillID2 = null;
                            }

                            string mainModelFile = GetMainModelFile(npcRepresentID);

                            if (!string.IsNullOrEmpty(mainModelFile))
                            {
                                string[] skillInfo = GetSkillInfo(mainModelFile);

                                if (skillInfo != null)
                                {
                                    npcForce = skillInfo[0];
                                    forceDetail = skillInfo[1];
                                }
                                else // 填空,按第二技能ID来找
                                {
                                    npcForce = "空";
                                    forceDetail = "空";
                                }

                                if (npcRepresentID != "" && npcRepresentID != "0")
                                {
                                    updateSuccess = AutoCreateSkills(false);
                                }
                                else
                                {
                                    logText.AppendLine("Error:RepresentID1为空!");
                                }                                
                            }
                            else
                            {
                                logText.AppendLine("Error:MainModelFile字段为空!");
                            } 
                        }
                        else
                        {
                            logText.AppendLine("Error:无效的表现ID!");
                        }
                    }
                    
                    if (updateSuccess)
                    {
                        updateSuccessNpcList.Add(string.Format("{0} ({1})", npcName, npcID));
                    }
                    else
                    {
                        updateFailNpcList.Add(string.Format("{0} ({1})", npcName, npcID));
                    }
                }

                // 更新记录
                try
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    SqlCommand cmd = conn.CreateCommand();

                    foreach(string s in updateSuccessNpcList)
                    {
                        npcID = GetNpcID(s).ToString();

                        sqlString = string.Format("SELECT ID FROM npc_skill_record WHERE ID = {0}", npcID);
                        cmd.CommandText = sqlString;

                        if (cmd.ExecuteScalar() == null) // 插入
                        {
                            sqlString = string.Format("INSERT INTO npc_skill_record (ID, UpdateSuccess) VALUES ({0}, 1)", npcID);
                        }
                        else // 更新
                        {
                            sqlString = string.Format("UPDATE npc_skill_record SET UpdateSuccess = 1 WHERE ID = {0}", npcID);
                        }
                        
                        cmd.CommandText = sqlString;
                        cmd.ExecuteNonQuery();
                    }
                }
                catch (SqlException ex)
                {
                    MessageBox.Show("更新NPC技能记录时产生sql异常:" + ex.Message, "更新技能记录",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }

                // 显示更新结果
                UpdateResultForm uForm = new UpdateResultForm(updateSuccessNpcList, updateFailNpcList);
                uForm.LogText = logText.ToString();
                uForm.Init();
                uForm.ShowDialog();
            }
        }