Search in sources :

Example 6 with SoulNetwork

use of WayofTime.bloodmagic.core.data.SoulNetwork in project BloodMagic by WayofTime.

the class TileMasterRitualStone method activateRitual.

@Override
public boolean activateRitual(ItemStack activationCrystal, @Nullable EntityPlayer activator, Ritual ritual) {
    if (PlayerHelper.isFakePlayer(activator))
        return false;
    Binding binding = ((IBindable) activationCrystal.getItem()).getBinding(activationCrystal);
    if (binding != null && ritual != null) {
        if (activationCrystal.getItem() instanceof ItemActivationCrystal) {
            int crystalLevel = ((ItemActivationCrystal) activationCrystal.getItem()).getCrystalLevel(activationCrystal);
            if (RitualHelper.canCrystalActivate(ritual, crystalLevel)) {
                if (!getWorld().isRemote) {
                    SoulNetwork network = NetworkHelper.getSoulNetwork(binding);
                    if (!isRedstoned() && network.getCurrentEssence() < ritual.getActivationCost() && (activator != null && !activator.capabilities.isCreativeMode)) {
                        activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.weak"), true);
                        return false;
                    }
                    if (currentRitual != null)
                        currentRitual.stopRitual(this, Ritual.BreakType.ACTIVATE);
                    RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(this, binding.getOwnerId(), ritual, activator, activationCrystal, crystalLevel);
                    if (MinecraftForge.EVENT_BUS.post(event)) {
                        if (activator != null)
                            activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.prevent"), true);
                        return false;
                    }
                    if (ritual.activateRitual(this, activator, binding.getOwnerId())) {
                        if (!isRedstoned() && (activator != null && !activator.capabilities.isCreativeMode))
                            network.syphon(ritual.getActivationCost());
                        if (activator != null)
                            activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.activate"), true);
                        this.active = true;
                        this.owner = binding.getOwnerId();
                        this.cachedNetwork = network;
                        this.currentRitual = ritual;
                        notifyUpdate();
                        return true;
                    }
                }
                notifyUpdate();
                return true;
            }
        }
    } else {
        if (activator != null)
            activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.notValid"), true);
    }
    return false;
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) RitualEvent(WayofTime.bloodmagic.event.RitualEvent) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBindable(WayofTime.bloodmagic.iface.IBindable) SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork) ItemActivationCrystal(WayofTime.bloodmagic.item.ItemActivationCrystal)

Example 7 with SoulNetwork

use of WayofTime.bloodmagic.core.data.SoulNetwork in project BloodMagic by WayofTime.

the class NetworkHelper method canSyphonFromContainer.

/**
 * Checks if the ItemStack has a user to be syphoned from.
 *
 * @param stack    - ItemStack to check
 * @param toSyphon - Amount of LP to syphon
 * @return - If syphoning is possible
 */
public static boolean canSyphonFromContainer(ItemStack stack, int toSyphon) {
    if (!(stack.getItem() instanceof IBindable))
        return false;
    Binding binding = ((IBindable) stack.getItem()).getBinding(stack);
    if (binding == null)
        return false;
    SoulNetwork network = getSoulNetwork(binding);
    return network.getCurrentEssence() >= toSyphon;
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) IBindable(WayofTime.bloodmagic.iface.IBindable) SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork)

Example 8 with SoulNetwork

use of WayofTime.bloodmagic.core.data.SoulNetwork in project BloodMagic by WayofTime.

the class SubCommandOrb method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    if (args.length > 0) {
        if (args[0].equalsIgnoreCase("help"))
            return;
        try {
            String givenName = commandSender.getName();
            if (args.length > 1)
                givenName = args[1];
            EntityPlayer player = CommandBase.getPlayer(server, commandSender, givenName);
            String uuid = PlayerHelper.getUUIDFromPlayer(player).toString();
            SoulNetwork network = NetworkHelper.getSoulNetwork(uuid);
            boolean displayHelp = args.length > 0 && args.length < 2;
            try {
                switch(ValidCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH))) {
                    case SET:
                        {
                            if (displayHelp) {
                                CommandBloodMagic.displayHelpString(commandSender, ValidCommands.SET.help);
                                break;
                            }
                            if (args.length == 3) {
                                if (Utils.isInteger(args[2])) {
                                    int amount = Integer.parseInt(args[2]);
                                    network.setOrbTier(amount);
                                    CommandBloodMagic.displaySuccessString(commandSender, "commands.success");
                                } else {
                                    CommandBloodMagic.displayErrorString(commandSender, "commands.error.arg.invalid");
                                }
                            } else {
                                CommandBloodMagic.displayErrorString(commandSender, "commands.error.arg.missing");
                            }
                            break;
                        }
                    case GET:
                        {
                            if (displayHelp) {
                                CommandBloodMagic.displayHelpString(commandSender, ValidCommands.GET.help);
                                break;
                            }
                            if (args.length > 1)
                                commandSender.sendMessage(new TextComponentString(TextHelper.localizeEffect("message.orb.currenttier", network.getOrbTier())));
                            break;
                        }
                }
            } catch (IllegalArgumentException e) {
                CommandBloodMagic.displayErrorString(commandSender, "commands.error.404");
            }
        } catch (PlayerNotFoundException e) {
            CommandBloodMagic.displayErrorString(commandSender, "commands.error.404");
        }
    }
}
Also used : SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PlayerNotFoundException(net.minecraft.command.PlayerNotFoundException) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 9 with SoulNetwork

