Search in sources :

Example 1 with Character

use of de.gg.game.model.entities.Character in project ProjektGG by eskalon.

the class CharacterFactory method createCharacterForPosition.

public static Character createCharacterForPosition(Random random, PositionType posType) {
    SocialStatus status;
    switch(posType.getLevel()) {
        default:
        case 1:
        case 2:
            {
                status = SocialStatus.CITIZEN;
                break;
            }
        case 3:
            {
                status = RandomUtils.isTrue(random, 3) ? SocialStatus.PATRICIAN : SocialStatus.CITIZEN;
                break;
            }
        case 4:
        case 5:
            {
                status = SocialStatus.PATRICIAN;
                break;
            }
        case 6:
            {
                status = RandomUtils.isTrue(random, 2) ? SocialStatus.PATRICIAN : SocialStatus.CAVALIER;
                break;
            }
        case 7:
            {
                status = SocialStatus.CAVALIER;
                break;
            }
        case 8:
            {
                status = RandomUtils.isTrue(random, 3) ? SocialStatus.CAVALIER : SocialStatus.BARON;
                break;
            }
        case 9:
            {
                status = SocialStatus.BARON;
                break;
            }
    }
    Character c = createCharacterWithStatus(random, status);
    c.setHighestPositionLevel(posType.getLevel());
    c.setPosition(posType);
    return c;
}
Also used : Character(de.gg.game.model.entities.Character) SocialStatus(de.gg.game.model.types.SocialStatus)

Example 2 with Character

use of de.gg.game.model.entities.Character in project ProjektGG by eskalon.

the class CharacterFactory method createCharacterWithStatus.

/**
 * Creates a random non-player character specified by its social status.
 *
 * @param random
 *            The random generator for this session.
 * @param status
 *            The social status of this character. Is used as guideline for
 *            all other values.
 * @return a random non-player character.
 */
public static Character createCharacterWithStatus(Random random, SocialStatus status) {
    Character c = new Character();
    c.setAge(RandomUtils.getInt(random, 17, 60));
    if (status != SocialStatus.NON_CITIZEN)
        c.setGold(RandomUtils.getInt(random, status.getFortuneRequirement(), status.getFortuneRequirement() * 2 - 200));
    else
        c.setGold(RandomUtils.getInt(random, 135, 735));
    if (status == SocialStatus.NON_CITIZEN)
        c.setHighestPositionLevel(RandomUtils.getInt(random, 0, 5));
    else if (status == SocialStatus.CITIZEN)
        c.setHighestPositionLevel(RandomUtils.getInt(random, 0, 3));
    else if (status == SocialStatus.PATRICIAN)
        c.setHighestPositionLevel(RandomUtils.getInt(random, 1, 6));
    else if (status == SocialStatus.CAVALIER)
        c.setHighestPositionLevel(RandomUtils.getInt(random, 2, 9));
    else if (status == SocialStatus.BARON)
        c.setHighestPositionLevel(RandomUtils.getInt(random, 7, 9));
    c.setHp(RandomUtils.getInt(random, 85, 105));
    c.setMale(RandomUtils.isTrue(random, 2));
    // two thirds of the
    c.setMarried(!RandomUtils.isTrue(random, 3));
    if (c.isMale()) {
        c.setName(MALE_NAMES.get(RandomUtils.getInt(random, 0, MALE_NAMES.size() - 1)));
    } else {
        c.setName(FEMALE_NAMES.get(RandomUtils.getInt(random, 0, FEMALE_NAMES.size() - 1)));
    }
    c.setReligion(RandomUtils.isTrue(random, 2) ? Religion.CATHOLIC : Religion.ORTHODOX);
    c.setStatus(status);
    c.setSurname(SURNAMES.get(RandomUtils.getInt(random, 0, SURNAMES.size() - 1)));
    switch(RandomUtils.getInt(random, 0, 7)) {
        case 0:
        case 1:
        case 2:
        case 3:
            {
                c.setNPCTrait(NPCCharacterTrait.EVEN_TEMPERED);
                break;
            }
        case 4:
        case 5:
            {
                c.setNPCTrait(NPCCharacterTrait.AMBITIOUS);
                break;
            }
        case 6:
            {
                c.setNPCTrait(NPCCharacterTrait.EVEN_TEMPERED);
                break;
            }
        case 7:
            {
                c.setNPCTrait(NPCCharacterTrait.EVEN_TEMPERED);
                break;
            }
    }
    return c;
}
Also used : Character(de.gg.game.model.entities.Character)

Example 3 with Character

use of de.gg.game.model.entities.Character in project ProjektGG by eskalon.

the class FirstEventWaveClientSystem method process.

@Override
public void process(short id, Player p) {
    if (id == localPlayerId) {
        Character c = p.getCurrentlyPlayedCharacter(world);
        // Inform about open positions
        for (Entry<PositionType, Position> e : world.getPositions().entrySet()) {
            if (!e.getValue().isHeld()) {
                if (e.getKey().getLevel() - 1 <= c.getHighestPositionLevel()) {
                    if (e.getKey().getStatusRequirement() == null || e.getKey().getStatusRequirement().getLevel() <= c.getStatus().getLevel()) {
                        NotificationData not = new NotificationData(Lang.get("notification.pos_available.title"), Lang.get("notification.pos_available.text", e.getKey()), null);
                        eventBus.post(new NotificationCreationEvent(not));
                    }
                }
            }
        }
        if (c.getStatus() == SocialStatus.NON_CITIZEN) {
            if (p.getFortune(world) >= SocialStatus.NON_CITIZEN.getFortuneRequirement()) {
            // TODO inform about possibility to buy citizen status
            }
        }
    }
}
Also used : PositionType(de.gg.game.model.types.PositionType) Character(de.gg.game.model.entities.Character) Position(de.gg.game.model.entities.Position) NotificationData(de.gg.game.ui.data.NotificationData) NotificationCreationEvent(de.gg.game.events.NotificationCreationEvent)

Example 4 with Character

use of de.gg.game.model.entities.Character in project ProjektGG by eskalon.

the class GameServer method onClientHandshake.

@Override
protected synchronized void onClientHandshake(Connection con, ClientHandshakeRequest msg) {
    Short id = connections.get(con);
    LobbyPlayer p;
    if (!serverSetup.getVersion().equals(msg.getVersion())) {
        Log.info("Server", "Kick: Version mismatch (%s)", msg.getVersion());
        con.sendTCP(new FailedHandshakeResponse(Lang.get("dialog.connecting_failed.version_mismatch")));
        con.close();
        return;
    }
    if (savedGame != null) {
        short foundId = -1;
        for (Entry<Short, String> e : savedGame.clientIdentifiers.entrySet()) {
            if (e.getValue().equals(msg.getHostname())) {
                foundId = e.getKey();
                break;
            }
        }
        if (foundId == -1) {
            Log.info("Server", "Kick: Client isn't part of this loaded save game");
            con.sendTCP(new FailedHandshakeResponse(Lang.get("dialog.connecting_failed.not_in_save")));
            con.close();
            return;
        } else {
            if ((id == HOST_PLAYER_NETWORK_ID && foundId != HOST_PLAYER_NETWORK_ID) || (foundId == HOST_PLAYER_NETWORK_ID && id != HOST_PLAYER_NETWORK_ID)) {
                // Host has hanged changed
                Log.info("Server", "Kick: The host of a loaded save game cannot be changed");
                con.sendTCP(new FailedHandshakeResponse(Lang.get("dialog.connecting_failed.cannot_change_host")));
                con.close();
                // Server gets closed if need be
                return;
            }
            Log.info("Server", "Client was recognized as part of this loaded save game");
            Player oldPlayer = savedGame.world.getPlayer(foundId);
            Character oldCharacter = savedGame.world.getCharacter(oldPlayer.getCurrentlyPlayedCharacterId());
            p = new LobbyPlayer(oldCharacter.getName(), oldCharacter.getSurname(), oldPlayer.getIcon(), -1, oldCharacter.isMale());
        }
    } else {
        Log.info("Server", "Client %d was registered as new player", id);
        p = PlayerUtils.getRandomPlayerWithUnusedProperties(playerStubs, players.values());
    }
    players.put(id, p);
    // Inform the other clients
    resultListener.onPlayerJoined(id, p);
    // Establish RMI connection (part 1)
    objectSpace.addConnection(con);
    Log.info("Server", "RMI connection to client established");
    // Perform the handshake
    con.sendTCP(new SuccessfulHandshakeResponse(id));
}
Also used : FailedHandshakeResponse(de.gg.engine.network.message.FailedHandshakeResponse) Player(de.gg.game.model.entities.Player) Character(de.gg.game.model.entities.Character) SuccessfulHandshakeResponse(de.gg.engine.network.message.SuccessfulHandshakeResponse)

