summaryrefslogtreecommitdiff
path: root/npc/functions/treasure.txt
blob: bf1c87d6d85b2579ee25c34e22399387317be640 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// TMW2 functions.
// Author:
//    Jesusalva
// Description:
//    Random Treasure Box Utils

// TreasureBox ( { bonus chance{, TreasureKey} } )
function	script	TreasureBox	{
    .@id=getnpcid();
    if (RNGTREASURE_DATE[.@id] > gettimetick(2)) {
        mesc l("The chest is unlocked and empty.");
        close;
    }

    .@key=getarg(1, TreasureKey);
    mesc l("Open the chest?");
    mesc l("Cost: 1 %s", getitemlink(.@key)), 1;
    if (!countitem(.@key))
        close;
    next;
    if (askyesno() == ASK_NO)
        close;

    delitem .@key, 1;
    mesc l("You open the chest!");
    RNGTREASURE_DATE[.@id]=gettimetick(2)+CHEST_WAITTIME; // Minimum 15 minutes

    .@empty=getvariableofnpc(.empty, strnpcinfo(0));
    if (!.@empty) {
        TREASURE_OPEN=TREASURE_OPEN+1;
        .@t=TREASURE_OPEN;
        .@r=rand(0,10000)-(readparam2(bLuk)*2);

        // Some chests may have different rates
        // Note that rare is used as 300 instead of 200
        // This is to normalize with SR/UR formula
        if (.@r > 1600) // UC and C (100% ~ 150% bonus)
            .@r-=max(getarg(0, 0), 1200)+min((.@r-1600), getarg(0, 0)/2);
        else if (.@r > 300) // Rare (67% ~ 120% bonus)
            .@r-=max(getarg(0, 0), 285)+min((.@r-300), getarg(0, 0)/5);
        else if (.@r <= 300) // SR and UR (67% Bonus)
            .@r-=getarg(0, 0)*2/3;

        // Select treasure list
        // You're warranted an ultra rare (0.1%) every 149 open chests
        // You're warranted a super rare (2%) every 50 open chests
        // There's also rares (14%), uncommons (36%) and commons (48%)
        .@ur_rate=min(15, (TREASURE_OPEN/10));
        .@count=1;
        .@money=0;
        // ultra rare
        if (.@t % 149 == 0 || .@r < .@ur_rate) {
            .@money=rand(1000, 2000);
            .@loot=any(ScrollMagnusHealC, SaviorBlueprint, DivineApple, MercBoxE, ScrollSDragon, EverburnPowder, IridiumOre, PlatinumOre, SacredImmortalityPotion, MagicApple, ElixirOfLife);
        // super rare
        } else if (.@t % 50 == 0 || .@r < 200) {
            .@money=rand(500, 750);
            .@loot=any(MercBoxC, ScrollMagnusHealB, SnakeEgg, LachesisBrew, ArrowAmmoBox, GoldPieces, SilverGift, TerraniteOre, LeadOre, TinOre, SilverOre, GoldOre, TitaniumOre, FluoPowder, Lockpicks, EquipmentBlueprintC, AlchemyBlueprintC, AlchemyBlueprintD, AncientBlueprint, YerbaMate, JasmineTea, DeathPotion, SacredLifePotion, SacredManaPotion, BrokenWarpCrystal, PurificationPotion, GoldenApple);
            if (.@loot == SnakeEgg)
              .@count=rand(2, 6);
            else if (.@loot == Lockpicks)
              .@count=rand2(3, 6);
            else if (.@loot == DeathPotion)
              .@count=rand2(1, 3);
        // rare
        } else if (.@r < 1600 || .@t == 0) {
            .@money=rand(100, 300);
            .@loot=any(MercBoxB, MoubooSteak, ClothoLiquor, Coal, RedPlushWine, PrecisionPotion, CoinBag, DodgePotion, MoveSpeedPotion, Lockpicks, BronzeGift, IronOre, CopperOre, BlueDye, EquipmentBlueprintB, AlchemyBlueprintB, AlchemyBlueprintC, OolongTea, Curshroom, ScrollSWolvern);
            if (.@loot == Coal)
              .@count=rand(6, 10);
            else if (.@loot == Lockpicks)
              .@count=rand2(1, 3);
            else if (.@loot == IronOre)
              .@count=rand(2, 5);
            else if (.@loot == CopperOre)
              .@count=rand(1, 3);
            else if (.@loot == ClothoLiquor)
              .@count=rand(2, 5);
        // uncommon
        } else if (.@r < 5200) {
            .@money=rand(20, 80);
            .@loot=any(MercBoxA, SmokeGrenade, Potatoz, MoubooSteak, ClothoLiquor, Coal, SmallMushroom, HastePotion, StrengthPotion, WoodenLog, LeatherPatch, Lockpicks, Beer, StrangeCoin, EquipmentBlueprintA, EquipmentBlueprintB, AlchemyBlueprintA, SpearmintTea, TreasureMap, DungeonMap, IcedBottle, ScrollSCave);
            if (.@loot == Coal)
              .@count=rand(4, 6);
            else if (.@loot == Potatoz)
              .@count=rand(4, 8);
            else if (.@loot == LeatherPatch)
              .@count=rand(3, 4);
            else if (.@loot == StrangeCoin)
              .@count=rand(1, 10);
            else if (.@loot == ScrollSCave)
              .@count=rand(2, 5);
            else if (.@loot == Beer)
              .@count=rand2(2, 4);
            else if (.@loot == WoodenLog)
              .@count=rand2(1, 3);
            else if (.@loot == SmallMushroom)
              .@count=rand(5, 8);
            else if (.@loot == IcedBottle) {
              .@count=(season() == WINTER ? rand2(2, 3) : rand2(1, 3));
              if (season() == SUMMER)
                dispbottom l("Just the right thing to cool down right now!");
            }
        // common
        } else {
            .@loot=any(FatesPotion, PiberriesInfusion, EmptyBottle, ChocolateBar, Chagashroom, Plushroom, SmallMushroom, MaggotSlime, RawLog, LeatherPatch, Coal, EmptyBox, ChamomileTea, EquipmentBlueprintA, ScrollSCave, ScrollSMaggot);
            if (.@loot == Coal || .@loot == EmptyBottle)
              .@count=rand2(1, 3);
            else if (.@loot == Chagashroom || .@loot == Plushroom)
              .@count=rand(10, 20);
            else if (.@loot == RawLog || .@loot == EmptyBox)
              .@count=rand(2, 4);
            else if (.@loot == LeatherPatch)
              .@count=rand2(1, 2);
            else if (.@loot == ScrollSMaggot)
              .@count=rand(1, 5);
            else if (.@loot == MaggotSlime) {
              .@count=rand(30, 40);
              dispbottom l("Eww! Some maggots got squashed when the chest was opened!");
            }
        }

        inventoryplace .@loot, .@count;
        mesc l("You find %s x%d inside!", getitemlink(.@loot), .@count);
        getitem .@loot, 1;
        Zeny+=.@money;
        // Pointless easteregg
        if ($EVENT$ == "Christmas" && .@loot == Coal)
            if (alignment() >= 0)
              dispbottom l("I must have been naughty.");
            else
              dispbottom l("My devilish actions have been rewarded!");

        // Get Monster points for treasure hunting (20% from job level)
        if (MPQUEST)
            Mobpt+=(JobLevel/5);

        // World Expo Event
        if ($EVENT$ == "Expo")
            FYE_Expo();
    } else {
        mesc l("Unfortunately, you find %s inside.", l("nothing"));
    }
    return;
}