Copy some files from Grasscutter-Quests

NOT completely finished, nor is it completely done. Protocol issues remain! (including lack of packet IDs)
This commit is contained in:
KingRainbow44
2023-04-01 18:06:30 -04:00
parent 262ee38ded
commit daa51e53b7
381 changed files with 10285 additions and 9150 deletions

View File

@@ -0,0 +1,24 @@
package emu.grasscutter.utils;
/* Various methods to convert from A -> B. */
public interface ConversionUtils {
/**
* Converts in-game minutes to days.
*
* @param minutes The elapsed in-game minutes.
* @return The elapsed in-game days.
*/
static long gameTimeToDays(long minutes) {
return minutes / 1440;
}
/**
* Converts in-game minutes to hours.
*
* @param minutes The elapsed in-game minutes.
* @return The elapsed in-game hours.
*/
static long gameTimeToHours(long minutes) {
return minutes / 60;
}
}

View File

@@ -1,118 +1,113 @@
package emu.grasscutter.utils;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import dev.morphia.annotations.Entity;
import lombok.Getter;
import lombok.Setter;
@Entity
public class GridPosition implements Serializable {
private static final long serialVersionUID = -2001232300615923575L;
@Getter @Setter private int x;
@Getter @Setter private int z;
@Getter @Setter private int width;
public GridPosition() {}
public GridPosition(int x, int y, int width) {
set(x, y, width);
}
public GridPosition(GridPosition pos) {
this.set(pos);
}
public GridPosition(Position pos, int width) {
this.set((int)(pos.getX() / width), (int)(pos.getZ() / width), width);
}
public GridPosition(List<Integer> xzwidth) {
this.width = xzwidth.get(2);
this.z = xzwidth.get(1);
this.x = xzwidth.get(0);
}
public GridPosition(String str) throws IOException {
String[] listOfParams = str.replace(" ", "").replace("(", "").replace(")", "").split(",");
if(listOfParams.length != 3)
throw new IOException("invalid size on GridPosition definition - ");
try {
this.x = Integer.parseInt(listOfParams[0]);
this.z = Integer.parseInt(listOfParams[1]);
this.width = Integer.parseInt(listOfParams[2]);
} catch(NumberFormatException ignored) {
throw new IOException("invalid number on GridPosition definition - ");
}
}
public GridPosition set(int x, int z) {
this.x = x;
this.z = z;
return this;
}
public GridPosition set(int x, int z, int width) {
this.x = x;
this.z = z;
this.width = width;
return this;
}
// Deep copy
public GridPosition set(GridPosition pos) {
return this.set(pos.getX(), pos.getZ(), pos.getWidth());
}
public GridPosition addClone(int x, int z) {
GridPosition pos = clone();
pos.x += x;
pos.z += z;
return pos;
}
@Override
public GridPosition clone() {
return new GridPosition(x, z, width);
}
@Override
public String toString() {
return "(" + this.getX() + ", " + this.getZ() + ", " + this.getWidth() + ")";
}
public int[] toIntArray() {
return new int[]{ x, z, width };
}
public int[] toXZIntArray() {
return new int[]{ x, z };
}
@Override
public int hashCode()
{
int result = (int) (x ^ (x >>> 32));
result = 31 * result + (int) (z ^ (z >>> 32));
result = 31 * result + (int) (width ^ (width >>> 32));
return result;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null)
return false;
if (getClass() != o.getClass())
return false;
GridPosition pos = (GridPosition) o;
// field comparison
return pos.x == x && pos.z == z && pos.width == width;
}
}
package emu.grasscutter.utils;
import dev.morphia.annotations.Entity;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
@Entity
public class GridPosition implements Serializable {
private static final long serialVersionUID = -2001232300615923575L;
@Getter @Setter private int x;
@Getter @Setter private int z;
@Getter @Setter private int width;
public GridPosition() {}
public GridPosition(int x, int y, int width) {
set(x, y, width);
}
public GridPosition(GridPosition pos) {
this.set(pos);
}
public GridPosition(Position pos, int width) {
this.set((int) (pos.getX() / width), (int) (pos.getZ() / width), width);
}
public GridPosition(List<Integer> xzwidth) {
this.width = xzwidth.get(2);
this.z = xzwidth.get(1);
this.x = xzwidth.get(0);
}
public GridPosition(String str) throws IOException {
String[] listOfParams = str.replace(" ", "").replace("(", "").replace(")", "").split(",");
if (listOfParams.length != 3)
throw new IOException("invalid size on GridPosition definition - ");
try {
this.x = Integer.parseInt(listOfParams[0]);
this.z = Integer.parseInt(listOfParams[1]);
this.width = Integer.parseInt(listOfParams[2]);
} catch (NumberFormatException ignored) {
throw new IOException("invalid number on GridPosition definition - ");
}
}
public GridPosition set(int x, int z) {
this.x = x;
this.z = z;
return this;
}
public GridPosition set(int x, int z, int width) {
this.x = x;
this.z = z;
this.width = width;
return this;
}
// Deep copy
public GridPosition set(GridPosition pos) {
return this.set(pos.getX(), pos.getZ(), pos.getWidth());
}
public GridPosition addClone(int x, int z) {
GridPosition pos = clone();
pos.x += x;
pos.z += z;
return pos;
}
@Override
public GridPosition clone() {
return new GridPosition(x, z, width);
}
@Override
public String toString() {
return "(" + this.getX() + ", " + this.getZ() + ", " + this.getWidth() + ")";
}
public int[] toIntArray() {
return new int[] {x, z, width};
}
public int[] toXZIntArray() {
return new int[] {x, z};
}
@Override
public int hashCode() {
int result = (int) (x ^ (x >>> 32));
result = 31 * result + (int) (z ^ (z >>> 32));
result = 31 * result + (int) (width ^ (width >>> 32));
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (getClass() != o.getClass()) return false;
GridPosition pos = (GridPosition) o;
// field comparison
return pos.x == x && pos.z == z && pos.width == width;
}
}

