Commit 791b9534 authored by Akka's avatar Akka Committed by Melledy
Browse files

refactor the challenge

parent 717c2d1d
package emu.grasscutter.scripts; package emu.grasscutter.scripts;
import emu.grasscutter.game.dungeons.DungeonChallenge; import emu.grasscutter.game.dungeons.challenge.DungeonChallenge;
import emu.grasscutter.game.entity.EntityGadget; import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.entity.gadget.GadgetWorktop; import emu.grasscutter.game.entity.gadget.GadgetWorktop;
import emu.grasscutter.game.dungeons.challenge.factory.ChallengeFactory;
import emu.grasscutter.scripts.data.SceneGroup; import emu.grasscutter.scripts.data.SceneGroup;
import emu.grasscutter.scripts.data.SceneRegion; import emu.grasscutter.scripts.data.SceneRegion;
import emu.grasscutter.server.packet.send.PacketCanUseSkillNotify; import emu.grasscutter.server.packet.send.PacketCanUseSkillNotify;
...@@ -159,48 +160,102 @@ public class ScriptLib { ...@@ -159,48 +160,102 @@ public class ScriptLib {
if (group == null || group.monsters == null) { if (group == null || group.monsters == null) {
return 1; return 1;
} }
var suiteData = group.getSuiteByIndex(suite);
if(suiteData == null){
return 1;
}
// avoid spawn wrong monster // avoid spawn wrong monster
if(getSceneScriptManager().getScene().getChallenge() != null) if(getSceneScriptManager().getScene().getChallenge() != null)
if(!getSceneScriptManager().getScene().getChallenge().inProgress() || if(!getSceneScriptManager().getScene().getChallenge().inProgress() ||
getSceneScriptManager().getScene().getChallenge().getGroup().id != groupId){ getSceneScriptManager().getScene().getChallenge().getGroup().id != groupId){
return 0; return 0;
} }
this.getSceneScriptManager().spawnMonstersInGroup(group, suite); this.getSceneScriptManager().addGroupSuite(group, suiteData);
return 0; return 0;
} }
public int GoToGroupSuite(int groupId, int suite) {
// param3 (probably time limit for timed dungeons) logger.debug("[LUA] Call GoToGroupSuite with {},{}",
public int ActiveChallenge(int challengeId, int challengeIndex, int timeLimitOrGroupId, int groupId, int objectiveKills, int param5) { groupId,suite);
logger.debug("[LUA] Call ActiveChallenge with {},{},{},{},{},{}",
challengeId,challengeIndex,timeLimitOrGroupId,groupId,objectiveKills,param5);
SceneGroup group = getSceneScriptManager().getGroupById(groupId); SceneGroup group = getSceneScriptManager().getGroupById(groupId);
var objective = objectiveKills; if (group == null || group.monsters == null) {
return 1;
}
var suiteData = group.getSuiteByIndex(suite);
if(suiteData == null){
return 1;
}
if(group == null){ for(var suiteItem : group.suites){
group = getSceneScriptManager().getGroupById(timeLimitOrGroupId); if(suiteData == suiteItem){
objective = groupId; continue;
}
this.getSceneScriptManager().removeGroupSuite(group, suiteItem);
} }
this.getSceneScriptManager().addGroupSuite(group, suiteData);
return 0;
}
public int RemoveExtraGroupSuite(int groupId, int suite) {
logger.debug("[LUA] Call RemoveExtraGroupSuite with {},{}",
groupId,suite);
SceneGroup group = getSceneScriptManager().getGroupById(groupId);
if (group == null || group.monsters == null) { if (group == null || group.monsters == null) {
return 1; return 1;
} }
var suiteData = group.getSuiteByIndex(suite);
if(suiteData == null){
return 1;
}
if(getSceneScriptManager().getScene().getChallenge() != null && this.getSceneScriptManager().removeGroupSuite(group, suiteData);
getSceneScriptManager().getScene().getChallenge().inProgress())
{ return 0;
return 0; }
public int KillExtraGroupSuite(int groupId, int suite) {
logger.debug("[LUA] Call KillExtraGroupSuite with {},{}",
groupId,suite);
SceneGroup group = getSceneScriptManager().getGroupById(groupId);
if (group == null || group.monsters == null) {
return 1;
}
var suiteData = group.getSuiteByIndex(suite);
if(suiteData == null){
return 1;
} }
DungeonChallenge challenge = new DungeonChallenge(getSceneScriptManager().getScene(), this.getSceneScriptManager().removeGroupSuite(group, suiteData);
group, challengeId, challengeIndex, objective);
// set if tower first stage (6-1)
challenge.setStage(getSceneScriptManager().getVariables().getOrDefault("stage", -1) == 0);
getSceneScriptManager().getScene().setChallenge(challenge); return 0;
}
// param3 (probably time limit for timed dungeons)
public int ActiveChallenge(int challengeId, int challengeIndex, int timeLimitOrGroupId, int groupId, int objectiveKills, int param5) {
logger.debug("[LUA] Call ActiveChallenge with {},{},{},{},{},{}",
challengeId,challengeIndex,timeLimitOrGroupId,groupId,objectiveKills,param5);
var challenge = ChallengeFactory.getChallenge(
challengeId,
challengeIndex,
timeLimitOrGroupId,
groupId,
objectiveKills,
param5,
getSceneScriptManager().getScene(),
getCurrentGroup().get()
);
if(challenge == null){
return 1;
}
if(challenge instanceof DungeonChallenge dungeonChallenge){
// set if tower first stage (6-1)
dungeonChallenge.setStage(getSceneScriptManager().getVariables().getOrDefault("stage", -1) == 0);
}
getSceneScriptManager().getScene().setChallenge(challenge);
challenge.start(); challenge.start();
return 0; return 0;
} }
...@@ -257,7 +312,7 @@ public class ScriptLib { ...@@ -257,7 +312,7 @@ public class ScriptLib {
public int GetRegionEntityCount(LuaTable table) { public int GetRegionEntityCount(LuaTable table) {
logger.debug("[LUA] Call GetRegionEntityCount with {}", logger.debug("[LUA] Call GetRegionEntityCount with {}",
table); printTable(table));
int regionId = table.get("region_eid").toint(); int regionId = table.get("region_eid").toint();
int entityType = table.get("entity_type").toint(); int entityType = table.get("entity_type").toint();
...@@ -280,9 +335,8 @@ public class ScriptLib { ...@@ -280,9 +335,8 @@ public class ScriptLib {
// TODO record time // TODO record time
return 0; return 0;
} }
public int GetGroupMonsterCount(int var1){ public int GetGroupMonsterCount(){
logger.debug("[LUA] Call GetGroupMonsterCount with {}", logger.debug("[LUA] Call GetGroupMonsterCount ");
var1);
return (int) getSceneScriptManager().getScene().getEntities().values().stream() return (int) getSceneScriptManager().getScene().getEntities().values().stream()
.filter(e -> e instanceof EntityMonster && .filter(e -> e instanceof EntityMonster &&
...@@ -328,7 +382,7 @@ public class ScriptLib { ...@@ -328,7 +382,7 @@ public class ScriptLib {
var entity = getSceneScriptManager().getScene().getEntityByConfigId(configId.toint()); var entity = getSceneScriptManager().getScene().getEntityByConfigId(configId.toint());
if(entity == null){ if(entity == null){
return 1; return 0;
} }
getSceneScriptManager().getScene().killEntity(entity, 0); getSceneScriptManager().getScene().killEntity(entity, 0);
return 0; return 0;
...@@ -398,8 +452,13 @@ public class ScriptLib { ...@@ -398,8 +452,13 @@ public class ScriptLib {
public int GetGadgetStateByConfigId(int groupId, int configId){ public int GetGadgetStateByConfigId(int groupId, int configId){
logger.debug("[LUA] Call GetGadgetStateByConfigId with {},{}", logger.debug("[LUA] Call GetGadgetStateByConfigId with {},{}",
groupId, configId); groupId, configId);
if(groupId == 0){
groupId = getCurrentGroup().get().id;
}
final int realGroupId = groupId;
var gadget = getSceneScriptManager().getScene().getEntities().values().stream() var gadget = getSceneScriptManager().getScene().getEntities().values().stream()
.filter(g -> g instanceof EntityGadget entityGadget && entityGadget.getGroupId() == groupId) .filter(g -> g instanceof EntityGadget entityGadget && entityGadget.getGroupId() == realGroupId)
.filter(g -> g.getConfigId() == configId) .filter(g -> g.getConfigId() == configId)
.findFirst(); .findFirst();
if(gadget.isEmpty()){ if(gadget.isEmpty()){
...@@ -409,8 +468,8 @@ public class ScriptLib { ...@@ -409,8 +468,8 @@ public class ScriptLib {
} }
public int MarkPlayerAction(int var1, int var2, int var3, int var4){ public int MarkPlayerAction(int var1, int var2, int var3, int var4){
logger.debug("[LUA] Call MarkPlayerAction with {},{}", logger.debug("[LUA] Call MarkPlayerAction with {},{},{},{}",
var1, var2); var1, var2,var3,var4);
return 0; return 0;
} }
......
...@@ -10,4 +10,5 @@ public class SceneGadget extends SceneObject{ ...@@ -10,4 +10,5 @@ public class SceneGadget extends SceneObject{
public int state; public int state;
public int point_type; public int point_type;
public SceneBossChest boss_chest; public SceneBossChest boss_chest;
public int interact_id;
} }
...@@ -73,7 +73,7 @@ public class SceneGroup { ...@@ -73,7 +73,7 @@ public class SceneGroup {
return bindings; return bindings;
} }
public SceneGroup load(int sceneId){ public synchronized SceneGroup load(int sceneId){
if(loaded){ if(loaded){
return this; return this;
} }
...@@ -118,6 +118,7 @@ public class SceneGroup { ...@@ -118,6 +118,7 @@ public class SceneGroup {
garbages = new SceneGarbage(); garbages = new SceneGarbage();
if (garbagesTable.checktable().get("gadgets") != LuaValue.NIL) { if (garbagesTable.checktable().get("gadgets") != LuaValue.NIL) {
garbages.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, garbagesTable.checktable().get("gadgets").checktable()); garbages.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, garbagesTable.checktable().get("gadgets").checktable());
garbages.gadgets.forEach(m -> m.group = this);
} }
} }
......
...@@ -7,4 +7,6 @@ import lombok.ToString; ...@@ -7,4 +7,6 @@ import lombok.ToString;
@Setter @Setter
public class SceneMonster extends SceneObject{ public class SceneMonster extends SceneObject{
public int monster_id; public int monster_id;
public int pose_id;
public int drop_id;
} }
\ No newline at end of file
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.dungeons.DungeonChallenge; import emu.grasscutter.game.dungeons.challenge.WorldChallenge;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ChallengeDataNotifyOuterClass.ChallengeDataNotify; import emu.grasscutter.net.proto.ChallengeDataNotifyOuterClass.ChallengeDataNotify;
public class PacketChallengeDataNotify extends BasePacket { public class PacketChallengeDataNotify extends BasePacket {
public PacketChallengeDataNotify(DungeonChallenge challenge, int index, int value) { public PacketChallengeDataNotify(WorldChallenge challenge, int index, int value) {
super(PacketOpcodes.ChallengeDataNotify); super(PacketOpcodes.ChallengeDataNotify);
ChallengeDataNotify proto = ChallengeDataNotify.newBuilder() ChallengeDataNotify proto = ChallengeDataNotify.newBuilder()
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.dungeons.DungeonChallenge; import emu.grasscutter.game.dungeons.challenge.WorldChallenge;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.DungeonChallengeBeginNotifyOuterClass.DungeonChallengeBeginNotify; import emu.grasscutter.net.proto.DungeonChallengeBeginNotifyOuterClass.DungeonChallengeBeginNotify;
public class PacketDungeonChallengeBeginNotify extends BasePacket { public class PacketDungeonChallengeBeginNotify extends BasePacket {
public PacketDungeonChallengeBeginNotify(DungeonChallenge challenge) { public PacketDungeonChallengeBeginNotify(WorldChallenge challenge) {
super(PacketOpcodes.DungeonChallengeBeginNotify, true); super(PacketOpcodes.DungeonChallengeBeginNotify, true);
DungeonChallengeBeginNotify proto = DungeonChallengeBeginNotify.newBuilder() DungeonChallengeBeginNotify proto = DungeonChallengeBeginNotify.newBuilder()
.setChallengeId(challenge.getChallengeId()) .setChallengeId(challenge.getChallengeId())
.setChallengeIndex(challenge.getChallengeIndex()) .setChallengeIndex(challenge.getChallengeIndex())
.setGroupId(challenge.getGroup().id) .setGroupId(challenge.getGroup().id)
.addParamList(challenge.getObjective()) .addAllParamList(challenge.getParamList())
.addParamList(challenge.getTimeLimit())
.build(); .build();
this.setData(proto); this.setData(proto);
} }
} }
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.dungeons.DungeonChallenge; import emu.grasscutter.game.dungeons.challenge.WorldChallenge;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.DungeonChallengeFinishNotifyOuterClass.DungeonChallengeFinishNotify; import emu.grasscutter.net.proto.DungeonChallengeFinishNotifyOuterClass.DungeonChallengeFinishNotify;
public class PacketDungeonChallengeFinishNotify extends BasePacket { public class PacketDungeonChallengeFinishNotify extends BasePacket {
public PacketDungeonChallengeFinishNotify(DungeonChallenge challenge) { public PacketDungeonChallengeFinishNotify(WorldChallenge challenge) {
super(PacketOpcodes.DungeonChallengeFinishNotify, true); super(PacketOpcodes.DungeonChallengeFinishNotify, true);
DungeonChallengeFinishNotify proto = DungeonChallengeFinishNotify.newBuilder() DungeonChallengeFinishNotify proto = DungeonChallengeFinishNotify.newBuilder()
...@@ -15,7 +15,7 @@ public class PacketDungeonChallengeFinishNotify extends BasePacket { ...@@ -15,7 +15,7 @@ public class PacketDungeonChallengeFinishNotify extends BasePacket {
.setIsSuccess(challenge.isSuccess()) .setIsSuccess(challenge.isSuccess())
.setUnk1(2) .setUnk1(2)
.build(); .build();
this.setData(proto); this.setData(proto);
} }
} }
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.dungeons.DungeonChallenge; import emu.grasscutter.game.dungeons.challenge.WorldChallenge;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.DungeonSettleNotifyOuterClass.DungeonSettleNotify; import emu.grasscutter.net.proto.DungeonSettleNotifyOuterClass.DungeonSettleNotify;
...@@ -9,7 +9,7 @@ import emu.grasscutter.net.proto.TowerLevelEndNotifyOuterClass.TowerLevelEndNoti ...@@ -9,7 +9,7 @@ import emu.grasscutter.net.proto.TowerLevelEndNotifyOuterClass.TowerLevelEndNoti
public class PacketDungeonSettleNotify extends BasePacket { public class PacketDungeonSettleNotify extends BasePacket {
public PacketDungeonSettleNotify(DungeonChallenge challenge) { public PacketDungeonSettleNotify(WorldChallenge challenge) {
super(PacketOpcodes.DungeonSettleNotify); super(PacketOpcodes.DungeonSettleNotify);
DungeonSettleNotify proto = DungeonSettleNotify.newBuilder() DungeonSettleNotify proto = DungeonSettleNotify.newBuilder()
...@@ -22,10 +22,10 @@ public class PacketDungeonSettleNotify extends BasePacket { ...@@ -22,10 +22,10 @@ public class PacketDungeonSettleNotify extends BasePacket {
this.setData(proto); this.setData(proto);
} }
public PacketDungeonSettleNotify(DungeonChallenge challenge, public PacketDungeonSettleNotify(WorldChallenge challenge,
boolean canJump, boolean canJump,
boolean hasNextLevel, boolean hasNextLevel,
int nextFloorId int nextFloorId
) { ) {
super(PacketOpcodes.DungeonSettleNotify); super(PacketOpcodes.DungeonSettleNotify);
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.props.LifeState; import emu.grasscutter.game.props.LifeState;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.LifeStateChangeNotifyOuterClass.LifeStateChangeNotify; import emu.grasscutter.net.proto.LifeStateChangeNotifyOuterClass.LifeStateChangeNotify;
import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType; import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType;
import emu.grasscutter.net.proto.ServerBuffOuterClass.ServerBuff;
import java.util.ArrayList;
public class PacketLifeStateChangeNotify extends BasePacket { public class PacketLifeStateChangeNotify extends BasePacket {
public PacketLifeStateChangeNotify(GameEntity target, LifeState lifeState) {
super(PacketOpcodes.LifeStateChangeNotify);
LifeStateChangeNotify proto = LifeStateChangeNotify.newBuilder()
.setEntityId(target.getId())
.setLifeState(lifeState.getValue())
.build();
this.setData(proto);
}
public PacketLifeStateChangeNotify(GameEntity attacker, GameEntity target, LifeState lifeState) { public PacketLifeStateChangeNotify(GameEntity attacker, GameEntity target, LifeState lifeState) {
super(PacketOpcodes.LifeStateChangeNotify); super(PacketOpcodes.LifeStateChangeNotify);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment