Fix ActionGenerateElemBall

This commit is contained in:
KingRainbow44 2023-06-04 01:00:27 -04:00
parent b050337216
commit b09c0d48bf
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE

View File

@ -2,6 +2,7 @@ package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
@ -12,13 +13,12 @@ import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.props.SceneType; import emu.grasscutter.game.props.SceneType;
import emu.grasscutter.net.proto.AbilityActionGenerateElemBallOuterClass.AbilityActionGenerateElemBall; import emu.grasscutter.net.proto.AbilityActionGenerateElemBallOuterClass.AbilityActionGenerateElemBall;
import emu.grasscutter.utils.Position; import emu.grasscutter.game.world.Position;
@AbilityAction(AbilityModifierAction.Type.GenerateElemBall) @AbilityAction(AbilityModifierAction.Type.GenerateElemBall)
public class ActionGenerateElemBall extends AbilityActionHandler { public final class ActionGenerateElemBall extends AbilityActionHandler {
@Override @Override
public boolean execute( public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
GameEntity owner = ability.getOwner(); GameEntity owner = ability.getOwner();
AbilityActionGenerateElemBall generateElemBall; AbilityActionGenerateElemBall generateElemBall;
@ -28,69 +28,54 @@ public class ActionGenerateElemBall extends AbilityActionHandler {
return false; return false;
} }
// Check if we should allow elem ball generation //Check if we should allow elem ball generation
if (action.dropType == 0x0) { if(action.dropType == 0x0) {
String levelEntityConfig = owner.getScene().getSceneData().getLevelEntityConfig(); String levelEntityConfig = owner.getScene().getSceneData().getLevelEntityConfig();
ConfigLevelEntity config = GameData.getConfigLevelEntityDataMap().get(levelEntityConfig); ConfigLevelEntity config = GameData.getConfigLevelEntityDataMap().get(levelEntityConfig);
if (config != null if(config != null && config.getDropElemControlType() != null && config.getDropElemControlType().compareTo("None") == 0) {
&& config.getDropElemControlType() != null
&& config.getDropElemControlType().compareTo("None") == 0) {
Grasscutter.getLogger().warn("This level config don't allow element balls"); Grasscutter.getLogger().warn("This level config don't allow element balls");
return true; return true;
} }
} else if (action.dropType == 0x1) { } else if(action.dropType == 0x1) {
if (owner.getScene().getSceneData().getSceneType() != SceneType.SCENE_WORLD) { if(owner.getScene().getSceneData().getSceneType() != SceneType.SCENE_WORLD) {
Grasscutter.getLogger().warn("This level config only allows element balls on big world"); Grasscutter.getLogger().warn("This level config only allows element balls on big world");
return true; return true;
} }
} // Else the drop is forced } //Else the drop is forced
var energy = action.baseEnergy.get(ability) * action.ratio.get(ability); var energy = action.baseEnergy.get(ability) * action.ratio.get(ability);
if (energy <= 0.0) return true; if(energy <= 0.0) return true;
var itemData = GameData.getItemDataMap().get(action.configID); var itemData = GameData.getItemDataMap().get(action.configID);
if (itemData == null) { if(itemData == null) {
Grasscutter.getLogger().warn("configID {} not found", action.configID); Grasscutter.getLogger().warn("configID {} not found", action.configID);
return false; return false;
} }
if (itemData.getItemUse() == null || itemData.getItemUse().isEmpty()) { if(itemData.getItemUse() == null || itemData.getItemUse().isEmpty()) {
Grasscutter.getLogger().warn("Item {} has no item use array", action.configID); Grasscutter.getLogger().warn("Item {} has no item use array", action.configID);
return true; return true;
} }
var itemUse = itemData.getItemUse().get(0); var itemUse = itemData.getItemUse().get(0);
double requiredEnergy; double requiredEnergy;
switch (itemUse.getUseOp()) { switch(itemUse.getUseOp()) {
case ITEM_USE_ADD_ELEM_ENERGY: case ITEM_USE_ADD_ELEM_ENERGY: requiredEnergy = Integer.parseInt(itemUse.getUseParam()[1]); break;
requiredEnergy = Integer.parseInt(itemUse.getUseParam()[1]); case ITEM_USE_ADD_ALL_ENERGY: requiredEnergy = Integer.parseInt(itemUse.getUseParam()[0]); break;
break;
case ITEM_USE_ADD_ALL_ENERGY:
requiredEnergy = Integer.parseInt(itemUse.getUseParam()[0]);
break;
default: default:
Grasscutter.getLogger().warn("UseOp not implemented", itemUse.getUseOp()); Grasscutter.getLogger().warn("UseOp not implemented", itemUse.getUseOp());
return false; return false;
} }
var amountGenerated = (int) Math.ceil(energy / requiredEnergy); var amountGenerated = (int)Math.ceil(energy / requiredEnergy);
if (amountGenerated >= 21) { if(amountGenerated >= 21) {
Grasscutter.getLogger() Grasscutter.getLogger().warn("Attempt to generate more than 20 element balls {}", amountGenerated);
.warn("Attempt to generate more than 20 element balls {}", amountGenerated);
return false; return false;
} }
Grasscutter.getLogger() Grasscutter.getLogger().debug("Generating {} of {} element balls", amountGenerated, action.configID);
.debug("Generating {} of {} element balls", amountGenerated, action.configID); for(int i = 0; i < amountGenerated; i++) {
for (int i = 0; i < amountGenerated; i++) { EntityItem energyBall = new EntityItem(owner.getScene(), (owner instanceof EntityAvatar avatar) ? avatar.getPlayer() : null, itemData, new Position(generateElemBall.getPos()), new Position(generateElemBall.getRot()), 1);
EntityItem energyBall =
new EntityItem(
owner.getScene(),
(owner instanceof EntityAvatar avatar) ? avatar.getPlayer() : null,
itemData,
new Position(generateElemBall.getPos()),
new Position(generateElemBall.getRot()),
1);
owner.getScene().addEntity(energyBall); owner.getScene().addEntity(energyBall);
} }