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
c919c9c9
Commit
c919c9c9
authored
Apr 17, 2022
by
Melledy
Browse files
Limit co-op teams to 4 avatars max total
parent
7925d1cd
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/TeamInfo.java
View file @
c919c9c9
...
...
@@ -60,13 +60,16 @@ public class TeamInfo {
}
public
void
copyFrom
(
TeamInfo
team
,
int
maxTeamSize
)
{
// Clear
// Clone avatar ids from team to copy from
List
<
Integer
>
avatarIds
=
new
ArrayList
<>(
team
.
getAvatars
());
// Clear current avatar list first
this
.
getAvatars
().
clear
();
// Copy from team
int
len
=
Math
.
min
(
team
.
getA
vatar
s
()
.
size
(),
maxTeamSize
);
int
len
=
Math
.
min
(
a
vatar
Ids
.
size
(),
maxTeamSize
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
id
=
team
.
getA
vatar
s
()
.
get
(
i
);
int
id
=
a
vatar
Ids
.
get
(
i
);
this
.
getAvatars
().
add
(
id
);
}
}
...
...
src/main/java/emu/grasscutter/game/TeamManager.java
View file @
c919c9c9
...
...
@@ -166,7 +166,7 @@ public class TeamManager {
// Methods
p
ublic
void
updateTeamResonances
()
{
p
rivate
void
updateTeamResonances
()
{
Int2IntOpenHashMap
map
=
new
Int2IntOpenHashMap
();
this
.
getTeamResonances
().
clear
();
...
...
@@ -196,7 +196,7 @@ public class TeamManager {
}
}
p
rivate
void
updateTeamEntities
(
GenshinPacket
responsePacket
)
{
p
ublic
void
updateTeamEntities
(
GenshinPacket
responsePacket
)
{
// Sanity check - Should never happen
if
(
this
.
getCurrentTeamInfo
().
getAvatars
().
size
()
<=
0
)
{
return
;
...
...
@@ -241,7 +241,7 @@ public class TeamManager {
// Set new selected character index
if
(
prevSelectedAvatarIndex
==
-
1
)
{
// Previous selected avatar is not in the same spot, we will select the current one in the prev slot
prevSelectedAvatarIndex
=
Math
.
min
(
this
.
currentCharacterIndex
,
getCurrentTeamInfo
().
getAvatars
().
size
()
-
1
);
prevSelectedAvatarIndex
=
Math
.
min
(
this
.
currentCharacterIndex
,
this
.
getActiveTeam
().
size
()
-
1
);
}
this
.
currentCharacterIndex
=
prevSelectedAvatarIndex
;
...
...
src/main/java/emu/grasscutter/game/World.java
View file @
c919c9c9
...
...
@@ -28,7 +28,6 @@ import emu.grasscutter.server.packet.send.PacketPlayerEnterSceneNotify;
import
emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify
;
import
emu.grasscutter.server.packet.send.PacketSceneEntityDisappearNotify
;
import
emu.grasscutter.server.packet.send.PacketScenePlayerInfoNotify
;
import
emu.grasscutter.server.packet.send.PacketSceneTeamUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketSyncScenePlayTeamEntityNotify
;
import
emu.grasscutter.server.packet.send.PacketSyncTeamEntityNotify
;
import
emu.grasscutter.server.packet.send.PacketWorldPlayerInfoNotify
;
...
...
@@ -169,7 +168,7 @@ public class World implements Iterable<GenshinPlayer> {
player
.
setPeerId
(
this
.
getNextPeerId
());
player
.
getTeamManager
().
setEntityId
(
getNextEntityId
(
EntityIdType
.
TEAM
));
//
TODO Update team of all playe
rs
//
Setup team avata
rs
this
.
setupPlayerAvatars
(
player
);
// Info packet for other players
...
...
@@ -212,18 +211,23 @@ public class World implements Iterable<GenshinPlayer> {
private
void
updatePlayerInfos
(
GenshinPlayer
paramPlayer
)
{
for
(
GenshinPlayer
player
:
getPlayers
())
{
// Dont send packets if player is loading in
// Dont send packets if player is loading in
and filter out joining player
if
(!
player
.
hasSentAvatarDataNotify
()
||
player
.
getSceneLoadState
().
getValue
()
<
SceneLoadState
.
INIT
.
getValue
()
||
player
==
paramPlayer
)
{
continue
;
}
// Update team of all players since max players has been changed - Probably not the best way to do it
if
(
this
.
isMultiplayer
())
{
player
.
getTeamManager
().
getMpTeam
().
copyFrom
(
player
.
getTeamManager
().
getMpTeam
(),
player
.
getTeamManager
().
getMaxTeamSize
());
player
.
getTeamManager
().
updateTeamEntities
(
null
);
}
// World player info packets
player
.
getSession
().
send
(
new
PacketWorldPlayerInfoNotify
(
this
));
player
.
getSession
().
send
(
new
PacketScenePlayerInfoNotify
(
this
));
player
.
getSession
().
send
(
new
PacketWorldPlayerRTTNotify
(
this
));
// Team packets
player
.
getSession
().
send
(
new
PacketSceneTeamUpdateNotify
(
player
));
player
.
getSession
().
send
(
new
PacketSyncTeamEntityNotify
(
player
));
player
.
getSession
().
send
(
new
PacketSyncScenePlayTeamEntityNotify
(
player
));
}
...
...
@@ -283,6 +287,11 @@ public class World implements Iterable<GenshinPlayer> {
EntityAvatar
entity
=
new
EntityAvatar
(
this
,
player
.
getAvatars
().
getAvatarById
(
avatarId
));
player
.
getTeamManager
().
getActiveTeam
().
add
(
entity
);
}
// Limit character index in case its out of bounds
if
(
player
.
getTeamManager
().
getCurrentCharacterIndex
()
>=
player
.
getTeamManager
().
getActiveTeam
().
size
()
||
player
.
getTeamManager
().
getCurrentCharacterIndex
()
<
0
)
{
player
.
getTeamManager
().
setCurrentCharacterIndex
(
player
.
getTeamManager
().
getCurrentCharacterIndex
()
-
1
);
}
}
private
void
removePlayerAvatars
(
GenshinPlayer
player
)
{
...
...
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