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