Search in sources :

Example 1 with KnowledgeType

use of yuzunyannn.elementalsorcery.elf.research.KnowledgeType in project ElementalSorcery by Yuzunyannn.

the class BlockSealStone method getAncientPaper.

public ItemStack getAncientPaper(World worldIn, @Nullable EntityPlayer player, int fortune, boolean isSuperDrop) {
    Random rand = worldIn.rand;
    ItemStack stack = new ItemStack(ESInit.ITEMS.ANCIENT_PAPER, 1, ItemAncientPaper.EnumType.NORMAL.getMetadata());
    AncientPaper ap = new AncientPaper();
    boolean isMantra = false;
    for (int i = 0; i < fortune + 1; i++) isMantra = isMantra || rand.nextFloat() <= MANTRA_DROP_PROBABILITY_PER_LUCKY;
    if (isSuperDrop)
        isMantra = isMantra || rand.nextBoolean();
    // 只有玩家打碎的时候才会掉mantra
    isMantra = isMantra && player != null;
    float at = rand.nextFloat();
    float length = rand.nextFloat() * 0.5f + 0.05f + Math.min(0.2f, fortune / 50.0f);
    if (isSuperDrop)
        length += rand.nextFloat() * 0.1f + 0.1f;
    at = findRangeStart(length, at);
    int start = MathHelper.floor(at * 100);
    ap.setStart(start).setEnd(start + MathHelper.floor(length * 100));
    ap.setProgress(0);
    RandomHelper.WeightRandom<KnowledgeType> wr = new RandomHelper.WeightRandom();
    for (Entry<String, KnowledgeType> entry : KnowledgeType.REGISTRY.entrySet()) {
        if (isMantra) {
            List<Entry<String, Integer>> list = entry.getValue().getTopics();
            if (!list.isEmpty() && list.get(0).getKey().equals("Mantra"))
                wr.add(entry.getValue(), 10);
        } else
            wr.add(entry.getValue(), 10);
    }
    ap.setType(wr.get());
    // 如果是咒文
    if (isMantra) {
        BlockPos pos = player.getPosition();
        RandomHelper.WeightRandom<Mantra> wMantras = new RandomHelper.WeightRandom();
        for (Entry<ResourceLocation, Mantra> entry : Mantra.REGISTRY.getEntries()) {
            Mantra mantra = entry.getValue();
            float rarity = mantra.getRarity(worldIn, pos);
            if (rarity <= 0)
                continue;
            // 所有都向100靠拢
            rarity = rarity + (100 - rarity) * Math.min(0.5f, fortune / 25.0f);
            wMantras.add(entry.getValue(), rarity);
        }
        Mantra mantra = wMantras.get();
        if (isSuperDrop) {
            // 超级掉落选择随机几次更稀有的
            int rarityTryTimes = 1;
            float raritier = mantra.getRarity(worldIn, pos);
            for (int i = 0; i < rarityTryTimes; i++) {
                Mantra check = wMantras.get();
                float r = check.getRarity(worldIn, pos);
                if (r < raritier) {
                    mantra = check;
                    raritier = r;
                }
            }
        }
        ap.setMantra(mantra);
    }
    ap.saveState(stack);
    return stack;
}
Also used : Mantra(yuzunyannn.elementalsorcery.grimoire.mantra.Mantra) RandomHelper(yuzunyannn.elementalsorcery.util.helper.RandomHelper) Entry(java.util.Map.Entry) Random(java.util.Random) AncientPaper(yuzunyannn.elementalsorcery.elf.research.AncientPaper) ItemAncientPaper(yuzunyannn.elementalsorcery.item.ItemAncientPaper) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) KnowledgeType(yuzunyannn.elementalsorcery.elf.research.KnowledgeType)

Example 2 with KnowledgeType

use of yuzunyannn.elementalsorcery.elf.research.KnowledgeType in project ElementalSorcery by Yuzunyannn.

the class ItemAncientPaper method doUnscramble.

/**
 * 进行一次解读
 */
