viewing paste rA-115861-w randomize_woe_castle | Athena

Posted on the | Last edited on
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
// https://rathena.org/board/topic/115861-woe-random-castle/
 
//  remember to disable these links
//== npc\guild\agit_controller.txt
//== npc\guild2\agit_start_se.txt
//== npc\re\guild3\agit_start_te.txt
 
function    script  F_ShuffleNumbers    {
    deletearray getarg(2);
    .@static = getarg(0);
    .@range = getarg(1) +1 - .@static;
    .@count = getarg(3, .@range);
    if (.@range <= 0 || .@count <= 0)
        return 0;
    if (.@count > .@range)
        .@count = .@range;
    for (.@i = 0; .@i < .@range; ++.@i)
        .@temparray[.@i] = .@i;
    for (.@i = 0; .@i < .@count; ++.@i) {
        .@rand = rand(.@range);
        set getelementofarray( getarg(2), .@i ), .@temparray[.@rand] + .@static;
        .@temparray[.@rand] = .@temparray[--.@range];
    }
    return .@count;
}
 
-   script  castle_randomize    -1,{
OnInit:
    for ( .@i = 0; .@i < 8; ++.@i )
        .castle$[.@i] = "06guild_0"+( .@i +1 );
    end;
OnClock2100:
    agitstart;
    end;
OnClock2200:
    agitend;
    end;
OnAgitStart:
    if ( gettime(DT_HOUR) != 21 ) end;
    // luckily 8/2 has no remainder
    if ( !getarraysize( $castle_random$ ) ) {
        callfunc "F_ShuffleNumbers", 0, 7, .@r;
        for ( .@i = 0; .@i < 8; ++.@i )
            $castle_random$[.@i] = .castle$[ .@r[.@i] ];
    }
    sleep 100;
    announce "The Castles open today are "+ getcastlename( $castle_random$[0] ) +" and "+  getcastlename( $castle_random$[1] ) +" !!", bc_woe;
    for ( .@i = 0; .@i < 8; ++.@i ) {
        if ( .castle$[.@i] != $castle_random$[0] && .castle$[.@i] != $castle_random$[1] ) {
            removemapflag .castle$[.@i], mf_gvg_castle;
            killmonster .castle$[.@i], "custom_castle#"+ charat( .castle$[.@i], 9 ) +"::OnEmpBreak";            
        }   
    }
    deletearray $castle_random$, 2;
//  for ( .@i = 0; .@i < 8; ++.@i )
//      announce getcastlename( .castle$[.@i] ), bc_all, ( ( getmapflag( .castle$[.@i], mf_gvg_castle ) )? 0x00FF00 : 0xFF0000 ) ;
    end;
OnAgitEnd:
    for ( .@i = 0; .@i < 8; ++.@i )
        if ( !getmapflag( .castle$[.@i], mf_gvg_castle ) )
            setmapflag .castle$[.@i], mf_gvg_castle;
    end;
}
 
/* db\castle_db.txt
51,06guild_01,Custom Castle 1,custom_castle#1
52,06guild_02,Custom Castle 2,custom_castle#2
53,06guild_03,Custom Castle 3,custom_castle#3
54,06guild_04,Custom Castle 4,custom_castle#4
55,06guild_05,Custom Castle 5,custom_castle#5
56,06guild_06,Custom Castle 6,custom_castle#6
57,06guild_07,Custom Castle 7,custom_castle#7
58,06guild_08,Custom Castle 8,custom_castle#8
*/
 
06guild_01,53,53,3  script  custom_castle#1 GUILD_FLAG,{
    .@gid = getcastledata( strnpcinfo(4), 1 );
    dispbottom "=========================";
    dispbottom "castle map : "+ getcastlename( strnpcinfo(4) );
    dispbottom "owner of the castle : "+( ( .@gid )? "["+ getguildname(.@gid) +"]" : "<none>" );
    dispbottom "agit check : "+( ( agitcheck() )?"on":"off" );
    dispbottom "gvg_castle mapflag : "+( ( getmapflag( strcharinfo(3), mf_gvg_castle )?"on":"off" ) );
    dispbottom "=========================";
    end;
OnInit:
    if ( agitcheck() )
        donpcevent strnpcinfo(0)+"::OnAgitStart";
    setmapflag strnpcinfo(4), mf_gvg_castle;
    flagemblem getcastledata( strnpcinfo(4), 1 );
    end;
OnAgitStart:
    monster strnpcinfo(4),49,49,"EMPERIUM",1288,1,strnpcinfo(0)+"::OnEmpBreak";
    setunitdata $@mobid, UMOB_HP, 5;
    end;
OnAgitEnd:
    killmonster strnpcinfo(4), strnpcinfo(0)+"::OnEmpBreak";
    end;
OnEmpBreak:
    announce "The Emperium has fallen", bc_woe;
    setcastledata strnpcinfo(4), 1, getcharid(2);
    donpcevent strnpcinfo(0)+"::OnRecvCastle123";
    sleep 6750;
    if ( agitcheck() )
        goto OnAgitStart;
    end;
OnAgitInit:
    requestguildinfo getcastledata( strnpcinfo(4), 1 );
OnRecvCastle123:
    flagemblem getcastledata( strnpcinfo(4), 1 );
    end;
OnGuildBreak:
    setcastledata strnpcinfo(4), 1, 0;
    donpcevent strnpcinfo(0)+"::OnRecvCastle123";
    end;
}
06guild_02,53,53,3  duplicate(custom_castle#1)  custom_castle#2 GUILD_FLAG
06guild_03,53,53,3  duplicate(custom_castle#1)  custom_castle#3 GUILD_FLAG
06guild_04,53,53,3  duplicate(custom_castle#1)  custom_castle#4 GUILD_FLAG
06guild_05,53,53,3  duplicate(custom_castle#1)  custom_castle#5 GUILD_FLAG
06guild_06,53,53,3  duplicate(custom_castle#1)  custom_castle#6 GUILD_FLAG
06guild_07,53,53,3  duplicate(custom_castle#1)  custom_castle#7 GUILD_FLAG
06guild_08,53,53,3  duplicate(custom_castle#1)  custom_castle#8 GUILD_FLAG
Viewed 1197 times, submitted by AnnieRuru.