summaryrefslogtreecommitdiff
path: root/src/main/java/fyresmodjam/EntityLevelStat.java
blob: ee2d72e8821420a56ea995ed1eb27a1f134253df (plain)
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
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 {
	public EntityLevelStat(String name, String value) {
		super(name, value);
	}

	@Override
	public Object getNewValue(Random r) {
		for (int i = 1;; i++) {
			if (ModjamMod.r.nextInt(
					5 * (Math.max(1, i / 5))) < 3) {
				return i;
			}
		}
	}

	@Override
	public String getAlteredEntityName(EntityLiving entity) {
		int level = 1;

		try {
			level = Integer.parseInt(entity.getEntityData()
					.getString(name));
		} catch (Exception e) {
			e.printStackTrace();
		}

		String baseName = "";

		if (BlessingUtils.hasDisadvantage("Organized Foes")) {
			baseName += "Level " + level + " ";

			switch (level) {
				case 2:
					baseName = "Private";
					break;
				case 3:
					baseName = "Corporal";
					break;
				case 4:
					baseName = "Sergeant";
					break;
				case 5:
					baseName = "Lieutenant";
					break;
				case 6:
					baseName = "Captain";
					break;
				case 7:
					baseName = "Major";
					break;
				case 8:
					baseName = "Colonel";
					break;
				case 9:
					baseName = "General";
				default:
					if (level > 9) {
						baseName = "Field Marshal";
					} else {
						baseName = "Unelisted";
					}
			}

			if (!baseName.equals("Unelisted")) {
				baseName += " ";
			}

			baseName += entity.getName();
		} else {
			baseName = (level == 5 ? "\u00A7c" : "")
					+ entity.getName() + ", Level "
					+ level;
		}

		return baseName;
	}

	@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) entity).getEntityAttribute(
					SharedMonsterAttributes.MAX_HEALTH)
					.setBaseValue(((EntityLivingBase) entity)
							.getMaxHealth()
							+ healthGain);
			((EntityLivingBase) entity).setHealth(
					((EntityLivingBase) entity)
							.getMaxHealth()
							+ healthGain);
		}

		if (level >= 5) {
			blessMob(entity);
		} else if (BlessingUtils.hasDisadvantage("Diabolic")
				&& ModjamMod.r.nextInt(20) == 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.world
				.getDifficultyForLocation(
						entity.getPosition()).getClampedAdditionalDifficulty();

		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 adjustedMaxHealth = ((EntityLivingBase) entity)
				.getMaxHealth() / 4;

		float bonusLevel5Health;

		if (level >= 5) {
			bonusLevel5Health = ((EntityLivingBase) entity)
					.getMaxHealth() / 4;

			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) {
			// TODO is it fine to comment this out?
			//((EntityCreeper) entity).getDataWatcher()
			//		.updateObject(17, (byte) 1);
			((EntityCreeper) entity).getEntityData()
					.setBoolean("powered", true);
		}
	}
}