protected void doUnscramble(AncientPaper ap, World world, EntityPlayer player, EnumHand handIn) {
    if (world.isRemote)
        return;
    NBTTagCompound playerData = EventServer.getPlayerNBT(player);
    // 上次的时间
    long nextTime = playerData.getLong("unsNext");
    if (nextTime > world.getWorldTime() && !player.isCreative()) {
        player.sendMessage(new TextComponentTranslation("info.want.not.unscramble").setStyle(new Style().setColor(TextFormatting.GRAY).setBold(true)));
        return;
    }
    Random rand = world.rand;
    // 一些前置处理
    EnumHand offHand = handIn == EnumHand.MAIN_HAND ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
    int noteEnergy = ItemUnscrambleNote.getNoteEnergy(player.getHeldItem(offHand), player);
    float energy = Math.max(playerData.getFloat("unsEnergy"), 1);
    boolean setTired = rand.nextFloat() < 0.5f / energy;
    if (setTired)
        playerData.setLong("unsNext", world.getWorldTime() + 12000);
    // 增加研究力
    playerData.setFloat("unsEnergy", Math.min(energy + 0.1f, 3));
    ItemUnscrambleNote.growNoteEnergy(player.getHeldItem(offHand), player, rand.nextInt(3), false);
    // 增加进度
    float originProgress = ap.getProgress();
    float grow = rand.nextFloat() * 0.04f + 0.01f + rand.nextFloat() * noteEnergy / 1000;
    ap.setProgress(originProgress + grow);
    if (player instanceof EntityPlayerMP)
        ESCriteriaTriggers.ES_TRING.trigger((EntityPlayerMP) player, "unscramble:once");
    if (!ap.hasType())
        return;
    // 增加研究点数
    KnowledgeType type = ap.getType();
    List<Entry<String, Integer>> topics = type.getTopics();
    if (topics == null)
        return;
    Entry<String, Integer> topic = topics.get(rand.nextInt(topics.size()));
    float rCount = topic.getValue() * grow * (ap.getEnd() - ap.getStart()) / 100.0f;
    int count = MathHelper.floor(rCount);
    float expect = (rCount) - MathHelper.floor(rCount);
    count += rand.nextFloat() <= expect ? 1 : 0;
    if (count > 0)
        Researcher.research(player, topic.getKey(), count);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TextComponentString(net.minecraft.util.text.TextComponentString) Entry(java.util.Map.Entry) Random(java.util.Random) EnumHand(net.minecraft.util.EnumHand) Style(net.minecraft.util.text.Style) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) KnowledgeType(yuzunyannn.elementalsorcery.elf.research.KnowledgeType)

Example 3 with KnowledgeType

use of yuzunyannn.elementalsorcery.elf.research.KnowledgeType in project ElementalSorcery by Yuzunyannn.

the class ItemAncientPaper method addInformation.

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
    AncientPaper ap = new AncientPaper(stack);
    if (ap.isLocked()) {
        tooltip.add(TextFormatting.DARK_AQUA + I18n.format("info.ancientPaper.unknow"));
        float rogress = ap.getProgress();
        if (rogress > 0 || stack.getMetadata() == EnumType.UNSCRAMBLE.getMetadata())
            tooltip.add(I18n.format("info.ancientPaper.progress", String.format("%.2f%%", rogress * 100)));
        return;
    }
    if (ap.hasMantra()) {
        Mantra m = ap.getMantra();
        String name = I18n.format(m.getTranslationKey() + ".name");
        tooltip.add(TextFormatting.YELLOW + I18n.format("info.ancientPaper.mantra", name));
    } else if (ap.hasType()) {
        KnowledgeType type = ap.getType();
        String name = I18n.format(type.getTranslationKey() + ".name");
        tooltip.add(TextFormatting.YELLOW + I18n.format("info.ancientPaper.normal", name));
    } else
        return;
    int start = ap.getStart();
    int end = ap.getEnd();
    if (end - start < 0)
        return;
    if (end - start >= 100)
        return;
    tooltip.add(TextFormatting.DARK_PURPLE + I18n.format("info.ancientPaper.record", start, end));
}
Also used : Mantra(yuzunyannn.elementalsorcery.grimoire.mantra.Mantra) AncientPaper(yuzunyannn.elementalsorcery.elf.research.AncientPaper) TextComponentString(net.minecraft.util.text.TextComponentString) KnowledgeType(yuzunyannn.elementalsorcery.elf.research.KnowledgeType) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with KnowledgeType

use of yuzunyannn.elementalsorcery.elf.research.KnowledgeType in project ElementalSorcery by Yuzunyannn.

the class ItemAncientPaper method toElement.

