Search in sources :

Example 1 with SiegeSide

use of com.gmail.goosius.siegewar.enums.SiegeSide in project SiegeWar by TownyAdvanced.

the class SiegeWarAllegianceUtil method isPlayerOnTownFriendlySide.

/**
 * Determine if a player is on the town-friendly side of a given siege
 */
public static boolean isPlayerOnTownFriendlySide(Player player, Resident resident, Siege siege) {
    Town gunnerResidentTown = resident.getTownOrNull();
    SiegeSide playerSiegeSide = calculateCandidateSiegePlayerSide(player, gunnerResidentTown, siege);
    switch(playerSiegeSide) {
        case DEFENDERS:
            return siege.getSiegeType() == SiegeType.CONQUEST || siege.getSiegeType() == SiegeType.SUPPRESSION;
        case ATTACKERS:
            return siege.getSiegeType() == SiegeType.REVOLT || siege.getSiegeType() == SiegeType.LIBERATION;
        default:
            return false;
    }
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) SiegeSide(com.gmail.goosius.siegewar.enums.SiegeSide)

Example 2 with SiegeSide

use of com.gmail.goosius.siegewar.enums.SiegeSide in project SiegeWar by TownyAdvanced.

the class PlayerDeath method evaluateSiegePlayerDeath.

/**
 * Evaluates a siege death event.
 * <p>
 * If the dead player is officially involved in a nearby siege,
 * - The opposing team gains battle points
 * - Their inventory items degrade a little (e.g. 20%)
 * <p>
 * The allegiance of the killer is not considered,
 * in order to allows for a wider range of siege-kill-tactics.
 * Examples:
 * - Players without towns can contribute to battle points
 * - Players from non-nation towns can contribute to battle points
 * - Players from secretly-allied nations can contribute to battle points
 * - Devices (cannons, traps, bombs etc.) can be used to gain battle points
 *
 * @param deadPlayer The player who died
 * @param playerDeathEvent The player death event
 */
