updated main and diolog for owner

This commit is contained in:
RebeccaNod1 2025-08-01 20:09:28 -05:00
parent 79be943fec
commit e7b853600a
2 changed files with 112 additions and 46 deletions

View file

@ -1,6 +1,12 @@
// === Main Peril Dice Controller (Refactored with Game Helpers Integration) === // === Main Peril Dice Controller (Refactored with Game Helpers Integration, with dynamic player join) ===
// --- Variables --- //
// This version of the main game controller includes support for players (including
// the owner) joining the game at runtime via a MSG_REGISTER_PLAYER message. When
// a new player registers, they are added to the internal lists (players, names,
// lives and picksData), a floating display is rezzed for them, and helpers are
// updated. This mirrors the behaviour used when adding a test player, but now
// applies to any avatar joining the game via the dialog handler.
integer syncChannel = -77777; integer syncChannel = -77777;
integer numberPickChannel = -77888; integer numberPickChannel = -77888;
@ -48,7 +54,8 @@ key currentPicker;
// Forward game state to helpers when it changes // Forward game state to helpers when it changes
updateHelpers() { updateHelpers() {
string serialized = llList2CSV(lives) + "~" + llList2CSV(picksData) + "~" + perilPlayer + "~" + llList2CSV(names); string serialized = llList2CSV(lives) + "~" + llList2CSV(picksData) +
"~" + perilPlayer + "~" + llList2CSV(names);
llMessageLinked(LINK_SET, MSG_SYNC_GAME_STATE, serialized, NULL_KEY); llMessageLinked(LINK_SET, MSG_SYNC_GAME_STATE, serialized, NULL_KEY);
llMessageLinked(LINK_SET, MSG_SYNC_PICKQUEUE, llList2CSV(pickQueue), NULL_KEY); llMessageLinked(LINK_SET, MSG_SYNC_PICKQUEUE, llList2CSV(pickQueue), NULL_KEY);
} }
@ -81,7 +88,7 @@ resetGame() {
pickQueue = []; pickQueue = [];
currentPickerIdx = 0; currentPickerIdx = 0;
llSay(syncChannel, "RESET"); llSay(syncChannel, "RESET");
llOwnerSay("🔄 Game reset!"); llOwnerSay(" Game reset!");
llSleep(0.2); llSleep(0.2);
llSetTimerEvent(0); llSetTimerEvent(0);
updateHelpers(); updateHelpers();
@ -89,21 +96,18 @@ resetGame() {
startNextRound() { startNextRound() {
if (llGetListLength(names) == 1) { if (llGetListLength(names) == 1) {
llSay(0, "🏆 " + llList2String(names, 0) + " is the last player standing and wins the game!"); llSay(0, " " + llList2String(names, 0) + " is the last player standing and wins the game!");
resetGame(); resetGame();
return; return;
} }
picksData = []; picksData = [];
globalPickedNumbers = []; globalPickedNumbers = [];
pickQueue = names; pickQueue = names;
currentPickerIdx = 0; currentPickerIdx = 0;
integer j; integer j;
for (j = 0; j < llGetListLength(names); j++) { for (j = 0; j < llGetListLength(names); j++) {
picksData += [llList2String(names, j) + "|"]; picksData += [llList2String(names, j) + "|"];
} }
updateHelpers(); updateHelpers();
// requestDiceType(); // Removed to avoid recursion loop // requestDiceType(); // Removed to avoid recursion loop
} }
@ -130,6 +134,8 @@ default {
key toucher = llDetectedKey(0); key toucher = llDetectedKey(0);
integer idx = llListFindList(players, [toucher]); integer idx = llListFindList(players, [toucher]);
if (toucher == llGetOwner()) { if (toucher == llGetOwner()) {
// Owner touches the prim: show menu for owner if already registered; else start as not starter
// Pass isStarter=0 because owner is never automatically starter until players join
llMessageLinked(LINK_SET, MSG_SHOW_MENU, "owner|0", toucher); llMessageLinked(LINK_SET, MSG_SHOW_MENU, "owner|0", toucher);
} else if (idx != -1) { } else if (idx != -1) {
integer isStarter = (idx == 0); integer isStarter = (idx == 0);
@ -138,6 +144,7 @@ default {
} }
link_message(integer sender, integer num, string str, key id) { link_message(integer sender, integer num, string str, key id) {
// Player list and pick list handling remain unchanged
if (num == 202 && str == "REQUEST_PLAYER_LIST") { if (num == 202 && str == "REQUEST_PLAYER_LIST") {
string namesCSV = llList2CSV(names); string namesCSV = llList2CSV(names);
llMessageLinked(LINK_SET, 203, namesCSV, id); llMessageLinked(LINK_SET, 203, namesCSV, id);
@ -166,24 +173,33 @@ default {
} }
return; return;
} }
// Handle dice type result from helper
if (num == MSG_DICE_TYPE_RESULT) { if (num == MSG_DICE_TYPE_RESULT) {
if (!roundStarted) { if (!roundStarted) {
roundStarted = TRUE; roundStarted = TRUE;
diceType = (integer)str; diceType = (integer)str;
llOwnerSay("🎲 Dice type set to: " + str); llOwnerSay(" Dice type set to: " + str);
showNextPickerDialog(); showNextPickerDialog();
} }
return;
} }
else if (num == MSG_GET_PICKS_REQUIRED) { if (num == MSG_GET_PICKS_REQUIRED) {
integer picksRequired = (integer)str; integer picksRequired = (integer)str;
llOwnerSay("📌 Picks required: " + str); llOwnerSay(" Picks required: " + str);
} else if (num == MSG_GET_PICKER_INDEX) { return;
}
if (num == MSG_GET_PICKER_INDEX) {
integer pickIndex = (integer)str; integer pickIndex = (integer)str;
llOwnerSay("🔍 Picker index: " + str); llOwnerSay(" Picker index: " + str);
} else if (num == MSG_SERIALIZE_GAME_STATE) { return;
}
if (num == MSG_SERIALIZE_GAME_STATE) {
string serialized = str; string serialized = str;
llOwnerSay("🧾 Serialized game state: " + serialized); llOwnerSay(" Serialized game state: " + serialized);
} else if (num == 204) { return;
}
// Handle pick actions
if (num == 204) {
list parts = llParseString2List(str, ["~"], []); list parts = llParseString2List(str, ["~"], []);
string action = llList2String(parts, 0); string action = llList2String(parts, 0);
list args = llParseString2List(llList2String(parts, 1), ["|"], []); list args = llParseString2List(llList2String(parts, 1), ["|"], []);
@ -216,25 +232,59 @@ default {
return; return;
} }
} }
return;
}
// New: handle dynamic registration of players (owner or players) via MSG_REGISTER_PLAYER
if (num == MSG_REGISTER_PLAYER) {
// str is in the format "Name|<key>"
list parts = llParseString2List(str, ["|"], []);
string newName = llList2String(parts, 0);
key newKey = (key)llList2String(parts, 1);
// Do not register if already present
integer existingIdx = llListFindList(players, [newKey]);
if (existingIdx == -1) {
// Add to local lists
players += [newKey];
names += [newName];
lives += [3];
picksData += [newName + "|"];
// Rez a float for the new player
llMessageLinked(LINK_SET, MSG_REZ_FLOAT, newName, newKey);
llSleep(0.2);
updateHelpers();
// Notify owner of registration
llOwnerSay("🔔 Added player: " + newName);
}
return;
} }
} }
listen(integer channel, string name, key id, string msg) { listen(integer channel, string name, key id, string msg) {
if (channel == DIALOG_CHANNEL) { if (channel == DIALOG_CHANNEL) {
// Owner-specific commands: only owner messages in the dialog should be processed here.
if (id == llGetOwner()) { if (id == llGetOwner()) {
if (msg == "Reset Game") { if (msg == "Reset Game") {
resetGame(); resetGame();
} else if (msg == "Start Game") { return;
}
if (msg == "Start Game") {
startNextRound(); startNextRound();
requestDiceType(); requestDiceType();
} else if (msg == "Dump Players") { return;
llOwnerSay("📋 Players: " + llList2CSV(names)); }
} else if (msg == "Manage Picks") { if (msg == "Dump Players") {
llOwnerSay("📋 Fetching list of players for pick management..."); llOwnerSay(" Players: " + llList2CSV(names));
return;
}
if (msg == "Manage Picks") {
llOwnerSay(" Fetching list of players for pick management...");
llMessageLinked(LINK_SET, 202, "REQUEST_PLAYER_LIST", llGetOwner()); llMessageLinked(LINK_SET, 202, "REQUEST_PLAYER_LIST", llGetOwner());
} else if (msg == "Add Test Player") { return;
}
if (msg == "Add Test Player") {
string name = "TestBot" + (string)llGetUnixTime(); string name = "TestBot" + (string)llGetUnixTime();
key fake = llGenerateKey(); key fake = llGenerateKey();
// Add the test player to lists and register them with floater manager
players += [fake]; players += [fake];
names += [name]; names += [name];
lives += [3]; lives += [3];
@ -244,11 +294,13 @@ default {
llSleep(0.2); llSleep(0.2);
updateHelpers(); updateHelpers();
llMessageLinked(LINK_SET, MSG_SHOW_MENU, "owner|0", llGetOwner()); llMessageLinked(LINK_SET, MSG_SHOW_MENU, "owner|0", llGetOwner());
return;
} }
} }
// If the message text matches a player name, request their pick list
if (llListFindList(names, [msg]) != -1) { if (llListFindList(names, [msg]) != -1) {
llMessageLinked(LINK_SET, 206, msg, id); llMessageLinked(LINK_SET, 206, msg, id);
} }
} }
} }
} }

