Enjoy it.
EDIT:
Clear flags.
If you want the NPC to not continously face the entity, then uncomment the lines that are commented out.
Code:
/**
* Clears the update flags.
*/
public void clearUpdateFlags() {
updateRequired = false;
textUpdateRequired = false;
secondHitUpdateRequired = false;
gfxUpdateRequired = false;
animUpdateRequired = false;
hitUpdateRequired = false;
faceToEntityUpdateRequired = false;
transformUpdateRequired = false;
faceToUpdateRequired = false;
//if (rawDirection != -1) {
//rawDirection = -1;
//faceToEntityUpdateRequired = true;
//updateRequired = true;
//}
hit = 0;
direction = -1;
}
Code:
public void appendSecondHitUpdate(NPC npc, Stream str) {
str.writeByteA(npc.hit); // hit
str.writeByteC(npc.hitType); // type
str.writeByteA(Misc.getCurrentHP(npc.hp, npc.maxHP, 100)); // current HP
str.writeByte(100); // max HP
}
public void npcGfxHigh(NPC npc, int gfx) {
npc.gfxId = gfx;
npc.gfxDelay = 6553600;
npc.gfxUpdateRequired = true;
npc.updateRequired = true;
}
public void npcGfxLow(NPC npc, int gfx) {
npc.gfxId = gfx;
npc.gfxDelay = 0;
npc.gfxUpdateRequired = true;
npc.updateRequired = true;
}
public void npcGfx(NPC npc, int id, int delay) {
npc.gfxId = id;
npc.gfxDelay = delay;
npc.gfxUpdateRequired = true;
npc.updateRequired = true;
}
public void appendGfxUpdate(NPC npc, Stream str) {
str.writeWord(npc.gfxId);
str.writeDWord(npc.gfxDelay);
}
public void appendFaceToEntity(NPC npc, Stream str) {
str.writeWord(npc.rawDirection);
}
public void faceTo(NPC npc, int playerId) {
npc.rawDirection = 32768 + playerId;
npc.faceToEntityUpdateRequired = true;
npc.updateRequired = true;
}
public void face(NPC npc, int dir) {
npc.rawDirection = dir;
npc.faceToEntityUpdateRequired = true;
npc.updateRequired = true;
}
public void requestTransform(NPC npc, int id) {
npc.transformId = id;
npc.transformUpdateRequired = true;
npc.updateRequired = true;
}
public void appendTransformUpdate(NPC npc, Stream str) {
str.writeWordBigEndianA(npc.transformId);
}
public void requestAnimation(NPC npc, int id, int delay) {
npc.animNumber = id;
npc.animDelay = delay;
npc.animUpdateRequired = true;
npc.updateRequired = true;
}
public void requestFaceCoords(NPC npc, int x, int y) {
npc.faceX = x;
npc.faceY = y;
npc.faceToUpdateRequired = true;
npc.updateRequired = true;
}
public void appendFaceToUpdate(NPC npc, Stream str) {
str.writeWordBigEndian(npc.faceX);
str.writeWordBigEndian(npc.faceY);
}
public void appendAnimUpdate(NPC npc, Stream str) {
str.writeWordBigEndian(npc.animNumber);
str.writeByte(npc.animDelay);
}
public void appendDirUpdate(NPC npc, Stream str) {
str.writeWord(npc.rawDirection);
}
public void appendHitUpdate(NPC npc, Stream str) {
str.writeByteC(npc.hit); // What the npc got 'hit' for
str.writeByteS(npc.hitType); // 0: red hitting - 1: blue hitting
str.writeByteS(Misc.getCurrentHP(npc.hp, npc.maxHP, 100)); // Their current HP, for HP bar
str.writeByteC(100); // Their max HP, for HP bar
}
public void appendNPCUpdateBlock(NPC npc, Stream str) {
if (!npc.updateRequired)
return;
int updateMask = 0;
if (npc.animUpdateRequired) updateMask |= 0x10;
if (npc.secondHitUpdateRequired) updateMask |= 8;
if (npc.gfxUpdateRequired) updateMask |= 0x80;
if (npc.faceToEntityUpdateRequired) updateMask |= 0x20;
if (npc.textUpdateRequired) updateMask |= 1;
if (npc.hitUpdateRequired) updateMask |= 0x40;
if (npc.transformUpdateRequired) updateMask |= 2;
if (npc.faceToUpdateRequired) updateMask |= 4;
str.writeByte(updateMask);
if (npc.animUpdateRequired) appendAnimUpdate(npc, str);
if (npc.secondHitUpdateRequired) appendSecondHitUpdate(npc, str);
if (npc.gfxUpdateRequired) appendGfxUpdate(npc, str);
if (npc.faceToEntityUpdateRequired) appendFaceToEntity(npc, str);
if (npc.textUpdateRequired) str.writeString(npc.textUpdate);
if (npc.hitUpdateRequired) appendHitUpdate(npc, str);
if (npc.transformUpdateRequired) appendTransformUpdate(npc, str);
if (npc.faceToUpdateRequired) appendFaceToUpdate(npc, str);
}
For my custom shard rev masks