diff options
Diffstat (limited to 'npc/magic/drops.txt')
-rw-r--r-- | npc/magic/drops.txt | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/npc/magic/drops.txt b/npc/magic/drops.txt new file mode 100644 index 000000000..fcfc57e03 --- /dev/null +++ b/npc/magic/drops.txt @@ -0,0 +1,65 @@ +// TMW2 script +// Author: Jesusalva <admin@tmw2.org> +// +// Magic Script: TMW2_DROPS +// +// Realm of Drops - A passive skill which drastically improves drop rates + +function script SK_drops { + .@mobId=getarg(0, killedrid); + if (getskilllv(TMW2_DROPS) <= 0) + return; + if (.@mobId <= 0) + return; + if (@skdrop[.@mobId] < 0) + return; + + // Keep in mind that it is reset on logout + @skdrop[.@mobId]+=1; + .@lv=getmonsterinfo(.@mobId, MOB_LV); + .@min=10-getskilllv(TMW2_DROPS)+(.@lv/10); + + // Maybe we are in condition for the bonus drop + if (@skdrop[.@mobId] % .@min == 0) { + // This creates .@item and .@rate with same index + deletearray($@MobDrop_item); + deletearray($@MobDrop_rate); + getmobdrops(.@mobId); + .@count = $@MobDrop_count; + copyarray(.@item[0], $@MobDrop_item[0], .@count); + copyarray(.@rate[0], $@MobDrop_rate[0], .@count); + + // .@total => sum of all drop rates + // .@array => The real array for relative_array_random() + .@total = 0; + .@array = -1; + for (.@i = 0; .@i < .@count; ++.@i) { + .@s = getarraysize(.@array); + array_push(.@array, .@item[.@i]); + array_push(.@array, .@rate[.@i]); + .@total+=.@rate[.@i]; + } + + // Now we determine if you can, or cannot, get a bonus drop + if (.@total < 500) { + if (.@total < 200) { + // Hard limit: 2% of total drop rate (-1 prevents execution) + @skdrop[.@mobId]=-1; + return; + } else { + // Soft limit: Half the efficiency + if (@skdrop[.@mobId] % (.@min*2) != 0) + return; + } + } + + // You can! So give you a random bonus drop with proper ponderation + .@drop = relative_array_random(.@array); + getmapxy(.@m$, .@x, .@y, 0); + makeitem(.@drop, 1, .@m$, .@x, .@y); + if ($@GM_OVERRIDE || debug) + debugmes("Realm of Drops: Created %d as bonus drop in (%d,%d) [TDR %d KL %d]", .@drop, .@x, .@y, .@total, @skdrop[.@mobId]); + } + return; +} + |