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
28323fed
Commit
28323fed
authored
May 21, 2022
by
ImmuState
Committed by
Melledy
May 22, 2022
Browse files
Move energy-related logic to a new EnergyManager.
parent
1d2fde40
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/ability/AbilityManager.java
View file @
28323fed
...
@@ -147,93 +147,9 @@ public class AbilityManager {
...
@@ -147,93 +147,9 @@ public class AbilityManager {
AbilityMixinCostStamina
costStamina
=
AbilityMixinCostStamina
.
parseFrom
((
invoke
.
getAbilityData
()));
AbilityMixinCostStamina
costStamina
=
AbilityMixinCostStamina
.
parseFrom
((
invoke
.
getAbilityData
()));
getPlayer
().
getStaminaManager
().
handleMixinCostStamina
(
costStamina
.
getIsSwim
());
getPlayer
().
getStaminaManager
().
handleMixinCostStamina
(
costStamina
.
getIsSwim
());
}
}
private
int
getCastingAvatarIdForElemBall
(
int
invokeEntityId
)
{
// To determine the avatar that has cast the skill that caused the energy particle to be generated,
// we have to look at the entity that has invoked the ability. This can either be that avatar directly,
// or it can be an `EntityClientGadget`, owned (some way up the owner hierarchy) by the avatar
// that cast the skill.
int
res
=
0
;
// Try to get the invoking entity from the scene.
GameEntity
entity
=
player
.
getScene
().
getEntityById
(
invokeEntityId
);
// If this entity is null, or not an `EntityClientGadget`, we assume that we are directly
// looking at the casting avatar.
if
(!(
entity
instanceof
EntityClientGadget
))
{
res
=
invokeEntityId
;
}
// If the entity is a `EntityClientGadget`, we need to "walk up" the owner hierarchy,
// until the owner is no longer a gadget. This should then be the ID of the casting avatar.
else
{
while
(
entity
instanceof
EntityClientGadget
gadget
)
{
res
=
gadget
.
getOwnerEntityId
();
entity
=
player
.
getScene
().
getEntityById
(
gadget
.
getOwnerEntityId
());
}
}
return
res
;
}
private
void
handleGenerateElemBall
(
AbilityInvokeEntry
invoke
)
throws
InvalidProtocolBufferException
{
private
void
handleGenerateElemBall
(
AbilityInvokeEntry
invoke
)
throws
InvalidProtocolBufferException
{
// Get action info.
this
.
player
.
getEnergyManager
().
handleGenerateElemBall
(
invoke
);
AbilityActionGenerateElemBall
action
=
AbilityActionGenerateElemBall
.
parseFrom
(
invoke
.
getAbilityData
());
if
(
action
==
null
)
{
return
;
}
// Determine the element of the energy particle that we have to generate.
// In case we can't, we default to an elementless particle.
// The element is the element of the avatar that has cast the ability.
// We can get that from the avatar's skill depot.
int
itemId
=
2024
;
// Try to fetch the avatar from the player's party and determine their element.
// ToDo: Does this work in co-op?
int
avatarId
=
getCastingAvatarIdForElemBall
(
invoke
.
getEntityId
());
Optional
<
EntityAvatar
>
avatarEntity
=
player
.
getTeamManager
().
getActiveTeam
()
.
stream
()
.
filter
(
character
->
character
.
getId
()
==
avatarId
)
.
findFirst
();
if
(
avatarEntity
.
isPresent
())
{
Avatar
avatar
=
avatarEntity
.
get
().
getAvatar
();
if
(
avatar
!=
null
)
{
AvatarSkillDepotData
skillDepotData
=
avatar
.
getSkillDepot
();
if
(
skillDepotData
!=
null
)
{
ElementType
element
=
skillDepotData
.
getElementType
();
// If we found the element, we use it to deterine the ID of the
// energy particle that we have to generate.
if
(
element
!=
null
)
{
itemId
=
switch
(
element
)
{
case
Fire
->
2017
;
case
Water
->
2018
;
case
Grass
->
2019
;
case
Electric
->
2020
;
case
Wind
->
2021
;
case
Ice
->
2022
;
case
Rock
->
2023
;
default
->
2024
;
};
}
}
}
}
// Get the item data for an energy particle of the correct element.
ItemData
itemData
=
GameData
.
getItemDataMap
().
get
(
itemId
);
if
(
itemData
==
null
)
{
return
;
// Should never happen
}
// Generate entity.
EntityItem
energyBall
=
new
EntityItem
(
getPlayer
().
getScene
(),
getPlayer
(),
itemData
,
new
Position
(
action
.
getPos
()),
1
);
energyBall
.
getRotation
().
set
(
action
.
getRot
());
getPlayer
().
getScene
().
addEntity
(
energyBall
);
}
}
private
void
invokeAction
(
AbilityModifierAction
action
,
GameEntity
target
,
GameEntity
sourceEntity
)
{
private
void
invokeAction
(
AbilityModifierAction
action
,
GameEntity
target
,
GameEntity
sourceEntity
)
{
...
...
src/main/java/emu/grasscutter/game/avatar/Avatar.java
View file @
28323fed
...
@@ -16,6 +16,7 @@ import dev.morphia.annotations.Indexed;
...
@@ -16,6 +16,7 @@ import dev.morphia.annotations.Indexed;
import
dev.morphia.annotations.PostLoad
;
import
dev.morphia.annotations.PostLoad
;
import
dev.morphia.annotations.PrePersist
;
import
dev.morphia.annotations.PrePersist
;
import
dev.morphia.annotations.Transient
;
import
dev.morphia.annotations.Transient
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.common.FightPropData
;
import
emu.grasscutter.data.common.FightPropData
;
import
emu.grasscutter.data.custom.OpenConfigEntry
;
import
emu.grasscutter.data.custom.OpenConfigEntry
;
...
@@ -519,7 +520,7 @@ public class Avatar {
...
@@ -519,7 +520,7 @@ public class Avatar {
if
(
data
.
getSkillDepot
()
!=
null
&&
data
.
getSkillDepot
().
getEnergySkillData
()
!=
null
)
{
if
(
data
.
getSkillDepot
()
!=
null
&&
data
.
getSkillDepot
().
getEnergySkillData
()
!=
null
)
{
ElementType
element
=
data
.
getSkillDepot
().
getElementType
();
ElementType
element
=
data
.
getSkillDepot
().
getElementType
();
this
.
setFightProperty
(
element
.
getMaxEnergyProp
(),
data
.
getSkillDepot
().
getEnergySkillData
().
getCostElemVal
());
this
.
setFightProperty
(
element
.
getMaxEnergyProp
(),
data
.
getSkillDepot
().
getEnergySkillData
().
getCostElemVal
());
if
(
GAME_OPTIONS
.
energyUsage
)
{
if
(
GAME_OPTIONS
.
energyUsage
)
{
this
.
setFightProperty
(
element
.
getCurEnergyProp
(),
currentEnergy
);
this
.
setFightProperty
(
element
.
getCurEnergyProp
(),
currentEnergy
);
}
}
...
...
src/main/java/emu/grasscutter/game/entity/EntityAvatar.java
View file @
28323fed
...
@@ -129,13 +129,24 @@ public class EntityAvatar extends GameEntity {
...
@@ -129,13 +129,24 @@ public class EntityAvatar extends GameEntity {
return
healed
;
return
healed
;
}
}
public
void
addEnergy
(
float
amount
)
{
public
void
clearEnergy
(
PropChangeReason
reason
)
{
this
.
addEnergy
(
amount
,
false
);
FightProperty
curEnergyProp
=
this
.
getAvatar
().
getSkillDepot
().
getElementType
().
getCurEnergyProp
();
this
.
setFightProperty
(
curEnergyProp
,
0
);
this
.
getScene
().
broadcastPacket
(
new
PacketAvatarFightPropUpdateNotify
(
this
.
getAvatar
(),
curEnergyProp
));
this
.
getScene
().
broadcastPacket
(
new
PacketEntityFightPropChangeReasonNotify
(
this
,
curEnergyProp
,
0
f
,
reason
));
}
public
void
addEnergy
(
float
amount
,
PropChangeReason
reason
)
{
this
.
addEnergy
(
amount
,
reason
,
false
);
}
}
public
void
addEnergy
(
float
amount
,
boolean
isFlat
)
{
public
void
addEnergy
(
float
amount
,
PropChangeReason
reason
,
boolean
isFlat
)
{
// Get current and maximum energy for this avatar.
// Get current and maximum energy for this avatar.
FightProperty
curEnergyProp
=
getAvatar
().
getSkillDepot
().
getElementType
().
getCurEnergyProp
();
FightProperty
curEnergyProp
=
this
.
getAvatar
().
getSkillDepot
().
getElementType
().
getCurEnergyProp
();
FightProperty
maxEnergyProp
=
getAvatar
().
getSkillDepot
().
getElementType
().
getMaxEnergyProp
();
FightProperty
maxEnergyProp
=
this
.
getAvatar
().
getSkillDepot
().
getElementType
().
getMaxEnergyProp
();
float
curEnergy
=
this
.
getFightProperty
(
curEnergyProp
);
float
maxEnergy
=
this
.
getFightProperty
(
maxEnergyProp
);
// Get energy recharge.
// Get energy recharge.
float
energyRecharge
=
this
.
getFightProperty
(
FightProperty
.
FIGHT_PROP_CHARGE_EFFICIENCY
);
float
energyRecharge
=
this
.
getFightProperty
(
FightProperty
.
FIGHT_PROP_CHARGE_EFFICIENCY
);
...
@@ -146,16 +157,15 @@ public class EntityAvatar extends GameEntity {
...
@@ -146,16 +157,15 @@ public class EntityAvatar extends GameEntity {
}
}
// Determine the new energy value.
// Determine the new energy value.
float
curEnergy
=
this
.
getFightProperty
(
curEnergyProp
);
float
maxEnergy
=
this
.
getFightProperty
(
maxEnergyProp
);
float
newEnergy
=
Math
.
min
(
curEnergy
+
amount
,
maxEnergy
);
float
newEnergy
=
Math
.
min
(
curEnergy
+
amount
,
maxEnergy
);
// Set energy and notify.
// Set energy and notify.
Grasscutter
.
getLogger
().
info
(
"Giving {} energy to {} with {} maximum energy, resulting in {} total enery. Energy fight prop: {}"
,
amount
,
this
.
getAvatar
(),
maxEnergy
,
newEnergy
,
maxEnergyProp
);
if
(
newEnergy
!=
curEnergy
)
{
if
(
newEnergy
!=
curEnergy
)
{
setFightProperty
(
curEnergyProp
,
newEnergy
);
this
.
setFightProperty
(
curEnergyProp
,
newEnergy
);
getScene
().
broadcastPacket
(
new
PacketAvatarFightPropUpdateNotify
(
getAvatar
(),
curEnergyProp
));
this
.
getScene
().
broadcastPacket
(
new
PacketAvatarFightPropUpdateNotify
(
this
.
getAvatar
(),
curEnergyProp
));
getScene
().
broadcastPacket
(
new
PacketEntityFightPropChangeReasonNotify
(
this
,
curEnergyProp
,
newEnergy
,
PropChangeReason
.
PROP_CHANGE_ENERGY_BALL
));
this
.
getScene
().
broadcastPacket
(
new
PacketEntityFightPropChangeReasonNotify
(
this
,
curEnergyProp
,
newEnergy
,
reason
));
}
}
}
}
...
...
src/main/java/emu/grasscutter/game/inventory/Inventory.java
View file @
28323fed
...
@@ -182,7 +182,7 @@ public class Inventory implements Iterable<GameItem> {
...
@@ -182,7 +182,7 @@ public class Inventory implements Iterable<GameItem> {
this
.
addVirtualItem
(
item
.
getItemId
(),
item
.
getCount
());
this
.
addVirtualItem
(
item
.
getItemId
(),
item
.
getCount
());
return
item
;
return
item
;
}
else
if
(
item
.
getItemData
().
getMaterialType
()
==
MaterialType
.
MATERIAL_ADSORBATE
)
{
}
else
if
(
item
.
getItemData
().
getMaterialType
()
==
MaterialType
.
MATERIAL_ADSORBATE
)
{
player
.
get
Team
Manager
().
addEnergyToTeam
(
item
);
this
.
player
.
get
Energy
Manager
().
handlePickupElemBall
(
item
);
return
null
;
return
null
;
}
else
if
(
item
.
getItemData
().
getMaterialType
()
==
MaterialType
.
MATERIAL_AVATAR
)
{
}
else
if
(
item
.
getItemData
().
getMaterialType
()
==
MaterialType
.
MATERIAL_AVATAR
)
{
// Get avatar id
// Get avatar id
...
...
src/main/java/emu/grasscutter/game/managers/EnergyManager.java
0 → 100644
View file @
28323fed
package
emu.grasscutter.game.managers
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.def.AvatarSkillDepotData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.entity.EntityAvatar
;
import
emu.grasscutter.game.entity.EntityClientGadget
;
import
emu.grasscutter.game.entity.EntityItem
;
import
emu.grasscutter.game.entity.GameEntity
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.props.ElementType
;
import
emu.grasscutter.net.proto.AbilityActionGenerateElemBallOuterClass.AbilityActionGenerateElemBall
;
import
emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry
;
import
emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.utils.Position
;
import
static
emu
.
grasscutter
.
Configuration
.
GAME_OPTIONS
;
import
java.util.Optional
;
import
com.google.protobuf.InvalidProtocolBufferException
;
public
class
EnergyManager
{
private
final
Player
player
;
public
EnergyManager
(
Player
player
)
{
this
.
player
=
player
;
}
public
Player
getPlayer
()
{
return
this
.
player
;
}
/**********
Particle creation for elemental skills.
**********/
private
int
getCastingAvatarIdForElemBall
(
int
invokeEntityId
)
{
// To determine the avatar that has cast the skill that caused the energy particle to be generated,
// we have to look at the entity that has invoked the ability. This can either be that avatar directly,
// or it can be an `EntityClientGadget`, owned (some way up the owner hierarchy) by the avatar
// that cast the skill.
int
res
=
0
;
// Try to get the invoking entity from the scene.
GameEntity
entity
=
player
.
getScene
().
getEntityById
(
invokeEntityId
);
// If this entity is null, or not an `EntityClientGadget`, we assume that we are directly
// looking at the casting avatar.
if
(!(
entity
instanceof
EntityClientGadget
))
{
res
=
invokeEntityId
;
}
// If the entity is a `EntityClientGadget`, we need to "walk up" the owner hierarchy,
// until the owner is no longer a gadget. This should then be the ID of the casting avatar.
else
{
while
(
entity
instanceof
EntityClientGadget
gadget
)
{
res
=
gadget
.
getOwnerEntityId
();
entity
=
player
.
getScene
().
getEntityById
(
gadget
.
getOwnerEntityId
());
}
}
return
res
;
}
public
void
handleGenerateElemBall
(
AbilityInvokeEntry
invoke
)
throws
InvalidProtocolBufferException
{
// Get action info.
AbilityActionGenerateElemBall
action
=
AbilityActionGenerateElemBall
.
parseFrom
(
invoke
.
getAbilityData
());
if
(
action
==
null
)
{
return
;
}
// Determine the element of the energy particle that we have to generate.
// In case we can't, we default to an elementless particle.
// The element is the element of the avatar that has cast the ability.
// We can get that from the avatar's skill depot.
int
itemId
=
2024
;
// Try to fetch the avatar from the player's party and determine their element.
// ToDo: Does this work in co-op?
int
avatarId
=
getCastingAvatarIdForElemBall
(
invoke
.
getEntityId
());
Optional
<
EntityAvatar
>
avatarEntity
=
player
.
getTeamManager
().
getActiveTeam
()
.
stream
()
.
filter
(
character
->
character
.
getId
()
==
avatarId
)
.
findFirst
();
if
(
avatarEntity
.
isPresent
())
{
Avatar
avatar
=
avatarEntity
.
get
().
getAvatar
();
if
(
avatar
!=
null
)
{
AvatarSkillDepotData
skillDepotData
=
avatar
.
getSkillDepot
();
if
(
skillDepotData
!=
null
)
{
ElementType
element
=
skillDepotData
.
getElementType
();
// If we found the element, we use it to deterine the ID of the
// energy particle that we have to generate.
if
(
element
!=
null
)
{
itemId
=
switch
(
element
)
{
case
Fire
->
2017
;
case
Water
->
2018
;
case
Grass
->
2019
;
case
Electric
->
2020
;
case
Wind
->
2021
;
case
Ice
->
2022
;
case
Rock
->
2023
;
default
->
2024
;
};
}
}
}
}
// Get the item data for an energy particle of the correct element.
ItemData
itemData
=
GameData
.
getItemDataMap
().
get
(
itemId
);
if
(
itemData
==
null
)
{
return
;
// Should never happen
}
// Generate entity.
EntityItem
energyBall
=
new
EntityItem
(
getPlayer
().
getScene
(),
getPlayer
(),
itemData
,
new
Position
(
action
.
getPos
()),
1
);
energyBall
.
getRotation
().
set
(
action
.
getRot
());
this
.
getPlayer
().
getScene
().
addEntity
(
energyBall
);
}
/**********
Pickup of elemental particles and orbs.
**********/
public
void
handlePickupElemBall
(
GameItem
elemBall
)
{
// Check if the item is indeed an energy particle/orb.
if
(
elemBall
.
getItemId
()
<
2001
||
elemBall
.
getItemId
()
>
2024
)
{
return
;
}
// Determine the base amount of energy given by the particle/orb.
// Particles have a base amount of 1.0, and orbs a base amount of 3.0.
float
baseEnergy
=
(
elemBall
.
getItemId
()
<=
2008
)
?
3.0f
:
1.0f
;
// Add energy to every team member.
for
(
int
i
=
0
;
i
<
this
.
player
.
getTeamManager
().
getActiveTeam
().
size
();
i
++)
{
EntityAvatar
entity
=
this
.
player
.
getTeamManager
().
getActiveTeam
().
get
(
i
);
// On-field vs off-field multiplier.
float
offFieldPenalty
=
(
this
.
player
.
getTeamManager
().
getCurrentCharacterIndex
()
==
i
)
?
1.0f
:
1.0f
-
this
.
player
.
getTeamManager
().
getActiveTeam
().
size
()
*
0.1f
;
// Same element/neutral bonus.
ElementType
avatarElement
=
entity
.
getAvatar
().
getSkillDepot
().
getElementType
();
ElementType
ballElement
=
switch
(
elemBall
.
getItemId
())
{
case
2001
,
2017
->
ElementType
.
Fire
;
case
2002
,
2018
->
ElementType
.
Water
;
case
2003
,
2019
->
ElementType
.
Grass
;
case
2004
,
2020
->
ElementType
.
Electric
;
case
2005
,
2021
->
ElementType
.
Wind
;
case
2006
,
2022
->
ElementType
.
Ice
;
case
2007
,
2023
->
ElementType
.
Rock
;
default
->
null
;
};
float
elementBonus
=
(
ballElement
==
null
)
?
2.0f
:
(
avatarElement
==
ballElement
)
?
3.0f
:
1.0f
;
// Add the energy.
entity
.
addEnergy
(
baseEnergy
*
elementBonus
*
offFieldPenalty
,
PropChangeReason
.
PROP_CHANGE_ENERGY_BALL
);
}
}
/**********
Energy logic related to using skills.
**********/
private
void
handleBurstCast
(
Avatar
avatar
,
int
skillId
)
{
// Don't do anything if energy usage is disabled.
if
(!
GAME_OPTIONS
.
energyUsage
)
{
return
;
}
// If the cast skill was a burst, consume energy.
if
(
skillId
==
avatar
.
getSkillDepot
().
getEnergySkill
())
{
avatar
.
getAsEntity
().
clearEnergy
(
PropChangeReason
.
PROP_CHANGE_ABILITY
);
}
}
public
void
handleEvtDoSkillSuccNotify
(
GameSession
session
,
int
skillId
,
int
casterId
)
{
// Determine the entity that has cast the skill. Cancel if we can't find that avatar.
Optional
<
EntityAvatar
>
caster
=
this
.
player
.
getTeamManager
().
getActiveTeam
().
stream
()
.
filter
(
character
->
character
.
getId
()
==
casterId
)
.
findFirst
();
if
(
caster
.
isEmpty
())
{
return
;
}
Avatar
avatar
=
caster
.
get
().
getAvatar
();
// Handle elemental burst.
this
.
handleBurstCast
(
avatar
,
skillId
);
}
}
src/main/java/emu/grasscutter/game/player/Player.java
View file @
28323fed
...
@@ -24,6 +24,7 @@ import emu.grasscutter.game.inventory.Inventory;
...
@@ -24,6 +24,7 @@ import emu.grasscutter.game.inventory.Inventory;
import
emu.grasscutter.game.mail.Mail
;
import
emu.grasscutter.game.mail.Mail
;
import
emu.grasscutter.game.mail.MailHandler
;
import
emu.grasscutter.game.mail.MailHandler
;
import
emu.grasscutter.game.managers.StaminaManager.StaminaManager
;
import
emu.grasscutter.game.managers.StaminaManager.StaminaManager
;
import
emu.grasscutter.game.managers.EnergyManager
;
import
emu.grasscutter.game.managers.SotSManager
;
import
emu.grasscutter.game.managers.SotSManager
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.game.props.EntityType
;
import
emu.grasscutter.game.props.EntityType
;
...
@@ -144,6 +145,7 @@ public class Player {
...
@@ -144,6 +145,7 @@ public class Player {
@Transient
private
MapMarksManager
mapMarksManager
;
@Transient
private
MapMarksManager
mapMarksManager
;
@Transient
private
StaminaManager
staminaManager
;
@Transient
private
StaminaManager
staminaManager
;
@Transient
private
EnergyManager
energyManager
;
private
long
springLastUsed
;
private
long
springLastUsed
;
private
HashMap
<
String
,
MapMark
>
mapMarks
;
private
HashMap
<
String
,
MapMark
>
mapMarks
;
...
@@ -194,6 +196,7 @@ public class Player {
...
@@ -194,6 +196,7 @@ public class Player {
this
.
mapMarksManager
=
new
MapMarksManager
(
this
);
this
.
mapMarksManager
=
new
MapMarksManager
(
this
);
this
.
staminaManager
=
new
StaminaManager
(
this
);
this
.
staminaManager
=
new
StaminaManager
(
this
);
this
.
sotsManager
=
new
SotSManager
(
this
);
this
.
sotsManager
=
new
SotSManager
(
this
);
this
.
energyManager
=
new
EnergyManager
(
this
);
}
}
// On player creation
// On player creation
...
@@ -222,6 +225,7 @@ public class Player {
...
@@ -222,6 +225,7 @@ public class Player {
this
.
mapMarksManager
=
new
MapMarksManager
(
this
);
this
.
mapMarksManager
=
new
MapMarksManager
(
this
);
this
.
staminaManager
=
new
StaminaManager
(
this
);
this
.
staminaManager
=
new
StaminaManager
(
this
);
this
.
sotsManager
=
new
SotSManager
(
this
);
this
.
sotsManager
=
new
SotSManager
(
this
);
this
.
energyManager
=
new
EnergyManager
(
this
);
}
}
public
int
getUid
()
{
public
int
getUid
()
{
...
@@ -1088,6 +1092,10 @@ public class Player {
...
@@ -1088,6 +1092,10 @@ public class Player {
public
SotSManager
getSotSManager
()
{
return
sotsManager
;
}
public
SotSManager
getSotSManager
()
{
return
sotsManager
;
}
public
EnergyManager
getEnergyManager
()
{
return
this
.
energyManager
;
}
public
AbilityManager
getAbilityManager
()
{
public
AbilityManager
getAbilityManager
()
{
return
abilityManager
;
return
abilityManager
;
}
}
...
...
src/main/java/emu/grasscutter/game/player/TeamManager.java
View file @
28323fed
...
@@ -4,13 +4,11 @@ import java.util.*;
...
@@ -4,13 +4,11 @@ import java.util.*;
import
dev.morphia.annotations.Entity
;
import
dev.morphia.annotations.Entity
;
import
dev.morphia.annotations.Transient
;
import
dev.morphia.annotations.Transient
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.GameConstants
;
import
emu.grasscutter.GameConstants
;
import
emu.grasscutter.data.def.AvatarSkillDepotData
;
import
emu.grasscutter.data.def.AvatarSkillDepotData
;
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.entity.EntityBaseGadget
;
import
emu.grasscutter.game.entity.EntityBaseGadget
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.props.ElementType
;
import
emu.grasscutter.game.props.ElementType
;
import
emu.grasscutter.game.props.EnterReason
;
import
emu.grasscutter.game.props.EnterReason
;
import
emu.grasscutter.game.props.FightProperty
;
import
emu.grasscutter.game.props.FightProperty
;
...
@@ -20,7 +18,6 @@ import emu.grasscutter.net.packet.PacketOpcodes;
...
@@ -20,7 +18,6 @@ import emu.grasscutter.net.packet.PacketOpcodes;
import
emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType
;
import
emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType
;
import
emu.grasscutter.net.proto.MotionStateOuterClass.MotionState
;
import
emu.grasscutter.net.proto.MotionStateOuterClass.MotionState
;
import
emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType
;
import
emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketAvatarDieAnimationEndRsp
;
import
emu.grasscutter.server.packet.send.PacketAvatarDieAnimationEndRsp
;
import
emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify
;
import
emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify
;
...
@@ -583,63 +580,6 @@ public class TeamManager {
...
@@ -583,63 +580,6 @@ public class TeamManager {
// Packets
// Packets
getPlayer
().
sendPacket
(
new
BasePacket
(
PacketOpcodes
.
WorldPlayerReviveRsp
));
getPlayer
().
sendPacket
(
new
BasePacket
(
PacketOpcodes
.
WorldPlayerReviveRsp
));
}
}
public
synchronized
void
addEnergyToTeam
(
GameItem
energyBall
)
{
// Check if the item is indeed an energy particle/orb.
if
(
energyBall
.
getItemId
()
<
2001
||
energyBall
.
getItemId
()
>
2024
)
{
return
;
}
// Determine the base amount of energy given by the particle/orb.
// Particles have a base amount of 1.0, and orbs a base amount of 3.0.
float
baseEnergy
=
(
energyBall
.
getItemId
()
<=
2008
)
?
3.0f
:
1.0f
;
// Add energy to every team member.
for
(
int
i
=
0
;
i
<
this
.
getActiveTeam
().
size
();
i
++)
{
EntityAvatar
entity
=
this
.
getActiveTeam
().
get
(
i
);
// On-field vs off-field multiplier.
float
offFieldPenalty
=
(
this
.
getCurrentCharacterIndex
()
==
i
)
?
1.0f
:
1.0f
-
this
.
getActiveTeam
().
size
()
*
0.1f
;
// Same element/neutral bonus.
ElementType
avatarElement
=
entity
.
getAvatar
().
getSkillDepot
().
getElementType
();
ElementType
ballElement
=
switch
(
energyBall
.
getItemId
())
{
case
2001
,
2017
->
ElementType
.
Fire
;
case
2002
,
2018
->
ElementType
.
Water
;
case
2003
,
2019
->
ElementType
.
Grass
;
case
2004
,
2020
->
ElementType
.
Electric
;
case
2005
,
2021
->
ElementType
.
Wind
;
case
2006
,
2022
->
ElementType
.
Ice
;
case
2007
,
2023
->
ElementType
.
Rock
;
default
->
null
;
};
float
elementBonus
=
(
ballElement
==
null
)
?
2.0f
:
(
avatarElement
==
ballElement
)
?
3.0f
:
1.0f
;
// Add the energy.
entity
.
addEnergy
(
baseEnergy
*
elementBonus
*
offFieldPenalty
);
}
}
public
void
handleEvtDoSkillSuccNotify
(
GameSession
session
,
int
skillId
,
int
casterId
)
{
if
(!
GAME_OPTIONS
.
energyUsage
)
{
return
;
}
// Determine the entity that has cast the skill.
Optional
<
EntityAvatar
>
caster
=
this
.
getActiveTeam
().
stream
()
.
filter
(
character
->
character
.
getId
()
==
casterId
)
.
findFirst
();
if
(
caster
.
isEmpty
())
{
return
;
}
Avatar
avatar
=
caster
.
get
().
getAvatar
();
// If the cast skill was a burst, consume energy.
if
(
skillId
==
avatar
.
getSkillDepot
().
getEnergySkill
())
{
float
consumedEnergy
=
avatar
.
getFightProperty
(
avatar
.
getSkillDepot
().
getElementType
().
getCurEnergyProp
());
avatar
.
getAsEntity
().
addEnergy
(-
consumedEnergy
,
true
);
}
}
public
void
saveAvatars
()
{
public
void
saveAvatars
()
{
// Save all avatars from active team
// Save all avatars from active team
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtDoSkillSuccNotify.java
View file @
28323fed
...
@@ -4,9 +4,7 @@ import emu.grasscutter.net.packet.Opcodes;
...
@@ -4,9 +4,7 @@ import emu.grasscutter.net.packet.Opcodes;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.EvtDoSkillSuccNotifyOuterClass.EvtDoSkillSuccNotify
;
import
emu.grasscutter.net.proto.EvtDoSkillSuccNotifyOuterClass.EvtDoSkillSuccNotify
;
import
emu.grasscutter.net.proto.VectorOuterClass.Vector
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.utils.Position
;
@Opcodes
(
PacketOpcodes
.
EvtDoSkillSuccNotify
)
@Opcodes
(
PacketOpcodes
.
EvtDoSkillSuccNotify
)
public
class
HandlerEvtDoSkillSuccNotify
extends
PacketHandler
{
public
class
HandlerEvtDoSkillSuccNotify
extends
PacketHandler
{
...
@@ -16,9 +14,8 @@ public class HandlerEvtDoSkillSuccNotify extends PacketHandler {
...
@@ -16,9 +14,8 @@ public class HandlerEvtDoSkillSuccNotify extends PacketHandler {
EvtDoSkillSuccNotify
notify
=
EvtDoSkillSuccNotify
.
parseFrom
(
payload
);
EvtDoSkillSuccNotify
notify
=
EvtDoSkillSuccNotify
.
parseFrom
(
payload
);
int
skillId
=
notify
.
getSkillId
();
int
skillId
=
notify
.
getSkillId
();
int
casterId
=
notify
.
getCasterId
();
int
casterId
=
notify
.
getCasterId
();
Vector
forwardVector
=
notify
.
getForward
();
Position
forward
=
new
Position
(
forwardVector
.
getX
(),
forwardVector
.
getY
(),
forwardVector
.
getZ
());
session
.
getPlayer
().
getStaminaManager
().
handleEvtDoSkillSuccNotify
(
session
,
skillId
,
casterId
);
session
.
getPlayer
().
getStaminaManager
().
handleEvtDoSkillSuccNotify
(
session
,
skillId
,
casterId
);
session
.
getPlayer
().
get
Team
Manager
().
handleEvtDoSkillSuccNotify
(
session
,
skillId
,
casterId
);
session
.
getPlayer
().
get
Energy
Manager
().
handleEvtDoSkillSuccNotify
(
session
,
skillId
,
casterId
);
}
}
}
}
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