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
0e1c8dc5
Commit
0e1c8dc5
authored
Jun 05, 2022
by
ImmuState
Committed by
Melledy
Jun 08, 2022
Browse files
Cancel forging and refund items.
parent
0cc4bad1
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java
View file @
0e1c8dc5
package
emu.grasscutter.game.managers.ForgingManager
;
package
emu.grasscutter.game.managers.ForgingManager
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -221,7 +222,40 @@ public class ForgingManager {
...
@@ -221,7 +222,40 @@ public class ForgingManager {
}
}
private
void
cancelForge
(
int
queueId
)
{
private
void
cancelForge
(
int
queueId
)
{
// Make sure there are no unfinished items.
int
currentTime
=
Utils
.
getCurrentSeconds
();
ActiveForgeData
forge
=
this
.
player
.
getActiveForges
().
get
(
queueId
-
1
);
if
(
forge
.
getFinishedCount
(
currentTime
)
>
0
)
{
return
;
}
// Return material items to the player.
ForgeData
data
=
GameData
.
getForgeDataMap
().
get
(
forge
.
getForgeId
());
var
returnItems
=
new
ArrayList
<
GameItem
>();
for
(
var
material
:
data
.
getMaterialItems
())
{
if
(
material
.
getItemId
()
==
0
)
{
continue
;
}
ItemData
resultItemData
=
GameData
.
getItemDataMap
().
get
(
material
.
getItemId
());
GameItem
returnItem
=
new
GameItem
(
resultItemData
,
material
.
getItemCount
()
*
forge
.
getCount
());
this
.
player
.
getInventory
().
addItem
(
returnItem
);
returnItems
.
add
(
returnItem
);
}
// Return Mora to the player.
this
.
player
.
setMora
(
this
.
player
.
getMora
()
+
data
.
getScoinCost
()
*
forge
.
getCount
());
ItemData
moraItem
=
GameData
.
getItemDataMap
().
get
(
202
);
GameItem
returnMora
=
new
GameItem
(
moraItem
,
data
.
getScoinCost
()
*
forge
.
getCount
());
returnItems
.
add
(
returnMora
);
// Send response.
this
.
player
.
sendPacket
(
new
PacketForgeQueueManipulateRsp
(
Retcode
.
RET_SUCC
,
ForgeQueueManipulateType
.
FORGE_QUEUE_MANIPULATE_TYPE_STOP_FORGE
,
List
.
of
(),
returnItems
,
List
.
of
()));
this
.
sendForgeDataNotify
();
}
}
public
void
handleForgeQueueManipulateReq
(
ForgeQueueManipulateReq
req
)
{
public
void
handleForgeQueueManipulateReq
(
ForgeQueueManipulateReq
req
)
{
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueManipulateRsp.java
View file @
0e1c8dc5
...
@@ -16,7 +16,8 @@ public class PacketForgeQueueManipulateRsp extends BasePacket {
...
@@ -16,7 +16,8 @@ public class PacketForgeQueueManipulateRsp extends BasePacket {
super
(
PacketOpcodes
.
ForgeQueueManipulateRsp
);
super
(
PacketOpcodes
.
ForgeQueueManipulateRsp
);
ForgeQueueManipulateRsp
.
Builder
builder
=
ForgeQueueManipulateRsp
.
newBuilder
()
ForgeQueueManipulateRsp
.
Builder
builder
=
ForgeQueueManipulateRsp
.
newBuilder
()
.
setRetcode
(
retcode
.
getNumber
());
.
setRetcode
(
retcode
.
getNumber
())
.
setManipulateType
(
type
);
for
(
GameItem
item
:
output
)
{
for
(
GameItem
item
:
output
)
{
ItemParam
toAdd
=
ItemParam
.
newBuilder
()
ItemParam
toAdd
=
ItemParam
.
newBuilder
()
...
...
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