Revert "Npc definitions/npc aggressiveness (#169)" (#171)

This reverts commit 2aef86ed25.
This commit is contained in:
Daniel Ginovker
2019-11-11 00:22:35 -05:00
committed by GitHub
parent 2f26fbe5fb
commit e26f32439a
4 changed files with 12 additions and 134427 deletions
File diff suppressed because it is too large Load Diff
@@ -1,129 +0,0 @@
package redone.game.npcs;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import redone.util.XStreamUtil;
public class NPCDefinition {
private static NPCDefinition[] definitions = null;
public static void init() throws IOException {
@SuppressWarnings("unchecked")
List<NPCDefinition> defs = (List<NPCDefinition>) XStreamUtil.getXStream().fromXML(new FileInputStream("data/cfg/npcDefinitions.xml"));
definitions = new NPCDefinition[3790];
for (NPCDefinition def : defs) {
definitions[def.getId()] = def;
}
}
public static NPCDefinition forId(int id) {
NPCDefinition d = definitions[id];
if (d == null) {
d = produceDefinition(id);
}
return d;
}
private int id;
private String name, examine;
private int respawn = 0, combat = 0, hitpoints = 1, maxHit = 0, size = 1, attackSpeed = 4000, attackAnim = 422, defenceAnim = 404, deathAnim = 2304, attackBonus = 20, defenceMelee = 20, defenceRange = 20, defenceMage = 20;
private boolean attackable = false;
private boolean aggressive = false;
private boolean retreats = false;
private boolean poisonous = false;
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getExamine() {
return examine;
}
public int getRespawn() {
return respawn;
}
public int getCombat() {
return combat;
}
public int getHitpoints() {
return hitpoints;
}
public int getMaxHit() {
return maxHit;
}
public int getSize() {
return size;
}
public boolean isAggressive() {
return aggressive;
}
public boolean retreats() {
return retreats;
}
public boolean isPoisonous() {
return poisonous;
}
public static NPCDefinition produceDefinition(int id) {
NPCDefinition def = new NPCDefinition();
def.id = id;
def.name = "NPC #" + def.id;
def.examine = "It's an NPC.";
return def;
}
public int getAttackSpeed() {
return attackSpeed;
}
public int getAttackAnimation() {
return attackAnim;
}
public int getDefenceAnimation() {
return defenceAnim;
}
public int getDeathAnimation() {
return deathAnim;
}
public boolean isAttackable() {
return attackable;
}
public int getAttackBonus() {
return attackBonus;
}
public int getDefenceRange() {
return defenceRange;
}
public int getDefenceMelee() {
return defenceMelee;
}
public int getDefenceMage() {
return defenceMage;
}
}
@@ -26,13 +26,13 @@ import redone.world.clip.Region;
public class NpcHandler {
public static int MAX_NPCS = 4000;
public static int maxListedNPCs = 4000;
public static Npc npcs[] = new Npc[MAX_NPCS];
public static int maxNPCs = 5000;
public static int maxListedNPCs = 5000;
public static Npc npcs[] = new Npc[maxNPCs];
public static NpcList NpcList[] = new NpcList[maxListedNPCs];
public NpcHandler() {
for (int i = 0; i < MAX_NPCS; i++) {
for (int i = 0; i < maxNPCs; i++) {
npcs[i] = null;
}
for (int i = 0; i < maxListedNPCs; i++) {
@@ -40,11 +40,6 @@ public class NpcHandler {
}
loadNPCList("./data/cfg/npc.cfg");
loadAutoSpawn("./data/cfg/spawn-config.cfg");
try {
NPCDefinition.init();
} catch (Exception e) {
System.out.println("npc def error");
}
}
public static boolean isUndead(int index) {
@@ -59,7 +54,7 @@ public class NpcHandler {
int WalkingType, int HP, int maxHit, int attack, int defence,
boolean attackPlayer, boolean headIcon, boolean summonFollow) {
int slot = -1;
for (int i = 1; i < MAX_NPCS; i++) {
for (int i = 1; i < maxNPCs; i++) {
if (npcs[i] == null) {
slot = i;
break;
@@ -154,7 +149,7 @@ public class NpcHandler {
int defence, boolean attackPlayer, boolean headIcon) {
// first, search for a free slot
int slot = -1;
for (int i = 1; i < MAX_NPCS; i++) {
for (int i = 1; i < maxNPCs; i++) {
if (npcs[i] == null) {
slot = i;
break;
@@ -201,7 +196,7 @@ public class NpcHandler {
public void spawnNpc2(int npcType, int x, int y, int heightLevel, int WalkingType, int HP, int maxHit, int attack, int defence) {
// first, search for a free slot
int slot = -1;
for (int i = 1; i < MAX_NPCS; i++) {
for (int i = 1; i < maxNPCs; i++) {
if (npcs[i] == null) {
slot = i;
break;
@@ -254,7 +249,7 @@ public class NpcHandler {
int WalkingType, int HP, int maxHit, int attack, int defence) {
// first, search for a free slot
int slot = -1;
for (int i = 1; i < MAX_NPCS; i++) {
for (int i = 1; i < maxNPCs; i++) {
if (npcs[i] == null) {
slot = i;
break;
@@ -337,7 +332,7 @@ public class NpcHandler {
i.clearUpdateFlags();
}
for (int i = 0; i < MAX_NPCS; i++) {
for (int i = 0; i < maxNPCs; i++) {
if (npcs[i] != null) {
Client slaveOwner = (Client) PlayerHandler.players[npcs[i].summonedBy];
@@ -420,7 +415,7 @@ public class NpcHandler {
Client client = (Client) PlayerHandler.players[NpcData.getCloseRandomPlayer(i)];
if (client != null) {
boolean aggressive = (NpcAggressive.isAggressive(i) || getNpcListCombat(npcs[i].npcType) * 2 > client.combatLevel && getNpcListAggressive(i));
boolean aggressive = (NpcAggressive.isAggressive(i) || getNpcListCombat(npcs[i].npcType) * 2 > client.combatLevel);
if (aggressive && !npcs[i].underAttack && !npcs[i].isDead && npcs[i].MaxHP > 0) {
npcs[i].killerId = NpcData.getCloseRandomPlayer(i);
}
@@ -1408,12 +1403,8 @@ public class NpcHandler {
}
public static boolean checkSpawn(Client player, int i) {
return npcs[i] != null && npcs[i].spawnedBy != -1 && npcs[i].npcType == i;
return npcs[i] != null && npcs[i].spawnedBy != -1
&& npcs[i].npcType == i;
}
public boolean getNpcListAggressive(int npcId) {
return NPCDefinition.forId(npcId).isAggressive();
}
}
@@ -1,37 +0,0 @@
package redone.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import com.thoughtworks.xstream.XStream;
import redone.game.npcs.NPCDefinition;
public class XStreamUtil {
private static XStreamUtil instance = new XStreamUtil();
private static XStream xStream = new XStream();
public static XStreamUtil getInstance() {
return instance;
}
static {
xStream.alias("npcDefinition", NPCDefinition.class);
}
public static XStream getXStream() {
return xStream;
}
public static void writeXML(Object object, File file) throws IOException {
FileOutputStream out = new FileOutputStream(file);
try {
xStream.toXML(object, out);
out.flush();
} finally {
out.close();
}
}
}