Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
791b9534
Commit
791b9534
authored
May 23, 2022
by
Akka
Committed by
Melledy
May 23, 2022
Browse files
refactor the challenge
parent
717c2d1d
Changes
29
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/scripts/ScriptLib.java
View file @
791b9534
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.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.scripts.data.SceneGroup
;
import
emu.grasscutter.scripts.data.SceneRegion
;
import
emu.grasscutter.server.packet.send.PacketCanUseSkillNotify
;
...
...
@@ -159,48 +160,102 @@ public class ScriptLib {
if
(
group
==
null
||
group
.
monsters
==
null
)
{
return
1
;
}
var
suiteData
=
group
.
getSuiteByIndex
(
suite
);
if
(
suiteData
==
null
){
return
1
;
}
// avoid spawn wrong monster
if
(
getSceneScriptManager
().
getScene
().
getChallenge
()
!=
null
)
if
(!
getSceneScriptManager
().
getScene
().
getChallenge
().
inProgress
()
||
getSceneScriptManager
().
getScene
().
getChallenge
().
getGroup
().
id
!=
groupId
){
return
0
;
}
this
.
getSceneScriptManager
().
spawnMonstersInGroup
(
group
,
suite
);
this
.
getSceneScriptManager
().
addGroupSuite
(
group
,
suite
Data
);
return
0
;
}
public
int
GoToGroupSuite
(
int
groupId
,
int
suite
)
{
logger
.
debug
(
"[LUA] Call GoToGroupSuite 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
;
}
// 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
);
for
(
var
suiteItem
:
group
.
suites
){
if
(
suiteData
==
suiteItem
){
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
);
var
objective
=
objectiveKills
;
if
(
group
==
null
||
group
.
monsters
==
null
)
{
return
1
;
}
var
suiteData
=
group
.
getSuiteByIndex
(
suite
);
if
(
suiteData
==
null
){
return
1
;
}
this
.
getSceneScriptManager
().
removeGroupSuite
(
group
,
suiteData
);
if
(
group
==
null
){
group
=
getSceneScriptManager
().
getGroupById
(
timeLimitOrGroupId
);
objective
=
groupId
;
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
;
}
this
.
getSceneScriptManager
().
removeGroupSuite
(
group
,
suiteData
);
if
(
getSceneScriptManager
().
getScene
().
getChallenge
()
!=
null
&&
getSceneScriptManager
().
getScene
().
getChallenge
().
inProgress
())
{
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
;
}
DungeonChallenge
challenge
=
new
DungeonChallenge
(
getSceneScriptManager
().
getScene
(),
group
,
challengeId
,
challengeIndex
,
objective
);
if
(
challenge
instanceof
DungeonChallenge
dungeonChallenge
){
// set if tower first stage (6-1)
challenge
.
setStage
(
getSceneScriptManager
().
getVariables
().
getOrDefault
(
"stage"
,
-
1
)
==
0
);
dungeonChallenge
.
setStage
(
getSceneScriptManager
().
getVariables
().
getOrDefault
(
"stage"
,
-
1
)
==
0
);
}
getSceneScriptManager
().
getScene
().
setChallenge
(
challenge
);
challenge
.
start
();
return
0
;
}
...
...
@@ -257,7 +312,7 @@ public class ScriptLib {
public
int
GetRegionEntityCount
(
LuaTable
table
)
{
logger
.
debug
(
"[LUA] Call GetRegionEntityCount with {}"
,
table
);
printTable
(
table
)
)
;
int
regionId
=
table
.
get
(
"region_eid"
).
toint
();
int
entityType
=
table
.
get
(
"entity_type"
).
toint
();
...
...
@@ -280,9 +335,8 @@ public class ScriptLib {
// TODO record time
return
0
;
}
public
int
GetGroupMonsterCount
(
int
var1
){
logger
.
debug
(
"[LUA] Call GetGroupMonsterCount with {}"
,
var1
);
public
int
GetGroupMonsterCount
(){
logger
.
debug
(
"[LUA] Call GetGroupMonsterCount "
);
return
(
int
)
getSceneScriptManager
().
getScene
().
getEntities
().
values
().
stream
()
.
filter
(
e
->
e
instanceof
EntityMonster
&&
...
...
@@ -328,7 +382,7 @@ public class ScriptLib {
var
entity
=
getSceneScriptManager
().
getScene
().
getEntityByConfigId
(
configId
.
toint
());
if
(
entity
==
null
){
return
1
;
return
0
;
}
getSceneScriptManager
().
getScene
().
killEntity
(
entity
,
0
);
return
0
;
...
...
@@ -398,8 +452,13 @@ public class ScriptLib {
public
int
GetGadgetStateByConfigId
(
int
groupId
,
int
configId
){
logger
.
debug
(
"[LUA] Call GetGadgetStateByConfigId with {},{}"
,
groupId
,
configId
);
if
(
groupId
==
0
){
groupId
=
getCurrentGroup
().
get
().
id
;
}
final
int
realGroupId
=
groupId
;
var
gadget
=
getSceneScriptManager
().
getScene
().
getEntities
().
values
().
stream
()
.
filter
(
g
->
g
instanceof
EntityGadget
entityGadget
&&
entityGadget
.
getGroupId
()
==
g
roupId
)
.
filter
(
g
->
g
instanceof
EntityGadget
entityGadget
&&
entityGadget
.
getGroupId
()
==
realG
roupId
)
.
filter
(
g
->
g
.
getConfigId
()
==
configId
)
.
findFirst
();
if
(
gadget
.
isEmpty
()){
...
...
@@ -409,8 +468,8 @@ public class ScriptLib {
}
public
int
MarkPlayerAction
(
int
var1
,
int
var2
,
int
var3
,
int
var4
){
logger
.
debug
(
"[LUA] Call MarkPlayerAction with {},{}"
,
var1
,
var2
);
logger
.
debug
(
"[LUA] Call MarkPlayerAction with
{},{},
{},{}"
,
var1
,
var2
,
var3
,
var4
);
return
0
;
}
...
...
src/main/java/emu/grasscutter/scripts/data/SceneGadget.java
View file @
791b9534
...
...
@@ -10,4 +10,5 @@ public class SceneGadget extends SceneObject{
public
int
state
;
public
int
point_type
;
public
SceneBossChest
boss_chest
;
public
int
interact_id
;
}
src/main/java/emu/grasscutter/scripts/data/SceneGroup.java
View file @
791b9534
...
...
@@ -73,7 +73,7 @@ public class SceneGroup {
return
bindings
;
}
public
SceneGroup
load
(
int
sceneId
){
public
synchronized
SceneGroup
load
(
int
sceneId
){
if
(
loaded
){
return
this
;
}
...
...
@@ -118,6 +118,7 @@ public class SceneGroup {
garbages
=
new
SceneGarbage
();
if
(
garbagesTable
.
checktable
().
get
(
"gadgets"
)
!=
LuaValue
.
NIL
)
{
garbages
.
gadgets
=
ScriptLoader
.
getSerializer
().
toList
(
SceneGadget
.
class
,
garbagesTable
.
checktable
().
get
(
"gadgets"
).
checktable
());
garbages
.
gadgets
.
forEach
(
m
->
m
.
group
=
this
);
}
}
...
...
src/main/java/emu/grasscutter/scripts/data/SceneMonster.java
View file @
791b9534
...
...
@@ -7,4 +7,6 @@ import lombok.ToString;
@Setter
public
class
SceneMonster
extends
SceneObject
{
public
int
monster_id
;
public
int
pose_id
;
public
int
drop_id
;
}
\ No newline at end of file
src/main/java/emu/grasscutter/server/packet/send/PacketChallengeDataNotify.java
View file @
791b9534
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.game.dungeons.
Dungeon
Challenge
;
import
emu.grasscutter.game.dungeons.
challenge.World
Challenge
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.ChallengeDataNotifyOuterClass.ChallengeDataNotify
;
public
class
PacketChallengeDataNotify
extends
BasePacket
{
public
PacketChallengeDataNotify
(
Dungeon
Challenge
challenge
,
int
index
,
int
value
)
{
public
PacketChallengeDataNotify
(
World
Challenge
challenge
,
int
index
,
int
value
)
{
super
(
PacketOpcodes
.
ChallengeDataNotify
);
ChallengeDataNotify
proto
=
ChallengeDataNotify
.
newBuilder
()
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketDungeonChallengeBeginNotify.java
View file @
791b9534
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.game.dungeons.
Dungeon
Challenge
;
import
emu.grasscutter.game.dungeons.
challenge.World
Challenge
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.DungeonChallengeBeginNotifyOuterClass.DungeonChallengeBeginNotify
;
public
class
PacketDungeonChallengeBeginNotify
extends
BasePacket
{
public
PacketDungeonChallengeBeginNotify
(
Dungeon
Challenge
challenge
)
{
public
PacketDungeonChallengeBeginNotify
(
World
Challenge
challenge
)
{
super
(
PacketOpcodes
.
DungeonChallengeBeginNotify
,
true
);
DungeonChallengeBeginNotify
proto
=
DungeonChallengeBeginNotify
.
newBuilder
()
.
setChallengeId
(
challenge
.
getChallengeId
())
.
setChallengeIndex
(
challenge
.
getChallengeIndex
())
.
setGroupId
(
challenge
.
getGroup
().
id
)
.
addParamList
(
challenge
.
getObjective
())
.
addParamList
(
challenge
.
getTimeLimit
())
.
addAllParamList
(
challenge
.
getParamList
())
.
build
();
this
.
setData
(
proto
);
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketDungeonChallengeFinishNotify.java
View file @
791b9534
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.game.dungeons.
Dungeon
Challenge
;
import
emu.grasscutter.game.dungeons.
challenge.World
Challenge
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.DungeonChallengeFinishNotifyOuterClass.DungeonChallengeFinishNotify
;
public
class
PacketDungeonChallengeFinishNotify
extends
BasePacket
{
public
PacketDungeonChallengeFinishNotify
(
Dungeon
Challenge
challenge
)
{
public
PacketDungeonChallengeFinishNotify
(
World
Challenge
challenge
)
{
super
(
PacketOpcodes
.
DungeonChallengeFinishNotify
,
true
);
DungeonChallengeFinishNotify
proto
=
DungeonChallengeFinishNotify
.
newBuilder
()
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketDungeonSettleNotify.java
View file @
791b9534
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.game.dungeons.
Dungeon
Challenge
;
import
emu.grasscutter.game.dungeons.
challenge.World
Challenge
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.DungeonSettleNotifyOuterClass.DungeonSettleNotify
;
...
...
@@ -9,7 +9,7 @@ import emu.grasscutter.net.proto.TowerLevelEndNotifyOuterClass.TowerLevelEndNoti
public
class
PacketDungeonSettleNotify
extends
BasePacket
{
public
PacketDungeonSettleNotify
(
Dungeon
Challenge
challenge
)
{
public
PacketDungeonSettleNotify
(
World
Challenge
challenge
)
{
super
(
PacketOpcodes
.
DungeonSettleNotify
);
DungeonSettleNotify
proto
=
DungeonSettleNotify
.
newBuilder
()
...
...
@@ -22,7 +22,7 @@ public class PacketDungeonSettleNotify extends BasePacket {
this
.
setData
(
proto
);
}
public
PacketDungeonSettleNotify
(
Dungeon
Challenge
challenge
,
public
PacketDungeonSettleNotify
(
World
Challenge
challenge
,
boolean
canJump
,
boolean
hasNextLevel
,
int
nextFloorId
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketLifeStateChangeNotify.java
View file @
791b9534
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.entity.GameEntity
;
import
emu.grasscutter.game.props.LifeState
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.LifeStateChangeNotifyOuterClass.LifeStateChangeNotify
;
import
emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType
;
import
emu.grasscutter.net.proto.ServerBuffOuterClass.ServerBuff
;
import
java.util.ArrayList
;
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
)
{
super
(
PacketOpcodes
.
LifeStateChangeNotify
);
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment