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
16f77ee5
Commit
16f77ee5
authored
May 02, 2022
by
dogdie233
Committed by
Melledy
May 02, 2022
Browse files
Add EnterDungeonCmd, fix error when enter dungeon by changescene, import spawn cmd
parent
fe2d2e8e
Changes
4
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java
0 → 100644
View file @
16f77ee5
package
emu.grasscutter.command.commands
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.player.Player
;
import
java.util.List
;
@Command
(
label
=
"enterdungeon"
,
usage
=
"enterdungeon <dungeon id>"
,
description
=
"Enter a dungeon"
,
aliases
=
{
"dungeon"
},
permission
=
"player.enterdungeon"
)
public
final
class
EnterDungeonCommand
implements
CommandHandler
{
@Override
public
void
execute
(
Player
sender
,
List
<
String
>
args
)
{
if
(
sender
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Run this command in-game."
);
return
;
}
if
(
args
.
size
()
<
1
)
{
CommandHandler
.
sendMessage
(
sender
,
"Usage: enterdungeon <dungeon id>"
);
return
;
}
try
{
int
dungeonId
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
dungeonId
==
sender
.
getSceneId
())
{
CommandHandler
.
sendMessage
(
sender
,
"You are already in that dungeon"
);
return
;
}
boolean
result
=
sender
.
getServer
().
getDungeonManager
().
enterDungeon
(
sender
.
getSession
().
getPlayer
(),
0
,
dungeonId
);
CommandHandler
.
sendMessage
(
sender
,
"Changed to dungeon "
+
dungeonId
);
if
(!
result
)
{
CommandHandler
.
sendMessage
(
sender
,
"Dungeon does not exist"
);
}
}
catch
(
Exception
e
)
{
CommandHandler
.
sendMessage
(
sender
,
"Usage: enterdungeon <dungeon id>"
);
}
}
}
src/main/java/emu/grasscutter/command/commands/SpawnCommand.java
View file @
16f77ee5
...
...
@@ -3,14 +3,22 @@ package emu.grasscutter.command.commands;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.def.AvatarData
;
import
emu.grasscutter.data.def.GadgetData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.data.def.MonsterData
;
import
emu.grasscutter.game.entity.EntityMonster
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.entity.*
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.props.EntityType
;
import
emu.grasscutter.game.props.FightProperty
;
import
emu.grasscutter.utils.Position
;
import
javax.swing.text.html.parser.Entity
;
import
java.util.List
;
import
java.util.Random
;
@Command
(
label
=
"spawn"
,
usage
=
"spawn <entityId
|entityName> [level] [amount
]"
,
@Command
(
label
=
"spawn"
,
usage
=
"spawn <entityId
> [amount] [level(monster only)
]"
,
description
=
"Spawns an entity near you"
,
permission
=
"server.spawn"
)
public
final
class
SpawnCommand
implements
CommandHandler
{
...
...
@@ -22,30 +30,65 @@ public final class SpawnCommand implements CommandHandler {
}
if
(
args
.
size
()
<
1
)
{
CommandHandler
.
sendMessage
(
sender
,
"Usage: spawn <entityId
|entityName> [amount
]"
);
CommandHandler
.
sendMessage
(
sender
,
"Usage: spawn <entityId
> [amount] [level(monster only)
]"
);
return
;
}
try
{
int
entity
=
Integer
.
parseInt
(
args
.
get
(
0
));
int
level
=
args
.
size
()
>
1
?
Integer
.
parseInt
(
args
.
get
(
1
))
:
1
;
int
amount
=
args
.
size
()
>
2
?
Integer
.
parseInt
(
args
.
get
(
2
))
:
1
;
int
id
=
Integer
.
parseInt
(
args
.
get
(
0
));
int
amount
=
args
.
size
()
>
1
?
Integer
.
parseInt
(
args
.
get
(
1
))
:
1
;
int
level
=
args
.
size
()
>
2
?
Integer
.
parseInt
(
args
.
get
(
2
))
:
1
;
MonsterData
entityData
=
GameData
.
getMonsterDataMap
().
get
(
entity
);
if
(
entityData
==
null
)
{
MonsterData
monsterData
=
GameData
.
getMonsterDataMap
().
get
(
id
);
GadgetData
gadgetData
=
GameData
.
getGadgetDataMap
().
get
(
id
);
ItemData
itemData
=
GameData
.
getItemDataMap
().
get
(
id
);
if
(
monsterData
==
null
&&
gadgetData
==
null
&&
itemData
==
null
)
{
CommandHandler
.
sendMessage
(
sender
,
"Invalid entity id."
);
return
;
}
float
range
=
(
5
f
+
(.
1
f
*
amount
)
);
double
maxRadius
=
Math
.
sqrt
(
amount
*
0.2
/
Math
.
PI
);
for
(
int
i
=
0
;
i
<
amount
;
i
++)
{
Position
pos
=
sender
.
getPos
().
clone
().
addX
((
float
)
(
Math
.
random
()
*
range
)
-
(
range
/
2
)).
addY
(
3
f
).
addZ
((
float
)
(
Math
.
random
()
*
range
)
-
(
range
/
2
));
EntityMonster
monster
=
new
EntityMonster
(
sender
.
getScene
(),
entityData
,
pos
,
level
);
sender
.
getScene
().
addEntity
(
monster
);
Position
pos
=
GetRandomPositionInCircle
(
sender
.
getPos
(),
maxRadius
).
addY
(
3
);
GameEntity
entity
=
null
;
if
(
itemData
!=
null
)
{
entity
=
new
EntityItem
(
sender
.
getScene
(),
null
,
itemData
,
pos
,
1
,
true
);
}
CommandHandler
.
sendMessage
(
sender
,
String
.
format
(
"Spawned %s of %s."
,
amount
,
entity
));
if
(
gadgetData
!=
null
)
{
entity
=
new
EntityVehicle
(
sender
.
getScene
(),
sender
.
getSession
().
getPlayer
(),
gadgetData
.
getId
(),
0
,
pos
,
sender
.
getRotation
());
int
gadgetId
=
gadgetData
.
getId
();
switch
(
gadgetId
)
{
// TODO: Not hardcode this. Waverider (skiff)
case
45001001
,
45001002
->
{
entity
.
addFightProperty
(
FightProperty
.
FIGHT_PROP_BASE_HP
,
10000
);
entity
.
addFightProperty
(
FightProperty
.
FIGHT_PROP_BASE_ATTACK
,
100
);
entity
.
addFightProperty
(
FightProperty
.
FIGHT_PROP_CUR_ATTACK
,
100
);
entity
.
addFightProperty
(
FightProperty
.
FIGHT_PROP_CUR_HP
,
10000
);
entity
.
addFightProperty
(
FightProperty
.
FIGHT_PROP_CUR_DEFENSE
,
0
);
entity
.
addFightProperty
(
FightProperty
.
FIGHT_PROP_CUR_SPEED
,
0
);
entity
.
addFightProperty
(
FightProperty
.
FIGHT_PROP_CHARGE_EFFICIENCY
,
0
);
entity
.
addFightProperty
(
FightProperty
.
FIGHT_PROP_MAX_HP
,
10000
);
}
default
->
{}
}
}
if
(
monsterData
!=
null
)
{
entity
=
new
EntityMonster
(
sender
.
getScene
(),
monsterData
,
pos
,
level
);
}
sender
.
getScene
().
addEntity
(
entity
);
}
CommandHandler
.
sendMessage
(
sender
,
String
.
format
(
"Spawned %s of %s."
,
amount
,
id
));
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
sender
,
"Invalid
item or player
ID."
);
CommandHandler
.
sendMessage
(
sender
,
"Invalid
entity
ID."
);
}
}
private
Position
GetRandomPositionInCircle
(
Position
origin
,
double
radius
){
Position
target
=
origin
.
clone
();
double
angle
=
Math
.
random
()
*
360
;
double
r
=
Math
.
sqrt
(
Math
.
random
()
*
radius
*
radius
);
target
.
addX
((
float
)
(
r
*
Math
.
cos
(
angle
))).
addZ
((
float
)
(
r
*
Math
.
sin
(
angle
)));
return
target
;
}
}
src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java
View file @
16f77ee5
...
...
@@ -37,11 +37,11 @@ public class DungeonManager {
player
.
sendPacket
(
new
PacketDungeonEntryInfoRsp
(
player
,
entry
.
getPointData
()));
}
public
void
enterDungeon
(
Player
player
,
int
pointId
,
int
dungeonId
)
{
public
boolean
enterDungeon
(
Player
player
,
int
pointId
,
int
dungeonId
)
{
DungeonData
data
=
GameData
.
getDungeonDataMap
().
get
(
dungeonId
);
if
(
data
==
null
)
{
return
;
return
false
;
}
Grasscutter
.
getLogger
().
info
(
player
.
getNickname
()
+
" is trying to enter dungeon "
+
dungeonId
);
...
...
@@ -53,6 +53,7 @@ public class DungeonManager {
player
.
getScene
().
setPrevScenePoint
(
pointId
);
player
.
sendPacket
(
new
PacketPlayerEnterDungeonRsp
(
pointId
,
dungeonId
));
return
true
;
}
public
void
exitDungeon
(
Player
player
)
{
...
...
src/main/java/emu/grasscutter/game/world/Scene.java
View file @
16f77ee5
...
...
@@ -175,7 +175,7 @@ public class Scene {
}
public
void
setDungeonData
(
DungeonData
dungeonData
)
{
if
(
this
.
dungeonData
!=
null
||
this
.
getSceneType
()
!=
SceneType
.
SCENE_DUNGEON
||
dungeonData
.
getSceneId
()
!=
this
.
getId
())
{
if
(
dungeonData
==
null
||
this
.
dungeonData
!=
null
||
this
.
getSceneType
()
!=
SceneType
.
SCENE_DUNGEON
||
dungeonData
.
getSceneId
()
!=
this
.
getId
())
{
return
;
}
this
.
dungeonData
=
dungeonData
;
...
...
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