Add 1.5x progression modifier for tiers the player has already reached
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<NBTTagCompound> {
|
||||
* {@link WizardData#discoverSpell(Spell)} instead. */
|
||||
public Set<Spell> spellsDiscovered;
|
||||
|
||||
/** The highest {@link Tier} this player has upgraded a wand to, used to apply progression modifiers. */
|
||||
private Tier maxTierReached = Tier.NOVICE;
|
||||
|
||||
private Set<UUID> 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. <b> Do not use this for any other
|
||||
@@ -257,6 +261,24 @@ public class WizardData implements INBTSerializable<NBTTagCompound> {
|
||||
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<NBTTagCompound> {
|
||||
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<NBTTagCompound> {
|
||||
}
|
||||
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<NBTTagCompound> {
|
||||
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),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Forfeit> matches = forfeits.get(Pair.of(tier, element));
|
||||
if(matches.isEmpty()){
|
||||
Wizardry.logger.warn("No forfeits with tier {} and element {}!", tier, element);
|
||||
|
||||
Reference in New Issue
Block a user