当前位置:网站首页>Et5.0 value type generation

Et5.0 value type generation

2022-06-13 00:50:00 Small fish game development

Generate results :
 Insert picture description here
stay ET in , The value component is composed of 5 The added value determines the final result , Of course, you can also change the formula

		public void Update(NumericType numericType)
		{
    
			if (numericType < NumericType.Max)
			{
    
				return;
			}
			int final = (int)numericType / 10;
			int bas = final * 10 + 1;
			int add = final * 10 + 2;
			int pct = final * 10 + 3;
			int finalAdd = final * 10 + 4;
			int finalPct = final * 10 + 5;

			//  A number can affect many things , Like speed , Add one buff It is possible to increase the absolute value of speed 100, There are also some buff increase 10% Speed , So a value can be determined by 5 Values to control the final result 
			// final = (((base + add) * (100 + pct) / 100) + finalAdd) * (100 + finalPct) / 100;
			long result = (long)(((this.GetByKey(bas) + this.GetByKey(add)) * (100 + this.GetAsFloat(pct)) / 100f + this.GetByKey(finalAdd)) * (100 + this.GetAsFloat(finalPct)) / 100f * 10000);
			this.NumericDic[final] = result;
		}

In the end = (( Base value + Fixed value ) X percentage + Final fixed value ) X The final percentage
Take a chestnut : A simple attack speed requires the following 6 Value names

AttackSpeed = 1000
AttackSpeedBase = AttackSpeed * 10 + 1,
AttackSpeedAdd = AttackSpeed * 10 + 2,
AttackSpeedPct = AttackSpeed * 10 + 3,
AttackSpeedFinalAdd = AttackSpeed * 10 + 4,
AttackSpeedFinalPct = AttackSpeed * 10 + 5,

If you copy and paste manually, it is a disaster . We can simply write a generation tool , First, write the attributes to be generated to excel
ID: Attribute ID
Name: Name of property
IsOperation: Whether this value needs to be calculated ( Some attributes do not need to be calculated , Generating an attribute is enough )
Label: Finally, a comment , Easily accessible
 Insert picture description here
Get ready excel Then you can read excel Generate the corresponding class file , Has been integrated in the framework NPOI, Use it directly to read excel that will do ,NPOI There is a small problem , The last line is unreadable . Be sure to add a blank line at the end

using System;
using System.Collections.Generic;
using NPOI.XSSF.UserModel;
using NPOI.XWPF.UserModel;
using System.IO;

namespace ETModel
{
    
    public static class ExcelHelper
    {
    
		public static List<string[]> ReadExcel(string path)
		{
    
			try
			{
    
				if (!File.Exists(path))
				{
    
					throw new Exception($"{
      path}  non-existent ");
				}
				XSSFWorkbook xssfWorkbook;
				using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
				{
    
					xssfWorkbook = new XSSFWorkbook(file);
				}
				var iSheet = xssfWorkbook.GetSheetAt(0);

				int colCount = iSheet.GetRow(1).LastCellNum;

				List<string[]> result = new List<string[]>();
				var list = new List<string>(colCount);
				for (int row = 0; row < iSheet.LastRowNum; row++)
				{
    
					var iRow = iSheet.GetRow(row);
					for (int col = 0; col < colCount; col++)
					{
    
						if (iRow != null)
						{
    
							var cell = iRow.GetCell(col);
							if (cell != null)
							{
    
								list.Add(cell.ToString() ?? string.Empty);
							}
						}
					}
					if (list.Count == 0)
						continue;
					result.Add(list.ToArray());
					list.Clear();
				}
				return result;
			}
			catch (Exception ex)
			{
    
				throw ex;
			}
		}

		public static void WriteExcel(string path, List<string[]> table)
		{
    
			XSSFWorkbook workbook = null;
			FileStream fs = null;
			try
			{
    
				workbook = new XSSFWorkbook();
				var sheet = workbook.CreateSheet("Sheet");
				for (int i = 0; i < table.Count; i++)
				{
    
					var row = sheet.CreateRow(i);
					var rowData = table[i];
					for (int j = 0; j < rowData.Length; j++)
					{
    
						var cell = row.CreateCell(j);
						var cellData = rowData[j];
						cell.SetCellValue(cellData);
					}
				}

				using (fs = File.OpenWrite(path))
				{
    
					workbook.Write(fs);
				}

			}
			catch
			{
    
				workbook?.Close();
				fs?.Close();
			}
		}

		public static void ReplaceWord(string filePath, string savePath, Dictionary<string, string> dict)
		{
    
			if (!File.Exists(filePath))
				throw new Exception($"Could not find file : {
      filePath}");
			using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
			{
    
				XWPFDocument doc = new XWPFDocument(fs);
				var tables = doc.Tables;

				foreach (var table in tables)
				{
    
					foreach (var row in table.Rows)
					{
    
						foreach (var cell in row.GetTableCells())
						{
    
							foreach (var para in cell.Paragraphs)
							{
    
								var oldString = para.ParagraphText;
								var newString = oldString;
								foreach (var item in dict)
								{
    
									newString = newString.Replace(item.Key, item.Value);
								}
								para.ReplaceText(oldString, newString);
							}
						}
					}
				}
				using (FileStream output = new FileStream(savePath, FileMode.Create))
				{
    
					doc.Write(output);
				}
			}
		}
	}
}

Now you can read excel, So let's generate the file

using System.IO;
using System.Text;

namespace ETModel
{
    
    public class NumericHelper
    {
    
        const string start = "// This is an automatically generated class by tools. Please do not modify it.\r\n" +
            "namespace ETModel{\r\n" +
            "\tpublic enum NumericType{\r\n" +
            "\t\tMax = 10000,\r\n";
        const string end = "\t}\r\n}\r\n";
        public static void Generate(string excelPath, string targetPath)
        {
    
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append(start);
            var table = ExcelHelper.ReadExcel(excelPath);
            table.RemoveAt(0);
            int id;
            bool isOperation;
            foreach (var line in table)
            {
    
                if (line.Length != 4)
                    continue;
                if(!int.TryParse(line[0],out id))
                    continue;
                if (!bool.TryParse(line[2], out isOperation))
                    continue;

                var name = line[1];
                stringBuilder.AppendLine($"\t\t/// <summary>");
                stringBuilder.AppendLine($"\t\t/// {
      line[3]}");
                stringBuilder.AppendLine($"\t\t/// </summary>");
                stringBuilder.AppendLine($"\t\t{
      name}={
      id},");
                if (isOperation)
                {
    
                    stringBuilder.AppendLine($"\t\t{
      name}Base = {
      name} * 10 + 1,");
                    stringBuilder.AppendLine($"\t\t{
      name}Add = {
      name} * 10 + 2,");
                    stringBuilder.AppendLine($"\t\t{
      name}Pct = {
      name} * 10 + 3,");
                    stringBuilder.AppendLine($"\t\t{
      name}FinalAdd = {
      name} * 10 + 4,");
                    stringBuilder.AppendLine($"\t\t{
      name}FinalPct = {
      name} * 10 + 5,");
                }
                stringBuilder.AppendLine();
            }
            stringBuilder.Append(end);
            File.WriteAllText(targetPath, stringBuilder.ToString(),Encoding.UTF8);
        }
    }
}

原网站

版权声明
本文为[Small fish game development]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280557591904.html