363 lines
No EOL
12 KiB
Text
363 lines
No EOL
12 KiB
Text
#include "Common.lsl"
|
|
|
|
integer g_iTreeStage;
|
|
integer g_iTreeGrowth;
|
|
integer g_iTotalWater;
|
|
|
|
float g_fMaxTreeSize = 10.0; // Maximum tree size
|
|
float g_fMaxGrowth = 150.0; // Maximum growth value
|
|
integer g_iLastGrowthStep = 0;
|
|
|
|
integer g_iLastUsedWater;
|
|
integer g_iChannel;
|
|
integer g_iListen;
|
|
key g_kAv;
|
|
string API_SERVER;
|
|
|
|
integer g_iTree;
|
|
integer g_iTreeStump;
|
|
integer g_iSapling;
|
|
integer g_iRequestedSapling;
|
|
integer g_iRezzedObject;
|
|
|
|
vector g_vInitialSapling = <0.59996, 0.56265, 1.01659>;
|
|
vector g_vInitialTree = <0.77864, 0.90290, 1.38959>;
|
|
vector g_vInitialStump = <0.14584, 0.14018, 0.05000>;
|
|
string g_sCallbackURL;
|
|
key g_kCallbackURLRequest;
|
|
integer g_iRemoveScripts=1;
|
|
|
|
|
|
SCAN() {
|
|
integer i=0;
|
|
integer end = llGetNumberOfPrims();
|
|
|
|
for(i=LINK_ROOT;i<=end;i++) {
|
|
string sName = llGetLinkName(i);
|
|
if(sName == "stump") g_iTreeStump = i;
|
|
if(sName == "tree") g_iTree = i;
|
|
if(sName == "sapling") g_iSapling = i;
|
|
}
|
|
|
|
if(!g_iTree && !g_iTreeStump && !g_iSapling) {
|
|
llSay(0, "Something has gone wrong with the linkset setup");
|
|
|
|
if(!g_iTree) llSay(0, "> Tree Prim");
|
|
if(!g_iTreeStump) llSay(0, "> Stump Prim");
|
|
if(!g_iSapling) llSay(0, "> Sapling Prim");
|
|
|
|
llSay(0, "Disabling script to prevent damage to linkset");
|
|
llSetScriptState(llGetScriptName(), FALSE);
|
|
}
|
|
}
|
|
|
|
InitialAppearance() {
|
|
llSetLinkPrimitiveParams(g_iTreeStump, [PRIM_POS_LOCAL, ZERO_VECTOR, PRIM_SIZE, g_vInitialStump]);
|
|
llSetLinkPrimitiveParams(g_iTree, [PRIM_POS_LOCAL, <0,-0.035,0.65>, PRIM_SIZE, g_vInitialTree]);
|
|
llSetLinkPrimitiveParams(g_iSapling, [PRIM_POS_LOCAL, <0,0.025,0.45>, PRIM_SIZE, g_vInitialSapling]);
|
|
llSetLinkPrimitiveParams(LINK_ROOT, [PRIM_SIZE, <0.05,0.05,0.05>]);
|
|
|
|
llSetLinkAlpha(g_iTreeStump, 0, ALL_SIDES);
|
|
llSetLinkAlpha(g_iTree, 0, ALL_SIDES);
|
|
llSetLinkAlpha(g_iSapling, 1, ALL_SIDES);
|
|
|
|
llScaleByFactor(0.2);
|
|
}
|
|
|
|
setText() {
|
|
|
|
if(g_iTreeStage == 1 && g_iTreeGrowth == 100) {
|
|
llSetText("", ZERO_VECTOR, 1);
|
|
}else
|
|
llSetText("Water: " + (string)g_iTotalWater+"%\nStage: " + (string)g_iTreeStage + "/1" + "\nProgress: " + (string)g_iTreeGrowth+"%\n \n \n \n \n \n \n \n", <1,1,1>,1);
|
|
}
|
|
|
|
integer g_iLastOwnerDev=1;
|
|
integer g_iDevListener;
|
|
|
|
integer g_iWaitDelivery = 0;
|
|
|
|
default
|
|
{
|
|
state_entry()
|
|
{
|
|
llLinksetDataReset();
|
|
XteaKey(PSK);
|
|
global_ingredients = getIngredientChannel(NULL_KEY);
|
|
llSay(0, "Scanning linkset...");
|
|
SCAN();
|
|
llSay(0, "Checking permissions...");
|
|
PROTECT();
|
|
llSay(0, "Done checking permissions");
|
|
|
|
llSay(0, "Setting scale, and hiding parts..");
|
|
InitialAppearance();
|
|
|
|
llSay(0, "Setting value: I need water");
|
|
g_iTotalWater = 0;
|
|
llSay(0, "Tree is now thirsty");
|
|
llSay(0, "Setting growth stage to 0, at 0%");
|
|
g_iTreeGrowth = 0;
|
|
g_iTreeStage = 0;
|
|
llSay(0, "> Timers are not running, they will be started on next rez");
|
|
llSay(0, "I am now ready to be packaged");
|
|
llListen(global_ingredients, "", "", "");
|
|
|
|
#ifdef DEBUG
|
|
llSay(0, "DEBUG MODE DETECTED.\n\n[ STARTING TIMERS ]");
|
|
llSetTimerEvent(1);
|
|
#endif
|
|
|
|
setText();
|
|
|
|
g_iDevListener = llListen(99, "", "", "");
|
|
}
|
|
|
|
changed(integer c) {
|
|
if(c&CHANGED_OWNER) {
|
|
if(!g_iLastOwnerDev)return;
|
|
|
|
g_iLastOwnerDev=0;
|
|
llListenRemove(g_iDevListener);
|
|
|
|
|
|
/*g_iTreeGrowth=0;
|
|
g_iTreeStage=0;
|
|
InitialAppearance();
|
|
g_iTotalWater=100;*/
|
|
llSetTimerEvent(2);
|
|
|
|
setText();
|
|
}
|
|
}
|
|
|
|
link_message(integer s,integer n,string m,key i) {
|
|
if(n == 0x004f) {
|
|
API_SERVER = DecipherService(m, "api") + "/zni";
|
|
}
|
|
}
|
|
|
|
on_rez(integer t) {
|
|
if(t == 0 && llGetObjectName() == SAPLING_NAME) {
|
|
llSetObjectName(TREE_NAME);
|
|
}
|
|
}
|
|
|
|
touch_start(integer t) {
|
|
if(!llSameGroup(llDetectedKey(0))) {
|
|
llRegionSayTo(llDetectedKey(0), 0, "/!\\ WARNING /!\\\n\n> You are not wearing the required group tag. All products in the Aria's Creations Farm System require you to wear the correct group tag for security reasons.");
|
|
return;
|
|
}
|
|
// Show the menu if done growing
|
|
if(g_iTreeStage == 1 && g_iTreeGrowth >= 100) {
|
|
g_iChannel = llRound(llFrand(0xFFFF));
|
|
g_iListen = llListen(g_iChannel, "", llDetectedKey(0), "");
|
|
|
|
llDialog(llDetectedKey(0), "Tree\n=====\nDo you want to chop the tree down?\n\n* Tools are not yet implemented", ["Yes", "No"], g_iChannel);
|
|
} else {
|
|
llRegionSayTo(llDetectedKey(0), 0, "/!\\ Tree Not Grown /!\\\n\n> At this time, the ability to chop the tree down at earlier stages is unavailable.");
|
|
return;
|
|
}
|
|
}
|
|
|
|
http_response(key k, integer s, list m, string b) {
|
|
list lPar = llParseString2List(b, [";;"], []);
|
|
if(llList2String(lPar,0) == "GetServerID") {
|
|
string sJson = llList2String(lPar,1);
|
|
g_sServerID = llJsonGetValue(sJson, ["id"]);
|
|
g_kCallbackURLRequest = llRequestURL();
|
|
} else if(llList2String(lPar,0) == "Get_Server_URL") {
|
|
altRequestDelivery(llList2String(lPar,2), g_kAv, SAPLING_NAME);
|
|
|
|
llSleep(2);
|
|
if(!g_iRemoveScripts) {
|
|
llSay(0, "> Server acknowledged delivery");
|
|
}
|
|
|
|
g_iRequestedSapling=1;
|
|
if(g_iRezzedObject && g_iRemoveScripts){
|
|
llRemoveInventory("Service Daemon [AC]");
|
|
llRemoveInventory(llGetScriptName());
|
|
}
|
|
}
|
|
}
|
|
|
|
http_request(key kID, string sMethod, string sBody) {
|
|
|
|
if(sMethod == URL_REQUEST_GRANTED && g_kCallbackURLRequest == kID) {
|
|
g_sCallbackURL = sBody;
|
|
if(!g_iRemoveScripts) {
|
|
llSay(0, "> Failsafe URL Obtained... Request Delivery [" + SAPLING_NAME + "]");
|
|
llSay(0, "API SERVER: " + API_SERVER);
|
|
llSay(0, "SERVER ID: " + g_sServerID);
|
|
}
|
|
|
|
requestProductForDelivery(SAPLING_NAME, g_kAv, g_sCallbackURL);
|
|
g_iWaitDelivery = 30;
|
|
llSetTimerEvent(2);
|
|
}else if(sMethod == "GET") {
|
|
llHTTPResponse(kID, 200, "");
|
|
llReleaseURL(g_sCallbackURL);
|
|
|
|
if(!g_iRemoveScripts) {
|
|
llSay(0, "> Server acknowledged delivery");
|
|
}
|
|
|
|
llSleep(2);
|
|
|
|
g_iRequestedSapling=1;
|
|
if(g_iRezzedObject && g_iRemoveScripts){
|
|
llRemoveInventory("Service Daemon [AC]");
|
|
llRemoveInventory(llGetScriptName());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
timer() {
|
|
if(g_iWaitDelivery) {
|
|
g_iWaitDelivery--;
|
|
|
|
if(g_iWaitDelivery == 1) {
|
|
llReleaseURL(g_sCallbackURL);
|
|
llHTTPRequest(API_SERVER + "/Get_Server_URL.php?NAME=Farming", [], "");
|
|
}
|
|
|
|
|
|
if(g_iTreeStage == 1 && g_iTreeGrowth == 100 && !g_iWaitDelivery) {
|
|
llSetTimerEvent(0);
|
|
return;
|
|
}
|
|
}
|
|
if(llGetUnixTime() > g_iLastUsedWater+5)
|
|
llWhisper(global_ingredients, xtea_encrypt_string(llList2Json(JSON_OBJECT, ["cmd", "query"])));
|
|
|
|
integer iGrowTime = 240;
|
|
#ifdef DEBUG
|
|
iGrowTime = 1;
|
|
#endif
|
|
|
|
if(llGetUnixTime() > g_iLastGrowthStep + iGrowTime) {
|
|
|
|
if(g_iTotalWater == 0) return;
|
|
|
|
g_iLastGrowthStep = llGetUnixTime();
|
|
integer iRoll = llRound(llFrand(100));
|
|
if((iRoll % 2) == 0) {
|
|
// Bump growth
|
|
g_iTreeGrowth++;
|
|
if(g_iTreeStage)
|
|
llSetLinkPrimitiveParams(g_iSapling, [PRIM_SIZE,ZERO_VECTOR]);
|
|
|
|
llScaleByFactor(1.0225);
|
|
|
|
setText();
|
|
|
|
iRoll = llRound(llFrand(100));
|
|
if(iRoll >= 75) {
|
|
g_iTotalWater--;
|
|
|
|
if(g_iTotalWater <= 0) g_iTotalWater = 0;
|
|
setText();
|
|
}
|
|
|
|
if(g_iTreeStage == 1 && g_iTreeGrowth == 100) {
|
|
llSetTimerEvent(0);
|
|
return;
|
|
}
|
|
|
|
if(g_iTreeGrowth == 100) {
|
|
g_iTreeStage++;
|
|
g_iTreeGrowth = 0;
|
|
llSetLinkAlpha(g_iSapling,0, ALL_SIDES);
|
|
llSetLinkAlpha(g_iTree,1,ALL_SIDES);
|
|
|
|
llSetLinkPrimitiveParams(g_iSapling, [PRIM_SIZE,ZERO_VECTOR]);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
object_rez(key kID) {
|
|
llSleep(2);
|
|
llRegionSayTo(kID, getIngredientChannel(kID), xtea_encrypt_string(llList2Json(JSON_OBJECT, [
|
|
"cmd", "init"
|
|
])));
|
|
|
|
llSleep(1);
|
|
llRegionSayTo(kID, getIngredientChannel(kID), xtea_encrypt_string(llList2Json(JSON_OBJECT, [
|
|
"cmd", "deposit",
|
|
"type", "Large Log",
|
|
"amount", 1,
|
|
"particle", "<0.502, 0.251, 0.000>",
|
|
"texture", NULL_KEY,
|
|
"dies", 1
|
|
])));
|
|
|
|
g_iRezzedObject=1;
|
|
if(g_iRequestedSapling) {
|
|
llRemoveInventory("Service Daemon [AC]");
|
|
llRemoveInventory(llGetScriptName());
|
|
}
|
|
}
|
|
|
|
listen(integer c,string n,key i,string m) {
|
|
if(c == global_ingredients) {
|
|
|
|
string sJson = xtea_decrypt_string(m);
|
|
if(llJsonGetValue(sJson, ["cmd"]) == "reply") {
|
|
if(llJsonGetValue(sJson, ["ingredient"]) == "Water") {
|
|
if(g_iTotalWater <= 75 && llGetUnixTime() > g_iLastUsedWater + 5) {
|
|
|
|
g_iTotalWater += 25;
|
|
g_iLastUsedWater = llGetUnixTime();
|
|
llRegionSayTo(i, getIngredientChannel(i), xtea_encrypt_string(llList2Json(JSON_OBJECT, ["cmd", "use", "id", llJsonGetValue(sJson, ["id"])])));
|
|
|
|
setText();
|
|
}
|
|
}
|
|
}
|
|
}else if( c == g_iChannel) {
|
|
|
|
llListenRemove(g_iListen);
|
|
if(m == "Yes") {
|
|
g_kAv = i;
|
|
llRezObject("Tree Log [AC]", llGetPos()+<0,0,0.5>, ZERO_VECTOR, ZERO_ROTATION, 1990);
|
|
|
|
llSetLinkAlpha(g_iTreeStump, 1, ALL_SIDES);
|
|
llSetLinkAlpha(g_iTree, 0, ALL_SIDES);
|
|
|
|
llSetLinkPrimitiveParams(g_iTree, [PRIM_POS_LOCAL, ZERO_VECTOR, PRIM_SIZE, ZERO_VECTOR]);
|
|
|
|
// Deliver 1 sapling, additional ones need to be bought
|
|
llHTTPRequest(API_SERVER + "/Get_Server_ID.php?NAME=Farming", [], "");
|
|
//requestProductForDelivery("Tree A Sapling [AC]");
|
|
}
|
|
} else if(c == 99) {
|
|
if(m == "devmode_off") {
|
|
llSay(0, "Disabling developer mode");
|
|
|
|
llSetTimerEvent(2);
|
|
g_iLastOwnerDev=0;
|
|
|
|
} else if(m == "water"){
|
|
g_iTotalWater=0;
|
|
llSay(0, "Setting thirsty");
|
|
} else if(m == "reset") {
|
|
g_iTreeGrowth = 0;
|
|
g_iTreeStage = 0;
|
|
} else if(m == "grow") {
|
|
g_iTreeGrowth = 100;
|
|
} else if(m == "freeze") {
|
|
llSetTimerEvent(0);
|
|
llSay(0, "State frozen");
|
|
} else if(m == "test_sapling") {
|
|
llSay(0, "Initiating sapling delivery test...");
|
|
g_kAv = i;
|
|
g_iRemoveScripts = 0;
|
|
llHTTPRequest(API_SERVER + "/Get_Server_ID.php?NAME=Farming", [], "");
|
|
}
|
|
}
|
|
}
|
|
} |