View File

@@ -1,66 +1,68 @@
package emu.grasscutter.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
public class KahnsSort {
public static class Node {
int source, dest; //Dest is a value, and source too
public Node(int source, int dest) {
this.source = source;
this.dest = dest;
}
}
public static class Graph {
Map<Integer, List<Integer>> mainList;
Map<Integer, Integer> degreeList;
List<Integer> nodeList;
public Graph(List<Node> nodes, List<Integer> nodeList) {
mainList = new HashMap<>();
this.nodeList = nodeList;
for(int i = 0; i < nodeList.size(); i++) mainList.put(nodeList.get(i), new ArrayList<>());
degreeList = new HashMap<>();
for(int i = 0; i < nodeList.size(); i++) degreeList.put(nodeList.get(i), 0);
for(Node node : nodes) {
mainList.get(node.source).add(node.dest);
degreeList.replace(node.dest, degreeList.get(node.dest) + 1);
}
}
}
public static List<Integer> doSort(Graph graph) {
List<Integer> orderedList = new ArrayList<>();
Map<Integer, Integer> degreeList = graph.degreeList;
Stack<Integer> zeroStack = new Stack<>();
degreeList.forEach((key, value) -> {
if(value == 0) zeroStack.add(key);
});
while(!zeroStack.isEmpty()) {
int element = zeroStack.pop();
//If the list is empty then this node
if(!graph.mainList.get(element).isEmpty()) orderedList.add(element);
for(int topElement : graph.mainList.get(element)) {
degreeList.replace(topElement, degreeList.get(topElement) - 1);
if(degreeList.get(topElement) == 0) zeroStack.add(topElement);
}
}
if(degreeList.values().stream().filter(value -> value != 0).count() != 0) return null; //Loop found
return orderedList;
}
}
package emu.grasscutter.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
public class KahnsSort {
public static class Node {
int source, dest; // Dest is a value, and source too
public Node(int source, int dest) {
this.source = source;
this.dest = dest;
}
}
public static class Graph {
Map<Integer, List<Integer>> mainList;
Map<Integer, Integer> degreeList;
List<Integer> nodeList;
public Graph(List<Node> nodes, List<Integer> nodeList) {
mainList = new HashMap<>();
this.nodeList = nodeList;
for (int i = 0; i < nodeList.size(); i++) mainList.put(nodeList.get(i), new ArrayList<>());
degreeList = new HashMap<>();
for (int i = 0; i < nodeList.size(); i++) degreeList.put(nodeList.get(i), 0);
for (Node node : nodes) {
mainList.get(node.source).add(node.dest);
degreeList.replace(node.dest, degreeList.get(node.dest) + 1);
}
}
}
public static List<Integer> doSort(Graph graph) {
List<Integer> orderedList = new ArrayList<>();
Map<Integer, Integer> degreeList = graph.degreeList;
Stack<Integer> zeroStack = new Stack<>();
degreeList.forEach(
(key, value) -> {
if (value == 0) zeroStack.add(key);
});
while (!zeroStack.isEmpty()) {
int element = zeroStack.pop();
// If the list is empty then this node
if (!graph.mainList.get(element).isEmpty()) orderedList.add(element);
for (int topElement : graph.mainList.get(element)) {
degreeList.replace(topElement, degreeList.get(topElement) - 1);
if (degreeList.get(topElement) == 0) zeroStack.add(topElement);
}
}
if (degreeList.values().stream().filter(value -> value != 0).count() != 0)
return null; // Loop found
return orderedList;
}
}

View File

@@ -8,7 +8,7 @@ import com.google.gson.JsonObject;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.data.excels.AchievementData;
import emu.grasscutter.data.excels.achievement.AchievementData;
import emu.grasscutter.game.player.Player;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;