mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-02 16:49:03 +00:00
Changesftw (#172)
* Npc definitions/npc aggressiveness Let me know how it works * Error fix fixes error
This commit is contained in:
committed by
Daniel Ginovker
parent
e26f32439a
commit
d14f4e5044
File diff suppressed because it is too large
Load Diff
@@ -412,7 +412,7 @@ public class DwarfCannon {
|
||||
|
||||
|
||||
private Npc targetNpc() {
|
||||
for (int i = 0; i < NpcHandler.maxNPCs; i++) {
|
||||
for (int i = 0; i < NpcHandler.MAX_NPCS; i++) {
|
||||
if (NpcHandler.npcs[i] == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ public class Stalls {
|
||||
}
|
||||
|
||||
private static void failGuards(final Client c) {
|
||||
for (int i = 1; i < NpcHandler.maxNPCs; i ++) {
|
||||
for (int i = 1; i < NpcHandler.MAX_NPCS; i ++) {
|
||||
if (NpcHandler.npcs[i] != null) {
|
||||
if (NpcHandler.npcs[i].npcType == 32
|
||||
|| NpcHandler.npcs[i].npcType == 1317
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
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 maxNPCs = 5000;
|
||||
public static int maxListedNPCs = 5000;
|
||||
public static Npc npcs[] = new Npc[maxNPCs];
|
||||
public static int MAX_NPCS = 4000;
|
||||
public static int maxListedNPCs = 4000;
|
||||
public static Npc npcs[] = new Npc[MAX_NPCS];
|
||||
public static NpcList NpcList[] = new NpcList[maxListedNPCs];
|
||||
|
||||
public NpcHandler() {
|
||||
for (int i = 0; i < maxNPCs; i++) {
|
||||
for (int i = 0; i < MAX_NPCS; i++) {
|
||||
npcs[i] = null;
|
||||
}
|
||||
for (int i = 0; i < maxListedNPCs; i++) {
|
||||
@@ -40,6 +40,11 @@ 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) {
|
||||
@@ -54,7 +59,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 < maxNPCs; i++) {
|
||||
for (int i = 1; i < MAX_NPCS; i++) {
|
||||
if (npcs[i] == null) {
|
||||
slot = i;
|
||||
break;
|
||||
@@ -149,7 +154,7 @@ public class NpcHandler {
|
||||
int defence, boolean attackPlayer, boolean headIcon) {
|
||||
// first, search for a free slot
|
||||
int slot = -1;
|
||||
for (int i = 1; i < maxNPCs; i++) {
|
||||
for (int i = 1; i < MAX_NPCS; i++) {
|
||||
if (npcs[i] == null) {
|
||||
slot = i;
|
||||
break;
|
||||
@@ -196,7 +201,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 < maxNPCs; i++) {
|
||||
for (int i = 1; i < MAX_NPCS; i++) {
|
||||
if (npcs[i] == null) {
|
||||
slot = i;
|
||||
break;
|
||||
@@ -249,7 +254,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 < maxNPCs; i++) {
|
||||
for (int i = 1; i < MAX_NPCS; i++) {
|
||||
if (npcs[i] == null) {
|
||||
slot = i;
|
||||
break;
|
||||
@@ -332,7 +337,7 @@ public class NpcHandler {
|
||||
i.clearUpdateFlags();
|
||||
}
|
||||
|
||||
for (int i = 0; i < maxNPCs; i++) {
|
||||
for (int i = 0; i < MAX_NPCS; i++) {
|
||||
if (npcs[i] != null) {
|
||||
|
||||
Client slaveOwner = (Client) PlayerHandler.players[npcs[i].summonedBy];
|
||||
@@ -415,7 +420,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);
|
||||
boolean aggressive = (NpcAggressive.isAggressive(i) || getNpcListCombat(npcs[i].npcType) * 2 > client.combatLevel && getNpcListAggressive(i));
|
||||
if (aggressive && !npcs[i].underAttack && !npcs[i].isDead && npcs[i].MaxHP > 0) {
|
||||
npcs[i].killerId = NpcData.getCloseRandomPlayer(i);
|
||||
}
|
||||
@@ -1403,8 +1408,12 @@ 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -888,11 +888,11 @@ public abstract class Player {
|
||||
|
||||
public byte playerInListBitmap[] = new byte[Constants.MAX_PLAYERS + 7 >> 3];
|
||||
|
||||
public static final int maxNPCListSize = NpcHandler.maxNPCs;
|
||||
public static final int maxNPCListSize = NpcHandler.MAX_NPCS;
|
||||
public Npc npcList[] = new Npc[maxNPCListSize];
|
||||
public int npcListSize = 0;
|
||||
|
||||
public byte npcInListBitmap[] = new byte[NpcHandler.maxNPCs + 7 >> 3];
|
||||
public byte npcInListBitmap[] = new byte[NpcHandler.MAX_NPCS + 7 >> 3];
|
||||
|
||||
public boolean withinDistance(Player otherPlr) {
|
||||
if (heightLevel != otherPlr.heightLevel) {
|
||||
|
||||
@@ -3094,7 +3094,7 @@ public class PlayerAssistant {
|
||||
}
|
||||
|
||||
public int getNpcId(int id) {
|
||||
for (int i = 0; i < NpcHandler.maxNPCs; i++) {
|
||||
for (int i = 0; i < NpcHandler.MAX_NPCS; i++) {
|
||||
if (NpcHandler.npcs[i] != null) {
|
||||
if (NpcHandler.npcs[i].npcId == id) {
|
||||
return i;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user