mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-02-07 02:26:43 +01:00
Choose Avatar & Enter Tower
This commit is contained in:
@@ -26,6 +26,7 @@ import emu.grasscutter.game.props.EntityType;
|
||||
import emu.grasscutter.game.props.PlayerProperty;
|
||||
import emu.grasscutter.game.shop.ShopLimit;
|
||||
import emu.grasscutter.game.managers.MapMarkManager.*;
|
||||
import emu.grasscutter.game.tower.TowerManager;
|
||||
import emu.grasscutter.game.world.Scene;
|
||||
import emu.grasscutter.game.world.World;
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
@@ -88,6 +89,8 @@ public class Player {
|
||||
@Transient private MessageHandler messageHandler;
|
||||
|
||||
private TeamManager teamManager;
|
||||
|
||||
private TowerManager towerManager;
|
||||
private PlayerGachaInfo gachaInfo;
|
||||
private PlayerProfile playerProfile;
|
||||
private boolean showAvatar;
|
||||
@@ -172,6 +175,7 @@ public class Player {
|
||||
this.nickname = "Traveler";
|
||||
this.signature = "";
|
||||
this.teamManager = new TeamManager(this);
|
||||
this.towerManager = new TowerManager(this);
|
||||
this.birthday = new PlayerBirthday();
|
||||
this.setProperty(PlayerProperty.PROP_PLAYER_LEVEL, 1);
|
||||
this.setProperty(PlayerProperty.PROP_IS_SPRING_AUTO_USE, 1);
|
||||
@@ -384,6 +388,10 @@ public class Player {
|
||||
return this.teamManager;
|
||||
}
|
||||
|
||||
public TowerManager getTowerManager() {
|
||||
return towerManager;
|
||||
}
|
||||
|
||||
public PlayerGachaInfo getGachaInfo() {
|
||||
return gachaInfo;
|
||||
}
|
||||
@@ -1020,6 +1028,9 @@ public class Player {
|
||||
if (this.getProfile().getUid() == 0) {
|
||||
this.getProfile().syncWithCharacter(this);
|
||||
}
|
||||
if (this.getTowerManager() == null) {
|
||||
this.towerManager = new TowerManager(this);
|
||||
}
|
||||
|
||||
// Check if player object exists in server
|
||||
// TODO - optimize
|
||||
|
||||
@@ -18,6 +18,11 @@ public class TeamInfo {
|
||||
this.avatars = new ArrayList<>(Grasscutter.getConfig().getGameServerOptions().MaxAvatarsInTeam);
|
||||
}
|
||||
|
||||
public TeamInfo(List<Integer> avatars) {
|
||||
this.name = "";
|
||||
this.avatars = avatars;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
package emu.grasscutter.game.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Transient;
|
||||
@@ -58,7 +52,13 @@ public class TeamManager {
|
||||
@Transient private final Set<EntityBaseGadget> gadgets;
|
||||
@Transient private final IntSet teamResonances;
|
||||
@Transient private final IntSet teamResonancesConfig;
|
||||
|
||||
|
||||
private int useTemporarilyTeamIndex = -1;
|
||||
/**
|
||||
* Temporary Team for tower
|
||||
*/
|
||||
private List<TeamInfo> temporaryTeam;
|
||||
|
||||
public TeamManager() {
|
||||
this.mpTeam = new TeamInfo();
|
||||
this.avatars = new ArrayList<>();
|
||||
@@ -124,6 +124,10 @@ public class TeamManager {
|
||||
}
|
||||
|
||||
public TeamInfo getCurrentTeamInfo() {
|
||||
if (useTemporarilyTeamIndex >= 0 &&
|
||||
useTemporarilyTeamIndex < temporaryTeam.size()){
|
||||
return temporaryTeam.get(useTemporarilyTeamIndex);
|
||||
}
|
||||
if (this.getPlayer().isInMultiplayer()) {
|
||||
return this.getMpTeam();
|
||||
}
|
||||
@@ -351,7 +355,51 @@ public class TeamManager {
|
||||
// Packet
|
||||
this.updateTeamEntities(new PacketChangeMpTeamAvatarRsp(getPlayer(), teamInfo));
|
||||
}
|
||||
|
||||
|
||||
public void setupTemporaryTeam(List<List<Long>> guidList) {
|
||||
var team = guidList.stream().map(list -> {
|
||||
// Sanity checks
|
||||
if (list.size() == 0 || list.size() > getMaxTeamSize()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set team data
|
||||
LinkedHashSet<Avatar> newTeam = new LinkedHashSet<>();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Avatar avatar = getPlayer().getAvatars().getAvatarByGuid(list.get(i));
|
||||
if (avatar == null || newTeam.contains(avatar)) {
|
||||
// Should never happen
|
||||
return null;
|
||||
}
|
||||
newTeam.add(avatar);
|
||||
}
|
||||
|
||||
// convert to avatar ids
|
||||
return newTeam.stream()
|
||||
.map(Avatar::getAvatarId)
|
||||
.toList();
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.map(TeamInfo::new)
|
||||
.toList();
|
||||
this.temporaryTeam = team;
|
||||
}
|
||||
|
||||
public void useTemporaryTeam(int index) {
|
||||
this.useTemporarilyTeamIndex = index;
|
||||
updateTeamEntities(null);
|
||||
}
|
||||
|
||||
public void cleanTemporaryTeam() {
|
||||
// check if using temporary team
|
||||
if(useTemporarilyTeamIndex < 0){
|
||||
return;
|
||||
}
|
||||
|
||||
this.useTemporarilyTeamIndex = -1;
|
||||
this.temporaryTeam = null;
|
||||
updateTeamEntities(null);
|
||||
}
|
||||
public synchronized void setCurrentTeam(int teamId) {
|
||||
//
|
||||
if (getPlayer().isInMultiplayer()) {
|
||||
|
||||
Reference in New Issue
Block a user