summaryrefslogtreecommitdiff
path: root/npc/functions/treasure.txt
blob: c6d9a70d53ac705af36f9be7de4ec392ffc9ac96 (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
// 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 @@", 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
        if (.@r > 1600) // UC and C (100 ~ 150% bonus)
            .@r-=getarg(0, 0)+min((.@r-1600), getarg(0, 0)/2);
        else if (.@r > 200) // Rare (100 ~ 120% bonus)
            .@r-=getarg(0, 0)+min((.@r-300), getarg(0, 0)/5); // 300 to normalize
        else if (.@r <= 200) // 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(10, (TREASURE_OPEN/10));
        if (.@t % 149 == 0 || .@r < .@ur_rate)
            .@loot=any(ScrollMagnusHealC, SaviorBlueprint, DivineApple, MercBoxE, ScrollSDragon, Shemagh, Shemagh, EverburnPowder, IridiumOre, PlatinumOre, SacredImmortalityPotion, MagicApple, ElixirOfLife);
        else if (.@t % 50 == 0 || .@r < 200)
            .@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);
        else if (.@r < 1600 || .@t == 0)
            .@loot=any(MercBoxB, MoubooSteak, SmokeGrenade, ClothoLiquor, Coal, RedPlushWine, PrecisionPotion, CoinBag, DodgePotion, MoveSpeedPotion, Dagger, BronzeGift, IronOre, CopperOre, BlueDye, EquipmentBlueprintB, AlchemyBlueprintB, AlchemyBlueprintC, OolongTea);
        else if (.@r < 5200)
            .@loot=any(MercBoxA, Croconut, Potatoz, MoubooSteak, ClothoLiquor, Coal, SmallMushroom, HastePotion, StrengthPotion, WoodenLog, LeatherPatch, Beer, StrangeCoin, EquipmentBlueprintA, EquipmentBlueprintB, AlchemyBlueprintA, SpearmintTea, TreasureMap, DungeonMap, IcedBottle);
        else
            .@loot=any(FatesPotion, PiberriesInfusion, EmptyBottle, ChocolateBar, Plushroom, Chagashroom, RawLog, LeatherPatch, BugLeg, ScorpionStinger, SmallKnife, ChamomileTea, EquipmentBlueprintA);


        inventoryplace .@loot, 1;
        mesc l("You find @@ inside!", getitemlink(.@loot));
        getitem .@loot, 1;
        // 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("You find @@ inside!", l("nothing"));
    }
    return;
}