summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2019-05-27 16:37:05 -0300
committerJesusaves <cpntb1@ymail.com>2019-05-27 16:37:05 -0300
commitf9b53e1fd26eea3a895d8712813f3daab70986b8 (patch)
tree0b494296cad863ae25200410d954a6dc6d0fccfd
parent32d36c77b23a449ca239c2b410d8ff5298ee0ed9 (diff)
downloadserverdata-f9b53e1fd26eea3a895d8712813f3daab70986b8.tar.gz
serverdata-f9b53e1fd26eea3a895d8712813f3daab70986b8.tar.bz2
serverdata-f9b53e1fd26eea3a895d8712813f3daab70986b8.tar.xz
serverdata-f9b53e1fd26eea3a895d8712813f3daab70986b8.zip
Helper functions for crafting with option system
-rw-r--r--npc/craft/options.txt91
1 files changed, 87 insertions, 4 deletions
diff --git a/npc/craft/options.txt b/npc/craft/options.txt
index 515cd315c..e9d7f87ec 100644
--- a/npc/craft/options.txt
+++ b/npc/craft/options.txt
@@ -9,7 +9,10 @@
// Player knowledge structure
// CRAFTSYS[ SKILL_SCOPE ] = SKILL_LV
-// ReturnVarID() takes the scope and finds out the skills on the group
+// Player craft skills selection:
+// CRAFTSYS_CURRENT
+
+// Generate() takes the scope and finds out the skills on the group
// It'll fill the following variables:
// @csys_attr → Available attributes
// @csys_penalty → Penalty attribute array
@@ -23,11 +26,12 @@
// Max Level for third tier:
// Max Level for ultimate tier: 1
-// ReturnVarID( cr_id{, preserve} )
-function script ReturnVarID {
+// csys_Generate( cr_id{, preserve} )
+function script csys_Generate {
.@gid=getarg(0);
if (!getarg(1, false)) {
deletearray(@csys_attr);
+ deletearray(@csys_penalty);
}
.@lvl=getd("CRAFTSYS["+.@gid+"]");
@@ -109,10 +113,89 @@ function script ReturnVarID {
array_push(@csys_penalty, VAR_ATTMPOWER);
break;
}
+ return;
+ //return Exception("Invalid ID");
+}
+
+// Check if you'll have success in applying options or not
+// Returns true if you was successful, and also cleans previous options
+// If you only want cleaning, just disregard the output.
+// csys_Check( invindex )
+function script csys_Check {
+ .@id=getarg(0);
- return Exception("Invalid ID");
+ // Clear all five options
+ setitemoptionbyindex(.@id, 0, 0, 0);
+ setitemoptionbyindex(.@id, 1, 0, 0);
+ setitemoptionbyindex(.@id, 2, 0, 0);
+ setitemoptionbyindex(.@id, 3, 0, 0);
+ setitemoptionbyindex(.@id, 4, 0, 0);
+
+ // Base Success Rate is: 40% + 5% each craft skill level
+ .@base=4000+(getskilllv(TMW2_CRAFT)*500);
+ if (rand(10000) < .@base)
+ return true;
+ return false;
}
+// Attribute item options
+// Does NOT performs success chance check, and can be used by NPC
+// csys_Apply( invindex{, lvl} )
+function script csys_Apply {
+ .@id=getarg(0);
+ .@lv=getarg(1, getskilllv(TMW2_CRAFT));
+
+ csys_Generate(CRAFTSYS_CURRENT);
+ // It'll fill the following variables:
+ // @csys_attr → Available attributes
+ // @csys_penalty → Penalty attribute array
+ //
+ // use getarraysize(@csys_attr) to know how many are there.
+ // Players can active the bonus groups they want to use (in future, TODO)
+
+ // Shuffle the arrays
+ array_shuffle(@csys_attr);
+ array_shuffle(@csys_penalty);
+
+ // How many bonuses we'll have? Never more than 3 bonus and 2 onus.
+ .@max_attr=getarraysize(@csys_attr);
+ .@max_pena=getarraysize(@csys_penalty);
+
+ .@slot=0;
+ while (.@slot < min(3, .@max_attr)) {
+ // You have 100% for first bonus/onus, -20% each, depending on skill lv
+ .@base=2000-(.@lv*75);
+ if (rand(10000) < 10000-(.@base*.@slot))
+ break;
+
+ // Apply a bonus using array_pop (it was shuffled so we're fine)
+ // A pity 1 str and 1 hp is so different.
+ .@vartp=array_pop(@csys_attr);
+ .@bonus=rand(1, .@lv/2);
+ setitemoptionbyindex(.@id, .@slot, .@vartp, .@bonus);
+ .@slot+=1;
+ }
+
+ // We need a new temp var
+ .@slt=0;
+ while (.@slt < min(2, .@max_pena)) {
+ // You have 100% for first bonus/onus, -20% each, depending on skill lv
+ .@base=2000-(.@lv*75);
+ if (rand(10000) < 10000-(.@base*.@slot))
+ break;
+
+ // Apply a bonus using array_pop (it was shuffled so we're fine)
+ // A pity 1 str and 1 hp is so different.
+ .@vartp=array_pop(@csys_penalty);
+ .@bonus=rand(1, .@lv/2);
+ setitemoptionbyindex(.@id, .@slot, .@vartp, .@bonus);
+ .@slot+=1;
+ .@slt+=1;
+ }
+
+ // The options have been attributed
+ return;
+}