Search in sources :

Example 11 with IParty

use of betterquesting.api.questing.party.IParty in project BetterQuesting by Funwayguy.

the class QuestInstance method update.

/**
 * Quest specific living update event. Do not use for item submissions
 */
@Override
public void update(EntityPlayer player) {
    UUID playerID = QuestingAPI.getQuestingUUID(player);
    if (isComplete(playerID)) {
        UserEntry entry = GetUserEntry(playerID);
        if (!hasClaimed(playerID)) {
            if (canClaim(player)) {
                // Task logic is not required to run.
                if (qInfo.getProperty(NativeProps.AUTO_CLAIM) && player.ticksExisted % 20 == 0) {
                    claimReward(player);
                }
                return;
            } else if (qInfo.getProperty(NativeProps.REPEAT_TIME).intValue() < 0 || rewards.size() <= 0) {
                // Task is non repeatable or has no rewards to claim
                return;
            } else {
            // Task logic will now run for repeat quest
            }
        } else if (rewards.size() > 0 && qInfo.getProperty(NativeProps.REPEAT_TIME).intValue() >= 0 && player.world.getTotalWorldTime() - entry.getTimestamp() >= qInfo.getProperty(NativeProps.REPEAT_TIME).intValue()) {
            // Task is scheduled to reset
            if (qInfo.getProperty(NativeProps.GLOBAL)) {
                resetAll(false);
            } else {
                resetUser(playerID, false);
            }
            if (!QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE) && !qInfo.getProperty(NativeProps.SILENT)) {
                postPresetNotice(player, 1);
            }
            PacketSender.INSTANCE.sendToAll(getSyncPacket());
            return;
        } else {
            // No reset or reset is pending
            return;
        }
    }
    if (isUnlocked(playerID) || qInfo.getProperty(NativeProps.LOCKED_PROGRESS)) {
        int done = 0;
        for (ITask tsk : tasks.getAllValues()) {
            if (tsk.isComplete(playerID)) {
                IParty party = PartyManager.INSTANCE.getUserParty(playerID);
                if (// Ensures task is marked as complete for all team members
                party != null) {
                    for (UUID mem : party.getMembers()) {
                        tsk.setComplete(mem);
                    }
                }
                done += 1;
            }
        }
        if (!isUnlocked(playerID)) {
            return;
        } else if ((tasks.size() > 0 || !QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE)) && qInfo.getProperty(NativeProps.LOGIC_TASK).getResult(done, tasks.size())) {
            setComplete(playerID, player.world.getTotalWorldTime());
            PacketSender.INSTANCE.sendToAll(getSyncPacket());
            if (!QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE) && !qInfo.getProperty(NativeProps.SILENT)) {
                postPresetNotice(player, 2);
            }
        } else if (done > 0 && qInfo.getProperty(NativeProps.SIMULTANEOUS)) {
            resetUser(playerID, false);
            PacketSender.INSTANCE.sendToAll(getSyncPacket());
        }
    }
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) UserEntry(betterquesting.misc.UserEntry) IParty(betterquesting.api.questing.party.IParty) UUID(java.util.UUID)

Example 12 with IParty

use of betterquesting.api.questing.party.IParty in project BetterQuesting by Funwayguy.

the class PartyManager method readFromNBT.

@Override
public void readFromNBT(NBTTagList json, EnumSaveType saveType) {
    if (saveType != EnumSaveType.CONFIG) {
        return;
    }
    partyList.clear();
    for (int i = 0; i < json.tagCount(); i++) {
        NBTBase element = json.get(i);
        if (element == null || element.getId() != 10) {
            continue;
        }
        NBTTagCompound jp = (NBTTagCompound) element;
        int partyID = jp.hasKey("partyID", 99) ? jp.getInteger("partyID") : -1;
        if (partyID < 0) {
            continue;
        }
        IParty party = new PartyInstance();
        party.readFromNBT(jp, EnumSaveType.CONFIG);
        if (party.getMembers().size() > 0) {
            partyList.put(partyID, party);
        }
    }
}
Also used : NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IParty(betterquesting.api.questing.party.IParty)

