Skip to content

Commit

Permalink
Move vehicle fightprop hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Birdulon committed Aug 24, 2022
1 parent 9970aeb commit fbf3dbb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 133 deletions.
25 changes: 5 additions & 20 deletions src/main/java/emu/grasscutter/command/commands/SpawnCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,18 @@ public void execute(Player sender, Player targetPlayer, List<String> args) {
}

double maxRadius = Math.sqrt(amount * 0.2 / Math.PI);
Position center = (x != 0 && y != 0 && z != 0)
? (new Position(x, y, z))
: (targetPlayer.getPosition());
for (int i = 0; i < amount; i++) {
Position pos = GetRandomPositionInCircle(targetPlayer.getPosition(), maxRadius).addY(3);
if (x != 0 && y != 0 && z != 0) {
pos = GetRandomPositionInCircle(new Position(x, y, z), maxRadius).addY(3);
}
Position pos = GetRandomPositionInCircle(center, maxRadius).addY(3);
GameEntity entity = null;
if (itemData != null) {
entity = new EntityItem(scene, null, itemData, pos, 1, true);
}
if (gadgetData != null) {
pos.addY(-3);
entity = new EntityVehicle(scene, targetPlayer.getSession().getPlayer(), gadgetData.getId(), 0, pos, targetPlayer.getRotation()); // TODO: does targetPlayer.getSession().getPlayer() have some meaning?
int gadgetId = gadgetData.getId();
switch (gadgetId) {
// TODO: Not hardcode this. Waverider (skiff)
case 45001001, 45001002 -> {
entity.addFightProperty(FightProperty.FIGHT_PROP_BASE_HP, 10000);
entity.addFightProperty(FightProperty.FIGHT_PROP_BASE_ATTACK, 100);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, 100);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 10000);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, 0);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_SPEED, 0);
entity.addFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, 0);
entity.addFightProperty(FightProperty.FIGHT_PROP_MAX_HP, 10000);
}
default -> {}
}
entity = new EntityVehicle(scene, targetPlayer, id, 0, pos, targetPlayer.getRotation());
}
if (monsterData != null) {
entity = new EntityMonster(scene, monsterData, pos, level);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package emu.grasscutter.game.entity;

import emu.grasscutter.game.world.Scene;
import emu.grasscutter.game.world.World;

public abstract class EntityBaseGadget extends GameEntity {

Expand Down
44 changes: 22 additions & 22 deletions src/main/java/emu/grasscutter/game/entity/EntityVehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.EntityIdType;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.game.world.Scene;

Expand All @@ -10,7 +11,6 @@
import emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityInfo;
import emu.grasscutter.net.proto.EntityRendererChangedInfoOuterClass.EntityRendererChangedInfo;
import emu.grasscutter.net.proto.FightPropPairOuterClass.*;
import emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq;
import emu.grasscutter.net.proto.MotionInfoOuterClass.MotionInfo;
import emu.grasscutter.net.proto.PropPairOuterClass.PropPair;
import emu.grasscutter.net.proto.ProtEntityTypeOuterClass.ProtEntityType;
Expand All @@ -25,23 +25,25 @@

import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.ArrayList;

public class EntityVehicle extends EntityBaseGadget {

private final Player owner;
private final Int2FloatOpenHashMap fightProp;
@Getter private final Player owner;
private final Int2FloatMap fightProp;

private final Position pos;
private final Position rot;

private final int pointId;
private final int gadgetId;
@Getter private final int pointId;
@Getter private final int gadgetId;

private float curStamina;
private List<VehicleMember> vehicleMembers;
@Getter @Setter private float curStamina;
@Getter private List<VehicleMember> vehicleMembers;

public EntityVehicle(Scene scene, Player player, int gadgetId, int pointId, Position pos, Position rot) {
super(scene);
Expand All @@ -54,25 +56,23 @@ public EntityVehicle(Scene scene, Player player, int gadgetId, int pointId, Posi
this.pointId = pointId;
this.curStamina = 240;
this.vehicleMembers = new ArrayList<VehicleMember>();
}

@Override
public int getGadgetId() { return gadgetId; }

public Player getOwner() {
return owner;
switch (gadgetId) {
case 45001001,45001002 -> { // TODO: Not hardcode this. Waverider (skiff)
this.addFightProperty(FightProperty.FIGHT_PROP_BASE_HP, 10000);
this.addFightProperty(FightProperty.FIGHT_PROP_BASE_ATTACK, 100);
this.addFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, 100);
this.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 10000);
this.addFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, 0);
this.addFightProperty(FightProperty.FIGHT_PROP_CUR_SPEED, 0);
this.addFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, 0);
this.addFightProperty(FightProperty.FIGHT_PROP_MAX_HP, 10000);
}
}
}

public float getCurStamina() { return curStamina; }

public void setCurStamina(float stamina) { this.curStamina = stamina; }

public int getPointId() { return pointId; }

public List<VehicleMember> getVehicleMembers() { return vehicleMembers; }

