').appendTo( $body )
.on( 'click', function() {
self.remove();
});
}
if( $('#TB_window').length == 0 ) {
$('
').appendTo( $body )
}
var queryString;
if( url.search(/#TB_inline/) != -1 ) {
queryString = url.slice( url.search(/#TB_inline/) );
}
queryString = queryString.replace(/^[^\?]+\??/,'');
var params = this.parseQuery( queryString );
var TB_WIDTH = (params['width' ]*1) + 30 || 630, //defaults to 630 if no paramaters were added to URL
TB_HEIGHT = (params['height']*1) + 40 || 440, //defaults to 440 if no paramaters were added to URL
ajaxContentW = TB_WIDTH - 30,
ajaxContentH = TB_HEIGHT - 45;
var html = '' +
'
' +
'
' + caption + '
' +
'
' +
'
' +
'
' +
'';
$('#TB_window').append( html );
$("#TB_ajaxContent").append( $('#' + params['inlineId']).children() );
// unload時に元に戻す
$("#TB_window").unload(function () {
$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() );
});
this.position( TB_WIDTH, TB_HEIGHT );
$('#TB_closeWindowButton').click( this.remove );
$('#TB_overlay,#TB_window').show();
return false;
},
parseQuery: function( query ) {
var Params = {};
if ( !query ) { return Params; }
var Pairs = query.split(/[;&]/);
for ( var i = 0; i < Pairs.length; i++ ) {
var KeyVal = Pairs[i].split('=');
if ( ! KeyVal || KeyVal.length != 2 ) { continue; }
var key = unescape( KeyVal[0] );
var val = unescape( KeyVal[1] );
val = val.replace(/\+/g, ' ');
Params[key] = val;
}
return Params;
},
position: function( w, h ) {
$("#TB_window").css({marginLeft: '-' + parseInt((w / 2),10) + 'px', width: w + 'px'});
$("#TB_window").css({marginTop: '-' + parseInt((h / 2),10) + 'px'});
},
remove: function() {
$('#TB_window').fadeOut('fast', function() {
$('#TB_window,#TB_overlay').trigger('unload').off().remove();
});
},
show: function( caption, url ) {
this.showCore( caption, url );
// ここに独自実装を追加
//カードウィンドウチェック
if ( url.indexOf('cardWindow') == -1 ) { return; }
$tb = $('#TB_ajaxContent');
//微調整
$tb.css({ height: 'auto' });
margintop = -Math.floor( $('#TB_window').height() / 2 - 20 );
if ( margintop < -350 ) { margintop = -350; }
$('#TB_window').css({ marginTop: margintop });
if ( $tb.find('.imc_table').length > 0 ) { return; }
var card = new Card( $tb ),
list = [], type, html, html2, $table;
//仮想の兵数セット
card.solNum = card.maxSolNum;
type = '長槍足軽 武士 長弓兵 弓騎馬 雑賀衆 精鋭騎馬 赤備え 騎馬鉄砲 焙烙火矢 鉄砲足軽'.split(' ');
$.each( type, function( idx, key ) {
//仮想の兵種セット
card.solName = key;
card.power();
list.push({
solName: card.solName,
atk: Math.floor( card.totalAtk ),
def: Math.floor( card.totalDef ),
costDef: Math.floor( card.totalDef / card.cost )
});
})
html = '
' +
'兵種 | 攻撃力 | 防御力 | 防 / C | ' +
'兵種 | 攻撃力 | 防御力 | 防 / C |
';
for ( var i = 0, len = Math.ceil( list.length / 2 ); i < len; i++ ) {
var left = list[ i ],
right = list[ len + i ];
html += '';
html += '' + left.solName + ' | ' +
'' + left.atk.toFormatNumber() + ' | ' +
'' + left.def.toFormatNumber() + ' | ' +
'' + left.costDef.toFormatNumber() + ' | ';
if ( right ) {
html += '' + right.solName + ' | ' +
'' + right.atk.toFormatNumber() + ' | ' +
'' + right.def.toFormatNumber() + ' | ' +
'' + right.costDef.toFormatNumber() + ' | ';
}
else {
html += ' | ';
}
html += '
';
}
html += '
';
//スキル候補
var { table, table_s1, s2, s2_s1 } = Util.getSkillCandidate( card.skillList );
html += '
' +
'' +
'候補A | ' +
'候補B | ' +
'候補C | ' +
'候補D | ' +
'S2 | ' +
'
' +
'';
html2 = '';
for ( var i = 0, len = table.length; i < len; i++ ) {
html += '' + table[ i ] + ' | ';
html2 += '' + table_s1[ i ] + ' | ';
}
for ( var i = table.length; i < 4; i++ ) {
html += '- | ';
html2 += '- | ';
}
html += '' + ( ( s2 ) ? s2 : '-' ) + ' | ';
html2 += '' + ( ( s2_s1 ) ? s2_s1 : '-' ) + ' | ';
html += '
' + html2 + '
';
html += '
';
$table = $( html ).appendTo( $tb );
$table.find('TR').filter(':even').css({ backgroundColor: '#eee' });
margintop = -Math.floor( $('#TB_window').height() / 2 - 20 );
if ( margintop < -350 ) { margintop = -350; }
$('#TB_window').css({ marginTop: margintop });
$tb.find('IMG[src$="nouryoku_title_white.png"]').parent().remove();
$tb.find('#trade_btn').css('padding-bottom', '10px');
$tb.find('#table_posi').css('background-color', '#000');
if ( card.rarity == '雅' ) {
$tb.find('.ig_card_cost').removeClass('ig_card_cost').addClass('ig_card_cost_over');
}
},
replaceClass: function() {
$('A.thickbox').removeClass('thickbox').addClass('metabox');
}
});
Metabox.replaceClass();
var selector = 'A.metabox';
$(document)
.on('click', selector, function() {
var caption = this.title || this.name || null,
anchor = this.href || this.alt;
Metabox.show( caption, anchor );
this.blur();
return false;
});
return Metabox;
})();
//■■■■■■■■■■■■■■■■■■■
//■ Env
var Env = (function() {
var storage = MetaStorage('ENVIRONMENT'),
$server = $('#server_time'),
$war = $('.situationWorldTable'),
world = ( location.hostname.match(/(\S+\d{2,3})/) || [] )[1],
start = ( document.cookie.match( new RegExp( world + '_st=(\\d+)' ) ) || [] )[1],
login = false, season, newseason, chapter, war, server_time, local_time, timeDiff, endtime;
$.ajaxSetup( { beforeSend: function( xhr ) { xhr.setRequestHeader('X-Requested-With', ' ') } } );
//storageから取得
endtime = storage.get('endtime');
season = storage.get('season');
chapter = storage.get('chapter');
if ( $server.length == 0 ) {
timeDiff = 0;
}
else {
//鯖との時差取得
server_time = new Date( $server.text().replace(/-/g, '/') ).getTime(),
local_time = new Date().getTime();
timeDiff = ( server_time - local_time );
}
if ( world && start ) {
login = true;
//クッキーから取得
newseason = ( document.cookie.match( new RegExp( world + '_s=(\\d+)' ) ) || [] )[1];
chapter = ( document.cookie.match( new RegExp( world + '_c=(\\d+)' ) ) || [] )[1];
//鯖との時差も含めてタイムアウト時間を設定(カウントダウンで鯖時間を使用する為)
endtime = start.toInt() + (3 * 60 * 60) + Math.floor( timeDiff / 1000 );
newseason = newseason.toInt();
chapter = chapter.toInt();
storage.begin();
storage.set( 'endtime', endtime );
storage.set( 'season', newseason );
storage.set( 'chapter', chapter );
storage.commit();
document.cookie = world + '_st=0; expires=Fri, 31-Dec-1999 23:59:59 GMT; domain=.sengokuixa.jp; path=/;';
document.cookie = world + '_s=0; expires=Fri, 31-Dec-1999 23:59:59 GMT; domain=.sengokuixa.jp; path=/;';
document.cookie = world + '_c=0; expires=Fri, 31-Dec-1999 23:59:59 GMT; domain=.sengokuixa.jp; path=/;';
if ( newseason !== season ) {
//期が変わった場合
'VILLAGE FACILITY ALLIANCE COUNTDOWN UNIT_STATUS USER_FALL USER_INFO FAVORITE_UNIT'.split(' ').forEach(function( value ) {
MetaStorage( value ).clear();
});
'1 2 3 4 5 6 7 8 9 10 11 12 20 21'.split(' ').forEach(function( value ) {
MetaStorage( 'COORD.' + value ).clear();
});
season = newseason;
}
}
if ( $war.find('IMG[src$="icon_warnow_new.png"]').length > 0 ) {
war = 2;
}
else if ( $war.find('IMG[src$="icon_warnow.png"]').length > 0 ) {
war = 1;
}
else {
war = 0;
}
if ( login && war == 0 ) {
MetaStorage('USER_FALL').clear();
MetaStorage('USER_INFO').clear();
}
return {
//. loginProcess
loginProcess: login,
//. world - 鯖
world: world,
//. season - 期
season: season,
//. chapter - 章
chapter: chapter,
//. war - 合戦 0:無し 1:通常合戦 2:新合戦
war: war,
//. timeDiff - 鯖との時差
timeDiff: timeDiff,
//. path - アクセスパス
path: location.pathname.match( /[^\/]+(?=(\/|\.))/g ) || [],
//. externalFilePath - 外部ファイルへのパス
externalFilePath: (function() {
var href = $('LINK[type="image/x-icon"][href^="http://cache"]').attr('href') || '';
href = href.match(/^.+(?=\/)/) || '';
return href;
})(),
//. loginState - ログイン状態
loginState: (function() {
var path = location.pathname;
if ( $('#lordName').length == 1 ) { return 1; }
if ( path == '/world/select_world.php' ) { return 0; }
if ( path == '/user/first_login.php' ) { return 0; }
if ( path == '/false/login_sessionout.php' ) { return -1; }
if ( path == '/maintenance/' ) { return -1; }
return -1;
})(),
//. endtime - タイムアウト期限
endtime: endtime,
//. ajax - 一部のajax通信の判定に使用
ajax: false
};
})();
//■ Util
var Util = {
//. getLocalTime
getLocalTime: function() {
return ~~( new Date().getTime() / 1000 );
},
//. getServerTime
getServerTime: function() {
return ~~( ( new Date().getTime() + Env.timeDiff ) / 1000 );
},
//. getTargetDate
getTargetDate: function( time, clock ) {
clock = clock.split(':');
var date = new Date(),
sec = ( clock[0].toInt() * 3600 ) + ( clock[1].toInt() * 60 ) + clock[2].toInt();
date.setTime( ( Util.getServerTime() + sec ) * 1000 );
return ~~( date.getTime() / 1000 );
},
//. getUserInfo
getUserInfo: function( userid, receive ) {
var storage = MetaStorage('USER_INFO'),
key = 'U' + userid,
info, url;
info = storage.get( key );
if ( info ) { return info; }
if ( receive === false ) { return null; }
info = {};
url = '/user/';
if ( userid ) { url += '?user_id=' + userid; }
$.ajax({ type: 'get', url: url, async: false })
.done(function( html ) {
var $html = $(html),
$profile = $html.find('.profile'),
$table = $html.find('TABLE.common_table1'),
base = [], camp = [], territory = 0, campc, text;
info.userId = userid;
if ( $profile.find('.busho_info_profile').length ) {
info.name = $profile.find('.card_profile_para').text().trim();
}
else {
info.name = $profile.find('.para:first').text().trim();
}
info.lv = $profile.find('.pro1 .para').text().match(/\d+/)[ 0 ].toInt();
info.pop = $profile.find('.pro3 .ranking').remove().end().find('.pro3 .para').text().toInt();
text = $profile.find('.family_name .name').text();
info.country = $.inArray( text, Data.countries );
info.alliance = $profile.find('A[href^="/alliance/info.php"]').text();
info.allianceId = $profile.find('A[href^="/alliance/info.php"]').attr('href').match(/id=(\d+)/)[ 1 ].toInt();
info.managerial = $profile.find('.pro5 .para').text().trim();
info.scale = $profile.find('.pro6 .ranking').remove().end().find('.pro6 .para').text().match(/\d+/)[ 0 ].toInt();
$table.find('TR.fs14').each(function() {
var $this = $(this),
type = $this.find('TD').eq( 0 ).text(),
pop = $this.find('TD').eq( 3 ).text().toInt() || '-',
$a = $this.find('A'),
name = $a.eq( 0 ).text().trim(),
point = $a.eq( 1 ).attr('href').match(/x=(-?\d+)&y=(-?\d+)&c=(\d+)/),
x = point[ 1 ].toInt(),
y = point[ 2 ].toInt(),
c = point[ 3 ].toInt();
if ( type == '本領' || type == '所領' || type == '出城' ) {
base.push({ type: type, name: name, x: x, y: y, c: c, pop: pop });
}
else if ( type == '陣' ) {
camp.push([ x, y ]);
campc = c;
}
else if ( type == '領地' ) {
territory++;
}
});
info.base = base;
info.camp = camp;
info.campc = campc;
info.territory = territory;
});
info.ranking = [ info.pop, '-', '-', '-', '-', '-', '-' ];
info.warRanking = [ '-', '-', '-', '-' ];
storage.set( key, info );
return info;
},
//. getUserRanking
getUserRanking: function( userid ) {
var storage = MetaStorage('USER_INFO'),
key = 'U' + userid,
info = storage.get( key ),
url;
url = '/user/ranking.php?m=total&find_rank=&find_name=' + encodeURIComponent( info.name ) + '&c=0';
$.ajax({ type: 'get', url: url, async: false })
.done(function( html ) {
var $html = $(html),
$td = $html.find('TR.now TD');
info.ranking = [
info.pop,
$td.eq( 4 ).text().toInt() || 0,
$td.eq( 5 ).text().toInt() || 0,
$td.eq( 6 ).text().toInt() || 0,
$td.eq( 8 ).text().toInt() || 0
];
});
url = '/user/ranking.php?m=attack_score&find_rank=&find_name=' + encodeURIComponent( info.name ) + '&c=0';
$.ajax({ type: 'get', url: url, async: false })
.done(function( html ) {
var $html = $(html),
$td = $html.find('TR.now TD');
info.ranking.push( $td.eq( 4 ).text().toInt() || 0 );
info.ranking.push( $td.eq( 5 ).text().toInt() || 0 );
});
url = '/war/war_ranking.php?m=&c=' + info.country + '&find_rank=&find_name=' + encodeURIComponent( info.name );
$.ajax({ type: 'get', url: url, async: false })
.done(function( html ) {
var $html = $(html),
$td = $html.find('TR.ig_rank_you TD');
info.warRanking = [
$td.eq( 3 ).text().toInt() || 0,
$td.eq( 4 ).text().toInt() || 0,
$td.eq( 5 ).text().toInt() || 0,
$td.eq( 6 ).text().toInt() || 0
];
});
storage.set( key, info );
},
//. getUserCamp
getUserCamp: function( userid ) {
var storage = MetaStorage('USER_INFO'),
key = 'U' + userid,
info = storage.get( key ),
url;
url = '/user/';
if ( userid ) { url += '?user_id=' + userid; }
$.ajax({ type: 'get', url: url, async: false })
.done(function( html ) {
var $html = $(html),
$table = $html.find('TABLE.common_table1'),
base = [], camp = [], campc, territory = 0;
$table.find('TR.fs14').each(function() {
var $this = $(this),
type = $this.find('TD').eq( 0 ).text(),
pop = $this.find('TD').eq( 3 ).text().toInt() || '-',
$a = $this.find('A'),
name = $a.eq( 0 ).text().trim(),
point = $a.eq( 1 ).attr('href').match(/x=(-?\d+)&y=(-?\d+)&c=(\d+)/),
x = point[ 1 ].toInt(),
y = point[ 2 ].toInt(),
c = point[ 3 ].toInt();
if ( type == '本領' || type == '所領' || type == '出城' ) {
base.push({ type: type, name: name, x: x, y: y, c: c, pop: pop });
}
else if ( type == '陣' ) {
camp.push([ x, y ]);
campc = c;
}
else if ( type == '領地' ) {
territory++;
}
});
for ( var i = 0, len = base.length; i < len; i++ ) {
let { x, y, c } = base[ i ];
for ( var j = 0, lenj = info.base.length; j < lenj; j++ ) {
let { x: nx, y: ny, c: nc } = info.base[ j ];
if ( x == nx && y == ny && c == nc ) {
base[ i ].fall = info.base[ j ].fall;
break;
}
}
}
info.base = base;
info.camp = camp;
info.campc = campc;
info.territory = territory;
});
storage.set( key, info );
},
//. getVillageByName
getVillageByName: function( name ) {
var list = MetaStorage('VILLAGE').get('list') || [];
for ( var i = 0, len = list.length; i < len; i++ ) {
if ( list[ i ].name != name ) { continue; }
return list[ i ];
}
//キャッシュで見つからない場合は最新情報取得
list = Util.getVillageList();
for ( var i = 0, len = list.length; i < len; i++ ) {
if ( list[ i ].name != name ) { continue; }
return list[ i ];
}
return null;
},
//. getVillageById
getVillageById: function( id ) {
var list = MetaStorage('VILLAGE').get('list') || [];
for ( var i = 0, len = list.length; i < len; i++ ) {
if ( list[ i ].id != id ) { continue; }
return list[ i ];
}
//キャッシュで見つからない場合は最新情報取得
list = Util.getVillageList();
for ( var i = 0, len = list.length; i < len; i++ ) {
if ( list[ i ].id != id ) { continue; }
return list[ i ];
}
return null;
},
//. getVillageByCoord
getVillageByCoord: function( x, y, country ) {
var list = MetaStorage('VILLAGE').get('list') || [];
for ( var i = 0, len = list.length; i < len; i++ ) {
if ( list[ i ].x != x ) { continue; }
if ( list[ i ].y != y ) { continue; }
if ( list[ i ].country != country ) { continue; }
return list[ i ];
}
//キャッシュで見つからない場合は最新情報取得
list = Util.getVillageList();
for ( var i = 0, len = list.length; i < len; i++ ) {
if ( list[ i ].x != x ) { continue; }
if ( list[ i ].y != y ) { continue; }
if ( list[ i ].country != country ) { continue; }
return list[ i ];
}
return null;
},
//. getVillageList
getVillageList: function() {
var list = [];
$.ajax({ type: 'get', url: '/user/', async: false })
.done(function( html ) {
var $html = $(html),
$table = $html.find('TABLE.common_table1');
//本領所領
$table.eq( 0 ).find('TR.fs14').each(function() {
var $this = $(this),
type = $this.find('TD').eq( 0 ).text(),
$a = $this.find('A'),
name = $a.eq( 0 ).text().trim(),
id = $a.eq( 0 ).attr('href').match(/village_id=(\d+)/)[ 1 ],
point = $a.eq( 1 ).attr('href').match(/x=(-?\d+)&y=(-?\d+)&c=(\d+)/),
x = point[ 1 ].toInt(),
y = point[ 2 ].toInt(),
country = point[ 3 ].toInt(),
fall = $this.find('TD').eq( 4 ).find('.red').length;
list.push({ type: type, id: id, name: name, x: x, y: y, country: country, fall: fall });
});
//出城・陣・領地
$table.eq( 1 ).find('TR.fs14').each(function() {
var $this = $(this),
type = $this.find('TD').eq( 0 ).text(),
$a = $this.find('A'),
name = $a.eq( 0 ).text().trim(),
id = $a.eq( 0 ).attr('href').match(/village_id=(\d+)/)[ 1 ],
point = $a.eq( 1 ).attr('href').match(/x=(-?\d+)&y=(-?\d+)&c=(\d+)/),
x = point[ 1 ].toInt(),
y = point[ 2 ].toInt(),
country = point[ 3 ].toInt(),
fall = $this.find('TD').eq( 4 ).find('.red').length;
list.push({ type: type, id: id, name: name, x: x, y: y, country: country, fall: fall });
});
MetaStorage('VILLAGE').set('list', list);
});
return list;
},
//. getVillageCurrent
getVillageCurrent: function() {
var name = $('#imi_basename .imc_basename .on > SPAN').text();
return Util.getVillageByName( name );
},
//. getVillageNearby
getVillageNearby: function( x, y, country ) {
var list = Util.getVillageList(),
minDist = Number.MAX_VALUE,
village, territory;
list.forEach(function( value ) {
if ( value.country != country ) { return; }
if ( value.type == '領地' ) { return; }
if ( value.fall == 1 ) { return; }
var dist = Util.getDistance( { x: x, y: y }, value );
if ( dist >= minDist ) { return; }
minDist = dist;
value.dist = dist;
village = value;
});
minDist = Number.MAX_VALUE;
list.forEach(function( value ) {
if ( value.country != country ) { return; }
if ( value.type != '領地' ) { return; }
var dist = Util.getDistance( { x: x, y: y }, value );
if ( dist >= minDist ) { return; }
minDist = dist;
value.dist = dist;
territory = value;
});
if ( village && territory && village.dist <= territory.dist ) {
territory = undefined;
}
return { village: village, territory: territory };
},
//. getVillageChangeUrl
getVillageChangeUrl: function( village_id, returnUrl ) {
return '/village_change.php?village_id=' + village_id + '&from=menu&page=' + encodeURIComponent( returnUrl );
},
//. getTrainingStatus
getTrainingStatus: function( $table ) {
$.Deferred().resolve()
.pipe(function() {
if ( $table ) { return $table; }
return $.get( '/facility/unit_list.php' )
.pipe(function( html ) {
return $(html).find('TABLE.table_fightlist2').slice( 1 );
});
})
.pipe(function( $table ) {
var data = {};
$table.each(function() {
var $this = $(this),
$tr = $this.find('TR'),
name = $tr.eq( 0 ).find('A').text(),
village = Util.getVillageByName( name ),
list = [];
$tr.slice( 1 ).each(function() {
var $this = $(this),
name = $this.find('IMG').attr('alt'),
date = $this.find('TD').last().text();
list.push( [ date.getTime(), name ] );
});
data[ village.id ] = list;
});
MetaStorage('COUNTDOWN').set('訓練', data);
});
},
//. getPoolSoldiers
getPoolSoldiers: function() {
var data = {};
$.ajax({ type: 'get', url: '/facility/unit_list.php', async: false })
.pipe(function( html ) {
var $html = $( html ),
$table, $cell, text;
text = $html.find('.ig_solder_commentarea').text().split('/')[ 1 ].trim();
data.capacity = text.toInt();
data.soldier = $html.find('#all_pool_unit_cnt').text().toInt();
data.pool = {};
data.training = [];
$table = $html.find('.ig_fight_dotbox');
$table.first().find('TH').each(function() {
var $this = $(this),
type = Soldier.getType( $this.text() ),
pool = $this.next().text().toInt();
data.pool[ type ] = pool;
});
$table.eq( 1 ).find('.table_fightlist2').each(function() {
var $tr = $(this).find('TR'),
name = $tr.first().find('A').text(),
village = Util.getVillageByName( name );
$tr.slice( 1 ).each(function() {
var $td = $(this).find('TD');
type = Soldier.getType( $td.eq( 0 ).find('IMG').attr('alt') ),
num = $td.eq( 1 ).text().toInt(),
finish = $td.eq( 3 ).text().getTime();
data.training.push({ id: village.id, type: type, num: num, finish: finish });
});
});
});
return data;
},
//. getUnitStatusCD
getUnitStatusCD: function() {
var build = MetaStorage('SETTINGS').get('build') || 0;
if ( build & 0x04 || location.pathname == '/map.php' ) {
Util.getUnitStatus();
}
},
//. getUnitStatusDelay
getUnitStatusDelay: function() {
var delay = MetaStorage('COUNTDOWN').get('delaytime') || 0,
time = Util.getLocalTime();
if ( delay < time ) {
MetaStorage('COUNTDOWN').set('delaytime', delay + 3);
window.setTimeout( Util.getUnitStatus, 3000 );
}
},
//. getUnitStatus
getUnitStatus: function( $table ) {
return $.Deferred().resolve()
.pipe(function() {
if ( $table ) { return $table; }
return Page.get( '/facility/unit_status.php?dmo=all' )
.pipe(function( html ) {
return $(html).find('.ig_decksection_innermid');
});
})
.pipe(function( $section ) {
var list = [], cards = [];
$section.find('.ig_fight_statusarea').each(function() {
var $this = $(this),
$panel = $this.find('.paneltable'),
$a1, $a2, name, arrival, target, base1, base2,
startpoint, targetpoint, startx, starty, endx, endy, country,
mode, count;
//部隊名
name = $this.find('H3').text().match(/\[(.+)\]/)[ 1 ];
//着弾時間
arrival = $panel.find('TR:eq(0) TD:eq(0)').text() || '';
arrival = ( arrival.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/) || [ 0 ] )[ 0 ];
if ( arrival ) {
arrival = new Date( arrival.replace(/-/g, '/') ).getTime() / 1000;
}
$a1 = $panel.find('TR:eq(2) TD:eq(0) A:eq(0)');
if ( $a1.length != 0 ) {
//拠点
base1 = $a1.text().trim();
//座標
startpoint = $a1.attr('href').match(/x=(-?\d+)&y=(-?\d+)&c=(\d+)/);
startx = startpoint[ 1 ].toInt();
starty = startpoint[ 2 ].toInt();
}
$a2 = $panel.find('TR:eq(2) TD:eq(1) A:eq(0)');
if ( $a2.length != 0 ) {
//拠点
base2 = $a2.text().trim();
//座標
targetpoint = $a2.attr('href').match(/x=(-?\d+)&y=(-?\d+)&c=(\d+)/);
endx = targetpoint[ 1 ].toInt();
endy = targetpoint[ 2 ].toInt();
country = targetpoint[ 3 ].toInt();
//目的地
target = base2;
}
//行動
mode = $this.find('TR:eq(1) TD:eq(1) IMG').attr('src') || '';
if ( mode.indexOf('_attack.png') != -1 ) {
count = $this.find('TR:eq(0) TD:eq(2)').text();
mode = ( count == '-' ) ? '陣張' : '攻撃';
}
else if ( mode.indexOf('_develop.png') != -1 ) {
mode = '開拓';
}
else if ( mode.indexOf('_meeting.png') != -1 ) {
mode = '合流';
}
else if ( mode.indexOf('_backup.png') != -1 ) {
mode = '加勢';
}
else if ( mode.indexOf('_return.png') != -1 || mode.indexOf('_back.png') != -1 ) {
mode = '帰還';
target = base1;
[ startx, starty, endx, endy ] = [ endx, endy, startx, starty ];
}
else if ( mode.indexOf('_dungeon.png') != -1 ) {
mode = '探索';
base1 = target = $panel.find('TR:eq(1) TD:eq(2) SPAN').text().trim();
}
else if ( mode.indexOf('_raidboss.png') != -1 ) {
mode = '討伐';
base1 = target = $panel.find('TR:eq(1) TD:eq(2) SPAN').text().trim();
}
else if ( mode.indexOf('_move.png') != -1 ) {
mode = '国移';
}
else if ( mode.indexOf('_wait.png') != -1 ) {
mode = '待機';
}
else {
//modeが取得できない時は加勢待機中(IMGタグではなくcssのbackgroundを使用している為)
mode = '加待';
}
list.push({ name: name, mode: mode, base: base1, target: target, arrival: arrival, sx: startx, sy: starty, ex: endx, ey: endy, ec: country });
$this.find('.waitingleader A').each(function() {
var card_id = $(this).attr('href').match(/cardWindow_(\d+)/)[ 1 ],
$card = $section.find('#cardWindow_' + card_id);
cards.push( new Card( $card ) );
});
});
MetaStorage('UNIT_STATUS').set('部隊', list);
$('#imi_unitstatus').trigger('update');
$('#imi_basename').trigger('update');
return cards;
});
},
//. getBaseList
getBaseList: function( country ) {
return $.get('/war/war_briefing.php')
.pipe(function( html ) {
var $html = $(html),
$ul = $html.find('#ig_battle_status_tozai_brf UL'),
$map = $html.find('#ig_battle_status_map'),
name = $html.find('.westTeam IMG').eq( 0 ).attr('title'),
list = [], countrys = [], $img;
if ( country == 21 ) {
//第二組
$img = $ul.slice( 2, 4 ).find('LI IMG');
}
else {
//第一組
$img = $ul.slice( 0, 2 ).find('LI IMG');
}
$img.each(function() {
countrys.push( $(this).attr('title') );
});
$map.find('A[href^="/map.php"]').each(function( idx ) {
var $this = $(this),
point = $this.attr('href').match(/x=(-?\d+)&y=(-?\d+)/),
name = countrys[ (idx < 6) ? idx: Math.floor( (idx-5) / 9 ) ],
gage = ( $this.prev('img.btIconGauge').attr('src').match(/_gauge_(\d+).png/) || [,0] )[1].toInt(),
data;
data = { name: name, x: point[1].toInt(), y: point[2].toInt(), color: (idx < 6) ? '#f00': '#fff', gage: gage };
// 並べ替え(大殿城-各国砦1~各国砦8)
var a = (idx < 6) ? idx: (((idx-6)%8)+1)*6+Math.floor((idx-6)/8);
list[a] = data;
});
return list;
});
},
//. getFee
getFee: function( price ) {
var fee = 0;
if ( price <= 500 ) {
fee = Math.floor( price * 0.1 );
}
else if ( price <= 1000 ) {
fee = Math.floor( price * 0.2 ) - 50;
}
else {
fee = Math.floor( price * 0.3 ) - 150;
}
return fee;
},
//. getDistance
getDistance: function( point1, point2 ) {
if ( typeof( point1 ) == 'string' ) {
point1 = point1.replace(/[\(\) ]/g, '').match(/(-?\d+),(-?\d+)/);
if ( point1 == null ) {
point1 = { x: 0, y: 0 };
}
else {
point1 = { x: point1[1].toInt(), y: point1[2].toInt() };
}
}
if ( typeof( point2 ) == 'string' ) {
point2 = point2.replace(/[\(\) ]/g, '').match(/(-?\d+),(-?\d+)/);
if ( point2 == null ) {
point2 = { x: 0, y: 0 };
}
else {
point2 = { x: point2[1].toInt(), y: point2[2].toInt() };
}
}
var x = Math.pow( point2.x - point1.x, 2 ),
y = Math.pow( point2.y - point1.y, 2 ),
distance = Math.sqrt( x + y );
return distance;
},
//. getExpectPower
getExpectPower: function( cards ) {
var int = cards.reduce(function( prev, curr ) { return prev + curr.int; }, 0),
max = Math.max.apply( null, cards.map(function( card ) { return card.int; }) ),
intMod = ( ( int - max ) / 600 ) + ( max / 100 ),
result = { '将': { atk: 0, def: 0 }, '上': { atk: 0, def: 0 } },
atk_mod = {}, def_mod = {};
cards.forEach(function( card ) {
var type = Soldier.getByName( card.solName ).skillType,
mod = Soldier.modify( card.solName, card.commands );
//atk, defは素の状態の為補正
result['将'].atk += card.atk * mod / 100;
result['将'].def += card.def * mod / 100;
if ( $.inArray( card.solName, [ '武士', '弓騎馬', '赤備え', '騎馬鉄砲' ] ) != -1 ) {
result['上'].atk += card.totalAtk;
result['上'].def += card.totalDef;
}
if ( !result[ type ] ) { result[ type ] = { atk: 0, def: 0 }; }
result[ type ].atk += card.totalAtk;
result[ type ].def += card.totalDef;
$.each( card.getSkillModify( '攻', intMod ), function( key, value ) {
if ( !atk_mod[ key ] ) { atk_mod[ key ] = 0; }
atk_mod[ key ] += value;
});
$.each( card.getSkillModify( '防', intMod ), function( key, value ) {
if ( !def_mod[ key ] ) { def_mod[ key ] = 0; }
def_mod[ key ] += value;
});
});
var atk = 0, def = 0;
$.each( result, function( key, elem ) {
var atkMod = 0, defMod = 0;
if ( atk_mod[ key ] ) { atkMod += atk_mod[ key ]; }
if ( atk_mod['全'] && key != '将' && key != '上' ) { atkMod += atk_mod[ '全' ]; }
if ( def_mod[ key ] ) { defMod += def_mod[ key ]; }
if ( def_mod['全'] && key != '将' && key != '上' ) { defMod += def_mod[ '全' ]; }
atk += elem.atk * atkMod / 100;
def += elem.def * defMod / 100;
});
return { atk: atk, def: def };
},
//. getSpeed
getSpeed: function( cards, unitskill ) {
var speed_list = {}, speed_mod = {}, min_speed = Number.MAX_VALUE;
for ( var i = 0, len = cards.length; i < len; i++ ) {
var card = cards[ i ];
data = Soldier.getByName( card.solName );
if ( !data ) { return 0; }
if ( !speed_list[ data.skillType ] ) {
speed_list[ data.skillType ] = data.speed;
}
else if ( data.speed < speed_list[ data.skillType ] ) {
speed_list[ data.skillType ] = data.speed;
}
$.each( card.getSkillModify( '速' ), function( key, value ) {
if ( !speed_mod[ key ] ) { speed_mod[ key ] = 0; }
speed_mod[ key ] += value;
});
}
$.each( speed_list, function( key, value ) {
var mod = 100, speed;
if ( speed_mod[ key ] ) { mod += speed_mod[ key ]; }
if ( speed_mod[ '全' ] ) { mod += speed_mod[ '全' ]; }
speed = value * mod / 100;
if ( speed < min_speed ) { min_speed = speed; }
});
if ( min_speed === Number.MAX_VALUE ) {
min_speed = 0;
}
if ( unitskill ) {
min_speed = min_speed * ( 100 + unitskill ) / 100;
}
return ( Env.war == 2) ? min_speed * 2: min_speed;
},
//. getNpcPower
getNpcPower: function( rank, materials ) {
var npc = Data.npcPower || Data.getNpcPower();
return npc[ rank + '-' + materials ];
},
//. getNext20Exp
getNext20Exp: function( rank, exp ) {
var next20 = [ 20546, 134144, 408474, 906404, 1766164, 3163879 ][ rank ];
return next20 - exp;
},
//. getSkillCandidate
getSkillCandidate: function( skill_list ) {
var list = [], list_s1 = [],
[ skill1, skill2, skill3 ] = skill_list,
skill, s1, s2, s2_s1;
skill = Data.skillTable[ skill1.name ];
if ( skill ) {
list.push( skill[ 0 ] || '不明A' );
list.push( skill[ 1 ] || '不明B' );
list.push( skill[ 2 ] || '不明C' );
s1 = skill[ 3 ] || '不明S1';
s2 = skill[ 4 ] || '不明S2';
}
else {
list.push( '不明A' );
list.push( '不明B' );
list.push( '不明C' );
s1 = '不明S1';
s2 = '不明S2';
}
if ( skill2 ) {
skill = Data.skillTable[ skill2.name ];
if ( skill ) {
list.push( skill[ 3 ] || '不明S1' );
}
}
if ( skill3 ) {
skill = Data.skillTable[ skill3.name ];
if ( skill ) {
list.push( skill[ 3 ] || '不明S1' );
}
}
list = list.slice( -3 );
list.push( s1 );
list = list.unique();
//候補のs1を取得
list.forEach(function( value ) {
var skill = Data.skillTable[ value ];
if ( skill ) {
list_s1.push( skill[ 3 ] || '不明S1' );
}
else {
list_s1.push( '不明S1' );
}
});
skill = Data.skillTable[ s2 ];
if ( skill ) {
s2_s1 = skill[ 3 ] || '不明S1';
}
else {
s2_s1 = '不明S1';
}
return { table: list, table_s1: list_s1, s2: s2, s2_s1: s2_s1 };
},
//. getConsumption
getConsumption: function( materials, number ) {
var modRate = 1, idx;
if ( number >= 5 ) {
idx = Math.floor( number / 10 );
if ( idx > 10 ) { idx = 10; }
modRate = [ 0.98, 0.96, 0.94, 0.94, 0.94, 0.92, 0.92, 0.92, 0.92, 0.92, 0.90 ][ idx ];
}
return materials.map(function( value ) {
return ( value * modRate ).toRound( 0 ) * number;
});
},
//. getFacility
getFacility: function( name ) {
var data = MetaStorage('FACILITY').data,
list = [];
for ( var vid in data ) {
let facility_list = data[ vid ],
village = Util.getVillageById( vid ),
facility;
if ( !village ) { continue; }
if ( facility_list[ name ] && facility_list[ name ].lv >= 1 ) {
facility = $.extend( { id: vid, name: village.name }, facility_list[ name ] );
list.push( facility );
}
}
return list;
},
//. getMarket
getMarket: function() {
var rates = [ 0, 0.4, 0.42, 0.44, 0.46, 0.48, 0.5, 0.52, 0.54, 0.56, 0.60 ],
list = Util.getFacility('市'),
market;
if ( list.length == 0 ) { return null; }
list.sort(function( a, b ) {
return ( b.lv > a.lv );
});
list[ 0 ].rate = rates[ list[ 0 ].lv ];
return list[ 0 ];
},
//. getResource
getResource: function() {
return [
$('#wood').text().toInt(),
$('#stone').text().toInt(),
$('#iron').text().toInt(),
$('#rice').text().toInt()
];
},
//. getProduction
getProduction: function() {
return [
$('#output_wood').text().toInt(),
$('#output_stone').text().toInt(),
$('#output_iron').text().toInt(),
$('#output_rice').text().toInt()
];
},
//. getUranai
getUranai: function() {
var $img = $('#status .rightF IMG');
if ( $img.length == 0 ) { return [ 1, 1, 1 ]; }
return $img.map(function() {
return ( 100 - $(this).attr('src').match(/_(\d)s/)[ 1 ].toInt() ) / 100;
});
},
//. checkExchange
checkExchange: function( resource, requirements, rate ) {
var shortage = 0, surplus = 0;
if ( isNaN( rate ) ) { rate = ( Util.getMarket() || { rate: 0 } ).rate; }
for ( var i = 0, len = resource.length; i < len; i++ ) {
if ( resource[ i ] >= requirements[ i ] ) {
surplus += resource[ i ] - requirements[ i ];
}
else {
shortage += requirements[ i ] - resource[ i ];
}
}
return ( shortage == 0 ) ? 2 : ( surplus * rate >= shortage ) ? 1 : 0;
},
//. getExchangePlan
getExchangePlan: function( resource, requirements, rate, type ) {
var surplus = [], shortage = [], totalSurplus, totalShortage;
'木 綿 鉄 糧'.split(' ').forEach(function( type, idx ) {
var value = resource[ idx ] - requirements[ idx ];
if ( value > 0 ) { surplus.push({ type: type, value: value }); }
else if ( value < 0 ) { shortage.push({ type: type, value: -value }); }
});
totalSurplus = surplus.reduce(function( prev, curr ) { return prev += curr.value; }, 0 );
totalShortage = shortage.reduce(function( prev, curr ) { return prev += curr.value; }, 0 );
totalShortage = Math.ceil( totalShortage / rate );
if ( totalSurplus < totalShortage ) {
return [];
}
if ( type == 'A' ) {
var modify = surplus.sort(function( a, b ) {
return ( b.value > a.value );
})
.reduce(function( prev, curr, idx ) {
if ( curr.value > prev.avg ) {
prev.value = prev.value + curr.value;
prev.avg = Math.floor( ( prev.value - totalShortage ) / ( idx + 1 ) );
}
return prev;
}, { value: 0, avg: 0 });
totalSurplus = 0;
surplus = surplus.map(function( elem ) {
elem.value -= modify.avg;
if ( elem.value < 0 ) { elem.value = 0; }
totalSurplus += elem.value;
return elem;
});
}
surplus = surplus.map(function( elem ) {
elem.ratio = elem.value / totalSurplus;
return elem;
});
var plans = [];
shortage.forEach(function( short ) {
surplus.forEach(function( plus ) {
var value = Math.ceil( short.value * plus.ratio ),
fixed;
if ( value == 0 ) { return; }
fixed = Math.floor( ( value - 1 ) / rate ) + 1;
value = Math.floor( value / rate );
if ( Math.ceil( value * rate ) == Math.ceil( fixed * rate ) ) { value = fixed; }
if ( value < 10 ) { value = 10; }
plans.push({ from: plus.type, to: short.type, value: value, receive: Math.ceil( value * rate ) });
});
});
return plans;
},
//. getValidSoldiers
getValidSoldiers: function( facility ) {
var url = Util.getVillageChangeUrl( facility.id, '/facility/facility.php?x=' + facility.x + '&y=' + facility.y ),
soldiers = [];
$.ajax({ type: 'get', url: url, async: false })
.pipe(function( html ) {
$(html).find('.ig_tilesection_innermid, .ig_tilesection_innermid2').each(function() {
var $this = $(this),
name, materials, soldata;
if ( $this.find('H3').length == 0 ) { return; }
if ( $this.find('H3 A').length > 0 ) { return; }
name = $this.find('H3').text().match(/\[(.*)\]/)[ 1 ];
materials = [
$this.find('.icon_wood').text().match(/(\d+)/)[ 1 ].toInt(),
$this.find('.icon_cotton').text().match(/(\d+)/)[ 1 ].toInt(),
$this.find('.icon_iron').text().match(/(\d+)/)[ 1 ].toInt(),
$this.find('.icon_food').text().match(/(\d+)/)[ 1 ].toInt()
];
soldata = Soldier.getByName( name );
image = $this.find('.ig_tilesection_iconarea IMG').attr('src');
soldiers.push({ type: soldata.type, name: name, materials: materials, training: soldata.training, image: image, order: soldata.order });
});
});
return soldiers.reverse();
},
//. getMaxTraining
getMaxTraining: function( resource, requirements, rate, max, min ) {
var c, materials, check, result = min;
while ( min <= max ) {
c = Math.floor( ( max + min ) / 2 );
materials = Util.getConsumption( requirements, c );
check = Util.checkExchange( resource, materials, rate );
if ( check == 0 ) {
max = c - 1;
}
else {
result = c;
min = c + 1;
}
}
return result;
},
//. divide
divide: function( list, soldata, solnum ) {
var uranai = Util.getUranai(),
facilities = [], maxidx = 0, total = 0, soltotal = 0;
for ( var i = 0, len = list.length; i < len; i++ ) {
let facility = $.extend( { type: soldata.type }, list[ i ] );
if ( Env.chapter <= 5 ) {
facility.mod = Math.pow( 0.8, facility.lv - 1 );
facility.rate = Math.pow( 1 / 0.8, facility.lv - 1 );
}
else {
facility.rate = soldata.training[ 0 ] / soldata.training[ facility.lv - 1 ];
}
total += facility.rate;
facilities.push( facility );
}
if ( facilities.length == 1 ) {
//施設が1つの場合、分配しない
facilities[ 0 ].solnum = solnum;
}
else {
for ( var i = 0, len = facilities.length; i < len; i++ ) {
let facility = facilities[ i ];
facility.rate = facility.rate / total;
facility.solnum = Math.floor( solnum * facility.rate );
soltotal += facility.solnum;
if ( facility.lv > facilities[ maxidx ].lv ) { maxidx = i; }
}
if ( soltotal != solnum ) {
//小数点以下を切り捨てているので、不足分はLVが一番高い施設で調整
facilities[ maxidx ].solnum += ( solnum - soltotal );
}
}
for ( var i = 0, len = facilities.length; i < len; i++ ) {
let facility = facilities[ i ];
facility.materials = Util.getConsumption( soldata.materials, facility.solnum );
if ( Env.chapter <= 5 ) {
facility.trainingtime = Math.ceil( facility.solnum * soldata.training * facility.mod * uranai[ 1 ] );
}
else {
facility.trainingtime = Math.floor( facility.solnum * soldata.training[ facility.lv - 1 ] * uranai[ 1 ] );
}
// 9章以降ではここの訓練時間は使わない
}
return facilities;
},
//. divide2
divide2: function( list, soldata, time ) {
var uranai = Util.getUranai(),
facilities = [], total = 0;
for ( var i = 0, len = list.length; i < len; i++ ) {
let facility = $.extend( { type: soldata.type }, list[ i ] );
if ( Env.chapter <= 5 ) {
facility.mod = Math.pow( 0.8, facility.lv - 1 );
facility.solnum = Math.floor( time / facility.mod / soldata.training / uranai[ 1 ] );
facility.trainingtime = Math.ceil( facility.solnum * soldata.training * facility.mod * uranai[ 1 ] );
}
else {
facility.solnum = Math.floor( time / soldata.training[ facility.lv - 1 ] / uranai[ 1 ] );
facility.trainingtime = Math.floor( facility.solnum * soldata.training[ facility.lv - 1 ] * uranai[ 1 ] );
}
facility.materials = Util.getConsumption( soldata.materials, facility.solnum );
total += facility.solnum;
facilities.push( facility );
}
facilities.totalnum = total;
return facilities;
},
//. searchFavoriteUnit
searchFavoriteUnit: function( cards ) {
var list = MetaStorage('FAVORITE_UNIT').get('list') || [];
list = list.filter(function( unit ) {
return unit.cardlist.every(function( cardid ) {
return cards.some(function( elem ) { return elem.cardId == cardid; });
})
});
return list;
},
//. searchFavoriteUnitSkill
searchFavoriteUnitSkill: function( cards ) {
var list, unitskill;
list = Util.searchFavoriteUnit( cards );
if ( list.length >= 1 ) {
unitskill = Math.max.apply( null, list.map(function( unit ) { return unit.skill; }) );
}
else {
unitskill = 0;
}
return unitskill;
},
//. searchTradeCardNo
searchTradeCardNo: function( card_no ) {
GM_openInTab( location.origin + '/card/trade.php?t=no&k=' + card_no + '&s=price&o=a');
},
//. searchTradeSkill
searchTradeSkill: function( name ) {
name = encodeURIComponent( name );
GM_openInTab( location.origin + '/card/trade.php?t=skill&k=' + name + '&s=price&o=a');
},
//. unionCardParam
unionCardParam: function( card ) {
return {
id: card.cardId,
name: card.name,
rarity: card.rarity,
rank: card.rank,
lv: card.lv,
rankup: card.canRankup(),
skilllvup: card.canSkillLvup(),
skilladd: card.canSkillAdd(),
skillslot2: card.useSkillSlot2(),
rankupslot2: card.useRankupSlot2(),
skillCount: card.skillCount
};
},
//. keyBindCallback
keyBindCallback: function( callback ) {
return function( key, event ) {
var tag = event.target.tagName.toUpperCase();
if ( tag == 'INPUT' || tag == 'TEXTAREA' ) {
return true;
}
if ( $.isFunction( callback ) ) {
return callback.call( null, key, event );
}
}
},
//. keyBindCommon
keyBindCommon: function() {
$(document).keybind({
'n': Util.keyBindCallback(function() {
location.href = '/village.php';
}),
'm': Util.keyBindCallback(function() {
location.href = '/map.php';
}),
'e': Util.keyBindCallback(function() {
var $curr, $next, href;
if ( location.pathname == '/map.php' ) { return; }
$curr = $('#imi_basename .on');
$next = $curr.next();
if ( $next.length == 0 ) { $next = $curr.parent().children('LI').first(); }
href = $next.find('A').attr('href');
if ( href ) { location.href = href; }
}),
'q': Util.keyBindCallback(function() {
var $curr, $prev, href;
if ( location.pathname == '/map.php' ) { return; }
$curr = $('#imi_basename .on');
$prev = $curr.prev();
if ( $prev.length == 0 ) { $prev = $curr.parent().children('LI').last(); }
href = $prev.find('A').attr('href');
if ( href ) { location.href = href; }
}),
'1': Util.keyBindCallback(function() {
location.href = '/card/deck.php?ano=0';
}),
'2': Util.keyBindCallback(function() {
location.href = '/card/deck.php?ano=1';
}),
'3': Util.keyBindCallback(function() {
location.href = '/card/deck.php?ano=2';
}),
'4': Util.keyBindCallback(function() {
location.href = '/card/deck.php?ano=3';
}),
'5': Util.keyBindCallback(function() {
location.href = '/card/deck.php?ano=4';
}),
't': Util.keyBindCallback(function() {
location.href = '/card/trade.php?t=name&k=&s=no&o=a';
}),
'A-1': Util.keyBindCallback(function() {
if ( location.pathname == '/card/deck.php' ) { return; }
if ( Deck.dialog.opened ) {
$('#imi_unit_tab LI').eq( 0 ).trigger('click');
}
else {
Deck.dialog( null, null, null, null, 0 );
}
}),
'A-2': Util.keyBindCallback(function() {
if ( location.pathname == '/card/deck.php' ) { return; }
if ( Deck.dialog.opened ) {
$('#imi_unit_tab LI').eq( 1 ).trigger('click');
}
else {
Deck.dialog( null, null, null, null, 1 );
}
}),
'A-3': Util.keyBindCallback(function() {
if ( location.pathname == '/card/deck.php' ) { return; }
if ( Deck.dialog.opened ) {
$('#imi_unit_tab LI').eq( 2 ).trigger('click');
}
else {
Deck.dialog( null, null, null, null, 2 );
}
}),
'A-4': Util.keyBindCallback(function() {
if ( location.pathname == '/card/deck.php' ) { return; }
if ( Deck.dialog.opened ) {
$('#imi_unit_tab LI').eq( 3 ).trigger('click');
}
else {
Deck.dialog( null, null, null, null, 3 );
}
}),
'A-5': Util.keyBindCallback(function() {
if ( location.pathname == '/card/deck.php' ) { return; }
if ( Deck.dialog.opened ) {
$('#imi_unit_tab LI').eq( 4 ).trigger('click');
}
else {
Deck.dialog( null, null, null, null, 4 );
}
}),
'u': Util.keyBindCallback(function() {
location.href = '/union/index.php';
}),
'l': Util.keyBindCallback(function() {
location.href = '/senkuji/senkuji.php';
}),
'c': Util.keyBindCallback(function() {
location.href = '/alliance/chat_view.php?ct=1&pager_select=100';
}),
'b': Util.keyBindCallback(function() {
location.href = '/bbs/topic_view.php';
}),
'r': Util.keyBindCallback(function() {
location.href = '/report/list.php';
}),
'i': Util.keyBindCallback(function() {
location.href = '/message/inbox.php';
}),
'f': Util.keyBindCallback(function() {
location.href = '/facility/set_unit_list.php?show_num=100';
}),
':': Util.keyBindCallback(function() {
$.noop();
}),
'?': Util.keyBindCallback(function() {
if( $('#keyboardHelp').size() == 0 ) {
let style =
'div.kbdtitle { font-family:MeiryoKe_PGothic,"Helvetica Neue",Arial,Helvetica,"Lucida Grande","Hiragino Kaku Gothic ProN","ヒラギノ角ゴ ProN W3",Meiryo,メイリオ,"Meiryo UI",sans-serif; font-size:16px; margin-bottom: 1em;}' +
'div.kbd { font-family:MeiryoKe_PGothic,"Helvetica Neue",Arial,Helvetica,"Lucida Grande","Hiragino Kaku Gothic ProN","ヒラギノ角ゴ ProN W3",Meiryo,メイリオ,"Meiryo UI",sans-serif; font-size:14px; float: left; width: 50%; }' +
'span.kbd { font-size: 1em; margin: 0; }' +
'dt.kbd { width: 6em; height: 0; text-align: right; margin-top: 0.5em; font: inherit; }' +
'dd.kbd { margin-left: 7em; }';
GM_addStyle( style );
let html =
'
キーボードショートカット一覧
' +
'
' +
'
各画面共通' +
'
' +
'- n
' + '- 拠点画面へ移動
' +
'- m
' + '- 地図画面へ移動
' +
'
' +
'- 1
' + '- 部隊編成画面で1部隊目を開く
' +
'- 2
' + '- 部隊編成画面で2部隊目を開く
' +
'- 3
' + '- 部隊編成画面で3部隊目を開く
' +
'- 4
' + '- 部隊編成画面で4部隊目を開く
' +
'- 5
' + '- 部隊編成画面で5部隊目を開く
' +
'
' +
'- Alt-1
' + '- 部隊編成ダイアログで1部隊目を開く
' +
'- Alt-2
' + '- 部隊編成ダイアログで2部隊目を開く
' +
'- Alt-3
' + '- 部隊編成ダイアログで3部隊目を開く
' +
'- Alt-4
' + '- 部隊編成ダイアログで4部隊目を開く
' +
'- Alt-5
' + '- 部隊編成ダイアログで5部隊目を開く
' +
'
' +
'- t
' + '- 取引画面へ移動
' +
'- u
' + '- 合成画面へ移動
' +
'- l
' + '- 戦国くじ画面へ移動
' +
'- c
' + '- 同盟チャットへ移動
' +
'- b
' + '- 同盟掲示板へ移動
' +
'- r
' + '- 報告書一覧へ移動
' +
'- i
' + '- 受信箱へ移動
' +
'- f
' + '- 兵士編成画面へ移動
' +
'- ?
' + '- キーボードショートカット一覧(この画面)を開く
' +
'
' +
'
' +
'
' +
'
内政画面' +
'
' +
'- e
' + '- 次の拠点を選択する
' +
'- q
' + '- 前の拠点を選択する
' +
'
' +
'
' +
'
地図画面' +
'
' +
'- w
' + '- 北に1画面分移動する
' +
'- s
' + '- 南に1画面分移動する
' +
'- a
' + '- 西に1画面分移動する
' +
'- d
' + '- 東に1画面分移動する
' +
'- e
' + '- 次の拠点を中心に表示する
' +
'- q
' + '- 前の拠点を中心に表示する
' +
'- z
' + '- ミニマップを拡大表示する
' +
'
' +
'
' +
'
ページャー' +
'
' +
'- e
' + '- 前のページを表示する
' +
'- q
' + '- 次のページを表示する
' +
'
' +
'
' +
'
件名選択' +
'
' +
'- w
' + '- 前の項目を表示する
' +
'- s
' + '- 次の項目を選択する
' +
'
' +
'
';
$('
' + html + '
').appendTo('body');
$('
').appendTo('body');
}
$('#keyboardHelpAnchor').click();
}),
});
},
//. keyBindPager
keyBindPager: function() {
var in_process = false;
$(document).keybind({
'a': Util.keyBindCallback(function() {
var $a = $('UL.pager LI:first A:last');
if ( $a.length == 1 && !in_process ) {
in_process = true;
location.href = $a.attr('href');
}
return false;
}),
'd': Util.keyBindCallback(function() {
var $a = $('UL.pager LI:last A:first');
if ( $a.length == 1 && !in_process ) {
in_process = true;
location.href = $a.attr('href');
}
return false;
})
});
},
//. keyBindMap
keyBindMap: function() {
$(document).keybind({
'w': Util.keyBindCallback(function() {
$('#ig_cur01_w').click();
}),
'd': Util.keyBindCallback(function() {
$('#ig_cur02_w').click();
}),
's': Util.keyBindCallback(function() {
$('#ig_cur03_w').click();
}),
'a': Util.keyBindCallback(function() {
$('#ig_cur04_w').click();
}),
'z': Util.keyBindCallback(function() {
$('#imi_map_zoom').click();
}),
'e': Util.keyBindCallback(function() {
var $curr, $next, village;
$curr = $('#imi_basename .imc_selected');
if ( $curr.length == 0 ) { $curr = $('#imi_basename .on'); }
{
$next = $curr.next();
if ( $next.length == 0 ) { $next = $curr.parent().children('LI').first(); }
village = Util.getVillageByName( $next.children().first().text() );
} while( !village );
$curr.removeClass('imc_selected');
$next.addClass('imc_selected');
Map.move( village.x, village.y, village.country );
}),
'q': Util.keyBindCallback(function() {
var $curr, $prev, village;
$curr = $('#imi_basename .imc_selected');
if ( $curr.length == 0 ) { $curr = $('#imi_basename .on'); }
{
$prev = $curr.prev();
if ( $prev.length == 0 ) { $prev = $curr.parent().children('LI').last(); }
village = Util.getVillageByName( $prev.children().first().text() );
} while( !village );
$curr.removeClass('imc_selected');
$prev.addClass('imc_selected');
Map.move( village.x, village.y, village.country );
})
});
},
//. senkuji
senkuji: function( count, ol, token ) {
if ( !ol ) { ol = Display.dialog({ height: 350 }); }
ol.message('クジを引いています...');
var dfd = $.Deferred();
if( !token ) {
$.get('/senkuji/senkuji.php')
.done( function( html ) {
token = $(html).find('INPUT[name=senkuji_token]').val();
dfd.resolve();
});
}
else {
dfd.resolve();
}
dfd.done( function() {
if ( count <= 1 ) {
Page.form('/senkuji/senkuji.php', {
send: 'send',
got_type: 0,
senkuji_token: token
});
return;
}
$.post('/senkuji/senkuji.php', {
send: 'send',
got_type: 0,
senkuji_token: token
})
.pipe(function( html ) {
var $html = $(html),
storage = MetaStorage('UNION_CARD'),
slot1 = storage.get('slot1'),
slot2 = storage.get('slot2'),
materials = storage.get('materials') || [],
$card, card;
$card = $html.find('.cardstatus');
if ( $card.length == 0 ) {
ol.message('クジ結果を取得できませんでした。');
return;
}
card = new Card( $card );
ol.message( '
' );
ol.message( card.cardNo + ' 「' + card.name + '」を引きました。').message('
');
//ベースカード情報がない場合
if ( !slot1 ) { return; }
if ( !slot2 ) {
//スロット2が空
slot2 = Util.unionCardParam( card );
storage.set('slot2', slot2 );
}
else if ( slot2.id != card.cardId ) {
if ( materials.every(function( elem ) { return elem.id != card.cardId; }) ) {
materials.push( Util.unionCardParam( card ) );
storage.set('materials', materials);
}
}
})
.pipe(function() { return Util.wait( 500 ); })
.always(function() {
count--;
Util.senkuji( count, ol, token );
});
});
},
//. wait
wait: function( ms ) {
var dfd = $.Deferred();
window.setTimeout( function() { dfd.resolve(); }, ms );
return dfd;
},
//. enter
enter: function() { $(this).addClass('imc_current'); },
//. leave
leave: function() { $(this).removeClass('imc_current'); },
//. countDown
countDown: (function() {
var EventListener = new Object(),
countdown_list, timer;
//.. init
function init() {
countdown_list = [];
$('.imc_countdown').each(function() {
var $this = $(this);
countdown_list.push({
target: $this,
display: $this.find('.imc_countdown_display')
});
});
}
//.. start
function start() {
var now = Util.getServerTime(),
event_list = {};
countdown_list = $.map( countdown_list, function( countdown ) {
var $this = countdown.target,
{ endtime, alert, alertevent, finishevent } = $this.data(),
sec = endtime - now;
if ( sec < 0 ) { sec = 0; }
if ( countdown.display ) {
countdown.display.text( sec.toFormatTime() );
}
if ( sec == 0 ) {
if ( !$this.hasClass('imc_countdown_finish') ) {
$this.addClass('imc_countdown_alert imc_countdown_finish');
if ( finishevent ) {
if ( !event_list[ finishevent ] ) { event_list[ finishevent ] = []; };
event_list[ finishevent ].push( $this );
}
}
return null;
}
alert = alert || -1;
if ( sec <= alert ) {
if ( !$this.hasClass('imc_countdown_alert') ) {
$this.addClass('imc_countdown_alert');
if ( alertevent ) {
if ( !event_list[ alertevent ] ) { event_list[ alertevent ] = []; };
event_list[ alertevent ].push( $this );
}
}
}
return countdown;
});
//event fire
$.each( event_list, function( key ) { $(EventListener).trigger( key, event_list[ key ] ); } );
timer = window.setTimeout( arguments.callee, 1000 );
}
$(EventListener)
.on('buildfinish', function() {
var list = Array.prototype.slice.call( arguments, 1 ),
html = '
- 建設が完了しました。
';
list.forEach(function( $elem ) {
html += '- ' + $elem.data('message') + '
';
});
html += '
';
Display.info( html, true );
})
.on('breakfinish', function() {
var list = Array.prototype.slice.call( arguments, 1 ),
html = '
- 削除が完了しました。
';
list.forEach(function( $elem ) {
html += '- ' + $elem.data('message') + '
';
});
html += '
';
Display.info( html, true );
})
.on('trainingfinish', function() {
var list = Array.prototype.slice.call( arguments, 1 ),
html = '
- 訓練が完了しました。
';
list.forEach(function( $elem ) {
html += '- ' + $elem.data('message') + '
';
});
html += '
';
Display.info( html, true );
})
.on('actionfinish', function() {
var list = Array.prototype.slice.call( arguments, 1 ),
html = '
- 部隊の行動が完了しました。
';
list.forEach(function( $elem ) {
html += '- ' + $elem.data('message') + '
';
});
html += '
';
Display.info( html, true );
//部隊情報更新
Util.getUnitStatusDelay();
})
.on('actionrefresh', function() {
//部隊情報更新
Util.getUnitStatusDelay();
})
.on('recoveryfinish', function() {
var list = Array.prototype.slice.call( arguments, 1 ),
html = '
- 武将のHPが全快しました。
';
list.forEach(function( $elem ) {
html += '- ' + $elem.data('message') + '
';
});
html += '
';
Display.info( html, true );
})
.on('raidlistupdate', function() {
window.setTimeout( function() { $('#imi_raid_list').trigger('update'); }, 1000 );
})
.on('raidlistupdate2', function() {
window.setTimeout( function() {
$('#imi_raid_list').trigger('update');
if ( Data.sounds.enemy_raid ) {
//アラーム
var audio = new Audio( Data.sounds.enemy_raid );
audio.volume = 0.6;
audio.play();
}
}, 1000 );
})
.on('sessionalert', function() {
Display.alert('まもなくセッションタイムアウトします。');
})
.on('sessiontimeout', function() {
Display.alert('セッションタイムアウトしました。
再ログインしてください。');
});
//.. return
return function() {
if ( timer ) { window.clearTimeout( timer ); }
init();
start();
};
})(),
//. Content Script Injection
// ContentScriptとUserScriptの実行コンテキストが分離したため
// UserScriptをContentPageにスクリプトを埋め込む
scriptInjection: function( source ) {
if( 'function' == typeof source ) {
source = '(' + source.toString() + ')()';
}
var $script = $('