Last active
January 22, 2017 05:26
-
-
Save puyo-sh/c387c882a672b2f58c3c4db20ef265ff to your computer and use it in GitHub Desktop.
ブラウザ三国志 鹵獲ツール
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name 3gokushi-RokakuTool | |
// @namespace https://github.com/puyo-sh/bro3 | |
// @description ブラウザ三国志 鹵獲ツール | |
// @include http://*.3gokushi.jp/* | |
// @version 0.2 | |
// @require http://code.jquery.com/jquery-3.1.1.js | |
// @require http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.js | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @grant GM_deleteValue | |
// ==/UserScript== | |
// ver 0.1 | |
// 選択中の拠点にセットされている武将をすべて出兵する | |
// ただし、攻撃の基礎値が3000以上かつ討伐ゲージが100以上とする | |
// その際、利用できるスキルが有る場合は自動で利用する | |
// テスト版 | |
// ver 0.2 | |
// 副将やらなんやらで討伐ゲージが100なくても出発しちゃってたので微調整&バグ修正 | |
// ついでに最低移速制限追加(50)&鹵獲系利用スキルがある場合はそれを優先するようにした(つもり) | |
// おまけでjQueryを3系に(動いたから) | |
j$ = jQuery.noConflict(true); | |
(function ($){ | |
// Chrome用GM_関数 --------------------------------------------------------------------------------- | |
// @copyright 2009, James Campos | |
// @license cc-by-3.0; http://creativecommons.org/licenses/by/3.0/ | |
if ((typeof GM_getValue == 'undefined') || (GM_getValue('a', 'b') == undefined)) { | |
GM_addStyle = function(css) { | |
var style = document.createElement('style'); | |
style.textContent = css; | |
document.getElementsByTagName('head')[0].appendChild(style); | |
}; | |
GM_deleteValue = function(name) { | |
localStorage.removeItem(name); | |
}; | |
GM_getValue = function(name, defaultValue) { | |
var value = localStorage.getItem(name); | |
if (!value) | |
return defaultValue; | |
var type = value[0]; | |
value = value.substring(1); | |
switch (type) { | |
case 'b': | |
return value == 'true'; | |
case 'n': | |
return Number(value); | |
default: | |
return value; | |
} | |
}; | |
GM_log = function(message) { | |
if (window.opera) { | |
opera.postError(message); | |
return; | |
} | |
console.log(message); | |
}; | |
GM_registerMenuCommand = function(name, funk) { | |
//todo | |
}; | |
GM_setValue = function(name, value) { | |
value = (typeof value)[0] + value; | |
localStorage.setItem(name, value); | |
}; | |
} | |
// サーバー名の取得(localstorageのkeyに利用) | |
var serverName = location.hostname.split(".")[0]; | |
// 出兵ボックスを生成 --------------------------------------------------------------------------------- | |
function makeTroopBox(param){ | |
var ls_rokakuXY = GM_getValue(serverName + "_rokakuXY", ""); | |
var param = {}; | |
var rokaku_run = '<a class="rokaku_run">[出兵]</a>'; | |
if(ls_rokakuXY == void(0) || ls_rokakuXY == ""){ | |
param.rokakuXY = '<span style="color:#FF0000">未設定</span>'; | |
}else{ | |
var rokakuXY = JSON.parse(ls_rokakuXY); | |
if(rokakuXY.hasOwnProperty("tree")){ | |
var xy_obj = rokakuXY.tree.match(/([\-0-9]{1,4}),([\-0-9]{1,4})/); | |
param.rokakuTreeXY = '<a href="/land.php?x='+xy_obj[1]+'&y='+xy_obj[2]+'">'+rokakuXY.tree+'</a>'; | |
param.rokakuTreeRun = rokaku_run; | |
}else{ | |
param.rokakuTreeXY = '<span style="color:#FF0000">未設定</span>'; | |
param.rokakuTreeRun = ''; | |
} | |
if(rokakuXY.hasOwnProperty("stone")){ | |
var xy_obj = rokakuXY.stone.match(/([\-0-9]{1,4}),([\-0-9]{1,4})/); | |
param.rokakuStoneXY = '<a href="/land.php?x='+xy_obj[1]+'&y='+xy_obj[2]+'">'+rokakuXY.stone+'</a>'; | |
param.rokakuStoneRun = rokaku_run; | |
}else{ | |
param.rokakuStoneXY = '<span style="color:#FF0000">未設定</span>'; | |
param.rokakuStoneRun = ''; | |
} | |
if(rokakuXY.hasOwnProperty("iron")){ | |
var xy_obj = rokakuXY.iron.match(/([\-0-9]{1,4}),([\-0-9]{1,4})/); | |
param.rokakuIronXY = '<a href="/land.php?x='+xy_obj[1]+'&y='+xy_obj[2]+'">'+rokakuXY.iron+'</a>'; | |
param.rokakuIronRun = rokaku_run; | |
}else{ | |
param.rokakuIronXY = '<span style="color:#FF0000">未設定</span>'; | |
param.rokakuIronRun = ''; | |
} | |
if(rokakuXY.hasOwnProperty("rice")){ | |
var xy_obj = rokakuXY.rice.match(/([\-0-9]{1,4}),([\-0-9]{1,4})/); | |
param.rokakuRiceXY = '<a href="/land.php?x='+xy_obj[1]+'&y='+xy_obj[2]+'">'+rokakuXY.rice+'</a>'; | |
param.rokakuRiceRun = rokaku_run; | |
}else{ | |
param.rokakuRiceXY = '<span style="color:#FF0000">未設定</span>'; | |
param.rokakuRiceRun = ''; | |
} | |
} | |
var troop_html = (function(param){/* | |
<li> | |
<div id="rokakuBox" class="clerfix"> | |
{{html troopXY}} | |
<table> | |
<tr data-type="tree"> | |
<td class="rokaku_target">木:</td> | |
<td>{{html rokakuTreeXY}}</td> | |
<td style="text-align:right">{{html rokakuTreeRun}}</td> | |
</tr> | |
<tr data-type="stone"> | |
<td class="rokaku_target">石:</td> | |
<td>{{html rokakuStoneXY}}</td> | |
<td style="text-align:right">{{html rokakuStoneRun}}</td> | |
</tr> | |
<tr data-type="iron"> | |
<td class="rokaku_target">鉄:</td> | |
<td>{{html rokakuIronXY}}</td> | |
<td style="text-align:right">{{html rokakuIronRun}}</td> | |
</tr> | |
<tr data-type="rice"> | |
<td class="rokaku_target">糧:</td> | |
<td>{{html rokakuRiceXY}}</td> | |
<td style="text-align:right">{{html rokakuRiceRun}}</td> | |
</tr> | |
<tr data-type="random"> | |
<td colspan="3"><a class="rokaku_run">[ランダム出兵]</a></td> | |
</tr> | |
</table> | |
<div id="rokaku_status"></div> | |
</div> | |
<style> | |
<!-- | |
#rokakuBox{ | |
font-size:0.8em; | |
padding:5px; | |
top:0;left:0; | |
background-color:#000000; | |
border:1px solid #FFFFFF; | |
} | |
#rokakuBox .rokaku_target{ | |
color:#FFFFFF; | |
} | |
#troop_xy{ | |
width: 90%; | |
} | |
.rokaku_run{ | |
text-decoration:none; | |
cursor:pointer; | |
} | |
#rokaku_status{ | |
color:yellow; | |
} | |
--> | |
</style> | |
</li> | |
*/}).toString().replace(/(\n)/g, '').split('*')[1]; | |
var html = $.tmpl(troop_html,param) || ''; | |
var $target = $("#sidebar > ul:first-child"); | |
$target.css("position","relative"); | |
$target.append(html); | |
// 出兵ボタンEvent | |
$(".rokaku_run").off("click").on("click",function(){ | |
$("#rokaku_status").empty(); | |
var data_type = $(this).closest("tr").attr("data-type"); | |
var ls_rokakuXY = GM_getValue(serverName + "_rokakuXY", ""); | |
var troopCode = 302; // 賊討伐 | |
if(ls_rokakuXY == void(0) || ls_rokakuXY == ""){ | |
alert("出兵先が未設定です"); | |
return false; | |
} | |
var rokakuXY = JSON.parse(ls_rokakuXY); | |
rokakuXY.data_type = data_type; | |
/* | |
if(data_type == "random"){ | |
// ランダム時処理 | |
console.log(rokakuXY); | |
var rand_keys = Object.keys(rokakuXY); | |
var data_type = rand_keys[Math.floor(Math.random() * rand_keys.length)]; | |
} | |
var troopXY = rokakuXY[data_type]; | |
*/ | |
$("#rokaku_status").append('出兵開始'); | |
var troop_card_Datas = []; | |
var troopDatas = []; | |
/* | |
// 設定中のXY座標を取得する | |
var check_xy = troopXY.match(/([\-0-9]{1,4}),([\-0-9]{1,4})/); | |
if(!$.isArray(check_xy)){ | |
$("#rokaku_status").html('出兵'); | |
alert("出兵先座標の値が不正です"); | |
return false; | |
} | |
var troop_x = parseInt(check_xy[1]); | |
var troop_y = parseInt(check_xy[2]); | |
if(!(troop_x >= -800 && troop_x <= 800 && troop_y >= -800 && troop_y <= 800)){ | |
$("#rokaku_status").html('出兵'); | |
alert("出兵先座標の値が不正です"); | |
return false; | |
} | |
*/ | |
// 出兵画面の情報を取得する | |
var onePageData = getTroopPageData(rokakuXY,troop_card_Datas); | |
onePageData.then( | |
function(){ | |
// 出兵実行 | |
if(troop_card_Datas.length > 0){ | |
$(troop_card_Datas).each(function(index,value){ | |
var oneTroopData = troopRun(value,troopCode); | |
troopDatas.push(oneTroopData); | |
}); | |
$.when.apply($,troopDatas).then( | |
function(){ | |
// location.href="/facility/unit_status.php"; | |
$("#rokaku_status").append('<br>出兵処理完了'); | |
} | |
); | |
}else{ | |
$("#rokaku_status").html('出兵'); | |
alert("出兵可能な武将が存在しません"); | |
return false; | |
} | |
},function(){ | |
} | |
); | |
}); | |
// 出兵画面のデータを取得する | |
function getTroopPageData(rokakuXY,troop_card_Datas){ | |
var d = new $.Deferred; | |
$.ajax({ | |
type: 'get', | |
url: '/facility/castle_send_troop.php?x=0&y=0', | |
dataType: 'html', | |
}).then( | |
function(data){ | |
$(data).find(".bushoList > table:not(:first)").each(function(){ | |
var busho_data = $(this).find("tr").eq(1).find("td").eq(1).html(); | |
var reg_busho_data = busho_data.match(/[-]?[0-9]+(\.[0-9]+)?/g); | |
// [2]:カードID | |
var busho_going = $(this).find("tr:nth-child(2) td:nth-child(1)").text(); | |
var busho_name = $(this).find("tr:nth-child(2) td:nth-child(2) a").text(); | |
var busho_status = $(this).find("tr").eq(1).find("td").eq(2).html(); | |
var reg_busho_status = busho_status.match(/[-]?[0-9]+(\.[0-9]+)?/g); | |
// [0]:HP [1]:討伐ゲージ [2]:攻撃 [4]:速度 | |
// 利用可能なスキルを取得する | |
var $busho_skill_data = $(this).find(".use"); | |
var skill_id = ""; | |
var skill_name = ""; | |
if($busho_skill_data.length > 0){ | |
$busho_skill_data.each(function(){ | |
// スキルIDの取得 | |
skill_id = $(this).find("input[type=radio]").attr("value"); | |
// スキル名の取得 | |
skill_name = $(this).find("a").text(); | |
// 鹵獲スキル優先 | |
if (skill_name.indexOf('鹵獲') > 0 || skill_name.indexOf('劫略') > 0 || skill_name.indexOf('大徳') > 0 ) { | |
return false; | |
} | |
}); | |
} | |
// 出兵条件(攻撃3000以上,速度50以上,討伐ゲージ100以上とする) | |
if(busho_going.indexOf("出兵中") == -1 && parseInt(reg_busho_status[2]) >= 3000 && parseInt(reg_busho_status[4]) >= 50 && parseInt(reg_busho_status[1]) >= 100){ | |
if($.inArray(reg_busho_data[2], troop_card_Datas) == '-1'){ | |
var rokakuXYClone = $.extend(true, {}, rokakuXY); | |
var data_type = rokakuXYClone.data_type; | |
delete rokakuXYClone.data_type; | |
if(data_type == "random"){ | |
// ランダム時処理 | |
console.log(rokakuXYClone); | |
var rand_keys = Object.keys(rokakuXYClone); | |
data_type = rand_keys[Math.floor(Math.random() * rand_keys.length)]; | |
} | |
var troopXY = rokakuXY[data_type]; | |
var check_xy = troopXY.match(/([\-0-9]{1,4}),([\-0-9]{1,4})/); | |
var troop_x = parseInt(check_xy[1]); | |
var troop_y = parseInt(check_xy[2]); | |
var troop_card_Data = { | |
"card_id" :parseInt(reg_busho_data[2]), | |
"skill_id" :skill_id, | |
"skill_name":skill_name, | |
"troop_x":troop_x, | |
"troop_y":troop_y | |
}; | |
troop_card_Datas.push(troop_card_Data); | |
switch(data_type){ | |
case "tree": | |
o_data_type = "木"; | |
break; | |
case "stone": | |
o_data_type = "石"; | |
break; | |
case "iron": | |
o_data_type = "鉄"; | |
break; | |
case "rice": | |
o_data_type = "糧"; | |
break; | |
} | |
$("#rokaku_status").append("<br>"+o_data_type+":"+busho_name+":"+skill_name); | |
} | |
} | |
}); | |
d.resolve(data); | |
},function(data){ | |
d.reject(); | |
} | |
); | |
return d.promise(); | |
} | |
// 出兵処理 | |
function troopRun(troopData,code){ | |
var d = new $.Deferred; | |
var unit_assign_card_id = troopData.card_id; | |
var skill_id = troopData.skill_id; | |
var skill_name = troopData.skill_name; | |
var params = {}; | |
params["village_x_value"] = troopData.troop_x; | |
params["village_y_value"] = troopData.troop_y; | |
params["village_name"] = ""; | |
params["unit_assign_card_id"] = unit_assign_card_id; | |
if(skill_id && code == 302){ | |
params["use_skill_id["+ unit_assign_card_id +"]"] = skill_id; | |
} | |
params["radio_move_type"] = code; // 301:援軍 302:賊討伐 303:強襲 | |
params["radio_reserve_type"] = 0; | |
params["card_id"] = 204; | |
params["btn_send"] = "出兵"; | |
$.ajax({ | |
type: 'post', | |
url: '/facility/castle_send_troop.php', | |
data: params, | |
}).then( | |
function(data){ | |
d.resolve(data); | |
},function(data){ | |
d.reject(); | |
} | |
); | |
return d.promise(); | |
} | |
} | |
// 領地登録ボックスを生成 --------------------------------------------------------------------------------- | |
function makeLandSaveBox(param){ | |
var tmpCurrentLand = $("#basepoint .xy").text(); | |
var regCurrentLand = tmpCurrentLand.match(/(\(.*\))/g); | |
var currentLand = regCurrentLand[0]; | |
var ls_rokakuXY = GM_getValue(serverName + "_rokakuXY"); | |
var param = {}; | |
if(ls_rokakuXY == void(0) || ls_rokakuXY == ""){ | |
param.rokakuXY = '<span style="color:#FF0000">未設定</span>'; | |
}else{ | |
var rokakuXY = JSON.parse(ls_rokakuXY); | |
if(rokakuXY.hasOwnProperty("tree")){ | |
var xy_obj = rokakuXY.tree.match(/([\-0-9]{1,4}),([\-0-9]{1,4})/); | |
param.rokakuTreeXY = '<a href="/land.php?x='+xy_obj[1]+'&y='+xy_obj[2]+'">'+rokakuXY.tree+'</a>'; | |
}else{ | |
param.rokakuTreeXY = '<span style="color:#FF0000">未設定</span>'; | |
param.rokakuTreeRun = ''; | |
} | |
if(rokakuXY.hasOwnProperty("stone")){ | |
var xy_obj = rokakuXY.stone.match(/([\-0-9]{1,4}),([\-0-9]{1,4})/); | |
param.rokakuStoneXY = '<a href="/land.php?x='+xy_obj[1]+'&y='+xy_obj[2]+'">'+rokakuXY.stone+'</a>'; | |
}else{ | |
param.rokakuStoneXY = '<span style="color:#FF0000">未設定</span>'; | |
param.rokakuStoneRun = ''; | |
} | |
if(rokakuXY.hasOwnProperty("iron")){ | |
var xy_obj = rokakuXY.iron.match(/([\-0-9]{1,4}),([\-0-9]{1,4})/); | |
param.rokakuIronXY = '<a href="/land.php?x='+xy_obj[1]+'&y='+xy_obj[2]+'">'+rokakuXY.iron+'</a>'; | |
}else{ | |
param.rokakuIronXY = '<span style="color:#FF0000">未設定</span>'; | |
param.rokakuIronRun = ''; | |
} | |
if(rokakuXY.hasOwnProperty("rice")){ | |
var xy_obj = rokakuXY.rice.match(/([\-0-9]{1,4}),([\-0-9]{1,4})/); | |
param.rokakuRiceXY = '<a href="/land.php?x='+xy_obj[1]+'&y='+xy_obj[2]+'">'+rokakuXY.rice+'</a>'; | |
}else{ | |
param.rokakuRiceXY = '<span style="color:#FF0000">未設定</span>'; | |
param.rokakuRiceRun = ''; | |
} | |
} | |
var troop_html = (function(param){/* | |
<div id="landRokakuDataBox"> | |
鹵獲ツール<br /> | |
<table> | |
<tr data-type="tree"> | |
<td>木:</td> | |
<td><span class="troop_land_xy">{{html rokakuTreeXY}}</span></td> | |
<td><a class="save">[登録]</a></td> | |
<td><a class="del">[解除]</a></td> | |
</tr> | |
<tr data-type="stone"> | |
<td>石:</td> | |
<td><span class="troop_land_xy">{{html rokakuStoneXY}}</span></td> | |
<td><a class="save">[登録]</a></td> | |
<td><a class="del">[解除]</a></td> | |
</tr> | |
<tr data-type="iron"> | |
<td>鉄:</td> | |
<td><span class="troop_land_xy">{{html rokakuIronXY}}</span></td> | |
<td><a class="save">[登録]</a></td> | |
<td><a class="del">[解除]</a></td> | |
</tr> | |
<tr data-type="rice"> | |
<td>糧:</td> | |
<td><span class="troop_land_xy">{{html rokakuRiceXY}}</span></td> | |
<td><a class="save">[登録]</a></td> | |
<td><a class="del">[解除]</a></td> | |
</tr> | |
</table> | |
</div> | |
<style> | |
<!-- | |
#landRokakuDataBox{ | |
width:200px; | |
padding:5px; | |
background-color:#FFFFFF; | |
border:1px solid #000000; | |
color:#333333; | |
} | |
#landRokakuDataBox a{ | |
color:#0000DD; | |
cursor:pointer; | |
} | |
#landRokakuDataBox span{ | |
color:#DD0000; | |
} | |
--> | |
</style> | |
*/}).toString().replace(/(\n)/g, '').split('*')[1]; | |
var html = $.tmpl(troop_html,param) || ''; | |
$("#tMenu_btnif").append(html); | |
// 登録無し 解除ボタンを非表示にする | |
$("#landRokakuDataBox .troop_land_xy").each(function(){ | |
if($(this).find(":contains('未設定')").length > 0){ | |
$(this).closest("tr").find("a.del").hide(); | |
} | |
}); | |
// 登録ボタンEvent | |
$("#landRokakuDataBox a.save").off("click").on("click",function(){ | |
// 登録データを取得 | |
var ls_rokakuXY = GM_getValue(serverName + "_rokakuXY", ""); | |
if(ls_rokakuXY == void(0) || ls_rokakuXY == ""){ | |
rokakuXY = {}; | |
}else{ | |
rokakuXY = JSON.parse(ls_rokakuXY); | |
} | |
// localstorageにデータを保存 | |
var data_type = $(this).closest("tr").attr("data-type"); | |
rokakuXY[data_type] = currentLand; | |
GM_setValue(serverName + "_rokakuXY",JSON.stringify(rokakuXY)); | |
$("#rokakuBox").closest("li").remove(); | |
makeTroopBox(); | |
$("#landRokakuDataBox").remove(); | |
makeLandSaveBox(); | |
alert("「"+currentLand+"」を出兵先として登録しました"); | |
}); | |
// 解除ボタンEvent | |
$("#landRokakuDataBox a.del").off("click").on("click",function(){ | |
// 登録データを取得 | |
var ls_rokakuXY = GM_getValue(serverName + "_rokakuXY", ""); | |
if(ls_rokakuXY == void(0) || ls_rokakuXY == ""){ | |
return false; | |
}else{ | |
rokakuXY = JSON.parse(ls_rokakuXY); | |
// 対象データを削除してlocalstorageにデータを更新 | |
var data_type = $(this).closest("tr").attr("data-type"); | |
delete rokakuXY[data_type]; | |
GM_setValue(serverName + "_rokakuXY",JSON.stringify(rokakuXY)); | |
} | |
$("#rokakuBox").closest("li").remove(); | |
makeTroopBox(); | |
$("#landRokakuDataBox").remove(); | |
makeLandSaveBox(); | |
}); | |
} | |
// Run | |
makeTroopBox(); | |
if (location.pathname == '/land.php') { | |
makeLandSaveBox(); | |
} | |
})(j$); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment