mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-21 11:18:08 +00:00
Added unlocking funcitonality when scanner is in the inventory
This commit is contained in:
@@ -37,7 +37,6 @@
|
||||
"takeable": true,
|
||||
"locked": true,
|
||||
"lockType": "bluetooth",
|
||||
"requires": "00:11:22:33:44:55",
|
||||
"mac": "00:11:22:33:44:55",
|
||||
"observations": "A locked tablet device that requires Bluetooth pairing"
|
||||
},
|
||||
|
||||
100
index.html
100
index.html
@@ -222,8 +222,9 @@
|
||||
this.load.image('safe', 'assets/objects/safe.png');
|
||||
this.load.image('book', 'assets/objects/book.png');
|
||||
this.load.image('workstation', 'assets/objects/workstation.png');
|
||||
this.load.image('tablet', 'assets/objects/tablet.png');
|
||||
this.load.image('bluetooth_scanner', 'assets/objects/bluetooth_scanner.png');
|
||||
this.load.image('tablet', 'assets/objects/tablet.png');
|
||||
|
||||
|
||||
this.load.json('gameScenarioJSON', 'assets/scenarios/ceo_exfil.json');
|
||||
gameScenario = this.cache.json.get('gameScenarioJSON');
|
||||
@@ -1405,22 +1406,10 @@
|
||||
}
|
||||
|
||||
const data = sprite.scenarioData;
|
||||
let message = `${data.name}\n\n`;
|
||||
message += `Observations: ${data.observations}\n\n`;
|
||||
|
||||
// Check for locked state in scenarioData
|
||||
if (data.locked === true) {
|
||||
console.log('Item is locked:', data);
|
||||
handleUnlock(sprite, 'item');
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.readable && data.text) {
|
||||
message += `Text: ${data.text}\n\n`;
|
||||
}
|
||||
|
||||
if (data.contents && data.contents.length > 0) {
|
||||
message += `You found the following items:\n`;
|
||||
// Check if this is an unlocked container that hasn't been collected yet
|
||||
if (data.isUnlockedButNotCollected && data.contents) {
|
||||
let message = `You found the following items:\n`;
|
||||
data.contents.forEach(item => {
|
||||
message += `- ${item.name}\n`;
|
||||
});
|
||||
@@ -1436,12 +1425,27 @@
|
||||
addToInventory(contentSprite);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Clear contents after adding to inventory
|
||||
data.contents = [];
|
||||
data.isUnlockedButNotCollected = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for locked state in scenarioData
|
||||
if (data.locked === true) {
|
||||
console.log('Item is locked:', data);
|
||||
handleUnlock(sprite, 'item');
|
||||
return;
|
||||
}
|
||||
|
||||
let message = `${data.name}\n\n`;
|
||||
message += `Observations: ${data.observations}\n\n`;
|
||||
|
||||
if (data.readable && data.text) {
|
||||
message += `Text: ${data.text}\n\n`;
|
||||
}
|
||||
|
||||
if (data.takeable) {
|
||||
message += `This item can be taken\n\n`;
|
||||
|
||||
@@ -1833,12 +1837,60 @@
|
||||
}
|
||||
break;
|
||||
|
||||
case 'bluetooth':
|
||||
const requiredMac = lockRequirements.requires;
|
||||
// Find the scanner in inventory
|
||||
const scanner = inventory.items.find(item =>
|
||||
item.scenarioData?.type === "bluetooth_scanner"
|
||||
);
|
||||
|
||||
console.log('Bluetooth unlock attempt:', {
|
||||
itemName: lockable.scenarioData?.name,
|
||||
itemMac: lockable.scenarioData?.mac,
|
||||
hasScanner: !!scanner
|
||||
});
|
||||
|
||||
if (!scanner) {
|
||||
alert("You need a Bluetooth scanner to unlock this device.");
|
||||
// Don't return here - allow the item to be picked up even without scanner
|
||||
if (type === 'item' && lockable.scenarioData?.takeable) {
|
||||
addToInventory(lockable);
|
||||
// Remove from room objects if it exists there
|
||||
if (currentRoom && rooms[currentRoom].objects) {
|
||||
delete rooms[currentRoom].objects[lockable.name];
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If scanner is in inventory, automatically unlock the device
|
||||
if (inventory.items.includes(scanner)) {
|
||||
console.log('Bluetooth unlock success: Scanner in inventory', {
|
||||
itemName: lockable.scenarioData?.name,
|
||||
itemMac: lockable.scenarioData?.mac
|
||||
});
|
||||
unlockTarget(lockable, type, lockable.layer);
|
||||
alert(`Using Bluetooth scanner from inventory to unlock device.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const devices = getBluetoothDevicesInRange({ x: scanner.x, y: scanner.y });
|
||||
const matchingDevice = devices.find(d => d.mac === requiredMac && d.signalStrength >= BLUETOOTH_MIN_SIGNAL);
|
||||
|
||||
if (matchingDevice) {
|
||||
unlockTarget(lockable, type, lockable.layer);
|
||||
alert(`Bluetooth connection established with ${matchingDevice.name}. Device unlocked.`);
|
||||
} else {
|
||||
alert("No compatible Bluetooth device in range or signal too weak.");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
alert(`Requires: ${lockRequirements.requires}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Generic unlock function
|
||||
// Modify the unlockTarget function
|
||||
function unlockTarget(lockable, type, layer) {
|
||||
if (type === 'door') {
|
||||
if (!layer) {
|
||||
@@ -1853,23 +1905,15 @@
|
||||
// Set new state for containers with contents
|
||||
if (lockable.scenarioData.contents) {
|
||||
lockable.scenarioData.isUnlockedButNotCollected = true;
|
||||
return; // Return early to prevent automatic collection
|
||||
}
|
||||
} else {
|
||||
lockable.locked = false;
|
||||
if (lockable.contents) {
|
||||
lockable.isUnlockedButNotCollected = true;
|
||||
return; // Return early to prevent automatic collection
|
||||
}
|
||||
}
|
||||
|
||||
// If the item has contents, make them accessible
|
||||
if (lockable.scenarioData?.contents) {
|
||||
lockable.scenarioData.contents.forEach(item => {
|
||||
const sprite = createInventorySprite(item);
|
||||
if (sprite) {
|
||||
addToInventory(sprite);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2080
indexbt.html
Normal file
2080
indexbt.html
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user