Implemented basic water well and water bucket
This commit is contained in:
parent
f928139088
commit
3dbc618418
17 changed files with 862 additions and 0 deletions
215
LSL/raw/water_well.lsl
Normal file
215
LSL/raw/water_well.lsl
Normal file
|
@ -0,0 +1,215 @@
|
|||
#include "Common.lsl"
|
||||
|
||||
integer g_iLastFillTime;
|
||||
integer g_iTotalWater;
|
||||
integer g_iWellChannel;
|
||||
integer g_iWellListener;
|
||||
string WATER_TEXTURE = "333d2eb0-f8c3-2c2e-3371-43df880ad2bf";
|
||||
vector WATER_PARTICLE = <0.20,0.36,0.79>;
|
||||
string API_SERVER="nset";
|
||||
key g_kAv=NULL_KEY;
|
||||
float g_fEmpty = -1.142;
|
||||
float g_fFull = -0.202;
|
||||
integer g_iRequestTime = 0;
|
||||
string WATER_WELL_NAME = "WoodStoneWaterWell";
|
||||
string VERSION = "1.0.0";
|
||||
integer g_iWaterPrim;
|
||||
integer g_iRoofPrim;
|
||||
integer g_iDestroyed = 0;
|
||||
|
||||
|
||||
float getScaledValue(integer percentage) {
|
||||
// Ensure the percentage is within the range 0-100
|
||||
if (percentage < 0) percentage = 0;
|
||||
if (percentage > 100) percentage = 100;
|
||||
|
||||
// Calculate the scaled value
|
||||
float scaledValue = g_fEmpty + ((g_fFull - g_fEmpty) * (percentage / 100.0));
|
||||
return scaledValue;
|
||||
}
|
||||
|
||||
setText() {
|
||||
llSetText("Water Well\nFill Level: " +(string)g_iTotalWater + "%", <1,1,1>, 1);
|
||||
}
|
||||
|
||||
updateLevel() {
|
||||
llSetLinkPrimitiveParams(2, [PRIM_POS_LOCAL, <0,0,getScaledValue(g_iTotalWater)>]);
|
||||
}
|
||||
|
||||
SCAN() {
|
||||
integer i;
|
||||
integer end = llGetNumberOfPrims();
|
||||
for(i=LINK_ROOT;i<=end;i++){
|
||||
string sName = llGetLinkName(i);
|
||||
if(sName == "water") g_iWaterPrim = i;
|
||||
if(sName == "roof") g_iRoofPrim = i;
|
||||
}
|
||||
|
||||
if(!g_iWaterPrim || !g_iRoofPrim) {
|
||||
llSay(0, "Something is wrong, either the water of roof was not detected");
|
||||
}
|
||||
}
|
||||
|
||||
default
|
||||
{
|
||||
state_entry()
|
||||
{
|
||||
llLinksetDataReset();
|
||||
XteaKey(PSK);
|
||||
PROTECT();
|
||||
llSay(0, "Scanning for needed linked prims...");
|
||||
SCAN();
|
||||
llSay(0, "Scan completed");
|
||||
|
||||
llSay(0, "Ready to be packaged");
|
||||
global_ingredients = getIngredientChannel(NULL_KEY);
|
||||
llListen(global_ingredients, "", "", "");
|
||||
g_iTotalWater = 100;
|
||||
|
||||
updateLevel();
|
||||
setText();
|
||||
|
||||
}
|
||||
|
||||
listen(integer c,string n,key i,string m) {
|
||||
string sJson = xtea_decrypt_string(m);
|
||||
if(llJsonGetValue(sJson, ["cmd"]) == "alive" && llJsonGetValue(sJson, ["type"]) == "Bucket") {
|
||||
|
||||
if(g_kAv != NULL_KEY) {
|
||||
|
||||
g_iTotalWater--;
|
||||
g_iLastFillTime = llGetUnixTime();
|
||||
llSetTimerEvent(1);
|
||||
g_kAv = NULL_KEY;
|
||||
|
||||
|
||||
integer iChannel = getIngredientChannel(i);
|
||||
llSleep(2);
|
||||
llRegionSayTo(i, iChannel, xtea_encrypt_string(llList2Json(JSON_OBJECT, ["cmd", "init"])));
|
||||
llSleep(1);
|
||||
|
||||
llRegionSayTo(i, iChannel, xtea_encrypt_string(llList2Json(JSON_OBJECT, ["cmd", "deposit", "type", "Water", "amount", 4, "texture", WATER_TEXTURE, "particle", WATER_PARTICLE, "dies", 1])));
|
||||
|
||||
setText();
|
||||
updateLevel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
on_rez(integer t) {
|
||||
// Start the timer
|
||||
g_iLastFillTime = llGetUnixTime();
|
||||
llSetTimerEvent(1);
|
||||
|
||||
if(g_iWellChannel != 0) {
|
||||
llListenRemove(g_iWellListener);
|
||||
}
|
||||
g_iWellChannel = (integer)("0x" + llGetSubString(llGetKey(), 0, 5));
|
||||
g_iWellListener = llListen(g_iWellChannel, "", "", "");
|
||||
|
||||
setText();
|
||||
}
|
||||
|
||||
link_message(integer s,integer n,string m,key i) {
|
||||
if(n == 0x004f) {
|
||||
API_SERVER = DecipherService(m, "api") + "/zni";
|
||||
}
|
||||
}
|
||||
|
||||
changed(integer c) {
|
||||
if(c & CHANGED_OWNER) {
|
||||
// pre-fill water
|
||||
g_iTotalWater = 100;
|
||||
} else if(c & CHANGED_REGION_START) {
|
||||
// Check for a product update
|
||||
llHTTPRequest(API_SERVER + "/Modify_Product_V2.php", [HTTP_MIMETYPE, "application/json", HTTP_METHOD, "POST"], llList2Json(JSON_OBJECT, ["psk", SERVER_PSK, "op", "get", "name", WATER_WELL_NAME]));
|
||||
}
|
||||
}
|
||||
|
||||
timer() {
|
||||
if(llGetUnixTime() > (g_iLastFillTime + 30)) {
|
||||
g_iLastFillTime = llGetUnixTime();
|
||||
g_iTotalWater ++;
|
||||
|
||||
updateLevel();
|
||||
|
||||
if(g_iTotalWater >= 100) {
|
||||
g_iTotalWater = 100;
|
||||
llSetTimerEvent(0);
|
||||
llLinksetDataWrite("water", (string)g_iTotalWater);
|
||||
}
|
||||
|
||||
setText();
|
||||
}
|
||||
}
|
||||
|
||||
touch_start(integer t) {
|
||||
if(g_iDestroyed) {
|
||||
llSay(0, "The well appears to have sustained a lot of damage. You'll need to construct a new one.");
|
||||
return;
|
||||
}
|
||||
if(g_iTotalWater == 0) {
|
||||
llSay(0, "The well is currently empty. Come back later");
|
||||
return;
|
||||
}
|
||||
|
||||
if(API_SERVER == "nset") {
|
||||
llWhisper(0, "Still waiting for API Server...");
|
||||
llMessageLinked(LINK_SET, -1, "", "");
|
||||
return;
|
||||
}
|
||||
|
||||
if(g_kAv == NULL_KEY) {
|
||||
|
||||
g_kAv = llDetectedKey(0);
|
||||
g_iRequestTime = llGetUnixTime();
|
||||
//llRezObject("Water Bucket [AC]", llGetPos() + <2,0,0>, ZERO_VECTOR, ZERO_ROTATION, g_iWellChannel);
|
||||
llHTTPRequest(API_SERVER + "/Get_Server_ID.php?NAME=Farming", [], "");
|
||||
|
||||
llWhisper(0, "Requesting a bucket...");
|
||||
llSetText("BUSY", <1,0,0>,1);
|
||||
} else {
|
||||
if(llGetAgentSize(g_kAv) == ZERO_VECTOR) {
|
||||
llWhisper(0, "I was previously in use, the person seems to have left the region. Try again now");
|
||||
g_kAv = NULL_KEY;
|
||||
setText();
|
||||
}else {
|
||||
llWhisper(0, "I am currently in use, please be patient");
|
||||
|
||||
if(llGetUnixTime() > g_iRequestTime + 120) {
|
||||
llWhisper(0, "2 minutes have passed, clearing busy status");
|
||||
g_kAv = NULL_KEY;
|
||||
g_iRequestTime = 0;
|
||||
setText();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
http_response(key kID, integer iStatus, list lMeta, string sBody) {
|
||||
list lParams = llParseString2List(sBody, [";", ";;"], []);
|
||||
string sScript = llList2String(lParams,0);
|
||||
|
||||
//llSay(0, sBody);
|
||||
|
||||
if(sScript == "GetServerID") {
|
||||
string sJson = llList2String(lParams,1);
|
||||
g_sServerID = llJsonGetValue(sJson, ["id"]);
|
||||
requestProductForDelivery("Water Bucket [AC]", g_kAv);
|
||||
}else if(sScript == "Modify_ProductV2") {
|
||||
// Gives the version information
|
||||
string sJson = llList2String(lParams,1);
|
||||
if(llJsonGetValue(sJson, ["status"]) == "ok") {
|
||||
// We now have the effective version, check it
|
||||
if(llJsonGetValue(sJson, ["version"]) != VERSION) {
|
||||
// Do what needs doing
|
||||
llSetLinkTexture(g_iRoofPrim, TEXTURE_TRANSPARENT, ALL_SIDES);
|
||||
llSetLinkTexture(g_iWaterPrim, TEXTURE_TRANSPARENT, ALL_SIDES);
|
||||
|
||||
g_iDestroyed=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue