Tools.java 5.73 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
package emu.grasscutter.tools;

3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileOutputStream;
Melledy's avatar
Melledy committed
6
7
import java.io.FileReader;
import java.io.FileWriter;
8
import java.io.InputStreamReader;
9
import java.io.OutputStreamWriter;
Melledy's avatar
Melledy committed
10
import java.io.PrintWriter;
11
import java.nio.charset.StandardCharsets;
Melledy's avatar
Melledy committed
12
13
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
KingRainbow44's avatar
KingRainbow44 committed
14
import java.util.ArrayList;
Melledy's avatar
Melledy committed
15
16
17
18
19
20
21
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.google.gson.reflect.TypeToken;

22
import emu.grasscutter.GameConstants;
Melledy's avatar
Melledy committed
23
import emu.grasscutter.Grasscutter;
24
import emu.grasscutter.data.GameData;
Melledy's avatar
Melledy committed
25
26
27
28
import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.data.def.MonsterData;
29
import emu.grasscutter.data.def.SceneData;
30
import emu.grasscutter.utils.Utils;
Melledy's avatar
Melledy committed
31

KingRainbow44's avatar
KingRainbow44 committed
32
public final class Tools {
Melledy's avatar
Melledy committed
33
34
35
36
37
38
	
	@SuppressWarnings("deprecation")
	public static void createGmHandbook() throws Exception {
		ResourceLoader.loadResources();
		
		Map<Long, String> map;
39
		try (InputStreamReader fileReader = new InputStreamReader(new FileInputStream(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "TextMap/TextMapEN.json")), StandardCharsets.UTF_8)) {
Melledy's avatar
Melledy committed
40
41
42
43
44
			map = Grasscutter.getGsonFactory().fromJson(fileReader, new TypeToken<Map<Long, String>>() {}.getType());
		}
		
		List<Integer> list;
		String fileName = "./GM Handbook.txt";
45
		try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8), false)) {
Melledy's avatar
Melledy committed
46
47
48
			DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");  
			LocalDateTime now = LocalDateTime.now();
			   
49
			writer.println("// Grasscutter " + GameConstants.VERSION + " GM Handbook");
Melledy's avatar
Melledy committed
50
51
			writer.println("// Created " + dtf.format(now) + System.lineSeparator() + System.lineSeparator());
			
52
			list = new ArrayList<>(GameData.getAvatarDataMap().keySet());
Melledy's avatar
Melledy committed
53
54
55
56
			Collections.sort(list); 
			 
			writer.println("// Avatars");
			for (Integer id : list) {
57
				AvatarData data = GameData.getAvatarDataMap().get(id);
Melledy's avatar
Melledy committed
58
59
60
61
62
				writer.println(data.getId() + " : " + map.get(data.getNameTextMapHash()));
			}
			
			writer.println();
			
63
			list = new ArrayList<>(GameData.getItemDataMap().keySet());
Melledy's avatar
Melledy committed
64
65
66
67
			Collections.sort(list); 
			
			writer.println("// Items");
			for (Integer id : list) {
68
				ItemData data = GameData.getItemDataMap().get(id);
Melledy's avatar
Melledy committed
69
70
71
72
73
				writer.println(data.getId() + " : " + map.get(data.getNameTextMapHash()));
			}
			
			writer.println();
			
74
			writer.println("// Scenes");
75
			list = new ArrayList<>(GameData.getSceneDataMap().keySet());
76
77
78
			Collections.sort(list); 
			
			for (Integer id : list) {
79
				SceneData data = GameData.getSceneDataMap().get(id);
80
81
82
83
84
				writer.println(data.getId() + " : " + data.getScriptData());
			}
			
			writer.println();
			
Melledy's avatar
Melledy committed
85
			writer.println("// Monsters");
86
			list = new ArrayList<>(GameData.getMonsterDataMap().keySet());
Melledy's avatar
Melledy committed
87
88
89
			Collections.sort(list); 
			
			for (Integer id : list) {
90
				MonsterData data = GameData.getMonsterDataMap().get(id);
Melledy's avatar
Melledy committed
91
92
93
94
95
				writer.println(data.getId() + " : " + map.get(data.getNameTextMapHash()));
			}
		}
		
		Grasscutter.getLogger().info("GM Handbook generated!");
96
		System.exit(0);
Melledy's avatar
Melledy committed
97
	}
98
99

	@SuppressWarnings("deprecation")
100
	public static void createGachaMapping(String location) throws Exception {
101
102
103
104
105
106
107
108
109
		ResourceLoader.loadResources();
		
		Map<Long, String> map;
		try (InputStreamReader fileReader = new InputStreamReader(new FileInputStream(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "TextMap/TextMapEN.json")), StandardCharsets.UTF_8)) {
			map = Grasscutter.getGsonFactory().fromJson(fileReader, new TypeToken<Map<Long, String>>() {}.getType());
		}
		
		List<Integer> list;

110
		String fileName = location;
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

		try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8), false)) {
			
			list = new ArrayList<>(GameData.getAvatarDataMap().keySet());
			Collections.sort(list); 
			 
			writer.println("mappings = {\"en-us\": {"); 

			// Avatars
			boolean first = true;
			for (Integer id : list) {
				AvatarData data = GameData.getAvatarDataMap().get(id);
				int avatarID = data.getId();
				if (avatarID >= 11000000) { // skip test avatar
					continue;
				}
				if (first) { // skip adding comma for the first element
					first = false;
				} else {
					writer.print(",");
				}
				String color;
				switch (data.getQualityType()){
					case "QUALITY_PURPLE":
						color = "purple";
						break;
					case "QUALITY_ORANGE":
						color = "yellow";
						break;
					case "QUALITY_BLUE":
					default:
						color = "blue";
				}
				
				writer.println(
					"\"" + (avatarID % 1000 + 1000) + "\" : [\"" 
					+ map.get(data.getNameTextMapHash()) + "(Avatar)\", \"" 
					+ color + "\"]");
			}
			
			writer.println();
			
			list = new ArrayList<>(GameData.getItemDataMap().keySet());
			Collections.sort(list); 
			
			// Weapons
			for (Integer id : list) {
				ItemData data = GameData.getItemDataMap().get(id);
				if (data.getId() <= 11101 || data.getId() >= 20000) {
					continue; //skip non weapon items
				}
				String color;

				switch (data.getRankLevel()){
					case 3: 
						color = "blue";
						break;
					case 4:
						color = "purple";
						break;
					case 5:
						color = "yellow";
						break;
					default:
						continue; // skip unnecessary entries
				}
				writer.println(",\"" + data.getId() +
						 "\" : [\"" + map.get(data.getNameTextMapHash()).replaceAll("\"", "")
						 + "(Weapon)\",\""+ color + "\"]");
			}
			writer.println(",\"200\": \"Standard\", \"301\": \"Avatar Event\", \"302\": \"Weapon event\"");
			writer.println("}\n}");
		}
184
		
185
		Grasscutter.getLogger().info("Mappings generated!");
186
		System.exit(0);
187
	}
Melledy's avatar
Melledy committed
188
}