@Override
public IToElementInfo toElement(ItemStack stack) {
    ElementStack[] estacks = new ElementStack[2];
    estacks[1] = new ElementStack(ESInit.ELEMENTS.WOOD, 8, 20);
    estacks[0] = new ElementStack(ESInit.ELEMENTS.KNOWLEDGE, 4, 30);
    AncientPaper ap = new AncientPaper(stack);
    if (ap.hasType()) {
        KnowledgeType type = ap.getType();
        ElementStack knowledge = type.getKnowledge().copy();
        knowledge.setCount((int) (knowledge.getCount() * (1 - ap.getProgress())));
        estacks[0].grow(knowledge);
    }
    if (ap.hasMantra()) {
        Mantra mantra = ap.getMantra();
        int rarity = mantra.getRarity(null, null);
        rarity = MathHelper.clamp(rarity, 10, 200);
        ElementStack knowledge = new ElementStack(ESInit.ELEMENTS.KNOWLEDGE);
        double power = 20 - MathHelper.sqrt(rarity * 1.45);
        knowledge.setPower(MathHelper.floor(power * power) + 10);
        knowledge.setCount((220 - rarity) / 2);
        estacks[0].grow(knowledge);
    }
    return ToElementInfoStatic.create(8, estacks);
}
Also used : ElementStack(yuzunyannn.elementalsorcery.element.ElementStack) Mantra(yuzunyannn.elementalsorcery.grimoire.mantra.Mantra) AncientPaper(yuzunyannn.elementalsorcery.elf.research.AncientPaper) KnowledgeType(yuzunyannn.elementalsorcery.elf.research.KnowledgeType)

Example 5 with KnowledgeType

use of yuzunyannn.elementalsorcery.elf.research.KnowledgeType in project ElementalSorcery by Yuzunyannn.

the class ElfProfessionResearcher method getChapter.

@Override
public TalkChapter getChapter(EntityElfBase elf, EntityPlayer player, NBTTagCompound shiftData) {
    TileElfTreeCore core = elf.getEdificeCore();
    TalkChapter chapter = new TalkChapter();
    if (core == null) {
        chapter.addScene(new TalkSceneSay("say.edifice.broken"));
        return chapter;
    }
    ItemStack stack = player.getHeldItemMainhand();
    if (stack.getItem() == ESInit.ITEMS.ANCIENT_PAPER) {
        AncientPaper ap = new AncientPaper(stack);
        if (ap.isLocked() && ap.getProgress() <= 0) {
            chapter.addScene(new TalkSceneSay("say.want.paper"));
            // 确认
            TalkSceneSelect confirm = new TalkSceneSelect();
            chapter.addScene(confirm);
            confirm.addString("say.ok", new TalkActionGoTo("whenOK"));
            confirm.addString("say.no", new TalkActionEnd());
            // 对话
            TalkSceneSay wok = new TalkSceneSay().setLabel("whenOK");
            chapter.addScene(wok);
            wok.addString("@#$@#%%^!@$!%%@$!@#!$%%!", Talker.OPPOSING);
            wok.addString("say.scholar.konw", Talker.PLAYER);
            wok.addAction((p, e, c, i, s, t) -> {
                stack.shrink(1);
                KnowledgeType type = ap.getType();
                giveTopicPoint(player, type, (ap.getEnd() - ap.getStart()) / 100.0f);
                return true;
            });
            return chapter;
        }
    }
    chapter.addScene(new TalkSceneSay("say.how.research"));
    return chapter;
}
Also used : TalkChapter(yuzunyannn.elementalsorcery.elf.talk.TalkChapter) TalkSceneSay(yuzunyannn.elementalsorcery.elf.talk.TalkSceneSay) TalkActionGoTo(yuzunyannn.elementalsorcery.elf.talk.TalkActionGoTo) TileElfTreeCore(yuzunyannn.elementalsorcery.tile.TileElfTreeCore) AncientPaper(yuzunyannn.elementalsorcery.elf.research.AncientPaper) ItemAncientPaper(yuzunyannn.elementalsorcery.item.ItemAncientPaper) TalkActionEnd(yuzunyannn.elementalsorcery.elf.talk.TalkActionEnd) TalkSceneSelect(yuzunyannn.elementalsorcery.elf.talk.TalkSceneSelect) ItemStack(net.minecraft.item.ItemStack) KnowledgeType(yuzunyannn.elementalsorcery.elf.research.KnowledgeType)

Aggregations

KnowledgeType (yuzunyannn.elementalsorcery.elf.research.KnowledgeType)5 AncientPaper (yuzunyannn.elementalsorcery.elf.research.AncientPaper)4 Mantra (yuzunyannn.elementalsorcery.grimoire.mantra.Mantra)3 Entry (java.util.Map.Entry)2 Random (java.util.Random)2 ItemStack (net.minecraft.item.ItemStack)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 ItemAncientPaper (yuzunyannn.elementalsorcery.item.ItemAncientPaper)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 EnumHand (net.minecraft.util.EnumHand)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 Style (net.minecraft.util.text.Style)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 ElementStack (yuzunyannn.elementalsorcery.element.ElementStack)1 TalkActionEnd (yuzunyannn.elementalsorcery.elf.talk.TalkActionEnd)1 TalkActionGoTo (yuzunyannn.elementalsorcery.elf.talk.TalkActionGoTo)1 TalkChapter (yuzunyannn.elementalsorcery.elf.talk.TalkChapter)1