mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-25 03:53:00 +08:00
Fix whitespace [skip actions]
This commit is contained in:
parent
d1d39db56c
commit
025e5d3c1c
@ -246,7 +246,7 @@ public final class Grasscutter {
|
|||||||
public static Language getLanguage(String langCode) {
|
public static Language getLanguage(String langCode) {
|
||||||
return Language.getLanguage(langCode);
|
return Language.getLanguage(langCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ServerRunMode getRunMode() {
|
public static ServerRunMode getRunMode() {
|
||||||
return Grasscutter.runModeOverride != null ? Grasscutter.runModeOverride : SERVER.runMode;
|
return Grasscutter.runModeOverride != null ? Grasscutter.runModeOverride : SERVER.runMode;
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ public class ResourceLoader {
|
|||||||
GameData.proudSkillGroupLevels
|
GameData.proudSkillGroupLevels
|
||||||
.computeIfAbsent(data.getProudSkillGroupId(), i -> new IntArraySet())
|
.computeIfAbsent(data.getProudSkillGroupId(), i -> new IntArraySet())
|
||||||
.add(data.getLevel()));
|
.add(data.getLevel()));
|
||||||
GameData.getAvatarSkillDataMap().forEach((id, data) ->
|
GameData.getAvatarSkillDataMap().forEach((id, data) ->
|
||||||
GameData.avatarSkillLevels.put((int) id, GameData.proudSkillGroupLevels.get(data.getProudSkillGroupId())));
|
GameData.avatarSkillLevels.put((int) id, GameData.proudSkillGroupLevels.get(data.getProudSkillGroupId())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,39 +10,39 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
|||||||
|
|
||||||
@ResourceType(name = "DailyDungeonConfigData.json")
|
@ResourceType(name = "DailyDungeonConfigData.json")
|
||||||
public class DailyDungeonData extends GameResource {
|
public class DailyDungeonData extends GameResource {
|
||||||
private int id;
|
private int id;
|
||||||
private int[] monday;
|
private int[] monday;
|
||||||
private int[] tuesday;
|
private int[] tuesday;
|
||||||
private int[] wednesday;
|
private int[] wednesday;
|
||||||
private int[] thursday;
|
private int[] thursday;
|
||||||
private int[] friday;
|
private int[] friday;
|
||||||
private int[] saturday;
|
private int[] saturday;
|
||||||
private int[] sunday;
|
private int[] sunday;
|
||||||
|
|
||||||
private static final int[] empty = new int[0];
|
|
||||||
private final Int2ObjectMap<int[]> map;
|
|
||||||
|
|
||||||
public DailyDungeonData() {
|
|
||||||
this.map = new Int2ObjectOpenHashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getId() {
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getDungeonsByDay(int day) {
|
|
||||||
return map.getOrDefault(day, empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
private static final int[] empty = new int[0];
|
||||||
public void onLoad() {
|
private final Int2ObjectMap<int[]> map;
|
||||||
map.put(Calendar.MONDAY, monday);
|
|
||||||
map.put(Calendar.TUESDAY, tuesday);
|
public DailyDungeonData() {
|
||||||
map.put(Calendar.WEDNESDAY, wednesday);
|
this.map = new Int2ObjectOpenHashMap<>();
|
||||||
map.put(Calendar.THURSDAY, thursday);
|
}
|
||||||
map.put(Calendar.FRIDAY, friday);
|
|
||||||
map.put(Calendar.SATURDAY, saturday);
|
@Override
|
||||||
map.put(Calendar.SUNDAY, sunday);
|
public int getId() {
|
||||||
}
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getDungeonsByDay(int day) {
|
||||||
|
return map.getOrDefault(day, empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
map.put(Calendar.MONDAY, monday);
|
||||||
|
map.put(Calendar.TUESDAY, tuesday);
|
||||||
|
map.put(Calendar.WEDNESDAY, wednesday);
|
||||||
|
map.put(Calendar.THURSDAY, thursday);
|
||||||
|
map.put(Calendar.FRIDAY, friday);
|
||||||
|
map.put(Calendar.SATURDAY, saturday);
|
||||||
|
map.put(Calendar.SUNDAY, sunday);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ public class ItemData extends GameResource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public static class WeaponProperty {
|
public static class WeaponProperty {
|
||||||
private FightProperty propType;
|
private FightProperty propType;
|
||||||
|
@ -50,10 +50,10 @@ public final class DatabaseManager {
|
|||||||
// Set mapper options.
|
// Set mapper options.
|
||||||
MapperOptions mapperOptions = MapperOptions.builder()
|
MapperOptions mapperOptions = MapperOptions.builder()
|
||||||
.storeEmpties(true).storeNulls(false).build();
|
.storeEmpties(true).storeNulls(false).build();
|
||||||
|
|
||||||
// Create data store.
|
// Create data store.
|
||||||
gameDatastore = Morphia.createDatastore(gameMongoClient, DATABASE.game.collection, mapperOptions);
|
gameDatastore = Morphia.createDatastore(gameMongoClient, DATABASE.game.collection, mapperOptions);
|
||||||
|
|
||||||
// Map classes.
|
// Map classes.
|
||||||
Class<?>[] entities = new Reflections(Grasscutter.class.getPackageName())
|
Class<?>[] entities = new Reflections(Grasscutter.class.getPackageName())
|
||||||
.getTypesAnnotatedWith(Entity.class)
|
.getTypesAnnotatedWith(Entity.class)
|
||||||
@ -71,15 +71,15 @@ public final class DatabaseManager {
|
|||||||
|
|
||||||
if (SERVER.runMode == ServerRunMode.GAME_ONLY) {
|
if (SERVER.runMode == ServerRunMode.GAME_ONLY) {
|
||||||
MongoClient dispatchMongoClient = MongoClients.create(DATABASE.server.connectionUri);
|
MongoClient dispatchMongoClient = MongoClients.create(DATABASE.server.connectionUri);
|
||||||
|
|
||||||
dispatchDatastore = Morphia.createDatastore(dispatchMongoClient, DATABASE.server.collection, mapperOptions);
|
dispatchDatastore = Morphia.createDatastore(dispatchMongoClient, DATABASE.server.collection, mapperOptions);
|
||||||
dispatchDatastore.getMapper().map(new Class<?>[] {DatabaseCounter.class, Account.class});
|
dispatchDatastore.getMapper().map(new Class<?>[] {DatabaseCounter.class, Account.class});
|
||||||
|
|
||||||
// Ensure indexes for dispatch datastore
|
// Ensure indexes for dispatch datastore
|
||||||
ensureIndexes(dispatchDatastore);
|
ensureIndexes(dispatchDatastore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures the database indexes exist and rebuilds them if there is an error with them
|
* Ensures the database indexes exist and rebuilds them if there is an error with them
|
||||||
* @param datastore The datastore to ensure indexes on
|
* @param datastore The datastore to ensure indexes on
|
||||||
|
@ -39,11 +39,11 @@ public class GameHome {
|
|||||||
ConcurrentHashMap<Integer, HomeSceneItem> sceneMap;
|
ConcurrentHashMap<Integer, HomeSceneItem> sceneMap;
|
||||||
Set<Integer> unlockedHomeBgmList;
|
Set<Integer> unlockedHomeBgmList;
|
||||||
|
|
||||||
public void save(){
|
public void save() {
|
||||||
DatabaseHelper.saveHome(this);
|
DatabaseHelper.saveHome(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GameHome getByUid(Integer uid){
|
public static GameHome getByUid(Integer uid) {
|
||||||
var home = DatabaseHelper.getHomeByUid(uid);
|
var home = DatabaseHelper.getHomeByUid(uid);
|
||||||
if (home == null) {
|
if (home == null) {
|
||||||
home = GameHome.create(uid);
|
home = GameHome.create(uid);
|
||||||
@ -51,7 +51,7 @@ public class GameHome {
|
|||||||
return home;
|
return home;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GameHome create(Integer uid){
|
public static GameHome create(Integer uid) {
|
||||||
return GameHome.of()
|
return GameHome.of()
|
||||||
.ownerUid(uid)
|
.ownerUid(uid)
|
||||||
.level(1)
|
.level(1)
|
||||||
@ -62,7 +62,7 @@ public class GameHome {
|
|||||||
public HomeSceneItem getHomeSceneItem(int sceneId) {
|
public HomeSceneItem getHomeSceneItem(int sceneId) {
|
||||||
return sceneMap.computeIfAbsent(sceneId, e -> {
|
return sceneMap.computeIfAbsent(sceneId, e -> {
|
||||||
var defaultItem = GameData.getHomeworldDefaultSaveData().get(sceneId);
|
var defaultItem = GameData.getHomeworldDefaultSaveData().get(sceneId);
|
||||||
if (defaultItem != null){
|
if (defaultItem != null) {
|
||||||
Grasscutter.getLogger().info("Set player {} home {} to initial setting", ownerUid, sceneId);
|
Grasscutter.getLogger().info("Set player {} home {} to initial setting", ownerUid, sceneId);
|
||||||
return HomeSceneItem.parseFrom(defaultItem, sceneId);
|
return HomeSceneItem.parseFrom(defaultItem, sceneId);
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ public class GameHome {
|
|||||||
return this.player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HomeWorldLevelData getLevelData(){
|
public HomeWorldLevelData getLevelData() {
|
||||||
return GameData.getHomeWorldLevelDataMap().get(level);
|
return GameData.getHomeWorldLevelDataMap().get(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +42,10 @@ public class HomeSceneItem {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(HomeSceneArrangementInfo arrangementInfo){
|
public void update(HomeSceneArrangementInfo arrangementInfo) {
|
||||||
for(var blockItem : arrangementInfo.getBlockArrangementInfoListList()){
|
for (var blockItem : arrangementInfo.getBlockArrangementInfoListList()) {
|
||||||
var block = this.blockItems.get(blockItem.getBlockId());
|
var block = this.blockItems.get(blockItem.getBlockId());
|
||||||
if(block == null){
|
if (block == null) {
|
||||||
Grasscutter.getLogger().warn("Could not found the Home Block {}", blockItem.getBlockId());
|
Grasscutter.getLogger().warn("Could not found the Home Block {}", blockItem.getBlockId());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -61,20 +61,20 @@ public class HomeSceneItem {
|
|||||||
this.tmpVersion = arrangementInfo.getTmpVersion();
|
this.tmpVersion = arrangementInfo.getTmpVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRoomSceneId(){
|
public int getRoomSceneId() {
|
||||||
if(mainHouse == null || mainHouse.getAsItem() == null){
|
if (mainHouse == null || mainHouse.getAsItem() == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return mainHouse.getAsItem().getRoomSceneId();
|
return mainHouse.getAsItem().getRoomSceneId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int calComfort(){
|
public int calComfort() {
|
||||||
return this.blockItems.values().stream()
|
return this.blockItems.values().stream()
|
||||||
.mapToInt(HomeBlockItem::calComfort)
|
.mapToInt(HomeBlockItem::calComfort)
|
||||||
.sum();
|
.sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HomeSceneArrangementInfo toProto(){
|
public HomeSceneArrangementInfo toProto() {
|
||||||
var proto = HomeSceneArrangementInfo.newBuilder();
|
var proto = HomeSceneArrangementInfo.newBuilder();
|
||||||
blockItems.values().forEach(b -> proto.addBlockArrangementInfoList(b.toProto()));
|
blockItems.values().forEach(b -> proto.addBlockArrangementInfoList(b.toProto()));
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ public class HomeSceneItem {
|
|||||||
.setUnk2700BJHAMKKECEI(homeBgmId)
|
.setUnk2700BJHAMKKECEI(homeBgmId)
|
||||||
.setTmpVersion(tmpVersion);
|
.setTmpVersion(tmpVersion);
|
||||||
|
|
||||||
if(mainHouse != null){
|
if (mainHouse != null) {
|
||||||
proto.setMainHouse(mainHouse.toProto());
|
proto.setMainHouse(mainHouse.toProto());
|
||||||
}
|
}
|
||||||
return proto.build();
|
return proto.build();
|
||||||
|
@ -39,59 +39,59 @@ import lombok.Setter;
|
|||||||
|
|
||||||
@Entity(value = "items", useDiscriminator = false)
|
@Entity(value = "items", useDiscriminator = false)
|
||||||
public class GameItem {
|
public class GameItem {
|
||||||
@Id private ObjectId id;
|
@Id private ObjectId id;
|
||||||
@Indexed private int ownerId;
|
@Indexed private int ownerId;
|
||||||
@Getter @Setter private int itemId;
|
@Getter @Setter private int itemId;
|
||||||
@Getter @Setter private int count;
|
@Getter @Setter private int count;
|
||||||
|
|
||||||
@Transient @Getter private long guid; // Player unique id
|
@Transient @Getter private long guid; // Player unique id
|
||||||
@Transient @Getter @Setter private ItemData itemData;
|
@Transient @Getter @Setter private ItemData itemData;
|
||||||
|
|
||||||
// Equips
|
// Equips
|
||||||
@Getter @Setter private int level;
|
@Getter @Setter private int level;
|
||||||
@Getter @Setter private int exp;
|
@Getter @Setter private int exp;
|
||||||
@Getter @Setter private int totalExp;
|
@Getter @Setter private int totalExp;
|
||||||
@Getter @Setter private int promoteLevel;
|
@Getter @Setter private int promoteLevel;
|
||||||
@Getter @Setter private boolean locked;
|
@Getter @Setter private boolean locked;
|
||||||
|
|
||||||
// Weapon
|
// Weapon
|
||||||
@Getter private List<Integer> affixes;
|
@Getter private List<Integer> affixes;
|
||||||
@Getter @Setter private int refinement = 0;
|
@Getter @Setter private int refinement = 0;
|
||||||
|
|
||||||
// Relic
|
// Relic
|
||||||
@Getter @Setter private int mainPropId;
|
@Getter @Setter private int mainPropId;
|
||||||
@Getter private List<Integer> appendPropIdList;
|
@Getter private List<Integer> appendPropIdList;
|
||||||
|
|
||||||
@Getter @Setter private int equipCharacter;
|
@Getter @Setter private int equipCharacter;
|
||||||
@Transient @Getter @Setter private int weaponEntityId;
|
@Transient @Getter @Setter private int weaponEntityId;
|
||||||
|
|
||||||
public GameItem() {
|
public GameItem() {
|
||||||
// Morphia only
|
// Morphia only
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameItem(int itemId) {
|
public GameItem(int itemId) {
|
||||||
this(GameData.getItemDataMap().get(itemId));
|
this(GameData.getItemDataMap().get(itemId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameItem(int itemId, int count) {
|
public GameItem(int itemId, int count) {
|
||||||
this(GameData.getItemDataMap().get(itemId), count);
|
this(GameData.getItemDataMap().get(itemId), count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GameItem(ItemParamData itemParamData) {
|
||||||
|
this(itemParamData.getId(), itemParamData.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameItem(ItemData data) {
|
||||||
|
this(data, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameItem(ItemData data, int count) {
|
||||||
|
this.itemId = data.getId();
|
||||||
|
this.itemData = data;
|
||||||
|
|
||||||
public GameItem(ItemParamData itemParamData) {
|
|
||||||
this(itemParamData.getId(), itemParamData.getCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
public GameItem(ItemData data) {
|
|
||||||
this(data, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GameItem(ItemData data, int count) {
|
|
||||||
this.itemId = data.getId();
|
|
||||||
this.itemData = data;
|
|
||||||
|
|
||||||
switch (data.getItemType()) {
|
switch (data.getItemType()) {
|
||||||
case ITEM_VIRTUAL:
|
case ITEM_VIRTUAL:
|
||||||
this.count = count;
|
this.count = count;
|
||||||
break;
|
break;
|
||||||
case ITEM_WEAPON:
|
case ITEM_WEAPON:
|
||||||
this.count = 1;
|
this.count = 1;
|
||||||
@ -114,72 +114,72 @@ public class GameItem {
|
|||||||
if (mainPropData != null) {
|
if (mainPropData != null) {
|
||||||
this.mainPropId = mainPropData.getId();
|
this.mainPropId = mainPropData.getId();
|
||||||
}
|
}
|
||||||
// Create extra stats
|
// Create extra stats
|
||||||
this.addAppendProps(data.getAppendPropNum());
|
this.addAppendProps(data.getAppendPropNum());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.count = Math.min(count, data.getStackLimit());
|
this.count = Math.min(count, data.getStackLimit());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOwnerId() {
|
public int getOwnerId() {
|
||||||
return ownerId;
|
return ownerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOwner(Player player) {
|
public void setOwner(Player player) {
|
||||||
this.ownerId = player.getUid();
|
this.ownerId = player.getUid();
|
||||||
this.guid = player.getNextGameGuid();
|
this.guid = player.getNextGameGuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectId getObjectId() {
|
public ObjectId getObjectId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemType getItemType() {
|
|
||||||
return this.itemData.getItemType();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getMinPromoteLevel(int level) {
|
public ItemType getItemType() {
|
||||||
if (level > 80) {
|
return this.itemData.getItemType();
|
||||||
return 6;
|
}
|
||||||
} else if (level > 70) {
|
|
||||||
return 5;
|
public static int getMinPromoteLevel(int level) {
|
||||||
} else if (level > 60) {
|
if (level > 80) {
|
||||||
return 4;
|
return 6;
|
||||||
} else if (level > 50) {
|
} else if (level > 70) {
|
||||||
return 3;
|
return 5;
|
||||||
} else if (level > 40) {
|
} else if (level > 60) {
|
||||||
return 2;
|
return 4;
|
||||||
} else if (level > 20) {
|
} else if (level > 50) {
|
||||||
return 1;
|
return 3;
|
||||||
}
|
} else if (level > 40) {
|
||||||
return 0;
|
return 2;
|
||||||
}
|
} else if (level > 20) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEquipSlot() {
|
||||||
|
return this.getItemData().getEquipType().getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEquipped() {
|
||||||
|
return this.getEquipCharacter() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDestroyable() {
|
||||||
|
return !this.isLocked() && !this.isEquipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAppendProp() {
|
||||||
|
if (this.appendPropIdList == null) {
|
||||||
|
this.appendPropIdList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.appendPropIdList.size() < 4) {
|
||||||
|
this.addNewAppendProp();
|
||||||
|
} else {
|
||||||
|
this.upgradeRandomAppendProp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getEquipSlot() {
|
|
||||||
return this.getItemData().getEquipType().getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEquipped() {
|
|
||||||
return this.getEquipCharacter() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDestroyable() {
|
|
||||||
return !this.isLocked() && !this.isEquipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAppendProp() {
|
|
||||||
if (this.appendPropIdList == null) {
|
|
||||||
this.appendPropIdList = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.appendPropIdList.size() < 4) {
|
|
||||||
this.addNewAppendProp();
|
|
||||||
} else {
|
|
||||||
this.upgradeRandomAppendProp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAppendProps(int quantity) {
|
public void addAppendProps(int quantity) {
|
||||||
int num = Math.max(quantity, 0);
|
int num = Math.max(quantity, 0);
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
@ -199,165 +199,165 @@ public class GameItem {
|
|||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNewAppendProp() {
|
private void addNewAppendProp() {
|
||||||
List<ReliquaryAffixData> affixList = GameDepot.getRelicAffixList(this.itemData.getAppendPropDepotId());
|
List<ReliquaryAffixData> affixList = GameDepot.getRelicAffixList(this.itemData.getAppendPropDepotId());
|
||||||
|
|
||||||
if (affixList == null) {
|
if (affixList == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build blacklist - Dont add same stat as main/sub stat
|
// Build blacklist - Dont add same stat as main/sub stat
|
||||||
Set<FightProperty> blacklist = this.getAppendFightProperties();
|
Set<FightProperty> blacklist = this.getAppendFightProperties();
|
||||||
ReliquaryMainPropData mainPropData = GameData.getReliquaryMainPropDataMap().get(this.mainPropId);
|
ReliquaryMainPropData mainPropData = GameData.getReliquaryMainPropDataMap().get(this.mainPropId);
|
||||||
if (mainPropData != null) {
|
if (mainPropData != null) {
|
||||||
blacklist.add(mainPropData.getFightProp());
|
blacklist.add(mainPropData.getFightProp());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build random list
|
|
||||||
WeightedList<ReliquaryAffixData> randomList = new WeightedList<>();
|
|
||||||
for (ReliquaryAffixData affix : affixList) {
|
|
||||||
if (!blacklist.contains(affix.getFightProp())) {
|
|
||||||
randomList.add(affix.getWeight(), affix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (randomList.size() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add random stat
|
// Build random list
|
||||||
ReliquaryAffixData affixData = randomList.next();
|
WeightedList<ReliquaryAffixData> randomList = new WeightedList<>();
|
||||||
this.appendPropIdList.add(affixData.getId());
|
for (ReliquaryAffixData affix : affixList) {
|
||||||
}
|
if (!blacklist.contains(affix.getFightProp())) {
|
||||||
|
randomList.add(affix.getWeight(), affix);
|
||||||
private void upgradeRandomAppendProp() {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (randomList.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add random stat
|
||||||
|
ReliquaryAffixData affixData = randomList.next();
|
||||||
|
this.appendPropIdList.add(affixData.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void upgradeRandomAppendProp() {
|
||||||
List<ReliquaryAffixData> affixList = GameDepot.getRelicAffixList(this.itemData.getAppendPropDepotId());
|
List<ReliquaryAffixData> affixList = GameDepot.getRelicAffixList(this.itemData.getAppendPropDepotId());
|
||||||
|
|
||||||
if (affixList == null) {
|
if (affixList == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build whitelist
|
// Build whitelist
|
||||||
Set<FightProperty> whitelist = this.getAppendFightProperties();
|
Set<FightProperty> whitelist = this.getAppendFightProperties();
|
||||||
|
|
||||||
// Build random list
|
|
||||||
WeightedList<ReliquaryAffixData> randomList = new WeightedList<>();
|
|
||||||
for (ReliquaryAffixData affix : affixList) {
|
|
||||||
if (whitelist.contains(affix.getFightProp())) {
|
|
||||||
randomList.add(affix.getUpgradeWeight(), affix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add random stat
|
|
||||||
ReliquaryAffixData affixData = randomList.next();
|
|
||||||
this.appendPropIdList.add(affixData.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostLoad
|
// Build random list
|
||||||
public void onLoad() {
|
WeightedList<ReliquaryAffixData> randomList = new WeightedList<>();
|
||||||
if (this.itemData == null) {
|
for (ReliquaryAffixData affix : affixList) {
|
||||||
this.itemData = GameData.getItemDataMap().get(getItemId());
|
if (whitelist.contains(affix.getFightProp())) {
|
||||||
}
|
randomList.add(affix.getUpgradeWeight(), affix);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public void save() {
|
|
||||||
if (this.count > 0 && this.ownerId > 0) {
|
|
||||||
DatabaseHelper.saveItem(this);
|
|
||||||
} else if (this.getObjectId() != null) {
|
|
||||||
DatabaseHelper.deleteItem(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public SceneWeaponInfo createSceneWeaponInfo() {
|
|
||||||
SceneWeaponInfo.Builder weaponInfo = SceneWeaponInfo.newBuilder()
|
|
||||||
.setEntityId(this.getWeaponEntityId())
|
|
||||||
.setItemId(this.getItemId())
|
|
||||||
.setGuid(this.getGuid())
|
|
||||||
.setLevel(this.getLevel())
|
|
||||||
.setGadgetId(this.getItemData().getGadgetId())
|
|
||||||
.setAbilityInfo(AbilitySyncStateInfo.newBuilder().setIsInited(getAffixes().size() > 0));
|
|
||||||
|
|
||||||
if (this.getAffixes() != null && this.getAffixes().size() > 0) {
|
|
||||||
for (int affix : this.getAffixes()) {
|
|
||||||
weaponInfo.putAffixMap(affix, this.getRefinement());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return weaponInfo.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SceneReliquaryInfo createSceneReliquaryInfo() {
|
|
||||||
SceneReliquaryInfo relicInfo = SceneReliquaryInfo.newBuilder()
|
|
||||||
.setItemId(this.getItemId())
|
|
||||||
.setGuid(this.getGuid())
|
|
||||||
.setLevel(this.getLevel())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
return relicInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Weapon toWeaponProto() {
|
// Add random stat
|
||||||
Weapon.Builder weapon = Weapon.newBuilder()
|
ReliquaryAffixData affixData = randomList.next();
|
||||||
.setLevel(this.getLevel())
|
this.appendPropIdList.add(affixData.getId());
|
||||||
.setExp(this.getExp())
|
}
|
||||||
.setPromoteLevel(this.getPromoteLevel());
|
|
||||||
|
|
||||||
if (this.getAffixes() != null && this.getAffixes().size() > 0) {
|
@PostLoad
|
||||||
for (int affix : this.getAffixes()) {
|
public void onLoad() {
|
||||||
weapon.putAffixMap(affix, this.getRefinement());
|
if (this.itemData == null) {
|
||||||
}
|
this.itemData = GameData.getItemDataMap().get(getItemId());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return weapon.build();
|
public void save() {
|
||||||
}
|
if (this.count > 0 && this.ownerId > 0) {
|
||||||
|
DatabaseHelper.saveItem(this);
|
||||||
|
} else if (this.getObjectId() != null) {
|
||||||
|
DatabaseHelper.deleteItem(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Reliquary toReliquaryProto() {
|
public SceneWeaponInfo createSceneWeaponInfo() {
|
||||||
Reliquary.Builder relic = Reliquary.newBuilder()
|
SceneWeaponInfo.Builder weaponInfo = SceneWeaponInfo.newBuilder()
|
||||||
.setLevel(this.getLevel())
|
.setEntityId(this.getWeaponEntityId())
|
||||||
.setExp(this.getExp())
|
.setItemId(this.getItemId())
|
||||||
.setPromoteLevel(this.getPromoteLevel())
|
.setGuid(this.getGuid())
|
||||||
.setMainPropId(this.getMainPropId())
|
.setLevel(this.getLevel())
|
||||||
.addAllAppendPropIdList(this.getAppendPropIdList());
|
.setGadgetId(this.getItemData().getGadgetId())
|
||||||
|
.setAbilityInfo(AbilitySyncStateInfo.newBuilder().setIsInited(getAffixes().size() > 0));
|
||||||
|
|
||||||
return relic.build();
|
if (this.getAffixes() != null && this.getAffixes().size() > 0) {
|
||||||
}
|
for (int affix : this.getAffixes()) {
|
||||||
|
weaponInfo.putAffixMap(affix, this.getRefinement());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Item toProto() {
|
return weaponInfo.build();
|
||||||
Item.Builder proto = Item.newBuilder()
|
}
|
||||||
.setGuid(this.getGuid())
|
|
||||||
.setItemId(this.getItemId());
|
|
||||||
|
|
||||||
switch (getItemType()) {
|
|
||||||
case ITEM_WEAPON:
|
|
||||||
Weapon weapon = this.toWeaponProto();
|
|
||||||
proto.setEquip(Equip.newBuilder().setWeapon(weapon).setIsLocked(this.isLocked()).build());
|
|
||||||
break;
|
|
||||||
case ITEM_RELIQUARY:
|
|
||||||
Reliquary relic = this.toReliquaryProto();
|
|
||||||
proto.setEquip(Equip.newBuilder().setReliquary(relic).setIsLocked(this.isLocked()).build());
|
|
||||||
break;
|
|
||||||
case ITEM_FURNITURE:
|
|
||||||
Furniture furniture = Furniture.newBuilder()
|
|
||||||
.setCount(getCount())
|
|
||||||
.build();
|
|
||||||
proto.setFurniture(furniture);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Material material = Material.newBuilder()
|
|
||||||
.setCount(getCount())
|
|
||||||
.build();
|
|
||||||
proto.setMaterial(material);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return proto.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemHint toItemHintProto() {
|
public SceneReliquaryInfo createSceneReliquaryInfo() {
|
||||||
return ItemHint.newBuilder().setItemId(getItemId()).setCount(getCount()).setIsNew(false).build();
|
SceneReliquaryInfo relicInfo = SceneReliquaryInfo.newBuilder()
|
||||||
}
|
.setItemId(this.getItemId())
|
||||||
|
.setGuid(this.getGuid())
|
||||||
|
.setLevel(this.getLevel())
|
||||||
|
.build();
|
||||||
|
|
||||||
public ItemParam toItemParam() {
|
return relicInfo;
|
||||||
return ItemParam.newBuilder().setItemId(this.getItemId()).setCount(this.getCount()).build();
|
}
|
||||||
}
|
|
||||||
|
public Weapon toWeaponProto() {
|
||||||
|
Weapon.Builder weapon = Weapon.newBuilder()
|
||||||
|
.setLevel(this.getLevel())
|
||||||
|
.setExp(this.getExp())
|
||||||
|
.setPromoteLevel(this.getPromoteLevel());
|
||||||
|
|
||||||
|
if (this.getAffixes() != null && this.getAffixes().size() > 0) {
|
||||||
|
for (int affix : this.getAffixes()) {
|
||||||
|
weapon.putAffixMap(affix, this.getRefinement());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return weapon.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Reliquary toReliquaryProto() {
|
||||||
|
Reliquary.Builder relic = Reliquary.newBuilder()
|
||||||
|
.setLevel(this.getLevel())
|
||||||
|
.setExp(this.getExp())
|
||||||
|
.setPromoteLevel(this.getPromoteLevel())
|
||||||
|
.setMainPropId(this.getMainPropId())
|
||||||
|
.addAllAppendPropIdList(this.getAppendPropIdList());
|
||||||
|
|
||||||
|
return relic.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Item toProto() {
|
||||||
|
Item.Builder proto = Item.newBuilder()
|
||||||
|
.setGuid(this.getGuid())
|
||||||
|
.setItemId(this.getItemId());
|
||||||
|
|
||||||
|
switch (getItemType()) {
|
||||||
|
case ITEM_WEAPON:
|
||||||
|
Weapon weapon = this.toWeaponProto();
|
||||||
|
proto.setEquip(Equip.newBuilder().setWeapon(weapon).setIsLocked(this.isLocked()).build());
|
||||||
|
break;
|
||||||
|
case ITEM_RELIQUARY:
|
||||||
|
Reliquary relic = this.toReliquaryProto();
|
||||||
|
proto.setEquip(Equip.newBuilder().setReliquary(relic).setIsLocked(this.isLocked()).build());
|
||||||
|
break;
|
||||||
|
case ITEM_FURNITURE:
|
||||||
|
Furniture furniture = Furniture.newBuilder()
|
||||||
|
.setCount(getCount())
|
||||||
|
.build();
|
||||||
|
proto.setFurniture(furniture);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Material material = Material.newBuilder()
|
||||||
|
.setCount(getCount())
|
||||||
|
.build();
|
||||||
|
proto.setMaterial(material);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return proto.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemHint toItemHintProto() {
|
||||||
|
return ItemHint.newBuilder().setItemId(getItemId()).setCount(getCount()).setIsNew(false).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemParam toItemParam() {
|
||||||
|
return ItemParam.newBuilder().setItemId(this.getItemId()).setCount(this.getCount()).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class PlayerCodex {
|
|||||||
@Getter private Set<Integer> unlockedReliquary;
|
@Getter private Set<Integer> unlockedReliquary;
|
||||||
@Getter private Set<Integer> unlockedReliquarySuitCodex;
|
@Getter private Set<Integer> unlockedReliquarySuitCodex;
|
||||||
|
|
||||||
public PlayerCodex(){
|
public PlayerCodex() {
|
||||||
this.unlockedWeapon = new HashSet<>();
|
this.unlockedWeapon = new HashSet<>();
|
||||||
this.unlockedAnimal = new HashMap<>();
|
this.unlockedAnimal = new HashMap<>();
|
||||||
this.unlockedMaterial = new HashSet<>();
|
this.unlockedMaterial = new HashSet<>();
|
||||||
@ -38,7 +38,7 @@ public class PlayerCodex {
|
|||||||
this.unlockedReliquarySuitCodex = new HashSet<>();
|
this.unlockedReliquarySuitCodex = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerCodex(Player player){
|
public PlayerCodex(Player player) {
|
||||||
this();
|
this();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ public class PlayerCodex {
|
|||||||
this.fixReliquaries();
|
this.fixReliquaries();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkAddedItem(GameItem item){
|
public void checkAddedItem(GameItem item) {
|
||||||
val itemData = item.getItemData();
|
val itemData = item.getItemData();
|
||||||
val itemId = item.getItemId();
|
val itemId = item.getItemId();
|
||||||
switch (itemData.getItemType()) {
|
switch (itemData.getItemType()) {
|
||||||
@ -85,7 +85,7 @@ public class PlayerCodex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkAnimal(GameEntity target, CodexAnimalData.CountType countType){
|
public void checkAnimal(GameEntity target, CodexAnimalData.CountType countType) {
|
||||||
if (target instanceof EntityMonster) {
|
if (target instanceof EntityMonster) {
|
||||||
val monsterId = ((EntityMonster) target).getMonsterData().getId();
|
val monsterId = ((EntityMonster) target).getMonsterData().getId();
|
||||||
val codexAnimal = GameData.getCodexAnimalDataMap().get(monsterId);
|
val codexAnimal = GameData.getCodexAnimalDataMap().get(monsterId);
|
||||||
@ -101,7 +101,7 @@ public class PlayerCodex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkUnlockedSuits(int reliquaryId){
|
public void checkUnlockedSuits(int reliquaryId) {
|
||||||
GameData.getCodexReliquaryArrayList().stream()
|
GameData.getCodexReliquaryArrayList().stream()
|
||||||
.filter(x -> !this.getUnlockedReliquarySuitCodex().contains(x.getId()))
|
.filter(x -> !this.getUnlockedReliquarySuitCodex().contains(x.getId()))
|
||||||
.filter(x -> x.containsId(reliquaryId))
|
.filter(x -> x.containsId(reliquaryId))
|
||||||
@ -127,4 +127,4 @@ public class PlayerCodex {
|
|||||||
.forEach(x -> this.getUnlockedReliquarySuitCodex().add(x.getId()));
|
.forEach(x -> this.getUnlockedReliquarySuitCodex().add(x.getId()));
|
||||||
this.player.save();
|
this.player.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public abstract class ItemUseAddEnergy extends ItemUseAction {
|
|||||||
var activeTeam = teamManager.getActiveTeam();
|
var activeTeam = teamManager.getActiveTeam();
|
||||||
// On-field vs off-field multiplier.
|
// On-field vs off-field multiplier.
|
||||||
// The on-field character gets full amount, off-field characters get less depending on the team size.
|
// The on-field character gets full amount, off-field characters get less depending on the team size.
|
||||||
final float offFieldRatio = switch(activeTeam.size()) {
|
final float offFieldRatio = switch (activeTeam.size()) {
|
||||||
case 2 -> 0.8f;
|
case 2 -> 0.8f;
|
||||||
case 3 -> 0.7f;
|
case 3 -> 0.7f;
|
||||||
default -> 0.6f;
|
default -> 0.6f;
|
||||||
|
@ -570,7 +570,7 @@ public class InventorySystem extends BaseGameSystem {
|
|||||||
|
|
||||||
// Calc exp
|
// Calc exp
|
||||||
int expGain = 0;
|
int expGain = 0;
|
||||||
|
|
||||||
var data = GameData.getItemDataMap().get(itemId);
|
var data = GameData.getItemDataMap().get(itemId);
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
var actions = data.getItemUseActions();
|
var actions = data.getItemUseActions();
|
||||||
|
@ -85,10 +85,10 @@ public class WorldDataSystem extends BaseGameSystem {
|
|||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
private InvestigationMonsterOuterClass.InvestigationMonster getInvestigationMonster(Player player, InvestigationMonsterData imd) {
|
private InvestigationMonsterOuterClass.InvestigationMonster getInvestigationMonster(Player player, InvestigationMonsterData imd) {
|
||||||
if(imd.getGroupIdList().isEmpty() || imd.getMonsterIdList().isEmpty()){
|
if (imd.getGroupIdList().isEmpty() || imd.getMonsterIdList().isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var groupId = imd.getGroupIdList().get(0);
|
var groupId = imd.getGroupIdList().get(0);
|
||||||
var monsterId = imd.getMonsterIdList().get(0);
|
var monsterId = imd.getMonsterIdList().get(0);
|
||||||
var sceneId = imd.getCityData().getSceneId();
|
var sceneId = imd.getCityData().getSceneId();
|
||||||
|
@ -30,28 +30,28 @@ import java.util.Optional;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class ScriptLoader {
|
public class ScriptLoader {
|
||||||
private static ScriptEngineManager sm;
|
private static ScriptEngineManager sm;
|
||||||
@Getter private static ScriptEngine engine;
|
@Getter private static ScriptEngine engine;
|
||||||
private static ScriptEngineFactory factory;
|
private static ScriptEngineFactory factory;
|
||||||
@Getter private static Serializer serializer;
|
@Getter private static Serializer serializer;
|
||||||
@Getter private static ScriptLib scriptLib;
|
@Getter private static ScriptLib scriptLib;
|
||||||
@Getter private static LuaValue scriptLibLua;
|
@Getter private static LuaValue scriptLibLua;
|
||||||
/**
|
/**
|
||||||
* suggest GC to remove it if the memory is less
|
* suggest GC to remove it if the memory is less
|
||||||
*/
|
*/
|
||||||
private static Map<String, SoftReference<CompiledScript>> scriptsCache = new ConcurrentHashMap<>();
|
private static Map<String, SoftReference<CompiledScript>> scriptsCache = new ConcurrentHashMap<>();
|
||||||
/**
|
/**
|
||||||
* sceneId - SceneMeta
|
* sceneId - SceneMeta
|
||||||
*/
|
*/
|
||||||
private static Map<Integer, SoftReference<SceneMeta>> sceneMetaCache = new ConcurrentHashMap<>();
|
private static Map<Integer, SoftReference<SceneMeta>> sceneMetaCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public synchronized static void init() throws Exception {
|
public synchronized static void init() throws Exception {
|
||||||
if (sm != null) {
|
if (sm != null) {
|
||||||
throw new Exception("Script loader already initialized");
|
throw new Exception("Script loader already initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create script engine
|
// Create script engine
|
||||||
sm = new ScriptEngineManager();
|
sm = new ScriptEngineManager();
|
||||||
engine = sm.getEngineByName("luaj");
|
engine = sm.getEngineByName("luaj");
|
||||||
factory = getEngine().getFactory();
|
factory = getEngine().getFactory();
|
||||||
|
|
||||||
@ -60,61 +60,61 @@ public class ScriptLoader {
|
|||||||
|
|
||||||
// Set engine to replace require as a temporary fix to missing scripts
|
// Set engine to replace require as a temporary fix to missing scripts
|
||||||
LuajContext ctx = (LuajContext) engine.getContext();
|
LuajContext ctx = (LuajContext) engine.getContext();
|
||||||
ctx.globals.set("require", new OneArgFunction() {
|
ctx.globals.set("require", new OneArgFunction() {
|
||||||
@Override
|
@Override
|
||||||
public LuaValue call(LuaValue arg0) {
|
public LuaValue call(LuaValue arg0) {
|
||||||
return LuaValue.ZERO;
|
return LuaValue.ZERO;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LuaTable table = new LuaTable();
|
LuaTable table = new LuaTable();
|
||||||
Arrays.stream(EntityType.values()).forEach(e -> table.set(e.name().toUpperCase(), e.getValue()));
|
Arrays.stream(EntityType.values()).forEach(e -> table.set(e.name().toUpperCase(), e.getValue()));
|
||||||
ctx.globals.set("EntityType", table);
|
ctx.globals.set("EntityType", table);
|
||||||
|
|
||||||
LuaTable table1 = new LuaTable();
|
LuaTable table1 = new LuaTable();
|
||||||
Arrays.stream(QuestState.values()).forEach(e -> table1.set(e.name().toUpperCase(), e.getValue()));
|
Arrays.stream(QuestState.values()).forEach(e -> table1.set(e.name().toUpperCase(), e.getValue()));
|
||||||
ctx.globals.set("QuestState", table1);
|
ctx.globals.set("QuestState", table1);
|
||||||
|
|
||||||
ctx.globals.set("EventType", CoerceJavaToLua.coerce(new EventType())); // TODO - make static class to avoid instantiating a new class every scene
|
ctx.globals.set("EventType", CoerceJavaToLua.coerce(new EventType())); // TODO - make static class to avoid instantiating a new class every scene
|
||||||
ctx.globals.set("GadgetState", CoerceJavaToLua.coerce(new ScriptGadgetState()));
|
ctx.globals.set("GadgetState", CoerceJavaToLua.coerce(new ScriptGadgetState()));
|
||||||
ctx.globals.set("RegionShape", CoerceJavaToLua.coerce(new ScriptRegionShape()));
|
ctx.globals.set("RegionShape", CoerceJavaToLua.coerce(new ScriptRegionShape()));
|
||||||
|
|
||||||
scriptLib = new ScriptLib();
|
scriptLib = new ScriptLib();
|
||||||
scriptLibLua = CoerceJavaToLua.coerce(scriptLib);
|
scriptLibLua = CoerceJavaToLua.coerce(scriptLib);
|
||||||
ctx.globals.set("ScriptLib", scriptLibLua);
|
ctx.globals.set("ScriptLib", scriptLibLua);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Optional<T> tryGet(SoftReference<T> softReference){
|
public static <T> Optional<T> tryGet(SoftReference<T> softReference) {
|
||||||
try{
|
try {
|
||||||
return Optional.ofNullable(softReference.get());
|
return Optional.ofNullable(softReference.get());
|
||||||
}catch (NullPointerException npe){
|
}catch (NullPointerException npe) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated(forRemoval = true)
|
@Deprecated(forRemoval = true)
|
||||||
public static CompiledScript getScriptByPath(String path) {
|
public static CompiledScript getScriptByPath(String path) {
|
||||||
var sc = tryGet(scriptsCache.get(path));
|
var sc = tryGet(scriptsCache.get(path));
|
||||||
if (sc.isPresent()) {
|
if (sc.isPresent()) {
|
||||||
return sc.get();
|
return sc.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Grasscutter.getLogger().debug("Loading script " + path);
|
Grasscutter.getLogger().debug("Loading script " + path);
|
||||||
|
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
|
|
||||||
if (!file.exists()) return null;
|
if (!file.exists()) return null;
|
||||||
|
|
||||||
try (FileReader fr = new FileReader(file)) {
|
try (FileReader fr = new FileReader(file)) {
|
||||||
var script = ((Compilable) getEngine()).compile(fr);
|
var script = ((Compilable) getEngine()).compile(fr);
|
||||||
scriptsCache.put(path, new SoftReference<>(script));
|
scriptsCache.put(path, new SoftReference<>(script));
|
||||||
return script;
|
return script;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Grasscutter.getLogger().error("Loading script {} failed!", path, e);
|
Grasscutter.getLogger().error("Loading script {} failed!", path, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompiledScript getScript(String path) {
|
public static CompiledScript getScript(String path) {
|
||||||
var sc = tryGet(scriptsCache.get(path));
|
var sc = tryGet(scriptsCache.get(path));
|
||||||
@ -136,12 +136,12 @@ public class ScriptLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SceneMeta getSceneMeta(int sceneId) {
|
public static SceneMeta getSceneMeta(int sceneId) {
|
||||||
return tryGet(sceneMetaCache.get(sceneId)).orElseGet(() -> {
|
return tryGet(sceneMetaCache.get(sceneId)).orElseGet(() -> {
|
||||||
var instance = SceneMeta.of(sceneId);
|
var instance = SceneMeta.of(sceneId);
|
||||||
sceneMetaCache.put(sceneId, new SoftReference<>(instance));
|
sceneMetaCache.put(sceneId, new SoftReference<>(instance));
|
||||||
return instance;
|
return instance;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,18 +11,18 @@ import emu.grasscutter.server.game.GameSession;
|
|||||||
@Opcodes(PacketOpcodes.EvtCreateGadgetNotify)
|
@Opcodes(PacketOpcodes.EvtCreateGadgetNotify)
|
||||||
public class HandlerEvtCreateGadgetNotify extends PacketHandler {
|
public class HandlerEvtCreateGadgetNotify extends PacketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||||
EvtCreateGadgetNotify notify = EvtCreateGadgetNotify.parseFrom(payload);
|
EvtCreateGadgetNotify notify = EvtCreateGadgetNotify.parseFrom(payload);
|
||||||
|
|
||||||
// Sanity check - dont add duplicate entities
|
// Sanity check - dont add duplicate entities
|
||||||
if (session.getPlayer().getScene().getEntityById(notify.getEntityId()) != null) {
|
if (session.getPlayer().getScene().getEntityById(notify.getEntityId()) != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create entity and summon in world
|
// Create entity and summon in world
|
||||||
var gadgetId = notify.getConfigId();
|
var gadgetId = notify.getConfigId();
|
||||||
EntityClientGadget gadget = switch (gadgetId) {
|
EntityClientGadget gadget = switch (gadgetId) {
|
||||||
//Solar Isotoma.
|
//Solar Isotoma.
|
||||||
case EntitySolarIsotomaClientGadget.GADGET_ID ->
|
case EntitySolarIsotomaClientGadget.GADGET_ID ->
|
||||||
new EntitySolarIsotomaClientGadget(session.getPlayer().getScene(), session.getPlayer(), notify);
|
new EntitySolarIsotomaClientGadget(session.getPlayer().getScene(), session.getPlayer(), notify);
|
||||||
@ -33,6 +33,6 @@ public class HandlerEvtCreateGadgetNotify extends PacketHandler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
session.getPlayer().getScene().onPlayerCreateGadget(gadget);
|
session.getPlayer().getScene().onPlayerCreateGadget(gadget);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,14 @@ import emu.grasscutter.net.proto.SceneTimeNotifyOuterClass.SceneTimeNotify;
|
|||||||
|
|
||||||
public class PacketSceneTimeNotify extends BasePacket {
|
public class PacketSceneTimeNotify extends BasePacket {
|
||||||
|
|
||||||
public PacketSceneTimeNotify(Player player) {
|
public PacketSceneTimeNotify(Player player) {
|
||||||
super(PacketOpcodes.SceneTimeNotify);
|
super(PacketOpcodes.SceneTimeNotify);
|
||||||
|
|
||||||
SceneTimeNotify proto = SceneTimeNotify.newBuilder()
|
SceneTimeNotify proto = SceneTimeNotify.newBuilder()
|
||||||
.setSceneId(player.getSceneId())
|
.setSceneId(player.getSceneId())
|
||||||
.setSceneTime(player.getScene().getSceneTime())
|
.setSceneTime(player.getScene().getSceneTime())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
this.setData(proto);
|
this.setData(proto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,93 +111,93 @@ public final class FileUtils {
|
|||||||
return SCRIPTS_PATH.resolve(path);
|
return SCRIPTS_PATH.resolve(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void write(String dest, byte[] bytes) {
|
public static void write(String dest, byte[] bytes) {
|
||||||
Path path = Path.of(dest);
|
Path path = Path.of(dest);
|
||||||
|
|
||||||
try {
|
|
||||||
Files.write(path, bytes);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Grasscutter.getLogger().warn("Failed to write file: " + dest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] read(String dest) {
|
|
||||||
return read(Path.of(dest));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] read(Path path) {
|
try {
|
||||||
try {
|
Files.write(path, bytes);
|
||||||
return Files.readAllBytes(path);
|
} catch (IOException e) {
|
||||||
} catch (IOException e) {
|
Grasscutter.getLogger().warn("Failed to write file: " + dest);
|
||||||
Grasscutter.getLogger().warn("Failed to read file: " + path);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new byte[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InputStream readResourceAsStream(String resourcePath) {
|
public static byte[] read(String dest) {
|
||||||
return Grasscutter.class.getResourceAsStream(resourcePath);
|
return read(Path.of(dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] readResource(String resourcePath) {
|
public static byte[] read(Path path) {
|
||||||
try (InputStream is = Grasscutter.class.getResourceAsStream(resourcePath)) {
|
try {
|
||||||
return is.readAllBytes();
|
return Files.readAllBytes(path);
|
||||||
} catch (Exception exception) {
|
} catch (IOException e) {
|
||||||
Grasscutter.getLogger().warn("Failed to read resource: " + resourcePath);
|
Grasscutter.getLogger().warn("Failed to read file: " + path);
|
||||||
exception.printStackTrace();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] read(File file) {
|
|
||||||
return read(file.getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void copyResource(String resourcePath, String destination) {
|
public static InputStream readResourceAsStream(String resourcePath) {
|
||||||
try {
|
return Grasscutter.class.getResourceAsStream(resourcePath);
|
||||||
byte[] resource = FileUtils.readResource(resourcePath);
|
}
|
||||||
FileUtils.write(destination, resource);
|
|
||||||
} catch (Exception exception) {
|
|
||||||
Grasscutter.getLogger().warn("Failed to copy resource: " + resourcePath + "\n" + exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getFilenameWithoutPath(String fileName) {
|
|
||||||
if (fileName.indexOf(".") > 0) {
|
|
||||||
return fileName.substring(0, fileName.lastIndexOf("."));
|
|
||||||
} else {
|
|
||||||
return fileName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// From https://mkyong.com/java/java-read-a-file-from-resources-folder/
|
public static byte[] readResource(String resourcePath) {
|
||||||
public static List<Path> getPathsFromResource(String folder) throws URISyntaxException {
|
try (InputStream is = Grasscutter.class.getResourceAsStream(resourcePath)) {
|
||||||
List<Path> result = null;
|
return is.readAllBytes();
|
||||||
|
} catch (Exception exception) {
|
||||||
|
Grasscutter.getLogger().warn("Failed to read resource: " + resourcePath);
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
return new byte[0];
|
||||||
// file walks JAR
|
}
|
||||||
result = Files.walk(JAR_FILE_SYSTEM.getPath(folder))
|
|
||||||
.filter(Files::isRegularFile)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Eclipse puts resources in its bin folder
|
|
||||||
File f = new File(System.getProperty("user.dir") + folder);
|
|
||||||
|
|
||||||
if (!f.exists() || f.listFiles().length == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = Arrays.stream(f.listFiles()).map(File::toPath).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
public static byte[] read(File file) {
|
||||||
public static String readToString(InputStream file) throws IOException {
|
return read(file.getPath());
|
||||||
byte[] content = file.readAllBytes();
|
}
|
||||||
|
|
||||||
return new String(content, StandardCharsets.UTF_8);
|
public static void copyResource(String resourcePath, String destination) {
|
||||||
}
|
try {
|
||||||
|
byte[] resource = FileUtils.readResource(resourcePath);
|
||||||
|
FileUtils.write(destination, resource);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
Grasscutter.getLogger().warn("Failed to copy resource: " + resourcePath + "\n" + exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFilenameWithoutPath(String fileName) {
|
||||||
|
if (fileName.indexOf(".") > 0) {
|
||||||
|
return fileName.substring(0, fileName.lastIndexOf("."));
|
||||||
|
} else {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// From https://mkyong.com/java/java-read-a-file-from-resources-folder/
|
||||||
|
public static List<Path> getPathsFromResource(String folder) throws URISyntaxException {
|
||||||
|
List<Path> result = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// file walks JAR
|
||||||
|
result = Files.walk(JAR_FILE_SYSTEM.getPath(folder))
|
||||||
|
.filter(Files::isRegularFile)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Eclipse puts resources in its bin folder
|
||||||
|
File f = new File(System.getProperty("user.dir") + folder);
|
||||||
|
|
||||||
|
if (!f.exists() || f.listFiles().length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = Arrays.stream(f.listFiles()).map(File::toPath).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
public static String readToString(InputStream file) throws IOException {
|
||||||
|
byte[] content = file.readAllBytes();
|
||||||
|
|
||||||
|
return new String(content, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user