2022-04-27 12:24:25 +08:00
|
|
|
package emu.grasscutter.game.mail;
|
2022-04-23 23:07:18 +08:00
|
|
|
|
2022-04-24 18:17:08 +08:00
|
|
|
import dev.morphia.annotations.Entity;
|
2022-05-02 17:01:01 +08:00
|
|
|
import dev.morphia.annotations.Id;
|
|
|
|
import dev.morphia.annotations.Indexed;
|
|
|
|
import dev.morphia.annotations.Transient;
|
|
|
|
import emu.grasscutter.database.DatabaseHelper;
|
2022-04-27 12:24:25 +08:00
|
|
|
import emu.grasscutter.game.player.Player;
|
2022-04-24 18:17:08 +08:00
|
|
|
|
2022-04-23 23:07:18 +08:00
|
|
|
import java.time.Instant;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2022-05-02 17:01:01 +08:00
|
|
|
import org.bson.types.ObjectId;
|
2022-04-23 23:07:18 +08:00
|
|
|
|
2022-05-02 17:01:01 +08:00
|
|
|
@Entity(value = "mail", useDiscriminator = false)
|
|
|
|
public class Mail {
|
|
|
|
@Id private ObjectId id;
|
|
|
|
@Indexed private int ownerUid;
|
2022-04-23 23:07:18 +08:00
|
|
|
public MailContent mailContent;
|
|
|
|
public List<MailItem> itemList;
|
|
|
|
public long sendTime;
|
|
|
|
public long expireTime;
|
|
|
|
public int importance;
|
|
|
|
public boolean isRead;
|
|
|
|
public boolean isAttachmentGot;
|
|
|
|
public int stateValue;
|
2022-05-02 17:01:01 +08:00
|
|
|
@Transient private boolean shouldDelete;
|
2022-04-23 23:07:18 +08:00
|
|
|
|
|
|
|
public Mail() {
|
2022-04-25 21:53:10 +08:00
|
|
|
this(new MailContent(), new ArrayList<MailItem>(), (int) Instant.now().getEpochSecond() + 604800); // TODO: add expire time to send mail command
|
2022-04-23 23:07:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime) {
|
2022-04-25 14:30:56 +08:00
|
|
|
this(mailContent, itemList, expireTime, 0);
|
2022-04-23 23:07:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime, int importance) {
|
|
|
|
this(mailContent, itemList, expireTime, importance, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime, int importance, int state) {
|
|
|
|
this.mailContent = mailContent;
|
|
|
|
this.itemList = itemList;
|
2022-04-24 19:06:52 +08:00
|
|
|
this.sendTime = (int) Instant.now().getEpochSecond();
|
2022-04-23 23:07:18 +08:00
|
|
|
this.expireTime = expireTime;
|
2022-04-25 21:53:10 +08:00
|
|
|
this.importance = importance; // Starred mail, 0 = No star, 1 = Star.
|
2022-04-23 23:07:18 +08:00
|
|
|
this.isRead = false;
|
|
|
|
this.isAttachmentGot = false;
|
2022-04-25 21:53:10 +08:00
|
|
|
this.stateValue = state; // Different mailboxes, 1 = Default, 3 = Gift-box.
|
2022-04-23 23:07:18 +08:00
|
|
|
}
|
|
|
|
|
2022-05-02 17:01:01 +08:00
|
|
|
public ObjectId getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getOwnerUid() {
|
|
|
|
return ownerUid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOwnerUid(int ownerUid) {
|
|
|
|
this.ownerUid = ownerUid;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Entity
|
2022-04-23 23:07:18 +08:00
|
|
|
public static class MailContent {
|
|
|
|
public String title;
|
|
|
|
public String content;
|
|
|
|
public String sender;
|
|
|
|
|
|
|
|
public MailContent() {
|
|
|
|
this.title = "";
|
|
|
|
this.content = "loading...";
|
|
|
|
this.sender = "loading";
|
|
|
|
}
|
|
|
|
|
|
|
|
public MailContent(String title, String content) {
|
|
|
|
this(title, content, "Server");
|
|
|
|
}
|
|
|
|
|
2022-04-27 12:21:57 +08:00
|
|
|
public MailContent(String title, String content, Player sender) {
|
2022-04-23 23:07:18 +08:00
|
|
|
this(title, content, sender.getNickname());
|
|
|
|
}
|
|
|
|
|
|
|
|
public MailContent(String title, String content, String sender) {
|
|
|
|
this.title = title;
|
|
|
|
this.content = content;
|
|
|
|
this.sender = sender;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-24 18:17:08 +08:00
|
|
|
@Entity
|
2022-04-23 23:07:18 +08:00
|
|
|
public static class MailItem {
|
|
|
|
public int itemId;
|
|
|
|
public int itemCount;
|
2022-04-25 14:30:56 +08:00
|
|
|
public int itemLevel;
|
2022-04-23 23:07:18 +08:00
|
|
|
|
|
|
|
public MailItem() {
|
|
|
|
this.itemId = 11101;
|
|
|
|
this.itemCount = 1;
|
2022-04-25 14:30:56 +08:00
|
|
|
this.itemLevel = 1;
|
2022-04-23 23:07:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public MailItem(int itemId) {
|
|
|
|
this(itemId, 1);
|
|
|
|
}
|
|
|
|
|
2022-04-25 14:30:56 +08:00
|
|
|
public MailItem(int itemId, int itemCount) { this(itemId, itemCount, 1); }
|
|
|
|
|
|
|
|
public MailItem(int itemId, int itemCount, int itemLevel) {
|
2022-04-23 23:07:18 +08:00
|
|
|
this.itemId = itemId;
|
|
|
|
this.itemCount = itemCount;
|
2022-04-25 14:30:56 +08:00
|
|
|
this.itemLevel = itemLevel;
|
2022-04-23 23:07:18 +08:00
|
|
|
}
|
|
|
|
}
|
2022-05-02 17:01:01 +08:00
|
|
|
|
|
|
|
public void save() {
|
|
|
|
if (this.expireTime * 1000 < System.currentTimeMillis()) {
|
|
|
|
DatabaseHelper.deleteMail(this);
|
|
|
|
} else {
|
|
|
|
DatabaseHelper.saveMail(this);
|
|
|
|
}
|
|
|
|
}
|
2022-04-23 23:07:18 +08:00
|
|
|
}
|