PlayerProfile.java 1.94 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
3
4
5
6
7
8
9
package emu.grasscutter.game.friends;

import dev.morphia.annotations.*;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.utils.Utils;

public class PlayerProfile {
	@Transient private GenshinPlayer player;
	
10
	@AlsoLoad("id") private int uid;
Melledy's avatar
Melledy committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
	private int nameCard;
	private int avatarId;
	private String name;
	private String signature;
	private int achievements;
	
	private int playerLevel;
	private int worldLevel;
	private int lastActiveTime;

	@Deprecated // Morphia only
	public PlayerProfile() { }
	
	public PlayerProfile(GenshinPlayer player) {
25
		this.uid = player.getUid();
Melledy's avatar
Melledy committed
26
27
28
		this.syncWithCharacter(player);
	}
	
29
30
	public int getUid() {
		return uid;
Melledy's avatar
Melledy committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
	}

	public GenshinPlayer getPlayer() {
		return player;
	}
	
	public synchronized void setPlayer(GenshinPlayer player) {
		this.player = player;
	}
	
	public String getName() {
		return name;
	}

	public int getNameCard() {
		return nameCard;
	}

	public int getAvatarId() {
		return avatarId;
	}

	public String getSignature() {
		return signature;
	}

	public int getAchievements() {
		return achievements;
	}

	public int getPlayerLevel() {
		return playerLevel;
	}

	public int getWorldLevel() {
		return worldLevel;
	}

	public int getLastActiveTime() {
		return lastActiveTime;
	}
	
	public void updateLastActiveTime() {
		this.lastActiveTime = Utils.getCurrentSeconds();
	}
	
	public int getDaysSinceLogin() {
		return (int) Math.floor((Utils.getCurrentSeconds() - getLastActiveTime()) / 86400.0);
	}

	public boolean isOnline() {
		return this.getPlayer() != null;
	}

	public void syncWithCharacter(GenshinPlayer player) {
		if (player == null) {
			return;
		}
		
90
		this.uid = player.getUid();
Melledy's avatar
Melledy committed
91
92
93
94
95
96
97
98
99
100
		this.name = player.getNickname();
		this.avatarId = player.getHeadImage();
		this.signature = player.getSignature();
		this.nameCard = player.getNameCardId();
		this.playerLevel = player.getLevel();
		this.worldLevel = player.getWorldLevel();
		//this.achievements = 0;
		this.updateLastActiveTime();
	}
}