public static void evaluateSiegePlayerDeath(Player deadPlayer, PlayerDeathEvent playerDeathEvent) {
    try {
        World world = playerDeathEvent.getEntity().getWorld();
        if (!TownyAPI.getInstance().isTownyWorld(world) || !TownyAPI.getInstance().getTownyWorld(world).isWarAllowed())
            return;
        TownyPermissionSource tps = TownyUniverse.getInstance().getPermissionSource();
        Resident deadResident = TownyUniverse.getInstance().getResident(deadPlayer.getUniqueId());
        if (deadResident == null || !deadResident.hasTown())
            return;
        /*
			 * Do an early permission test to avoid hitting the sieges list if
			 * it could never return a proper SiegeSide.
			 */
        if (!tps.testPermission(deadPlayer, SiegeWarPermissionNodes.SIEGEWAR_TOWN_SIEGE_BATTLE_POINTS.getNode()) && !tps.testPermission(deadPlayer, SiegeWarPermissionNodes.SIEGEWAR_NATION_SIEGE_BATTLE_POINTS.getNode()))
            return;
        Town deadResidentTown = deadResident.getTown();
        // Declare local variables
        Siege confirmedCandidateSiege = null;
        SiegeSide confirmedCandidateSiegePlayerSide = SiegeSide.NOBODY;
        double confirmedCandidateDistanceToPlayer = 0;
        double candidateSiegeDistanceToPlayer;
        SiegeSide candidateSiegePlayerSide;
        // Find nearest eligible siege
        for (Siege candidateSiege : SiegeController.getSieges()) {
            // Skip if siege is not active
            if (!candidateSiege.getStatus().isActive())
                continue;
            // Skip if player is not is siege-zone
            if (!SiegeWarDistanceUtil.isInSiegeZone(deadPlayer, candidateSiege))
                continue;
            // Is player eligible ?
            candidateSiegePlayerSide = SiegeWarAllegianceUtil.calculateCandidateSiegePlayerSide(deadPlayer, deadResidentTown, candidateSiege);
            if (candidateSiegePlayerSide == SiegeSide.NOBODY)
                continue;
            // Confirm candidate siege if it is 1st viable one OR closer than confirmed candidate
            candidateSiegeDistanceToPlayer = deadPlayer.getLocation().distance(candidateSiege.getFlagLocation());
            if (confirmedCandidateSiege == null || candidateSiegeDistanceToPlayer < confirmedCandidateDistanceToPlayer) {
                confirmedCandidateSiege = candidateSiege;
                confirmedCandidateSiegePlayerSide = candidateSiegePlayerSide;
                confirmedCandidateDistanceToPlayer = candidateSiegeDistanceToPlayer;
            }
        }
        // apply siege point penalty for the nearest one, and keep inventory
        if (confirmedCandidateSiege != null) {
            // Award penalty points w/ notification if siege is in progress
            if (confirmedCandidateSiege.getStatus() == SiegeStatus.IN_PROGRESS) {
                if (SiegeWarSettings.getWarSiegeDeathSpawnFireworkEnabled()) {
                    if (isBannerMissing(confirmedCandidateSiege.getFlagLocation()))
                        replaceMissingBanner(confirmedCandidateSiege.getFlagLocation());
                    Color bannerColor = ((Banner) confirmedCandidateSiege.getFlagLocation().getBlock().getState()).getBaseColor().getColor();
                    CosmeticUtil.spawnFirework(deadPlayer.getLocation().add(0, 2, 0), Color.RED, bannerColor, true);
                }
                boolean residentIsAttacker = confirmedCandidateSiegePlayerSide == SiegeSide.ATTACKERS;
                SiegeWarScoringUtil.awardPenaltyPoints(residentIsAttacker, deadPlayer, confirmedCandidateSiege);
            }
            // Keep and degrade inventory
            degradeInventory(playerDeathEvent);
            keepInventory(playerDeathEvent);
            // Keep level
            keepLevel(playerDeathEvent);
            if (confirmedCandidateSiege.getBannerControlSessions().containsKey(deadPlayer)) {
                // If the player that died had an ongoing session, remove it.
                confirmedCandidateSiege.removeBannerControlSession(confirmedCandidateSiege.getBannerControlSessions().get(deadPlayer));
                Translatable errorMessage = SiegeWarSettings.isTrapWarfareMitigationEnabled() ? Translatable.of("msg_siege_war_banner_control_session_failure_with_altitude") : Translatable.of("msg_siege_war_banner_control_session_failure");
                Messaging.sendMsg(deadPlayer, errorMessage);
            }
        }
    } catch (Exception e) {
        try {
            SiegeWar.severe("Error evaluating siege death for player " + deadPlayer.getName());
        } catch (Exception e2) {
            SiegeWar.severe("Error evaluating siege death (could not read player name)");
        }
        e.printStackTrace();
    }
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) Color(org.bukkit.Color) Resident(com.palmergames.bukkit.towny.object.Resident) Translatable(com.palmergames.bukkit.towny.object.Translatable) TownyPermissionSource(com.palmergames.bukkit.towny.permissions.TownyPermissionSource) World(org.bukkit.World) SiegeSide(com.gmail.goosius.siegewar.enums.SiegeSide) Siege(com.gmail.goosius.siegewar.objects.Siege)

Example 3 with SiegeSide

use of com.gmail.goosius.siegewar.enums.SiegeSide in project SiegeWar by TownyAdvanced.

the class SiegeWarAllegianceUtil method isPlayerOnTownHostileSide.

/**
 * Determine if a player is on the town-hostile side of a given siege
 */
public static boolean isPlayerOnTownHostileSide(Player player, Resident resident, Siege siege) {
    Town gunnerResidentTown = resident.getTownOrNull();
    SiegeSide playerSiegeSide = calculateCandidateSiegePlayerSide(player, gunnerResidentTown, siege);
    switch(playerSiegeSide) {
        case ATTACKERS:
            return siege.getSiegeType() == SiegeType.CONQUEST || siege.getSiegeType() == SiegeType.SUPPRESSION;
        case DEFENDERS:
            return siege.getSiegeType() == SiegeType.REVOLT || siege.getSiegeType() == SiegeType.LIBERATION;
        default:
            return false;
    }
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) SiegeSide(com.gmail.goosius.siegewar.enums.SiegeSide)

Example 4 with SiegeSide

use of com.gmail.goosius.siegewar.enums.SiegeSide in project SiegeWar by TownyAdvanced.

the class SiegeWarBannerControlUtil method evaluateNewBannerControlSessions.

