summaryrefslogtreecommitdiff
path: root/npc/011-3/flood.txt
blob: 68046922aba87583057a180b72373d39c3a3fbfb (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
// TMW2 scripts.
// Authors:
//    Jesusalva
// Description:
//    Controls Eternal Swamps.
//    Contains functions to flood the map (hide the bridges - mask 1024 + mask 2)
//    Flood happens at random and causes BluePar to be spawn. Runs every 6/4 minutes.
//    At the 6th minute of an hour (6, 16, 26, 36, 46, 56)
//    At the 2nd minute of an hour (2, 14 ... 44, 54)

011-3,0,0,0	script	#EternalSwampCore	NPC_HIDDEN,{
    end;

OnSwampMob:
    end;

OnInit:
    addmapmask "011-3", MASK_SPECIAL;
    bindatcmd "es_flood", "#EternalSwampCore::OnSkipFlood", 99, 99, 1;
    end;

OnMinute02:
OnMinute06:
OnMinute12:
OnMinute16:
OnMinute22:
OnMinute26:
OnMinute32:
OnMinute36:
OnMinute42:
OnMinute46:
OnMinute52:
OnMinute56:
OnSkipFlood:
    debugmes "[Flood] Cycle begin";
    .@fd=!(getmapmask("011-3")&MASK_SPECIAL); // .@fd - is flooded?

    if (.@fd) {
        debugmes "[Flood] UF - Unflooding";
        // If it is flooded, unflood it to prevent players getting struck for too long
        killmonster("011-3", "#EternalSwampCore::OnSwampMob");
        addmapmask "011-3", MASK_SPECIAL;
        debugmes "[Flood] UF - Del Cells";
        delcells "ESwpBridge1";
        delcells "ESwpBridge2";
        delcells "ESwpBridge3";
        delcells "ESwpBridge4";
        delcells "ESwpBridge5";
        delcells "ESwpBridge6";
        delcells "ESwpBridge7";
        mapannounce "011-3", "Eternal Swamps: The flood ceases!",bc_all|bc_npc;
    } else {
        // 40% chances to flood, 75% during night
        .@odds=40;
        if (is_night())
            .@odds+=35;

        // Bugfix
        .@odds=0;

        debugmes "[Flood] Analysis with %d odds to flood", .@odds;

        // Maybe we should flood it
        if (rand(0,100) < .@odds) {
            debugmes "[Flood] F - Flooding";
            removemapmask "011-3", MASK_SPECIAL;

            debugmes "[Flood] F - Adding Cells";
            setcells "011-3", 37, 22, 39, 24, 1, "ESwpBridge1";
            setcells "011-3", 37, 34, 39, 41, 1, "ESwpBridge2";
            setcells "011-3", 31, 67, 33, 73, 1, "ESwpBridge3";
            setcells "011-3", 40, 96, 42, 102, 1, "ESwpBridge4";
            setcells "011-3", 38, 130, 40, 136, 1, "ESwpBridge5";
            setcells "011-3", 41, 157, 43, 163, 1, "ESwpBridge6";
            setcells "011-3", 36, 187, 38, 193, 1, "ESwpBridge7";

            debugmes "[Flood] F - Spawn and Announce";
            areamonster "011-3", 20, 20, 60, 220, "Bluepar", Bluepar, rand(8,26), "#EternalSwampCore::OnSwampMob";
            mapannounce "011-3", "Eternal Swamps: A flood starts!",bc_all|bc_npc;

            // TODO: Handle players in bridges
            debugmes "[Flood] F - Map Timer OK";
            maptimer("011-3", "#EternalSwampCore::OnBridgeDown", 10);
        } else {
            debugmes "[Flood] NF Aborted";
        }

    }
    debugmes "[Flood] Cycle finished";
    end;

// Fix players struck by setcells
OnBridgeDown:
    debugmes "[Flood] [OnBD] Bridge is Down";
    if (isin(37, 22, 39, 24))
        slide 38, 21;
    else if (isin(37, 34, 39, 41))
        slide 38, 33;
    else if (isin(31, 67, 33, 73))
        slide 32, 65;
    else if (isin(40, 96, 42, 102))
        slide 41, 95;
    else if (isin(38, 130, 40, 136))
        slide 39, 128;
    else if (isin(41, 157, 43, 163))
        slide 42, 155;
    else if (isin(36, 187, 38, 193))
        slide 37, 185;
    debugmes "[Flood] [OnBD] Finished";

    end;
}