1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
package fyresmodjam;
import java.util.Random;
import fyresmodjam.blessings.BlessingUtils;
import fyresmodjam.misc.EntityStat;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.monster.EntityCreeper;
public final class EntityLevelStat extends EntityStat {
private static final int DIABOLIC_CHANCE = 20;
private static final int BLESSING_LEVEL = 5;
private static final int LEVELUP_CHANCE = 3;
public EntityLevelStat(String name, String value) {
super(name, value);
}
@Override
public Object getNewValue(Random r) {
int lvl = 1;
while (true) {
int chance = 5 * (Math.max(1, lvl / 5));
if (ModjamMod.r.nextInt(chance) < LEVELUP_CHANCE) {
return lvl;
}
lvl += 1;
}
}
@Override
public String getAlteredEntityName(EntityLiving entity) {
int level = 1;
try {
String entityName = entity.getEntityData()
.getString(name);
level = Integer.parseInt(entityName);
} catch (Exception e) {
e.printStackTrace();
}
String levelSuffix = String.format("Level %d ", level);
String newName = "";
String entityName = entity.getCommandSenderName();
if (BlessingUtils.hasDisadvantage("Organized Foes")) {
String rank = "Unelisted ";
switch (level) {
case 2:
rank = "Private";
break;
case 3:
rank = "Corporal";
break;
case 4:
rank = "Sergeant";
break;
case 5:
rank = "Lieutenant";
break;
case 6:
rank = "Captain";
break;
case 7:
rank = "Major";
break;
case 8:
rank = "Colonel";
break;
case 9:
rank = "General";
break;
default:
if (level > 9) {
rank = "Field Marshal";
} else {
rank = "Unelisted";
}
}
newName = String.format("%s %s", rank, entityName);
} else {
String colPrefix = "";
if (level == 5) {
colPrefix = "\u00A7c";
}
newName = String.format("%s%s, %s", colPrefix,
entityName, levelSuffix);
}
return newName;
}
@Override
public void modifyEntity(Entity entity) {
int level = 1;
try {
level = Integer.parseInt(entity.getEntityData()
.getString(name));
} catch (Exception e) {
e.printStackTrace();
}
int healthGain = calculateMobHealthGain(entity, level);
if (healthGain != 0) {
EntityLivingBase livingBase = (EntityLivingBase) entity;
float newHealth = livingBase.getMaxHealth()
+ healthGain;
livingBase.getEntityAttribute(
SharedMonsterAttributes.maxHealth)
.setBaseValue(newHealth);
livingBase.setHealth(newHealth);
}
if (level >= BLESSING_LEVEL) {
blessMob(entity);
} else if (BlessingUtils.hasDisadvantage("Diabolic")
&& ModjamMod.r.nextInt(
DIABOLIC_CHANCE) == 0) {
blessMob(entity);
}
if (BlessingUtils.hasDisadvantage("Organized Mobs")) {
equipMob((EntityLivingBase) entity, level);
}
}
private void equipMob(EntityLivingBase entity, int level) {
if (level < 2) {
return;
}
float regionalDifficulty = entity.worldObj.func_147462_b(
entity.posX, entity.posY, entity.posZ);
int adjustedDifficulty = (int) Math
.ceil(level + regionalDifficulty);
if (ModjamMod.r.nextInt(10) == 0
|| adjustedDifficulty > 5) {
}
// TODO actually implement this
}
private int calculateMobHealthGain(Entity entity, int level) {
int levelBase = level - 1;
float quarteredHealth = ((EntityLivingBase) entity)
.getMaxHealth() / 4;
float adjustedMaxHealth = quarteredHealth;
float bonusLevel5Health;
if (level >= 5) {
bonusLevel5Health = quarteredHealth;
bonusLevel5Health *= Math.max(1, level / 5);
} else {
bonusLevel5Health = 0;
}
return (int) ((levelBase * adjustedMaxHealth)
+ bonusLevel5Health);
}
private void blessMob(Entity entity) {
String chosenBlessing = BlessingUtils.getMobBlessing();
entity.getEntityData().setString("Blessing",
chosenBlessing);
BlessingUtils.getBlessingInstance(chosenBlessing)
.correctBlessing(entity);
if (entity instanceof EntityCreeper) {
EntityCreeper creeper = (EntityCreeper) entity;
creeper.getDataWatcher().updateObject(17,
(byte) 1);
creeper.getEntityData().setBoolean("powered",
true);
}
}
}
|