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
6d59159b
Commit
6d59159b
authored
Jun 16, 2022
by
Melledy
Browse files
Cleanup package names
parent
ac49114c
Changes
24
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/Grasscutter.java
View file @
6d59159b
...
...
@@ -6,8 +6,8 @@ import java.util.Calendar;
import
emu.grasscutter.auth.AuthenticationSystem
;
import
emu.grasscutter.auth.DefaultAuthentication
;
import
emu.grasscutter.command.CommandMap
;
import
emu.grasscutter.game.managers.
E
nergy
Manager
.EnergyManager
;
import
emu.grasscutter.game.managers.
S
tamina
Manager
.StaminaManager
;
import
emu.grasscutter.game.managers.
e
nergy.EnergyManager
;
import
emu.grasscutter.game.managers.
s
tamina.StaminaManager
;
import
emu.grasscutter.plugin.PluginManager
;
import
emu.grasscutter.plugin.api.ServerHook
;
import
emu.grasscutter.scripts.ScriptLoader
;
...
...
src/main/java/emu/grasscutter/command/commands/UnlimitEnergyCommand.java
View file @
6d59159b
...
...
@@ -5,7 +5,7 @@ import emu.grasscutter.command.Command;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.entity.EntityAvatar
;
import
emu.grasscutter.game.managers.
E
nergy
Manager
.EnergyManager
;
import
emu.grasscutter.game.managers.
e
nergy.EnergyManager
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.TeamManager
;
import
emu.grasscutter.game.props.ElementType
;
...
...
src/main/java/emu/grasscutter/game/managers/
C
hat
Manager
/ChatManager.java
→
src/main/java/emu/grasscutter/game/managers/
c
hat/ChatManager.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
C
hat
Manager
;
package
emu.grasscutter.game.managers.
c
hat
;
import
emu.grasscutter.command.CommandMap
;
import
emu.grasscutter.game.player.Player
;
...
...
src/main/java/emu/grasscutter/game/managers/
C
hat
Manager
/ChatManagerHandler.java
→
src/main/java/emu/grasscutter/game/managers/
c
hat/ChatManagerHandler.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
C
hat
Manager
;
package
emu.grasscutter.game.managers.
c
hat
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.game.GameServer
;
...
...
src/main/java/emu/grasscutter/game/managers/
D
eforestation
Manager
/DeforestationManager.java
→
src/main/java/emu/grasscutter/game/managers/
d
eforestation/DeforestationManager.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
D
eforestation
Manager
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
dev.morphia.annotations.Transient
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.game.entity.EntityItem
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.world.Scene
;
import
emu.grasscutter.net.proto.HitTreeNotifyOuterClass
;
import
emu.grasscutter.net.proto.VectorOuterClass
;
import
emu.grasscutter.utils.Position
;
public
class
DeforestationManager
{
final
static
int
RECORD_EXPIRED_SECONDS
=
60
*
5
;
// 5 min
final
static
int
RECORD_MAX_TIMES
=
3
;
// max number of wood
final
static
int
RECORD_MAX_TIMES_OTHER_HIT_TREE
=
10
;
// if hit 10 times other trees, reset wood
@Transient
private
final
Player
player
;
@Transient
private
final
ArrayList
<
HitTreeRecord
>
currentRecord
;
@Transient
private
final
static
HashMap
<
Integer
,
Integer
>
ColliderTypeToWoodItemID
=
new
HashMap
<>();
static
{
/* define wood types which reflected to item id*/
ColliderTypeToWoodItemID
.
put
(
1
,
101301
);
ColliderTypeToWoodItemID
.
put
(
2
,
101302
);
ColliderTypeToWoodItemID
.
put
(
3
,
101303
);
ColliderTypeToWoodItemID
.
put
(
4
,
101304
);
ColliderTypeToWoodItemID
.
put
(
5
,
101305
);
ColliderTypeToWoodItemID
.
put
(
6
,
101306
);
ColliderTypeToWoodItemID
.
put
(
7
,
101307
);
ColliderTypeToWoodItemID
.
put
(
8
,
101308
);
ColliderTypeToWoodItemID
.
put
(
9
,
101309
);
ColliderTypeToWoodItemID
.
put
(
10
,
101310
);
ColliderTypeToWoodItemID
.
put
(
11
,
101311
);
ColliderTypeToWoodItemID
.
put
(
12
,
101312
);
}
public
DeforestationManager
(
Player
player
){
this
.
player
=
player
;
this
.
currentRecord
=
new
ArrayList
<>();
}
public
void
resetWood
(){
synchronized
(
currentRecord
)
{
currentRecord
.
clear
();
}
}
public
void
onDeforestationInvoke
(
HitTreeNotifyOuterClass
.
HitTreeNotify
hit
){
synchronized
(
currentRecord
)
{
//Grasscutter.getLogger().info("onDeforestationInvoke! Wood records {}", currentRecord);
VectorOuterClass
.
Vector
hitPosition
=
hit
.
getHitPostion
();
int
woodType
=
hit
.
getWoodType
();
if
(
ColliderTypeToWoodItemID
.
containsKey
(
woodType
))
{
// is a available wood type
Scene
scene
=
player
.
getScene
();
int
itemId
=
ColliderTypeToWoodItemID
.
get
(
woodType
);
int
positionHash
=
hitPosition
.
hashCode
();
HitTreeRecord
record
=
searchRecord
(
positionHash
);
if
(
record
==
null
)
{
record
=
new
HitTreeRecord
(
positionHash
);
}
else
{
currentRecord
.
remove
(
record
);
// move it to last position
}
currentRecord
.
add
(
record
);
if
(
currentRecord
.
size
()>
RECORD_MAX_TIMES_OTHER_HIT_TREE
){
currentRecord
.
remove
(
0
);
}
if
(
record
.
record
())
{
EntityItem
entity
=
new
EntityItem
(
scene
,
null
,
GameData
.
getItemDataMap
().
get
(
itemId
),
new
Position
(
hitPosition
.
getX
(),
hitPosition
.
getY
(),
hitPosition
.
getZ
()),
1
,
false
);
scene
.
addEntity
(
entity
);
}
//record.record()=false : too many wood they have deforested, no more wood dropped!
}
else
{
Grasscutter
.
getLogger
().
warn
(
"No wood type {} found."
,
woodType
);
}
}
// unknown wood type
}
private
HitTreeRecord
searchRecord
(
int
id
){
for
(
HitTreeRecord
record
:
currentRecord
)
{
if
(
record
.
getUnique
()
==
id
)
{
return
record
;
}
}
return
null
;
}
}
package
emu.grasscutter.game.managers.
d
eforestation
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
dev.morphia.annotations.Transient
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.game.entity.EntityItem
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.world.Scene
;
import
emu.grasscutter.net.proto.HitTreeNotifyOuterClass
;
import
emu.grasscutter.net.proto.VectorOuterClass
;
import
emu.grasscutter.utils.Position
;
public
class
DeforestationManager
{
final
static
int
RECORD_EXPIRED_SECONDS
=
60
*
5
;
// 5 min
final
static
int
RECORD_MAX_TIMES
=
3
;
// max number of wood
final
static
int
RECORD_MAX_TIMES_OTHER_HIT_TREE
=
10
;
// if hit 10 times other trees, reset wood
@Transient
private
final
Player
player
;
@Transient
private
final
ArrayList
<
HitTreeRecord
>
currentRecord
;
@Transient
private
final
static
HashMap
<
Integer
,
Integer
>
ColliderTypeToWoodItemID
=
new
HashMap
<>();
static
{
/* define wood types which reflected to item id*/
ColliderTypeToWoodItemID
.
put
(
1
,
101301
);
ColliderTypeToWoodItemID
.
put
(
2
,
101302
);
ColliderTypeToWoodItemID
.
put
(
3
,
101303
);
ColliderTypeToWoodItemID
.
put
(
4
,
101304
);
ColliderTypeToWoodItemID
.
put
(
5
,
101305
);
ColliderTypeToWoodItemID
.
put
(
6
,
101306
);
ColliderTypeToWoodItemID
.
put
(
7
,
101307
);
ColliderTypeToWoodItemID
.
put
(
8
,
101308
);
ColliderTypeToWoodItemID
.
put
(
9
,
101309
);
ColliderTypeToWoodItemID
.
put
(
10
,
101310
);
ColliderTypeToWoodItemID
.
put
(
11
,
101311
);
ColliderTypeToWoodItemID
.
put
(
12
,
101312
);
}
public
DeforestationManager
(
Player
player
){
this
.
player
=
player
;
this
.
currentRecord
=
new
ArrayList
<>();
}
public
void
resetWood
(){
synchronized
(
currentRecord
)
{
currentRecord
.
clear
();
}
}
public
void
onDeforestationInvoke
(
HitTreeNotifyOuterClass
.
HitTreeNotify
hit
){
synchronized
(
currentRecord
)
{
//Grasscutter.getLogger().info("onDeforestationInvoke! Wood records {}", currentRecord);
VectorOuterClass
.
Vector
hitPosition
=
hit
.
getHitPostion
();
int
woodType
=
hit
.
getWoodType
();
if
(
ColliderTypeToWoodItemID
.
containsKey
(
woodType
))
{
// is a available wood type
Scene
scene
=
player
.
getScene
();
int
itemId
=
ColliderTypeToWoodItemID
.
get
(
woodType
);
int
positionHash
=
hitPosition
.
hashCode
();
HitTreeRecord
record
=
searchRecord
(
positionHash
);
if
(
record
==
null
)
{
record
=
new
HitTreeRecord
(
positionHash
);
}
else
{
currentRecord
.
remove
(
record
);
// move it to last position
}
currentRecord
.
add
(
record
);
if
(
currentRecord
.
size
()>
RECORD_MAX_TIMES_OTHER_HIT_TREE
){
currentRecord
.
remove
(
0
);
}
if
(
record
.
record
())
{
EntityItem
entity
=
new
EntityItem
(
scene
,
null
,
GameData
.
getItemDataMap
().
get
(
itemId
),
new
Position
(
hitPosition
.
getX
(),
hitPosition
.
getY
(),
hitPosition
.
getZ
()),
1
,
false
);
scene
.
addEntity
(
entity
);
}
//record.record()=false : too many wood they have deforested, no more wood dropped!
}
else
{
Grasscutter
.
getLogger
().
warn
(
"No wood type {} found."
,
woodType
);
}
}
// unknown wood type
}
private
HitTreeRecord
searchRecord
(
int
id
){
for
(
HitTreeRecord
record
:
currentRecord
)
{
if
(
record
.
getUnique
()
==
id
)
{
return
record
;
}
}
return
null
;
}
}
src/main/java/emu/grasscutter/game/managers/
D
eforestation
Manager
/HitTreeRecord.java
→
src/main/java/emu/grasscutter/game/managers/
d
eforestation/HitTreeRecord.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
D
eforestation
Manager
;
public
class
HitTreeRecord
{
private
final
int
unique
;
private
short
count
;
// hit this tree times
private
long
time
;
// last available hitting time
HitTreeRecord
(
int
unique
){
this
.
count
=
0
;
this
.
time
=
0
;
this
.
unique
=
unique
;
}
/**
* reset hit time
*/
private
void
resetTime
(){
this
.
time
=
System
.
currentTimeMillis
();
}
/**
* commit hit behavior
*/
public
boolean
record
(){
if
(
this
.
count
<
DeforestationManager
.
RECORD_MAX_TIMES
)
{
this
.
count
++;
resetTime
();
return
true
;
}
// check expired
boolean
isWaiting
=
System
.
currentTimeMillis
()
-
this
.
time
<
DeforestationManager
.
RECORD_EXPIRED_SECONDS
*
1000L
;
if
(
isWaiting
){
return
false
;
}
else
{
this
.
count
=
1
;
resetTime
();
return
true
;
}
}
/**
* get unique id
*/
public
int
getUnique
(){
return
unique
;
}
@Override
public
String
toString
()
{
return
"HitTreeRecord{"
+
"unique="
+
unique
+
", count="
+
count
+
", time="
+
time
+
'}'
;
}
}
package
emu.grasscutter.game.managers.
d
eforestation
;
public
class
HitTreeRecord
{
private
final
int
unique
;
private
short
count
;
// hit this tree times
private
long
time
;
// last available hitting time
HitTreeRecord
(
int
unique
){
this
.
count
=
0
;
this
.
time
=
0
;
this
.
unique
=
unique
;
}
/**
* reset hit time
*/
private
void
resetTime
(){
this
.
time
=
System
.
currentTimeMillis
();
}
/**
* commit hit behavior
*/
public
boolean
record
(){
if
(
this
.
count
<
DeforestationManager
.
RECORD_MAX_TIMES
)
{
this
.
count
++;
resetTime
();
return
true
;
}
// check expired
boolean
isWaiting
=
System
.
currentTimeMillis
()
-
this
.
time
<
DeforestationManager
.
RECORD_EXPIRED_SECONDS
*
1000L
;
if
(
isWaiting
){
return
false
;
}
else
{
this
.
count
=
1
;
resetTime
();
return
true
;
}
}
/**
* get unique id
*/
public
int
getUnique
(){
return
unique
;
}
@Override
public
String
toString
()
{
return
"HitTreeRecord{"
+
"unique="
+
unique
+
", count="
+
count
+
", time="
+
time
+
'}'
;
}
}
src/main/java/emu/grasscutter/game/managers/
E
nergy
Manager
/EnergyDropEntry.java
→
src/main/java/emu/grasscutter/game/managers/
e
nergy/EnergyDropEntry.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
E
nergy
Manager
;
package
emu.grasscutter.game.managers.
e
nergy
;
import
java.util.List
;
...
...
src/main/java/emu/grasscutter/game/managers/
E
nergy
Manager
/EnergyDropInfo.java
→
src/main/java/emu/grasscutter/game/managers/
e
nergy/EnergyDropInfo.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
E
nergy
Manager
;
package
emu.grasscutter.game.managers.
e
nergy
;
public
class
EnergyDropInfo
{
private
int
ballId
;
...
...
src/main/java/emu/grasscutter/game/managers/
E
nergy
Manager
/EnergyManager.java
→
src/main/java/emu/grasscutter/game/managers/
e
nergy/EnergyManager.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
E
nergy
Manager
;
package
emu.grasscutter.game.managers.
e
nergy
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.DataLoader
;
...
...
src/main/java/emu/grasscutter/game/managers/
E
nergy
Manager
/SkillParticleGenerationEntry.java
→
src/main/java/emu/grasscutter/game/managers/
e
nergy/SkillParticleGenerationEntry.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
E
nergy
Manager
;
package
emu.grasscutter.game.managers.
e
nergy
;
import
java.util.List
;
...
...
src/main/java/emu/grasscutter/game/managers/
E
nergy
Manager
/SkillParticleGenerationInfo.java
→
src/main/java/emu/grasscutter/game/managers/
e
nergy/SkillParticleGenerationInfo.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
E
nergy
Manager
;
package
emu.grasscutter.game.managers.
e
nergy
;
public
class
SkillParticleGenerationInfo
{
private
int
value
;
...
...
src/main/java/emu/grasscutter/game/managers/
F
orging
Manager
/ActiveForgeData.java
→
src/main/java/emu/grasscutter/game/managers/
f
orging/ActiveForgeData.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
F
orging
Manager
;
package
emu.grasscutter.game.managers.
f
orging
;
import
dev.morphia.annotations.Entity
;
import
emu.grasscutter.utils.Utils
;
...
...
src/main/java/emu/grasscutter/game/managers/
F
orging
Manager
/ForgingManager.java
→
src/main/java/emu/grasscutter/game/managers/
f
orging/ForgingManager.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
F
orging
Manager
;
package
emu.grasscutter.game.managers.
f
orging
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
src/main/java/emu/grasscutter/game/managers/
M
ap
M
ark
Manager
/MapMark.java
→
src/main/java/emu/grasscutter/game/managers/
m
ap
m
ark/MapMark.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
M
ap
M
ark
Manager
;
import
dev.morphia.annotations.Entity
;
import
emu.grasscutter.net.proto.MapMarkFromTypeOuterClass.MapMarkFromType
;
import
emu.grasscutter.net.proto.MapMarkPointOuterClass.MapMarkPoint
;
import
emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType
;
import
emu.grasscutter.utils.Position
;
@Entity
public
class
MapMark
{
private
int
sceneId
;
private
String
name
;
private
Position
position
;
private
MapMarkPointType
mapMarkPointType
;
private
int
monsterId
;
private
MapMarkFromType
mapMarkFromType
;
private
int
questId
;
@Deprecated
// Morhpia
public
MapMark
()
{
this
.
mapMarkPointType
=
MapMarkPointType
.
MAP_MARK_POINT_TYPE_MONSTER
;
this
.
mapMarkFromType
=
MapMarkFromType
.
MAP_MARK_FROM_TYPE_MONSTER
;
}
public
MapMark
(
MapMarkPoint
mapMarkPoint
)
{
this
.
sceneId
=
mapMarkPoint
.
getSceneId
();
this
.
name
=
mapMarkPoint
.
getName
();
this
.
position
=
new
Position
(
mapMarkPoint
.
getPos
().
getX
(),
mapMarkPoint
.
getPos
().
getY
(),
mapMarkPoint
.
getPos
().
getZ
()
);
this
.
mapMarkPointType
=
mapMarkPoint
.
getPointType
();
this
.
monsterId
=
mapMarkPoint
.
getMonsterId
();
this
.
mapMarkFromType
=
mapMarkPoint
.
getFromType
();
this
.
questId
=
mapMarkPoint
.
getQuestId
();
}
public
int
getSceneId
()
{
return
this
.
sceneId
;
}
public
String
getName
()
{
return
this
.
name
;
}
public
Position
getPosition
()
{
return
this
.
position
;
}
public
MapMarkPointType
getMapMarkPointType
()
{
return
this
.
mapMarkPointType
;
}
public
int
getMonsterId
()
{
return
this
.
monsterId
;
}
public
MapMarkFromType
getMapMarkFromType
()
{
return
this
.
mapMarkFromType
;
}
public
int
getQuestId
()
{
return
this
.
questId
;
}
package
emu.grasscutter.game.managers.
m
ap
m
ark
;
import
dev.morphia.annotations.Entity
;
import
emu.grasscutter.net.proto.MapMarkFromTypeOuterClass.MapMarkFromType
;
import
emu.grasscutter.net.proto.MapMarkPointOuterClass.MapMarkPoint
;
import
emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType
;
import
emu.grasscutter.utils.Position
;
@Entity
public
class
MapMark
{
private
int
sceneId
;
private
String
name
;
private
Position
position
;
private
MapMarkPointType
mapMarkPointType
;
private
int
monsterId
;
private
MapMarkFromType
mapMarkFromType
;
private
int
questId
;
@Deprecated
// Morhpia
public
MapMark
()
{
this
.
mapMarkPointType
=
MapMarkPointType
.
MAP_MARK_POINT_TYPE_MONSTER
;
this
.
mapMarkFromType
=
MapMarkFromType
.
MAP_MARK_FROM_TYPE_MONSTER
;
}
public
MapMark
(
MapMarkPoint
mapMarkPoint
)
{
this
.
sceneId
=
mapMarkPoint
.
getSceneId
();
this
.
name
=
mapMarkPoint
.
getName
();
this
.
position
=
new
Position
(
mapMarkPoint
.
getPos
().
getX
(),
mapMarkPoint
.
getPos
().
getY
(),
mapMarkPoint
.
getPos
().
getZ
()
);
this
.
mapMarkPointType
=
mapMarkPoint
.
getPointType
();
this
.
monsterId
=
mapMarkPoint
.
getMonsterId
();
this
.
mapMarkFromType
=
mapMarkPoint
.
getFromType
();
this
.
questId
=
mapMarkPoint
.
getQuestId
();
}
public
int
getSceneId
()
{
return
this
.
sceneId
;
}
public
String
getName
()
{
return
this
.
name
;
}
public
Position
getPosition
()
{
return
this
.
position
;
}
public
MapMarkPointType
getMapMarkPointType
()
{
return
this
.
mapMarkPointType
;
}
public
int
getMonsterId
()
{
return
this
.
monsterId
;
}
public
MapMarkFromType
getMapMarkFromType
()
{
return
this
.
mapMarkFromType
;
}
public
int
getQuestId
()
{
return
this
.
questId
;
}
}
\ No newline at end of file
src/main/java/emu/grasscutter/game/managers/
M
ap
M
ark
Manager
/MapMarksManager.java
→
src/main/java/emu/grasscutter/game/managers/
m
ap
m
ark/MapMarksManager.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
M
ap
M
ark
Manager
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType
;
import
emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq
;
import
emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq.Operation
;
import
emu.grasscutter.server.packet.send.PacketMarkMapRsp
;
import
emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify
;
import
emu.grasscutter.utils.Position
;
import
java.util.HashMap
;
public
class
MapMarksManager
{
public
static
final
int
mapMarkMaxCount
=
150
;
private
HashMap
<
String
,
MapMark
>
mapMarks
;
private
final
Player
player
;
public
MapMarksManager
(
Player
player
)
{
this
.
player
=
player
;
this
.
mapMarks
=
player
.
getMapMarks
();
if
(
this
.
mapMarks
==
null
)
{
this
.
mapMarks
=
new
HashMap
<>();
}
}
public
void
handleMapMarkReq
(
MarkMapReq
req
)
{
Operation
op
=
req
.
getOp
();
switch
(
op
)
{
case
OPERATION_ADD
->
{
MapMark
createMark
=
new
MapMark
(
req
.
getMark
());
// keep teleporting functionality on fishhook mark.
if
(
createMark
.
getMapMarkPointType
()
==
MapMarkPointType
.
MAP_MARK_POINT_TYPE_FISH_POOL
)
{
teleport
(
player
,
createMark
);
return
;
}
addMapMark
(
createMark
);
}
case
OPERATION_MOD
->
{
MapMark
oldMark
=
new
MapMark
(
req
.
getOld
());
removeMapMark
(
oldMark
.
getPosition
());
MapMark
newMark
=
new
MapMark
(
req
.
getMark
());
addMapMark
(
newMark
);
}
case
OPERATION_DEL
->
{
MapMark
deleteMark
=
new
MapMark
(
req
.
getMark
());
removeMapMark
(
deleteMark
.
getPosition
());
}
}
if
(
op
!=
Operation
.
OPERATION_GET
)
{
saveMapMarks
();
}
player
.
getSession
().
send
(
new
PacketMarkMapRsp
(
getMapMarks
()));
}
public
HashMap
<
String
,
MapMark
>
getMapMarks
()
{
return
mapMarks
;
}
public
String
getMapMarkKey
(
Position
position
)
{
return
"x"
+
(
int
)
position
.
getX
()+
"z"
+
(
int
)
position
.
getZ
();
}
public
void
removeMapMark
(
Position
position
)
{
mapMarks
.
remove
(
getMapMarkKey
(
position
));
}
public
void
addMapMark
(
MapMark
mapMark
)
{
if
(
mapMarks
.
size
()
<
mapMarkMaxCount
)
{
mapMarks
.
put
(
getMapMarkKey
(
mapMark
.
getPosition
()),
mapMark
);
}
}
private
void
saveMapMarks
()
{
player
.
setMapMarks
(
mapMarks
);
player
.
save
();
}
private
void
teleport
(
Player
player
,
MapMark
mapMark
)
{
float
y
;
try
{
y
=
(
float
)
Integer
.
parseInt
(
mapMark
.
getName
());
}
catch
(
Exception
e
)
{
y
=
300
;
}
Position
pos
=
mapMark
.
getPosition
();
player
.
getPos
().
set
(
pos
.
getX
(),
y
,
pos
.
getZ
());
if
(
mapMark
.
getSceneId
()
!=
player
.
getSceneId
())
{
player
.
getWorld
().
transferPlayerToScene
(
player
,
mapMark
.
getSceneId
(),
player
.
getPos
());
}
player
.
getScene
().
broadcastPacket
(
new
PacketSceneEntityAppearNotify
(
player
));
}
}
package
emu.grasscutter.game.managers.
m
ap
m
ark
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType
;
import
emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq
;
import
emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq.Operation
;
import
emu.grasscutter.server.packet.send.PacketMarkMapRsp
;
import
emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify
;
import
emu.grasscutter.utils.Position
;
import
java.util.HashMap
;
public
class
MapMarksManager
{
public
static
final
int
mapMarkMaxCount
=
150
;
private
HashMap
<
String
,
MapMark
>
mapMarks
;
private
final
Player
player
;
public
MapMarksManager
(
Player
player
)
{
this
.
player
=
player
;
this
.
mapMarks
=
player
.
getMapMarks
();
if
(
this
.
mapMarks
==
null
)
{
this
.
mapMarks
=
new
HashMap
<>();
}
}
public
void
handleMapMarkReq
(
MarkMapReq
req
)
{
Operation
op
=
req
.
getOp
();
switch
(
op
)
{
case
OPERATION_ADD
->
{
MapMark
createMark
=
new
MapMark
(
req
.
getMark
());
// keep teleporting functionality on fishhook mark.
if
(
createMark
.
getMapMarkPointType
()
==
MapMarkPointType
.
MAP_MARK_POINT_TYPE_FISH_POOL
)
{
teleport
(
player
,
createMark
);
return
;
}
addMapMark
(
createMark
);
}
case
OPERATION_MOD
->
{
MapMark
oldMark
=
new
MapMark
(
req
.
getOld
());
removeMapMark
(
oldMark
.
getPosition
());
MapMark
newMark
=
new
MapMark
(
req
.
getMark
());
addMapMark
(
newMark
);
}
case
OPERATION_DEL
->
{
MapMark
deleteMark
=
new
MapMark
(
req
.
getMark
());
removeMapMark
(
deleteMark
.
getPosition
());
}
}
if
(
op
!=
Operation
.
OPERATION_GET
)
{
saveMapMarks
();
}
player
.
getSession
().
send
(
new
PacketMarkMapRsp
(
getMapMarks
()));
}
public
HashMap
<
String
,
MapMark
>
getMapMarks
()
{
return
mapMarks
;
}
public
String
getMapMarkKey
(
Position
position
)
{
return
"x"
+
(
int
)
position
.
getX
()+
"z"
+
(
int
)
position
.
getZ
();
}
public
void
removeMapMark
(
Position
position
)
{
mapMarks
.
remove
(
getMapMarkKey
(
position
));
}
public
void
addMapMark
(
MapMark
mapMark
)
{
if
(
mapMarks
.
size
()
<
mapMarkMaxCount
)
{
mapMarks
.
put
(
getMapMarkKey
(
mapMark
.
getPosition
()),
mapMark
);
}
}
private
void
saveMapMarks
()
{
player
.
setMapMarks
(
mapMarks
);
player
.
save
();
}
private
void
teleport
(
Player
player
,
MapMark
mapMark
)
{
float
y
;
try
{
y
=
(
float
)
Integer
.
parseInt
(
mapMark
.
getName
());
}
catch
(
Exception
e
)
{
y
=
300
;
}
Position
pos
=
mapMark
.
getPosition
();
player
.
getPos
().
set
(
pos
.
getX
(),
y
,
pos
.
getZ
());
if
(
mapMark
.
getSceneId
()
!=
player
.
getSceneId
())
{
player
.
getWorld
().
transferPlayerToScene
(
player
,
mapMark
.
getSceneId
(),
player
.
getPos
());
}
player
.
getScene
().
broadcastPacket
(
new
PacketSceneEntityAppearNotify
(
player
));
}
}
src/main/java/emu/grasscutter/game/managers/
S
tamina
Manager
/AfterUpdateStaminaListener.java
→
src/main/java/emu/grasscutter/game/managers/
s
tamina/AfterUpdateStaminaListener.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
S
tamina
Manager
;
public
interface
AfterUpdateStaminaListener
{
/**
* onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina.
* This gives listeners a chance to intercept this update.
*
* @param reason Why updating stamina.
* @param newStamina New Stamina value.
*/
void
onAfterUpdateStamina
(
String
reason
,
int
newStamina
,
boolean
isCharacterStamina
);
}
package
emu.grasscutter.game.managers.
s
tamina
;
public
interface
AfterUpdateStaminaListener
{
/**
* onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina.
* This gives listeners a chance to intercept this update.
*
* @param reason Why updating stamina.
* @param newStamina New Stamina value.
*/
void
onAfterUpdateStamina
(
String
reason
,
int
newStamina
,
boolean
isCharacterStamina
);
}
src/main/java/emu/grasscutter/game/managers/
S
tamina
Manager
/BeforeUpdateStaminaListener.java
→
src/main/java/emu/grasscutter/game/managers/
s
tamina/BeforeUpdateStaminaListener.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
S
tamina
Manager
;
public
interface
BeforeUpdateStaminaListener
{
/**
* onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina.
* This gives listeners a chance to intercept this update.
* @param reason Why updating stamina.
* @param newStamina New ABSOLUTE stamina value.
* @return true if you want to cancel this update, otherwise false.
*/
int
onBeforeUpdateStamina
(
String
reason
,
int
newStamina
,
boolean
isCharacterStamina
);
/**
* onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina.
* This gives listeners a chance to intercept this update.
* @param reason Why updating stamina.
* @param consumption ConsumptionType and RELATIVE stamina change amount.
* @return true if you want to cancel this update, otherwise false.
*/
Consumption
onBeforeUpdateStamina
(
String
reason
,
Consumption
consumption
,
boolean
isCharacterStamina
);
package
emu.grasscutter.game.managers.
s
tamina
;
public
interface
BeforeUpdateStaminaListener
{
/**
* onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina.
* This gives listeners a chance to intercept this update.
* @param reason Why updating stamina.
* @param newStamina New ABSOLUTE stamina value.
* @return true if you want to cancel this update, otherwise false.
*/
int
onBeforeUpdateStamina
(
String
reason
,
int
newStamina
,
boolean
isCharacterStamina
);
/**
* onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina.
* This gives listeners a chance to intercept this update.
* @param reason Why updating stamina.
* @param consumption ConsumptionType and RELATIVE stamina change amount.
* @return true if you want to cancel this update, otherwise false.
*/
Consumption
onBeforeUpdateStamina
(
String
reason
,
Consumption
consumption
,
boolean
isCharacterStamina
);
}
\ No newline at end of file
src/main/java/emu/grasscutter/game/managers/
S
tamina
Manager
/Consumption.java
→
src/main/java/emu/grasscutter/game/managers/
s
tamina/Consumption.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
S
tamina
Manager
;
public
class
Consumption
{
public
ConsumptionType
type
=
ConsumptionType
.
None
;
public
int
amount
=
0
;
public
Consumption
(
ConsumptionType
type
,
int
amount
)
{
this
.
type
=
type
;
this
.
amount
=
amount
;
}
public
Consumption
(
ConsumptionType
type
)
{
this
(
type
,
type
.
amount
);
}
public
Consumption
()
{
}
}
package
emu.grasscutter.game.managers.
s
tamina
;
public
class
Consumption
{
public
ConsumptionType
type
=
ConsumptionType
.
None
;
public
int
amount
=
0
;
public
Consumption
(
ConsumptionType
type
,
int
amount
)
{
this
.
type
=
type
;
this
.
amount
=
amount
;
}
public
Consumption
(
ConsumptionType
type
)
{
this
(
type
,
type
.
amount
);
}
public
Consumption
()
{
}
}
src/main/java/emu/grasscutter/game/managers/
S
tamina
Manager
/ConsumptionType.java
→
src/main/java/emu/grasscutter/game/managers/
s
tamina/ConsumptionType.java
View file @
6d59159b
package
emu.grasscutter.game.managers.
S
tamina
Manager
;
public
enum
ConsumptionType
{
None
(
0
),
// consume
CLIMBING
(-
150
),
CLIMB_START
(-
500
),
CLIMB_JUMP
(-
2500
),
DASH
(-
360
),
FIGHT
(
0
),
// See StaminaManager.getFightConsumption()
FLY
(-
60
),
// Slow swimming is handled per movement, not per second.
// Arm movement frequency depends on gender/age/height.
// TODO: Instead of cost -80 per tick, find a proper way to calculate cost.
SKIFF_DASH
(-
204
),
SPRINT
(-
1800
),
SWIM_DASH_START
(-
2000
),
SWIM_DASH
(-
204
),
// -10.2 per second, 5Hz = -204 each tick
SWIMMING
(-
80
),
TALENT_DASH
(-
300
),
// -1500 per second, 5Hz = -300 each tick
TALENT_DASH_START
(-
1000
),
// restore
POWERED_FLY
(
500
),
POWERED_SKIFF
(
500
),
RUN
(
500
),
SKIFF
(
500
),
STANDBY
(
500
),
WALK
(
500
);
public
final
int
amount
;
ConsumptionType
(
int
amount
)
{
this
.
amount
=
amount
;
}
package
emu.grasscutter.game.managers.
s
tamina
;
public
enum
ConsumptionType
{
None
(
0
),
// consume
CLIMBING
(-
150
),
CLIMB_START
(-
500
),
CLIMB_JUMP
(-
2500
),
DASH
(-
360
),
FIGHT
(
0
),
// See StaminaManager.getFightConsumption()
FLY
(-
60
),
// Slow swimming is handled per movement, not per second.
// Arm movement frequency depends on gender/age/height.
// TODO: Instead of cost -80 per tick, find a proper way to calculate cost.
SKIFF_DASH
(-
204
),
SPRINT
(-
1800
),
SWIM_DASH_START
(-
2000
),
SWIM_DASH
(-
204
),
// -10.2 per second, 5Hz = -204 each tick
SWIMMING
(-
80
),
TALENT_DASH
(-
300
),
// -1500 per second, 5Hz = -300 each tick
TALENT_DASH_START
(-
1000
),
// restore
POWERED_FLY
(
500
),
POWERED_SKIFF
(
500
),
RUN
(
500
),
SKIFF
(
500
),
STANDBY
(
500
),
WALK
(
500
);
public
final
int
amount
;
ConsumptionType
(
int
amount
)
{
this
.
amount
=
amount
;
}
}
\ No newline at end of file
src/main/java/emu/grasscutter/game/managers/
S
tamina
Manager
/README.md
→
src/main/java/emu/grasscutter/game/managers/
s
tamina/README.md
View file @
6d59159b
# Stamina Manager
---
## UpdateStamina
```
java
// will use consumption.consumptionType as reason
public
int
updateStaminaRelative
(
GameSession
session
,
Consumption
consumption
);
```
```
java
public
int
updateStaminaAbsolute
(
GameSession
session
,
String
reason
,
int
newStamina
)
```
---
## Pause and Resume
```
java
public
void
startSustainedStaminaHandler
()
```
```
java
public
void
stopSustainedStaminaHandler
()
```
---
## Stamina change listeners and intercepting
### BeforeUpdateStaminaListener
```
java
import
emu.grasscutter.game.managers.StaminaManager.BeforeUpdateStaminaListener
;
// Listener sample: plugin disable CLIMB_JUMP stamina cost.
private
class
MyClass
implements
BeforeUpdateStaminaListener
{
// Make your class implement the listener, and pass in your class as a listener.
public
MyClass
()
{
getStaminaManager
().
registerBeforeUpdateStaminaListener
(
"myClass"
,
this
);
}
@Override
public
boolean
onBeforeUpdateStamina
(
String
reason
,
int
newStamina
)
{
// do not intercept this update
return
false
;
}
@Override
public
boolean
onBeforeUpdateStamina
(
String
reason
,
Consumption
consumption
)
{
// Try to intercept if this update is CLIMB_JUMP
if
(
consumption
.
consumptionType
==
ConsumptionType
.
CLIMB_JUMP
)
{
return
true
;
}
// If it is not CLIMB_JUMP, do not intercept.
return
false
;
}
}
```
### AfterUpdateStaminaListener
```
java
import
emu.grasscutter.game.managers.StaminaManager.AfterUpdateStaminaListener
;
// Listener sample: plugin listens for changes already made.
private
class
MyClass
implements
AfterUpdateStaminaListener
{
// Make your class implement the listener, and pass in your class as a listener.
public
MyClass
()
{
registerAfterUpdateStaminaListener
(
"myClass"
,
this
);
}
@Override
public
void
onAfterUpdateStamina
(
String
reason
,
int
newStamina
)
{
// ...
}
}
# Stamina Manager
---
## UpdateStamina
```
java
// will use consumption.consumptionType as reason
public
int
updateStaminaRelative
(
GameSession
session
,
Consumption
consumption
);
```
```
java
public
int
updateStaminaAbsolute
(
GameSession
session
,
String
reason
,
int
newStamina
)
```
---
## Pause and Resume
```
java
public
void
startSustainedStaminaHandler
()
```
```
java
public
void
stopSustainedStaminaHandler
()
```
---
## Stamina change listeners and intercepting
### BeforeUpdateStaminaListener
```
java
import
emu.grasscutter.game.managers.StaminaManager.BeforeUpdateStaminaListener
;
// Listener sample: plugin disable CLIMB_JUMP stamina cost.
private
class
MyClass
implements
BeforeUpdateStaminaListener
{
// Make your class implement the listener, and pass in your class as a listener.
public
MyClass
()
{
getStaminaManager
().
registerBeforeUpdateStaminaListener
(
"myClass"
,
this
);
}
@Override
public
boolean
onBeforeUpdateStamina
(
String
reason
,
int
newStamina
)
{
// do not intercept this update
return
false
;
}
@Override
public
boolean
onBeforeUpdateStamina
(
String
reason
,
Consumption
consumption
)
{
// Try to intercept if this update is CLIMB_JUMP
if
(
consumption
.
consumptionType
==
ConsumptionType
.
CLIMB_JUMP
)
{
return
true
;
}
// If it is not CLIMB_JUMP, do not intercept.
return
false
;
}
}
```
### AfterUpdateStaminaListener
```
java
import
emu.grasscutter.game.managers.StaminaManager.AfterUpdateStaminaListener
;
// Listener sample: plugin listens for changes already made.
private
class
MyClass
implements
AfterUpdateStaminaListener
{
// Make your class implement the listener, and pass in your class as a listener.
public
MyClass
()
{
registerAfterUpdateStaminaListener
(
"myClass"
,
this
);
}
@Override
public
void
onAfterUpdateStamina
(
String
reason
,
int
newStamina
)
{
// ...
}
}
```
\ No newline at end of file
Prev
1
2
Next
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