summaryrefslogtreecommitdiff
path: root/npc/items/alcohol.txt
blob: 01eb4d4b0e48f4f82fc29ca9446b8c2a49ccfc44 (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
// TMW-2 Script.
// Author:
//    Crush
//    Jesusalva
// Description:
//    Alcohol effects
//    TODO: Retroactive, weakens every hour...
//
// Variables:
//    @taste    Alcohol taste (0~100) - influences exp up
//    @Alcohol   Alcoholic rating (0~100) - influences Attack Speed Malus, Min. Vit and duration
//    ALC_DELAYTIME For how long you are drunk (the delay) - gettimetick(2)
//    ALC_THRESHOLD How drunk you are (the bonus)
//
//    When drunk, attack speed is lowered but exp gain is increased.
//    Attack Speed Reductor: SC_ATTHASTE_INFINITY (reset upon death), SC_ATTHASTE_POTION2 (not reset upon death)
//    Max HP Reductor: SC_INCMHPRATE
//    EXP Increaser: SC_CASH_PLUSEXP (not reset upon death), SC_OVERLAPEXPUP (reset upon death)

-	script	alcohol_sc	-1,{

    // Stack remaning bonuses if the last one hasn't finished
    // remaining_bonuses(sc, type)
    // type 0: delay
    // type 1: value
    function remaining_bonus
    {
        if (getstatus(getarg(0)))
        {
            if (getarg(1))
                return getstatus(getarg(0), 1);
            else
                return getstatus(getarg(0), 5); // Shouldn't it be 5?
        }
        return 0;
    }

OnUse:
    if (@Alcohol <= 0 || @taste <= 0) {
        Exception("Invalid alcoholic item, deleting without any effect.");
        end;
    }
    // Do you have enough vitality to hold your beer?
    // Skip this check on the first drink
    if (ALC_THRESHOLD) {
        .@vit=readparam(bVit);
        if (@Alcohol+ALC_THRESHOLD > .@vit) {
            dispbottom l("You vomit, you are too drunk for this to have effect anymore.");
            dispbottom l("Raise vitality to be able to drink even more.");
		    sc_start SC_CONFUSION, 5000, 0, 10000, SCFLAG_NOAVOID; // Warning, forces user to use @resync!
            end;
        }
    }
    .@deltatime=2*60*1000; // How long (in ms) each Alcohol point works? (max. 100 points)
    // Default value is 2 minutes per alcohol point - you'll be somber after at most four hours.
    // Beer (7): 14 minutes
    // Wine (16): 32 minutes
    // Sake (25): 50 minutes
    // Rum (40) : 80 minutes (1h20)
    // Ale (70) : 140 minutes (2h20)

    // Taste is affected by users near you.
    // Each user raises exp bonus in 1.5%, capped to the beverage taste
    // If you are with many people, drink a better beverage! ;-)
    getmapxy(.@m$, .@x, .@y, 0);
    .@bonus=getareausers(.@m$, .@x-12, .@y-12, .@x+12, .@y+12)-1;
    .@bonus=.@bonus*15/10;
    @taste+=min(@taste, .@bonus);

    // Alcohol EXP Bonus - ponderate average, so having more VIT doesn't means
    // more experience - only more time (be careful when mixing alcohol!)
    .@v=remaining_bonus(SC_OVERLAPEXPUP, true);
    .@t=remaining_bonus(SC_OVERLAPEXPUP, false)/1000;

    if (.@t) .@val1 = ponderate_avg(@taste, @Alcohol, .@v, .@t);
    else .@val1 = @taste;

    // Put the delay in ms.
    .@delay = remaining_bonus(SC_OVERLAPEXPUP, false);
    .@delay = .@t + @Alcohol*.@deltatime;

    // Reset EXP Bonus based on the new cumulative delay and average exp bonus
    sc_end SC_OVERLAPEXPUP;
    sc_start SC_OVERLAPEXPUP, .@delay, .@val1;

    // Recalculate Alcohol Threshold and time
    ALC_THRESHOLD+=@Alcohol;
    if (ALC_DELAYTIME < gettimetick(2)) {
        ALC_DELAYTIME=gettimetick(2);
        ALC_THRESHOLD=@Alcohol;
    }
    ALC_DELAYTIME+=@Alcohol*.@deltatime;

    // Debug comment if you need to check stuff
    //debugmes "%d %d | %d %d | f t ", remaining_bonus(SC_OVERLAPEXPUP, false), remaining_bonus(SC_OVERLAPEXPUP, true), remaining_bonus(SC_ATTHASTE_INFINITY, false), remaining_bonus(SC_ATTHASTE_INFINITY, true);

    // For debuff I'll use inc_sc_bonus utilities (exp gain = atk speed loss)
    .@delay=@Alcohol*(.@deltatime/1000);
    .@min=-(remaining_bonus(SC_OVERLAPEXPUP, true)*2);
    .@max=-(remaining_bonus(SC_OVERLAPEXPUP, true)*2);
    SC_Bonus(.@delay, SC_ATTHASTE_INFINITY, .@min, .@max);
    close;
}

function	script	ALCReset	{
    if (ALC_DELAYTIME < gettimetick(2))
        ALC_THRESHOLD=0;
    end;
}