Example 13 with IParty

use of betterquesting.api.questing.party.IParty in project BetterQuesting by Funwayguy.

the class PktHandlerPartyAction method handleServer.

@Override
public // Party management
void handleServer(// Party management
NBTTagCompound data, // Party management
EntityPlayerMP sender) {
    if (sender == null) {
        return;
    }
    /*
		 * If the user is OP than they will have owner permissions of any party
		 * Non OPs can only edit the party they own.
		 */
    boolean isOp = sender.world.getMinecraftServer().getPlayerList().canSendCommands(sender.getGameProfile());
    int aID = !data.hasKey("action") ? -1 : data.getInteger("action");
    if (aID < 0 || aID >= EnumPacketAction.values().length) {
        return;
    }
    EnumPacketAction action = EnumPacketAction.values()[aID];
    int partyID = !data.hasKey("partyID") ? -1 : data.getInteger("partyID");
    UUID tarUser = null;
    IParty tarParty = null;
    EnumPartyStatus status = null;
    UUID senderID = QuestingAPI.getQuestingUUID(sender);
    if (isOp) {
        tarParty = PartyManager.INSTANCE.getValue(partyID);
        status = EnumPartyStatus.OWNER;
    } else {
        if (action == EnumPacketAction.JOIN) {
            tarParty = PartyManager.INSTANCE.getValue(partyID);
        } else {
            tarParty = PartyManager.INSTANCE.getUserParty(senderID);
        }
        if (tarParty != null) {
            status = tarParty.getStatus(senderID);
        }
    }
    try {
        tarUser = UUID.fromString(data.getString("target"));
    } catch (Exception e) {
        // In case an unrecognized name was used instead of their UUID
        tarUser = NameCache.INSTANCE.getUUID(data.getString("target"));
    }
    if (// Create new party if not currently in a party
    action == EnumPacketAction.ADD && tarParty == null) {
        String name = data.getString("name");
        name = name.length() > 0 ? name : "New Party";
        IParty nParty = new PartyInstance();
        nParty.getProperties().setProperty(NativeProps.NAME, name);
        nParty.inviteUser(senderID);
        PartyManager.INSTANCE.add(nParty, PartyManager.INSTANCE.nextKey());
        PacketSender.INSTANCE.sendToAll(PartyManager.INSTANCE.getSyncPacket());
        return;
    } else if (// Operator force deletes party or owner disbands it
    action == EnumPacketAction.REMOVE && tarParty != null && status == EnumPartyStatus.OWNER) {
        PartyManager.INSTANCE.removeKey(partyID);
        PacketSender.INSTANCE.sendToAll(PartyManager.INSTANCE.getSyncPacket());
        return;
    } else if (// Kick/leave party
    action == EnumPacketAction.KICK && tarUser != null && tarParty != null && status != null && (status.ordinal() >= 2 || tarUser == senderID)) {
        tarParty.kickUser(tarUser);
        PacketSender.INSTANCE.sendToAll(tarParty.getSyncPacket());
        return;
    } else if (// Edit party
    action == EnumPacketAction.EDIT && tarParty != null && status == EnumPartyStatus.OWNER) {
        tarParty.readPacket(data);
        PacketSender.INSTANCE.sendToAll(tarParty.getSyncPacket());
        return;
    } else if (// Join party
    action == EnumPacketAction.JOIN && tarParty != null && (isOp || status == EnumPartyStatus.INVITE)) {
        if (isOp) {
            tarParty.inviteUser(senderID);
        }
        tarParty.setStatus(senderID, EnumPartyStatus.MEMBER);
        PacketSender.INSTANCE.sendToAll(tarParty.getSyncPacket());
        return;
    } else if (// Invite to party
    action == EnumPacketAction.INVITE && tarParty != null && tarUser != null && status.ordinal() >= 2) {
        tarParty.inviteUser(tarUser);
        PacketSender.INSTANCE.sendToAll(tarParty.getSyncPacket());
        return;
    }
    return;
}
Also used : EnumPartyStatus(betterquesting.api.enums.EnumPartyStatus) PartyInstance(betterquesting.questing.party.PartyInstance) EnumPacketAction(betterquesting.api.enums.EnumPacketAction) IParty(betterquesting.api.questing.party.IParty) UUID(java.util.UUID)