@Override
public Int2FloatOpenHashMap getFightProperties() {
public Int2FloatMap getFightProperties() {
return fightProp;
}

Expand Down
90 changes: 17 additions & 73 deletions src/main/java/emu/grasscutter/game/entity/GameEntity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package emu.grasscutter.game.entity;

import java.util.HashMap;
import java.util.Map;

import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.LifeState;
Expand All @@ -20,36 +17,35 @@
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap;
import lombok.Getter;
import lombok.Setter;

public abstract class GameEntity {
protected int id;
private final Scene scene;
private SpawnDataEntry spawnEntry;
@Getter protected int id;
@Getter private final Scene scene;
@Getter @Setter private SpawnDataEntry spawnEntry;

private int blockId;
private int configId;
private int groupId;
@Getter @Setter private int blockId;
@Getter @Setter private int configId;
@Getter @Setter private int groupId;

private MotionState moveState;
private int lastMoveSceneTimeMs;
private int lastMoveReliableSeq;
@Getter @Setter private int lastMoveSceneTimeMs;
@Getter @Setter private int lastMoveReliableSeq;

// Abilities
private Map<String, Float> metaOverrideMap;
private Object2FloatMap<String> metaOverrideMap;
private Int2ObjectMap<String> metaModifiers;

public GameEntity(Scene scene) {
this.scene = scene;
this.moveState = MotionState.MOTION_STATE_NONE;
}

public int getId() {
return this.id;
}

public int getEntityType() {
return this.getId() >> 24;
}
Expand All @@ -58,10 +54,6 @@ public World getWorld() {
return this.getScene().getWorld();
}

public Scene getScene() {
return this.scene;
}

public boolean isAlive() {
return true;
}
Expand All @@ -70,9 +62,9 @@ public LifeState getLifeState() {
return this.isAlive() ? LifeState.LIFE_ALIVE : LifeState.LIFE_DEAD;
}

public Map<String, Float> getMetaOverrideMap() {
public Object2FloatMap<String> getMetaOverrideMap() {
if (this.metaOverrideMap == null) {
this.metaOverrideMap = new HashMap<>();
this.metaOverrideMap = new Object2FloatOpenHashMap<>();
}
return this.metaOverrideMap;
}
Expand All @@ -84,7 +76,7 @@ public Int2ObjectMap<String> getMetaModifiers() {
return this.metaModifiers;
}

public abstract Int2FloatOpenHashMap getFightProperties();
public abstract Int2FloatMap getFightProperties();

public abstract Position getPosition();

Expand All @@ -98,27 +90,11 @@ public void setMotionState(MotionState moveState) {
this.moveState = moveState;
}

public int getLastMoveSceneTimeMs() {
return lastMoveSceneTimeMs;
}

public void setLastMoveSceneTimeMs(int lastMoveSceneTimeMs) {
this.lastMoveSceneTimeMs = lastMoveSceneTimeMs;
}

public int getLastMoveReliableSeq() {
return lastMoveReliableSeq;
}

public void setLastMoveReliableSeq(int lastMoveReliableSeq) {
this.lastMoveReliableSeq = lastMoveReliableSeq;
}

public void setFightProperty(FightProperty prop, float value) {
this.getFightProperties().put(prop.getId(), value);
}

private void setFightProperty(int id, float value) {
public void setFightProperty(int id, float value) {
this.getFightProperties().put(id, value);
}

Expand All @@ -140,30 +116,6 @@ public void addAllFightPropsToEntityInfo(SceneEntityInfo.Builder entityInfo) {
}
}

public int getBlockId() {
return blockId;
}

public void setBlockId(int blockId) {
this.blockId = blockId;
}

public int getConfigId() {
return configId;
}

public void setConfigId(int configId) {
this.configId = configId;
}

public int getGroupId() {
return groupId;
}

public void setGroupId(int groupId) {
this.groupId = groupId;
}

protected MotionInfo getMotionInfo() {
MotionInfo proto = MotionInfo.newBuilder()
.setPos(this.getPosition().toProto())
Expand All @@ -175,14 +127,6 @@ protected MotionInfo getMotionInfo() {
return proto;
}

public SpawnDataEntry getSpawnEntry() {
return spawnEntry;
}

public void setSpawnEntry(SpawnDataEntry spawnEntry) {
this.spawnEntry = spawnEntry;
}

public float heal(float amount) {
if (this.getFightProperties() == null) {
return 0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.entity.EntityVehicle;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.entity.GameEntity;

import emu.grasscutter.net.packet.BasePacket;
Expand Down Expand Up @@ -40,22 +39,6 @@ public PacketCreateVehicleRsp(Player player, int vehicleId, int pointId, Positio
});

EntityVehicle vehicle = new EntityVehicle(player.getScene(), player, vehicleId, pointId, pos, rot);

switch (vehicleId) {
// TODO: Not hardcode this. Waverider (skiff)
case 45001001,45001002 -> {
vehicle.addFightProperty(FightProperty.FIGHT_PROP_BASE_HP, 10000);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_BASE_ATTACK, 100);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, 100);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 10000);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, 0);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_CUR_SPEED, 0);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, 0);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_MAX_HP, 10000);
}
default -> {}
}

player.getScene().addEntity(vehicle);

proto.setVehicleId(vehicleId);
Expand Down

0 comments on commit fbf3dbb

Please sign in to comment.