forked from MagicBane/Server
Class cleanup and reformat.
This commit is contained in:
+408
-428
@@ -45,19 +45,25 @@ import static engine.util.StringUtils.wordCount;
|
||||
|
||||
public class NPC extends AbstractCharacter {
|
||||
|
||||
public static int SVR_CLOSE_WINDOW = 4;
|
||||
public static ArrayList<Integer> Oprhans = new ArrayList<>();
|
||||
public static HashMap<Integer, ArrayList<String>> _pirateNames = new HashMap<>();
|
||||
// Used for thread safety
|
||||
public final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
private final ArrayList<MobLoot> rolling = new ArrayList<>();
|
||||
private final ArrayList<Mob> siegeMinions = new ArrayList<>();
|
||||
public Building building;
|
||||
public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock();
|
||||
public ArrayList<ProducedItem> forgedItems = new ArrayList<>();
|
||||
public HashMap<Integer, MobEquipment> equip = null;
|
||||
public int runeSetID = 0;
|
||||
public int extraRune2 = 0;
|
||||
protected int loadID;
|
||||
protected boolean isMob;
|
||||
protected MobBase mobBase;
|
||||
protected String name;
|
||||
public Building building;
|
||||
|
||||
protected int dbID;
|
||||
protected int currentID;
|
||||
private DateTime upgradeDateTime = null;
|
||||
|
||||
//used by static npcs
|
||||
protected Zone parentZone;
|
||||
protected float statLat;
|
||||
@@ -70,30 +76,14 @@ public class NPC extends AbstractCharacter {
|
||||
protected ArrayList<Integer> modSuffixTable;
|
||||
protected ArrayList<Byte> itemModTable;
|
||||
protected int symbol;
|
||||
public static int SVR_CLOSE_WINDOW = 4;
|
||||
|
||||
public static ArrayList<Integer>Oprhans = new ArrayList<>();
|
||||
|
||||
// Variables NOT to be stored in db
|
||||
protected boolean isStatic = false;
|
||||
private ArrayList<MobLoot> rolling = new ArrayList<>();
|
||||
private ArrayList<Mob> siegeMinions = new ArrayList<>();
|
||||
private DateTime upgradeDateTime = null;
|
||||
private ConcurrentHashMap<Mob, Integer> siegeMinionMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
private HashSet<Integer> canRoll = null;
|
||||
public static HashMap<Integer, ArrayList<String>> _pirateNames = new HashMap<>();
|
||||
|
||||
public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock();
|
||||
|
||||
private int parentZoneID;
|
||||
|
||||
public ArrayList<ProducedItem> forgedItems = new ArrayList<>();
|
||||
|
||||
public HashMap<Integer, MobEquipment> equip = null;
|
||||
private int equipmentSetID = 0;
|
||||
public int runeSetID = 0;
|
||||
|
||||
private int repairCost = 5;
|
||||
public int extraRune2 = 0;
|
||||
|
||||
|
||||
/**
|
||||
@@ -185,13 +175,15 @@ public class NPC extends AbstractCharacter {
|
||||
|
||||
// Default to contract load ID
|
||||
|
||||
if (loadID == 0)
|
||||
if (loadID == 0) {
|
||||
|
||||
if (this.contract != null)
|
||||
loadID = this.contract.getMobbaseID();
|
||||
else {
|
||||
Logger.error("Invalid contract for NPC: " + this.getObjectUUID());
|
||||
loadID = 2100; // Default human male
|
||||
}
|
||||
}
|
||||
|
||||
this.mobBase = MobBase.getMobBase(this.loadID);
|
||||
this.level = rs.getByte("npc_level");
|
||||
@@ -279,198 +271,10 @@ public class NPC extends AbstractCharacter {
|
||||
//This method restarts an upgrade timer when a building is loaded from the database.
|
||||
// Submit upgrade job for this building based upon it's current upgradeDateTime
|
||||
|
||||
public final void submitUpgradeJob() {
|
||||
|
||||
JobContainer jc;
|
||||
|
||||
if (this.getUpgradeDateTime() == null) {
|
||||
Logger.error("Attempt to submit upgrade job for non-ranking NPC");
|
||||
return;
|
||||
}
|
||||
|
||||
// Submit upgrade job for future date or current instant
|
||||
|
||||
if (this.getUpgradeDateTime().isAfter(DateTime.now()))
|
||||
jc = JobScheduler.getInstance().scheduleJob(new UpgradeNPCJob(this),
|
||||
this.getUpgradeDateTime().getMillis());
|
||||
else
|
||||
JobScheduler.getInstance().scheduleJob(new UpgradeNPCJob(this), 0);
|
||||
|
||||
}
|
||||
|
||||
public void setRank(int newRank) {
|
||||
|
||||
DbManager.NPCQueries.SET_PROPERTY(this, "npc_level", newRank);
|
||||
this.level = (short) newRank;
|
||||
}
|
||||
|
||||
public int getDBID() {
|
||||
return this.dbID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getObjectUUID() {
|
||||
return currentID;
|
||||
}
|
||||
|
||||
private void clearStatic() {
|
||||
this.parentZone = null;
|
||||
this.statLat = 0f;
|
||||
this.statLon = 0f;
|
||||
this.statAlt = 0f;
|
||||
}
|
||||
|
||||
private void initializeNPC() {
|
||||
|
||||
int slot;
|
||||
Vector3fImmutable slotLocation;
|
||||
Quaternion slotRotation;
|
||||
|
||||
if (ConfigManager.serverType.equals(ServerType.LOGINSERVER))
|
||||
return;
|
||||
|
||||
// NPC Guild owners have no contract
|
||||
|
||||
if (this.contract == null)
|
||||
return;
|
||||
|
||||
// Configure parent zone adding this NPC to the
|
||||
// zone collection
|
||||
|
||||
this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneID);
|
||||
this.parentZone.zoneNPCSet.remove(this);
|
||||
this.parentZone.zoneNPCSet.add(this);
|
||||
|
||||
// Setup location for this NPC
|
||||
|
||||
this.bindLoc = new Vector3fImmutable(this.statLat, this.statAlt, this.statLon);
|
||||
this.bindLoc = this.parentZone.getLoc().add(this.bindLoc);
|
||||
this.loc = new Vector3fImmutable(bindLoc);
|
||||
|
||||
// Handle NPCs within buildings
|
||||
|
||||
if (this.building != null) {
|
||||
|
||||
// Get next available slot for this NPC and use it
|
||||
// to add the NPC to the building's hireling list
|
||||
|
||||
slot = BuildingManager.getAvailableSlot(building);
|
||||
|
||||
if (slot == -1)
|
||||
Logger.error("No available slot for NPC: " + this.getObjectUUID());
|
||||
|
||||
building.getHirelings().put(this, slot);
|
||||
|
||||
// Override bind and location for this npc derived
|
||||
// from BuildingManager slot location data.
|
||||
|
||||
slotLocation = BuildingManager.getSlotLocation(building, slot).getLocation();
|
||||
|
||||
this.bindLoc = building.getLoc().add(slotLocation);
|
||||
|
||||
// Rotate slot position by the building rotation
|
||||
|
||||
this.bindLoc = Vector3fImmutable.rotateAroundPoint(building.getLoc(), this.bindLoc, building.getBounds().getQuaternion().angleY);
|
||||
|
||||
this.loc = new Vector3fImmutable(bindLoc);
|
||||
|
||||
// Rotate NPC by slot rotation
|
||||
|
||||
slotRotation = BuildingManager.getSlotLocation(building, slot).getRotation();
|
||||
this.setRot(new Vector3f(0, slotRotation.y, 0));
|
||||
|
||||
// Rotate NPC rotation by the building's rotation
|
||||
|
||||
slotRotation = new Quaternion().fromAngles(0, acos(this.getRot().y) * 2, 0);
|
||||
slotRotation = slotRotation.mult(building.getBounds().getQuaternion());
|
||||
this.setRot(new Vector3f(0, slotRotation.y, 0));
|
||||
|
||||
// Configure region and floor/level for this NPC
|
||||
|
||||
this.region = BuildingManager.GetRegion(this.building, bindLoc.x, bindLoc.y, bindLoc.z);
|
||||
}
|
||||
|
||||
if (this.contract != null) {
|
||||
this.symbol = this.contract.getIconID();
|
||||
this.modTypeTable = this.contract.getNPCModTypeTable();
|
||||
this.modSuffixTable = this.contract.getNpcModSuffixTable();
|
||||
this.itemModTable = this.contract.getItemModTable();
|
||||
int VID = this.contract.getVendorID();
|
||||
|
||||
if (VID != 0)
|
||||
this.vendorID = VID;
|
||||
else
|
||||
this.vendorID = 1; //no vendor items
|
||||
}
|
||||
|
||||
if (this.mobBase != null) {
|
||||
this.healthMax = this.mobBase.getHealthMax();
|
||||
this.manaMax = 0;
|
||||
this.staminaMax = 0;
|
||||
this.setHealth(this.healthMax);
|
||||
this.mana.set(this.manaMax);
|
||||
this.stamina.set(this.staminaMax);
|
||||
}
|
||||
|
||||
if (this.parentZone.isPlayerCity())
|
||||
if (NPC.GetNPCProfits(this) == null)
|
||||
NPCProfits.CreateProfits(this);
|
||||
|
||||
//TODO set these correctly later
|
||||
this.rangeHandOne = 8;
|
||||
this.rangeHandTwo = -1;
|
||||
this.minDamageHandOne = 1;
|
||||
this.maxDamageHandOne = 4;
|
||||
this.minDamageHandTwo = 1;
|
||||
this.maxDamageHandTwo = 4;
|
||||
this.atrHandOne = 300;
|
||||
this.defenseRating = 200;
|
||||
this.isActive = true;
|
||||
|
||||
this.charItemManager.load();
|
||||
}
|
||||
|
||||
|
||||
public static NPC getFromCache(int id) {
|
||||
return (NPC) DbManager.getFromCache(GameObjectType.NPC, id);
|
||||
}
|
||||
|
||||
/*
|
||||
* Getters
|
||||
*/
|
||||
|
||||
public boolean isMob() {
|
||||
return this.isMob;
|
||||
}
|
||||
|
||||
public MobBase getMobBase() {
|
||||
return this.mobBase;
|
||||
}
|
||||
|
||||
public Contract getContract() {
|
||||
return this.contract;
|
||||
}
|
||||
|
||||
public int getContractID() {
|
||||
|
||||
if (this.contract != null)
|
||||
return this.contract.getObjectUUID();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return this.isStatic;
|
||||
}
|
||||
|
||||
public Building getBuilding() {
|
||||
return this.building;
|
||||
}
|
||||
|
||||
public void setName(String value) {
|
||||
this.name = value;
|
||||
}
|
||||
|
||||
public static boolean UpdateName(NPC npc, String value) {
|
||||
|
||||
if (!DbManager.NPCQueries.UPDATE_NAME(npc, value))
|
||||
@@ -481,49 +285,11 @@ public class NPC extends AbstractCharacter {
|
||||
|
||||
}
|
||||
|
||||
public void setBuilding(Building value) {
|
||||
this.building = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLastName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3fImmutable getBindLoc() {
|
||||
return this.bindLoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGuildUUID() {
|
||||
|
||||
if (this.guild == null)
|
||||
return 0;
|
||||
|
||||
return this.guild.getObjectUUID();
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialization
|
||||
*/
|
||||
|
||||
public static void serializeNpcForClientMsgOtherPlayer(NPC npc, ByteBufferWriter writer, boolean hideAsciiLastName)
|
||||
throws SerializationException {
|
||||
serializeForClientMsgOtherPlayer(npc, writer);
|
||||
}
|
||||
|
||||
|
||||
public static void serializeForClientMsgOtherPlayer(NPC npc, ByteBufferWriter writer)
|
||||
throws SerializationException {
|
||||
|
||||
@@ -782,6 +548,389 @@ public class NPC extends AbstractCharacter {
|
||||
writer.put((byte) 0);
|
||||
}
|
||||
|
||||
private static int serializeExtraRune(NPC npc, int runeID, int cnt, ByteBufferWriter writer) {
|
||||
writer.putInt(5);
|
||||
writer.putInt(0);
|
||||
writer.putInt(runeID);
|
||||
if (cnt == 0)
|
||||
writer.putInt(GameObjectType.NPCClassRuneTwo.ordinal());
|
||||
else
|
||||
writer.putInt(GameObjectType.NPCClassRuneThree.ordinal());
|
||||
|
||||
writer.putInt(npc.currentID);
|
||||
return cnt + 1;
|
||||
}
|
||||
|
||||
public static NPC createNPC(String name, int contractID, Vector3fImmutable spawn, Guild guild, boolean isMob, Zone parent, short level, Building building) {
|
||||
|
||||
NPC npcWithoutID = new NPC(name, (short) 0, (short) 0, (short) 0, (short) 0,
|
||||
(short) 0, (short) 1, 0, false, false, false, spawn, spawn, Vector3fImmutable.ZERO,
|
||||
(short) 1, (short) 1, (short) 1, guild, (byte) 0, 0, isMob, building, contractID, parent);
|
||||
|
||||
npcWithoutID.setLevel(level);
|
||||
|
||||
if (npcWithoutID.mobBase == null) {
|
||||
return null;
|
||||
}
|
||||
if (parent != null) {
|
||||
npcWithoutID.setRelPos(parent, spawn.x - parent.absX, spawn.y - parent.absY, spawn.z - parent.absZ);
|
||||
}
|
||||
NPC npc;
|
||||
try {
|
||||
npc = DbManager.NPCQueries.ADD_NPC(npcWithoutID, isMob);
|
||||
npc.setObjectTypeMask(MBServerStatics.MASK_NPC);
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
npc = null;
|
||||
}
|
||||
|
||||
|
||||
return npc;
|
||||
}
|
||||
|
||||
public static NPC getNPC(int id) {
|
||||
|
||||
if (id == 0)
|
||||
return null;
|
||||
NPC npc = (NPC) DbManager.getFromCache(GameObjectType.NPC, id);
|
||||
if (npc != null)
|
||||
return npc;
|
||||
|
||||
return DbManager.NPCQueries.GET_NPC(id);
|
||||
}
|
||||
|
||||
/*
|
||||
* Getters
|
||||
*/
|
||||
|
||||
public static boolean ISGuardCaptain(int contractID) {
|
||||
return MinionType.ContractToMinionMap.containsKey(contractID);
|
||||
}
|
||||
|
||||
public static boolean UpdateEquipSetID(NPC npc, int equipSetID) {
|
||||
|
||||
if (!NPCManager._bootySetMap.containsKey(equipSetID))
|
||||
return false;
|
||||
|
||||
if (!DbManager.NPCQueries.UPDATE_EQUIPSET(npc, equipSetID))
|
||||
return false;
|
||||
|
||||
npc.equipmentSetID = equipSetID;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean UpdateRaceID(NPC npc, int raceID) {
|
||||
|
||||
if (!DbManager.NPCQueries.UPDATE_MOBBASE(npc, raceID))
|
||||
return false;
|
||||
|
||||
npc.loadID = raceID;
|
||||
npc.mobBase = MobBase.getMobBase(npc.loadID);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static NPCProfits GetNPCProfits(NPC npc) {
|
||||
return NPCProfits.ProfitCache.get(npc.currentID);
|
||||
}
|
||||
|
||||
public static void processRedeedNPC(NPC npc, Building building, ClientConnection origin) {
|
||||
|
||||
// Member variable declaration
|
||||
PlayerCharacter player;
|
||||
Contract contract;
|
||||
CharacterItemManager itemMan;
|
||||
ItemBase itemBase;
|
||||
Item item;
|
||||
|
||||
npc.lock.writeLock().lock();
|
||||
|
||||
try {
|
||||
|
||||
|
||||
if (building == null)
|
||||
return;
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
itemMan = player.getCharItemManager();
|
||||
|
||||
contract = npc.getContract();
|
||||
|
||||
if (!player.getCharItemManager().hasRoomInventory((short) 1)) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 21);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!building.getHirelings().containsKey(npc))
|
||||
return;
|
||||
|
||||
if (!npc.remove()) {
|
||||
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
|
||||
return;
|
||||
}
|
||||
|
||||
building.getHirelings().remove(npc);
|
||||
|
||||
itemBase = ItemBase.getItemBase(contract.getContractID());
|
||||
|
||||
if (itemBase == null) {
|
||||
Logger.error("Could not find Contract for npc: " + npc.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
boolean itemWorked = false;
|
||||
|
||||
item = new Item(itemBase, player.getObjectUUID(), OwnerType.PlayerCharacter, (byte) ((byte) npc.getRank() - 1), (byte) ((byte) npc.getRank() - 1),
|
||||
(short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0,
|
||||
new ArrayList<>(), "");
|
||||
item.setNumOfItems(1);
|
||||
item.containerType = Enum.ItemContainerType.INVENTORY;
|
||||
|
||||
try {
|
||||
item = DbManager.ItemQueries.ADD_ITEM(item);
|
||||
itemWorked = true;
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
if (itemWorked) {
|
||||
itemMan.addItemToInventory(item);
|
||||
itemMan.updateInventory();
|
||||
}
|
||||
|
||||
ManageCityAssetsMsg mca = new ManageCityAssetsMsg();
|
||||
mca.actionType = SVR_CLOSE_WINDOW;
|
||||
mca.setTargetType(building.getObjectType().ordinal());
|
||||
mca.setTargetID(building.getObjectUUID());
|
||||
origin.sendMsg(mca);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
npc.lock.writeLock().unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public final void submitUpgradeJob() {
|
||||
|
||||
JobContainer jc;
|
||||
|
||||
if (this.getUpgradeDateTime() == null) {
|
||||
Logger.error("Attempt to submit upgrade job for non-ranking NPC");
|
||||
return;
|
||||
}
|
||||
|
||||
// Submit upgrade job for future date or current instant
|
||||
|
||||
if (this.getUpgradeDateTime().isAfter(DateTime.now()))
|
||||
jc = JobScheduler.getInstance().scheduleJob(new UpgradeNPCJob(this),
|
||||
this.getUpgradeDateTime().getMillis());
|
||||
else
|
||||
JobScheduler.getInstance().scheduleJob(new UpgradeNPCJob(this), 0);
|
||||
|
||||
}
|
||||
|
||||
public void setRank(int newRank) {
|
||||
|
||||
DbManager.NPCQueries.SET_PROPERTY(this, "npc_level", newRank);
|
||||
this.level = (short) newRank;
|
||||
}
|
||||
|
||||
public int getDBID() {
|
||||
return this.dbID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getObjectUUID() {
|
||||
return currentID;
|
||||
}
|
||||
|
||||
private void clearStatic() {
|
||||
this.parentZone = null;
|
||||
this.statLat = 0f;
|
||||
this.statLon = 0f;
|
||||
this.statAlt = 0f;
|
||||
}
|
||||
|
||||
private void initializeNPC() {
|
||||
|
||||
int slot;
|
||||
Vector3fImmutable slotLocation;
|
||||
Quaternion slotRotation;
|
||||
|
||||
if (ConfigManager.serverType.equals(ServerType.LOGINSERVER))
|
||||
return;
|
||||
|
||||
// NPC Guild owners have no contract
|
||||
|
||||
if (this.contract == null)
|
||||
return;
|
||||
|
||||
// Configure parent zone adding this NPC to the
|
||||
// zone collection
|
||||
|
||||
this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneID);
|
||||
this.parentZone.zoneNPCSet.remove(this);
|
||||
this.parentZone.zoneNPCSet.add(this);
|
||||
|
||||
// Setup location for this NPC
|
||||
|
||||
this.bindLoc = new Vector3fImmutable(this.statLat, this.statAlt, this.statLon);
|
||||
this.bindLoc = this.parentZone.getLoc().add(this.bindLoc);
|
||||
this.loc = new Vector3fImmutable(bindLoc);
|
||||
|
||||
// Handle NPCs within buildings
|
||||
|
||||
if (this.building != null) {
|
||||
|
||||
// Get next available slot for this NPC and use it
|
||||
// to add the NPC to the building's hireling list
|
||||
|
||||
slot = BuildingManager.getAvailableSlot(building);
|
||||
|
||||
if (slot == -1)
|
||||
Logger.error("No available slot for NPC: " + this.getObjectUUID());
|
||||
|
||||
building.getHirelings().put(this, slot);
|
||||
|
||||
// Override bind and location for this npc derived
|
||||
// from BuildingManager slot location data.
|
||||
|
||||
slotLocation = BuildingManager.getSlotLocation(building, slot).getLocation();
|
||||
|
||||
this.bindLoc = building.getLoc().add(slotLocation);
|
||||
|
||||
// Rotate slot position by the building rotation
|
||||
|
||||
this.bindLoc = Vector3fImmutable.rotateAroundPoint(building.getLoc(), this.bindLoc, building.getBounds().getQuaternion().angleY);
|
||||
|
||||
this.loc = new Vector3fImmutable(bindLoc);
|
||||
|
||||
// Rotate NPC by slot rotation
|
||||
|
||||
slotRotation = BuildingManager.getSlotLocation(building, slot).getRotation();
|
||||
this.setRot(new Vector3f(0, slotRotation.y, 0));
|
||||
|
||||
// Rotate NPC rotation by the building's rotation
|
||||
|
||||
slotRotation = new Quaternion().fromAngles(0, acos(this.getRot().y) * 2, 0);
|
||||
slotRotation = slotRotation.mult(building.getBounds().getQuaternion());
|
||||
this.setRot(new Vector3f(0, slotRotation.y, 0));
|
||||
|
||||
// Configure region and floor/level for this NPC
|
||||
|
||||
this.region = BuildingManager.GetRegion(this.building, bindLoc.x, bindLoc.y, bindLoc.z);
|
||||
}
|
||||
|
||||
if (this.contract != null) {
|
||||
this.symbol = this.contract.getIconID();
|
||||
this.modTypeTable = this.contract.getNPCModTypeTable();
|
||||
this.modSuffixTable = this.contract.getNpcModSuffixTable();
|
||||
this.itemModTable = this.contract.getItemModTable();
|
||||
int VID = this.contract.getVendorID();
|
||||
|
||||
if (VID != 0)
|
||||
this.vendorID = VID;
|
||||
else
|
||||
this.vendorID = 1; //no vendor items
|
||||
}
|
||||
|
||||
if (this.mobBase != null) {
|
||||
this.healthMax = this.mobBase.getHealthMax();
|
||||
this.manaMax = 0;
|
||||
this.staminaMax = 0;
|
||||
this.setHealth(this.healthMax);
|
||||
this.mana.set(this.manaMax);
|
||||
this.stamina.set(this.staminaMax);
|
||||
}
|
||||
|
||||
if (this.parentZone.isPlayerCity())
|
||||
if (NPC.GetNPCProfits(this) == null)
|
||||
NPCProfits.CreateProfits(this);
|
||||
|
||||
//TODO set these correctly later
|
||||
this.rangeHandOne = 8;
|
||||
this.rangeHandTwo = -1;
|
||||
this.minDamageHandOne = 1;
|
||||
this.maxDamageHandOne = 4;
|
||||
this.minDamageHandTwo = 1;
|
||||
this.maxDamageHandTwo = 4;
|
||||
this.atrHandOne = 300;
|
||||
this.defenseRating = 200;
|
||||
this.isActive = true;
|
||||
|
||||
this.charItemManager.load();
|
||||
}
|
||||
|
||||
public boolean isMob() {
|
||||
return this.isMob;
|
||||
}
|
||||
|
||||
public MobBase getMobBase() {
|
||||
return this.mobBase;
|
||||
}
|
||||
|
||||
public Contract getContract() {
|
||||
return this.contract;
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialization
|
||||
*/
|
||||
|
||||
public int getContractID() {
|
||||
|
||||
if (this.contract != null)
|
||||
return this.contract.getObjectUUID();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return this.isStatic;
|
||||
}
|
||||
|
||||
public Building getBuilding() {
|
||||
return this.building;
|
||||
}
|
||||
|
||||
public void setBuilding(Building value) {
|
||||
this.building = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String value) {
|
||||
this.name = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLastName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3fImmutable getBindLoc() {
|
||||
return this.bindLoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGuildUUID() {
|
||||
|
||||
if (this.guild == null)
|
||||
return 0;
|
||||
|
||||
return this.guild.getObjectUUID();
|
||||
}
|
||||
|
||||
public void removeMinions() {
|
||||
|
||||
for (Mob toRemove : this.siegeMinionMap.keySet()) {
|
||||
@@ -813,20 +962,6 @@ public class NPC extends AbstractCharacter {
|
||||
}
|
||||
}
|
||||
|
||||
private static int serializeExtraRune(NPC npc,int runeID, int cnt, ByteBufferWriter writer) {
|
||||
writer.putInt(5);
|
||||
writer.putInt(0);
|
||||
writer.putInt(runeID);
|
||||
if (cnt == 0)
|
||||
writer.putInt(GameObjectType.NPCClassRuneTwo.ordinal());
|
||||
else
|
||||
writer.putInt(GameObjectType.NPCClassRuneThree.ordinal());
|
||||
|
||||
writer.putInt(npc.currentID);
|
||||
return cnt + 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getSpeed() {
|
||||
|
||||
@@ -891,7 +1026,6 @@ public class NPC extends AbstractCharacter {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vector3fImmutable getLoc() {
|
||||
|
||||
@@ -937,13 +1071,14 @@ public class NPC extends AbstractCharacter {
|
||||
return this.sellPercent;
|
||||
}
|
||||
|
||||
public void setSellPercent(float sellPercent) {
|
||||
this.sellPercent = sellPercent;
|
||||
}
|
||||
|
||||
public float getBuyPercent() {
|
||||
return this.buyPercent;
|
||||
}
|
||||
|
||||
public void setBuyPercent(float buyPercent) {
|
||||
this.buyPercent = buyPercent;
|
||||
}
|
||||
|
||||
public float getBuyPercent(PlayerCharacter player) {
|
||||
if (NPC.GetNPCProfits(this) == null || this.guild == null)
|
||||
return this.buyPercent;
|
||||
@@ -968,53 +1103,11 @@ public class NPC extends AbstractCharacter {
|
||||
return 1 + profits.sellNormal;
|
||||
}
|
||||
|
||||
public void setBuyPercent(float buyPercent) {
|
||||
this.buyPercent = buyPercent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeLooted() {
|
||||
return !this.isAlive();
|
||||
}
|
||||
|
||||
public static NPC createNPC(String name, int contractID, Vector3fImmutable spawn, Guild guild, boolean isMob, Zone parent, short level, Building building) {
|
||||
|
||||
NPC npcWithoutID = new NPC(name, (short) 0, (short) 0, (short) 0, (short) 0,
|
||||
(short) 0, (short) 1, 0, false, false, false, spawn, spawn, Vector3fImmutable.ZERO,
|
||||
(short) 1, (short) 1, (short) 1, guild, (byte) 0, 0, isMob, building, contractID, parent);
|
||||
|
||||
npcWithoutID.setLevel(level);
|
||||
|
||||
if (npcWithoutID.mobBase == null) {
|
||||
return null;
|
||||
}
|
||||
if (parent != null) {
|
||||
npcWithoutID.setRelPos(parent, spawn.x - parent.absX, spawn.y - parent.absY, spawn.z - parent.absZ);
|
||||
}
|
||||
NPC npc;
|
||||
try {
|
||||
npc = DbManager.NPCQueries.ADD_NPC(npcWithoutID, isMob);
|
||||
npc.setObjectTypeMask(MBServerStatics.MASK_NPC);
|
||||
} catch (Exception e) {
|
||||
Logger.error( e);
|
||||
npc = null;
|
||||
}
|
||||
|
||||
|
||||
return npc;
|
||||
}
|
||||
|
||||
public static NPC getNPC(int id) {
|
||||
|
||||
if (id == 0)
|
||||
return null;
|
||||
NPC npc = (NPC) DbManager.getFromCache(GameObjectType.NPC, id);
|
||||
if (npc != null)
|
||||
return npc;
|
||||
|
||||
return DbManager.NPCQueries.GET_NPC(id);
|
||||
}
|
||||
|
||||
public ArrayList<Integer> getModTypeTable() {
|
||||
return this.modTypeTable;
|
||||
}
|
||||
@@ -1088,7 +1181,9 @@ public class NPC extends AbstractCharacter {
|
||||
ml.setDateToUpgrade(producedItem.getDateToUpgrade().getMillis());
|
||||
ml.containerType = Enum.ItemContainerType.FORGE;
|
||||
this.addItemToForge(ml);
|
||||
|
||||
} else {
|
||||
|
||||
if (producedItem.getPrefix() != null && !producedItem.getPrefix().isEmpty()) {
|
||||
ml.addPermanentEnchantment(producedItem.getPrefix(), 0, 0, true);
|
||||
ml.setPrefix(producedItem.getPrefix());
|
||||
@@ -1201,6 +1296,9 @@ public class NPC extends AbstractCharacter {
|
||||
return this.guild;
|
||||
}
|
||||
|
||||
// Method removes the npc from the game simulation
|
||||
// and deletes it from the database.
|
||||
|
||||
public ArrayList<Mob> getSiegeMinions() {
|
||||
return siegeMinions;
|
||||
}
|
||||
@@ -1251,13 +1349,6 @@ public class NPC extends AbstractCharacter {
|
||||
return siegeMinionMap;
|
||||
}
|
||||
|
||||
public void setSiegeMinionMap(ConcurrentHashMap<Mob, Integer> siegeMinionMap) {
|
||||
this.siegeMinionMap = siegeMinionMap;
|
||||
}
|
||||
|
||||
// Method removes the npc from the game simulation
|
||||
// and deletes it from the database.
|
||||
|
||||
public boolean remove() {
|
||||
|
||||
Building building;
|
||||
@@ -1309,10 +1400,6 @@ public class NPC extends AbstractCharacter {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static boolean ISGuardCaptain(int contractID){
|
||||
return MinionType.ContractToMinionMap.containsKey(contractID);
|
||||
}
|
||||
|
||||
public synchronized Item produceItem(int playerID, int amount, boolean isRandom, int pToken, int sToken, String customName, int itemID) {
|
||||
|
||||
Zone serverZone;
|
||||
@@ -1425,37 +1512,10 @@ public class NPC extends AbstractCharacter {
|
||||
return equipmentSetID;
|
||||
}
|
||||
|
||||
public static boolean UpdateEquipSetID(NPC npc, int equipSetID){
|
||||
|
||||
if (!NPCManager._bootySetMap.containsKey(equipSetID))
|
||||
return false;
|
||||
|
||||
if (!DbManager.NPCQueries.UPDATE_EQUIPSET(npc, equipSetID))
|
||||
return false;
|
||||
|
||||
npc.equipmentSetID = equipSetID;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean UpdateRaceID(NPC npc, int raceID){
|
||||
|
||||
if (!DbManager.NPCQueries.UPDATE_MOBBASE(npc, raceID))
|
||||
return false;
|
||||
|
||||
npc.loadID = raceID;
|
||||
npc.mobBase = MobBase.getMobBase(npc.loadID);
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getNameOverride() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static NPCProfits GetNPCProfits(NPC npc){
|
||||
return NPCProfits.ProfitCache.get(npc.currentID);
|
||||
}
|
||||
|
||||
public int getRepairCost() {
|
||||
return repairCost;
|
||||
}
|
||||
@@ -1529,84 +1589,4 @@ public class NPC extends AbstractCharacter {
|
||||
}
|
||||
}
|
||||
|
||||
public static void processRedeedNPC(NPC npc, Building building, ClientConnection origin) {
|
||||
|
||||
// Member variable declaration
|
||||
PlayerCharacter player;
|
||||
Contract contract;
|
||||
CharacterItemManager itemMan;
|
||||
ItemBase itemBase;
|
||||
Item item;
|
||||
|
||||
npc.lock.writeLock().lock();
|
||||
|
||||
try{
|
||||
|
||||
|
||||
if (building == null)
|
||||
return;
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
itemMan = player.getCharItemManager();
|
||||
|
||||
contract = npc.getContract();
|
||||
|
||||
if (!player.getCharItemManager().hasRoomInventory((short)1)){
|
||||
ErrorPopupMsg.sendErrorPopup(player, 21);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!building.getHirelings().containsKey(npc))
|
||||
return;
|
||||
|
||||
if (!npc.remove()) {
|
||||
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
|
||||
return;
|
||||
}
|
||||
|
||||
building.getHirelings().remove(npc);
|
||||
|
||||
itemBase = ItemBase.getItemBase(contract.getContractID());
|
||||
|
||||
if (itemBase == null) {
|
||||
Logger.error("Could not find Contract for npc: " + npc.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
boolean itemWorked = false;
|
||||
|
||||
item = new Item( itemBase, player.getObjectUUID(), OwnerType.PlayerCharacter, (byte) ((byte) npc.getRank() - 1), (byte) ((byte) npc.getRank() - 1),
|
||||
(short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0,
|
||||
new ArrayList<>(),"");
|
||||
item.setNumOfItems(1);
|
||||
item.containerType = Enum.ItemContainerType.INVENTORY;
|
||||
|
||||
try {
|
||||
item = DbManager.ItemQueries.ADD_ITEM(item);
|
||||
itemWorked = true;
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
if (itemWorked) {
|
||||
itemMan.addItemToInventory(item);
|
||||
itemMan.updateInventory();
|
||||
}
|
||||
|
||||
ManageCityAssetsMsg mca = new ManageCityAssetsMsg();
|
||||
mca.actionType = SVR_CLOSE_WINDOW;
|
||||
mca.setTargetType(building.getObjectType().ordinal());
|
||||
mca.setTargetID(building.getObjectUUID());
|
||||
origin.sendMsg(mca);
|
||||
|
||||
}catch(Exception e){
|
||||
Logger.error(e);
|
||||
}finally{
|
||||
npc.lock.writeLock().unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user