GachaBanner.java 7.14 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
package emu.grasscutter.game.gacha;

CamChua_VN's avatar
CamChua_VN committed
3
4
5
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account;
import emu.grasscutter.game.player.Player;
Melledy's avatar
Melledy committed
6
7
import emu.grasscutter.net.proto.GachaInfoOuterClass.GachaInfo;
import emu.grasscutter.net.proto.GachaUpInfoOuterClass.GachaUpInfo;
AnimeGitB's avatar
AnimeGitB committed
8
import emu.grasscutter.utils.Utils;
Melledy's avatar
Melledy committed
9

10
11
import static emu.grasscutter.Configuration.*;

12
import emu.grasscutter.Grasscutter;
13
14
import emu.grasscutter.data.common.ItemParamData;

Melledy's avatar
Melledy committed
15
16
17
18
19
20
public class GachaBanner {
	private int gachaType;
	private int scheduleId;
	private String prefabPath;
	private String previewPrefabPath;
	private String titlePath;
21
22
23
24
	private int costItemId = 0;
	private int costItemAmount = 1;
	private int costItemId10 = 0;
	private int costItemAmount10 = 10;
Melledy's avatar
Melledy committed
25
26
27
	private int beginTime;
	private int endTime;
	private int sortId;
AnimeGitB's avatar
AnimeGitB committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
	private int[] rateUpItems4 = {};
	private int[] rateUpItems5 = {};
	private int[] fallbackItems3 = {11301, 11302, 11306, 12301, 12302, 12305, 13303, 14301, 14302, 14304, 15301, 15302, 15304};
	private int[] fallbackItems4Pool1 = {1014, 1020, 1023, 1024, 1025, 1027, 1031, 1032, 1034, 1036, 1039, 1043, 1044, 1045, 1048, 1053, 1055, 1056, 1064};
	private int[] fallbackItems4Pool2 = {11401, 11402, 11403, 11405, 12401, 12402, 12403, 12405, 13401, 13407, 14401, 14402, 14403, 14409, 15401, 15402, 15403, 15405};
	private int[] fallbackItems5Pool1 = {1003, 1016, 1042, 1035, 1041};
	private int[] fallbackItems5Pool2 = {11501, 11502, 12501, 12502, 13502, 13505, 14501, 14502, 15501, 15502};
	private boolean removeC6FromPool = false;
	private boolean autoStripRateUpFromFallback = true;
	private int[][] weights4 = {{1,510}, {8,510}, {10,10000}};
	private int[][] weights5 = {{1,75}, {73,150}, {90,10000}};
	private int[][] poolBalanceWeights4 = {{1,255}, {17,255}, {21,10455}};
	private int[][] poolBalanceWeights5 = {{1,30}, {147,150}, {181,10230}};
	private int eventChance4 = 50; // Chance to win a featured event item
	private int eventChance5 = 50; // Chance to win a featured event item
Melledy's avatar
Melledy committed
43
	private BannerType bannerType = BannerType.STANDARD;
AnimeGitB's avatar
AnimeGitB committed
44
45
46
47
48

	// Kinda wanna deprecate these but they're in people's configs
	private int[] rateUpItems1 = {};
	private int[] rateUpItems2 = {};
	private int eventChance = -1;
49
	private int costItem = 0;
CamChua_VN's avatar
CamChua_VN committed
50
	private int wishMaxProgress = 2;
Melledy's avatar
Melledy committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
	
	public int getGachaType() {
		return gachaType;
	}

	public BannerType getBannerType() {
		return bannerType;
	}

	public int getScheduleId() {
		return scheduleId;
	}

	public String getPrefabPath() {
		return prefabPath;
	}

	public String getPreviewPrefabPath() {
		return previewPrefabPath;
	}

