44import io .netty .channel .ChannelHandlerContext ;
55import net .infstudio .goki .GokiStats ;
66import net .infstudio .goki .common .utils .DataHelper ;
7+ import net .infstudio .goki .common .config .GokiConfig ;
78import net .infstudio .goki .common .stats .StatBase ;
89import net .infstudio .goki .common .stats .StatMaxHealth ;
910import 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}
0 commit comments