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;
}
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);
}
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));
}
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);
}
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;
}
Aggregations