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
e0593554
Commit
e0593554
authored
May 24, 2022
by
logictc
Committed by
Melledy
May 24, 2022
Browse files
implement persist energy
parent
7f7e82e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/avatar/Avatar.java
View file @
e0593554
...
@@ -81,6 +81,7 @@ public class Avatar {
...
@@ -81,6 +81,7 @@ public class Avatar {
private
int
satiation
;
// ?
private
int
satiation
;
// ?
private
int
satiationPenalty
;
// ?
private
int
satiationPenalty
;
// ?
private
float
currentHp
;
private
float
currentHp
;
private
float
currentEnergy
;
@Transient
private
final
Int2ObjectMap
<
GameItem
>
equips
;
@Transient
private
final
Int2ObjectMap
<
GameItem
>
equips
;
@Transient
private
final
Int2FloatOpenHashMap
fightProp
;
@Transient
private
final
Int2FloatOpenHashMap
fightProp
;
...
@@ -149,7 +150,7 @@ public class Avatar {
...
@@ -149,7 +150,7 @@ public class Avatar {
this
.
recalcStats
();
this
.
recalcStats
();
this
.
currentHp
=
getFightProperty
(
FightProperty
.
FIGHT_PROP_MAX_HP
);
this
.
currentHp
=
getFightProperty
(
FightProperty
.
FIGHT_PROP_MAX_HP
);
setFightProperty
(
FightProperty
.
FIGHT_PROP_CUR_HP
,
this
.
currentHp
);
setFightProperty
(
FightProperty
.
FIGHT_PROP_CUR_HP
,
this
.
currentHp
);
this
.
currentEnergy
=
0
f
;
// Load handler
// Load handler
this
.
onLoad
();
this
.
onLoad
();
}
}
...
@@ -358,6 +359,30 @@ public class Avatar {
...
@@ -358,6 +359,30 @@ public class Avatar {
this
.
currentHp
=
currentHp
;
this
.
currentHp
=
currentHp
;
}
}
public
void
setCurrentEnergy
()
{
this
.
setCurrentEnergy
(
this
.
currentEnergy
);
}
public
void
setCurrentEnergy
(
float
currentEnergy
)
{
if
(
this
.
getSkillDepot
()
!=
null
&&
this
.
getSkillDepot
().
getEnergySkillData
()
!=
null
)
{
ElementType
element
=
this
.
getSkillDepot
().
getElementType
();
this
.
setFightProperty
(
element
.
getMaxEnergyProp
(),
this
.
getSkillDepot
().
getEnergySkillData
().
getCostElemVal
());
if
(
GAME_OPTIONS
.
energyUsage
)
{
this
.
setFightProperty
(
element
.
getCurEnergyProp
(),
currentEnergy
);
}
else
{
this
.
setFightProperty
(
element
.
getCurEnergyProp
(),
this
.
getSkillDepot
().
getEnergySkillData
().
getCostElemVal
());
}
}
}
public
void
setCurrentEnergy
(
FightProperty
curEnergyProp
,
float
currentEnergy
)
{
this
.
setFightProperty
(
curEnergyProp
,
currentEnergy
);
this
.
currentEnergy
=
currentEnergy
;
this
.
save
();
}
public
Int2FloatOpenHashMap
getFightProperties
()
{
public
Int2FloatOpenHashMap
getFightProperties
()
{
return
fightProp
;
return
fightProp
;
}
}
...
@@ -516,17 +541,7 @@ public class Avatar {
...
@@ -516,17 +541,7 @@ public class Avatar {
}
}
// Set energy usage
// Set energy usage
if
(
this
.
getSkillDepot
()
!=
null
&&
this
.
getSkillDepot
().
getEnergySkillData
()
!=
null
)
{
setCurrentEnergy
(
currentEnergy
);
ElementType
element
=
this
.
getSkillDepot
().
getElementType
();
this
.
setFightProperty
(
element
.
getMaxEnergyProp
(),
this
.
getSkillDepot
().
getEnergySkillData
().
getCostElemVal
());
if
(
GAME_OPTIONS
.
energyUsage
)
{
this
.
setFightProperty
(
element
.
getCurEnergyProp
(),
currentEnergy
);
}
else
{
this
.
setFightProperty
(
element
.
getCurEnergyProp
(),
this
.
getSkillDepot
().
getEnergySkillData
().
getCostElemVal
());
}
}
// Artifacts
// Artifacts
for
(
int
slotId
=
1
;
slotId
<=
5
;
slotId
++)
{
for
(
int
slotId
=
1
;
slotId
<=
5
;
slotId
++)
{
...
...
src/main/java/emu/grasscutter/game/entity/EntityAvatar.java
View file @
e0593554
...
@@ -46,6 +46,7 @@ public class EntityAvatar extends GameEntity {
...
@@ -46,6 +46,7 @@ public class EntityAvatar extends GameEntity {
public
EntityAvatar
(
Scene
scene
,
Avatar
avatar
)
{
public
EntityAvatar
(
Scene
scene
,
Avatar
avatar
)
{
super
(
scene
);
super
(
scene
);
this
.
avatar
=
avatar
;
this
.
avatar
=
avatar
;
this
.
avatar
.
setCurrentEnergy
();
this
.
id
=
getScene
().
getWorld
().
getNextEntityId
(
EntityIdType
.
AVATAR
);
this
.
id
=
getScene
().
getWorld
().
getNextEntityId
(
EntityIdType
.
AVATAR
);
GameItem
weapon
=
this
.
getAvatar
().
getWeapon
();
GameItem
weapon
=
this
.
getAvatar
().
getWeapon
();
...
@@ -57,6 +58,7 @@ public class EntityAvatar extends GameEntity {
...
@@ -57,6 +58,7 @@ public class EntityAvatar extends GameEntity {
public
EntityAvatar
(
Avatar
avatar
)
{
public
EntityAvatar
(
Avatar
avatar
)
{
super
(
null
);
super
(
null
);
this
.
avatar
=
avatar
;
this
.
avatar
=
avatar
;
this
.
avatar
.
setCurrentEnergy
();
}
}
public
Player
getPlayer
()
{
public
Player
getPlayer
()
{
...
@@ -128,7 +130,7 @@ public class EntityAvatar extends GameEntity {
...
@@ -128,7 +130,7 @@ public class EntityAvatar extends GameEntity {
public
void
clearEnergy
(
PropChangeReason
reason
)
{
public
void
clearEnergy
(
PropChangeReason
reason
)
{
FightProperty
curEnergyProp
=
this
.
getAvatar
().
getSkillDepot
().
getElementType
().
getCurEnergyProp
();
FightProperty
curEnergyProp
=
this
.
getAvatar
().
getSkillDepot
().
getElementType
().
getCurEnergyProp
();
this
.
setFightProp
er
t
y
(
curEnergyProp
,
0
);
this
.
avatar
.
setCurrentEn
er
g
y
(
curEnergyProp
,
0
);
this
.
getScene
().
broadcastPacket
(
new
PacketAvatarFightPropUpdateNotify
(
this
.
getAvatar
(),
curEnergyProp
));
this
.
getScene
().
broadcastPacket
(
new
PacketAvatarFightPropUpdateNotify
(
this
.
getAvatar
(),
curEnergyProp
));
this
.
getScene
().
broadcastPacket
(
new
PacketEntityFightPropChangeReasonNotify
(
this
,
curEnergyProp
,
0
f
,
reason
));
this
.
getScene
().
broadcastPacket
(
new
PacketEntityFightPropChangeReasonNotify
(
this
,
curEnergyProp
,
0
f
,
reason
));
...
@@ -158,7 +160,7 @@ public class EntityAvatar extends GameEntity {
...
@@ -158,7 +160,7 @@ public class EntityAvatar extends GameEntity {
// Set energy and notify.
// Set energy and notify.
if
(
newEnergy
!=
curEnergy
)
{
if
(
newEnergy
!=
curEnergy
)
{
this
.
setFightProp
er
t
y
(
curEnergyProp
,
newEnergy
);
this
.
avatar
.
setCurrentEn
er
g
y
(
curEnergyProp
,
newEnergy
);
this
.
getScene
().
broadcastPacket
(
new
PacketAvatarFightPropUpdateNotify
(
this
.
getAvatar
(),
curEnergyProp
));
this
.
getScene
().
broadcastPacket
(
new
PacketAvatarFightPropUpdateNotify
(
this
.
getAvatar
(),
curEnergyProp
));
this
.
getScene
().
broadcastPacket
(
new
PacketEntityFightPropChangeReasonNotify
(
this
,
curEnergyProp
,
newEnergy
,
reason
));
this
.
getScene
().
broadcastPacket
(
new
PacketEntityFightPropChangeReasonNotify
(
this
,
curEnergyProp
,
newEnergy
,
reason
));
...
...
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