|
@@ -15,7 +15,6 @@ module.exports = function boxOpener(dispatch){
|
|
|
statUsed = 0,
|
|
statUsed = 0,
|
|
|
statStarted = null,
|
|
statStarted = null,
|
|
|
scanning = false,
|
|
scanning = false,
|
|
|
- boxId = 166901, // MWA box as default.
|
|
|
|
|
inventory = null;
|
|
inventory = null;
|
|
|
|
|
|
|
|
command.add('box', () => {
|
|
command.add('box', () => {
|
|
@@ -52,9 +51,17 @@ module.exports = function boxOpener(dispatch){
|
|
|
|
|
|
|
|
dispatch.hook('C_PLAYER_LOCATION', 5, event =>{location = event});
|
|
dispatch.hook('C_PLAYER_LOCATION', 5, event =>{location = event});
|
|
|
|
|
|
|
|
|
|
+ dispatch.game.initialize("inventory");
|
|
|
|
|
+
|
|
|
|
|
+ dispatch.game.inventory.on('update', () => {
|
|
|
|
|
+ if(!enabled) return;
|
|
|
|
|
+
|
|
|
|
|
+ isLooting = false; // event comes only after all S_SYSTEM_MESSAGE_LOOT_ITEM (probably)
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
function load()
|
|
function load()
|
|
|
{
|
|
{
|
|
|
- hook('S_INVEN', 18, event =>{
|
|
|
|
|
|
|
+ /*hook('S_INVEN', 18, event =>{ // pre patch 85
|
|
|
if(!enabled) return
|
|
if(!enabled) return
|
|
|
|
|
|
|
|
isLooting = false; // S_INVEN comes only after all S_SYSTEM_MESSAGE_LOOT_ITEM
|
|
isLooting = false; // S_INVEN comes only after all S_SYSTEM_MESSAGE_LOOT_ITEM
|
|
@@ -84,7 +91,7 @@ module.exports = function boxOpener(dispatch){
|
|
|
inventory = [];
|
|
inventory = [];
|
|
|
inventory = null
|
|
inventory = null
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
|
|
+ });*/
|
|
|
|
|
|
|
|
hook('C_USE_ITEM', 3, event =>{
|
|
hook('C_USE_ITEM', 3, event =>{
|
|
|
if(!scanning) return
|
|
if(!scanning) return
|
|
@@ -92,14 +99,14 @@ module.exports = function boxOpener(dispatch){
|
|
|
if(scanning){
|
|
if(scanning){
|
|
|
boxEvent = event;
|
|
boxEvent = event;
|
|
|
boxEvent.dbid = 0n; // to open all inv slots
|
|
boxEvent.dbid = 0n; // to open all inv slots
|
|
|
- boxId = event.id;
|
|
|
|
|
- command.message("Box set to: "+boxId+", proceeding to auto-open it with " + (useDelay ? "a minimum " + (delay / 1000) + " sec delay" : "no delay" ));
|
|
|
|
|
|
|
+ command.message("Box set to: "+event.id+", proceeding to auto-open it with " + (useDelay ? "a minimum " + (delay / 1000) + " sec delay" : "no delay" ));
|
|
|
scanning = false;
|
|
scanning = false;
|
|
|
|
|
|
|
|
let d = new Date();
|
|
let d = new Date();
|
|
|
statStarted = d.getTime();
|
|
statStarted = d.getTime();
|
|
|
enabled = true;
|
|
enabled = true;
|
|
|
timer = setTimeout(openBox,delay);
|
|
timer = setTimeout(openBox,delay);
|
|
|
|
|
+ return true; // for consistency of sent data
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -148,14 +155,22 @@ module.exports = function boxOpener(dispatch){
|
|
|
|
|
|
|
|
function openBox()
|
|
function openBox()
|
|
|
{
|
|
{
|
|
|
- boxEvent.loc = location.loc;
|
|
|
|
|
- boxEvent.w = location.w;
|
|
|
|
|
- dispatch.toServer('C_USE_ITEM', 3, boxEvent);
|
|
|
|
|
- if(useDelay)
|
|
|
|
|
|
|
+ if(dispatch.game.inventory.getTotalAmount(boxEvent.id) > 0)
|
|
|
{
|
|
{
|
|
|
- statUsed++; // counter for used items other than boxes
|
|
|
|
|
|
|
+ boxEvent.loc = location.loc;
|
|
|
|
|
+ boxEvent.w = location.w;
|
|
|
|
|
+ dispatch.toServer('C_USE_ITEM', 3, boxEvent);
|
|
|
|
|
+ if(useDelay)
|
|
|
|
|
+ {
|
|
|
|
|
+ statUsed++; // counter for used items other than boxes
|
|
|
|
|
+ }
|
|
|
|
|
+ timer = setTimeout(openBox,delay);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ command.message("You ran out of boxes, stopping");
|
|
|
|
|
+ stop();
|
|
|
}
|
|
}
|
|
|
- timer = setTimeout(openBox,delay);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function addZero(i)
|
|
function addZero(i)
|