private static void evaluateNewBannerControlSessions(Siege siege) {
    try {
        TownyUniverse universe = TownyUniverse.getInstance();
        Resident resident;
        for (Player player : Bukkit.getOnlinePlayers()) {
            resident = universe.getResident(player.getUniqueId());
            if (resident == null)
                throw new TownyException(Translation.of("msg_err_not_registered_1", player.getName()));
            if (!doesPlayerMeetBasicSessionRequirements(siege, player, resident))
                continue;
            if (!player.isOp() && player.hasPermission(SiegeWarPermissionNodes.SIEGEWAR_SIEGEZONE_CANNOT_GET_BANNER_CONTROL.getNode()))
                continue;
            if (!BattleSession.getBattleSession().isActive()) {
                Translatable message = Translatable.of("msg_war_siege_battle_session_break_cannot_get_banner_control", SiegeWarBattleSessionUtil.getFormattedTimeUntilNextBattleSessionStarts());
                Messaging.sendErrorMsg(player, message);
                continue;
            }
            if (siege.getBannerControlSessions().containsKey(player))
                // Player already has a control session
                continue;
            if (siege.getBannerControllingResidents().contains(resident))
                // Player already on the BC list
                continue;
            if (SiegeWarBattleSessionUtil.isBattleSessionCappingLimiterActiveForResident(resident)) {
                Translatable message = Translatable.of("msg_war_siege_max_daily_player_battle_sessions_reached_cannot_get_banner_control", SiegeWarSettings.getBattleSessionCappingLimiter(), SiegeWarBattleSessionUtil.getFormattedTimeUntilPlayerBattleSessionLimitExpires(resident));
                Messaging.sendErrorMsg(player, message);
                // Player is being limited by the battle session capping limiter
                continue;
            }
            SiegeSide siegeSide = SiegeWarAllegianceUtil.calculateCandidateSiegePlayerSide(player, resident.getTown(), siege);
            switch(siegeSide) {
                case ATTACKERS:
                    addNewBannerControlSession(siege, player, resident, SiegeSide.ATTACKERS);
                    break;
                case DEFENDERS:
                    addNewBannerControlSession(siege, player, resident, SiegeSide.DEFENDERS);
                    break;
                case NOBODY:
                    continue;
            }
        }
    } catch (Exception e) {
        SiegeWar.severe("Problem evaluating new banner control sessions");
        e.printStackTrace();
    }
}
Also used : Player(org.bukkit.entity.Player) Resident(com.palmergames.bukkit.towny.object.Resident) Translatable(com.palmergames.bukkit.towny.object.Translatable) TownyUniverse(com.palmergames.bukkit.towny.TownyUniverse) SiegeSide(com.gmail.goosius.siegewar.enums.SiegeSide) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 5 with SiegeSide

use of com.gmail.goosius.siegewar.enums.SiegeSide in project SiegeWar by TownyAdvanced.

the class CosmeticUtil method getGlassColor.

/**
 * @param player The player to get the glass color for.
 * @param siege The siege
 * @return The material for the colour of glass.
 */
public static Material getGlassColor(Player player, Siege siege) {
    Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
    if (siege.getBannerControlSessions().containsKey(player))
        return getCaptureColor();
    SiegeSide siegeSide = SiegeSide.NOBODY;
    if (resident.hasTown())
        siegeSide = SiegeWarAllegianceUtil.calculateCandidateSiegePlayerSide(player, TownyAPI.getInstance().getResidentTownOrNull(resident), siege);
    if (siegeSide == SiegeSide.NOBODY || siege.getBannerControllingSide() == SiegeSide.NOBODY)
        return Material.GLASS;
    if (siege.getBannerControllingSide() != siegeSide)
        return getEnemyColor();
    else
        return getCapturedColor();
}
Also used : Resident(com.palmergames.bukkit.towny.object.Resident) SiegeSide(com.gmail.goosius.siegewar.enums.SiegeSide)

Aggregations

SiegeSide (com.gmail.goosius.siegewar.enums.SiegeSide)5 Resident (com.palmergames.bukkit.towny.object.Resident)3 Town (com.palmergames.bukkit.towny.object.Town)3 Translatable (com.palmergames.bukkit.towny.object.Translatable)2 Siege (com.gmail.goosius.siegewar.objects.Siege)1 TownyUniverse (com.palmergames.bukkit.towny.TownyUniverse)1 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)1 TownyPermissionSource (com.palmergames.bukkit.towny.permissions.TownyPermissionSource)1 Color (org.bukkit.Color)1 World (org.bukkit.World)1 Player (org.bukkit.entity.Player)1