Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,13 @@ public static class GlobalModifiers {
@Config.Name("Death Loss Multiplier")
@Config.Comment("Multiplier of levels you will lose, between 0~1.")
public float loseStatsMultiplier = 1;

@Config.Name("Maximum revertable skill level")
@Config.Comment("An integer that constrains the max number of level of the skill can be reverted. -1 for no limit.")
public int globalMaxRevertLevel = -1;

@Config.Name("Revert Factor")
@Config.Comment("How much percentage of exp will be given back to player if a player revert a skill.")
public float globalRevertFactor = 0.8F;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.netty.channel.ChannelHandlerContext;
import net.infstudio.goki.GokiStats;
import net.infstudio.goki.common.utils.DataHelper;
import net.infstudio.goki.common.config.GokiConfig;
import net.infstudio.goki.common.stats.StatBase;
import net.infstudio.goki.common.stats.StatMaxHealth;
import net.minecraft.entity.SharedMonsterAttributes;
Expand Down Expand Up @@ -40,50 +41,57 @@ public void handleClientSide(EntityPlayer player) {

@Override
public void handleServerSide(EntityPlayer player) {
if (player != null) {
StatBase stat = StatBase.stats.get(this.stat);
if (stat.enabled) {
int level = DataHelper.getPlayerStatLevel(player, stat);
if (this.amount > 0) {
int cost = stat.getCost(level + this.amount - 1);
int currentXP = DataHelper.getXPTotal(player.experienceLevel,
player.experience);

if (stat.enabled) {
if (level + this.amount > stat.getLimit()) {
this.amount = 0;
}

if ((currentXP >= cost) && (this.amount != 0)) {
DataHelper.setPlayerStatLevel(player,
stat,
level + this.amount);
if (stat instanceof StatMaxHealth) {
player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20 + level + this.amount);
}

if (this.amount > 0) {
DataHelper.setPlayersExpTo(player, currentXP - cost);
}
}
}
} else if (DataHelper.getPlayerStatLevel(player, stat) > 0) {
player.addExperience((int) (stat.getCost(level + this.amount - 2) * 0.8)); // TODO Configure 0.8
DataHelper.setPlayerStatLevel(player,
stat,
level + this.amount);
if (stat instanceof StatMaxHealth) {
player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20 + level + this.amount);
}
if (player == null)
return;
StatBase stat = StatBase.stats.get(this.stat);
if (!stat.enabled)
return;
int level = DataHelper.getPlayerStatLevel(player, stat);
if (this.amount > 0) {

if (level + this.amount > stat.getLimit()) {
this.amount = stat.getLimit() - level;
}

int cost = stat.getCost(level + this.amount - 1);
int currentXP = DataHelper.getXPTotal(player.experienceLevel, player.experience);

if (currentXP >= cost) {
int reverted = DataHelper.getPlayerRevertStatLevel(player, stat);
reverted = Math.max(reverted - this.amount, 0);
DataHelper.setPlayerRevertStatLevel(player, stat, reverted);

DataHelper.setPlayerStatLevel(player, stat, level + this.amount);
if (stat instanceof StatMaxHealth) {
player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH)
.setBaseValue(20 + level + this.amount);
}

DataHelper.setPlayersExpTo(player, currentXP - cost);
}

GokiStats.packetPipeline.sendTo(new PacketStatSync(player), (EntityPlayerMP) player);
GokiStats.packetPipeline.sendTo(new PacketSyncXP(player), (EntityPlayerMP) player);
} else if (DataHelper.getPlayerStatLevel(player, stat) > 0) {

int reverted = DataHelper.getPlayerRevertStatLevel(player, stat);
int maxRevert = GokiConfig.globalModifiers.globalMaxRevertLevel;

if (maxRevert > 0 && reverted + (-this.amount) > maxRevert) { // check if we limit the max revert, and if the revert overflow the value
this.amount = -(maxRevert - reverted); // ceil the value for max revert
}

reverted += (-this.amount);
DataHelper.setPlayerRevertStatLevel(player, stat, reverted);

player.addExperience((int) (stat.getCost(level + this.amount - 2) * GokiConfig.globalModifiers.globalRevertFactor));
DataHelper.setPlayerStatLevel(player, stat, level + this.amount);
if (stat instanceof StatMaxHealth) {
player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20 + level + this.amount);
}
// else if (this.amount >= 0)
// ;

GokiStats.packetPipeline.sendTo(new PacketStatSync(player),
(EntityPlayerMP) player);
GokiStats.packetPipeline.sendTo(new PacketSyncXP(player),
(EntityPlayerMP) player);
GokiStats.packetPipeline.sendTo(new PacketStatSync(player), (EntityPlayerMP) player);
GokiStats.packetPipeline.sendTo(new PacketSyncXP(player), (EntityPlayerMP) player);
}
}
}
17 changes: 17 additions & 0 deletions src/main/java/net/infstudio/goki/common/utils/DataHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ public static NBTTagCompound getPlayerPersistentNBT(EntityPlayer player) {
return nbt;
}

public static int getPlayerRevertStatLevel(EntityPlayer player, StatBase stat) {
NBTTagCompound nbt = getPlayerPersistentNBT(player);
if (nbt.hasKey("gokistats_Stats")) {
return ((NBTTagCompound) nbt.getTag("gokistats_Stats")).getInteger(stat.key + ".revert");
}
return 0;
}

public static int setPlayerRevertStatLevel(EntityPlayer player, StatBase stat, int level) {
NBTTagCompound nbt = getPlayerPersistentNBT(player);
if (nbt.hasKey("gokistats_Stats")) {
((NBTTagCompound) nbt.getTag("gokistats_Stats")).setInteger(stat.key + ".revert",
(byte) level);
}
return 0;
}

public static int getPlayerStatLevel(EntityPlayer player, StatBase stat) {
NBTTagCompound nbt = getPlayerPersistentNBT(player);
if (nbt.hasKey("gokistats_Stats")) {
Expand Down