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
b375881a
Commit
b375881a
authored
May 18, 2022
by
Melledy
Browse files
Fix errors caused by merge + Refactor chests into GadgetChest
parent
94997276
Changes
5
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/entity/EntityGadget.java
View file @
b375881a
...
@@ -3,6 +3,7 @@ package emu.grasscutter.game.entity;
...
@@ -3,6 +3,7 @@ package emu.grasscutter.game.entity;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.def.GadgetData
;
import
emu.grasscutter.data.def.GadgetData
;
import
emu.grasscutter.game.entity.gadget.GadgetChest
;
import
emu.grasscutter.game.entity.gadget.GadgetContent
;
import
emu.grasscutter.game.entity.gadget.GadgetContent
;
import
emu.grasscutter.game.entity.gadget.GadgetGatherPoint
;
import
emu.grasscutter.game.entity.gadget.GadgetGatherPoint
;
import
emu.grasscutter.game.entity.gadget.GadgetRewardStatue
;
import
emu.grasscutter.game.entity.gadget.GadgetRewardStatue
;
...
@@ -27,6 +28,7 @@ import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
...
@@ -27,6 +28,7 @@ import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
import
emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo
;
import
emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo
;
import
emu.grasscutter.net.proto.VectorOuterClass.Vector
;
import
emu.grasscutter.net.proto.VectorOuterClass.Vector
;
import
emu.grasscutter.net.proto.WorktopInfoOuterClass.WorktopInfo
;
import
emu.grasscutter.net.proto.WorktopInfoOuterClass.WorktopInfo
;
import
emu.grasscutter.server.packet.send.PacketGadgetStateNotify
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.ProtoHelper
;
import
emu.grasscutter.utils.ProtoHelper
;
import
it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap
;
import
it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap
;
...
@@ -92,6 +94,11 @@ public class EntityGadget extends EntityBaseGadget {
...
@@ -92,6 +94,11 @@ public class EntityGadget extends EntityBaseGadget {
this
.
state
=
state
;
this
.
state
=
state
;
}
}
public
void
updateState
(
int
state
){
this
.
setState
(
state
);
this
.
getScene
().
broadcastPacket
(
new
PacketGadgetStateNotify
(
this
,
state
));
}
public
int
getPointType
()
{
public
int
getPointType
()
{
return
pointType
;
return
pointType
;
}
}
...
@@ -120,6 +127,7 @@ public class EntityGadget extends EntityBaseGadget {
...
@@ -120,6 +127,7 @@ public class EntityGadget extends EntityBaseGadget {
case
GatherPoint
->
new
GadgetGatherPoint
(
this
);
case
GatherPoint
->
new
GadgetGatherPoint
(
this
);
case
Worktop
->
new
GadgetWorktop
(
this
);
case
Worktop
->
new
GadgetWorktop
(
this
);
case
RewardStatue
->
new
GadgetRewardStatue
(
this
);
case
RewardStatue
->
new
GadgetRewardStatue
(
this
);
case
Chest
->
new
GadgetChest
(
this
);
default
->
null
;
default
->
null
;
};
};
...
@@ -176,30 +184,4 @@ public class EntityGadget extends EntityBaseGadget {
...
@@ -176,30 +184,4 @@ public class EntityGadget extends EntityBaseGadget {
return
entityInfo
.
build
();
return
entityInfo
.
build
();
}
}
public
void
openChest
(
Player
player
)
{
var
chestRewardMap
=
getScene
().
getWorld
().
getServer
().
getWorldDataManager
().
getChestRewardMap
();
var
chestReward
=
chestRewardMap
.
get
(
this
.
getGadgetData
().
getJsonName
());
if
(
chestReward
==
null
){
Grasscutter
.
getLogger
().
warn
(
"Could not found the config of this type of Chests {}"
,
this
.
getGadgetData
().
getJsonName
());
return
;
}
player
.
earnExp
(
chestReward
.
getAdvExp
());
player
.
getInventory
().
addItem
(
201
,
chestReward
.
getResin
());
var
mora
=
chestReward
.
getMora
()
*
(
1
+
(
player
.
getWorldLevel
()
-
1
)
*
0.5
);
player
.
getInventory
().
addItem
(
202
,
(
int
)
mora
);
for
(
int
i
=
0
;
i
<
chestReward
.
getContent
().
size
();
i
++){
getScene
().
addItemEntity
(
chestReward
.
getContent
().
get
(
i
).
getItemId
(),
chestReward
.
getContent
().
get
(
i
).
getCount
(),
this
);
}
var
random
=
new
Random
(
System
.
currentTimeMillis
());
for
(
int
i
=
0
;
i
<
chestReward
.
getRandomCount
();
i
++){
var
index
=
random
.
nextInt
(
chestReward
.
getRandomContent
().
size
());
var
item
=
chestReward
.
getRandomContent
().
get
(
index
);
getScene
().
addItemEntity
(
item
.
getItemId
(),
item
.
getCount
(),
this
);
}
}
}
}
src/main/java/emu/grasscutter/game/entity/gadget/GadgetChest.java
0 → 100644
View file @
b375881a
package
emu.grasscutter.game.entity.gadget
;
import
java.util.Random
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.entity.EntityGadget
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType
;
import
emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo
;
import
emu.grasscutter.scripts.constants.ScriptGadgetState
;
import
emu.grasscutter.server.packet.send.PacketGadgetInteractRsp
;
public
class
GadgetChest
extends
GadgetContent
{
public
GadgetChest
(
EntityGadget
gadget
)
{
super
(
gadget
);
}
public
boolean
onInteract
(
Player
player
)
{
var
chestRewardMap
=
getGadget
().
getScene
().
getWorld
().
getServer
().
getWorldDataManager
().
getChestRewardMap
();
var
chestReward
=
chestRewardMap
.
get
(
getGadget
().
getGadgetData
().
getJsonName
());
if
(
chestReward
==
null
)
{
Grasscutter
.
getLogger
().
warn
(
"Could not found the config of this type of Chests {}"
,
getGadget
().
getGadgetData
().
getJsonName
());
return
true
;
}
player
.
earnExp
(
chestReward
.
getAdvExp
());
player
.
getInventory
().
addItem
(
201
,
chestReward
.
getResin
());
var
mora
=
chestReward
.
getMora
()
*
(
1
+
(
player
.
getWorldLevel
()
-
1
)
*
0.5
);
player
.
getInventory
().
addItem
(
202
,
(
int
)
mora
);
for
(
int
i
=
0
;
i
<
chestReward
.
getContent
().
size
();
i
++){
getGadget
().
getScene
().
addItemEntity
(
chestReward
.
getContent
().
get
(
i
).
getItemId
(),
chestReward
.
getContent
().
get
(
i
).
getCount
(),
getGadget
());
}
var
random
=
new
Random
(
System
.
currentTimeMillis
());
for
(
int
i
=
0
;
i
<
chestReward
.
getRandomCount
();
i
++){
var
index
=
random
.
nextInt
(
chestReward
.
getRandomContent
().
size
());
var
item
=
chestReward
.
getRandomContent
().
get
(
index
);
getGadget
().
getScene
().
addItemEntity
(
item
.
getItemId
(),
item
.
getCount
(),
getGadget
());
}
getGadget
().
updateState
(
ScriptGadgetState
.
ChestOpened
);
player
.
sendPacket
(
new
PacketGadgetInteractRsp
(
getGadget
(),
InteractType
.
INTERACT_OPEN_CHEST
));
return
true
;
}
public
void
onBuildProto
(
SceneGadgetInfo
.
Builder
gadgetInfo
)
{
}
}
src/main/java/emu/grasscutter/game/player/Player.java
View file @
b375881a
...
@@ -928,13 +928,6 @@ public class Player {
...
@@ -928,13 +928,6 @@ public class Player {
if
(
shouldDelete
)
{
if
(
shouldDelete
)
{
entity
.
getScene
().
removeEntity
(
entity
);
entity
.
getScene
().
removeEntity
(
entity
);
}
}
else
if
(
gadget
.
getGadgetData
().
getType
()
==
EntityType
.
Chest
)
{
getScene
().
updateGadgetState
(
gadget
,
ScriptGadgetState
.
ChestOpened
);
gadget
.
openChest
(
this
);
this
.
sendPacket
(
new
PacketGadgetInteractRsp
(
gadget
,
InteractType
.
INTERACT_OPEN_CHEST
));
getScene
().
killEntity
(
gadget
,
0
);
}
}
else
{
}
else
{
// Delete directly
// Delete directly
entity
.
getScene
().
removeEntity
(
entity
);
entity
.
getScene
().
removeEntity
(
entity
);
...
...
src/main/java/emu/grasscutter/game/world/Scene.java
View file @
b375881a
...
@@ -579,7 +579,7 @@ public class Scene {
...
@@ -579,7 +579,7 @@ public class Scene {
List
<
SceneGadget
>
garbageGadgets
=
group
.
getGarbageGadgets
();
List
<
SceneGadget
>
garbageGadgets
=
group
.
getGarbageGadgets
();
if
(
garbageGadgets
!=
null
)
{
if
(
garbageGadgets
!=
null
)
{
garbageGadgets
.
forEach
(
g
->
scriptManager
.
createGadget
s
(
group
.
id
,
group
.
block_id
,
g
));
garbageGadgets
.
forEach
(
g
->
scriptManager
.
createGadget
(
group
.
id
,
group
.
block_id
,
g
));
}
}
// Load suites
// Load suites
...
@@ -706,9 +706,4 @@ public class Scene {
...
@@ -706,9 +706,4 @@ public class Scene {
addEntity
(
entity
);
addEntity
(
entity
);
}
}
}
}
public
void
updateGadgetState
(
EntityGadget
gadget
,
int
state
){
gadget
.
setState
(
state
);
broadcastPacket
(
new
PacketGadgetStateNotify
(
gadget
,
state
));
}
}
}
src/main/java/emu/grasscutter/scripts/ScriptLib.java
View file @
b375881a
...
@@ -437,8 +437,8 @@ public class ScriptLib {
...
@@ -437,8 +437,8 @@ public class ScriptLib {
return
1
;
return
1
;
}
}
if
(
entity
instanceof
EntityGadget
entityGadget
){
if
(
entity
instanceof
EntityGadget
entityGadget
)
{
getSceneScriptManager
().
getScene
().
updateGadgetState
(
entityGadget
,
state
);
entityGadget
.
updateState
(
state
);
}
}
return
0
;
return
0
;
...
...
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