use of WayofTime.bloodmagic.core.data.SoulNetwork in project BloodMagic by WayofTime.

the class GenericHandler method onInteract.

// Handles binding of IBindable's as well as setting a player's highest orb tier
@SubscribeEvent
public static void onInteract(PlayerInteractEvent.RightClickItem event) {
    if (event.getWorld().isRemote)
        return;
    EntityPlayer player = event.getEntityPlayer();
    if (PlayerHelper.isFakePlayer(player))
        return;
    ItemStack held = event.getItemStack();
    if (!held.isEmpty() && held.getItem() instanceof IBindable) {
        // Make sure it's bindable
        IBindable bindable = (IBindable) held.getItem();
        Binding binding = bindable.getBinding(held);
        if (binding == null) {
            // If the binding is null, let's create one
            if (bindable.onBind(player, held)) {
                ItemBindEvent toPost = new ItemBindEvent(player, held);
                if (// Allow cancellation of binding
                MinecraftForge.EVENT_BUS.post(toPost))
                    return;
                // Bind item to the player
                BindableHelper.applyBinding(held, player);
            }
        // If the binding exists, we'll check if the player's name has changed since they last used it and update that if so.
        } else if (binding.getOwnerId().equals(player.getGameProfile().getId()) && !binding.getOwnerName().equals(player.getGameProfile().getName())) {
            binding.setOwnerName(player.getGameProfile().getName());
            BindableHelper.applyBinding(held, binding);
        }
    }
    if (!held.isEmpty() && held.getItem() instanceof IBloodOrb) {
        IBloodOrb bloodOrb = (IBloodOrb) held.getItem();
        SoulNetwork network = NetworkHelper.getSoulNetwork(player);
        BloodOrb orb = bloodOrb.getOrb(held);
        if (orb == null)
            return;
        if (orb.getTier() > network.getOrbTier())
            network.setOrbTier(orb.getTier());
    }
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) IBindable(WayofTime.bloodmagic.iface.IBindable) SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) BloodOrb(WayofTime.bloodmagic.orb.BloodOrb) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) ItemBindEvent(WayofTime.bloodmagic.event.ItemBindEvent) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 10 with SoulNetwork

use of WayofTime.bloodmagic.core.data.SoulNetwork in project BloodMagic by WayofTime.

the class NetworkHelper method syphonFromContainer.

/**
 * Syphons a player from within a container.
 *
 * @param stack    - ItemStack in the Container.
 * @param toSyphon - Amount of LP to syphon
 * @return - If the syphon was successful.
 */
public static // TODO: Change to a String, int?
boolean syphonFromContainer(// TODO: Change to a String, int?
ItemStack stack, // TODO: Change to a String, int?
int toSyphon) {
    if (!(stack.getItem() instanceof IBindable))
        return false;
    Binding binding = ((IBindable) stack.getItem()).getBinding(stack);
    if (binding == null)
        return false;
    SoulNetwork network = getSoulNetwork(binding);
    SoulNetworkEvent.ItemDrainInContainerEvent event = new SoulNetworkEvent.ItemDrainInContainerEvent(stack, binding.getOwnerId(), toSyphon);
    return !(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) && network.syphon(event.syphon) >= toSyphon;
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) IBindable(WayofTime.bloodmagic.iface.IBindable) SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork) SoulNetworkEvent(WayofTime.bloodmagic.event.SoulNetworkEvent)

Aggregations

SoulNetwork (WayofTime.bloodmagic.core.data.SoulNetwork)11 Binding (WayofTime.bloodmagic.core.data.Binding)6 ItemStack (net.minecraft.item.ItemStack)6 IBindable (WayofTime.bloodmagic.iface.IBindable)5 IBloodOrb (WayofTime.bloodmagic.orb.IBloodOrb)4 BloodOrb (WayofTime.bloodmagic.orb.BloodOrb)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 EntityBloodLight (WayofTime.bloodmagic.entity.projectile.EntityBloodLight)1 ItemBindEvent (WayofTime.bloodmagic.event.ItemBindEvent)1 RitualEvent (WayofTime.bloodmagic.event.RitualEvent)1 SoulNetworkEvent (WayofTime.bloodmagic.event.SoulNetworkEvent)1 ItemActivationCrystal (WayofTime.bloodmagic.item.ItemActivationCrystal)1 LivingArmour (WayofTime.bloodmagic.livingArmour.LivingArmour)1 TileAltar (WayofTime.bloodmagic.tile.TileAltar)1 PlayerNotFoundException (net.minecraft.command.PlayerNotFoundException)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 TextComponentString (net.minecraft.util.text.TextComponentString)1