Initial commit
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
const PropertyChangedPacket = require("../Packets/PropertyChanged");
|
||||
const EquipmentConfirmationPacket = require("../Packets/EquipmentConfirmation");
|
||||
|
||||
module.exports = function (ws, message, player) {
|
||||
let packet = null;
|
||||
|
||||
if (player.isAttacking()) {
|
||||
packet = EquipmentConfirmationPacket(false);
|
||||
player.map.registerIndividualNetworkPacket(player.id, packet);
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
const equimpentTypeID = message.getUint8(2);
|
||||
const id = message.getUint8(3);
|
||||
|
||||
const equimpents = equimpentTypeID === 1 ? player.inventory.getCannons() : player.inventory.getHarpooners();
|
||||
const equimpent = equimpents.find(e => e.id === id);
|
||||
if (!equimpent) return
|
||||
|
||||
const playerID = player.id;
|
||||
const currentRange = equimpentTypeID === 1 ? player.maximumCannonRange : player.maximumHarpoonerRange;
|
||||
const typeID = equimpentTypeID === 1 ? 3 : 4;
|
||||
|
||||
const type = message.getUint8(1);
|
||||
const quantity = message.getUint8(4);
|
||||
|
||||
let propertyChangedPacket = null;
|
||||
let maximumRange = 0;
|
||||
|
||||
if (type) {
|
||||
if (!equimpent.amountEquipped && equimpent.range > currentRange) {
|
||||
propertyChangedPacket = PropertyChangedPacket({
|
||||
playerID,
|
||||
typeID,
|
||||
value: equimpent.range
|
||||
});
|
||||
|
||||
maximumRange = equimpent.range;
|
||||
};
|
||||
|
||||
const isEquipmentAlterSuccessful = equimpent.equip(quantity);
|
||||
|
||||
packet = EquipmentConfirmationPacket(isEquipmentAlterSuccessful);
|
||||
} else {
|
||||
const isEquipmentAlterSuccessful = equimpent.unequip(quantity);
|
||||
|
||||
if (!equimpent.amountEquipped) {
|
||||
for (let i = 0, length = equimpents.length; i < length; i++)
|
||||
if (equimpents[i].range > maximumRange && equimpents[i].amountEquipped) maximumRange = equimpents[i].range;
|
||||
|
||||
if (currentRange > maximumRange)
|
||||
propertyChangedPacket = PropertyChangedPacket({
|
||||
playerID,
|
||||
typeID,
|
||||
value: maximumRange
|
||||
});
|
||||
};
|
||||
|
||||
packet = EquipmentConfirmationPacket(isEquipmentAlterSuccessful);
|
||||
};
|
||||
|
||||
if (propertyChangedPacket) {
|
||||
if (equimpentTypeID === 1) player.maximumCannonRange = maximumRange;
|
||||
else player.maximumHarpoonerRange = maximumRange;
|
||||
|
||||
player.map.registerNetworkPacket(player.id, propertyChangedPacket);
|
||||
};
|
||||
|
||||
player.map.registerIndividualNetworkPacket(player.id, packet);
|
||||
|
||||
const metadata = [player.hp.current / player.hp.maximum, equimpentTypeID, 0, quantity];
|
||||
|
||||
return metadata;
|
||||
};
|
||||
Reference in New Issue
Block a user