当前位置:网站首页>Et5.0 value type generation
Et5.0 value type generation
2022-06-13 00:50:00 【Small fish game development】
Generate results :
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 
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);
}
}
}
边栏推荐
- Can GPU acceleration pytorch work?
- [MRCTF2020]Ez_ bypass --BUUCTF
- OceanBase 雄踞墨天轮2021年度中国数据库魔力象限领导者
- Arduino control soil moisture sensor
- People and gods are angry. Details of Tangshan "mass beating of women incident"
- Today's sleep quality record 74 points
- sort
- 三角波与三角波卷积
- Canvas game 2048 free map size
- Buuctf babyupload[gxyctf2019]
猜你喜欢
![[JS] battle chess](/img/1f/83ca6bcb000a5567dc6d3b72463ff8.jpg)
[JS] battle chess

Kotlin 协程,job的生命周期

Win10 home vs pro vs enterprise vs enterprise LTSC

Antdpro - protable realizes the linkage effect of two selection boxes
![[error] invalid use of incomplete type uses an undefined type](/img/8a/7cb5d270cfd8831ddc146687fe4499.png)
[error] invalid use of incomplete type uses an undefined type

Binary tree -- using hierarchical sequence and middle sequence to determine a tree

Programming training 1

Static analysis of malicious code

1. Google grpc framework source code analysis Hello World

DNS attack surface analysis
随机推荐
什么是 Meebits?一个简短的解释
Canvas airplane game
硬(磁)盘(一)
Stack overflow learning summary
What are the conditions of index invalidation?
How many steps are appropriate for each cycle of deep learning?
Oceanbase is the leader in the magic quadrant of China's database in 2021
Another year 1024, happy programmer's Day!
. The way to prove the effect of throwing exceptions on performance in. Net core
Easyexcel read excel simple demo
pytorch是什么?解释pytorch的基本概念
A simple deadlock example
【SCA-CNN 解读】空间与通道注意力:Spatial and Channel-wise Attention
【北亚服务器数据恢复】虚拟机文件丢失导致Hyper-V服务瘫痪的数据恢复案例
[virtual machine] notes on virtual machine environment problems
In / out / inout details of MySQL stored procedures
Learning and Development notes of mongdb
Kotlin coroutine suspend function suspend keyword
Notes: the 11th and 12th generation mobile versions of Intel support the native thunderbolt4 interface, but the desktop version does not
[network protocol] problems and solutions in the use of LwIP