Example 5 with Character

use of de.gg.game.model.entities.Character in project ProjektGG by eskalon.

the class CharacterBehaviour method getOpinionOfAnotherCharacter.

/**
 * The opinion <code>otherCharacter</code> has of
 * <code>thisCharacter</code>.
 * <p>
 * Has to get compared with the specific skill and trait modifiers as well
 * as the own usefulness and threat modifiers to determine whether a npc
 * should execute a specific action.
 *
 * @param thisCharacterId
 *            The id of the character that the opinion is held of.
 * @param otherCharacterId
 *            The id of the character that has the opinion.
 * @param session
 *            The game session.
 * @return the opinion <code>otherCharacter</code> has of
 *         <code>thisCharacter</code>. Is never lower than <code>0</code>
 *         and normally around <code>55</code>.
 */
public static int getOpinionOfAnotherCharacter(short thisCharacterId, short otherCharacterId, GameSession session) {
    Character thisCharacter = session.getWorld().getCharacter(thisCharacterId);
    Character otherCharacter = session.getWorld().getCharacter(otherCharacterId);
    int opinion = 0;
    // Difficulty (-4, 10)
    opinion += session.getSessionSetup().getDifficulty().getOpinionModifer();
    // Base Opinion (14, 43)
    Random r = new Random(thisCharacterId * otherCharacterId);
    opinion += RandomUtils.getInt(r, -9, 20) + 23;
    // NPC Opinion Modifier (0, 10)
    if (otherCharacter.getNPCTrait() != null)
        opinion += otherCharacter.getNPCTrait().getBaseOpinionModifier();
    // Reputation (0, 20)
    opinion += thisCharacter.getReputation();
    // Religion (5, 12)
    if (otherCharacter.getNPCTrait() != null) {
        boolean isReligionImportant = otherCharacter.getNPCTrait().isReligionImportant();
        if (thisCharacter.getReligion() == otherCharacter.getReligion())
            opinion += isReligionImportant ? 16 : 11;
        else
            opinion += isReligionImportant ? 0 : 5;
    }
    // Temporary Opinion Modifiers
    if (thisCharacter.getOpinionModifiers().containsKey(otherCharacterId))
        opinion += Math.round(thisCharacter.getOpinionModifiers().get(otherCharacterId));
    // Temporary Round Modifier (-3, 4)
    opinion += getPerRoundAndCharacterPopularityModifier(session.getRandomSeedForCurrentRound(), thisCharacterId, otherCharacterId);
    return opinion < 0 ? 0 : opinion;
}
Also used : Character(de.gg.game.model.entities.Character) Random(java.util.Random)

Aggregations

Character (de.gg.game.model.entities.Character)12 Player (de.gg.game.model.entities.Player)3 SocialStatus (de.gg.game.model.types.SocialStatus)2 LobbyPlayer (de.gg.game.network.LobbyPlayer)2 FailedHandshakeResponse (de.gg.engine.network.message.FailedHandshakeResponse)1 SuccessfulHandshakeResponse (de.gg.engine.network.message.SuccessfulHandshakeResponse)1 NotificationCreationEvent (de.gg.game.events.NotificationCreationEvent)1 Position (de.gg.game.model.entities.Position)1 Profession (de.gg.game.model.entities.Profession)1 NPCCharacterTrait (de.gg.game.model.types.NPCCharacterTrait)1 PositionType (de.gg.game.model.types.PositionType)1 FirstCharacterEventWaveServerSystem (de.gg.game.systems.server.FirstCharacterEventWaveServerSystem)1 FirstPlayerEventWaveServerSystem (de.gg.game.systems.server.FirstPlayerEventWaveServerSystem)1 IllnessDamageSystem (de.gg.game.systems.server.IllnessDamageSystem)1 NpcActionSystem (de.gg.game.systems.server.NpcActionSystem)1 NpcActionSystem2 (de.gg.game.systems.server.NpcActionSystem2)1 ServerProcessingSystem (de.gg.game.systems.server.ServerProcessingSystem)1 NotificationData (de.gg.game.ui.data.NotificationData)1 Random (java.util.Random)1