Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Librarian Story Quest #2218

Merged
merged 7 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/emu/grasscutter/game/entity/GameEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public GameEntity(Scene scene) {

public abstract void initAbilities();

public int getEntityType() {
return this.getId() >> 24;
public EntityType getEntityType() {
return EntityIdType.toEntityType(this.getId() >> 24);
scooterboo marked this conversation as resolved.
Show resolved Hide resolved
}

public abstract int getEntityTypeId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import emu.grasscutter.net.proto.GatherGadgetInfoOuterClass.GatherGadgetInfo;
import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType;
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
import emu.grasscutter.scripts.constants.EventType;
import emu.grasscutter.scripts.data.ScriptArgs;
import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp;
import emu.grasscutter.utils.Utils;

Expand Down Expand Up @@ -57,6 +59,12 @@ public boolean onInteract(Player player, GadgetInteractReq req) {
GameItem item = new GameItem(itemData, 1);
player.getInventory().addItem(item, ActionReason.Gather);

getGadget()
.getScene()
.getScriptManager()
.callEvent(
new ScriptArgs(getGadget().getGroupId(), EventType.EVENT_GATHER, getGadget().getConfigId()));

getGadget()
.getScene()
.broadcastPacket(
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/emu/grasscutter/game/props/EntityIdType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package emu.grasscutter.game.props;

import java.util.HashMap;
import java.util.Map;

public enum EntityIdType {
AVATAR(0x01),
MONSTER(0x02),
Expand All @@ -12,10 +15,27 @@ public enum EntityIdType {

private final int id;

private static final Map<Integer, EntityType> map = new HashMap<>();

static {
map.put(EntityIdType.AVATAR.getId(),EntityType.Avatar);
map.put(EntityIdType.MONSTER.getId(),EntityType.Monster);
map.put(EntityIdType.NPC.getId(),EntityType.NPC);
map.put(EntityIdType.GADGET.getId(),EntityType.Gadget);
map.put(EntityIdType.REGION.getId(),EntityType.Region);
map.put(EntityIdType.WEAPON.getId(),EntityType.Equip);
map.put(EntityIdType.TEAM.getId(),EntityType.Team);
map.put(EntityIdType.MPLEVEL.getId(),EntityType.MPLevel);
}

EntityIdType(int id) {
this.id = id;
}

public static EntityType toEntityType(int entityId) {
return map.getOrDefault(entityId, EntityType.None);
}

public int getId() {
return id;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emu/grasscutter/game/props/EntityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public enum EntityType implements IntValueEnum {
Screen(64),
EchoShell(65),
UIInteractGadget(66),
Region(98),
PlaceHolder(99);

private static final Int2ObjectMap<EntityType> map = new Int2ObjectOpenHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public void checkRegions() {
getScene().getEntities().values().stream()
.filter(
e ->
e.getEntityType() == EntityType.Avatar.getValue()
e.getEntityType() == EntityType.Avatar
&& region.getMetaRegion().contains(e.getPosition()))
.toList();
entities.forEach(region::addEntity);
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/emu/grasscutter/scripts/ScriptLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import emu.grasscutter.game.quest.enums.QuestState;
import emu.grasscutter.game.world.SceneGroupInstance;
import emu.grasscutter.net.proto.EnterTypeOuterClass;
import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
import emu.grasscutter.scripts.constants.EventType;
import emu.grasscutter.scripts.constants.GroupKillPolicy;
import emu.grasscutter.scripts.data.SceneGroup;
Expand Down Expand Up @@ -610,6 +611,11 @@ public int CreateGadget(LuaTable table){
logger.debug("[LUA] Call CreateGadget with {}",
printTable(table));
var configId = table.get("config_id").toint();
//TODO: figure out what creating gadget configId 0 does
if (configId == 0){
Grasscutter.getLogger().warn("Tried to CreateGadget with config_id 0: {}", printTable(table));
return 0;
}

var group = getCurrentGroup();

Expand Down Expand Up @@ -704,7 +710,7 @@ public int GetEntityType(int entityId){
return EntityType.None.getValue();
}

return entity.getEntityType();
return entity.getEntityType().getValue();
}

public int GetQuestState(int entityId, int questId){
Expand Down Expand Up @@ -739,11 +745,11 @@ public int RemoveEntityByConfigId(int groupId, int entityType, int configId){

val entity = getSceneScriptManager().getScene().getEntityByConfigId(configId, groupId);

if(entity == null || entity.getEntityType() != entityType){
if(entity == null || entity.getEntityType().getValue() != entityType){
return 1;
}

getSceneScriptManager().getScene().removeEntity(entity);
getSceneScriptManager().getScene().removeEntity(entity, VisionType.VISION_TYPE_REMOVE);

return 0;
}
Expand Down Expand Up @@ -819,7 +825,7 @@ public int GetChannellerSlabLoopDungeonLimitTime(){
}
public int IsPlayerAllAvatarDie(int sceneUid){
logger.warn("[LUA] Call unimplemented IsPlayerAllAvatarDie {}", sceneUid);
var playerEntities = getSceneScriptManager().getScene().getEntities().values().stream().filter(e -> e.getEntityType() == EntityIdType.AVATAR.getId()).toList();
var playerEntities = getSceneScriptManager().getScene().getEntities().values().stream().filter(e -> e.getEntityType() == EntityType.Avatar).toList();
for (GameEntity p : playerEntities){
var player = (EntityAvatar)p;
if(player.isAlive()){
Expand Down
Loading