Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
9a313e50
Commit
9a313e50
authored
Jun 06, 2022
by
ImmuState
Committed by
Melledy
Jun 08, 2022
Browse files
Send periodic notifications to the client for ongoing forges.
parent
4b77e84e
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/managers/ForgingManager/ActiveForgeData.java
View file @
9a313e50
...
...
@@ -11,11 +11,9 @@ public class ActiveForgeData {
private
int
startTime
;
private
int
forgeTime
;
// private int finishedCount;
// private int unfinishedCount;
// private int nextFinishTimestamp;
// private int totalFinishTimestamp;
private
int
lastUnfinishedCount
;
private
boolean
changed
;
public
int
getFinishedCount
(
int
currentTime
)
{
int
timeDelta
=
currentTime
-
this
.
startTime
;
...
...
@@ -73,4 +71,22 @@ public class ActiveForgeData {
public
void
setForgeTime
(
int
value
)
{
this
.
forgeTime
=
value
;
}
public
boolean
isChanged
()
{
return
this
.
changed
;
}
public
void
setChanged
(
boolean
value
)
{
this
.
changed
=
value
;
}
public
boolean
updateChanged
(
int
currentTime
)
{
int
currentUnfinished
=
this
.
getUnfinishedCount
(
currentTime
);
if
(
currentUnfinished
!=
this
.
lastUnfinishedCount
)
{
this
.
changed
=
true
;
this
.
lastUnfinishedCount
=
currentUnfinished
;
}
return
this
.
changed
;
}
}
src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java
View file @
9a313e50
...
...
@@ -5,6 +5,8 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
com.mongodb.QueryBuilder
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.common.ItemParamData
;
...
...
@@ -289,4 +291,34 @@ public class ForgingManager {
break
;
//Should never happen.
}
}
/**********
Periodic forging updates.
**********/
public
void
sendPlayerForgingUpdate
()
{
int
currentTime
=
Utils
.
getCurrentSeconds
();
// Determine if sending an update is necessary.
// We only send an update if there are forges in the forge queue
// that have changed since the last notification.
if
(
this
.
player
.
getActiveForges
().
size
()
<=
0
)
{
return
;
}
boolean
hasChanges
=
this
.
player
.
getActiveForges
().
stream
()
.
filter
(
forge
->
forge
.
updateChanged
(
currentTime
))
.
findAny
()
.
isPresent
();
if
(!
hasChanges
)
{
return
;
}
// Send notification.
this
.
sendForgeQueueDataNotify
();
// Reset changed flags.
this
.
player
.
getActiveForges
().
stream
()
.
forEach
(
forge
->
forge
.
setChanged
(
false
));
}
}
src/main/java/emu/grasscutter/game/player/Player.java
View file @
9a313e50
...
...
@@ -1194,6 +1194,9 @@ public class Player {
this
.
save
();
this
.
sendPacket
(
new
PacketAvatarExpeditionDataNotify
(
this
));
}
// Send updated forge queue data, if necessary.
this
.
getForgingManager
().
sendPlayerForgingUpdate
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment