mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-16 08:56:04 +01:00
Merge branch 'development' into dungeon-scripts
This commit is contained in:
@@ -83,6 +83,9 @@ public class DropManager {
|
||||
ItemData itemData = GameData.getItemDataMap().get(dd.getItemId());
|
||||
int num = Utils.randomRange(dd.getMinCount(), dd.getMaxCount());
|
||||
|
||||
if (itemData == null) {
|
||||
return;
|
||||
}
|
||||
if (itemData.isEquip()) {
|
||||
for (int i = 0; i < num; i++) {
|
||||
float range = (5f + (.1f * num));
|
||||
|
||||
124
src/main/java/emu/grasscutter/game/entity/EntityVehicle.java
Normal file
124
src/main/java/emu/grasscutter/game/entity/EntityVehicle.java
Normal file
@@ -0,0 +1,124 @@
|
||||
package emu.grasscutter.game.entity;
|
||||
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.EntityIdType;
|
||||
import emu.grasscutter.game.props.PlayerProperty;
|
||||
import emu.grasscutter.game.world.Scene;
|
||||
|
||||
import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo;
|
||||
import emu.grasscutter.net.proto.AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair;
|
||||
import emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityInfo;
|
||||
import emu.grasscutter.net.proto.EntityRendererChangedInfoOuterClass.EntityRendererChangedInfo;
|
||||
import emu.grasscutter.net.proto.FightPropPairOuterClass.*;
|
||||
import emu.grasscutter.net.proto.MotionInfoOuterClass.MotionInfo;
|
||||
import emu.grasscutter.net.proto.PropPairOuterClass.PropPair;
|
||||
import emu.grasscutter.net.proto.ProtEntityTypeOuterClass.ProtEntityType;
|
||||
import emu.grasscutter.net.proto.SceneEntityAiInfoOuterClass.SceneEntityAiInfo;
|
||||
import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
|
||||
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
|
||||
import emu.grasscutter.net.proto.VectorOuterClass.Vector;
|
||||
import emu.grasscutter.net.proto.VehicleInfoOuterClass.*;
|
||||
|
||||
import emu.grasscutter.utils.Position;
|
||||
import emu.grasscutter.utils.ProtoHelper;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2FloatMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
|
||||
|
||||
public class EntityVehicle extends EntityGadget {
|
||||
private final Player owner;
|
||||
private final Int2FloatOpenHashMap fightProp;
|
||||
|
||||
private final Position pos;
|
||||
private final Position rot;
|
||||
|
||||
private float curStamina;
|
||||
private final int pointId;
|
||||
private final int gadgetId;
|
||||
|
||||
public EntityVehicle(Scene scene, Player player, int gadgetId, int pointId, Position pos, Position rot) {
|
||||
super(scene);
|
||||
this.owner = player;
|
||||
this.id = getScene().getWorld().getNextEntityId(EntityIdType.GADGET);
|
||||
this.fightProp = new Int2FloatOpenHashMap();
|
||||
this.pos = new Position(pos);
|
||||
this.rot = new Position(rot);
|
||||
this.gadgetId = gadgetId;
|
||||
this.pointId = pointId;
|
||||
this.curStamina = 240;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGadgetId() { return gadgetId; }
|
||||
|
||||
public Player getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public float getCurStamina() { return curStamina; }
|
||||
|
||||
public void setCurStamina(float stamina) { this.curStamina = stamina; }
|
||||
|
||||
public int getPointId() { return pointId; }
|
||||
|
||||
@Override
|
||||
public Int2FloatOpenHashMap getFightProperties() {
|
||||
return fightProp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getPosition() { return this.pos; }
|
||||
|
||||
@Override
|
||||
public Position getRotation() {
|
||||
return this.rot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneEntityInfo toProto() {
|
||||
|
||||
VehicleInfo vehicle = VehicleInfo.newBuilder()
|
||||
.setOwnerUid(this.owner.getUid())
|
||||
.setCurStamina(getCurStamina())
|
||||
.build();
|
||||
|
||||
EntityAuthorityInfo authority = EntityAuthorityInfo.newBuilder()
|
||||
.setAbilityInfo(AbilitySyncStateInfo.newBuilder())
|
||||
.setRendererChangedInfo(EntityRendererChangedInfo.newBuilder())
|
||||
.setAiInfo(SceneEntityAiInfo.newBuilder().setIsAiOpen(true).setBornPos(getPosition().toProto()))
|
||||
.setBornPos(getPosition().toProto())
|
||||
.build();
|
||||
|
||||
SceneGadgetInfo.Builder gadgetInfo = SceneGadgetInfo.newBuilder()
|
||||
.setGadgetId(this.getGadgetId())
|
||||
.setAuthorityPeerId(this.getOwner().getPeerId())
|
||||
.setIsEnableInteract(true)
|
||||
.setVehicleInfo(vehicle);
|
||||
|
||||
SceneEntityInfo.Builder entityInfo = SceneEntityInfo.newBuilder()
|
||||
.setEntityId(getId())
|
||||
.setEntityType(ProtEntityType.PROT_ENTITY_GADGET)
|
||||
.setMotionInfo(MotionInfo.newBuilder().setPos(getPosition().toProto()).setRot(getRotation().toProto()).setSpeed(Vector.newBuilder()))
|
||||
.addAnimatorParaList(AnimatorParameterValueInfoPair.newBuilder())
|
||||
.setGadget(gadgetInfo)
|
||||
.setEntityAuthorityInfo(authority)
|
||||
.setLifeState(1);
|
||||
|
||||
PropPair pair = PropPair.newBuilder()
|
||||
.setType(PlayerProperty.PROP_LEVEL.getId())
|
||||
.setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, 47))
|
||||
.build();
|
||||
|
||||
for (Int2FloatMap.Entry entry : getFightProperties().int2FloatEntrySet()) {
|
||||
if (entry.getIntKey() == 0) {
|
||||
continue;
|
||||
}
|
||||
FightPropPair fightProp = FightPropPair.newBuilder().setPropType(entry.getIntKey()).setPropValue(entry.getFloatValue()).build();
|
||||
entityInfo.addFightPropList(fightProp);
|
||||
}
|
||||
|
||||
entityInfo.addPropList(pair);
|
||||
|
||||
return entityInfo.build();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import emu.grasscutter.game.inventory.Inventory;
|
||||
import emu.grasscutter.game.mail.Mail;
|
||||
import emu.grasscutter.game.props.ActionReason;
|
||||
import emu.grasscutter.game.props.PlayerProperty;
|
||||
import emu.grasscutter.game.shop.ShopInfo;
|
||||
import emu.grasscutter.game.shop.ShopLimit;
|
||||
import emu.grasscutter.game.world.Scene;
|
||||
import emu.grasscutter.game.world.World;
|
||||
@@ -621,27 +622,26 @@ public class Player {
|
||||
return shopLimit;
|
||||
}
|
||||
|
||||
public int getGoodsLimitNum(int goodsId) {
|
||||
for (ShopLimit sl : getShopLimit()) {
|
||||
if (sl.getShopGoodId() == goodsId)
|
||||
return sl.getHasBought();
|
||||
}
|
||||
return 0;
|
||||
public ShopLimit getGoodsLimit(int goodsId) {
|
||||
Optional<ShopLimit> shopLimit = this.shopLimit.stream().filter(x -> x.getShopGoodId() == goodsId).findFirst();
|
||||
if (shopLimit.isEmpty())
|
||||
return null;
|
||||
return shopLimit.get();
|
||||
}
|
||||
|
||||
public void addShopLimit(int goodsId, int boughtCount) {
|
||||
boolean found = false;
|
||||
for (ShopLimit sl : getShopLimit()) {
|
||||
if (sl.getShopGoodId() == goodsId){
|
||||
sl.setHasBought(sl.getHasBought() + boughtCount);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
public void addShopLimit(int goodsId, int boughtCount, int nextRefreshTime) {
|
||||
ShopLimit target = getGoodsLimit(goodsId);
|
||||
if (target != null) {
|
||||
target.setHasBought(target.getHasBought() + boughtCount);
|
||||
target.setHasBoughtInPeriod(target.getHasBoughtInPeriod() + boughtCount);
|
||||
target.setNextRefreshTime(nextRefreshTime);
|
||||
} else {
|
||||
ShopLimit sl = new ShopLimit();
|
||||
sl.setShopGoodId(goodsId);
|
||||
sl.setHasBought(boughtCount);
|
||||
shopLimit.add(sl);
|
||||
sl.setHasBoughtInPeriod(boughtCount);
|
||||
sl.setNextRefreshTime(nextRefreshTime);
|
||||
getShopLimit().add(sl);
|
||||
}
|
||||
this.save();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package emu.grasscutter.game.shop;
|
||||
|
||||
import emu.grasscutter.data.common.ItemParamData;
|
||||
import emu.grasscutter.data.def.ShopGoodsData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -14,7 +15,6 @@ public class ShopInfo {
|
||||
private int buyLimit = 0;
|
||||
private int beginTime = 0;
|
||||
private int endTime = 1924992000;
|
||||
private int nextRefreshTime = 1924992000;
|
||||
private int minLevel = 0;
|
||||
private int maxLevel = 61;
|
||||
private List<Integer> preGoodsIdList = new ArrayList<>();
|
||||
@@ -23,6 +23,43 @@ public class ShopInfo {
|
||||
private int disableType = 0;
|
||||
private int secondarySheetId = 0;
|
||||
|
||||
private String refreshType;
|
||||
|
||||
public enum ShopRefreshType {
|
||||
NONE(0),
|
||||
SHOP_REFRESH_DAILY(1),
|
||||
SHOP_REFRESH_WEEKLY(2),
|
||||
SHOP_REFRESH_MONTHLY(3);
|
||||
|
||||
private final int value;
|
||||
ShopRefreshType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int value() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private transient ShopRefreshType shopRefreshType;
|
||||
private int shopRefreshParam;
|
||||
|
||||
public ShopInfo(ShopGoodsData sgd) {
|
||||
this.goodsId = sgd.getGoodsId();
|
||||
this.goodsItem = new ItemParamData(sgd.getItemId(), sgd.getItemCount());
|
||||
this.scoin = sgd.getCostScoin();
|
||||
this.mcoin = sgd.getCostMcoin();
|
||||
this.hcoin = sgd.getCostHcoin();
|
||||
this.buyLimit = sgd.getBuyLimit();
|
||||
|
||||
this.minLevel = sgd.getMinPlayerLevel();
|
||||
this.maxLevel = sgd.getMaxPlayerLevel();
|
||||
this.costItemList = sgd.getCostItems().stream().filter(x -> x.getId() != 0).map(x -> new ItemParamData(x.getId(), x.getCount())).toList();
|
||||
this.secondarySheetId = sgd.getSubTabId();
|
||||
this.shopRefreshType = sgd.getRefreshType();
|
||||
this.shopRefreshParam = sgd.getRefreshParam();
|
||||
}
|
||||
|
||||
public int getHcoin() {
|
||||
return hcoin;
|
||||
}
|
||||
@@ -127,14 +164,6 @@ public class ShopInfo {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public int getNextRefreshTime() {
|
||||
return nextRefreshTime;
|
||||
}
|
||||
|
||||
public void setNextRefreshTime(int nextRefreshTime) {
|
||||
this.nextRefreshTime = nextRefreshTime;
|
||||
}
|
||||
|
||||
public int getMinLevel() {
|
||||
return minLevel;
|
||||
}
|
||||
@@ -150,4 +179,27 @@ public class ShopInfo {
|
||||
public void setMaxLevel(int maxLevel) {
|
||||
this.maxLevel = maxLevel;
|
||||
}
|
||||
|
||||
public ShopRefreshType getShopRefreshType() {
|
||||
if (refreshType == null)
|
||||
return ShopRefreshType.NONE;
|
||||
return switch (refreshType) {
|
||||
case "SHOP_REFRESH_DAILY" -> ShopInfo.ShopRefreshType.SHOP_REFRESH_DAILY;
|
||||
case "SHOP_REFRESH_WEEKLY" -> ShopInfo.ShopRefreshType.SHOP_REFRESH_WEEKLY;
|
||||
case "SHOP_REFRESH_MONTHLY" -> ShopInfo.ShopRefreshType.SHOP_REFRESH_MONTHLY;
|
||||
default -> ShopInfo.ShopRefreshType.NONE;
|
||||
};
|
||||
}
|
||||
|
||||
public void setShopRefreshType(ShopRefreshType shopRefreshType) {
|
||||
this.shopRefreshType = shopRefreshType;
|
||||
}
|
||||
|
||||
public int getShopRefreshParam() {
|
||||
return shopRefreshParam;
|
||||
}
|
||||
|
||||
public void setShopRefreshParam(int shopRefreshParam) {
|
||||
this.shopRefreshParam = shopRefreshParam;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,24 @@ public class ShopLimit {
|
||||
this.hasBought = hasBought;
|
||||
}
|
||||
|
||||
public int getNextRefreshTime() {
|
||||
return nextRefreshTime;
|
||||
}
|
||||
|
||||
public void setNextRefreshTime(int nextRefreshTime) {
|
||||
this.nextRefreshTime = nextRefreshTime;
|
||||
}
|
||||
|
||||
public int getHasBoughtInPeriod() {
|
||||
return hasBoughtInPeriod;
|
||||
}
|
||||
|
||||
public void setHasBoughtInPeriod(int hasBoughtInPeriod) {
|
||||
this.hasBoughtInPeriod = hasBoughtInPeriod;
|
||||
}
|
||||
|
||||
private int shopGoodId;
|
||||
private int hasBought;
|
||||
private int hasBoughtInPeriod = 0;
|
||||
private int nextRefreshTime = 0;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,20 @@ package emu.grasscutter.game.shop;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.common.ItemParamData;
|
||||
import emu.grasscutter.data.def.ShopGoodsData;
|
||||
import emu.grasscutter.net.proto.ItemParamOuterClass;
|
||||
import emu.grasscutter.net.proto.ShopGoodsOuterClass;
|
||||
import emu.grasscutter.server.game.GameServer;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ShopManager {
|
||||
@@ -25,18 +33,57 @@ public class ShopManager {
|
||||
this.load();
|
||||
}
|
||||
|
||||
private static final int REFRESH_HOUR = 4; // In GMT+8 server
|
||||
private static final String TIME_ZONE = "Asia/Shanghai"; // GMT+8 Timezone
|
||||
|
||||
public static int getShopNextRefreshTime(ShopInfo shopInfo) {
|
||||
return switch (shopInfo.getShopRefreshType()) {
|
||||
case SHOP_REFRESH_DAILY -> Utils.GetNextTimestampOfThisHour(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
|
||||
case SHOP_REFRESH_WEEKLY -> Utils.GetNextTimestampOfThisHourInNextWeek(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
|
||||
case SHOP_REFRESH_MONTHLY -> Utils.GetNextTimestampOfThisHourInNextMonth(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
public synchronized void load() {
|
||||
try (FileReader fileReader = new FileReader(Grasscutter.getConfig().DATA_FOLDER + "Shop.json")) {
|
||||
getShopData().clear();
|
||||
List<ShopTable> banners = Grasscutter.getGsonFactory().fromJson(fileReader, TypeToken.getParameterized(Collection.class, ShopTable.class).getType());
|
||||
if(banners.size() > 0) {
|
||||
for (ShopTable shopTable : banners) {
|
||||
for (ShopInfo cost : shopTable.getItems()) {
|
||||
if (cost.getCostItemList() != null) {
|
||||
Iterator<ItemParamData> iterator = cost.getCostItemList().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ItemParamData ipd = iterator.next();
|
||||
if (ipd.getId() == 201) {
|
||||
cost.setHcoin(cost.getHcoin() + ipd.getCount());
|
||||
iterator.remove();
|
||||
}
|
||||
if (ipd.getId() == 203) {
|
||||
cost.setMcoin(cost.getMcoin() + ipd.getCount());
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
getShopData().put(shopTable.getShopId(), shopTable.getItems());
|
||||
}
|
||||
Grasscutter.getLogger().info("Shop data successfully loaded.");
|
||||
} else {
|
||||
Grasscutter.getLogger().error("Unable to load shop data. Shop data size is 0.");
|
||||
}
|
||||
|
||||
if (Grasscutter.getConfig().getGameServerOptions().EnableOfficialShop) {
|
||||
GameData.getShopGoodsDataEntries().forEach((k, v) -> {
|
||||
if (!getShopData().containsKey(k.intValue()))
|
||||
getShopData().put(k.intValue(), new ArrayList<>());
|
||||
for (ShopGoodsData sgd : v) {
|
||||
var shopInfo = new ShopInfo(sgd);
|
||||
getShopData().get(k.intValue()).add(shopInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user