Commit 6d59159b authored by Melledy's avatar Melledy
Browse files

Cleanup package names

parent ac49114c
...@@ -6,8 +6,8 @@ import java.util.Calendar; ...@@ -6,8 +6,8 @@ import java.util.Calendar;
import emu.grasscutter.auth.AuthenticationSystem; import emu.grasscutter.auth.AuthenticationSystem;
import emu.grasscutter.auth.DefaultAuthentication; import emu.grasscutter.auth.DefaultAuthentication;
import emu.grasscutter.command.CommandMap; import emu.grasscutter.command.CommandMap;
import emu.grasscutter.game.managers.EnergyManager.EnergyManager; import emu.grasscutter.game.managers.energy.EnergyManager;
import emu.grasscutter.game.managers.StaminaManager.StaminaManager; import emu.grasscutter.game.managers.stamina.StaminaManager;
import emu.grasscutter.plugin.PluginManager; import emu.grasscutter.plugin.PluginManager;
import emu.grasscutter.plugin.api.ServerHook; import emu.grasscutter.plugin.api.ServerHook;
import emu.grasscutter.scripts.ScriptLoader; import emu.grasscutter.scripts.ScriptLoader;
......
...@@ -5,7 +5,7 @@ import emu.grasscutter.command.Command; ...@@ -5,7 +5,7 @@ import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
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.managers.EnergyManager.EnergyManager; import emu.grasscutter.game.managers.energy.EnergyManager;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.player.TeamManager; import emu.grasscutter.game.player.TeamManager;
import emu.grasscutter.game.props.ElementType; import emu.grasscutter.game.props.ElementType;
......
package emu.grasscutter.game.managers.ChatManager; package emu.grasscutter.game.managers.chat;
import emu.grasscutter.command.CommandMap; import emu.grasscutter.command.CommandMap;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
......
package emu.grasscutter.game.managers.ChatManager; package emu.grasscutter.game.managers.chat;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameServer;
......
package emu.grasscutter.game.managers.DeforestationManager; package emu.grasscutter.game.managers.deforestation;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import dev.morphia.annotations.Transient; import dev.morphia.annotations.Transient;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.game.entity.EntityItem; import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.world.Scene; import emu.grasscutter.game.world.Scene;
import emu.grasscutter.net.proto.HitTreeNotifyOuterClass; import emu.grasscutter.net.proto.HitTreeNotifyOuterClass;
import emu.grasscutter.net.proto.VectorOuterClass; import emu.grasscutter.net.proto.VectorOuterClass;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
public class DeforestationManager { public class DeforestationManager {
final static int RECORD_EXPIRED_SECONDS = 60*5; // 5 min final static int RECORD_EXPIRED_SECONDS = 60*5; // 5 min
final static int RECORD_MAX_TIMES = 3; // max number of wood final static int RECORD_MAX_TIMES = 3; // max number of wood
final static int RECORD_MAX_TIMES_OTHER_HIT_TREE = 10; // if hit 10 times other trees, reset wood final static int RECORD_MAX_TIMES_OTHER_HIT_TREE = 10; // if hit 10 times other trees, reset wood
@Transient private final Player player; @Transient private final Player player;
@Transient private final ArrayList<HitTreeRecord> currentRecord; @Transient private final ArrayList<HitTreeRecord> currentRecord;
@Transient private final static HashMap<Integer, Integer> ColliderTypeToWoodItemID = new HashMap<>(); @Transient private final static HashMap<Integer, Integer> ColliderTypeToWoodItemID = new HashMap<>();
static { static {
/* define wood types which reflected to item id*/ /* define wood types which reflected to item id*/
ColliderTypeToWoodItemID.put(1,101301); ColliderTypeToWoodItemID.put(1,101301);
ColliderTypeToWoodItemID.put(2,101302); ColliderTypeToWoodItemID.put(2,101302);
ColliderTypeToWoodItemID.put(3,101303); ColliderTypeToWoodItemID.put(3,101303);
ColliderTypeToWoodItemID.put(4,101304); ColliderTypeToWoodItemID.put(4,101304);
ColliderTypeToWoodItemID.put(5,101305); ColliderTypeToWoodItemID.put(5,101305);
ColliderTypeToWoodItemID.put(6,101306); ColliderTypeToWoodItemID.put(6,101306);
ColliderTypeToWoodItemID.put(7,101307); ColliderTypeToWoodItemID.put(7,101307);
ColliderTypeToWoodItemID.put(8,101308); ColliderTypeToWoodItemID.put(8,101308);
ColliderTypeToWoodItemID.put(9,101309); ColliderTypeToWoodItemID.put(9,101309);
ColliderTypeToWoodItemID.put(10,101310); ColliderTypeToWoodItemID.put(10,101310);
ColliderTypeToWoodItemID.put(11,101311); ColliderTypeToWoodItemID.put(11,101311);
ColliderTypeToWoodItemID.put(12,101312); ColliderTypeToWoodItemID.put(12,101312);
} }
public DeforestationManager(Player player){ public DeforestationManager(Player player){
this.player = player; this.player = player;
this.currentRecord = new ArrayList<>(); this.currentRecord = new ArrayList<>();
} }
public void resetWood(){ public void resetWood(){
synchronized (currentRecord) { synchronized (currentRecord) {
currentRecord.clear(); currentRecord.clear();
} }
} }
public void onDeforestationInvoke(HitTreeNotifyOuterClass.HitTreeNotify hit){ public void onDeforestationInvoke(HitTreeNotifyOuterClass.HitTreeNotify hit){
synchronized (currentRecord) { synchronized (currentRecord) {
//Grasscutter.getLogger().info("onDeforestationInvoke! Wood records {}", currentRecord); //Grasscutter.getLogger().info("onDeforestationInvoke! Wood records {}", currentRecord);
VectorOuterClass.Vector hitPosition = hit.getHitPostion(); VectorOuterClass.Vector hitPosition = hit.getHitPostion();
int woodType = hit.getWoodType(); int woodType = hit.getWoodType();
if (ColliderTypeToWoodItemID.containsKey(woodType)) {// is a available wood type if (ColliderTypeToWoodItemID.containsKey(woodType)) {// is a available wood type
Scene scene = player.getScene(); Scene scene = player.getScene();
int itemId = ColliderTypeToWoodItemID.get(woodType); int itemId = ColliderTypeToWoodItemID.get(woodType);
int positionHash = hitPosition.hashCode(); int positionHash = hitPosition.hashCode();
HitTreeRecord record = searchRecord(positionHash); HitTreeRecord record = searchRecord(positionHash);
if (record == null) { if (record == null) {
record = new HitTreeRecord(positionHash); record = new HitTreeRecord(positionHash);
}else{ }else{
currentRecord.remove(record);// move it to last position currentRecord.remove(record);// move it to last position
} }
currentRecord.add(record); currentRecord.add(record);
if(currentRecord.size()>RECORD_MAX_TIMES_OTHER_HIT_TREE){ if(currentRecord.size()>RECORD_MAX_TIMES_OTHER_HIT_TREE){
currentRecord.remove(0); currentRecord.remove(0);
} }
if(record.record()) { if(record.record()) {
EntityItem entity = new EntityItem(scene, EntityItem entity = new EntityItem(scene,
null, null,
GameData.getItemDataMap().get(itemId), GameData.getItemDataMap().get(itemId),
new Position(hitPosition.getX(), hitPosition.getY(), hitPosition.getZ()), new Position(hitPosition.getX(), hitPosition.getY(), hitPosition.getZ()),
1, 1,
false); false);
scene.addEntity(entity); scene.addEntity(entity);
} }
//record.record()=false : too many wood they have deforested, no more wood dropped! //record.record()=false : too many wood they have deforested, no more wood dropped!
} else { } else {
Grasscutter.getLogger().warn("No wood type {} found.", woodType); Grasscutter.getLogger().warn("No wood type {} found.", woodType);
} }
} }
// unknown wood type // unknown wood type
} }
private HitTreeRecord searchRecord(int id){ private HitTreeRecord searchRecord(int id){
for (HitTreeRecord record : currentRecord) { for (HitTreeRecord record : currentRecord) {
if (record.getUnique() == id) { if (record.getUnique() == id) {
return record; return record;
} }
} }
return null; return null;
} }
} }
package emu.grasscutter.game.managers.DeforestationManager; package emu.grasscutter.game.managers.deforestation;
public class HitTreeRecord { public class HitTreeRecord {
private final int unique; private final int unique;
private short count; // hit this tree times private short count; // hit this tree times
private long time; // last available hitting time private long time; // last available hitting time
HitTreeRecord(int unique){ HitTreeRecord(int unique){
this.count = 0; this.count = 0;
this.time = 0; this.time = 0;
this.unique = unique; this.unique = unique;
} }
/** /**
* reset hit time * reset hit time
*/ */
private void resetTime(){ private void resetTime(){
this.time = System.currentTimeMillis(); this.time = System.currentTimeMillis();
} }
/** /**
* commit hit behavior * commit hit behavior
*/ */
public boolean record(){ public boolean record(){
if (this.count < DeforestationManager.RECORD_MAX_TIMES) { if (this.count < DeforestationManager.RECORD_MAX_TIMES) {
this.count++; this.count++;
resetTime(); resetTime();
return true; return true;
} }
// check expired // check expired
boolean isWaiting = System.currentTimeMillis() - this.time < DeforestationManager.RECORD_EXPIRED_SECONDS * 1000L; boolean isWaiting = System.currentTimeMillis() - this.time < DeforestationManager.RECORD_EXPIRED_SECONDS * 1000L;
if(isWaiting){ if(isWaiting){
return false; return false;
}else{ }else{
this.count = 1; this.count = 1;
resetTime(); resetTime();
return true; return true;
} }
} }
/** /**
* get unique id * get unique id
*/ */
public int getUnique(){ public int getUnique(){
return unique; return unique;
} }
@Override @Override
public String toString() { public String toString() {
return "HitTreeRecord{" + return "HitTreeRecord{" +
"unique=" + unique + "unique=" + unique +
", count=" + count + ", count=" + count +
", time=" + time + ", time=" + time +
'}'; '}';
} }
} }
package emu.grasscutter.game.managers.EnergyManager; package emu.grasscutter.game.managers.energy;
import java.util.List; import java.util.List;
......
package emu.grasscutter.game.managers.EnergyManager; package emu.grasscutter.game.managers.energy;
public class EnergyDropInfo { public class EnergyDropInfo {
private int ballId; private int ballId;
......
package emu.grasscutter.game.managers.EnergyManager; package emu.grasscutter.game.managers.energy;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.DataLoader; import emu.grasscutter.data.DataLoader;
......
package emu.grasscutter.game.managers.EnergyManager; package emu.grasscutter.game.managers.energy;
import java.util.List; import java.util.List;
......
package emu.grasscutter.game.managers.EnergyManager; package emu.grasscutter.game.managers.energy;
public class SkillParticleGenerationInfo { public class SkillParticleGenerationInfo {
private int value; private int value;
......
package emu.grasscutter.game.managers.ForgingManager; package emu.grasscutter.game.managers.forging;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
......
package emu.grasscutter.game.managers.ForgingManager; package emu.grasscutter.game.managers.forging;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
package emu.grasscutter.game.managers.MapMarkManager; package emu.grasscutter.game.managers.mapmark;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import emu.grasscutter.net.proto.MapMarkFromTypeOuterClass.MapMarkFromType; import emu.grasscutter.net.proto.MapMarkFromTypeOuterClass.MapMarkFromType;
import emu.grasscutter.net.proto.MapMarkPointOuterClass.MapMarkPoint; import emu.grasscutter.net.proto.MapMarkPointOuterClass.MapMarkPoint;
import emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType; import emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
@Entity @Entity
public class MapMark { public class MapMark {
private int sceneId; private int sceneId;
private String name; private String name;
private Position position; private Position position;
private MapMarkPointType mapMarkPointType; private MapMarkPointType mapMarkPointType;
private int monsterId; private int monsterId;
private MapMarkFromType mapMarkFromType; private MapMarkFromType mapMarkFromType;
private int questId; private int questId;
@Deprecated // Morhpia @Deprecated // Morhpia
public MapMark() { public MapMark() {
this.mapMarkPointType = MapMarkPointType.MAP_MARK_POINT_TYPE_MONSTER; this.mapMarkPointType = MapMarkPointType.MAP_MARK_POINT_TYPE_MONSTER;
this.mapMarkFromType = MapMarkFromType.MAP_MARK_FROM_TYPE_MONSTER; this.mapMarkFromType = MapMarkFromType.MAP_MARK_FROM_TYPE_MONSTER;
} }
public MapMark(MapMarkPoint mapMarkPoint) { public MapMark(MapMarkPoint mapMarkPoint) {
this.sceneId = mapMarkPoint.getSceneId(); this.sceneId = mapMarkPoint.getSceneId();
this.name = mapMarkPoint.getName(); this.name = mapMarkPoint.getName();
this.position = new Position( this.position = new Position(
mapMarkPoint.getPos().getX(), mapMarkPoint.getPos().getX(),
mapMarkPoint.getPos().getY(), mapMarkPoint.getPos().getY(),
mapMarkPoint.getPos().getZ() mapMarkPoint.getPos().getZ()
); );
this.mapMarkPointType = mapMarkPoint.getPointType(); this.mapMarkPointType = mapMarkPoint.getPointType();
this.monsterId = mapMarkPoint.getMonsterId(); this.monsterId = mapMarkPoint.getMonsterId();
this.mapMarkFromType = mapMarkPoint.getFromType(); this.mapMarkFromType = mapMarkPoint.getFromType();
this.questId = mapMarkPoint.getQuestId(); this.questId = mapMarkPoint.getQuestId();
} }
public int getSceneId() { public int getSceneId() {
return this.sceneId; return this.sceneId;
} }
public String getName() { public String getName() {
return this.name; return this.name;
} }
public Position getPosition() { public Position getPosition() {
return this.position; return this.position;
} }
public MapMarkPointType getMapMarkPointType() { public MapMarkPointType getMapMarkPointType() {
return this.mapMarkPointType; return this.mapMarkPointType;
} }
public int getMonsterId() { public int getMonsterId() {
return this.monsterId; return this.monsterId;
} }
public MapMarkFromType getMapMarkFromType() { public MapMarkFromType getMapMarkFromType() {
return this.mapMarkFromType; return this.mapMarkFromType;
} }
public int getQuestId() { public int getQuestId() {
return this.questId; return this.questId;
} }
} }
\ No newline at end of file
package emu.grasscutter.game.managers.MapMarkManager; package emu.grasscutter.game.managers.mapmark;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType; import emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType;
import emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq; import emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq;
import emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq.Operation; import emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq.Operation;
import emu.grasscutter.server.packet.send.PacketMarkMapRsp; import emu.grasscutter.server.packet.send.PacketMarkMapRsp;
import emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify; import emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import java.util.HashMap; import java.util.HashMap;
public class MapMarksManager { public class MapMarksManager {
public static final int mapMarkMaxCount = 150; public static final int mapMarkMaxCount = 150;
private HashMap<String, MapMark> mapMarks; private HashMap<String, MapMark> mapMarks;
private final Player player; private final Player player;
public MapMarksManager(Player player) { public MapMarksManager(Player player) {
this.player = player; this.player = player;
this.mapMarks = player.getMapMarks(); this.mapMarks = player.getMapMarks();
if (this.mapMarks == null) { this.mapMarks = new HashMap<>(); } if (this.mapMarks == null) { this.mapMarks = new HashMap<>(); }
} }
public void handleMapMarkReq(MarkMapReq req) { public void handleMapMarkReq(MarkMapReq req) {
Operation op = req.getOp(); Operation op = req.getOp();
switch (op) { switch (op) {
case OPERATION_ADD -> { case OPERATION_ADD -> {
MapMark createMark = new MapMark(req.getMark()); MapMark createMark = new MapMark(req.getMark());
// keep teleporting functionality on fishhook mark. // keep teleporting functionality on fishhook mark.
if (createMark.getMapMarkPointType() == MapMarkPointType.MAP_MARK_POINT_TYPE_FISH_POOL) { if (createMark.getMapMarkPointType() == MapMarkPointType.MAP_MARK_POINT_TYPE_FISH_POOL) {
teleport(player, createMark); teleport(player, createMark);
return; return;
} }
addMapMark(createMark); addMapMark(createMark);
} }
case OPERATION_MOD -> { case OPERATION_MOD -> {
MapMark oldMark = new MapMark(req.getOld()); MapMark oldMark = new MapMark(req.getOld());
removeMapMark(oldMark.getPosition()); removeMapMark(oldMark.getPosition());
MapMark newMark = new MapMark(req.getMark()); MapMark newMark = new MapMark(req.getMark());
addMapMark(newMark); addMapMark(newMark);
} }
case OPERATION_DEL -> { case OPERATION_DEL -> {
MapMark deleteMark = new MapMark(req.getMark()); MapMark deleteMark = new MapMark(req.getMark());
removeMapMark(deleteMark.getPosition()); removeMapMark(deleteMark.getPosition());
} }
} }
if (op != Operation.OPERATION_GET) { if (op != Operation.OPERATION_GET) {
saveMapMarks(); saveMapMarks();
} }
player.getSession().send(new PacketMarkMapRsp(getMapMarks())); player.getSession().send(new PacketMarkMapRsp(getMapMarks()));
} }
public HashMap<String, MapMark> getMapMarks() { public HashMap<String, MapMark> getMapMarks() {
return mapMarks; return mapMarks;
} }
public String getMapMarkKey(Position position) { public String getMapMarkKey(Position position) {
return "x" + (int)position.getX()+ "z" + (int)position.getZ(); return "x" + (int)position.getX()+ "z" + (int)position.getZ();
} }
public void removeMapMark(Position position) { public void removeMapMark(Position position) {
mapMarks.remove(getMapMarkKey(position)); mapMarks.remove(getMapMarkKey(position));
} }
public void addMapMark(MapMark mapMark) { public void addMapMark(MapMark mapMark) {
if (mapMarks.size() < mapMarkMaxCount) { if (mapMarks.size() < mapMarkMaxCount) {
mapMarks.put(getMapMarkKey(mapMark.getPosition()), mapMark); mapMarks.put(getMapMarkKey(mapMark.getPosition()), mapMark);
} }
} }
private void saveMapMarks() { private void saveMapMarks() {
player.setMapMarks(mapMarks); player.setMapMarks(mapMarks);
player.save(); player.save();
} }
private void teleport(Player player, MapMark mapMark) { private void teleport(Player player, MapMark mapMark) {
float y; float y;
try { try {
y = (float)Integer.parseInt(mapMark.getName()); y = (float)Integer.parseInt(mapMark.getName());
} catch (Exception e) { } catch (Exception e) {
y = 300; y = 300;
} }
Position pos = mapMark.getPosition(); Position pos = mapMark.getPosition();
player.getPos().set(pos.getX(), y, pos.getZ()); player.getPos().set(pos.getX(), y, pos.getZ());
if (mapMark.getSceneId() != player.getSceneId()) { if (mapMark.getSceneId() != player.getSceneId()) {
player.getWorld().transferPlayerToScene(player, mapMark.getSceneId(), player.getPos()); player.getWorld().transferPlayerToScene(player, mapMark.getSceneId(), player.getPos());
} }
player.getScene().broadcastPacket(new PacketSceneEntityAppearNotify(player)); player.getScene().broadcastPacket(new PacketSceneEntityAppearNotify(player));
} }
} }
package emu.grasscutter.game.managers.StaminaManager; package emu.grasscutter.game.managers.stamina;
public interface AfterUpdateStaminaListener { public interface AfterUpdateStaminaListener {
/** /**
* onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina. * onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina.
* This gives listeners a chance to intercept this update. * This gives listeners a chance to intercept this update.
* *
* @param reason Why updating stamina. * @param reason Why updating stamina.
* @param newStamina New Stamina value. * @param newStamina New Stamina value.
*/ */
void onAfterUpdateStamina(String reason, int newStamina, boolean isCharacterStamina); void onAfterUpdateStamina(String reason, int newStamina, boolean isCharacterStamina);
} }
package emu.grasscutter.game.managers.StaminaManager; package emu.grasscutter.game.managers.stamina;
public interface BeforeUpdateStaminaListener { public interface BeforeUpdateStaminaListener {
/** /**
* onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina. * onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina.
* This gives listeners a chance to intercept this update. * This gives listeners a chance to intercept this update.
* @param reason Why updating stamina. * @param reason Why updating stamina.
* @param newStamina New ABSOLUTE stamina value. * @param newStamina New ABSOLUTE stamina value.
* @return true if you want to cancel this update, otherwise false. * @return true if you want to cancel this update, otherwise false.
*/ */
int onBeforeUpdateStamina(String reason, int newStamina, boolean isCharacterStamina); int onBeforeUpdateStamina(String reason, int newStamina, boolean isCharacterStamina);
/** /**
* onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina. * onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina.
* This gives listeners a chance to intercept this update. * This gives listeners a chance to intercept this update.
* @param reason Why updating stamina. * @param reason Why updating stamina.
* @param consumption ConsumptionType and RELATIVE stamina change amount. * @param consumption ConsumptionType and RELATIVE stamina change amount.
* @return true if you want to cancel this update, otherwise false. * @return true if you want to cancel this update, otherwise false.
*/ */
Consumption onBeforeUpdateStamina(String reason, Consumption consumption, boolean isCharacterStamina); Consumption onBeforeUpdateStamina(String reason, Consumption consumption, boolean isCharacterStamina);
} }
\ No newline at end of file
package emu.grasscutter.game.managers.StaminaManager; package emu.grasscutter.game.managers.stamina;
public class Consumption { public class Consumption {
public ConsumptionType type = ConsumptionType.None; public ConsumptionType type = ConsumptionType.None;
public int amount = 0; public int amount = 0;
public Consumption(ConsumptionType type, int amount) { public Consumption(ConsumptionType type, int amount) {
this.type = type; this.type = type;
this.amount = amount; this.amount = amount;
} }
public Consumption(ConsumptionType type) { public Consumption(ConsumptionType type) {
this(type, type.amount); this(type, type.amount);
} }
public Consumption() { public Consumption() {
} }
} }
package emu.grasscutter.game.managers.StaminaManager; package emu.grasscutter.game.managers.stamina;
public enum ConsumptionType { public enum ConsumptionType {
None(0), None(0),
// consume // consume
CLIMBING(-150), CLIMBING(-150),
CLIMB_START(-500), CLIMB_START(-500),
CLIMB_JUMP(-2500), CLIMB_JUMP(-2500),
DASH(-360), DASH(-360),
FIGHT(0), // See StaminaManager.getFightConsumption() FIGHT(0), // See StaminaManager.getFightConsumption()
FLY(-60), FLY(-60),
// Slow swimming is handled per movement, not per second. // Slow swimming is handled per movement, not per second.
// Arm movement frequency depends on gender/age/height. // Arm movement frequency depends on gender/age/height.
// TODO: Instead of cost -80 per tick, find a proper way to calculate cost. // TODO: Instead of cost -80 per tick, find a proper way to calculate cost.
SKIFF_DASH(-204), SKIFF_DASH(-204),
SPRINT(-1800), SPRINT(-1800),
SWIM_DASH_START(-2000), SWIM_DASH_START(-2000),
SWIM_DASH(-204), // -10.2 per second, 5Hz = -204 each tick SWIM_DASH(-204), // -10.2 per second, 5Hz = -204 each tick
SWIMMING(-80), SWIMMING(-80),
TALENT_DASH(-300), // -1500 per second, 5Hz = -300 each tick TALENT_DASH(-300), // -1500 per second, 5Hz = -300 each tick
TALENT_DASH_START(-1000), TALENT_DASH_START(-1000),
// restore // restore
POWERED_FLY(500), POWERED_FLY(500),
POWERED_SKIFF(500), POWERED_SKIFF(500),
RUN(500), RUN(500),
SKIFF(500), SKIFF(500),
STANDBY(500), STANDBY(500),
WALK(500); WALK(500);
public final int amount; public final int amount;
ConsumptionType(int amount) { ConsumptionType(int amount) {
this.amount = amount; this.amount = amount;
} }
} }
\ No newline at end of file
# Stamina Manager # Stamina Manager
--- ---
## UpdateStamina ## UpdateStamina
```java ```java
// will use consumption.consumptionType as reason // will use consumption.consumptionType as reason
public int updateStaminaRelative(GameSession session, Consumption consumption); public int updateStaminaRelative(GameSession session, Consumption consumption);
``` ```
```java ```java
public int updateStaminaAbsolute(GameSession session, String reason, int newStamina) public int updateStaminaAbsolute(GameSession session, String reason, int newStamina)
``` ```
--- ---
## Pause and Resume ## Pause and Resume
```java ```java
public void startSustainedStaminaHandler() public void startSustainedStaminaHandler()
``` ```
```java ```java
public void stopSustainedStaminaHandler() public void stopSustainedStaminaHandler()
``` ```
--- ---
## Stamina change listeners and intercepting ## Stamina change listeners and intercepting
### BeforeUpdateStaminaListener ### BeforeUpdateStaminaListener
```java ```java
import emu.grasscutter.game.managers.StaminaManager.BeforeUpdateStaminaListener; import emu.grasscutter.game.managers.StaminaManager.BeforeUpdateStaminaListener;
// Listener sample: plugin disable CLIMB_JUMP stamina cost. // Listener sample: plugin disable CLIMB_JUMP stamina cost.
private class MyClass implements BeforeUpdateStaminaListener { private class MyClass implements BeforeUpdateStaminaListener {
// Make your class implement the listener, and pass in your class as a listener. // Make your class implement the listener, and pass in your class as a listener.
public MyClass() { public MyClass() {
getStaminaManager().registerBeforeUpdateStaminaListener("myClass", this); getStaminaManager().registerBeforeUpdateStaminaListener("myClass", this);
} }
@Override @Override
public boolean onBeforeUpdateStamina(String reason, int newStamina) { public boolean onBeforeUpdateStamina(String reason, int newStamina) {
// do not intercept this update // do not intercept this update
return false; return false;
} }
@Override @Override
public boolean onBeforeUpdateStamina(String reason, Consumption consumption) { public boolean onBeforeUpdateStamina(String reason, Consumption consumption) {
// Try to intercept if this update is CLIMB_JUMP // Try to intercept if this update is CLIMB_JUMP
if (consumption.consumptionType == ConsumptionType.CLIMB_JUMP) { if (consumption.consumptionType == ConsumptionType.CLIMB_JUMP) {
return true; return true;
} }
// If it is not CLIMB_JUMP, do not intercept. // If it is not CLIMB_JUMP, do not intercept.
return false; return false;
} }
} }
``` ```
### AfterUpdateStaminaListener ### AfterUpdateStaminaListener
```java ```java
import emu.grasscutter.game.managers.StaminaManager.AfterUpdateStaminaListener; import emu.grasscutter.game.managers.StaminaManager.AfterUpdateStaminaListener;
// Listener sample: plugin listens for changes already made. // Listener sample: plugin listens for changes already made.
private class MyClass implements AfterUpdateStaminaListener { private class MyClass implements AfterUpdateStaminaListener {
// Make your class implement the listener, and pass in your class as a listener. // Make your class implement the listener, and pass in your class as a listener.
public MyClass() { public MyClass() {
registerAfterUpdateStaminaListener("myClass", this); registerAfterUpdateStaminaListener("myClass", this);
} }
@Override @Override
public void onAfterUpdateStamina(String reason, int newStamina) { public void onAfterUpdateStamina(String reason, int newStamina) {
// ... // ...
} }
} }
``` ```
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment