Skip to content

Commit

Permalink
Everything triggers regions (#2271)
Browse files Browse the repository at this point in the history
* Everything triggers regions

* hotfix
  • Loading branch information
scooterboo authored Jul 23, 2023
1 parent 0b806e2 commit ddc082f
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions src/main/java/emu/grasscutter/scripts/SceneScriptManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.entity.*;
import emu.grasscutter.game.entity.gadget.platform.BaseRoute;
import emu.grasscutter.game.props.EntityType;
import emu.grasscutter.game.props.EntityIdType;
import emu.grasscutter.game.quest.*;
import emu.grasscutter.game.world.*;
import emu.grasscutter.net.proto.VisionTypeOuterClass;
Expand Down Expand Up @@ -634,27 +634,24 @@ public void checkRegions() {
var entities =
getScene().getEntities().values().stream()
.filter(
e ->
e.getEntityType() == EntityType.Avatar
&& region.getMetaRegion().contains(e.getPosition()))
e ->
region.getMetaRegion().contains(e.getPosition()))
.toList();
entities.forEach(region::addEntity);

var targetId = 0;
if (entities.size() > 0) {
targetId = entities.get(0).getId();
}
var entitiesIds = entities.stream().map(GameEntity::getId).toList();
var enterEntities = entitiesIds.stream().filter(e -> !region.getEntities().contains(e)).toList();
var leaveEntities = region.getEntities().stream().filter(e -> !entitiesIds.contains(e)).toList();

entities.forEach(region::addEntity);

if (region.entityHasEntered()) {
for (var targetId : enterEntities){
Grasscutter.getLogger()
.trace("Call EVENT_ENTER_REGION_{}", region.getMetaRegion().config_id);
this.callEvent(
new ScriptArgs(region.getGroupId(), EventType.EVENT_ENTER_REGION, region.getConfigId())
.setEventSource(EntityType.Avatar.getValue())
.setEventSource(EntityIdType.toEntityType(targetId>>24).getValue())
.setSourceEntityId(region.getId())
.setTargetEntityId(targetId));

region.resetNewEntities();
}

for (var entityId : region.getEntities()) {
Expand All @@ -664,14 +661,12 @@ public void checkRegions() {
}
}

if (region.entityHasLeft()) {
for (var targetId : leaveEntities) {
this.callEvent(
new ScriptArgs(region.getGroupId(), EventType.EVENT_LEAVE_REGION, region.getConfigId())
.setEventSource(EntityType.Avatar.getValue())
.setEventSource(EntityIdType.toEntityType(targetId>>24).getValue())
.setSourceEntityId(region.getId())
.setTargetEntityId(region.getFirstEntityId()));

region.resetNewEntities();
.setTargetEntityId(targetId));
}
}
}
Expand Down Expand Up @@ -899,15 +894,13 @@ private void callTrigger(SceneTrigger trigger, ScriptArgs params) {
.toList()
.get(0);
this.getScene().getPlayers().forEach(p -> p.onEnterRegion(region.getMetaRegion()));
this.deregisterRegion(region.getMetaRegion());
} else if (trigger.getEvent() == EventType.EVENT_LEAVE_REGION) {
var region =
this.regions.values().stream()
.filter(p -> p.getConfigId() == params.param1)
.toList()
.get(0);
this.getScene().getPlayers().forEach(p -> p.onLeaveRegion(region.getMetaRegion()));
this.deregisterRegion(region.getMetaRegion());
}

if (trigger.getEvent() == EVENT_TIMER_EVENT) {
Expand Down

0 comments on commit ddc082f

Please sign in to comment.