Search in sources :

Example 1 with FactionManager

use of com.lying.variousoddities.world.savedata.FactionManager in project VariousOddities by Lyinginbedmon.

the class FactionReputation method resetPlayerReputation.

/**
 * Returns the given player's reputation with the given faction to its configured starting value
 * @param player
 * @param factionName
 * @return
 */
public static int resetPlayerReputation(PlayerEntity player, String factionName) {
    factionName = validateName(factionName);
    FactionManager manager = FactionManager.get(player.getEntityWorld());
    Faction faction = manager.getFaction(factionName);
    int rep = faction == null ? 0 : faction.startingRep;
    PlayerData data = PlayerData.forPlayer(player);
    if (data != null)
        data.reputation.setReputation(factionName, rep);
    return rep;
}
Also used : FactionManager(com.lying.variousoddities.world.savedata.FactionManager) PlayerData(com.lying.variousoddities.capabilities.PlayerData) Faction(com.lying.variousoddities.world.savedata.FactionManager.Faction)

Example 2 with FactionManager

use of com.lying.variousoddities.world.savedata.FactionManager in project VariousOddities by Lyinginbedmon.

the class NearestAttackableTargetGoalMixin method getPredicate.

private static Predicate<LivingEntity> getPredicate(LivingEntity goalOwnerIn) {
    return new Predicate<LivingEntity>() {

        public boolean test(LivingEntity target) {
            // Undead mobs do not target other undead
            if (goalOwnerIn.isNonBoss() && goalOwnerIn.isEntityUndead())
                if (target.isEntityUndead())
                    return false;
            // Mobs do not attack creatures that have mind-controlled them somehow
            LivingData mobData = LivingData.forEntity(goalOwnerIn);
            if (mobData != null && mobData.isTargetingHindered(target))
                return false;
            // Faction mobs do not attack mobs with good reputation
            if (goalOwnerIn instanceof IFactionMob) {
                FactionManager factionManager = FactionManager.get(target.getEntityWorld());
                Faction ownerFaction = factionManager.getFaction(goalOwnerIn);
                if (ownerFaction != null)
                    if (target.getType() == EntityType.PLAYER) {
                        PlayerData data = PlayerData.forPlayer((PlayerEntity) target);
                        if (data != null) {
                            int reputation = data.reputation.getReputation(ownerFaction.name);
                            if (reputation == Integer.MIN_VALUE) {
                                data.reputation.setReputation(ownerFaction.name, ownerFaction.startingRep);
                                reputation = ownerFaction.startingRep;
                            }
                            return EnumAttitude.fromRep(reputation).allowsInteraction(EnumInteraction.ATTACK);
                        }
                    } else if (target instanceof IFactionMob) {
                        Faction inputFaction = factionManager.getFaction(target);
                        if (inputFaction != null)
                            return ownerFaction.relationWith(inputFaction.name).allowsInteraction(EnumInteraction.ATTACK);
                    }
            }
            return true;
        }
    };
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) IFactionMob(com.lying.variousoddities.api.entity.IFactionMob) LivingData(com.lying.variousoddities.capabilities.LivingData) FactionManager(com.lying.variousoddities.world.savedata.FactionManager) PlayerData(com.lying.variousoddities.capabilities.PlayerData) Predicate(java.util.function.Predicate) Faction(com.lying.variousoddities.world.savedata.FactionManager.Faction) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 3 with FactionManager

use of com.lying.variousoddities.world.savedata.FactionManager in project VariousOddities by Lyinginbedmon.

the class FactionReputation method getPlayerReputation.

public static int getPlayerReputation(PlayerEntity player, String factionName) {
    factionName = validateName(factionName);
    PlayerData data = PlayerData.forPlayer(player);
    if (data == null)
        return 0;
    int rep = data.reputation.getReputation(factionName);
    if (rep == Integer.MIN_VALUE) {
        // Set to starting reputation
        FactionManager manager = FactionManager.get(player.getEntityWorld());
        Faction faction = manager.getFaction(factionName);
        if (faction != null)
            rep = faction.startingRep;
        else
            rep = 0;
    }
    return rep;
}
Also used : FactionManager(com.lying.variousoddities.world.savedata.FactionManager) PlayerData(com.lying.variousoddities.capabilities.PlayerData) Faction(com.lying.variousoddities.world.savedata.FactionManager.Faction)

Example 4 with FactionManager

use of com.lying.variousoddities.world.savedata.FactionManager in project VariousOddities by Lyinginbedmon.

the class FactionReputation method changePlayerReputation.

public static void changePlayerReputation(PlayerEntity player, String faction, ReputationChange causeIn, int change, @Nullable LivingEntity sourceMob) {
    if (player == null || (faction == null || faction.length() == 0))
        return;
    FactionManager manager = FactionManager.get(player.getEntityWorld());
    if (manager == null || manager.getFaction(faction) == null)
        return;
    FactionReputation.addPlayerReputation(player, faction, causeIn, change, sourceMob);
}
Also used : FactionManager(com.lying.variousoddities.world.savedata.FactionManager)

Example 5 with FactionManager

use of com.lying.variousoddities.world.savedata.FactionManager in project VariousOddities by Lyinginbedmon.

the class CommandFaction method getFaction.

public static Faction getFaction(CommandContext<CommandSource> context, String name) throws CommandSyntaxException {
    FactionManager manager = FactionManager.get(context.getSource().getWorld());
    Faction faction = manager.getFaction(name);
    if (faction == null)
        throw FACTION_NOT_FOUND.create();
    else
        return faction;
}
Also used : FactionManager(com.lying.variousoddities.world.savedata.FactionManager) Faction(com.lying.variousoddities.world.savedata.FactionManager.Faction)

Aggregations

FactionManager (com.lying.variousoddities.world.savedata.FactionManager)5 Faction (com.lying.variousoddities.world.savedata.FactionManager.Faction)4 PlayerData (com.lying.variousoddities.capabilities.PlayerData)3 IFactionMob (com.lying.variousoddities.api.entity.IFactionMob)1 LivingData (com.lying.variousoddities.capabilities.LivingData)1 Predicate (java.util.function.Predicate)1 LivingEntity (net.minecraft.entity.LivingEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1