mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-02-05 18:53:22 +08:00
add new command (unlimitenergy):toggle energyusage for each player (#1186)
* add new command (unlimitenergy):toggle energyusage for each player while energyusage is ture in config.json * Solve the problem of layout and naming errors * make currentActiveTeam's Avatar full-energy while turn on the ule. * Resolve language document errors * add config_error message while player try to execute UnlimitEnergyCommand in GAME_OPTIONS.energyUsage == false
This commit is contained in:
parent
d4bb7c95b6
commit
36fb08095f
@ -0,0 +1,55 @@
|
|||||||
|
package emu.grasscutter.command.commands;
|
||||||
|
|
||||||
|
import emu.grasscutter.Grasscutter;
|
||||||
|
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.EnergyManager.EnergyManager;
|
||||||
|
import emu.grasscutter.game.player.Player;
|
||||||
|
import emu.grasscutter.game.player.TeamManager;
|
||||||
|
import emu.grasscutter.game.props.ElementType;
|
||||||
|
import emu.grasscutter.net.proto.PropChangeReasonOuterClass;
|
||||||
|
import emu.grasscutter.utils.Position;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static emu.grasscutter.Configuration.GAME_OPTIONS;
|
||||||
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
|
@Command(label = "unlimitenergy", usage = "unlimitenergy [on|off|toggle]", aliases = {"ule"}, permission = "player.unlimitenergy", permissionTargeted = "player.unlimitenergy.others", description = "commands.unlimitenergy.description")
|
||||||
|
public final class UnlimitEnergyCommand implements CommandHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||||
|
if(!GAME_OPTIONS.energyUsage){
|
||||||
|
CommandHandler.sendMessage(sender, translate(sender, "commands.unlimitenergy.config_error"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Boolean status = targetPlayer.getEnergyManager().getEnergyUsage();
|
||||||
|
if (args.size() == 1) {
|
||||||
|
switch (args.get(0).toLowerCase()) {
|
||||||
|
case "on":
|
||||||
|
status = true;
|
||||||
|
break;
|
||||||
|
case "off":
|
||||||
|
status = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
status = !status;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EnergyManager energyManager=targetPlayer.getEnergyManager();
|
||||||
|
energyManager.setEnergyUsage(!status);
|
||||||
|
// if unlimitEnergy is enable , make currentActiveTeam's Avatar full-energy
|
||||||
|
if (status) {
|
||||||
|
for (EntityAvatar entityAvatar : targetPlayer.getTeamManager().getActiveTeam()) {
|
||||||
|
entityAvatar.addEnergy(1000,
|
||||||
|
PropChangeReasonOuterClass.PropChangeReason.PROP_CHANGE_REASON_GM,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandHandler.sendMessage(sender, translate(sender, "commands.unlimitenergy.success", (status ? translate(sender, "commands.status.enabled") : translate(sender, "commands.status.disabled")), targetPlayer.getNickname()));
|
||||||
|
}
|
||||||
|
}
|
@ -46,394 +46,404 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
|
||||||
public class EnergyManager {
|
public class EnergyManager {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final Map<EntityAvatar, Integer> avatarNormalProbabilities;
|
private final Map<EntityAvatar, Integer> avatarNormalProbabilities;
|
||||||
|
// energyUsage for each player
|
||||||
private final static Int2ObjectMap<List<EnergyDropInfo>> energyDropData = new Int2ObjectOpenHashMap<>();
|
private Boolean energyUsage;
|
||||||
private final static Int2ObjectMap<List<SkillParticleGenerationInfo>> skillParticleGenerationData = new Int2ObjectOpenHashMap<>();
|
private final static Int2ObjectMap<List<EnergyDropInfo>> energyDropData = new Int2ObjectOpenHashMap<>();
|
||||||
|
private final static Int2ObjectMap<List<SkillParticleGenerationInfo>> skillParticleGenerationData = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
public EnergyManager(Player player) {
|
public EnergyManager(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.avatarNormalProbabilities = new HashMap<>();
|
this.avatarNormalProbabilities = new HashMap<>();
|
||||||
}
|
this.energyUsage=GAME_OPTIONS.energyUsage;
|
||||||
|
}
|
||||||
|
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
// Read the data we need for monster energy drops.
|
// Read the data we need for monster energy drops.
|
||||||
try (Reader fileReader = new InputStreamReader(DataLoader.load("EnergyDrop.json"))) {
|
try (Reader fileReader = new InputStreamReader(DataLoader.load("EnergyDrop.json"))) {
|
||||||
List<EnergyDropEntry> energyDropList = Grasscutter.getGsonFactory().fromJson(fileReader, TypeToken.getParameterized(Collection.class, EnergyDropEntry.class).getType());
|
List<EnergyDropEntry> energyDropList = Grasscutter.getGsonFactory().fromJson(fileReader, TypeToken.getParameterized(Collection.class, EnergyDropEntry.class).getType());
|
||||||
|
|
||||||
for (EnergyDropEntry entry : energyDropList) {
|
for (EnergyDropEntry entry : energyDropList) {
|
||||||
energyDropData.put(entry.getDropId(), entry.getDropList());
|
energyDropData.put(entry.getDropId(), entry.getDropList());
|
||||||
}
|
}
|
||||||
|
|
||||||
Grasscutter.getLogger().info("Energy drop data successfully loaded.");
|
Grasscutter.getLogger().info("Energy drop data successfully loaded.");
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Grasscutter.getLogger().error("Unable to load energy drop data.", ex);
|
Grasscutter.getLogger().error("Unable to load energy drop data.", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the data for particle generation from skills
|
// Read the data for particle generation from skills
|
||||||
try (Reader fileReader = new InputStreamReader(DataLoader.load("SkillParticleGeneration.json"))) {
|
try (Reader fileReader = new InputStreamReader(DataLoader.load("SkillParticleGeneration.json"))) {
|
||||||
List<SkillParticleGenerationEntry> skillParticleGenerationList = Grasscutter.getGsonFactory().fromJson(fileReader, TypeToken.getParameterized(Collection.class, SkillParticleGenerationEntry.class).getType());
|
List<SkillParticleGenerationEntry> skillParticleGenerationList = Grasscutter.getGsonFactory().fromJson(fileReader, TypeToken.getParameterized(Collection.class, SkillParticleGenerationEntry.class).getType());
|
||||||
|
|
||||||
for (SkillParticleGenerationEntry entry : skillParticleGenerationList) {
|
for (SkillParticleGenerationEntry entry : skillParticleGenerationList) {
|
||||||
skillParticleGenerationData.put(entry.getAvatarId(), entry.getAmountList());
|
skillParticleGenerationData.put(entry.getAvatarId(), entry.getAmountList());
|
||||||
}
|
}
|
||||||
|
|
||||||
Grasscutter.getLogger().info("Skill particle generation data successfully loaded.");
|
Grasscutter.getLogger().info("Skill particle generation data successfully loaded.");
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Grasscutter.getLogger().error("Unable to load skill particle generation data data.", ex);
|
Grasscutter.getLogger().error("Unable to load skill particle generation data data.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********
|
/**********
|
||||||
Particle creation for elemental skills.
|
Particle creation for elemental skills.
|
||||||
**********/
|
**********/
|
||||||
private int getBallCountForAvatar(int avatarId) {
|
private int getBallCountForAvatar(int avatarId) {
|
||||||
// We default to two particles.
|
// We default to two particles.
|
||||||
int count = 2;
|
int count = 2;
|
||||||
|
|
||||||
// If we don't have any data for this avatar, stop.
|
// If we don't have any data for this avatar, stop.
|
||||||
if (!skillParticleGenerationData.containsKey(avatarId)) {
|
if (!skillParticleGenerationData.containsKey(avatarId)) {
|
||||||
Grasscutter.getLogger().warn("No particle generation data for avatarId {} found.", avatarId);
|
Grasscutter.getLogger().warn("No particle generation data for avatarId {} found.", avatarId);
|
||||||
}
|
}
|
||||||
// If we do have data, roll for how many particles we should generate.
|
// If we do have data, roll for how many particles we should generate.
|
||||||
else {
|
else {
|
||||||
int roll = ThreadLocalRandom.current().nextInt(0, 100);
|
int roll = ThreadLocalRandom.current().nextInt(0, 100);
|
||||||
int percentageStack = 0;
|
int percentageStack = 0;
|
||||||
for (SkillParticleGenerationInfo info : skillParticleGenerationData.get(avatarId)) {
|
for (SkillParticleGenerationInfo info : skillParticleGenerationData.get(avatarId)) {
|
||||||
int chance = info.getChance();
|
int chance = info.getChance();
|
||||||
percentageStack += chance;
|
percentageStack += chance;
|
||||||
if (roll < percentageStack) {
|
if (roll < percentageStack) {
|
||||||
count = info.getValue();
|
count = info.getValue();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done.
|
// Done.
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getBallIdForElement(ElementType element) {
|
private int getBallIdForElement(ElementType element) {
|
||||||
// If we have no element, we default to an elementless particle.
|
// If we have no element, we default to an elementless particle.
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
return 2024;
|
return 2024;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we determin the particle's ID based on the element.
|
// Otherwise, we determin the particle's ID based on the element.
|
||||||
return switch (element) {
|
return switch (element) {
|
||||||
case Fire -> 2017;
|
case Fire -> 2017;
|
||||||
case Water -> 2018;
|
case Water -> 2018;
|
||||||
case Grass -> 2019;
|
case Grass -> 2019;
|
||||||
case Electric -> 2020;
|
case Electric -> 2020;
|
||||||
case Wind -> 2021;
|
case Wind -> 2021;
|
||||||
case Ice -> 2022;
|
case Ice -> 2022;
|
||||||
case Rock -> 2023;
|
case Rock -> 2023;
|
||||||
default -> 2024;
|
default -> 2024;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleGenerateElemBall(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
|
public void handleGenerateElemBall(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
|
||||||
// ToDo:
|
// ToDo:
|
||||||
// This is also called when a weapon like Favonius Warbow etc. creates energy through its passive.
|
// This is also called when a weapon like Favonius Warbow etc. creates energy through its passive.
|
||||||
// We are not handling this correctly at the moment.
|
// We are not handling this correctly at the moment.
|
||||||
|
|
||||||
// Get action info.
|
// Get action info.
|
||||||
AbilityActionGenerateElemBall action = AbilityActionGenerateElemBall.parseFrom(invoke.getAbilityData());
|
AbilityActionGenerateElemBall action = AbilityActionGenerateElemBall.parseFrom(invoke.getAbilityData());
|
||||||
if (action == null) {
|
if (action == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to an elementless particle.
|
// Default to an elementless particle.
|
||||||
int itemId = 2024;
|
int itemId = 2024;
|
||||||
|
|
||||||
// Generate 2 particles by default.
|
// Generate 2 particles by default.
|
||||||
int amount = 2;
|
int amount = 2;
|
||||||
|
|
||||||
// Try to get the casting avatar from the player's party.
|
// Try to get the casting avatar from the player's party.
|
||||||
Optional<EntityAvatar> avatarEntity = getCastingAvatarEntityForEnergy(invoke.getEntityId());
|
Optional<EntityAvatar> avatarEntity = getCastingAvatarEntityForEnergy(invoke.getEntityId());
|
||||||
|
|
||||||
// Bug: invokes twice sometimes, Ayato, Keqing
|
// Bug: invokes twice sometimes, Ayato, Keqing
|
||||||
// ToDo: deal with press, hold difference. deal with charge(Beidou, Yunjin)
|
// ToDo: deal with press, hold difference. deal with charge(Beidou, Yunjin)
|
||||||
if (avatarEntity.isPresent()) {
|
if (avatarEntity.isPresent()) {
|
||||||
Avatar avatar = avatarEntity.get().getAvatar();
|
Avatar avatar = avatarEntity.get().getAvatar();
|
||||||
|
|
||||||
if (avatar != null) {
|
if (avatar != null) {
|
||||||
int avatarId = avatar.getAvatarId();
|
int avatarId = avatar.getAvatarId();
|
||||||
AvatarSkillDepotData skillDepotData = avatar.getSkillDepot();
|
AvatarSkillDepotData skillDepotData = avatar.getSkillDepot();
|
||||||
|
|
||||||
// Determine how many particles we need to create for this avatar.
|
// Determine how many particles we need to create for this avatar.
|
||||||
amount = this.getBallCountForAvatar(avatarId);
|
amount = this.getBallCountForAvatar(avatarId);
|
||||||
|
|
||||||
// Determine the avatar's element, and based on that the ID of the
|
// Determine the avatar's element, and based on that the ID of the
|
||||||
// particles we have to generate.
|
// particles we have to generate.
|
||||||
if (skillDepotData != null) {
|
if (skillDepotData != null) {
|
||||||
ElementType element = skillDepotData.getElementType();
|
ElementType element = skillDepotData.getElementType();
|
||||||
itemId = getBallIdForElement(element);
|
itemId = getBallIdForElement(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the particles.
|
// Generate the particles.
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
generateElemBall(itemId, new Position(action.getPos()), 1);
|
generateElemBall(itemId, new Position(action.getPos()), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********
|
/**********
|
||||||
Pickup of elemental particles and orbs.
|
Pickup of elemental particles and orbs.
|
||||||
**********/
|
**********/
|
||||||
public void handlePickupElemBall(GameItem elemBall) {
|
public void handlePickupElemBall(GameItem elemBall) {
|
||||||
// Check if the item is indeed an energy particle/orb.
|
// Check if the item is indeed an energy particle/orb.
|
||||||
if (elemBall.getItemId() < 2001 ||elemBall.getItemId() > 2024) {
|
if (elemBall.getItemId() < 2001 ||elemBall.getItemId() > 2024) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the base amount of energy given by the particle/orb.
|
// 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.
|
// 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;
|
float baseEnergy = (elemBall.getItemId() <= 2008) ? 3.0f : 1.0f;
|
||||||
|
|
||||||
// Add energy to every team member.
|
// Add energy to every team member.
|
||||||
for (int i = 0; i < this.player.getTeamManager().getActiveTeam().size(); i++) {
|
for (int i = 0; i < this.player.getTeamManager().getActiveTeam().size(); i++) {
|
||||||
EntityAvatar entity = this.player.getTeamManager().getActiveTeam().get(i);
|
EntityAvatar entity = this.player.getTeamManager().getActiveTeam().get(i);
|
||||||
|
|
||||||
// On-field vs off-field multiplier.
|
// On-field vs off-field multiplier.
|
||||||
// The on-field character gets no penalty.
|
// The on-field character gets no penalty.
|
||||||
// Off-field characters get a penalty depending on the team size, as follows:
|
// Off-field characters get a penalty depending on the team size, as follows:
|
||||||
// - 2 character team: 0.8
|
// - 2 character team: 0.8
|
||||||
// - 3 character team: 0.7
|
// - 3 character team: 0.7
|
||||||
// - 4 character team: 0.6
|
// - 4 character team: 0.6
|
||||||
// - etc.
|
// - etc.
|
||||||
// We set a lower bound of 0.1 here, to avoid gaining no or negative energy.
|
// We set a lower bound of 0.1 here, to avoid gaining no or negative energy.
|
||||||
float offFieldPenalty =
|
float offFieldPenalty =
|
||||||
(this.player.getTeamManager().getCurrentCharacterIndex() == i)
|
(this.player.getTeamManager().getCurrentCharacterIndex() == i)
|
||||||
? 1.0f
|
? 1.0f
|
||||||
: 1.0f - this.player.getTeamManager().getActiveTeam().size() * 0.1f;
|
: 1.0f - this.player.getTeamManager().getActiveTeam().size() * 0.1f;
|
||||||
offFieldPenalty = Math.max(offFieldPenalty, 0.1f);
|
offFieldPenalty = Math.max(offFieldPenalty, 0.1f);
|
||||||
|
|
||||||
// Same element/neutral bonus.
|
// Same element/neutral bonus.
|
||||||
// Same-element characters get a bonus of *3, while different-element characters get no bonus at all.
|
// Same-element characters get a bonus of *3, while different-element characters get no bonus at all.
|
||||||
// For neutral particles/orbs, the multiplier is always *2.
|
// For neutral particles/orbs, the multiplier is always *2.
|
||||||
if (entity.getAvatar().getSkillDepot() == null) {
|
if (entity.getAvatar().getSkillDepot() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementType avatarElement = entity.getAvatar().getSkillDepot().getElementType();
|
ElementType avatarElement = entity.getAvatar().getSkillDepot().getElementType();
|
||||||
ElementType ballElement = switch (elemBall.getItemId()) {
|
ElementType ballElement = switch (elemBall.getItemId()) {
|
||||||
case 2001, 2017 -> ElementType.Fire;
|
case 2001, 2017 -> ElementType.Fire;
|
||||||
case 2002, 2018 -> ElementType.Water;
|
case 2002, 2018 -> ElementType.Water;
|
||||||
case 2003, 2019 -> ElementType.Grass;
|
case 2003, 2019 -> ElementType.Grass;
|
||||||
case 2004, 2020 -> ElementType.Electric;
|
case 2004, 2020 -> ElementType.Electric;
|
||||||
case 2005, 2021 -> ElementType.Wind;
|
case 2005, 2021 -> ElementType.Wind;
|
||||||
case 2006, 2022 -> ElementType.Ice;
|
case 2006, 2022 -> ElementType.Ice;
|
||||||
case 2007, 2023 -> ElementType.Rock;
|
case 2007, 2023 -> ElementType.Rock;
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
|
|
||||||
float elementBonus = (ballElement == null) ? 2.0f : (avatarElement == ballElement) ? 3.0f : 1.0f;
|
float elementBonus = (ballElement == null) ? 2.0f : (avatarElement == ballElement) ? 3.0f : 1.0f;
|
||||||
|
|
||||||
// Add the energy.
|
// Add the energy.
|
||||||
entity.addEnergy(baseEnergy * elementBonus * offFieldPenalty * elemBall.getCount(), PropChangeReason.PROP_CHANGE_REASON_ENERGY_BALL);
|
entity.addEnergy(baseEnergy * elementBonus * offFieldPenalty * elemBall.getCount(), PropChangeReason.PROP_CHANGE_REASON_ENERGY_BALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********
|
/**********
|
||||||
Energy generation for NAs/CAs.
|
Energy generation for NAs/CAs.
|
||||||
**********/
|
**********/
|
||||||
private void generateEnergyForNormalAndCharged(EntityAvatar avatar) {
|
private void generateEnergyForNormalAndCharged(EntityAvatar avatar) {
|
||||||
// This logic is based on the descriptions given in
|
// This logic is based on the descriptions given in
|
||||||
// https://genshin-impact.fandom.com/wiki/Energy#Energy_Generated_by_Normal_Attacks
|
// https://genshin-impact.fandom.com/wiki/Energy#Energy_Generated_by_Normal_Attacks
|
||||||
// https://library.keqingmains.com/combat-mechanics/energy#auto-attacking
|
// https://library.keqingmains.com/combat-mechanics/energy#auto-attacking
|
||||||
// Those descriptions are lacking in some information, so this implementation most likely
|
// Those descriptions are lacking in some information, so this implementation most likely
|
||||||
// does not fully replicate the behavior of the official server. Open questions:
|
// does not fully replicate the behavior of the official server. Open questions:
|
||||||
// - Does the probability for a character reset after some time?
|
// - Does the probability for a character reset after some time?
|
||||||
// - Does the probability for a character reset when switching them out?
|
// - Does the probability for a character reset when switching them out?
|
||||||
// - Does this really count every individual hit separately?
|
// - Does this really count every individual hit separately?
|
||||||
|
|
||||||
// Get the avatar's weapon type.
|
// Get the avatar's weapon type.
|
||||||
WeaponType weaponType = avatar.getAvatar().getAvatarData().getWeaponType();
|
WeaponType weaponType = avatar.getAvatar().getAvatarData().getWeaponType();
|
||||||
|
|
||||||
// Check if we already have probability data for this avatar. If not, insert it.
|
// Check if we already have probability data for this avatar. If not, insert it.
|
||||||
if (!this.avatarNormalProbabilities.containsKey(avatar)) {
|
if (!this.avatarNormalProbabilities.containsKey(avatar)) {
|
||||||
this.avatarNormalProbabilities.put(avatar, weaponType.getEnergyGainInitialProbability());
|
this.avatarNormalProbabilities.put(avatar, weaponType.getEnergyGainInitialProbability());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Roll for energy.
|
// Roll for energy.
|
||||||
int currentProbability = this.avatarNormalProbabilities.get(avatar);
|
int currentProbability = this.avatarNormalProbabilities.get(avatar);
|
||||||
int roll = ThreadLocalRandom.current().nextInt(0, 100);
|
int roll = ThreadLocalRandom.current().nextInt(0, 100);
|
||||||
|
|
||||||
// If the player wins the roll, we increase the avatar's energy and reset the probability.
|
// If the player wins the roll, we increase the avatar's energy and reset the probability.
|
||||||
if (roll < currentProbability) {
|
if (roll < currentProbability) {
|
||||||
avatar.addEnergy(1.0f, PropChangeReason.PROP_CHANGE_REASON_ABILITY, true);
|
avatar.addEnergy(1.0f, PropChangeReason.PROP_CHANGE_REASON_ABILITY, true);
|
||||||
this.avatarNormalProbabilities.put(avatar, weaponType.getEnergyGainInitialProbability());
|
this.avatarNormalProbabilities.put(avatar, weaponType.getEnergyGainInitialProbability());
|
||||||
}
|
}
|
||||||
// Otherwise, we increase the probability for the next hit.
|
// Otherwise, we increase the probability for the next hit.
|
||||||
else {
|
else {
|
||||||
this.avatarNormalProbabilities.put(avatar, currentProbability + weaponType.getEnergyGainIncreaseProbability());
|
this.avatarNormalProbabilities.put(avatar, currentProbability + weaponType.getEnergyGainIncreaseProbability());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleAttackHit(EvtBeingHitInfo hitInfo) {
|
public void handleAttackHit(EvtBeingHitInfo hitInfo) {
|
||||||
// Get the attack result.
|
// Get the attack result.
|
||||||
AttackResult attackRes = hitInfo.getAttackResult();
|
AttackResult attackRes = hitInfo.getAttackResult();
|
||||||
|
|
||||||
// Make sure the attack was performed by the currently active avatar. If not, we ignore the hit.
|
// Make sure the attack was performed by the currently active avatar. If not, we ignore the hit.
|
||||||
Optional<EntityAvatar> attackerEntity = this.getCastingAvatarEntityForEnergy(attackRes.getAttackerId());
|
Optional<EntityAvatar> attackerEntity = this.getCastingAvatarEntityForEnergy(attackRes.getAttackerId());
|
||||||
if (attackerEntity.isEmpty() || this.player.getTeamManager().getCurrentAvatarEntity().getId() != attackerEntity.get().getId()) {
|
if (attackerEntity.isEmpty() || this.player.getTeamManager().getCurrentAvatarEntity().getId() != attackerEntity.get().getId()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the target is an actual enemy.
|
// Make sure the target is an actual enemy.
|
||||||
GameEntity targetEntity = this.player.getScene().getEntityById(attackRes.getDefenseId());
|
GameEntity targetEntity = this.player.getScene().getEntityById(attackRes.getDefenseId());
|
||||||
if (!(targetEntity instanceof EntityMonster)) {
|
if (!(targetEntity instanceof EntityMonster)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityMonster targetMonster = (EntityMonster)targetEntity;
|
EntityMonster targetMonster = (EntityMonster)targetEntity;
|
||||||
MonsterType targetType = targetMonster.getMonsterData().getType();
|
MonsterType targetType = targetMonster.getMonsterData().getType();
|
||||||
if (targetType != MonsterType.MONSTER_ORDINARY && targetType != MonsterType.MONSTER_BOSS) {
|
if (targetType != MonsterType.MONSTER_ORDINARY && targetType != MonsterType.MONSTER_BOSS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the ability that caused this hit.
|
|
||||||
AbilityIdentifier ability = attackRes.getAbilityIdentifier();
|
|
||||||
|
|
||||||
// Make sure there is no actual "ability" associated with the hit. For now, this is how we
|
// Get the ability that caused this hit.
|
||||||
// identify normal and charged attacks. Note that this is not completely accurate:
|
AbilityIdentifier ability = attackRes.getAbilityIdentifier();
|
||||||
// - Many character's charged attacks have an ability associated with them. This means that,
|
|
||||||
// for now, we don't identify charged attacks reliably.
|
|
||||||
// - There might also be some cases where we incorrectly identify something as a normal or
|
|
||||||
// charged attack that is not (Diluc's E?).
|
|
||||||
// - Catalyst normal attacks have an ability, so we don't handle those for now.
|
|
||||||
// ToDo: Fix all of that.
|
|
||||||
if (ability != AbilityIdentifier.getDefaultInstance()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle the energy generation.
|
// Make sure there is no actual "ability" associated with the hit. For now, this is how we
|
||||||
this.generateEnergyForNormalAndCharged(attackerEntity.get());
|
// identify normal and charged attacks. Note that this is not completely accurate:
|
||||||
}
|
// - Many character's charged attacks have an ability associated with them. This means that,
|
||||||
|
// for now, we don't identify charged attacks reliably.
|
||||||
|
// - There might also be some cases where we incorrectly identify something as a normal or
|
||||||
|
// charged attack that is not (Diluc's E?).
|
||||||
|
// - Catalyst normal attacks have an ability, so we don't handle those for now.
|
||||||
|
// ToDo: Fix all of that.
|
||||||
|
if (ability != AbilityIdentifier.getDefaultInstance()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the energy generation.
|
||||||
|
this.generateEnergyForNormalAndCharged(attackerEntity.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**********
|
/**********
|
||||||
Energy logic related to using skills.
|
Energy logic related to using skills.
|
||||||
**********/
|
**********/
|
||||||
private void handleBurstCast(Avatar avatar, int skillId) {
|
private void handleBurstCast(Avatar avatar, int skillId) {
|
||||||
// Don't do anything if energy usage is disabled.
|
// Don't do anything if energy usage is disabled.
|
||||||
if (!GAME_OPTIONS.energyUsage) {
|
if (!GAME_OPTIONS.energyUsage || !this.energyUsage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the cast skill was a burst, consume energy.
|
// If the cast skill was a burst, consume energy.
|
||||||
if (avatar.getSkillDepot() != null && skillId == avatar.getSkillDepot().getEnergySkill()) {
|
if (avatar.getSkillDepot() != null && skillId == avatar.getSkillDepot().getEnergySkill()) {
|
||||||
avatar.getAsEntity().clearEnergy(PropChangeReason.PROP_CHANGE_REASON_ABILITY);
|
avatar.getAsEntity().clearEnergy(PropChangeReason.PROP_CHANGE_REASON_ABILITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleEvtDoSkillSuccNotify(GameSession session, int skillId, int casterId) {
|
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.
|
// Determine the entity that has cast the skill. Cancel if we can't find that avatar.
|
||||||
Optional<EntityAvatar> caster = this.player.getTeamManager().getActiveTeam().stream()
|
Optional<EntityAvatar> caster = this.player.getTeamManager().getActiveTeam().stream()
|
||||||
.filter(character -> character.getId() == casterId)
|
.filter(character -> character.getId() == casterId)
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
if (caster.isEmpty()) {
|
if (caster.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Avatar avatar = caster.get().getAvatar();
|
Avatar avatar = caster.get().getAvatar();
|
||||||
|
|
||||||
// Handle elemental burst.
|
// Handle elemental burst.
|
||||||
this.handleBurstCast(avatar, skillId);
|
this.handleBurstCast(avatar, skillId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********
|
/**********
|
||||||
Monster energy drops.
|
Monster energy drops.
|
||||||
**********/
|
**********/
|
||||||
private void generateElemBallDrops(EntityMonster monster, int dropId) {
|
private void generateElemBallDrops(EntityMonster monster, int dropId) {
|
||||||
// Generate all drops specified for the given drop id.
|
// Generate all drops specified for the given drop id.
|
||||||
if (!energyDropData.containsKey(dropId)) {
|
if (!energyDropData.containsKey(dropId)) {
|
||||||
Grasscutter.getLogger().warn("No drop data for dropId {} found.", dropId);
|
Grasscutter.getLogger().warn("No drop data for dropId {} found.", dropId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (EnergyDropInfo info : energyDropData.get(dropId)) {
|
for (EnergyDropInfo info : energyDropData.get(dropId)) {
|
||||||
this.generateElemBall(info.getBallId(), monster.getPosition(), info.getCount());
|
this.generateElemBall(info.getBallId(), monster.getPosition(), info.getCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void handleMonsterEnergyDrop(EntityMonster monster, float hpBeforeDamage, float hpAfterDamage) {
|
public void handleMonsterEnergyDrop(EntityMonster monster, float hpBeforeDamage, float hpAfterDamage) {
|
||||||
// Make sure this is actually a monster.
|
// Make sure this is actually a monster.
|
||||||
// Note that some wildlife also has that type, like boars or birds.
|
// Note that some wildlife also has that type, like boars or birds.
|
||||||
MonsterType type = monster.getMonsterData().getType();
|
MonsterType type = monster.getMonsterData().getType();
|
||||||
if (type != MonsterType.MONSTER_ORDINARY && type != MonsterType.MONSTER_BOSS) {
|
if (type != MonsterType.MONSTER_ORDINARY && type != MonsterType.MONSTER_BOSS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the HP tresholds for before and after the damage was taken.
|
// Calculate the HP tresholds for before and after the damage was taken.
|
||||||
float maxHp = monster.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
|
float maxHp = monster.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
|
||||||
float thresholdBefore = hpBeforeDamage / maxHp;
|
float thresholdBefore = hpBeforeDamage / maxHp;
|
||||||
float thresholdAfter = hpAfterDamage / maxHp;
|
float thresholdAfter = hpAfterDamage / maxHp;
|
||||||
|
|
||||||
// Determine the thresholds the monster has passed, and generate drops based on that.
|
|
||||||
for (HpDrops drop : monster.getMonsterData().getHpDrops()) {
|
|
||||||
if (drop.getDropId() == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
float threshold = drop.getHpPercent() / 100.0f;
|
// Determine the thresholds the monster has passed, and generate drops based on that.
|
||||||
if (threshold < thresholdBefore && threshold >= thresholdAfter) {
|
for (HpDrops drop : monster.getMonsterData().getHpDrops()) {
|
||||||
generateElemBallDrops(monster, drop.getDropId());
|
if (drop.getDropId() == 0) {
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle kill drops.
|
float threshold = drop.getHpPercent() / 100.0f;
|
||||||
if (hpAfterDamage <= 0 && monster.getMonsterData().getKillDropId() != 0) {
|
if (threshold < thresholdBefore && threshold >= thresholdAfter) {
|
||||||
generateElemBallDrops(monster, monster.getMonsterData().getKillDropId());
|
generateElemBallDrops(monster, drop.getDropId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********
|
// Handle kill drops.
|
||||||
Utility.
|
if (hpAfterDamage <= 0 && monster.getMonsterData().getKillDropId() != 0) {
|
||||||
**********/
|
generateElemBallDrops(monster, monster.getMonsterData().getKillDropId());
|
||||||
private void generateElemBall(int ballId, Position position, int count) {
|
}
|
||||||
// Generate a particle/orb with the specified parameters.
|
}
|
||||||
ItemData itemData = GameData.getItemDataMap().get(ballId);
|
|
||||||
if (itemData == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityItem energyBall = new EntityItem(this.getPlayer().getScene(), this.getPlayer(), itemData, position, count);
|
/**********
|
||||||
this.getPlayer().getScene().addEntity(energyBall);
|
Utility.
|
||||||
}
|
**********/
|
||||||
|
private void generateElemBall(int ballId, Position position, int count) {
|
||||||
|
// Generate a particle/orb with the specified parameters.
|
||||||
|
ItemData itemData = GameData.getItemDataMap().get(ballId);
|
||||||
|
if (itemData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
private Optional<EntityAvatar> getCastingAvatarEntityForEnergy(int invokeEntityId) {
|
EntityItem energyBall = new EntityItem(this.getPlayer().getScene(), this.getPlayer(), itemData, position, count);
|
||||||
// To determine the avatar that has cast the skill that caused the energy particle to be generated,
|
this.getPlayer().getScene().addEntity(energyBall);
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Try to get the invoking entity from the scene.
|
|
||||||
GameEntity entity = player.getScene().getEntityById(invokeEntityId);
|
|
||||||
|
|
||||||
// Determine the ID of the entity that originally cast this skill. If the scene entity is null,
|
private Optional<EntityAvatar> getCastingAvatarEntityForEnergy(int invokeEntityId) {
|
||||||
// or not an `EntityClientGadget`, we assume that we are directly looking at the casting avatar
|
// To determine the avatar that has cast the skill that caused the energy particle to be generated,
|
||||||
// (the null case will happen if the avatar was switched out between casting the skill and the
|
// we have to look at the entity that has invoked the ability. This can either be that avatar directly,
|
||||||
// particle being generated). If the scene entity is an `EntityClientGadget`, we need to find the
|
// or it can be an `EntityClientGadget`, owned (some way up the owner hierarchy) by the avatar
|
||||||
// ID of the original owner of that gadget.
|
// that cast the skill.
|
||||||
int avatarEntityId =
|
|
||||||
(!(entity instanceof EntityClientGadget))
|
|
||||||
? invokeEntityId
|
|
||||||
: ((EntityClientGadget)entity).getOriginalOwnerEntityId();
|
|
||||||
|
|
||||||
// Finally, find the avatar entity in the player's team.
|
// Try to get the invoking entity from the scene.
|
||||||
return player.getTeamManager().getActiveTeam()
|
GameEntity entity = player.getScene().getEntityById(invokeEntityId);
|
||||||
.stream()
|
|
||||||
.filter(character -> character.getId() == avatarEntityId)
|
// Determine the ID of the entity that originally cast this skill. If the scene entity is null,
|
||||||
.findFirst();
|
// or not an `EntityClientGadget`, we assume that we are directly looking at the casting avatar
|
||||||
}
|
// (the null case will happen if the avatar was switched out between casting the skill and the
|
||||||
}
|
// particle being generated). If the scene entity is an `EntityClientGadget`, we need to find the
|
||||||
|
// ID of the original owner of that gadget.
|
||||||
|
int avatarEntityId =
|
||||||
|
(!(entity instanceof EntityClientGadget))
|
||||||
|
? invokeEntityId
|
||||||
|
: ((EntityClientGadget)entity).getOriginalOwnerEntityId();
|
||||||
|
|
||||||
|
// Finally, find the avatar entity in the player's team.
|
||||||
|
return player.getTeamManager().getActiveTeam()
|
||||||
|
.stream()
|
||||||
|
.filter(character -> character.getId() == avatarEntityId)
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getEnergyUsage() {
|
||||||
|
return energyUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnergyUsage(Boolean energyUsage) {
|
||||||
|
this.energyUsage = energyUsage;
|
||||||
|
}
|
||||||
|
}
|
@ -184,6 +184,12 @@
|
|||||||
"success": "NoStamina is now %s for %s.",
|
"success": "NoStamina is now %s for %s.",
|
||||||
"description": "Keep your endurance to the maximum."
|
"description": "Keep your endurance to the maximum."
|
||||||
},
|
},
|
||||||
|
"unlimitenergy": {
|
||||||
|
"usage": "unlimitenergy [targetUID] [on | off | toggle ]",
|
||||||
|
"success": "unlimitenergy is now %s for %s.",
|
||||||
|
"description": "Use the element does not waste energy in unlimitenergy on",
|
||||||
|
"config_error": "Command is disable,because energyUsage is false in config.json."
|
||||||
|
},
|
||||||
"heal": {
|
"heal": {
|
||||||
"success": "All characters have been healed.",
|
"success": "All characters have been healed.",
|
||||||
"description": "Heal all characters in your current team."
|
"description": "Heal all characters in your current team."
|
||||||
|
@ -157,6 +157,12 @@
|
|||||||
"success": "NoStamina 已设为 %s。[用户:%s]",
|
"success": "NoStamina 已设为 %s。[用户:%s]",
|
||||||
"description": "保持你的体力处于最高状态"
|
"description": "保持你的体力处于最高状态"
|
||||||
},
|
},
|
||||||
|
"unlimitenergy": {
|
||||||
|
"usage": "用法:unlimitenergy [目标玩家] [on | off | toggle ]",
|
||||||
|
"success": "unlimitEnergy 已设为 %s。[用户:%s]",
|
||||||
|
"description": "使用元素爆发不消耗能量",
|
||||||
|
"config_error": "当前命令不可用,需要在config.json中配置 energyUsage : true 才可生效"
|
||||||
|
},
|
||||||
"giveArtifact": {
|
"giveArtifact": {
|
||||||
"usage": "用法:giveart|gart [玩家] <圣遗物ID> <主词条ID> [<副词条ID>[,<强化次数>]]... [等级]",
|
"usage": "用法:giveart|gart [玩家] <圣遗物ID> <主词条ID> [<副词条ID>[,<强化次数>]]... [等级]",
|
||||||
"id_error": "无效的圣遗物ID。",
|
"id_error": "无效的圣遗物ID。",
|
||||||
|
Loading…
Reference in New Issue
Block a user