summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2021-05-26 21:40:57 -0300
committerJesusaves <cpntb1@ymail.com>2021-05-26 21:40:57 -0300
commit5730649cb1df93a3cae88313e96f443979430210 (patch)
treeea367ed7fe45f60ab5f897b549e363a07cb40f8d
parent9050c51d647e9e32db39080c25f9d0e0a56b3216 (diff)
downloadserverdata-5730649cb1df93a3cae88313e96f443979430210.tar.gz
serverdata-5730649cb1df93a3cae88313e96f443979430210.tar.bz2
serverdata-5730649cb1df93a3cae88313e96f443979430210.tar.xz
serverdata-5730649cb1df93a3cae88313e96f443979430210.zip
Add Mirror Lake Vault Functionality. Along other required changes.
-rw-r--r--db/constants.conf20
-rw-r--r--npc/functions/bitwise.txt176
-rw-r--r--npc/functions/game_rules.txt4
-rw-r--r--npc/functions/global_event_handler.txt7
-rw-r--r--npc/functions/main.txt66
-rw-r--r--npc/functions/math.txt18
-rw-r--r--npc/functions/vault.txt97
-rw-r--r--npc/scripts.conf2
8 files changed, 367 insertions, 23 deletions
diff --git a/db/constants.conf b/db/constants.conf
index e3661a82..5d0e317e 100644
--- a/db/constants.conf
+++ b/db/constants.conf
@@ -2870,6 +2870,12 @@ more than one separator can be used in a row (so 12_3___456 is illegal).
/* ==================================================== */
/** evol constants **/
+ comment__: "API codes"
+ API_DISCORD: 301
+ API_PINCODE: 302
+ API_SENDMAIL: 501
+ API_FLUSHVAULT: 607
+
comment__: "outdated constants. must be removed"
// >>>
equip_head: 1
@@ -3291,8 +3297,18 @@ more than one separator can be used in a row (so 12_3___456 is illegal).
comment__: "Misc settings"
CHEST_WAITTIME: 900 // 15 minutes
ROSSY_INSTIME: 1200 // 20 minutes
- VEGAN: 1
- CARNIVOROUS: 2
+ WORLD_ID: 2 // Vault WID Identifier
+
+ comment__: "Report Bug Flags"
+ RB_NONE: 0
+ RB_DISPBOTTOM: 1
+ RB_DEBUGMES: 2
+ RB_SPEECH: 4
+ RB_ISFATAL: 8
+ RB_PLEASEREPORT: 16
+ RB_IRCBROADCAST: 32
+ RB_GLOBALANNOUNCE: 64
+ RB_DEFAULT: 19 // dispbottom + debugmes + pleasereport
comment__: "Location Constants"
TP_NONE: 0
diff --git a/npc/functions/bitwise.txt b/npc/functions/bitwise.txt
new file mode 100644
index 00000000..fd80024e
--- /dev/null
+++ b/npc/functions/bitwise.txt
@@ -0,0 +1,176 @@
+// The Mana World Script
+// Author: Gumi, Jesusalva
+/**
+ * Gets a bitmasked value in from an integer. If the shift is omitted, it will
+ * be deduced from the mask.
+ *
+ * @arg 0 - the variable
+ * @arg 1 - mask
+ * @arg 2 - shift */
+function script bitwise_get {
+ .@shift = getarg(2, 0);
+
+ if (getargcount() < 3) {
+ // guess the shift from the mask:
+ for (.@shift = 0; .@shift < 32; ++.@shift) {
+ if ((getarg(1) & (1 << .@shift)) != 0) {
+ break;
+ }
+ }
+ }
+
+ return (getarg(0) & getarg(1)) >> .@shift;
+}
+
+/**
+ * sets a bitmasked value in a variable
+ *
+ * @arg 0 - the target variable
+ * @arg 1 - mask
+ * @arg 2 - shift
+ * @arg 3 - new value
+ * @return a reference to the variable
+ */
+function script bitwise_set {
+ if (getargcount() < 4) {
+ // guess the shift from the mask:
+ for (.@shift = 0; .@shift < 32; ++.@shift) {
+ if ((getarg(1) & (1 << .@shift)) != 0) {
+ break;
+ }
+ }
+
+ return set(getarg(0), (getarg(0) & ~(getarg(1))) | (getarg(2, 0) << .@shift));
+ }
+
+ return set(getarg(0), (getarg(0) & ~(getarg(1))) | (getarg(3, 0) << getarg(2, 0)));
+}
+
+// bitmask_count(<int>)
+// returns the number of bits set in <int> (up to 4096?)
+function script bitmask_count {
+ .@n = getarg(0); // Number evaluated
+ .@p=0; // Bits set/unset
+ .@s=0; // Stack and Check
+ .@m=0; // Memory
+
+ // Loop only as needed
+ while (.@s < .@n) {
+ .@s=2**.@m;
+ if (.@n & .@s)
+ .@p++;
+ .@m++;
+ }
+ return .@p;
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+// A Nibble can go up to 15. There are 7 nibbles.
+// get_nibble(VAR, NIBBLEID)
+function script get_nibble {
+ .@v=getarg(0);
+ switch (getarg(1)) {
+ case 0:
+ .@s=0; .@m=0xF; break;
+ case 1:
+ .@s=4; .@m=0XF0; break;
+ case 2:
+ .@s=8; .@m=0XF00; break;
+ case 3:
+ .@s=12; .@m=0XF000; break;
+ case 4:
+ .@s=16; .@m=0XF0000; break;
+ case 5:
+ .@s=20; .@m=0XF00000; break;
+ case 6:
+ .@s=24; .@m=0XF000000; break;
+ default:
+ Exception("Invalid Nibble: "+getarg(1), RB_DEFAULT, .@v);
+ }
+
+ return bitwise_get(.@v, .@m, .@s);
+}
+
+// A Byte can go up to 255. There are 3 bytes. The forth can go up to 127.
+// get_nibble(VAR, BYTEID)
+function script get_byte {
+ .@v=getarg(0);
+ switch (getarg(1)) {
+ case 0:
+ .@s=0; .@m=0xFF; break;
+ case 1:
+ .@s=8; .@m=0XFF00; break;
+ case 2:
+ .@s=16; .@m=0XFF0000; break;
+ case 3:
+ .@s=24; .@m=0X7F000000; break;
+ default:
+ Exception("Invalid Byte: "+getarg(1), RB_DEFAULT, .@v);
+ }
+
+ return bitwise_get(.@v, .@m, .@s);
+}
+
+// A Bitword can go up to 65535 and is fixed in position to handle Soul EXP.
+// get_bitword(VAR)
+function script get_bitword {
+ .@v=getarg(0);
+
+ return bitwise_get(.@v, 0xFFFF, 0);
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+// A Nibble can go up to 15. There are 7 nibbles.
+// set_nibble(VAR, VAL, NIBBLEID)
+function script set_nibble {
+ .@v=getarg(0);
+ switch (getarg(2)) {
+ case 0:
+ .@s=0; .@m=0xF; break;
+ case 1:
+ .@s=4; .@m=0XF0; break;
+ case 2:
+ .@s=8; .@m=0XF00; break;
+ case 3:
+ .@s=12; .@m=0XF000; break;
+ case 4:
+ .@s=16; .@m=0XF0000; break;
+ case 5:
+ .@s=20; .@m=0XF00000; break;
+ case 6:
+ .@s=24; .@m=0XF000000; break;
+ default:
+ Exception("Invalid SNibble: "+getarg(2), RB_DEFAULT);
+ }
+
+ return bitwise_set(.@v, .@m, .@s, getarg(1));
+}
+
+// A Byte can go up to 255. There are 3 bytes. The forth can go up to 127.
+// set_nibble(VAR, VAL, BYTEID)
+function script set_byte {
+ .@v=getarg(0);
+ switch (getarg(2)) {
+ case 0:
+ .@s=0; .@m=0xFF; break;
+ case 1:
+ .@s=8; .@m=0XFF00; break;
+ case 2:
+ .@s=16; .@m=0XFF0000; break;
+ case 3:
+ .@s=24; .@m=0X7F000000; break;
+ default:
+ Exception("Invalid SByte: "+getarg(2), RB_DEFAULT);
+ }
+
+ return bitwise_set(.@v, .@m, .@s, getarg(1));
+}
+
+// A Bitword can go up to 65535 and is fixed in position to handle Soul EXP.
+// set_bitword(VAR, VAL)
+function script set_bitword {
+ .@v=getarg(0);
+
+ return bitwise_set(.@v, 0xFFFF, 0, getarg(1));
+}
+
diff --git a/npc/functions/game_rules.txt b/npc/functions/game_rules.txt
index 25cc3fd1..9b416a83 100644
--- a/npc/functions/game_rules.txt
+++ b/npc/functions/game_rules.txt
@@ -1,8 +1,8 @@
function script GameRules {
- mes "##BPlease click submit.";
+ mes l("##BPlease click submit.");
clear;
- title "Game Rules";
+ title l("Game Rules");
mes l("Players breaking the following rules may be banned for any length of time (even permanently) or have their characters reset at a GM's discretion:");
mes l("1) Do not abuse other players. Insults, swearing, and the like are not to be directed towards a particular person or group.");
mes l("2) No bots – including ##Bany##b AFK activity or automated actions of any sort.");
diff --git a/npc/functions/global_event_handler.txt b/npc/functions/global_event_handler.txt
index 3d8156c4..bc8f6742 100644
--- a/npc/functions/global_event_handler.txt
+++ b/npc/functions/global_event_handler.txt
@@ -6,12 +6,17 @@ OnPCLoginEvent:
@login_event = 1;
adddefaultskills();
//callfunc "fixHeadStyles"; // convert headstyles
- callfunc "ClearVariables"; // removes / converts old variables
+ ClearVariables(); // removes / converts old variables
DisplayMOTD(); // send the motd to the client, if enabled
// add more here
+ vaultOnLogin();
@login_event = 2;
end;
+OnPCLogoutEvent:
+ vaultOnLogout();
+ end;
+
OnPCKillEvent:
elanore_decrease_exp(); // decrease heal exp for doing bad things
end;
diff --git a/npc/functions/main.txt b/npc/functions/main.txt
index 6a0aeb72..d072ff60 100644
--- a/npc/functions/main.txt
+++ b/npc/functions/main.txt
@@ -521,6 +521,72 @@ function script sqldate {
return .@strdate$;
}
+// Makes a monster aggro
+// set_aggro( monster{, mode=MD_AGGRESSIVE} )
+function script set_aggro {
+ .@m=getarg(0);
+ .@x=getarg(1, MD_AGGRESSIVE);
+ .@op=getunitdata(.@m, UDT_MODE);
+ .@op=.@op|.@x;
+ setunitdata(.@m, UDT_MODE, .@op);
+ return;
+}
+
+// Special function which makes a date as a number
+// numdate( - )
+function script numdate {
+ .@strdate$=sprintf("%04d%02d%02d", gettime(GETTIME_YEAR), gettime(GETTIME_MONTH), gettime(GETTIME_DAYOFMONTH));
+ // Debug payload
+ if ($@OVERRIDE_NUMDATE)
+ return $@OVERRIDE_NUMDATE;
+ return atoi(.@strdate$);
+}
+
+// json_encode( {varname, varvalue}, {varname 2, varvalue 2}... )
+// returns string
+function script json_encode {
+ if (getargcount() < 2 || getargcount() % 2 != 0)
+ return Exception("json_encode arguments must be paired");
+
+ .@json$="{";
+ .@tab=true;
+
+ // For arguments
+ for (.@i=0;.@i < getargcount(); .@i++) {
+ // Close previous item
+ if (.@tab)
+ .@tab=false;
+ else
+ .@json$+=",";
+
+ // Input variable name
+ .@json$+="\""+getarg(.@i)+"\": ";
+
+ // Input variable value
+ if (isstr(getarg(.@i+1)))
+ .@json$+="\""+getarg(.@i+1)+"\"";
+ else
+ .@json$+=getarg(.@i+1);
+
+ // Advance
+ .@i++;
+ }
+
+ // Close the JSON
+ .@json$+="}";
+ return .@json$;
+}
+
+
+// api_send( code, data )
+// sends to API
+function script api_send {
+ .@cde=getarg(0);
+ .@fm$=escape_sql(getarg(1));
+ query_sql("INSERT INTO `api_export` (`type`, `data`) VALUES ('"+.@cde+"', \""+.@fm$+"\")");
+ return;
+}
+
// Linking functions
/////////////////////////////////////////////
function script getquestlink {
diff --git a/npc/functions/math.txt b/npc/functions/math.txt
index 9c93fbb7..941dfa90 100644
--- a/npc/functions/math.txt
+++ b/npc/functions/math.txt
@@ -102,22 +102,4 @@ function script ponderate_avg {
return (.@h1+.@h2)/.@dd;
}
-// bitmask_count(<int>)
-// returns the number of bits set in <int> (max. 4096)
-
-function script bitmask_count {
- .@n = getarg(0); // Number evaluated
- .@p=0; // Bits set/unset
- .@s=0; // Stack and Check
- .@m=0; // Memory
-
- // Loop only as needed
- while (.@s < .@n) {
- .@s=2**.@m;
- if (.@n & .@s)
- .@p++;
- .@m++;
- }
- return .@p;
-}
diff --git a/npc/functions/vault.txt b/npc/functions/vault.txt
new file mode 100644
index 00000000..4ef97470
--- /dev/null
+++ b/npc/functions/vault.txt
@@ -0,0 +1,97 @@
+// TMW-2 Script
+// Author:
+// Jesusalva
+// Description:
+// Vault Utilities
+
+function script getvaultid {
+ // FIXME: Make this False
+ if (debug || !debug)
+ return ##VAULT;
+ else
+ return 0;
+}
+
+function script getvaultexp {
+ .@exp=getarg(0);
+ if (.@exp > 100)
+ Exception("ILLEGAL VAULT EXPERIENCE, FIXME URGENTLY. STOPPING SCRIPT BY FORCE WHILE DOING NOTHING.",
+ RB_DEBUGMES | RB_IRCBROADCAST | RB_GLOBALANNOUNCE | RB_ISFATAL);
+ if (getvaultid()) {
+ ##VAULT_EXP+=.@exp;
+ debugmes("Granting %d Soul Exp to %d under Jande's authority.",
+ .@exp, ##VAULT);
+ }
+ return;
+}
+
+function script vaultOnLogin {
+ // Mirror Lake functionality
+ if (getvaultid() && !getstatus(SC_JAILED)) {
+ .@gto=get_byte(##00_INFO, 3);
+ .@mlp=get_nibble(##00_INFO, 5);
+ // Work only on new chars, or chars which cleared Tulimshar.
+ if (.@gto == WORLD_ID) {
+ // Warp to the proper Mirror Lake
+ switch (.@mlp) {
+ //case 1: somewhere
+ default: warp "013-2", 37, 23; LOCATION$ = "Hurns"; break;
+ }
+
+ // Send debug information
+ debugmes("Vault User %d moved to lake %d.", getvaultid(), .@mlp);
+
+ // Handle new user (non-native) accounts - automatic tutorial skip
+ if (QL_BEGIN < 8) {
+ if (!TUT_var) {
+ callfunc "GameRules";
+ next;
+ closeclientdialog;
+ adddefaultskills();
+ getitem Knife, 1;
+ getitem SlingShot, 1;
+ getitem SlingBullet, 500;
+ getitem HitchhikersTowel, 1;
+ getitem CottonShirt, 1;
+ getitem RaggedShorts, 1;
+ set Zeny, Zeny + 35; // tanisha gives 5 Zeny
+ equip(CottonShirt);
+ equip(RaggedShorts);
+ equip(Knife);
+ }
+ QL_BEGIN = 8;
+ dispbottom l("Mirror Lake : Obtain help with Sorfina in Candor.");
+ }
+
+ // Unset the target lake/world
+ set_byte(##00_INFO, 0, 3);
+ set_nibble(##00_INFO, 0, 5);
+ } else if (.@gto) {
+ // Heading somewhere which is not here!
+ mesc l("WARNING: If you use any Mirror Lake feature on this world, the current Mirror Lake Quest will be marked as \"Failed\"."), 1;
+ mesc l("If this is undesired, select the correct world, and if needed create a new char on it."), 1;
+ next;
+ closeclientdialog;
+ }
+ }
+ return;
+}
+
+function script vaultOnLogout {
+ // Send updates to Vault API
+ if (getvaultid()) {
+ .@api$=json_encode("UID", ##VAULT,
+ "GID", getcharid(3),
+ "VAR1N", "TMWQUEST",
+ "VAR1V", ##02_TMWQUEST,
+ "VEXP", ##VAULT_EXP,
+ "GOTO", ##VAULT_GOTO,
+ "MLTO", ##VAULT_MLTO);
+ ##VAULT_EXP=0;
+ ##VAULT_GOTO=0;
+ ##VAULT_MLTO=0;
+ api_send(API_FLUSHVAULT, .@api$);
+ }
+ return;
+}
+
diff --git a/npc/scripts.conf b/npc/scripts.conf
index 94266b4a..11129046 100644
--- a/npc/scripts.conf
+++ b/npc/scripts.conf
@@ -3,6 +3,7 @@
"npc/functions/string.txt",
"npc/functions/array.txt",
"npc/functions/math.txt",
+"npc/functions/bitwise.txt",
"npc/functions/permissions.txt",
// General-Purpose Framework Functions
@@ -10,6 +11,7 @@
"npc/functions/time.txt",
"npc/functions/timer.txt",
"npc/functions/goodbye.txt",
+"npc/functions/vault.txt",
// Pre-Loading Functions
"npc/functions/clear_vars.txt",