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

Cleanup package names

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