Changed home id logic
This commit is contained in:
parent
25f5e2603e
commit
5f6563d356
@ -153,7 +153,6 @@ public class GameServer {
|
||||
long requestedLocation = message.getArguments().get(1).getLong();
|
||||
if( requestedLocation == -1L ) {
|
||||
int homePlayerId = message.getArguments().get(0).getInt();
|
||||
this.players.get(playerId).setHomeId(homePlayerId);
|
||||
this.sendResult(playerId, message.getTransactionId(), xmlMapper.writeValueAsString(locationService.getHomeByUserId(homePlayerId)));
|
||||
return;
|
||||
}
|
||||
@ -388,7 +387,7 @@ public class GameServer {
|
||||
private void setPlayerLocation(int playerId, SetLocationMessage message) {
|
||||
Player p = this.players.get(playerId);
|
||||
this.deleteSelf(playerId, p.getLocationId());
|
||||
int prevLocation = p.getLocationId();
|
||||
long prevLocation = p.getLocationId();
|
||||
p.setLocationId(GameUtils.extractLocationId(message.getLocation()));
|
||||
p.setX(message.getCoordinates().get("x").getDouble());
|
||||
p.setY(message.getCoordinates().get("y").getDouble());
|
||||
@ -397,15 +396,14 @@ public class GameServer {
|
||||
this.sendResult(playerId, message.getTransactionId(), "");
|
||||
}
|
||||
|
||||
private void deleteSelf(int playerId, int locationId) {
|
||||
private void deleteSelf(int playerId, long locationId) {
|
||||
Player p = this.players.get(playerId);
|
||||
this.sendInLocation(locationId, p.getHomeId(), CommandType.RemoveUserFromLocation, playerId);
|
||||
this.sendInLocation(locationId, CommandType.RemoveUserFromLocation, playerId);
|
||||
}
|
||||
|
||||
private void updateLocationPlayers(int playerId, int prevLocation) {
|
||||
int locationId = this.players.get(playerId).getLocationId();
|
||||
long homeId = this.players.get(playerId).getHomeId();
|
||||
this.sendInLocation(prevLocation, homeId, CommandType.RemoveUserFromLocation, playerId);
|
||||
private void updateLocationPlayers(int playerId, long prevLocation) {
|
||||
long locationId = this.players.get(playerId).getLocationId();
|
||||
this.sendInLocation(prevLocation, CommandType.RemoveUserFromLocation, playerId);
|
||||
for( int i = 0; i < 3; i++ ) {
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
@ -420,7 +418,6 @@ public class GameServer {
|
||||
this.players.keySet().forEach(pid -> {
|
||||
Player p = this.players.get(pid);
|
||||
if( p.getLocationId() != locationId ) return;
|
||||
if( p.getLocationId() == -1 && p.getHomeId() != homeId ) return;
|
||||
this.call(playerId, CommandType.AddUserToLocation, new AddUserToLocation(
|
||||
pid,
|
||||
users.getAvatarById(pid, this.players.get(pid))
|
||||
@ -434,13 +431,12 @@ public class GameServer {
|
||||
|
||||
private void sendInPlayersLocation(int playerId, CommandType type, Object obj) {
|
||||
Player player = this.players.get(playerId);
|
||||
this.sendInLocation(player.getLocationId(), player.getHomeId(), type, obj);
|
||||
this.sendInLocation(player.getLocationId(), type, obj);
|
||||
}
|
||||
|
||||
private void sendInLocation(int locationId, long playersHome, CommandType type, Object obj) {
|
||||
private void sendInLocation(long locationId, CommandType type, Object obj) {
|
||||
players.keySet().forEach(k -> {
|
||||
if( locationId != players.get(k).getLocationId() ) return;
|
||||
if( locationId == -1 && players.get(k).getHomeId() != playersHome) return;
|
||||
this.call(k, type, obj);
|
||||
});
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ public class Player {
|
||||
private final String username;
|
||||
private double x;
|
||||
private double y;
|
||||
private int locationId;
|
||||
private long locationId;
|
||||
private double state;
|
||||
private long homeId;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import com.alterdekim.game.repository.GoodRepository;
|
||||
import com.alterdekim.game.repository.HouseLocationRepository;
|
||||
import com.alterdekim.game.repository.LocationObjectInstanceRepository;
|
||||
import com.alterdekim.game.repository.LocationRepository;
|
||||
import com.alterdekim.game.utils.GameUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -80,7 +81,7 @@ public class LocationService {
|
||||
public LocationObject getHomeByUserId(Integer userId) {
|
||||
Long goodId = goodRepository.findById(avatarInventoryService.getUsedHouse(userId)).map(Good::getId).orElse(102L);
|
||||
var house = this.houseLocationRepository.findDefaultHouseLocationByGoodId(goodId).get();
|
||||
return new LocationObject(-1L, true, false, userService.getBooleanUserProperty(userId, PlayerProperties.IsHomeLocked, true), true, house.getMediaResourceId().longValue(), 300.0, 300.0, "", userId, userService.getUsernameById(userId).get(), Collections.emptyList());
|
||||
return new LocationObject(GameUtils.convertToSpecialLocation(userId, true), true, false, userService.getBooleanUserProperty(userId, PlayerProperties.IsHomeLocked, true), true, house.getMediaResourceId().longValue(), 300.0, 300.0, "", userId, userService.getUsernameById(userId).get(), Collections.emptyList());
|
||||
}
|
||||
|
||||
public void addHouseLocation(HouseLocation house) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.alterdekim.game.utils;
|
||||
|
||||
import org.javatuples.Pair;
|
||||
|
||||
public class GameUtils {
|
||||
|
||||
public static final Long EmptyGoodId = 360L;
|
||||
@ -9,4 +11,16 @@ public class GameUtils {
|
||||
if( r.length < 3) return 0;
|
||||
return Integer.parseInt(r[2]);
|
||||
}
|
||||
|
||||
// returns true if it's user's club
|
||||
public static Pair<Integer, Boolean> getPlayerIdFromNegative(long l) {
|
||||
if (l < -4294967295L) {
|
||||
return Pair.with((int) (Math.abs(l) >> 32), true);
|
||||
}
|
||||
return Pair.with((int) Math.abs(l), false);
|
||||
}
|
||||
|
||||
public static long convertToSpecialLocation(int playerId, boolean isHome) {
|
||||
return -(isHome ? (long) playerId : ((long) playerId) << 32);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user