mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
Move items to whatever controller the player ends up with
Syncing the controller required syncing the inventories, and with the controller off a god or ghost kept its local items while the stored character was left alone. Cooldude pointed out there is no reason the items can't follow the player to a different controller. The controller and inventories components are now independent. The god inventory and the hidden ghost inventory belong to the inventories component. On download the scenario first settles the controller, synced or local, and then places the stored items into whatever that controller holds. An inventory goes slot for slot into the inventory of the same name when it fits, otherwise its items are inserted into the main, guns, ammo and armor inventories, and anything left goes into a corpse below the player. A spectator holds nothing, so everything goes into the corpse. A player without a character gets the crafting queue ingredients as items. This removes the early respawn of a ghost with a stored character and the upload of the respawned character, a ghost now gets and uploads its hidden inventory. Download spectates every synced player when the inventories are synced, as a god or ghost now holds synced items too. The controller keeps the stored logistic requests when the upload came from a player with nowhere to hold them. Slot filters are dropped when the destination does not support them, such as a script inventory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f3d67ed7d9
commit
aa06b9afe3
5 files changed
+256
-100
No files matched your search
@@ -51,9 +51,9 @@ describe("player_sync components", function() {
|
||||
assert.equal(enabled.has("quick_bar"), false);
|
||||
assert.equal(enabled.size, allComponents.length - 2);
|
||||
});
|
||||
it("should not sync the controller without the inventories", function() {
|
||||
it("should sync the controller without the inventories", function() {
|
||||
const enabled = enabledComponents(configWith(["inventories"]));
|
||||
assert.equal(enabled.has("controller"), false);
|
||||
assert.equal(enabled.has("controller"), true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,12 +71,11 @@ describe("player_sync components", function() {
|
||||
}
|
||||
assert.equal(playerData.force, "enemy");
|
||||
});
|
||||
it("should remove the god inventory with the controller", function() {
|
||||
it("should remove the god inventory with the inventories", function() {
|
||||
const playerData = structuredClone(stored);
|
||||
stripPlayerData(playerData, new Set(allComponents.filter(c => c !== "controller")));
|
||||
stripPlayerData(playerData, new Set(allComponents.filter(c => c !== "inventories")));
|
||||
assert.equal("inventories" in playerData, false);
|
||||
assert.equal("controller" in playerData, false);
|
||||
assert.equal(playerData.tag, "stored");
|
||||
assert.equal(playerData.controller, "god");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -91,8 +90,8 @@ describe("player_sync components", function() {
|
||||
it("should sync nothing for an empty table encoded as an array", function() {
|
||||
assert.equal(uploadedComponents([]).size, 0);
|
||||
});
|
||||
it("should not sync the controller without the inventories", function() {
|
||||
assert.equal(uploadedComponents({ controller: true }).has("controller"), false);
|
||||
it("should sync the controller without the inventories", function() {
|
||||
assert.deepEqual([...uploadedComponents({ controller: true })], ["controller"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -121,26 +120,33 @@ describe("player_sync components", function() {
|
||||
assert.equal("force" in merged, false);
|
||||
assert.equal(merged.tag, "uploaded");
|
||||
});
|
||||
it("should take the character but not the controller when the controller is not synced", function() {
|
||||
it("should take the items but not the controller when the controller is not synced", function() {
|
||||
const merged = mergePlayerData(stored, withComponents(uploaded, ["controller"]));
|
||||
assert.equal(merged.controller, "god");
|
||||
assert.equal(merged.cheat_mode, true);
|
||||
assert.equal(merged.character, character);
|
||||
assert.deepEqual(merged.inventories, { main: ["stored god item"] }, "god inventory is kept");
|
||||
assert.equal("inventories" in merged, false, "the god inventory moved to the character");
|
||||
});
|
||||
it("should keep the character data for a player without one when the controller is not synced", function() {
|
||||
it("should take the items of a player without a character", function() {
|
||||
const storedCharacter = {
|
||||
...stored, character, crafting_queue: ["stored"], personal_logistic_slots: [{ name: "stored" }],
|
||||
};
|
||||
const god = { ...uploaded, controller: "god", inventories: { main: ["new god item"] } };
|
||||
delete god.character;
|
||||
delete god.crafting_queue;
|
||||
god.personal_logistic_slots = [{ name: "uploaded" }];
|
||||
delete god.personal_logistic_slots;
|
||||
const merged = mergePlayerData(storedCharacter, withComponents(god, ["controller"]));
|
||||
assert.equal(merged.character, character);
|
||||
assert.deepEqual(merged.crafting_queue, ["stored"]);
|
||||
assert.deepEqual(merged.personal_logistic_slots, [{ name: "stored" }], "logistics stay with the character");
|
||||
assert.deepEqual(merged.inventories, { main: ["stored god item"] });
|
||||
assert.equal("character" in merged, false);
|
||||
assert.equal("crafting_queue" in merged, false);
|
||||
assert.deepEqual(merged.inventories, { main: ["new god item"] });
|
||||
assert.deepEqual(merged.personal_logistic_slots, [{ name: "stored" }], "nowhere to hold logistics");
|
||||
});
|
||||
it("should drop logistic requests a character uploaded without", function() {
|
||||
const storedSlots = { ...stored, personal_logistic_slots: [{ name: "stored" }] };
|
||||
const noSlots = { ...uploaded };
|
||||
delete noSlots.personal_logistic_slots;
|
||||
const merged = mergePlayerData(storedSlots, withComponents(noSlots, []));
|
||||
assert.equal("personal_logistic_slots" in merged, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user