Skip to content

Commit e7fcbd5

Browse files
ci010LasmGratel
authored andcommitted
add revert skill limit; revert skill return exp is configurable now; (#24)
1 parent a71344c commit e7fcbd5

3 files changed

Lines changed: 74 additions & 41 deletions

File tree

src/main/java/net/infstudio/goki/common/config/GokiConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,13 @@ public static class GlobalModifiers {
3939
@Config.Name("Death Loss Multiplier")
4040
@Config.Comment("Multiplier of levels you will lose, between 0~1.")
4141
public float loseStatsMultiplier = 1;
42+
43+
@Config.Name("Maximum revertable skill level")
44+
@Config.Comment("An integer that constrains the max number of level of the skill can be reverted. -1 for no limit.")
45+
public int globalMaxRevertLevel = -1;
46+
47+
@Config.Name("Revert Factor")
48+
@Config.Comment("How much percentage of exp will be given back to player if a player revert a skill.")
49+
public float globalRevertFactor = 0.8F;
4250
}
4351
}

src/main/java/net/infstudio/goki/common/network/packet/PacketStatAlter.java

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.netty.channel.ChannelHandlerContext;
55
import net.infstudio.goki.GokiStats;
66
import net.infstudio.goki.common.utils.DataHelper;
7+
import net.infstudio.goki.common.config.GokiConfig;
78
import net.infstudio.goki.common.stats.StatBase;
89
import net.infstudio.goki.common.stats.StatMaxHealth;
910
import net.minecraft.entity.SharedMonsterAttributes;
@@ -40,50 +41,57 @@ public void handleClientSide(EntityPlayer player) {
4041

4142
@Override
4243
public void handleServerSide(EntityPlayer player) {
43-
if (player != null) {
44-
StatBase stat = StatBase.stats.get(this.stat);
45-
if (stat.enabled) {
46-
int level = DataHelper.getPlayerStatLevel(player, stat);
47-
if (this.amount > 0) {
48-
int cost = stat.getCost(level + this.amount - 1);
49-
int currentXP = DataHelper.getXPTotal(player.experienceLevel,
50-
player.experience);
51-
52-
if (stat.enabled) {
53-
if (level + this.amount > stat.getLimit()) {
54-
this.amount = 0;
55-
}
56-
57-
if ((currentXP >= cost) && (this.amount != 0)) {
58-
DataHelper.setPlayerStatLevel(player,
59-
stat,
60-
level + this.amount);
61-
if (stat instanceof StatMaxHealth) {
62-
player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20 + level + this.amount);
63-
}
64-
65-
if (this.amount > 0) {
66-
DataHelper.setPlayersExpTo(player, currentXP - cost);
67-
}
68-
}
69-
}
70-
} else if (DataHelper.getPlayerStatLevel(player, stat) > 0) {
71-
player.addExperience((int) (stat.getCost(level + this.amount - 2) * 0.8)); // TODO Configure 0.8
72-
DataHelper.setPlayerStatLevel(player,
73-
stat,
74-
level + this.amount);
75-
if (stat instanceof StatMaxHealth) {
76-
player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20 + level + this.amount);
77-
}
44+
if (player == null)
45+
return;
46+
StatBase stat = StatBase.stats.get(this.stat);
47+
if (!stat.enabled)
48+
return;
49+
int level = DataHelper.getPlayerStatLevel(player, stat);
50+
if (this.amount > 0) {
51+
52+
if (level + this.amount > stat.getLimit()) {
53+
this.amount = stat.getLimit() - level;
54+
}
55+
56+
int cost = stat.getCost(level + this.amount - 1);
57+
int currentXP = DataHelper.getXPTotal(player.experienceLevel, player.experience);
58+
59+
if (currentXP >= cost) {
60+
int reverted = DataHelper.getPlayerRevertStatLevel(player, stat);
61+
reverted = Math.max(reverted - this.amount, 0);
62+
DataHelper.setPlayerRevertStatLevel(player, stat, reverted);
63+
64+
DataHelper.setPlayerStatLevel(player, stat, level + this.amount);
65+
if (stat instanceof StatMaxHealth) {
66+
player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH)
67+
.setBaseValue(20 + level + this.amount);
7868
}
69+
70+
DataHelper.setPlayersExpTo(player, currentXP - cost);
71+
}
72+
73+
GokiStats.packetPipeline.sendTo(new PacketStatSync(player), (EntityPlayerMP) player);
74+
GokiStats.packetPipeline.sendTo(new PacketSyncXP(player), (EntityPlayerMP) player);
75+
} else if (DataHelper.getPlayerStatLevel(player, stat) > 0) {
76+
77+
int reverted = DataHelper.getPlayerRevertStatLevel(player, stat);
78+
int maxRevert = GokiConfig.globalModifiers.globalMaxRevertLevel;
79+
80+
if (maxRevert > 0 && reverted + (-this.amount) > maxRevert) { // check if we limit the max revert, and if the revert overflow the value
81+
this.amount = -(maxRevert - reverted); // ceil the value for max revert
82+
}
83+
84+
reverted += (-this.amount);
85+
DataHelper.setPlayerRevertStatLevel(player, stat, reverted);
86+
87+
player.addExperience((int) (stat.getCost(level + this.amount - 2) * GokiConfig.globalModifiers.globalRevertFactor));
88+
DataHelper.setPlayerStatLevel(player, stat, level + this.amount);
89+
if (stat instanceof StatMaxHealth) {
90+
player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20 + level + this.amount);
7991
}
80-
// else if (this.amount >= 0)
81-
// ;
8292

83-
GokiStats.packetPipeline.sendTo(new PacketStatSync(player),
84-
(EntityPlayerMP) player);
85-
GokiStats.packetPipeline.sendTo(new PacketSyncXP(player),
86-
(EntityPlayerMP) player);
93+
GokiStats.packetPipeline.sendTo(new PacketStatSync(player), (EntityPlayerMP) player);
94+
GokiStats.packetPipeline.sendTo(new PacketSyncXP(player), (EntityPlayerMP) player);
8795
}
8896
}
8997
}

src/main/java/net/infstudio/goki/common/utils/DataHelper.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ public static NBTTagCompound getPlayerPersistentNBT(EntityPlayer player) {
2424
return nbt;
2525
}
2626

27+
public static int getPlayerRevertStatLevel(EntityPlayer player, StatBase stat) {
28+
NBTTagCompound nbt = getPlayerPersistentNBT(player);
29+
if (nbt.hasKey("gokistats_Stats")) {
30+
return ((NBTTagCompound) nbt.getTag("gokistats_Stats")).getInteger(stat.key + ".revert");
31+
}
32+
return 0;
33+
}
34+
35+
public static int setPlayerRevertStatLevel(EntityPlayer player, StatBase stat, int level) {
36+
NBTTagCompound nbt = getPlayerPersistentNBT(player);
37+
if (nbt.hasKey("gokistats_Stats")) {
38+
((NBTTagCompound) nbt.getTag("gokistats_Stats")).setInteger(stat.key + ".revert",
39+
(byte) level);
40+
}
41+
return 0;
42+
}
43+
2744
public static int getPlayerStatLevel(EntityPlayer player, StatBase stat) {
2845
NBTTagCompound nbt = getPlayerPersistentNBT(player);
2946
if (nbt.hasKey("gokistats_Stats")) {

0 commit comments

Comments
 (0)