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

Some fix about scene script and quest #2029

Merged
merged 7 commits into from
Feb 9, 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
14 changes: 8 additions & 6 deletions src/main/java/emu/grasscutter/game/quest/GameMainQuest.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ public void finish() {

// Add rewards
MainQuestData mainQuestData = GameData.getMainQuestDataMap().get(this.getParentQuestId());
for (int rewardId : mainQuestData.getRewardIdList()) {
RewardData rewardData = GameData.getRewardDataMap().get(rewardId);
if (mainQuestData != null && mainQuestData.getRewardIdList() != null) {
for (int rewardId : mainQuestData.getRewardIdList()) {
RewardData rewardData = GameData.getRewardDataMap().get(rewardId);

if (rewardData == null) {
continue;
}
if (rewardData == null) {
continue;
}

getOwner().getInventory().addItemParamDatas(rewardData.getRewardItemList(), ActionReason.QuestReward);
getOwner().getInventory().addItemParamDatas(rewardData.getRewardItemList(), ActionReason.QuestReward);
}
}

// handoff main quest
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emu/grasscutter/game/quest/QuestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ public void triggerEvent(QuestTrigger condType, String paramStr, int... params)
case QUEST_CONTENT_INTERACT_GADGET:
case QUEST_CONTENT_TRIGGER_FIRE:
case QUEST_CONTENT_UNLOCK_TRANS_POINT:
case QUEST_CONTENT_SKILL:
for (GameMainQuest mainQuest : checkMainQuests) {
mainQuest.tryFinishSubQuests(condType, paramStr, params);
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/emu/grasscutter/game/quest/content/ContentSkill.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package emu.grasscutter.game.quest.content;

import emu.grasscutter.data.excels.QuestData;
import emu.grasscutter.game.quest.GameQuest;
import emu.grasscutter.game.quest.QuestValue;
import emu.grasscutter.game.quest.enums.QuestTrigger;

@QuestValue(QuestTrigger.QUEST_CONTENT_SKILL)
public class ContentSkill extends BaseContent {
@Override
public boolean execute(GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) {
return (condition.getParam()[0] == params[0]) && (condition.getParam()[1] == params[1]);
}
}
6 changes: 6 additions & 0 deletions src/main/java/emu/grasscutter/scripts/SceneScriptManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,22 @@ public void resetTriggers(int eventId) {
currentTriggers.put(eventId, new HashSet<>());
}
public void refreshGroup(SceneGroup group, int suiteIndex) {
if (group == null) {
return;
}
ZanyRain marked this conversation as resolved.
Show resolved Hide resolved

var suite = group.getSuiteByIndex(suiteIndex);
if (suite == null) {
return;
}

if (suite.sceneTriggers.size() > 0) {
for (var trigger : suite.sceneTriggers) {
resetTriggers(trigger.event);
this.currentTriggers.get(trigger.event).add(trigger);
}
}

spawnMonstersInGroup(group, suite);
spawnGadgetsInGroup(group, suite);
}
Expand Down
52 changes: 30 additions & 22 deletions src/main/java/emu/grasscutter/scripts/ScriptLib.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package emu.grasscutter.scripts;

import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.dungeons.challenge.DungeonChallenge;
import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.entity.gadget.GadgetWorktop;
import emu.grasscutter.game.dungeons.challenge.factory.ChallengeFactory;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.EntityType;
import emu.grasscutter.game.quest.enums.QuestState;
import emu.grasscutter.game.quest.enums.QuestTrigger;
Expand Down Expand Up @@ -89,14 +91,14 @@ public int SetGroupGadgetStateByConfigId(int groupId, int configId, int gadgetSt
.filter(e -> e instanceof EntityGadget)
.map(e -> (EntityGadget)e)
.forEach(e -> e.updateState(gadgetState));

return 0;
}

public int SetWorktopOptionsByGroupId(int groupId, int configId, int[] options) {
logger.debug("[LUA] Call SetWorktopOptionsByGroupId with {},{},{}",
groupId,configId,options);

Optional<GameEntity> entity = getSceneScriptManager().getScene().getEntities().values().stream()
.filter(e -> e.getConfigId() == configId && e.getGroupId() == groupId).findFirst();

Expand All @@ -108,10 +110,10 @@ public int SetWorktopOptionsByGroupId(int groupId, int configId, int[] options)
if (!(gadget.getContent() instanceof GadgetWorktop worktop)) {
return 1;
}

worktop.addWorktopOptions(options);
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));

return 0;
}

Expand All @@ -133,13 +135,13 @@ public int DelWorktopOptionByGroupId(int groupId, int configId, int option) {
if (!(gadget.getContent() instanceof GadgetWorktop worktop)) {
return 1;
}

worktop.removeWorktopOption(option);
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));

