From e2327132d895ce88350e77e4d2d00e487e81b398 Mon Sep 17 00:00:00 2001 From: Tara Date: Sun, 25 Dec 2022 12:35:29 -0700 Subject: [PATCH] Implement more of the game! --- SOURCE/LSL/.ext-dependency | 1 + SOURCE/LSL/CAH.lsl | 374 +++++++++++++++++++++++++++++++++++++ SOURCE/LSL/Card.lsl | 68 +++++++ SOURCE/LSL/HUD.lsl | 321 +++++++++++++++++++++++++++++++ 4 files changed, 764 insertions(+) create mode 100644 SOURCE/LSL/.ext-dependency create mode 100644 SOURCE/LSL/CAH.lsl create mode 100644 SOURCE/LSL/Card.lsl create mode 100644 SOURCE/LSL/HUD.lsl diff --git a/SOURCE/LSL/.ext-dependency b/SOURCE/LSL/.ext-dependency new file mode 100644 index 0000000..d531337 --- /dev/null +++ b/SOURCE/LSL/.ext-dependency @@ -0,0 +1 @@ +FURWARE TEXT \ No newline at end of file diff --git a/SOURCE/LSL/CAH.lsl b/SOURCE/LSL/CAH.lsl new file mode 100644 index 0000000..1cdecc0 --- /dev/null +++ b/SOURCE/LSL/CAH.lsl @@ -0,0 +1,374 @@ + +integer ingredient_channel = -8392888; +integer containerChannel = -8392891; +integer updater_channel = 15418070; +integer card_channel = -32988199; +integer hud_channel = -328478727; + +string g_sVersion = "1.0.0.0000"; +key g_kToken; +integer DEBUG = FALSE; +list g_lReqs; +string URL = "https://api.zontreck.dev/ls_bionics"; +Send(string Req,string method){ + g_lReqs += [Req,method]; + Sends(); +} +Sends(){ + if(g_kCurrentReq == NULL_KEY){ + DoNextRequest(); + } + //g_lReqs += [llHTTPRequest(URL + llList2String(lTmp,0), [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], llDumpList2String(llList2List(lTmp,1,-1), "?"))]; +} + +integer g_iCzar; +key g_kCurrentReq = NULL_KEY; +DoNextRequest(){ + if(llGetListLength(g_lReqs)==0)return; + list lTmp = llParseString2List(llList2String(g_lReqs,0),["?"],[]); + if(DEBUG)llSay(0, "SENDING REQUEST: "+URL+llList2String(g_lReqs,0)); + + string append = ""; + if(llList2String(g_lReqs,1) == "GET")append = "?"+llDumpList2String(llList2List(lTmp,1,-1),"?"); + + g_kCurrentReq = llHTTPRequest(URL + llList2String(lTmp,0) + append, [HTTP_METHOD, llList2String(g_lReqs,1), HTTP_MIMETYPE, "application/x-www-form-urlencoded"], llDumpList2String(llList2List(lTmp,1,-1),"?")); +} + + +integer Dice(integer NTimes, integer Max, integer Test1, integer Test2){ + integer i=0; + integer LTotal=0; + for(i=0;i Test1&&Mean < Test2)return TRUE; + else return FALSE; +} + +list g_lListener; +list g_lPending; +REZ(key i){ + if(g_iBlockRez)return; + integer chan = llRound(llFrand(548937)); + + llRezObject("Cards Against Humanity HUD [LS]", llGetPos(), ZERO_VECTOR, ZERO_ROTATION, chan); + + g_lPending += [i, chan]; + + integer rnd = llRound(llFrand(5843758)); + g_lListener += [i,rnd,llListen(rnd,"",i,"")]; + llDialog(i, "Are you male or female?", ["Female", "Male"], rnd); + + llRequestPermissions(i, PERMISSION_TRIGGER_ANIMATION); +} + +Rescan(){ + list OldPlayers = Players; + + Players=[]; + integer i=0; + integer end = llGetNumberOfPrims(); + integer ChairNumber = 0; + //llSay(0, "Simulating player count"); + list ToEvict = []; + for(i=0;i<=end;i++){ + vector Scale = llGetAgentSize(llGetLinkKey(i)); + if(Scale != ZERO_VECTOR){ + // This is an avatar + integer Chair = llList2Integer(Chairs,ChairNumber); + if(ChairNumber > llGetListLength(Chairs)) ToEvict += [llGetLinkKey(i)]; + ChairNumber++; + //llSay(0, "Discover: Avatar ID : secondlife:///app/agent/"+(string)llGetLinkKey(i)+"/about"); + list ChairParams = llGetLinkPrimitiveParams(Chair, [PRIM_POS_LOCAL, PRIM_DESC]); + list ChairData = llParseString2List(llList2String(ChairParams,1), ["`"],[]); + Players += llGetLinkKey(i); + if(llListFindList(OldPlayers, [llGetLinkKey(i)])==-1){ + llWhisper(0, "secondlife:///app/agent/"+(string)llGetLinkKey(i)+"/about has joined the game!"); + llInstantMessage(llGetLinkKey(i), "Rezzing a HUD. Please accept attachment permissions"); + REZ(llGetLinkKey(i)); + } + llSetLinkPrimitiveParams(i, [PRIM_POS_LOCAL, llList2Vector(ChairParams,0)+<0,0,1>+(vector)llList2String(ChairData,1), PRIM_ROT_LOCAL, llEuler2Rot((vector)llList2String(ChairData,0)*DEG_TO_RAD)]); + } + } + + Compare(OldPlayers); + Evict(ToEvict); + + if(llGetListLength(Players)==0 && llGetListLength(OldPlayers)!=0){ + llSay(0, "All players left the game. Resetting game and shuffling cards!"); + llResetScript(); + } +} +list Chairs=[]; +list Players; + +Compare(list OldList){ + // Check for who has left the game, then deactivate their HUD + integer i=0; + integer end = llGetListLength(OldList); + for(i=0;i= llGetListLength(Players)){ + g_iCzar = 0; + } + } + + key czar = llList2String(Players,g_iCzar); + llRegionSay(hud_channel, llList2Json(JSON_OBJECT, ["type", "select", "czar", czar, "sel_count", num_req])); + } + llRegionSayTo(Sender, card_channel, llList2Json(JSON_OBJECT, ["type", "set", "card", llList2Json(JSON_OBJECT, ["text", card_text, "color", color, "num", num_req])])); + } + } + } + + + Sends(); + } + } + + listen(integer c,string n,key i, string m){ + if(DEBUG){ + llSay(0, "LISTEN: "+llDumpList2String([c,n,i,m], " - ")); + } + if(c==hud_channel){ + if(llJsonGetValue(m,["type"])=="card_request"){ + integer card_count = (integer)llJsonGetValue(m,["count"]); + Send("/Modify_Card.php?TYPE_OVERRIDE=GET_CARD&TABLE_ID="+(string)g_kID+"&COLOR=0&DRAW_COUNT="+(string)card_count+"&SENDER="+(string)i+"&REZZED=0", "POST"); + } else if(llJsonGetValue(m,["type"])=="alive"){ + integer index = llListFindList(g_lPending,[(integer)llJsonGetValue(m,["boot"])]); + if(index==-1)return; + else { + // Boot the HUD + if(DEBUG)llSay(0, "Sending HUD Activation signal"); + index--; + + + llRegionSayTo(i,llList2Integer(g_lPending,index+1), llList2Json(JSON_OBJECT, ["type", "activate", "user", llList2String(g_lPending,index), "table", g_kID])); + g_lPending = llDeleteSubList(g_lPending, index,index+1); + } + } + } else if(c==card_channel){ + if(llJsonGetValue(m,["type"])=="alive"){ + llSay(0, "IN ALIVE BLOCK"); + integer index = llListFindList(g_lPendingCards,[(integer)llJsonGetValue(m,["boot"])]); + if(index==-1){ + return; + } + + + g_lPendingCards = llDeleteSubList(g_lPendingCards,index,index+1); + + llRegionSayTo(i, (integer)llJsonGetValue(m,["boot"]), llList2Json(JSON_OBJECT, ["type", "activate", "table", g_kID])); + // Calculate position offset + llSleep(1); + llRegionSayTo(i, card_channel, llList2Json(JSON_OBJECT, ["type", "position", "pos", llGetPos()+<0,0,0.5>])); + if(DEBUG)llSay(0, "Alive request on the Cards Channel: "+m); + Send("/Modify_Card.php?TYPE_OVERRIDE=GET_CARD&TABLE_ID="+(string)g_kID+"&COLOR=1&DRAW_COUNT=1&SENDER="+(string)i+"&REZZED=1", "POST"); + + } + } else if(llListFindList(g_lListener,[c])!=-1){ + integer index = llListFindList(g_lListener,[c]); + index--; + if(m == "Female"){ + llStartAnimation("female"); + } else { + llStartAnimation("male"); + } + + llListenRemove(llList2Integer(g_lListener,index+2)); + g_lListener=llDeleteSubList(g_lListener,index,index+2); + + } + } + + changed(integer t){ + if(t&CHANGED_REGION_START){ + llResetScript(); + } else if(t&CHANGED_LINK){ + Rescan(); + } + } + + on_rez(integer t){ + llResetScript(); + } + + touch_start(integer t){ + string name = llGetLinkName(llDetectedLinkNumber(0)); + if(name == "START"){ + + if(!(llGetListLength(Players) > 1)){ + llSay(0, "Must have more than 1 player to start!"); + } + // Begin the game loop + integer chan = llRound(llFrand(548378)); + g_lPendingCards += [chan, "null|black"]; + llRezObject("Playing Card [LS]", llGetPos(), ZERO_VECTOR, ZERO_ROTATION, chan); + } + } +} \ No newline at end of file diff --git a/SOURCE/LSL/Card.lsl b/SOURCE/LSL/Card.lsl new file mode 100644 index 0000000..a3a06e7 --- /dev/null +++ b/SOURCE/LSL/Card.lsl @@ -0,0 +1,68 @@ + +integer card_channel = -32988199; + +integer g_iStart; +key g_kTable; + +default +{ + state_entry() + { + llMessageLinked(LINK_SET,0,"","fw_reset"); + llSetLinkColor(LINK_ROOT, <1,1,1>,1); + llSetLinkColor(LINK_ROOT, <1,1,1>,0); + llWhisper(0, "You must not rez this card by itself!"); + } + + on_rez(integer t){ + if(t==0){ + llResetScript(); + }else{ + llSay(0, "Card is trying to find a table"); + llListen(t, "", "", ""); + g_iStart=t; + llSay(card_channel, llList2Json(JSON_OBJECT, ["type", "alive", "boot", t])); + } + } + + listen(integer c,string n,key i,string m){ + if(c == g_iStart){ + if(llJsonGetValue(m, ["type"]) == "activate"){ + llListen(card_channel, "", i, ""); + llMessageLinked(LINK_SET,0,"","fw_reset"); + g_kTable = (key)llJsonGetValue(m,["table"]); + } + } else if(c == card_channel){ + if(llJsonGetValue(m,["type"]) == "position"){ + llSetPos((vector)llJsonGetValue(m,["pos"])); + } else if(llJsonGetValue(m,["type"]) == "rotation"){ + llSetRot((rotation)llJsonGetValue(m,["rot"])); + } else if(llJsonGetValue(m,["type"]) == "set"){ + string text = llJsonGetValue(m,["card", "text"]); + integer color = (integer)llJsonGetValue(m,["card","color"]); + integer num = (integer)llJsonGetValue(m,["card", "num"]); + if(color){ + // black + llSetLinkColor(LINK_ROOT, <0.2,0.2,0.2>, 1); + llSetLinkColor(LINK_ROOT, <0.2,0.2,0.2>, 0); + + llMessageLinked(LINK_SET, 0, "c=white", "fw_conf"); + }else { + llSetLinkColor(LINK_ROOT, <1,1,1>,1); + llSetLinkColor(LINK_ROOT, <1,1,1>,0); + llMessageLinked(LINK_SET,0,"c=black", "fw_conf"); + } + + llMessageLinked(LINK_SET,0,text, "fw_data : card_text"); + + if(num > 1){ + llMessageLinked(LINK_SET,0,"Pick ("+(string)num+")\nDraw ("+(string)num+")", "fw_data : card_helpertext"); + } else { + llMessageLinked(LINK_SET,0,"Cards Against Humanity", "fw_data : card_helpertext"); + } + } else if(llJsonGetValue(m, ["type"]) == "die"){ + llDie(); + } + } + } +} diff --git a/SOURCE/LSL/HUD.lsl b/SOURCE/LSL/HUD.lsl new file mode 100644 index 0000000..8bbf93d --- /dev/null +++ b/SOURCE/LSL/HUD.lsl @@ -0,0 +1,321 @@ +integer g_iStartParam; +key g_kUser; +key g_kTable; + +integer card_channel = -32988199; +integer hud_channel = -328478727; + + +s(string m){ + llInstantMessage(g_kUser,m); +} +list g_lCards; +Cards(){ + integer x = 0; + integer e = 10; + integer CurCard = 1; + integer NCard = 0; + for(x=0;x x){ + string card_params = llList2String(g_lCards,x); + llMessageLinked(LINK_SET,0,llJsonGetValue(card_params,["text"]), "fw_data : card_text"+(string)CurCard); + } else { + NCard++; + llMessageLinked(LINK_SET,0,"", "fw_data : card_text"+(string)CurCard); + } + + llMessageLinked(LINK_SET,0,"Cards Against Humanity","fw_data : card_helpertext"+(string)CurCard); + CurCard++; + } + + if(NCard>0){ + integer CardsToRequest = NCard; + if(CardsToRequest == 0)return; + else { + llRegionSayTo(g_kTable,hud_channel, llList2Json(JSON_OBJECT, ["type","card_request","count", CardsToRequest])); + } + } +} + +POS(){ + if(!llGetAttached())return; + vector local = <0.02395, 0.47113, -0.15166>; + llSetPrimitiveParams([PRIM_POS_LOCAL, local]); +} + +POS2(){ + if(!llGetAttached())return; + vector local = <0.02395, 1.77734, -0.15166>; + llSetPrimitiveParams([PRIM_POS_LOCAL, local]); +} + +list g_lSelected = []; + +Highlight(){ + integer i=1; + integer end = 10; + for(i=1;i<=end;i++){ + if(llListFindList(g_lSelected,[i])==-1){ + integer x=0; + integer end2 = llGetNumberOfPrims(); + for(x=1;x<=end2;x++){ + string LinkName = llGetLinkName(x); + if(LinkName=="Card"+(string)i){ + llSetLinkColor(x, <1,1,1>, 2); + jump stopFor; + } + } + @stopFor; + } else { + integer x = 0; + integer end2 = llGetNumberOfPrims(); + for(x=1;x<=end2;x++){ + string LinkName = llGetLinkName(x); + if(LinkName == "Card"+(string)i){ + llSetLinkColor(x,<0,1,0>,2); + jump stopFor2; + } + } + @stopFor2; + } + } +} + +integer g_iSelectNum=0; +integer g_iCanSelect=0; +integer g_iListen=-1; +integer g_iChan; + +ShowPrompt(){ + if(g_iListen==-1){ + g_iChan = llRound(llFrand(5493874)); + g_iListen = llListen(g_iChan, "", g_kUser, ""); + } + + llDialog(g_kUser, "Do you want to submit your selected card(s)?", ["Yes", "No"], g_iChan); +} + +default +{ + state_entry() + { + llWhisper(0, "HUD was not rezzed or attached using the game table"); + llWhisper(0, "Some functionality may not work"); + llMessageLinked(LINK_SET,0,"","fw_reset"); + llWhisper(0, "HUD is now activating"); + + g_kUser=llGetOwner(); + g_kTable = llGetOwner(); + + Highlight(); + } + + on_rez(integer t){ + if(t==0){ + llResetScript(); + }else { + llSetPrimitiveParams([PRIM_TEMP_ON_REZ,TRUE]); + g_iStartParam = t; + llListen(t, "", "", ""); + llSay(hud_channel, llList2Json(JSON_OBJECT, ["type", "alive", "boot", t])); + } + } + + listen(integer c,string n,key i,string m){ + if(g_iStartParam == c){ + // listen for the UUID of who to attach the HUD to! + if(llJsonGetValue(m,["type"])=="activate"){ + g_kTable = (key)llJsonGetValue(m,["table"]); + llWhisper(0, "HUD now activating..."); + key g_kUser = (key)llJsonGetValue(m, ["user"]); + llRequestPermissions(g_kUser, PERMISSION_ATTACH); + //Cards(); + } + }else if(c == hud_channel){ + //llSay(0, "HUD message: "+m); + if(llJsonGetValue(m,["type"])=="card"){ + if(llJsonGetValue(m,["avatar"])==(string)g_kUser){ + if(llGetListLength(g_lCards)<10 && llListFindList(g_lCards,[llJsonGetValue(m,["card"])])==-1){ + g_lCards += llJsonGetValue(m,["card"]); + s("Added card: "+llJsonGetValue(m,["card", "text"])); + } + } + } else if(llJsonGetValue(m,["type"]) == "select"){ + if(llJsonGetValue(m,["czar"]) == (string)g_kUser){ + s("You are the Card Czar, hiding the HUD"); + POS2(); + g_iCanSelect=0; + } else { + g_iSelectNum = (integer)llJsonGetValue(m,["sel_count"]); + POS(); + g_lSelected=[]; + Highlight(); + s("Select ("+(string)g_iSelectNum+") cards to submit"); + s("Card czar: secondlife:///app/agent/"+llJsonGetValue(m,["czar"])+"/about"); + Cards(); + g_iCanSelect=1; + } + } else if(llJsonGetValue(m,["type"]) == "judging"){ + s("Judging begun. HUD hidden!"); + POS2(); + g_lSelected=[]; + Highlight(); + g_iCanSelect=0; + if(g_iListen!=-1){ + llListenRemove(g_iListen); + g_iListen=-1; + g_iChan=0; + } + } else if(llJsonGetValue(m,["type"])=="die"){ + llSay(0, "(DEBUG)\nm: "+m+"\n-> Table: "+(string)g_kTable+"\n-> User: "+(string)g_kUser); + if(llJsonGetValue(m,["table"])==(string)g_kTable){ + if(llJsonGetValue(m,["avatar"])==(string)g_kUser || llJsonGetValue(m,["avatar"])==(string)NULL_KEY || llJsonGetValue(m,["avatar"])==""){ + llSay(0, "Deactivating HUD"); + state detach; + } + } + } + } else if(g_iChan == c){ + if(m == "No"){ + // reshow prompt until user selects yes + ShowPrompt(); + } else if(m == "Yes"){ + // Gather card data and send to table + //llWhisper(0, "Locating the cards..."); + integer x = 0; + integer end = llGetListLength(g_lSelected); + string sActualCardData; + if(end == 0 || end!= g_iSelectNum){ + s("You must select "+(string)g_iSelectNum+" cards!"); + }else { + list lToRemove = []; + for(x=0;x