RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
PlayerRecord.java
1package com.osroyale.content.activity.record;
2
3import com.osroyale.content.activity.ActivityType;
4import com.osroyale.game.world.entity.mob.player.Player;
5import com.osroyale.game.world.entity.mob.player.PlayerRight;
6import com.osroyale.net.packet.out.*;
7import com.osroyale.util.Utility;
8
9import java.util.*;
10
42
43public class PlayerRecord {
44
45 private final Player player;
46 public long time;
47 public boolean global;
48 private Map<ActivityType, TreeSet<GameRecord>> personalRecord = new HashMap<>();
49
50 public PlayerRecord(Player player) {
51 this.player = player;
52 }
53
54 public void start() {
55 time = System.currentTimeMillis();
56 }
57
58 public long end(ActivityType activity) {
59 return end(activity, true);
60 }
61
62 public long end(ActivityType activity, boolean track) {
63 long record = System.currentTimeMillis() - time;
64
65 /* Don't add if time is longer than 30 minutes */
66 if (record > 1_800_000) {
67 return 0;
68 }
69
70 if (track && !PlayerRight.isAdministrator(player)) {
71 GameRecord tracker = new GameRecord(player, record, activity);
72 // GlobalRecords.add(player, tracker);
73 add(tracker);
74 }
75
76 time = -1;
77 return record;
78 }
79
80 public void add(GameRecord tracker) {
81 ActivityType activity = tracker.activityType;
82 TreeSet<GameRecord> personal = personalRecord.computeIfAbsent(activity, act -> new TreeSet<>(Comparator.comparingLong(record -> record.time)));
83 if (personal.size() < 10) {
84 personal.add(tracker);
85 } else if (tracker.time < personal.first().time) {
86 personal.pollLast();
87 personal.add(tracker);
88 }
89 }
90
91 void clean(int size) {
92 int string = 32401;
93 for (int count = 0; count < (size < 25 ? 25 : size); count++) {
94 player.send(new SendString("", ++string));
95 player.send(new SendString("", ++string));
96 player.send(new SendString("", ++string));
97 player.send(new SendString("", ++string));
98 string++;
99 }
100 player.send(new SendScrollbar(32400, (size < 10 ? 10 : size) * 28));
101 }
102
103 void showActivities(ActivityType viewing) {
104 int count = 0;
105 String[] marquee = new String[5];
106 List<ActivityType> activities = ActivityType.getRecordable();
107 for (ActivityType activity : activities) {
108 String name = Utility.formatEnum(activity.name());
109 player.send(new SendString((viewing == activity ? "<col=ffffff>" : "</col>") + name, 32352 + count));
110 player.send(new SendTooltip("Display " + name + " records", 32352 + count));
111 count +=2;
112 }
113 for (int index = 0; index < marquee.length; index++) {
114 ActivityType type = Utility.randomElement(activities);
115 // GameRecord top = GlobalRecords.getTopRecord(type);
116 activities.remove(type);
117 // String details = top == null ? "None" : top.name + "(" + Utility.getTime(top.time) + ")";
118 // marquee[index] = Utility.formatEnum(type.name()) + ": " + details;
119 }
120 int size = ActivityType.values().length < 12 ? 12 : ActivityType.values().length;
121 player.send(new SendScrollbar(32350 , size * 23));
122 player.send(new SendMarquee(32306, marquee));
123 }
124
125 public void display(ActivityType activity) {
126 display(global, activity);
127 }
128
129 public void display(boolean global, ActivityType activity) {
130 this.global = global;
131 player.send(new SendConfig(325, global ? 1 : 0));
132
133 /* if (global) {
134 GlobalRecords.display(player, activity);
135 return;
136 }*/
137
138 clean(0);
139 showActivities(activity);
140 TreeSet<GameRecord> records = personalRecord.getOrDefault(activity, new TreeSet<>());
141
142 int idx = 0;
143 for (GameRecord personal : records) {
144 player.send(new SendString((idx / 5 + 1) + ")", (idx + 1) + 32401));
145 player.send(new SendString(Utility.formatName(personal.name), (idx + 2) + 32401));
146 player.send(new SendString(personal.time == 0 ? "None!" : Utility.getTime(personal.time), (idx + 3) + 32401));
147 player.send(new SendString(personal.date, (idx + 4) + 32401));
148 idx += 5;
149 }
150 player.send(new SendScrollbar(32400, (records.size() < 9 ? 9 : records.size()) * 28));
151 player.interfaceManager.open(32300);
152 }
153}
static< T > T randomElement(Collection< T > collection)
Definition Utility.java:285
static String getTime()
Definition Utility.java:178
static String formatEnum(final String string)
Definition Utility.java:126