return 0;
}

// Some fields are guessed
public int AutoMonsterTide(int challengeIndex, int groupId, Integer[] ordersConfigId, int tideCount, int sceneLimit, int param6) {
logger.debug("[LUA] Call AutoMonsterTide with {},{},{},{},{},{}",
Expand All @@ -152,15 +154,15 @@ public int AutoMonsterTide(int challengeIndex, int groupId, Integer[] ordersConf
}

this.getSceneScriptManager().startMonsterTideInGroup(group, ordersConfigId, tideCount, sceneLimit);

return 0;
}

public int AddExtraGroupSuite(int groupId, int suite) {
logger.debug("[LUA] Call AddExtraGroupSuite with {},{}",
groupId,suite);
SceneGroup group = getSceneScriptManager().getGroupById(groupId);

if (group == null || group.monsters == null) {
return 1;
}
Expand Down Expand Up @@ -263,28 +265,28 @@ public int ActiveChallenge(int challengeId, int challengeIndex, int timeLimitOrG
challenge.start();
return 0;
}

public int GetGroupMonsterCountByGroupId(int groupId) {
logger.debug("[LUA] Call GetGroupMonsterCountByGroupId with {}",
groupId);
return (int) getSceneScriptManager().getScene().getEntities().values().stream()
.filter(e -> e instanceof EntityMonster && e.getGroupId() == groupId)
.count();
}

public int GetGroupVariableValue(String var) {
logger.debug("[LUA] Call GetGroupVariableValue with {}",
var);
return getSceneScriptManager().getVariables().getOrDefault(var, 0);
}

public int SetGroupVariableValue(String var, int value) {
logger.debug("[LUA] Call SetGroupVariableValue with {},{}",
var, value);
getSceneScriptManager().getVariables().put(var, value);
return 0;
}

public LuaValue ChangeGroupVariableValue(String var, int value) {
logger.debug("[LUA] Call ChangeGroupVariableValue with {},{}",
var, value);
Expand All @@ -302,15 +304,15 @@ public int RefreshGroup(LuaTable table) {
// Kill and Respawn?
int groupId = table.get("group_id").toint();
int suite = table.get("suite").toint();

SceneGroup group = getSceneScriptManager().getGroupById(groupId);

if (group == null || group.monsters == null) {
return 1;
}

getSceneScriptManager().refreshGroup(group, suite);

return 0;
}

Expand Down Expand Up @@ -430,14 +432,14 @@ public int CreateGadget(LuaTable table){
var configId = table.get("config_id").toint();

var group = getCurrentGroup();

if (group.isEmpty()) {
return 1;
}

var gadget = group.get().gadgets.get(configId);
var entity = getSceneScriptManager().createGadget(group.get().id, group.get().block_id, gadget);

getSceneScriptManager().addEntity(entity);

return 0;
Expand Down Expand Up @@ -515,6 +517,12 @@ public int ChangeGroupGadget(LuaTable table){
public int GetEntityType(int entityId){
var entity = getSceneScriptManager().getScene().getEntityById(entityId);
if(entity == null){
// check players
Player player = DatabaseHelper.getPlayerByUid(entityId);
if (player != null) {
return EntityType.Avatar.getValue();
}

return EntityType.None.getValue();
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/emu/grasscutter/scripts/data/Explore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package emu.grasscutter.scripts.data;

import lombok.Setter;
import lombok.ToString;

@ToString
@Setter
public class Explore {
public String name;
public int exp;
}
7 changes: 7 additions & 0 deletions src/main/java/emu/grasscutter/scripts/data/SceneGadget.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public class SceneGadget extends SceneObject{
public int interact_id;
public boolean isOneoff;
public int draft_id;
public String drop_tag;
public boolean persistent;
public int mark_flag;
public int route_id;
public Explore explore;
public int trigger_count;
public boolean showcutscene;

public void setIsOneoff(boolean isOneoff) {
this.isOneoff = isOneoff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
public class SceneInitConfig {
public int suite;
public int end_suite;
public int rand_suite;
public boolean rand_suite;
}
9 changes: 8 additions & 1 deletion src/main/java/emu/grasscutter/scripts/data/SceneMonster.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ public class SceneMonster extends SceneObject{
public int monster_id;
public int pose_id;
public int drop_id;
}
public int special_name_id;
public String drop_tag;
public int climate_area_id;
public boolean disableWander;
public int title_id;
public int[] affix;
public int mark_flag;
}
5 changes: 5 additions & 0 deletions src/main/java/emu/grasscutter/scripts/data/SceneRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import emu.grasscutter.utils.Position;
import lombok.Setter;

import java.util.List;


@Setter
public class SceneRegion {
Expand All @@ -14,6 +16,9 @@ public class SceneRegion {
public Position size;
// for SPHERE
public int radius;
public int area_id;
public float height;
public List<Position> point_array;

public transient SceneGroup group;
public boolean contains(Position position) {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/emu/grasscutter/scripts/data/SceneSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
@ToString
@Setter
public class SceneSuite {
// make it refer the default empty list to avoid NPE caused by some group
// make it refer the default empty list to avoid NPE caused by some group
public List<Integer> monsters = List.of();
public List<Integer> gadgets = List.of();
public List<String> triggers = List.of();
public List<Integer> regions = List.of();
public int rand_weight;
public int[] npcs;

public transient List<SceneMonster> sceneMonsters = List.of();
public transient List<SceneGadget> sceneGadgets = List.of();
public transient List<SceneTrigger> sceneTriggers = List.of();
public transient List<SceneRegion> sceneRegions = List.of();

public void init(SceneGroup sceneGroup) {
if(sceneGroup.monsters != null){
if(sceneGroup.monsters != null && this.monsters != null){
this.sceneMonsters = new ArrayList<>(
this.monsters.stream()
.filter(sceneGroup.monsters::containsKey)
Expand All @@ -31,7 +32,7 @@ public void init(SceneGroup sceneGroup) {
);
}

if(sceneGroup.gadgets != null){
if(sceneGroup.gadgets != null && this.gadgets != null){
this.sceneGadgets = new ArrayList<>(
this.gadgets.stream()
.filter(sceneGroup.gadgets::containsKey)
Expand All @@ -40,15 +41,15 @@ public void init(SceneGroup sceneGroup) {
);
}

if(sceneGroup.triggers != null) {
if(sceneGroup.triggers != null && this.triggers != null) {
this.sceneTriggers = new ArrayList<>(
this.triggers.stream()
.filter(sceneGroup.triggers::containsKey)
.map(sceneGroup.triggers::get)
.toList()
);
}
if(sceneGroup.regions != null) {
if(sceneGroup.regions != null && this.regions != null) {
this.sceneRegions = new ArrayList<>(
this.regions.stream()
.filter(sceneGroup.regions::containsKey)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/emu/grasscutter/scripts/data/SceneTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class SceneTrigger {
public String source;
public String condition;
public String action;
public boolean forbid_guest;
public int trigger_count;
public String tlog_tag;

public transient SceneGroup currentGroup;
@Override
Expand All @@ -34,6 +37,8 @@ public String toString() {
", source='" + source + '\'' +
", condition='" + condition + '\'' +
", action='" + action + '\'' +
", forbid_guest='" + forbid_guest + '\'' +
", trigger_count='" + trigger_count + '\'' +
'}';
}
}
1 change: 1 addition & 0 deletions src/main/java/emu/grasscutter/scripts/data/SceneVar.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class SceneVar {
public String name;
public int value;
public boolean no_refresh;
public int configId;
}
Loading