[BREAKING] Item Usage Overhaul

-De-hardcode elemental orb values
-De-hardcode exp items
-Change ShopChest format (temporary, drop system overhaul will replace it entirely)
-Food healing actually uses Ability data for real HP amounts
This commit is contained in:
AnimeGitB
2022-10-14 00:00:40 +10:30
parent 5bb43ac074
commit d1d39db56c
66 changed files with 1533 additions and 786 deletions

View File

@@ -1,7 +1,6 @@
package emu.grasscutter.game.managers;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -46,22 +45,13 @@ public class CookingManager extends BasePlayerManager {
/********************
* Unlocking for recipies.
********************/
public synchronized boolean unlockRecipe(GameItem recipeItem) {
// Make sure this is actually a cooking recipe.
if (recipeItem.getItemData().getItemUse().get(0).getUseOp() != ItemUseOp.ITEM_USE_UNLOCK_COOK_RECIPE) {
return false;
public boolean unlockRecipe(int id) {
if (this.player.getUnlockedRecipies().containsKey(id)) {
return false; // Recipe already unlocked
}
// Determine the recipe we should unlock.
int recipeId = Integer.parseInt(recipeItem.getItemData().getItemUse().get(0).getUseParam()[0]);
// Remove the item from the player's inventory.
// We need to do this here, before sending CookRecipeDataNotify, or the the UI won't correctly update.
player.getInventory().removeItem(recipeItem, 1);
// Tell the client that this blueprint is now unlocked and add the unlocked item to the player.
this.player.getUnlockedRecipies().put(recipeId, 0);
this.player.sendPacket(new PacketCookRecipeDataNotify(recipeId));
this.player.getUnlockedRecipies().put(id, 0);
this.player.sendPacket(new PacketCookRecipeDataNotify(id));
return true;
}

View File

@@ -1,12 +1,9 @@
package emu.grasscutter.game.managers;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.game.home.FurnitureMakeSlotItem;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ItemUseOp;
import emu.grasscutter.net.proto.ItemParamOuterClass;
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
import emu.grasscutter.server.packet.send.*;
@@ -34,26 +31,19 @@ public class FurnitureManager extends BasePlayerManager {
player.getSession().send(new PacketUnlockedFurnitureSuiteDataNotify(player.getUnlockedFurnitureSuite()));
}
public synchronized boolean unlockFurnitureOrSuite(GameItem useItem) {
ItemUseOp itemUseOp = useItem.getItemData().getItemUse().get(0).getUseOp();
// Check
if (itemUseOp != ItemUseOp.ITEM_USE_UNLOCK_FURNITURE_SUITE && itemUseOp != ItemUseOp.ITEM_USE_UNLOCK_FURNITURE_FORMULA) {
return false;
public boolean unlockFurnitureFormula(int id) {
if (!player.getUnlockedFurniture().add(id)) {
return false; // Already unlocked!
}
notifyUnlockFurniture();
return true;
}
int furnitureIdOrSuiteId = Integer.parseInt(useItem.getItemData().getItemUse().get(0).getUseParam()[0]);
// Remove first
player.getInventory().removeItem(useItem, 1);
if (useItem.getItemData().getItemUse().get(0).getUseOp() == ItemUseOp.ITEM_USE_UNLOCK_FURNITURE_FORMULA) {
player.getUnlockedFurniture().add(furnitureIdOrSuiteId);
notifyUnlockFurniture();
}else {
player.getUnlockedFurnitureSuite().add(furnitureIdOrSuiteId);
notifyUnlockFurnitureSuite();
public boolean unlockFurnitureSuite(int id) {
if (!player.getUnlockedFurnitureSuite().add(id)) {
return false; // Already unlocked!
}
notifyUnlockFurnitureSuite();
return true;
}

View File

@@ -13,12 +13,17 @@ import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.inventory.MaterialType;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ElementType;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.ItemUseOp;
import emu.grasscutter.game.props.ItemUseTarget;
import emu.grasscutter.game.props.MonsterType;
import emu.grasscutter.game.props.WeaponType;
import emu.grasscutter.game.props.ItemUseAction.ItemUseAction;
import emu.grasscutter.game.props.ItemUseAction.ItemUseAddEnergy;
import emu.grasscutter.net.proto.AbilityActionGenerateElemBallOuterClass.AbilityActionGenerateElemBall;
import emu.grasscutter.net.proto.AbilityIdentifierOuterClass.AbilityIdentifier;
import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry;
@@ -30,10 +35,10 @@ import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;
@@ -42,7 +47,7 @@ import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import com.google.protobuf.InvalidProtocolBufferException;
public class EnergyManager extends BasePlayerManager {
private final Map<EntityAvatar, Integer> avatarNormalProbabilities;
private final Object2IntMap<EntityAvatar> avatarNormalProbabilities;
private boolean energyUsage; // Should energy usage be enabled for this player?
private final static Int2ObjectMap<List<EnergyDropInfo>> energyDropData = new Int2ObjectOpenHashMap<>();
@@ -50,7 +55,7 @@ public class EnergyManager extends BasePlayerManager {
public EnergyManager(Player player) {
super(player);
this.avatarNormalProbabilities = new HashMap<>();
this.avatarNormalProbabilities = new Object2IntOpenHashMap<>();
this.energyUsage=GAME_OPTIONS.energyUsage;
}
@@ -170,66 +175,9 @@ public class EnergyManager extends BasePlayerManager {
}
// Generate the particles.
var pos = new Position(action.getPos());
for (int i = 0; i < amount; i++) {
this.generateElemBall(itemId, new Position(action.getPos()), 1);
}
}
/**
* Pickup of elemental particles and orbs.
* @param elemBall The elemental particle or orb.
*/
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.
// The on-field character gets no penalty.
// Off-field characters get a penalty depending on the team size, as follows:
// - 2 character team: 0.8
// - 3 character team: 0.7
// - 4 character team: 0.6
// - etc.
// We set a lower bound of 0.1 here, to avoid gaining no or negative energy.
float offFieldPenalty =
(this.player.getTeamManager().getCurrentCharacterIndex() == i)
? 1.0f
: 1.0f - this.player.getTeamManager().getActiveTeam().size() * 0.1f;
offFieldPenalty = Math.max(offFieldPenalty, 0.1f);
// Same element/neutral bonus.
// 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.
if (entity.getAvatar().getSkillDepot() == null) {
continue;
}
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 * elemBall.getCount(), PropChangeReason.PROP_CHANGE_REASON_ENERGY_BALL);
this.generateElemBall(itemId, pos, 1);
}
}
@@ -256,7 +204,7 @@ public class EnergyManager extends BasePlayerManager {
}
// Roll for energy.
int currentProbability = this.avatarNormalProbabilities.get(avatar);
int currentProbability = this.avatarNormalProbabilities.getInt(avatar);
int roll = ThreadLocalRandom.current().nextInt(0, 100);
// If the player wins the roll, we increase the avatar's energy and reset the probability.

View File

@@ -5,7 +5,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.data.excels.ForgeData;
@@ -14,7 +13,6 @@ import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.ItemUseOp;
import emu.grasscutter.game.props.WatcherTriggerType;
import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData;
import emu.grasscutter.net.proto.ForgeQueueManipulateReqOuterClass.ForgeQueueManipulateReq;
@@ -38,24 +36,12 @@ public class ForgingManager extends BasePlayerManager {
/**********
Blueprint unlocking.
**********/
public synchronized boolean unlockForgingBlueprint(GameItem blueprintItem) {
// Make sure this is actually a forging blueprint.
if (blueprintItem.getItemData().getItemUse().get(0).getUseOp() != ItemUseOp.ITEM_USE_UNLOCK_FORGE) {
return false;
}
// Determine the forging item we should unlock.
int forgeId = Integer.parseInt(blueprintItem.getItemData().getItemUse().get(0).getUseParam()[0]);
// Remove the blueprint from the player's inventory.
// We need to do this here, before sending ForgeFormulaDataNotify, or the the forging UI won't correctly
// update when unlocking the blueprint.
player.getInventory().removeItem(blueprintItem, 1);
public boolean unlockForgingBlueprint(int id) {
// Tell the client that this blueprint is now unlocked and add the unlocked item to the player.
this.player.getUnlockedForgingBlueprints().add(forgeId);
this.player.sendPacket(new PacketForgeFormulaDataNotify(forgeId));
if (!this.player.getUnlockedForgingBlueprints().add(id)) {
return false; // Already unlocked
}
this.player.sendPacket(new PacketForgeFormulaDataNotify(id));
return true;
}

View File

@@ -29,49 +29,49 @@ import java.util.*;
public class StaminaManager extends BasePlayerManager {
// TODO: Skiff state detection?
private static final HashMap<String, HashSet<MotionState>> MotionStatesCategorized = new HashMap<>() {{
put("CLIMB", new HashSet<>(List.of(
private static final Map<String, Set<MotionState>> MotionStatesCategorized = new HashMap<>() {{
put("CLIMB", Set.of(
MotionState.MOTION_STATE_CLIMB, // sustained, when not moving no cost no recover
MotionState.MOTION_STATE_STANDBY_TO_CLIMB // NOT OBSERVED, see MOTION_JUMP_UP_WALL_FOR_STANDBY
)));
put("DASH", new HashSet<>(List.of(
));
put("DASH", Set.of(
MotionState.MOTION_STATE_DANGER_DASH, // sustained
MotionState.MOTION_STATE_DASH // sustained
)));
put("FLY", new HashSet<>(List.of(
));
put("FLY", Set.of(
MotionState.MOTION_STATE_FLY, // sustained
MotionState.MOTION_STATE_FLY_FAST, // sustained
MotionState.MOTION_STATE_FLY_SLOW, // sustained
MotionState.MOTION_STATE_POWERED_FLY // sustained, recover
)));
put("RUN", new HashSet<>(List.of(
));
put("RUN", Set.of(
MotionState.MOTION_STATE_DANGER_RUN, // sustained, recover
MotionState.MOTION_STATE_RUN // sustained, recover
)));
put("SKIFF", new HashSet<>(List.of(
));
put("SKIFF", Set.of(
MotionState.MOTION_STATE_SKIFF_BOARDING, // NOT OBSERVED even when boarding
MotionState.MOTION_STATE_SKIFF_DASH, // sustained, observed with waverider entity ID.
MotionState.MOTION_STATE_SKIFF_NORMAL, // sustained, OBSERVED when both normal and dashing
MotionState.MOTION_STATE_SKIFF_POWERED_DASH // sustained, recover
)));
put("STANDBY", new HashSet<>(List.of(
));
put("STANDBY", Set.of(
MotionState.MOTION_STATE_DANGER_STANDBY_MOVE, // sustained, recover
MotionState.MOTION_STATE_DANGER_STANDBY, // sustained, recover
MotionState.MOTION_STATE_LADDER_TO_STANDBY, // NOT OBSERVED
MotionState.MOTION_STATE_STANDBY_MOVE, // sustained, recover
MotionState.MOTION_STATE_STANDBY // sustained, recover
)));
put("SWIM", new HashSet<>(List.of(
));
put("SWIM", Set.of(
MotionState.MOTION_STATE_SWIM_IDLE, // sustained
MotionState.MOTION_STATE_SWIM_DASH, // immediate and sustained
MotionState.MOTION_STATE_SWIM_JUMP, // NOT OBSERVED
MotionState.MOTION_STATE_SWIM_MOVE // sustained
)));
put("WALK", new HashSet<>(List.of(
));
put("WALK", Set.of(
MotionState.MOTION_STATE_DANGER_WALK, // sustained, recover
MotionState.MOTION_STATE_WALK // sustained, recover
)));
put("OTHER", new HashSet<>(List.of(
));
put("OTHER", Set.of(
MotionState.MOTION_STATE_CLIMB_JUMP, // cost only once if repeated without switching state
MotionState.MOTION_STATE_DASH_BEFORE_SHAKE, // immediate one time sprint charge.
MotionState.MOTION_STATE_FIGHT, // immediate, if sustained then subsequent will be MOTION_NOTIFY
@@ -79,13 +79,13 @@ public class StaminaManager extends BasePlayerManager {
MotionState.MOTION_STATE_NOTIFY, // can be either cost or recover - check previous state and check skill casting
MotionState.MOTION_STATE_SIT_IDLE, // sustained, recover
MotionState.MOTION_STATE_JUMP // recover
)));
put("NOCOST_NORECOVER", new HashSet<>(List.of(
));
put("NOCOST_NORECOVER", Set.of(
MotionState.MOTION_STATE_LADDER_SLIP, // NOT OBSERVED
MotionState.MOTION_STATE_SLIP, // sustained, no cost no recover
MotionState.MOTION_STATE_FLY_IDLE // NOT OBSERVED
)));
put("IGNORE", new HashSet<>(List.of(
));
put("IGNORE", Set.of(
// these states have no impact on stamina
MotionState.MOTION_STATE_CROUCH_IDLE,
MotionState.MOTION_STATE_CROUCH_MOVE,
@@ -106,7 +106,7 @@ public class StaminaManager extends BasePlayerManager {
MotionState.MOTION_STATE_RESET,
MotionState.MOTION_STATE_STANDBY_TO_LADDER,
MotionState.MOTION_STATE_WATERFALL
)));
));
}};
private final Logger logger = Grasscutter.getLogger();
@@ -127,9 +127,7 @@ public class StaminaManager extends BasePlayerManager {
private boolean lastSkillFirstTick = true;
private int vehicleId = -1;
private int vehicleStamina = GlobalVehicleMaxStamina;
private static final HashSet<Integer> TalentMovements = new HashSet<>(List.of(
10013, 10413
));
private static final Set<Integer> TalentMovements = Set.of(10013, 10413);
private static final HashMap<Integer, Float> ClimbFoodReductionMap = new HashMap<>() {{
// TODO: get real food id
put(0, 0.8f); // Sample food
@@ -190,6 +188,17 @@ public class StaminaManager extends BasePlayerManager {
return vehicleStamina;
}
public boolean addCurrentStamina(int amount) {
var cur = this.getCurrentCharacterStamina();
var max = this.getMaxCharacterStamina();
if (cur >= max) return false;
var value = cur + amount;
if (value > max)
value = max;
this.player.setProperty(PlayerProperty.PROP_CUR_PERSIST_STAMINA, value);
return true;
}
public boolean registerBeforeUpdateStaminaListener(String listenerName, BeforeUpdateStaminaListener listener) {
if (beforeUpdateStaminaListeners.containsKey(listenerName)) {
return false;
@@ -405,27 +414,17 @@ public class StaminaManager extends BasePlayerManager {
// Internal handler
private void handleImmediateStamina(GameSession session, @NotNull MotionState motionState) {
if (currentState == motionState) return;
switch (motionState) {
case MOTION_STATE_CLIMB:
if (currentState != MotionState.MOTION_STATE_CLIMB) {
case MOTION_STATE_CLIMB ->
updateStaminaRelative(session, new Consumption(ConsumptionType.CLIMB_START), true);
}
break;
case MOTION_STATE_DASH_BEFORE_SHAKE:
if (previousState != MotionState.MOTION_STATE_DASH_BEFORE_SHAKE) {
case MOTION_STATE_DASH_BEFORE_SHAKE ->
updateStaminaRelative(session, new Consumption(ConsumptionType.SPRINT), true);
}
break;
case MOTION_STATE_CLIMB_JUMP:
if (previousState != MotionState.MOTION_STATE_CLIMB_JUMP) {
case MOTION_STATE_CLIMB_JUMP ->
updateStaminaRelative(session, new Consumption(ConsumptionType.CLIMB_JUMP), true);
}
break;
case MOTION_STATE_SWIM_DASH:
if (previousState != MotionState.MOTION_STATE_SWIM_DASH) {
case MOTION_STATE_SWIM_DASH ->
updateStaminaRelative(session, new Consumption(ConsumptionType.SWIM_DASH_START), true);
}
break;
default -> {}
}
}
@@ -526,20 +525,14 @@ public class StaminaManager extends BasePlayerManager {
// Bow avatar charged attack
Avatar currentAvatar = player.getTeamManager().getCurrentAvatarEntity().getAvatar();
switch (currentAvatar.getAvatarData().getWeaponType()) {
case WEAPON_BOW:
return getBowSustainedCost(skillCasting);
case WEAPON_CLAYMORE:
return getClaymoreSustainedCost(skillCasting);
case WEAPON_CATALYST:
return getCatalystCost(skillCasting);
case WEAPON_POLE:
return getPolearmCost(skillCasting);
case WEAPON_SWORD_ONE_HAND:
return getSwordCost(skillCasting);
}
return new Consumption();
return switch (currentAvatar.getAvatarData().getWeaponType()) {
case WEAPON_BOW -> getBowSustainedCost(skillCasting);
case WEAPON_CLAYMORE -> getClaymoreSustainedCost(skillCasting);
case WEAPON_CATALYST -> getCatalystCost(skillCasting);
case WEAPON_POLE -> getPolearmCost(skillCasting);
case WEAPON_SWORD_ONE_HAND -> getSwordCost(skillCasting);
default -> new Consumption();
};
}
private Consumption getClimbConsumption() {