View file

@ -1,4 +1,6 @@
// === Dialog Handler (Owner & Player) === // === Dialog Handler (Owner & Player) with unified Ready/Leave menu ===
// Owners and players share the same Ready/Leave dialog.
// Owners also get an "Owner" button to access advanced options.
integer DIALOG_CHANNEL = -88888; integer DIALOG_CHANNEL = -88888;
integer MSG_SHOW_MENU = 201; integer MSG_SHOW_MENU = 201;
@ -7,25 +9,36 @@ integer MSG_PLAYER_LIST_RESULT = 203;
integer MSG_PICK_LIST_RESULT = 205; integer MSG_PICK_LIST_RESULT = 205;
integer MSG_LIFE_LOOKUP = 207; integer MSG_LIFE_LOOKUP = 207;
// Owner-specific options shown when pressing the "Owner" button
list ownerOptions = ["Join Game", "Leave Game", "Add Test Player", "Manage Picks", "Start Game", "Reset Game", "Dump Players"]; list ownerOptions = ["Join Game", "Leave Game", "Add Test Player", "Manage Picks", "Start Game", "Reset Game", "Dump Players"];
list playerOptions = ["Start", "Ready"];
// Display the debug/owner menu
showOwnerMenu(key id) {
llDialog(id, "🔧 Owner Menu", ownerOptions, DIALOG_CHANNEL);
}
// Display the combined Ready/Leave menu for both players and owners
// If the caller is the starter, the first button is "Start"; otherwise "Ready".
// Owners receive an extra "Owner" button to access the advanced owner menu.
showReadyLeaveMenu(key id, integer isStarter, integer isOwner) {
list options;
if (isStarter) {
options = ["Start", "Leave Game"];
} else {
options = ["Ready", "Leave Game"];
}
if (isOwner) {
options += ["Owner"];
}
// Display the combined menu
llDialog(id, "Select an option:", options, DIALOG_CHANNEL);
}
// Manage picks UI helpers remain unchanged
list currentPickList; list currentPickList;
string currentPickTarget; string currentPickTarget;
integer currentPickLimit = 3; integer currentPickLimit = 3;
showOwnerMenu(key id) {
llDialog(id, "🔧 Debug Menu", ownerOptions, DIALOG_CHANNEL);
}
showPlayerMenu(key id, integer isStarter) {
if (isStarter) {
llDialog(id, "You are the game starter. Click Start to begin when all are ready.", playerOptions, DIALOG_CHANNEL);
} else {
llDialog(id, "Click Ready when you are ready to begin.", ["Ready"], DIALOG_CHANNEL);
}
}
showPickManageMenu(key id, list playerNames) { showPickManageMenu(key id, list playerNames) {
list options = []; list options = [];
integer i; integer i;
@ -69,13 +82,12 @@ default {
} }
string targetType = llList2String(args, 0); string targetType = llList2String(args, 0);
integer isStarter = (integer)llList2String(args, 1); integer isStarter = (integer)llList2String(args, 1);
// We treat owners and players the same for the Ready/Leave menu.
// If the targetType is "owner" we pass isOwner=TRUE and display the extra Owner button.
if (targetType == "owner") { if (targetType == "owner") {
llOwnerSay("👤 Showing owner menu"); showReadyLeaveMenu(id, isStarter, TRUE);
showOwnerMenu(id);
} else if (targetType == "player") { } else if (targetType == "player") {
llOwnerSay("👥 Showing player menu"); showReadyLeaveMenu(id, isStarter, FALSE);
showPlayerMenu(id, isStarter);
} }
} }
else if (num == MSG_PLAYER_LIST_RESULT) { else if (num == MSG_PLAYER_LIST_RESULT) {
@ -105,7 +117,11 @@ default {
} }
listen(integer channel, string name, key id, string msg) { listen(integer channel, string name, key id, string msg) {
if (msg == "Manage Picks") { // Handle menus: if the user selects "Owner" on the combined menu, display the owner options.
if (msg == "Owner") {
showOwnerMenu(id);
}
else if (msg == "Manage Picks") {
llMessageLinked(LINK_THIS, 202, "REQUEST_PLAYER_LIST", id); llMessageLinked(LINK_THIS, 202, "REQUEST_PLAYER_LIST", id);
} }
else if (llSubStringIndex(msg, "🛠 ") == 0) { else if (llSubStringIndex(msg, "🛠 ") == 0) {
@ -127,19 +143,18 @@ default {
llSleep(0.2); llSleep(0.2);
llMessageLinked(LINK_THIS, 206, currentPickTarget, id); llMessageLinked(LINK_THIS, 206, currentPickTarget, id);
} }
// Forward numeric picks to the game logic
else if ((integer)msg > 0) { else if ((integer)msg > 0) {
if (llGetListLength(currentPickList) >= currentPickLimit) { if (llGetListLength(currentPickList) >= currentPickLimit) {
llOwnerSay("⚠️ Reached pick limit of " + (string)currentPickLimit + " for " + currentPickTarget); llOwnerSay("⚠️ Reached pick limit of " + (string)currentPickLimit + " for " + currentPickTarget);
showPickListMenu(id); showPickListMenu(id);
return; return;
} }
if (llListFindList(currentPickList, [msg]) != -1) { if (llListFindList(currentPickList, [msg]) != -1) {
llOwnerSay("⚠️ Pick already exists: " + msg); llOwnerSay("⚠️ Pick already exists: " + msg);
showPickListMenu(id); showPickListMenu(id);
return; return;
} }
integer i; integer i;
for (i = 0; i < llGetListLength(currentPickList); i++) { for (i = 0; i < llGetListLength(currentPickList); i++) {
if (llList2String(currentPickList, i) == msg) { if (llList2String(currentPickList, i) == msg) {
@ -147,7 +162,6 @@ default {
return; return;
} }
} }
string payload = "ADD_PICK~" + currentPickTarget + "|" + msg; string payload = "ADD_PICK~" + currentPickTarget + "|" + msg;
llMessageLinked(LINK_THIS, MSG_PICK_ACTION, payload, id); llMessageLinked(LINK_THIS, MSG_PICK_ACTION, payload, id);
llSleep(0.2); llSleep(0.2);