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
0cc4bad1
Commit
0cc4bad1
authored
Jun 05, 2022
by
ImmuState
Committed by
Melledy
Jun 08, 2022
Browse files
Obtain forging results (UI is broken though).
parent
28a8475c
Changes
5
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/data/excels/ForgeData.java
View file @
0cc4bad1
...
@@ -13,6 +13,7 @@ public class ForgeData extends GameResource {
...
@@ -13,6 +13,7 @@ public class ForgeData extends GameResource {
private
int
id
;
private
int
id
;
private
int
playerLevel
;
private
int
playerLevel
;
private
int
forgeType
;
private
int
forgeType
;
private
int
resultItemId
;
private
int
resultItemCount
;
private
int
resultItemCount
;
private
int
forgeTime
;
private
int
forgeTime
;
private
int
queueNum
;
private
int
queueNum
;
...
@@ -33,6 +34,10 @@ public class ForgeData extends GameResource {
...
@@ -33,6 +34,10 @@ public class ForgeData extends GameResource {
return
forgeType
;
return
forgeType
;
}
}
public
int
getResultItemId
()
{
return
resultItemId
;
}
public
int
getResultItemCount
()
{
public
int
getResultItemCount
()
{
return
resultItemCount
;
return
resultItemCount
;
}
}
...
...
src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java
View file @
0cc4bad1
package
emu.grasscutter.game.managers.ForgingManager
;
package
emu.grasscutter.game.managers.ForgingManager
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.common.ItemParamData
;
import
emu.grasscutter.data.common.ItemParamData
;
import
emu.grasscutter.data.excels.ForgeData
;
import
emu.grasscutter.data.excels.ForgeData
;
import
emu.grasscutter.data.excels.ItemData
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.inventory.ItemType
;
import
emu.grasscutter.game.inventory.ItemType
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.net.proto.ForgeStartReqOuterClass
;
import
emu.grasscutter.net.proto.ForgeStartReqOuterClass
;
import
emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData
;
import
emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData
;
import
emu.grasscutter.net.proto.ForgeQueueManipulateReqOuterClass.ForgeQueueManipulateReq
;
import
emu.grasscutter.net.proto.ForgeQueueManipulateTypeOuterClass.ForgeQueueManipulateType
;
import
emu.grasscutter.net.proto.ForgeStartReqOuterClass.ForgeStartReq
;
import
emu.grasscutter.net.proto.RetcodeOuterClass.Retcode
;
import
emu.grasscutter.net.proto.RetcodeOuterClass.Retcode
;
import
emu.grasscutter.server.packet.send.PacketForgeDataNotify
;
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.PacketForgeQueueManipulateRsp
;
import
emu.grasscutter.server.packet.send.PacketForgeStartRsp
;
import
emu.grasscutter.server.packet.send.PacketForgeStartRsp
;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.utils.Utils
;
...
@@ -104,7 +110,7 @@ public class ForgingManager {
...
@@ -104,7 +110,7 @@ public class ForgingManager {
/**********
/**********
Initiate forging process.
Initiate forging process.
**********/
**********/
public
void
startForging
(
ForgeStartReq
OuterClass
.
ForgeStartReq
req
)
{
public
void
handle
ForgeStartReq
(
ForgeStartReq
req
)
{
// Refuse if all queues are already full.
// Refuse if all queues are already full.
if
(
this
.
player
.
getActiveForges
().
size
()
>=
this
.
determineNumberOfQueues
())
{
if
(
this
.
player
.
getActiveForges
().
size
()
>=
this
.
determineNumberOfQueues
())
{
this
.
player
.
sendPacket
(
new
PacketForgeStartRsp
(
Retcode
.
RET_FORGE_QUEUE_FULL
));
this
.
player
.
sendPacket
(
new
PacketForgeStartRsp
(
Retcode
.
RET_FORGE_QUEUE_FULL
));
...
@@ -165,4 +171,74 @@ public class ForgingManager {
...
@@ -165,4 +171,74 @@ public class ForgingManager {
this
.
player
.
sendPacket
(
new
PacketForgeStartRsp
(
Retcode
.
RET_SUCC
));
this
.
player
.
sendPacket
(
new
PacketForgeStartRsp
(
Retcode
.
RET_SUCC
));
this
.
sendForgeDataNotify
();
this
.
sendForgeDataNotify
();
}
}
/**********
Forge queue manipulation (obtaining results and cancelling forges).
**********/
private
void
obtainItems
(
int
queueId
)
{
// Determin how many items are finished.
int
currentTime
=
Utils
.
getCurrentSeconds
();
ActiveForgeData
forge
=
this
.
player
.
getActiveForges
().
get
(
queueId
-
1
);
int
finished
=
forge
.
getFinishedCount
(
currentTime
);
int
unfinished
=
forge
.
getUnfinishedCount
(
currentTime
);
// Sanity check: Are any items finished?
if
(
finished
<=
0
)
{
return
;
}
// Give finished items to the player.
ForgeData
data
=
GameData
.
getForgeDataMap
().
get
(
forge
.
getForgeId
());
ItemData
resultItemData
=
GameData
.
getItemDataMap
().
get
(
data
.
getResultItemId
());
GameItem
addItem
=
new
GameItem
(
resultItemData
,
data
.
getResultItemCount
()
*
finished
);
this
.
player
.
getInventory
().
addItem
(
addItem
);
// Replace active forge with a new one for the unfinished items, if there are any.
if
(
unfinished
>
0
)
{
ActiveForgeData
remainingForge
=
new
ActiveForgeData
();
remainingForge
.
setForgeId
(
forge
.
getForgeId
());
remainingForge
.
setAvatarId
(
forge
.
getAvatarId
());
remainingForge
.
setCount
(
unfinished
);
remainingForge
.
setForgeTime
(
forge
.
getForgeTime
());
// We simple restart the forge. This will increase the time, but is easier for now.
// ToDo: Make this more accurate.
remainingForge
.
setStartTime
(
currentTime
);
this
.
player
.
getActiveForges
().
set
(
queueId
-
1
,
remainingForge
);
}
// Otherwise, completely remove it.
else
{
this
.
player
.
getActiveForges
().
remove
(
queueId
-
1
);
}
// Send response.
this
.
player
.
sendPacket
(
new
PacketForgeQueueManipulateRsp
(
Retcode
.
RET_SUCC
,
ForgeQueueManipulateType
.
FORGE_QUEUE_MANIPULATE_TYPE_RECEIVE_OUTPUT
,
List
.
of
(
addItem
),
List
.
of
(),
List
.
of
()));
this
.
sendForgeDataNotify
();
}
private
void
cancelForge
(
int
queueId
)
{
}
public
void
handleForgeQueueManipulateReq
(
ForgeQueueManipulateReq
req
)
{
// Get info from the request.
int
queueId
=
req
.
getForgeQueueId
();
var
manipulateType
=
req
.
getManipulateType
();
// Handle according to the manipulation type.
switch
(
manipulateType
)
{
case
FORGE_QUEUE_MANIPULATE_TYPE_RECEIVE_OUTPUT:
this
.
obtainItems
(
queueId
);
break
;
case
FORGE_QUEUE_MANIPULATE_TYPE_STOP_FORGE:
this
.
cancelForge
(
queueId
);
break
;
default
:
break
;
//Should never happen.
}
}
}
}
src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeQueueManipulateReq.java
0 → 100644
View file @
0cc4bad1
package
emu.grasscutter.server.packet.recv
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.ForgeQueueManipulateReqOuterClass.ForgeQueueManipulateReq
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.server.game.GameSession
;
@Opcodes
(
PacketOpcodes
.
ForgeQueueManipulateReq
)
public
class
HandlerForgeQueueManipulateReq
extends
PacketHandler
{
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
ForgeQueueManipulateReq
req
=
ForgeQueueManipulateReq
.
parseFrom
(
payload
);
session
.
getPlayer
().
getForgingManager
().
handleForgeQueueManipulateReq
(
req
);
}
}
src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeStartReq.java
View file @
0cc4bad1
...
@@ -17,7 +17,7 @@ public class HandlerForgeStartReq extends PacketHandler {
...
@@ -17,7 +17,7 @@ public class HandlerForgeStartReq extends PacketHandler {
@Override
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
ForgeStartReqOuterClass
.
ForgeStartReq
req
=
ForgeStartReqOuterClass
.
ForgeStartReq
.
parseFrom
(
payload
);
ForgeStartReqOuterClass
.
ForgeStartReq
req
=
ForgeStartReqOuterClass
.
ForgeStartReq
.
parseFrom
(
payload
);
session
.
getPlayer
().
getForgingManager
().
startForging
(
req
);
session
.
getPlayer
().
getForgingManager
().
handleForgeStartReq
(
req
);
}
}
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueManipulateRsp.java
0 → 100644
View file @
0cc4bad1
package
emu.grasscutter.server.packet.send
;
import
java.util.List
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.ForgeQueueManipulateRspOuterClass.ForgeQueueManipulateRsp
;
import
emu.grasscutter.net.proto.ForgeQueueManipulateTypeOuterClass.ForgeQueueManipulateType
;
import
emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam
;
import
emu.grasscutter.net.proto.RetcodeOuterClass.Retcode
;
public
class
PacketForgeQueueManipulateRsp
extends
BasePacket
{
public
PacketForgeQueueManipulateRsp
(
Retcode
retcode
,
ForgeQueueManipulateType
type
,
List
<
GameItem
>
output
,
List
<
GameItem
>
refund
,
List
<
GameItem
>
extra
)
{
super
(
PacketOpcodes
.
ForgeQueueManipulateRsp
);
ForgeQueueManipulateRsp
.
Builder
builder
=
ForgeQueueManipulateRsp
.
newBuilder
()
.
setRetcode
(
retcode
.
getNumber
());
for
(
GameItem
item
:
output
)
{
ItemParam
toAdd
=
ItemParam
.
newBuilder
()
.
setItemId
(
item
.
getItemId
())
.
setCount
(
item
.
getCount
())
.
build
();
builder
.
addOutputItemList
(
toAdd
);
}
for
(
GameItem
item
:
refund
)
{
ItemParam
toAdd
=
ItemParam
.
newBuilder
()
.
setItemId
(
item
.
getItemId
())
.
setCount
(
item
.
getCount
())
.
build
();
builder
.
addReturnItemList
(
toAdd
);
}
// ToDo: Add extra items when once we have handling for it.
this
.
setData
(
builder
.
build
());
}
}
\ No newline at end of file
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