Example 14 with IParty

use of betterquesting.api.questing.party.IParty in project BetterQuesting by Funwayguy.

the class PktHandlerPartySync method handleClient.

@Override
public void handleClient(NBTTagCompound tag) {
    int partyID = !tag.hasKey("partyID") ? -1 : tag.getInteger("partyID");
    if (partyID < 0) {
        return;
    }
    IParty party = PartyManager.INSTANCE.getValue(partyID);
    if (party == null) {
        party = new PartyInstance();
        PartyManager.INSTANCE.add(party, partyID);
    }
    party.readPacket(tag);
    MinecraftForge.EVENT_BUS.post(new DatabaseEvent.Update());
}
Also used : PartyInstance(betterquesting.questing.party.PartyInstance) IParty(betterquesting.api.questing.party.IParty) DatabaseEvent(betterquesting.api.events.DatabaseEvent)

Example 15 with IParty

use of betterquesting.api.questing.party.IParty in project BetterQuesting by Funwayguy.

the class GuiGameOverBQ method initGui.

/**
 * Adds the buttons (and other controls) to the screen in question.
 */
public void initGui() {
    UUID playerID = QuestingAPI.getQuestingUUID(mc.player);
    IParty party = PartyManager.INSTANCE.getUserParty(playerID);
    if (party == null || !party.getProperties().getProperty(NativeProps.PARTY_LIVES)) {
        lifeCache = LifeDatabase.INSTANCE.getLives(playerID);
    } else {
        lifeCache = LifeDatabase.INSTANCE.getLives(party);
    }
    this.buttonList.clear();
    if (this.mc.world.getWorldInfo().isHardcoreModeEnabled() || (QuestSettings.INSTANCE.getProperty(NativeProps.HARDCORE) && lifeCache <= 0)) {
        this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 72, I18n.format("deathScreen.spectate")));
        this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 96, I18n.format("deathScreen." + (this.mc.isIntegratedServerRunning() ? "deleteWorld" : "leaveServer"))));
    } else {
        this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 72, I18n.format("deathScreen.respawn")));
        this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 96, I18n.format("deathScreen.titleScreen")));
        if (this.mc.getSession() == null) {
            this.buttonList.get(1).enabled = false;
        }
    }
    for (GuiButton guibutton : this.buttonList) {
        guibutton.enabled = false;
    }
}
Also used : GuiButton(net.minecraft.client.gui.GuiButton) IParty(betterquesting.api.questing.party.IParty) UUID(java.util.UUID)

Aggregations

IParty (betterquesting.api.questing.party.IParty)15 UUID (java.util.UUID)9 UserEntry (betterquesting.misc.UserEntry)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 EnumPartyStatus (betterquesting.api.enums.EnumPartyStatus)2 ITask (betterquesting.api.questing.tasks.ITask)2 PartyInstance (betterquesting.questing.party.PartyInstance)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 GuiButtonThemed (betterquesting.api.client.gui.controls.GuiButtonThemed)1 EnumPacketAction (betterquesting.api.enums.EnumPacketAction)1 DatabaseEvent (betterquesting.api.events.DatabaseEvent)1 IReward (betterquesting.api.questing.rewards.IReward)1 IPanelButton (betterquesting.api2.client.gui.controls.IPanelButton)1 GuiJsonEditor (betterquesting.client.gui.editors.json.scrolling.GuiJsonEditor)1 GuiManageParty (betterquesting.client.gui.party.GuiManageParty)1 GuiNoParty (betterquesting.client.gui.party.GuiNoParty)1 ArrayList (java.util.ArrayList)1 Minecraft (net.minecraft.client.Minecraft)1