From 92b54edb4ae5b485503482c77694a3ec9f3c0f9a Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Thu, 4 Jun 2020 12:27:10 +0100 Subject: [PATCH] Add 1.5x progression modifier for tiers the player has already reached --- .../electroblob/wizardry/constants/Tier.java | 10 +++++++ .../electroblob/wizardry/data/WizardData.java | 27 +++++++++++++++++++ .../electroblob/wizardry/item/ItemWand.java | 26 +++++++++++++----- .../electroblob/wizardry/misc/Forfeit.java | 4 +-- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/main/java/electroblob/wizardry/constants/Tier.java b/src/main/java/electroblob/wizardry/constants/Tier.java index 38bd61aa..47f4bf7e 100644 --- a/src/main/java/electroblob/wizardry/constants/Tier.java +++ b/src/main/java/electroblob/wizardry/constants/Tier.java @@ -52,6 +52,16 @@ public enum Tier { throw new IllegalArgumentException("No such tier with unlocalised name: " + name); } + /** Returns the tier above this one, or the same tier if this is the highest tier. */ + public Tier next(){ + return ordinal() + 1 < values().length ? values()[ordinal() + 1] : this; + } + + /** Returns the tier below this one, or the same tier if this is the lowest tier. */ + public Tier previous(){ + return ordinal() > 0 ? values()[ordinal() - 1] : this; + } + /** Returns the translated display name of this tier, without formatting. */ public String getDisplayName(){ return Wizardry.proxy.translate("tier." + unlocalisedName); diff --git a/src/main/java/electroblob/wizardry/data/WizardData.java b/src/main/java/electroblob/wizardry/data/WizardData.java index a6880a63..2380c52f 100644 --- a/src/main/java/electroblob/wizardry/data/WizardData.java +++ b/src/main/java/electroblob/wizardry/data/WizardData.java @@ -2,6 +2,7 @@ package electroblob.wizardry.data; import com.google.common.collect.EvictingQueue; import electroblob.wizardry.Wizardry; +import electroblob.wizardry.constants.Tier; import electroblob.wizardry.enchantment.Imbuement; import electroblob.wizardry.entity.living.ISummonedCreature; import electroblob.wizardry.event.SpellCastEvent; @@ -109,6 +110,9 @@ public class WizardData implements INBTSerializable { * {@link WizardData#discoverSpell(Spell)} instead. */ public Set spellsDiscovered; + /** The highest {@link Tier} this player has upgraded a wand to, used to apply progression modifiers. */ + private Tier maxTierReached = Tier.NOVICE; + private Set allies; /** List of usernames of this player's allies. May not be accurate 100% of the time. This is here so that a player * can view the usernames of their allies even when those allies are not online. Do not use this for any other @@ -257,6 +261,24 @@ public class WizardData implements INBTSerializable { return spellsDiscovered.add(spell); } + /** + * Sets the tier this player has reached to the given tier, if they have not yet reached it. + * @param tier The tier the player has reached + */ + public void setTierReached(Tier tier){ + if(!hasReachedTier(tier)) this.maxTierReached = tier; + } + + /** + * Returns true if this player has previously upgraded a wand to the given tier. + * @param tier The tier to check for + * @return True if this player has already upgraded a wand to the given tier, false if not. This does not include + * wands that were purchased at the given tier, unless they have since been upgraded. + */ + public boolean hasReachedTier(Tier tier){ + return tier.level >= maxTierReached.level; + } + // Recent spell tracking /** @@ -485,6 +507,7 @@ public class WizardData implements INBTSerializable { this.allyNames = data.allyNames; this.selectedMinion = data.selectedMinion; this.spellsDiscovered = data.spellsDiscovered; + this.maxTierReached = data.maxTierReached; this.recentSpells = data.recentSpells; for(IVariable variable : data.spellData.keySet()){ @@ -530,6 +553,8 @@ public class WizardData implements INBTSerializable { } properties.setIntArray("discoveredSpells", spells); + properties.setInteger("maxTierReached", maxTierReached.ordinal()); + NBTExtras.storeTagSafely(properties, "recentSpells", NBTExtras.listToNBT(recentSpells, s -> new NBTTagInt(s.metadata()))); storedVariables.forEach(k -> k.write(properties, this.spellData.get(k))); @@ -553,6 +578,8 @@ public class WizardData implements INBTSerializable { spellsDiscovered.add(Spell.byMetadata(id)); } + this.maxTierReached = Tier.values()[nbt.getInteger("maxTierReached")]; + // Probably won't be null but we may as well just reinitialise it instead of clearing it this.recentSpells = EvictingQueue.create(MAX_RECENT_SPELLS); this.recentSpells.addAll(NBTExtras.NBTToList(nbt.getTagList("recentSpells", NBT.TAG_INT), diff --git a/src/main/java/electroblob/wizardry/item/ItemWand.java b/src/main/java/electroblob/wizardry/item/ItemWand.java index b9213621..cb338bcc 100644 --- a/src/main/java/electroblob/wizardry/item/ItemWand.java +++ b/src/main/java/electroblob/wizardry/item/ItemWand.java @@ -76,6 +76,8 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem, private static final float ELEMENTAL_PROGRESSION_MODIFIER = 1.2f; /** The increase in progression for casting an undiscovered spell (can only happen once per spell for each player). */ private static final float DISCOVERY_PROGRESSION_MODIFIER = 5f; + /** The increase in progression for tiers that the player has already reached. */ + private static final float SECOND_TIME_PROGRESSION_MODIFIER = 1.5f; /** The fraction of progression lost when all recently-cast spells are the same as the one being cast. */ private static final float MAX_PROGRESSION_REDUCTION = 0.75f; @@ -182,7 +184,7 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem, @Override public boolean hasEffect(ItemStack stack){ return !Wizardry.settings.legacyWandLevelling && this.tier.level < Tier.MASTER.level - && WandHelper.getProgression(stack) >= Tier.values()[tier.ordinal() + 1].progression; + && WandHelper.getProgression(stack) >= tier.next().progression; } @Override @@ -328,7 +330,7 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem, this.getMana(stack), this.getManaCapacity(stack))); text.add(Wizardry.proxy.translate("item." + Wizardry.MODID + ":wand.progression", new Style().setColor(TextFormatting.GRAY), - WandHelper.getProgression(stack), this.tier.level < Tier.MASTER.level ? Tier.values()[tier.ordinal() + 1].progression : 0)); + WandHelper.getProgression(stack), this.tier.level < Tier.MASTER.level ? tier.next().progression : 0)); } } @@ -473,7 +475,7 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem, if(!Wizardry.settings.legacyWandLevelling){ // Don't display the message if legacy wand levelling is enabled // If the wand just gained enough progression to be upgraded... - Tier nextTier = Tier.values()[tier.ordinal() + 1]; + Tier nextTier = tier.next(); int excess = WandHelper.getProgression(stack) - nextTier.progression; if(excess >= 0 && excess < progression){ // ...display a message above the player's hotbar @@ -590,9 +592,17 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem, progressionModifier *= ELEMENTAL_PROGRESSION_MODIFIER; } - if(WizardData.get(player) != null && !WizardData.get(player).hasSpellBeenDiscovered(spell)){ - // Casting an undiscovered spell now grants 5x progression - progressionModifier *= DISCOVERY_PROGRESSION_MODIFIER; + if(WizardData.get(player) != null){ + + if(!WizardData.get(player).hasSpellBeenDiscovered(spell)){ + // Casting an undiscovered spell now grants 5x progression + progressionModifier *= DISCOVERY_PROGRESSION_MODIFIER; + } + + if(!WizardData.get(player).hasReachedTier(this.tier.next())){ + // 1.5x progression for tiers that have already been reached + progressionModifier *= SECOND_TIME_PROGRESSION_MODIFIER; + } } modifiers.set(SpellModifiers.PROGRESSION, progressionModifier, false); @@ -646,7 +656,7 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem, // progression or the player is in creative mode. if((player == null || player.isCreative() || Wizardry.settings.legacyWandLevelling || WandHelper.getProgression(wand) >= tier.progression) - && tier.ordinal() - 1 == this.tier.ordinal()){ + && tier == this.tier.next()){ // We're not carrying over excess progression for now, but if we do want to, this is how // if(!Wizardry.settings.legacyWandLevelling){ @@ -656,6 +666,8 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem, WandHelper.setProgression(wand, 0); + if(player != null) WizardData.get(player).setTierReached(tier); + ItemStack newWand = new ItemStack(WizardryItems.getWand(tier, this.element)); newWand.setTagCompound(wand.getTagCompound()); // This needs to be done after copying the tag compound so the mana capacity for the new wand diff --git a/src/main/java/electroblob/wizardry/misc/Forfeit.java b/src/main/java/electroblob/wizardry/misc/Forfeit.java index 46e9bb07..31d2c185 100644 --- a/src/main/java/electroblob/wizardry/misc/Forfeit.java +++ b/src/main/java/electroblob/wizardry/misc/Forfeit.java @@ -112,8 +112,8 @@ public abstract class Forfeit { public static Forfeit getRandomForfeit(Random random, Tier tier, Element element){ float f = random.nextFloat(); - if(f < TIER_CHANGE_CHANCE && tier.ordinal() > 0) tier = Tier.values()[tier.ordinal() - 1]; - else if(f > 1 - TIER_CHANGE_CHANCE && tier.ordinal() < Tier.values().length-1) tier = Tier.values()[tier.ordinal() + 1]; + if(f < TIER_CHANGE_CHANCE) tier = tier.previous(); + else if(f > 1 - TIER_CHANGE_CHANCE) tier = tier.next(); List matches = forfeits.get(Pair.of(tier, element)); if(matches.isEmpty()){ Wizardry.logger.warn("No forfeits with tier {} and element {}!", tier, element);