@Override public void consume(Player player, Message message) { log("ChatServer: Received " + message.getType()); if (message.getType() == Message.MessageType.JOIN_CHAT) { JoinChatMessage joinChatMessage = new JoinChatMessage(((JoinChatMessage) message).getMsg()); server.sendToAll(joinChatMessage); } else if (message.getType() == Message.MessageType.CHAT_MSG) { ((ChatMessage) message).addNick(player.getName()); server.sendToAll(message); } }
public void updateScores(Array<Player> players, Array<ServerShip> ships, float scoreMultiplier) { for (Player p : players) { scores.put(p.getId(), 0f); } // give out points according to what ships are nearby the gathering point // first store weights of every ship float totalWeight = 0f; for (ServerShip ship : ships) { float dst = ship.getBody().getWorldCenter().dst(position); dst = Math.max(3, dst); float weight = 10f / (float) Math.pow(dst, 0.6f); // todo multiply with the cost of the ship totalWeight += weight; long ownerId = ship.getPlayer().getId(); Float currentWeight = scores.get(ownerId); scores.put(ownerId, currentWeight + weight); } if (totalWeight == 0f) { return; } for (Player p : players) { float score = scores.get(p.getId()) / totalWeight * SCORE_PER_TICK * scoreMultiplier; p.setScore(p.getScore() + score); } }