	public String getTitlePath() {
		return titlePath;
	}

76
77
78
79
80
81
82
	public ItemParamData getCost(int numRolls) {
		return switch (numRolls) {
			case 10 -> new ItemParamData((costItemId10 > 0) ? costItemId10 : getCostItem(), costItemAmount10);
			default -> new ItemParamData(getCostItem(), costItemAmount * numRolls);
		};
	}

Melledy's avatar
Melledy committed
83
	public int getCostItem() {
84
		return (costItem > 0) ? costItem : costItemId;
Melledy's avatar
Melledy committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
	}

	public int getBeginTime() {
		return beginTime;
	}

	public int getEndTime() {
		return endTime;
	}

	public int getSortId() {
		return sortId;
	}

AnimeGitB's avatar
AnimeGitB committed
99
100
	public int[] getRateUpItems4() {
		return (rateUpItems2.length > 0) ? rateUpItems2 : rateUpItems4;
Melledy's avatar
Melledy committed
101
	}
AnimeGitB's avatar
AnimeGitB committed
102
103
	public int[] getRateUpItems5() {
		return (rateUpItems1.length > 0) ? rateUpItems1 : rateUpItems5;
Melledy's avatar
Melledy committed
104
105
	}

AnimeGitB's avatar
AnimeGitB committed
106
107
108
109
110
	public int[] getFallbackItems3() {return fallbackItems3;}
	public int[] getFallbackItems4Pool1() {return fallbackItems4Pool1;}
	public int[] getFallbackItems4Pool2() {return fallbackItems4Pool2;}
	public int[] getFallbackItems5Pool1() {return fallbackItems5Pool1;}
	public int[] getFallbackItems5Pool2() {return fallbackItems5Pool2;}
Melledy's avatar
Melledy committed
111

AnimeGitB's avatar
AnimeGitB committed
112
113
114
	public boolean getRemoveC6FromPool() {return removeC6FromPool;}
	public boolean getAutoStripRateUpFromFallback() {return autoStripRateUpFromFallback;}

CamChua_VN's avatar
CamChua_VN committed
115
116
117
118
119
	public int getWishMaxProgress() {return wishMaxProgress;}

	public boolean hasEpitomized() {
		return bannerType.equals(BannerType.WEAPON);
	}
AnimeGitB's avatar
AnimeGitB committed
120
121
122
123
124
125

	public int getWeight(int rarity, int pity) {
		return switch(rarity) {
			case 4 -> Utils.lerp(pity, weights4);
			default -> Utils.lerp(pity, weights5);
		};
Melledy's avatar
Melledy committed
126
127
	}

AnimeGitB's avatar
AnimeGitB committed
128
129
130
131
132
	public int getPoolBalanceWeight(int rarity, int pity) {
		return switch(rarity) {
			case 4 -> Utils.lerp(pity, poolBalanceWeights4);
			default -> Utils.lerp(pity, poolBalanceWeights5);
		};
Melledy's avatar
Melledy committed
133
134
	}

AnimeGitB's avatar
AnimeGitB committed
135
136
137
138
139
	public int getEventChance(int rarity) {
		return switch(rarity) {
			case 4 -> eventChance4;
			default -> (eventChance > -1) ? eventChance : eventChance5;
		};
Melledy's avatar
Melledy committed
140
	}
141
	
142
143
144
145
	public GachaInfo toProto(Player player) {
		// TODO: use other Nonce/key insteadof session key to ensure the overall security for the player
		String sessionKey = player.getAccount().getSessionKey();
		
146
147
148
		String record = "http" + (HTTP_ENCRYPTION.useInRouting ? "s" : "") + "://"
						+ lr(HTTP_INFO.accessAddress, HTTP_INFO.bindAddress) + ":"
						+ lr(HTTP_INFO.accessPort, HTTP_INFO.bindPort)
149
						+ "/gacha?s=" + sessionKey + "&gachaType=" + gachaType;
KingRainbow44's avatar
KingRainbow44 committed
150
151
152
		String details = "http" + (HTTP_ENCRYPTION.useInRouting ? "s" : "") + "://"
						+ lr(HTTP_INFO.accessAddress, HTTP_INFO.bindAddress) + ":"
						+ lr(HTTP_INFO.accessPort, HTTP_INFO.bindPort)
153
						+ "/gacha/details?s=" + sessionKey + "&scheduleId=" + scheduleId;
ImmuState's avatar
ImmuState committed
154

155
		// Grasscutter.getLogger().info("record = " + record);
156
157
		ItemParamData costItem1 = this.getCost(1);
		ItemParamData costItem10 = this.getCost(10);
Melledy's avatar
Melledy committed
158
159
160
161
162
		GachaInfo.Builder info = GachaInfo.newBuilder()
				.setGachaType(this.getGachaType())
				.setScheduleId(this.getScheduleId())
				.setBeginTime(this.getBeginTime())
				.setEndTime(this.getEndTime())
163
164
165
166
				.setCostItemId(costItem1.getId())
	            .setCostItemNum(costItem1.getCount())
	            .setTenCostItemId(costItem10.getId())
	            .setTenCostItemNum(costItem10.getCount())
Melledy's avatar
Melledy committed
167
168
	            .setGachaPrefabPath(this.getPrefabPath())
	            .setGachaPreviewPrefabPath(this.getPreviewPrefabPath())
ImmuState's avatar
ImmuState committed
169
170
	            .setGachaProbUrl(details)
	            .setGachaProbUrlOversea(details)
Melledy's avatar
Melledy committed
171
172
173
174
175
	            .setGachaRecordUrl(record)
	            .setGachaRecordUrlOversea(record)
	            .setLeftGachaTimes(Integer.MAX_VALUE)
	            .setGachaTimesLimit(Integer.MAX_VALUE)
	            .setGachaSortId(this.getSortId());
CamChua_VN's avatar
CamChua_VN committed
176

177
		if(hasEpitomized()) {
CamChua_VN's avatar
CamChua_VN committed
178
179
180
181
182
183
184
			PlayerGachaBannerInfo gachaInfo = player.getGachaInfo().getBannerInfo(this);

			info.setWishItemId(gachaInfo.getWishItemId())
				.setWishProgress(gachaInfo.getFailedChosenItemPulls())
				.setWishMaxProgress(this.getWishMaxProgress());
		}

Melledy's avatar
Melledy committed
185
		if (this.getTitlePath() != null) {
186
			info.setTitleTextmap(this.getTitlePath());
Melledy's avatar
Melledy committed
187
188
		}
		
AnimeGitB's avatar
AnimeGitB committed
189
		if (this.getRateUpItems5().length > 0) {
Melledy's avatar
Melledy committed
190
191
			GachaUpInfo.Builder upInfo = GachaUpInfo.newBuilder().setItemParentType(1);
			
AnimeGitB's avatar
AnimeGitB committed
192
			for (int id : getRateUpItems5()) {
Melledy's avatar
Melledy committed
193
				upInfo.addItemIdList(id);
194
				info.addDisplayUp5ItemList(id);
Melledy's avatar
Melledy committed
195
196
197
198
199
			}
			
			info.addGachaUpInfoList(upInfo);
		}
		
AnimeGitB's avatar
AnimeGitB committed
200
		if (this.getRateUpItems4().length > 0) {
Melledy's avatar
Melledy committed
201
202
			GachaUpInfo.Builder upInfo = GachaUpInfo.newBuilder().setItemParentType(2);
			
AnimeGitB's avatar
AnimeGitB committed
203
			for (int id : getRateUpItems4()) {
Melledy's avatar
Melledy committed
204
				upInfo.addItemIdList(id);
205
206
				if (info.getDisplayUp4ItemListCount() == 0) {
					info.addDisplayUp4ItemList(id);
Melledy's avatar
Melledy committed
207
208
209
210
211
212
213
214
215
216
217
218
219
				}
			}
			
			info.addGachaUpInfoList(upInfo);
		}
		
		return info.build();
	}
	
	public enum BannerType {
		STANDARD, EVENT, WEAPON;
	}
}