mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-23 16:16:46 +00:00
Fix errors caused by merge + Refactor chests into GadgetChest
This commit is contained in:
parent
73a88b2da2
commit
f53dda0335
@ -3,6 +3,7 @@ package emu.grasscutter.game.entity;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.def.GadgetData;
|
||||
import emu.grasscutter.game.entity.gadget.GadgetChest;
|
||||
import emu.grasscutter.game.entity.gadget.GadgetContent;
|
||||
import emu.grasscutter.game.entity.gadget.GadgetGatherPoint;
|
||||
import emu.grasscutter.game.entity.gadget.GadgetRewardStatue;
|
||||
@ -27,6 +28,7 @@ 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.WorktopInfoOuterClass.WorktopInfo;
|
||||
import emu.grasscutter.server.packet.send.PacketGadgetStateNotify;
|
||||
import emu.grasscutter.utils.Position;
|
||||
import emu.grasscutter.utils.ProtoHelper;
|
||||
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
|
||||
@ -91,6 +93,11 @@ public class EntityGadget extends EntityBaseGadget {
|
||||
public void setState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public void updateState(int state){
|
||||
this.setState(state);
|
||||
this.getScene().broadcastPacket(new PacketGadgetStateNotify(this, state));
|
||||
}
|
||||
|
||||
public int getPointType() {
|
||||
return pointType;
|
||||
@ -120,6 +127,7 @@ public class EntityGadget extends EntityBaseGadget {
|
||||
case GatherPoint -> new GadgetGatherPoint(this);
|
||||
case Worktop -> new GadgetWorktop(this);
|
||||
case RewardStatue -> new GadgetRewardStatue(this);
|
||||
case Chest -> new GadgetChest(this);
|
||||
default -> null;
|
||||
};
|
||||
|
||||
@ -176,30 +184,4 @@ public class EntityGadget extends EntityBaseGadget {
|
||||
|
||||
return entityInfo.build();
|
||||
}
|
||||
|
||||
public void openChest(Player player) {
|
||||
var chestRewardMap = getScene().getWorld().getServer().getWorldDataManager().getChestRewardMap();
|
||||
var chestReward = chestRewardMap.get(this.getGadgetData().getJsonName());
|
||||
if(chestReward == null){
|
||||
Grasscutter.getLogger().warn("Could not found the config of this type of Chests {}", this.getGadgetData().getJsonName());
|
||||
return;
|
||||
}
|
||||
|
||||
player.earnExp(chestReward.getAdvExp());
|
||||
player.getInventory().addItem(201, chestReward.getResin());
|
||||
|
||||
var mora = chestReward.getMora() * (1 + (player.getWorldLevel() - 1) * 0.5);
|
||||
player.getInventory().addItem(202, (int)mora);
|
||||
|
||||
for(int i=0;i<chestReward.getContent().size();i++){
|
||||
getScene().addItemEntity(chestReward.getContent().get(i).getItemId(), chestReward.getContent().get(i).getCount(), this);
|
||||
}
|
||||
|
||||
var random = new Random(System.currentTimeMillis());
|
||||
for(int i=0;i<chestReward.getRandomCount();i++){
|
||||
var index = random.nextInt(chestReward.getRandomContent().size());
|
||||
var item = chestReward.getRandomContent().get(index);
|
||||
getScene().addItemEntity(item.getItemId(), item.getCount(), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package emu.grasscutter.game.entity.gadget;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.game.entity.EntityGadget;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType;
|
||||
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
|
||||
import emu.grasscutter.scripts.constants.ScriptGadgetState;
|
||||
import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp;
|
||||
|
||||
public class GadgetChest extends GadgetContent {
|
||||
|
||||
public GadgetChest(EntityGadget gadget) {
|
||||
super(gadget);
|
||||
}
|
||||
|
||||
public boolean onInteract(Player player) {
|
||||
var chestRewardMap = getGadget().getScene().getWorld().getServer().getWorldDataManager().getChestRewardMap();
|
||||
var chestReward = chestRewardMap.get(getGadget().getGadgetData().getJsonName());
|
||||
if (chestReward == null) {
|
||||
Grasscutter.getLogger().warn("Could not found the config of this type of Chests {}", getGadget().getGadgetData().getJsonName());
|
||||
return true;
|
||||
}
|
||||
|
||||
player.earnExp(chestReward.getAdvExp());
|
||||
player.getInventory().addItem(201, chestReward.getResin());
|
||||
|
||||
var mora = chestReward.getMora() * (1 + (player.getWorldLevel() - 1) * 0.5);
|
||||
player.getInventory().addItem(202, (int)mora);
|
||||
|
||||
for(int i=0;i<chestReward.getContent().size();i++){
|
||||
getGadget().getScene().addItemEntity(chestReward.getContent().get(i).getItemId(), chestReward.getContent().get(i).getCount(), getGadget());
|
||||
}
|
||||
|
||||
var random = new Random(System.currentTimeMillis());
|
||||
for(int i=0;i<chestReward.getRandomCount();i++){
|
||||
var index = random.nextInt(chestReward.getRandomContent().size());
|
||||
var item = chestReward.getRandomContent().get(index);
|
||||
getGadget().getScene().addItemEntity(item.getItemId(), item.getCount(), getGadget());
|
||||
}
|
||||
|
||||
getGadget().updateState(ScriptGadgetState.ChestOpened);
|
||||
player.sendPacket(new PacketGadgetInteractRsp(getGadget(), InteractType.INTERACT_OPEN_CHEST));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onBuildProto(SceneGadgetInfo.Builder gadgetInfo) {
|
||||
|
||||
}
|
||||
}
|
@ -928,13 +928,6 @@ public class Player {
|
||||
if (shouldDelete) {
|
||||
entity.getScene().removeEntity(entity);
|
||||
}
|
||||
else if (gadget.getGadgetData().getType() == EntityType.Chest) {
|
||||
getScene().updateGadgetState(gadget, ScriptGadgetState.ChestOpened);
|
||||
gadget.openChest(this);
|
||||
|
||||
this.sendPacket(new PacketGadgetInteractRsp(gadget, InteractType.INTERACT_OPEN_CHEST));
|
||||
getScene().killEntity(gadget, 0);
|
||||
}
|
||||
} else {
|
||||
// Delete directly
|
||||
entity.getScene().removeEntity(entity);
|
||||
|
@ -579,7 +579,7 @@ public class Scene {
|
||||
List<SceneGadget> garbageGadgets = group.getGarbageGadgets();
|
||||
|
||||
if (garbageGadgets != null) {
|
||||
garbageGadgets.forEach(g -> scriptManager.createGadgets(group.id, group.block_id, g));
|
||||
garbageGadgets.forEach(g -> scriptManager.createGadget(group.id, group.block_id, g));
|
||||
}
|
||||
|
||||
// Load suites
|
||||
@ -706,9 +706,4 @@ public class Scene {
|
||||
addEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateGadgetState(EntityGadget gadget, int state){
|
||||
gadget.setState(state);
|
||||
broadcastPacket(new PacketGadgetStateNotify(gadget, state));
|
||||
}
|
||||
}
|
||||
|
@ -437,8 +437,8 @@ public class ScriptLib {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(entity instanceof EntityGadget entityGadget){
|
||||
getSceneScriptManager().getScene().updateGadgetState(entityGadget, state);
|
||||
if (entity instanceof EntityGadget entityGadget) {
|
||||
entityGadget.updateState(state);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user