mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-15 16:34:56 +01:00
Implement gacha history record subsystem
* Frontend is not very beautiful yet * Didn't include too much `some anime game` data in the page to avoid being DMCA'd
This commit is contained in:
@@ -91,9 +91,21 @@ public class GachaBanner {
|
||||
return eventChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public GachaInfo toProto() {
|
||||
String record = "http://" + (Grasscutter.getConfig().getDispatchOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getDispatchOptions().Ip : Grasscutter.getConfig().getDispatchOptions().PublicIp) + "/gacha";
|
||||
|
||||
return toProto("");
|
||||
}
|
||||
public GachaInfo toProto(String sessionKey) {
|
||||
String record = "https://"
|
||||
+ (Grasscutter.getConfig().getDispatchOptions().PublicIp.isEmpty() ?
|
||||
Grasscutter.getConfig().getDispatchOptions().Ip :
|
||||
Grasscutter.getConfig().getDispatchOptions().PublicIp)
|
||||
+ ":"
|
||||
+ Integer.toString(Grasscutter.getConfig().getDispatchOptions().PublicPort == 0 ?
|
||||
Grasscutter.getConfig().getDispatchOptions().Port :
|
||||
Grasscutter.getConfig().getDispatchOptions().PublicPort)
|
||||
+ "/gacha?s=" + sessionKey + "&gachaType=" + gachaType;
|
||||
// Grasscutter.getLogger().info("record = " + record);
|
||||
GachaInfo.Builder info = GachaInfo.newBuilder()
|
||||
.setGachaType(this.getGachaType())
|
||||
.setScheduleId(this.getScheduleId())
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.sun.nio.file.SensitivityWatchEventModifier;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.def.ItemData;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.avatar.Avatar;
|
||||
import emu.grasscutter.game.gacha.GachaBanner.BannerType;
|
||||
import emu.grasscutter.game.inventory.GameItem;
|
||||
@@ -196,6 +197,10 @@ public class GachaManager {
|
||||
if (itemData == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Write gacha record
|
||||
GachaRecord gachaRecord = new GachaRecord(itemId, player.getUid(), gachaType);
|
||||
DatabaseHelper.saveGachaRecord(gachaRecord);
|
||||
|
||||
// Create gacha item
|
||||
GachaItem.Builder gachaItem = GachaItem.newBuilder();
|
||||
@@ -321,6 +326,7 @@ public class GachaManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private synchronized GetGachaInfoRsp createProto() {
|
||||
GetGachaInfoRsp.Builder proto = GetGachaInfoRsp.newBuilder().setGachaRandom(12345);
|
||||
|
||||
@@ -330,12 +336,26 @@ public class GachaManager {
|
||||
|
||||
return proto.build();
|
||||
}
|
||||
|
||||
private synchronized GetGachaInfoRsp createProto(String sessionKey) {
|
||||
GetGachaInfoRsp.Builder proto = GetGachaInfoRsp.newBuilder().setGachaRandom(12345);
|
||||
|
||||
for (GachaBanner banner : getGachaBanners().values()) {
|
||||
proto.addGachaInfoList(banner.toProto(sessionKey));
|
||||
}
|
||||
|
||||
return proto.build();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public GetGachaInfoRsp toProto() {
|
||||
if (this.cachedProto == null) {
|
||||
this.cachedProto = createProto();
|
||||
}
|
||||
|
||||
return this.cachedProto;
|
||||
}
|
||||
|
||||
public GetGachaInfoRsp toProto(String sessionKey) {
|
||||
return createProto(sessionKey);
|
||||
}
|
||||
}
|
||||
|
||||
75
src/main/java/emu/grasscutter/game/gacha/GachaRecord.java
Normal file
75
src/main/java/emu/grasscutter/game/gacha/GachaRecord.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package emu.grasscutter.game.gacha;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import dev.morphia.annotations.*;
|
||||
|
||||
@Entity(value = "gachas", useDiscriminator = false)
|
||||
public class GachaRecord {
|
||||
@Id private ObjectId id;
|
||||
|
||||
@Indexed private int ownerId;
|
||||
|
||||
private Date transactionDate;
|
||||
private int itemID;
|
||||
@Indexed private int gachaType;
|
||||
|
||||
public GachaRecord() {}
|
||||
|
||||
public GachaRecord(int itemId ,int ownerId, int gachaType){
|
||||
this.transactionDate = new Date();
|
||||
this.itemID = itemId;
|
||||
this.ownerId = ownerId;
|
||||
this.gachaType = gachaType;
|
||||
}
|
||||
|
||||
public int getOwnerId() {
|
||||
return ownerId;
|
||||
}
|
||||
|
||||
public void setOwnerId(int ownerId) {
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
|
||||
public int getGachaType() {
|
||||
return gachaType;
|
||||
}
|
||||
|
||||
public void setGachaType(int type) {
|
||||
this.gachaType = type;
|
||||
}
|
||||
|
||||
public Date getTransactionDate() {
|
||||
return transactionDate;
|
||||
}
|
||||
|
||||
public void setTransactionDate(Date transactionDate) {
|
||||
this.transactionDate = transactionDate;
|
||||
}
|
||||
|
||||
public int getItemID() {
|
||||
return itemID;
|
||||
}
|
||||
|
||||
public void setItemID(int itemID) {
|
||||
this.itemID = itemID;
|
||||
}
|
||||
|
||||
public ObjectId getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(ObjectId id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return toJsonString();
|
||||
}
|
||||
public String toJsonString() {
|
||||
return "{\"time\": " + this.transactionDate.getTime() + ",\"item\":" + this.itemID + "}";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user