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
5db5c90a
Commit
5db5c90a
authored
Jun 04, 2022
by
ImmuState
Committed by
Melledy
Jun 08, 2022
Browse files
Start a new forge (no checking for now).
parent
e5498e37
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/data/GameData.java
View file @
5db5c90a
...
@@ -368,4 +368,8 @@ public class GameData {
...
@@ -368,4 +368,8 @@ public class GameData {
public
static
Int2ObjectMap
<
QuestData
>
getQuestDataMap
()
{
public
static
Int2ObjectMap
<
QuestData
>
getQuestDataMap
()
{
return
questDataMap
;
return
questDataMap
;
}
}
public
static
Int2ObjectMap
<
ForgeData
>
getForgeDataMap
()
{
return
forgeDataMap
;
}
}
}
src/main/java/emu/grasscutter/game/managers/ForgingManager/ActiveForgeData.java
View file @
5db5c90a
package
emu.grasscutter.game.managers.ForgingManager
;
package
emu.grasscutter.game.managers.ForgingManager
;
import
dev.morphia.annotations.Entity
;
import
dev.morphia.annotations.Entity
;
import
emu.grasscutter.utils.Utils
;
@Entity
@Entity
public
class
ActiveForgeData
{
public
class
ActiveForgeData
{
private
int
forgeId
;
private
int
forgeId
;
private
int
avatarId
;
private
int
avatarId
;
private
int
count
;
private
int
startTime
;
private
int
startTime
;
private
int
forgeTime
;
private
int
forgeTime
;
...
@@ -14,6 +16,29 @@ public class ActiveForgeData {
...
@@ -14,6 +16,29 @@ public class ActiveForgeData {
// private int nextFinishTimestamp;
// private int nextFinishTimestamp;
// private int totalFinishTimestamp;
// private int totalFinishTimestamp;
public
int
getFinishedCount
(
int
currentTime
)
{
int
timeDelta
=
currentTime
-
this
.
startTime
;
int
finishedCount
=
(
int
)
Math
.
floor
(
timeDelta
/
this
.
forgeTime
);
return
Math
.
min
(
finishedCount
,
this
.
count
);
}
public
int
getUnfinishedCount
(
int
currentTime
)
{
return
this
.
count
-
this
.
getFinishedCount
(
currentTime
);
}
public
int
getNextFinishTimestamp
(
int
currentTime
)
{
return
(
currentTime
>=
this
.
getTotalFinishTimestamp
())
?
this
.
getTotalFinishTimestamp
()
:
(
this
.
getFinishedCount
(
currentTime
)
*
this
.
forgeTime
+
this
.
forgeTime
+
this
.
startTime
);
}
public
int
getTotalFinishTimestamp
()
{
return
this
.
startTime
+
this
.
forgeTime
*
this
.
count
;
}
public
int
getForgeId
()
{
public
int
getForgeId
()
{
return
this
.
forgeId
;
return
this
.
forgeId
;
}
}
...
@@ -28,6 +53,13 @@ public class ActiveForgeData {
...
@@ -28,6 +53,13 @@ public class ActiveForgeData {
this
.
avatarId
=
value
;
this
.
avatarId
=
value
;
}
}
public
int
getCount
()
{
return
count
;
}
public
void
setCount
(
int
value
)
{
this
.
count
=
value
;
}
public
int
getStartTime
()
{
public
int
getStartTime
()
{
return
this
.
startTime
;
return
this
.
startTime
;
}
}
...
...
src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java
View file @
5db5c90a
...
@@ -3,6 +3,9 @@ package emu.grasscutter.game.managers.ForgingManager;
...
@@ -3,6 +3,9 @@ package emu.grasscutter.game.managers.ForgingManager;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.excels.ForgeData
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.net.proto.ForgeStartReqOuterClass
;
import
emu.grasscutter.net.proto.ForgeStartReqOuterClass
;
...
@@ -12,6 +15,9 @@ import emu.grasscutter.server.packet.send.PacketForgeDataNotify;
...
@@ -12,6 +15,9 @@ import emu.grasscutter.server.packet.send.PacketForgeDataNotify;
import
emu.grasscutter.server.packet.send.PacketForgeFormulaDataNotify
;
import
emu.grasscutter.server.packet.send.PacketForgeFormulaDataNotify
;
import
emu.grasscutter.server.packet.send.PacketForgeGetQueueDataRsp
;
import
emu.grasscutter.server.packet.send.PacketForgeGetQueueDataRsp
;
import
emu.grasscutter.server.packet.send.PacketForgeStartRsp
;
import
emu.grasscutter.server.packet.send.PacketForgeStartRsp
;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.utils.ConfigContainer.Game
;
import
net.bytebuddy.dynamic.TypeResolutionStrategy.Active
;
public
class
ForgingManager
{
public
class
ForgingManager
{
private
final
Player
player
;
private
final
Player
player
;
...
@@ -53,19 +59,25 @@ public class ForgingManager {
...
@@ -53,19 +59,25 @@ public class ForgingManager {
}
}
private
Map
<
Integer
,
ForgeQueueData
>
determineCurrentForgeQueueData
()
{
private
Map
<
Integer
,
ForgeQueueData
>
determineCurrentForgeQueueData
()
{
// Dummy for now.
Map
<
Integer
,
ForgeQueueData
>
res
=
new
HashMap
<>();
int
currentTime
=
Utils
.
getCurrentSeconds
();
// Create queue information for all active forges.
for
(
int
i
=
0
;
i
<
this
.
player
.
getActiveForges
().
size
();
i
++)
{
ActiveForgeData
activeForge
=
this
.
player
.
getActiveForges
().
get
(
i
);
ForgeQueueData
data
=
ForgeQueueData
.
newBuilder
()
ForgeQueueData
data
=
ForgeQueueData
.
newBuilder
()
.
setQueueId
(
1
)
.
setQueueId
(
i
+
1
)
.
setForgeId
(
11001
)
.
setForgeId
(
activeForge
.
getForgeId
()
)
.
setFinishCount
(
2
)
.
setFinishCount
(
activeForge
.
getFinishedCount
(
currentTime
)
)
.
setUnfinishCount
(
3
)
.
setUnfinishCount
(
activeForge
.
getUnfinishedCount
(
currentTime
)
)
.
set
Next
FinishTimestamp
(
0
)
.
set
TotalFinishTimestamp
(
activeForge
.
getTotal
FinishTimestamp
(
)
)
.
setNextFinishTimestamp
(
0
)
.
setNextFinishTimestamp
(
activeForge
.
getNextFinishTimestamp
(
currentTime
)
)
.
setAvatarId
(
0
)
.
setAvatarId
(
activeForge
.
getAvatarId
()
)
.
build
();
.
build
();
Map
<
Integer
,
ForgeQueueData
>
res
=
new
HashMap
<>(
);
res
.
put
(
i
+
1
,
data
);
res
.
put
(
1
,
data
);
}
return
res
;
return
res
;
}
}
...
@@ -93,8 +105,39 @@ public class ForgingManager {
...
@@ -93,8 +105,39 @@ public class ForgingManager {
Initiate forging process.
Initiate forging process.
**********/
**********/
public
void
startForging
(
ForgeStartReqOuterClass
.
ForgeStartReq
req
)
{
public
void
startForging
(
ForgeStartReqOuterClass
.
ForgeStartReq
req
)
{
// Dummy for now.
// Refuse if all queues are already full.
this
.
player
.
sendPacket
(
new
PacketForgeStartRsp
(
Retcode
.
RET_SUCC
));
if
(
this
.
player
.
getActiveForges
().
size
()
>=
this
.
determineNumberOfQueues
())
{
this
.
player
.
sendPacket
(
new
PacketForgeStartRsp
(
Retcode
.
RET_FORGE_QUEUE_FULL
));
return
;
}
// Get the required forging information for the target item.
if
(!
GameData
.
getForgeDataMap
().
containsKey
(
req
.
getForgeId
()))
{
this
.
player
.
sendPacket
(
new
PacketForgeStartRsp
(
Retcode
.
RET_FAIL
));
//ToDo: Probably the wrong return code.
Grasscutter
.
getLogger
().
error
(
"Missing forgeId"
);
return
;
}
}
ForgeData
forgeData
=
GameData
.
getForgeDataMap
().
get
(
req
.
getForgeId
());
// Check if we have enough of each material.
// ToDo.
// Consume material.
// ToDo.
// Create and add active forge.
ActiveForgeData
activeForge
=
new
ActiveForgeData
();
activeForge
.
setForgeId
(
req
.
getForgeId
());
activeForge
.
setAvatarId
(
req
.
getAvatarId
());
activeForge
.
setCount
(
req
.
getForgeCount
());
activeForge
.
setStartTime
(
Utils
.
getCurrentSeconds
());
activeForge
.
setForgeTime
(
forgeData
.
getForgeTime
());
this
.
player
.
getActiveForges
().
add
(
activeForge
);
// Done.
this
.
player
.
sendPacket
(
new
PacketForgeStartRsp
(
Retcode
.
RET_SUCC
));
this
.
sendForgeDataNotify
();
}
}
}
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