noname/game/game.js

20809 lines
610 KiB
JavaScript
Raw Normal View History

2015-04-29 03:25:17 +00:00
"use strict";
(function(){
var _status={
paused:false,
paused2:false,
over:false,
clicked:false,
auto:false,
event:{
finished:true,
next:[],
},
ai:{},
2015-11-01 07:54:42 +00:00
lastdragchange:[],
skillaudio:[],
2015-11-09 03:15:16 +00:00
dieClose:[]
2015-04-29 03:25:17 +00:00
};
var lib={
2015-12-12 08:37:15 +00:00
version:1.71,
2015-11-30 13:08:29 +00:00
changeLog:[
2015-12-12 08:37:15 +00:00
'bug修复',
'双指拖动对话框',
'对决模式调整',
2015-11-30 13:08:29 +00:00
],
2015-04-29 03:25:17 +00:00
configprefix:'noname_0.9_',
updates:[],
canvasUpdates:[],
2015-11-04 01:59:00 +00:00
video:[],
2015-11-09 09:05:28 +00:00
arenaReady:[],
2015-11-04 01:59:00 +00:00
_onDB:[],
2015-12-06 15:23:47 +00:00
customCharacters:[],
customCards:[],
skilllist:[],
characterPack:{},
cardPack:{},
2015-11-04 01:59:00 +00:00
onDB:function(func){
if(lib.db){
func();
}
else{
lib._onDB.push(func);
}
},
2015-12-06 15:23:47 +00:00
setTranslate:function(name){
if(name.indexOf(':')==-1){
lib.translate[name]=name;
}
else{
lib.translate[name]=name.slice(name.indexOf(':')+1);
}
},
checkCharacterName:function(name){
if(lib.character[name]){
if(!lib.customCharacters.contains(name)) return true;
for(var i in lib.config.customCharacterPack){
if(lib.config.customCharacterPack[i].character.contains(name)) return true;
}
}
return false;
},
checkSkillName:function(name){
if(lib.skill[name]){
if(!lib.skill[name].createInfo) return true;
for(var i in lib.config.customCharacterPack){
if(lib.config.customCharacterPack[i].skill.contains(name)) return true;
}
}
return false;
},
2015-11-23 10:59:44 +00:00
listenEnd:function(node){
if(!node._listeningEnd){
node._listeningEnd=true;
node.addEventListener('webkitTransitionEnd',function(){
2015-12-08 13:54:44 +00:00
delete node._listeningEnd;
2015-11-23 10:59:44 +00:00
if(node._onEndMoveDelete){
node.moveDelete(node._onEndMoveDelete);
}
2015-11-24 15:44:21 +00:00
else if(node._onEndDelete){
node.delete();
}
2015-11-23 10:59:44 +00:00
node._transitionEnded=true;
});
}
},
2015-10-29 17:36:14 +00:00
configMenu:{
general:{
name:'通用',
config:{
cheat:{
name:'控制台命令',
init:false,
onclick:function(bool){
if(lib.config.cheat&&bool==false){
lib.cheat=window.cheat;
delete window.cheat;
delete window.game;
delete window.ui;
delete window.get;
delete window.ai;
delete window.lib;
delete window._status;
}
else if(!lib.config.cheat&&bool){
window.cheat=lib.cheat;
window.cheat.i();
}
game.saveConfig('cheat',bool);
},
unfrequent:true,
},
2015-11-23 10:59:44 +00:00
low_performance:{
2015-11-30 13:08:29 +00:00
name:'流畅模式',
2015-11-23 10:59:44 +00:00
init:false,
2015-11-24 00:50:54 +00:00
onclick:function(bool){
game.saveConfig('low_performance',bool);
if(bool){
ui.arena.classList.add('low_performance');
}
else{
ui.arena.classList.remove('low_performance');
}
}
2015-11-23 10:59:44 +00:00
},
2015-11-21 13:23:23 +00:00
confirm_exit:{
name:'确认退出',
init:false,
unfrequent:true
},
2015-10-29 17:36:14 +00:00
auto_confirm:{
name:'自动确认',
init:true,
2015-11-15 05:54:58 +00:00
unfrequent:true,
2015-10-29 17:36:14 +00:00
},
enable_drag:{
name:'启用拖拽',
init:true,
2015-11-15 05:54:58 +00:00
unfrequent:true,
2015-10-29 17:36:14 +00:00
},
2015-12-03 16:28:06 +00:00
enable_dragline:{
name:'拖拽指示线',
init:true,
unfrequent:true,
},
enable_touchdragline:{
name:'拖拽指示线',
init:false,
unfrequent:true,
},
2015-10-29 17:36:14 +00:00
wuxie_self:{
name:'不无懈自己',
init:true,
2015-10-30 09:13:19 +00:00
},
2015-11-15 05:54:58 +00:00
tao_enemy:{
name:'不对敌将使用桃',
init:false,
},
2015-11-05 02:34:35 +00:00
touchscreen:{
name:'触屏模式',
init:false,
2015-11-26 08:15:28 +00:00
restart:true,
unfrequent:true,
2015-11-05 02:34:35 +00:00
},
2015-11-23 10:59:44 +00:00
change_skin:{
name:'双击换肤',
init:true
2015-11-15 05:54:58 +00:00
},
2015-11-29 11:46:51 +00:00
swipe:{
name:'滑动手势',
init:true,
unfrequent:true,
},
swipe_down:{
name:'下划操作',
init:'system',
unfrequent:true,
item:{
system:'显示按钮',
menu:'打开菜单',
2015-11-30 13:08:29 +00:00
pause:'切换暂停',
2015-12-07 11:15:35 +00:00
auto:'切换托管',
off:'关闭',
2015-11-29 11:46:51 +00:00
}
},
swipe_up:{
name:'上划操作',
init:'auto',
unfrequent:true,
item:{
system:'显示按钮',
menu:'打开菜单',
pause:'切换暂停',
2015-12-07 11:15:35 +00:00
auto:'切换托管',
off:'关闭',
}
},
swipe_left:{
name:'左划操作',
init:'off',
unfrequent:true,
item:{
system:'显示按钮',
menu:'打开菜单',
pause:'切换暂停',
auto:'切换托管',
off:'关闭',
}
},
swipe_right:{
name:'右划操作',
init:'off',
unfrequent:true,
item:{
system:'显示按钮',
menu:'打开菜单',
pause:'切换暂停',
auto:'切换托管',
off:'关闭',
2015-11-29 11:46:51 +00:00
}
},
2015-12-06 15:23:47 +00:00
show_splash:{
name:'显示开始界面',
2015-12-09 03:05:36 +00:00
init:true,
2015-12-06 15:23:47 +00:00
},
2015-10-30 09:13:19 +00:00
game_speed:{
name:'游戏速度',
init:'mid',
item:{
vslow:'慢',
slow:'较慢',
mid:'中',
fast:'较快',
vfast:'快',
2015-11-21 13:23:23 +00:00
vvfast:'很快',
2015-10-30 09:13:19 +00:00
},
},
right_click:{
name:'右键功能',
init:'pause',
unfrequent:true,
item:{
pause:'暂停',
config:'选项',
auto:'托管',
}
},
right_info:{
name:'右键显示信息',
init:true,
unfrequent:true,
restart:true
},
hover_all:{
name:'悬停显示信息',
init:true,
unfrequent:true,
restart:true,
},
hover_handcard:{
name:'悬停手牌显示信息',
init:true,
unfrequent:true,
},
hoveration:{
name:'悬停菜单弹出时间',
unfrequent:true,
init:'1000',
item:{
'500':'0.5秒',
'700':'0.7秒',
'1000':'1秒',
'1500':'1.5秒',
'2500':'2.5秒',
}
},
mousewheel:{
name:'滚轮控制手牌',
init:true,
unfrequent:true,
onclick:function(bool){
game.saveConfig('mousewheel',bool);
if(lib.config.touchscreen) return;
if(lib.config.mousewheel){
2015-11-25 15:42:29 +00:00
ui.handcards1Container.onmousewheel=ui.click.mousewheel;
ui.handcards2Container.onmousewheel=ui.click.mousewheel;
2015-10-30 09:13:19 +00:00
}
else{
2015-11-25 15:42:29 +00:00
ui.handcards1Container.onmousewheel=null;
ui.handcards2Container.onmousewheel=null;
2015-10-30 09:13:19 +00:00
}
}
},
2015-11-04 01:59:00 +00:00
video:{
name:'保存录像',
init:'20',
item:{
'0':'关闭',
'5':'五局',
'10':'十局',
'20':'二十局',
'50':'五十局',
'10000':'无限',
},
unfrequent:true,
},
2015-10-30 09:13:19 +00:00
update:function(config,map){
if(config.touchscreen){
map.mousewheel.hide();
2015-11-09 17:04:18 +00:00
map.hover_all.hide();
map.hover_handcard.hide();
map.hoveration.hide();
2015-11-15 05:54:58 +00:00
map.right_info.hide();
map.right_click.hide();
2015-11-29 11:46:51 +00:00
map.swipe.show();
2015-11-30 13:08:29 +00:00
if(config.swipe){
map.swipe_up.show();
map.swipe_down.show();
2015-12-07 11:15:35 +00:00
map.swipe_left.show();
map.swipe_right.show();
2015-11-30 13:08:29 +00:00
}
else{
map.swipe_up.hide();
map.swipe_down.hide();
2015-12-07 11:15:35 +00:00
map.swipe_left.hide();
map.swipe_right.hide();
2015-11-30 13:08:29 +00:00
}
2015-10-30 09:13:19 +00:00
}
else{
map.mousewheel.show();
2015-11-09 17:04:18 +00:00
map.hover_all.show();
2015-11-15 05:54:58 +00:00
map.right_info.show();
map.right_click.show();
if(!config.hover_all){
map.hover_handcard.hide();
map.hoveration.hide();
}
else{
map.hover_handcard.show();
map.hoveration.show();
}
2015-11-29 11:46:51 +00:00
map.swipe.hide();
2015-11-30 13:08:29 +00:00
map.swipe_up.hide();
map.swipe_down.hide();
2015-12-07 11:15:35 +00:00
map.swipe_left.hide();
map.swipe_right.hide();
2015-10-30 09:13:19 +00:00
}
2015-12-03 16:28:06 +00:00
if(lib.config.enable_drag){
if(lib.config.touchscreen){
map.enable_dragline.hide();
map.enable_touchdragline.show();
}
else{
map.enable_dragline.show();
map.enable_touchdragline.hide();
}
}
else{
map.enable_dragline.hide();
map.enable_touchdragline.hide();
}
2015-10-29 17:36:14 +00:00
}
}
},
appearence:{
name:'外观',
config:{
theme:{
name:'主题',
init:'woodden',
item:{
woodden:'木纹',
music:'音乐',
simple:'简约',
},
onclick:function(theme){
game.saveConfig('theme',theme);
ui.arena.hide();
setTimeout(function(){
var theme=ui.css.theme;
ui.css.theme=lib.init.css('theme/'+lib.config.theme,'style');
theme.remove();
setTimeout(function(){ui.arena.show();},100);
},500);
}
2015-10-30 09:13:19 +00:00
},
layout:{
name:'布局',
2015-11-05 02:34:35 +00:00
init:'mobile',
2015-10-30 09:13:19 +00:00
item:{
2015-10-31 10:14:14 +00:00
default:'旧版',
2015-11-05 02:34:35 +00:00
newlayout:'对称',
mobile:'默认',
2015-10-31 16:18:20 +00:00
phone:'移动'
2015-10-30 09:13:19 +00:00
},
onclick:function(layout){
2015-10-31 10:14:14 +00:00
if(lib.config.layoutfixed.contains(lib.config.mode)&&layout=='default'){
2015-11-25 10:25:18 +00:00
game.saveConfig('layout',layout);
}
else{
lib.init.layout(layout);
2015-10-30 09:13:19 +00:00
}
}
},
ui_zoom:{
name:'界面缩放',
unfrequent:true,
init:'normal',
item:{
2015-11-05 02:34:35 +00:00
esmall:'80%',
vsmall:'90%',
small:'95%',
normal:'100%',
big:'105%',
vbig:'110%',
ebig:'120%',
2015-10-30 09:13:19 +00:00
},
onclick:function(zoom){
game.saveConfig('ui_zoom',zoom);
switch(zoom){
case 'esmall':ui.window.style.zoom=0.8;break;
case 'vsmall':ui.window.style.zoom=0.9;break;
case 'small':ui.window.style.zoom=0.95;break;
case 'big':ui.window.style.zoom=1.05;break;
case 'vbig':ui.window.style.zoom=1.1;break;
2015-11-05 02:34:35 +00:00
case 'ebig':ui.window.style.zoom=1.2;break;
2015-10-30 09:13:19 +00:00
default:ui.window.style.zoom=1;
}
}
},
image_background:{
name:'游戏背景',
init:'default',
item:{
default:'默认',
2015-12-02 10:40:25 +00:00
custom:'自定',
2015-10-30 09:13:19 +00:00
},
onclick:function(background){
var animate=lib.config.image_background=='default';
game.saveConfig('image_background',background);
ui.background.delete();
ui.background=ui.create.div('.background');
switch (lib.config.image_background_filter){
2015-11-05 02:34:35 +00:00
case 'blur':
ui.background.style.filter='blur(8px)';
ui.background.style.webkitFilter='blur(8px)';
ui.background.style.transform='scale(1.05)';
break;
case 'gray':
ui.background.style.filter='grayscale(1)';
ui.background.style.webkitFilter='grayscale(1)';
break;
case 'sepia':
ui.background.style.filter='sepia(0.5)';
ui.background.style.webkitFilter='sepia(0.5)';
break;
case 'invert':
ui.background.style.filter='invert(1)';
ui.background.style.webkitFilter='invert(1)';
break;
case 'saturate':
ui.background.style.filter='saturate(5)';
ui.background.style.webkitFilter='saturate(5)';
break;
case 'contrast':
ui.background.style.filter='contrast(1.4)';
ui.background.style.webkitFilter='contrast(1.4)';
break;
case 'hue':
ui.background.style.filter='hue-rotate(180deg)';
ui.background.style.webkitFilter='hue-rotate(180deg)';
break;
case 'brightness':
ui.background.style.filter='brightness(5)';
ui.background.style.webkitFilter='brightness(5)';
break;
default:
ui.background.style.filter='';
ui.background.style.webkitFilter='';
ui.background.style.transform='';
2015-10-30 09:13:19 +00:00
}
document.body.insertBefore(ui.background,document.body.firstChild);
if(animate) ui.background.animate('start');
if(lib.config.image_background=='default'){
ui.background.style.backgroundImage="none";
}
2015-12-02 10:40:25 +00:00
else if(lib.config.image_background=='custom'){
ui.background.style.backgroundImage="none";
game.getDB('image','background',function(fileToLoad){
if(!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var data = fileLoadedEvent.target.result;
ui.background.style.backgroundImage='url('+data+')';
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
}
2015-10-30 09:13:19 +00:00
else{
ui.background.style.backgroundImage="url('image/background/"+lib.config.image_background+".jpg')";
}
ui.background.style.backgroundSize='cover';
},
},
2015-12-02 10:40:25 +00:00
import_background:{
name:'<div style="white-space:nowrap;width:calc(100% - 5px)">'+
'<input type="file" style="width:calc(100% - 40px)" accept="image/jpeg">'+
'<button style="width:40px">确定</button></div>',
clear:true,
},
2015-10-30 09:13:19 +00:00
image_background_filter:{
name:'背景特效',
init:'default',
item:{
default:'无',
blur:'模糊',
2015-11-21 05:30:26 +00:00
gray:'黑白',
2015-10-30 09:13:19 +00:00
sepia:'怀旧',
invert:'反色',
saturate:'饱和',
contrast:'对比',
hue:'偏色',
brightness:'高亮',
},
onclick:function(filter){
game.saveConfig('image_background_filter',filter);
ui.click.sidebar.image_background(lib.config.image_background);
},
},
2015-11-06 10:05:08 +00:00
card_style:{
name:'卡牌样式',
2015-11-18 03:39:14 +00:00
init:'default',
2015-11-06 10:05:08 +00:00
item:{
default:'默认',
wood:'木纹',
music:'音乐',
simple:'原版'
},
onclick:function(layout){
game.saveConfig('card_style',layout);
var style=ui.css.card_style;
2015-11-18 03:39:14 +00:00
ui.css.card_style=lib.init.css('theme/style/card',lib.config.card_style);
style.remove();
},
unfrequent:true,
},
cardback_style:{
name:'卡背样式',
init:'default',
item:{
default:'默认',
wood:'木纹',
music:'音乐',
official:'原版'
},
onclick:function(layout){
game.saveConfig('cardback_style',layout);
var style=ui.css.cardback_style;
ui.css.cardback_style=lib.init.css('theme/style/cardback',lib.config.cardback_style);
2015-11-06 10:05:08 +00:00
style.remove();
},
unfrequent:true,
},
2015-11-18 03:39:14 +00:00
hp_style:{
name:'体力条样式',
init:'default',
item:{
default:'默认',
2015-11-30 13:08:29 +00:00
official:'勾玉',
2015-11-18 03:39:14 +00:00
},
onclick:function(layout){
game.saveConfig('hp_style',layout);
var style=ui.css.hp_style;
ui.css.hp_style=lib.init.css('theme/style/hp',lib.config.hp_style);
style.remove();
if(lib.config.layout=='default'&&lib.config.hp_style=='official'){
ui.arena.classList.add('hpimage');
}
else{
ui.arena.classList.remove('hpimage');
}
},
unfrequent:true,
},
2015-12-07 11:15:35 +00:00
show_log:{
name:'显示历史记录',
init:'off',
unfrequent:true,
item:{
off:'关闭',
left:'靠左',
center:'居中',
right:'靠右',
},
onclick:function(bool){
game.saveConfig('show_log',bool);
if(lib.config.show_log!='off'){
ui.arenalog.style.display='';
ui.arenalog.dataset.position=bool;
}
else{
ui.arenalog.style.display='none';
ui.arenalog.innerHTML='';
}
}
},
2015-12-08 13:54:44 +00:00
log_highlight:{
name:'历史记录高亮',
init:true,
unfrequent:true,
},
2015-11-28 07:19:04 +00:00
glow_phase:{
name:'当前回合角色高亮',
unfrequent:true,
init:'yellow',
item:{
none:'无',
yellow:'黄色',
green:'绿色',
purple:'紫色',
},
onclick:function(bool){
game.saveConfig('glow_phase',bool);
if(_status.currentPhase){
if(lib.config.glow_phase){
_status.currentPhase.classList.add('glow_phase');
ui.arena.dataset.glow_phase=lib.config.glow_phase;
}
else{
_status.currentPhase.classList.remove('glow_phase');
}
}
}
},
2015-11-30 13:08:29 +00:00
slim_player:{
name:'窄边框',
init:true,
unfrequent:true,
onclick:function(bool){
game.saveConfig('slim_player',bool);
if(bool){
ui.arena.classList.add('slim_player');
}
else{
ui.arena.classList.remove('slim_player');
}
}
},
2015-12-04 04:43:06 +00:00
fold_card:{
name:'折叠手牌',
init:true,
unfrequent:true,
},
2015-11-05 02:34:35 +00:00
auto_popped_config:{
name:'自动弹出选项',
2015-10-30 09:13:19 +00:00
init:true,
unfrequent:true,
},
2015-11-05 02:34:35 +00:00
auto_popped_history:{
name:'自动弹出历史',
init:false,
unfrequent:true,
},
2015-10-30 09:13:19 +00:00
hide_card_image:{
name:'隐藏卡牌背景',
init:false,
unfrequent:true,
restart:true,
},
2015-11-25 10:25:18 +00:00
// bottom_line:{
// name:'指示线置底',
// init:false,
// unfrequent:true,
// onclick:function(bool){
// game.saveConfig('bottom_line',bool);
// if(lib.config.bottom_line){
// ui.canvas.style.zIndex=0;
// }
// else{
// ui.canvas.style.zIndex='';
// }
// }
// },
// line_dash:{
// name:'虚线指示线',
// init:false,
// unfrequent:true,
// },
2015-10-30 09:13:19 +00:00
show_name:{
name:'显示武将名',
init:false,
unfrequent:true,
onclick:function(bool){
game.saveConfig('show_name',bool);
if(lib.config.show_name){
for(var i=0;i<game.players.length;i++){
game.players[i].node.name.style.display='';
}
}
else{
for(var i=0;i<game.players.length;i++){
game.players[i].node.name.style.display='none';
}
}
}
},
2015-11-06 10:05:08 +00:00
// savevideo:{
// name:'显示保存录像',
// init:true,
// onclick:function(bool){
// game.saveConfig('savevideo',bool);
// if(!lib.db) return;
// if(lib.config.savevideo){
// if(!ui.savevideo&&_status.over){
// ui.savevideo=ui.create.control('保存录像',game.saveVideo);
// }
// }
// else if(ui.savevideo){
// ui.savevideo.close();
// delete ui.savevideo;
// }
// },
// unfrequent:true,
// },
2015-11-29 11:46:51 +00:00
show_roundmenu:{
name:'显示触屏按钮',
init:true,
unfrequent:true,
onclick:function(bool){
game.saveConfig('show_roundmenu',bool);
if(bool&&lib.config.touchscreen){
ui.roundmenu.style.display='';
}
else{
ui.roundmenu.style.display='none';
}
}
},
round_menu_func:{
name:'触屏按钮功能',
init:'system',
unfrequent:true,
item:{
system:'显示按钮',
menu:'打开菜单',
2015-11-30 13:08:29 +00:00
// pause:'切换暂停',
// auto:'切换托管'
2015-11-29 11:46:51 +00:00
}
},
2015-10-30 09:13:19 +00:00
show_replay:{
name:'显示重来按钮',
init:false,
unfrequent:true,
onclick:function(bool){
game.saveConfig('show_replay',bool);
if(lib.config.show_replay){
ui.replay.style.display='';
}
else{
ui.replay.style.display='none';
}
}
},
show_playerids:{
name:'显示身份按钮',
init:true,
unfrequent:true,
onclick:function(bool){
game.saveConfig('show_playerids',bool);
if(lib.config.show_playerids){
ui.playerids.style.display='';
}
else{
ui.playerids.style.display='none';
}
}
},
show_pause:{
2015-11-07 09:20:15 +00:00
name:'显示暂停按钮',
2015-10-30 09:13:19 +00:00
init:true,
unfrequent:true,
onclick:function(bool){
game.saveConfig('show_pause',bool);
if(lib.config.show_pause){
ui.pause.style.display='';
}
else{
ui.pause.style.display='none';
}
}
},
show_auto:{
name:'显示托管按钮',
init:true,
unfrequent:true,
onclick:function(bool){
game.saveConfig('show_auto',bool);
if(lib.config.show_auto){
ui.auto.style.display='';
}
else{
ui.auto.style.display='none';
}
}
},
show_volumn:{
name:'显示音量按钮',
init:true,
unfrequent:true,
onclick:function(bool){
game.saveConfig('show_volumn',bool);
if(lib.config.show_volumn){
ui.volumn.style.display='';
}
else{
ui.volumn.style.display='none';
}
}
},
2015-11-28 03:45:23 +00:00
show_cardpile:{
name:'显示牌堆按钮',
init:true,
unfrequent:true,
onclick:function(bool){
game.saveConfig('show_cardpile',bool);
if(lib.config.show_cardpile){
ui.cardPileButton.style.display='';
}
else{
ui.cardPileButton.style.display='none';
}
}
},
2015-10-30 09:13:19 +00:00
show_wuxie:{
name:'显示不询问无懈',
2015-11-28 03:45:23 +00:00
init:false,
2015-10-30 09:13:19 +00:00
unfrequent:true,
onclick:function(bool){
game.saveConfig('show_wuxie',bool);
if(lib.config.show_wuxie){
ui.wuxie.style.display='';
}
else{
ui.wuxie.style.display='none';
}
}
},
show_discardpile:{
name:'暂停时显示弃牌堆',
init:false,
unfrequent:true,
},
title:{
name:'标题栏显示信息',
init:false,
unfrequent:true,
onclick:function(bool){
game.saveConfig('title',bool);
if(!lib.config.title) document.title='无名杀';
}
},
blur_ui:{
name:'模糊效果',
init:false,
unfrequent:true,
onclick:function(bool){
game.saveConfig('blur_ui',bool);
if(bool){
ui.css.blur_ui=lib.init.css('layout/default','blur');
}
else if(ui.css.blur_ui){
ui.css.blur_ui.remove();
}
}
},
2015-11-18 03:39:14 +00:00
damage_shake:{
name:'伤害抖动',
init:true,
unfrequent:true,
},
2015-11-14 15:48:04 +00:00
button_press:{
name:'按钮效果',
init:true,
unfrequent:true,
},
2015-11-21 13:23:23 +00:00
jiu_effect:{
name:'喝酒效果',
init:true,
unfrequent:true,
},
2015-11-26 08:15:28 +00:00
die_flip:{
name:'阵亡效果',
2015-12-03 16:28:06 +00:00
init:true,
2015-11-26 08:15:28 +00:00
unfrequent:true,
},
2015-10-30 09:13:19 +00:00
animation:{
name:'游戏特效',
init:true,
},
2015-11-30 13:08:29 +00:00
name_font:{
name:'人名字体',
init:'xinwei',
unfrequent:true,
item:{
xinwei:'新魏',
huangcao:'黄草',
xiaozhuan:'小篆',
// default:'默认',
},
onclick:function(font){
game.saveConfig('name_font',font);
ui.arena.dataset.name_font=font;
}
},
identity_font:{
name:'身份字体',
init:'huangcao',
unfrequent:true,
item:{
xinwei:'新魏',
huangcao:'黄草',
xiaozhuan:'小篆',
// default:'默认',
},
onclick:function(font){
game.saveConfig('identity_font',font);
ui.arena.dataset.identity_font=font;
}
},
global_font:{
name:'界面字体',
init:'default',
unfrequent:true,
item:{
xinwei:'新魏',
huangcao:'黄草',
xiaozhuan:'小篆',
default:'默认',
},
onclick:function(font){
game.saveConfig('global_font',font);
ui.arena.dataset.global_font=font;
}
},
// font_size:{
// name:'字体大小',
// init:'16',
// unfrequent:true,
// item:{
// '14':'14px',
// '16':'16px',
// '18':'18px',
// '20':'20px',
// },
// onclick:function(font){
// game.saveConfig('font_size',font);
// ui.arena.dataset.font_size=font;
// }
// },
2015-10-30 09:13:19 +00:00
update:function(config,map){
if(lib.config.image_background=='default'){
map.image_background_filter.hide();
}
else{
map.image_background_filter.show();
}
2015-12-02 10:40:25 +00:00
if(lib.config.image_background=='custom'&&lib.db){
map.import_background.show();
}
else{
map.import_background.hide();
}
2015-11-29 11:46:51 +00:00
if(lib.config.layout!='phone'){
map.round_menu_func.hide();
map.show_roundmenu.hide();
}
else{
map.round_menu_func.show();
map.show_roundmenu.show();
}
2015-10-30 09:13:19 +00:00
},
}
},
audio:{
name:'音效',
config:{
2015-12-08 00:56:54 +00:00
update:function(config,map){
if(lib.config.background_music=='music_custom'&&lib.db){
map.import_music.show();
}
else{
map.import_music.hide();
}
},
2015-10-30 09:13:19 +00:00
background_music:{
name:'背景音乐',
init:true,
2015-12-08 00:56:54 +00:00
item:{
music_default:'默认',
music_custom:'自定',
},
2015-10-30 09:13:19 +00:00
onclick:function(item){
game.saveConfig('background_music',item);
game.playBackgroundMusic();
}
},
2015-12-08 00:56:54 +00:00
import_music:{
name:'<div style="white-space:nowrap;width:calc(100% - 5px)">'+
'<input type="file" style="width:calc(100% - 40px)" accept="audio/ogg,audio/mpeg">'+
'<button style="width:40px">确定</button></div>',
clear:true,
},
2015-10-30 09:13:19 +00:00
background_audio:{
name:'游戏音效',
init:true,
},
background_speak:{
name:'人物配音',
init:true,
},
background_ogg:{
name:'补全配音',
2015-11-11 02:41:42 +00:00
init:true
2015-11-30 13:08:29 +00:00
},
volumn_audio:{
name:'音效音量',
init:8,
item:{
'1':'一',
'2':'二',
'3':'三',
'4':'四',
'5':'五',
'6':'六',
'7':'七',
'8':'八',
},
onclick:function(volume){
game.saveConfig('volumn_audio',parseInt(volume));
}
},
volumn_background:{
name:'音乐音量',
init:8,
item:{
'1':'一',
'2':'二',
'3':'三',
'4':'四',
'5':'五',
'6':'六',
'7':'七',
'8':'八',
},
onclick:function(volume){
game.saveConfig('volumn_background',parseInt(volume));
2015-12-02 10:40:25 +00:00
ui.backgroundMusic.volume=volume/8;
2015-11-30 13:08:29 +00:00
}
2015-10-30 09:13:19 +00:00
}
}
},
playpack:{
name:'玩法',
config:{
character:{
2015-11-09 23:11:17 +00:00
name:'技能卡牌',
2015-10-30 09:13:19 +00:00
init:false,
restart:true,
onclick:function(bool){
if(bool){
lib.config.plays.add('character');
}
else{
lib.config.plays.remove('character');
}
game.saveConfig('plays',lib.config.plays);
}
},
2015-11-09 23:11:17 +00:00
character_num_playpackconfig:{
name:'卡牌比例',
init:'0.05',
item:{
'0.02':'2%',
'0.05':'5%',
'0.1':'10%',
'0.2':'20%',
}
},
2015-10-30 09:13:19 +00:00
soldier:{
name:'士兵模式',
init:false,
restart:true,
onclick:function(bool){
if(bool){
lib.config.plays.add('soldier');
}
else{
lib.config.plays.remove('soldier');
}
game.saveConfig('plays',lib.config.plays);
}
},
wuxing:{
name:'五行生克',
init:false,
restart:true,
onclick:function(bool){
if(bool){
lib.config.plays.add('wuxing');
}
else{
lib.config.plays.remove('wuxing');
}
game.saveConfig('plays',lib.config.plays);
}
},
2015-11-09 23:11:17 +00:00
wuxing_num_playpackconfig:{
name:'带属性卡牌',
init:'0.3',
item:{
'0.1':'10%',
'0.2':'20%',
'0.3':'30%',
'0.5':'50%',
}
},
2015-11-09 09:05:28 +00:00
weather:{
name:'天气变化',
init:false,
restart:true,
onclick:function(bool){
if(bool){
lib.config.plays.add('weather');
}
else{
lib.config.plays.remove('weather');
}
game.saveConfig('plays',lib.config.plays);
}
},
2015-11-10 10:13:53 +00:00
// weather_animation_playpackconfig:{
// name:'天气动画',
// init:true
2015-11-09 23:11:17 +00:00
// },
2015-11-10 10:13:53 +00:00
weather_noqing_playpackconfig:{
name:'异常天气出现概率',
init:'0.5',
item:{
'0.1':'10%',
'0.3':'30%',
'0.5':'50%',
'0.7':'70%',
'0.9':'90%',
}
},
2015-11-09 23:11:17 +00:00
weather_chance_playpackconfig:{
name:'天气效果触发概率',
2015-11-10 10:13:53 +00:00
init:'0.5',
2015-11-09 23:11:17 +00:00
item:{
'0.1':'10%',
'0.2':'20%',
'0.3':'30%',
'0.5':'50%',
2015-11-10 10:13:53 +00:00
'0.8':'80%',
2015-11-09 23:11:17 +00:00
},
onclick:function(item){
game.saveConfig('weather_chance_playpackconfig',item);
_status.weatherchance=parseFloat(lib.config.weather_chance_playpackconfig)||0;
}
},
weather_duration_playpackconfig:{
name:'异常天气持续时间',
2015-11-10 10:13:53 +00:00
init:'[4,4]',
2015-11-09 23:11:17 +00:00
item:{
2015-11-10 10:13:53 +00:00
'[2,4]':'1~3回合',
'[4,4]':'3~6回合',
'[4,7]':'3~9回合',
'[7,4]':'6~9回合',
'[7,7]':'6~12回合',
2015-11-09 23:11:17 +00:00
}
},
weather_qingduration_playpackconfig:{
name:'晴朗天气持续时间',
2015-11-10 10:13:53 +00:00
init:'[2,4]',
2015-11-09 23:11:17 +00:00
item:{
2015-11-10 10:13:53 +00:00
'[2,4]':'1~3回合',
'[4,4]':'3~6回合',
'[4,7]':'3~9回合',
'[7,4]':'6~9回合',
'[7,7]':'6~12回合',
2015-11-09 23:11:17 +00:00
}
},
2015-10-30 09:13:19 +00:00
update:function(config,map){
for(var i in map){
2015-11-09 23:11:17 +00:00
if(i.indexOf('_playpackconfig')!=-1){
map[i].classList.add('indent');
if(lib.config.plays.contains(i.slice(0,i.indexOf('_')))){
map[i].show();
}
else{
map[i].hide();
}
2015-10-30 09:13:19 +00:00
}
else{
2015-11-09 23:11:17 +00:00
if(lib.config.plays.contains(i)){
map[i].classList.add('on');
}
else{
map[i].classList.remove('on');
}
2015-10-30 09:13:19 +00:00
}
}
}
}
},
skill:{
name:'技能',
config:{
update:function(config,map){
for(var i in map){
if(map[i]._link.config.type=='autoskill'){
if(!lib.config.autoskilllist.contains(i)){
map[i].classList.add('on');
ui.autoskill[i].lastChild.classList.add('on');
}
else{
map[i].classList.remove('on');
ui.autoskill[i].lastChild.classList.remove('on');
}
}
else if(map[i]._link.config.type=='banskill'){
if(!lib.config.forbidlist.contains(i)){
map[i].classList.add('on');
}
else{
map[i].classList.remove('on');
}
}
}
}
}
},
others:{
name:'其它',
config:{
reset_game:{
name:'重置游戏',
onclick:function(){
var node=this;
if(node._clearing){
localStorage.clear();
2015-11-10 10:13:53 +00:00
if(indexedDB) indexedDB.deleteDatabase(lib.configprefix+'data');
2015-11-07 09:20:15 +00:00
game.reload();
2015-10-30 09:13:19 +00:00
return;
}
node._clearing=true;
node.innerHTML='单击以确认 (3)';
setTimeout(function(){
node.innerHTML='单击以确认 (2)';
setTimeout(function(){
node.innerHTML='单击以确认 (1)';
setTimeout(function(){
node.innerHTML='重置游戏';
delete node._clearing;
},1000);
},1000);
},1000);
},
clear:true
},
2015-12-06 15:23:47 +00:00
reset_hiddenpack:{
name:'重置隐藏扩展包',
onclick:function(){
if(this.innerHTML!='已重置'){
this.innerHTML='已重置'
game.saveConfig('hiddenModePack',[]);
game.saveConfig('hiddenCharacterPack',[]);
game.saveConfig('hiddenCardPack',[]);
var that=this;
setTimeout(function(){
that.innerHTML='重置隐藏扩展包';
},500);
}
},
clear:true
},
2015-11-25 10:25:18 +00:00
reset_tutorial:{
name:'重置新手向导',
onclick:function(){
2015-12-06 15:23:47 +00:00
if(this.innerHTML!='已重置'){
this.innerHTML='已重置'
game.saveConfig('new_tutorial',false);
var that=this;
setTimeout(function(){
that.innerHTML='重置新手向导';
},500);
}
2015-11-25 10:25:18 +00:00
},
clear:true
},
2015-10-30 09:13:19 +00:00
import_data:{
name:'导入游戏数据',
onclick:function(){
ui.import_data_button.classList.toggle('hidden');
},
clear:true
},
import_data_button:{
name:'<div style="white-space:nowrap;width:calc(100% - 10px)">'+
2015-12-02 10:40:25 +00:00
'<input type="file" style="width:calc(100% - 40px)">'+
2015-10-30 09:13:19 +00:00
'<button style="width:40px">确定</button></div>',
clear:true,
},
export_data:{
name:'导出游戏数据',
onclick:function(){
var data={};
for(var i in localStorage){
data[i]=localStorage[i];
}
2015-11-05 02:34:35 +00:00
game.export(lib.init.encode(JSON.stringify(data)),
'无名杀 - 数据 - '+(new Date()).toLocaleString());
2015-10-30 09:13:19 +00:00
},
clear:true
2015-10-29 17:36:14 +00:00
}
}
}
},
mode:{
identity:{
name:'身份',
config:{
2015-11-06 10:05:08 +00:00
update:function(config,map){
2015-11-07 09:20:15 +00:00
if(config.identity_mode=='zhong'){
map.player_number.hide();
map.enhance_zhu.hide();
map.double_nei.hide();
map.auto_identity.hide();
}
else{
map.player_number.show();
map.enhance_zhu.show();
map.auto_identity.show();
2015-12-09 03:05:36 +00:00
if(config.player_number=='8'){
map.double_nei.show();
}
else{
map.double_nei.hide();
}
2015-11-07 09:20:15 +00:00
}
},
identity_mode:{
name:'游戏模式',
init:'normal',
item:{
normal:'普通',
zhong:'明忠'
},
restart:true,
frequent:true,
2015-11-06 10:05:08 +00:00
},
2015-10-29 17:36:14 +00:00
player_number:{
name:'游戏人数',
init:'8',
item:{
'2':'两人',
'3':'三人',
'4':'四人',
'5':'五人',
'6':'六人',
'7':'七人',
'8':'八人'
},
2015-10-30 15:32:48 +00:00
frequent:true,
restart:true,
2015-10-29 17:36:14 +00:00
},
2015-11-06 10:05:08 +00:00
double_nei:{
name:'双内奸',
init:false,
frequent:true,
restart:true,
},
2015-10-29 17:36:14 +00:00
double_character:{
name:'双将模式',
init:false,
frequent:true,
restart:true,
},
double_hp:{
name:'双将体力上限',
init:'pingjun',
item:{
hejiansan:'和减三',
pingjun:'平均值',
zuidazhi:'最大值',
zuixiaozhi:'最小值',
zonghe:'相加',
},
restart:true,
},
auto_identity:{
name:'自动显示身份',
item:{
off:'关闭',
one:'一轮',
two:'两轮',
three:'三轮',
always:'始终'
},
init:'off',
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('auto_identity',bool,this._link.config.mode);
2015-11-07 09:20:15 +00:00
if(get.config('identity_mode')=='zhong') return;
2015-10-29 17:36:14 +00:00
var num;
switch(bool){
case '一轮':num=1;break;
case '两轮':num=2;break;
case '三轮':num=3;break;
default:num=0;break;
}
if(num&!_status.identityShown&&game.phaseNumber>game.players.length*num&&game.showIdentity){
_status.identityShown=true;
2015-11-01 07:54:42 +00:00
game.showIdentity(false);
2015-10-29 17:36:14 +00:00
}
}
},
ban_weak:{
name:'屏蔽弱将',
init:false,
restart:true,
2015-11-18 03:39:14 +00:00
},
ban_strong:{
name:'屏蔽强将',
init:false,
restart:true,
2015-10-29 17:36:14 +00:00
},
enhance_zhu:{
name:'加强主公',
init:false,
restart:true,
frequent:true,
},
free_choose:{
name:'自由选将',
init:true,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('free_choose',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat2&&get.config('free_choose')) ui.create.cheat2();
else if(ui.cheat2&&!get.config('free_choose')){
ui.cheat2.close();
delete ui.cheat2;
if(ui.cheat2x){
ui.cheat2x.close();
delete ui.cheat2;
}
}
}
},
change_identity:{
name:'自由选择身份和座位',
init:true,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('change_identity',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
var dialog;
if(ui.cheat2&&ui.cheat2.backup) dialog=ui.cheat2.backup;
else dialog=_status.event.dialog;
if(!dialog.querySelector('table')&&get.config('change_identity')) _status.event.parent.addSetting(dialog);
else _status.event.parent.removeSetting(dialog);
ui.update();
}
},
change_choice:{
name:'开启换将卡',
init:false,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('change_choice',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat&&get.config('change_choice')) ui.create.cheat();
else if(ui.cheat&&!get.config('change_choice')){
ui.cheat.close();
delete ui.cheat;
}
}
},
change_card:{
name:'开启手气卡',
init:false,
},
dierestart:{
name:'死亡后显示重来',
init:true,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('dierestart',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(get.config('dierestart')){
if(!ui.restart&&game.me.isDead()){
ui.restart=ui.create.control('restart',game.reload);
}
}
else if(ui.restart){
ui.restart.close();
delete ui.restart;
}
}
},
2015-11-06 10:05:08 +00:00
// swap:{
// name:'死亡后显示换人',
// init:true,
// onclick:function(bool){
// game.saveConfig('swap',bool,this._link.config.mode);
// if(get.config('swap')){
// if(!ui.swap&&game.me.isDead()){
// ui.swap=ui.create.control('换人',ui.click.dieswap);
// }
// }
// else if(ui.swap){
// ui.swap.close();
// delete ui.swap;
// }
// }
// },
2015-10-29 17:36:14 +00:00
revive:{
name:'死亡后显示复活',
init:false,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('revive',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(get.config('revive')){
if(!ui.revive&&game.me.isDead()){
ui.revive=ui.create.control('revive',ui.click.dierevive);
}
}
else if(ui.revive){
ui.revive.close();
delete ui.revive;
}
}
},
ai_strategy:{
name:'内奸策略',
init:'ai_strategy_1',
item:{
ai_strategy_1:'均衡',
ai_strategy_2:'偏反',
ai_strategy_3:'偏忠',
ai_strategy_4:'酱油',
ai_strategy_5:'天使',
ai_strategy_6:'仇主',
}
},
difficulty:{
name:'AI对人类态度',
init:'normal',
item:{
easy:'友好',
normal:'一般',
hard:'仇视',
}
},
2015-11-28 07:19:04 +00:00
choice_zhu:{
name:'主公候选武将数',
init:'3',
restart:true,
item:{
'3':'三',
'4':'四',
'5':'五',
'6':'六',
'8':'八',
'10':'十',
}
},
choice_zhong:{
name:'忠臣候选武将数',
init:'4',
restart:true,
item:{
'3':'三',
'4':'四',
'5':'五',
'6':'六',
'8':'八',
'10':'十',
}
},
choice_nei:{
name:'内奸候选武将数',
init:'5',
restart:true,
item:{
'3':'三',
'4':'四',
'5':'五',
'6':'六',
'8':'八',
'10':'十',
}
},
choice_fan:{
name:'反贼候选武将数',
init:'3',
restart:true,
item:{
'3':'三',
'4':'四',
'5':'五',
'6':'六',
'8':'八',
'10':'十',
}
},
2015-10-29 17:36:14 +00:00
}
},
guozhan:{
name:'国战',
config:{
2015-11-09 17:04:18 +00:00
guozhan_mode:{
name:'游戏模式',
init:'normal',
item:{
normal:'普通',
mingjiang:'明将'
},
restart:true,
frequent:true,
},
2015-10-29 17:36:14 +00:00
player_number:{
name:'游戏人数',
init:'8',
item:{
'3':'三人',
'4':'四人',
'5':'五人',
'6':'六人',
'7':'七人',
'8':'八人'
},
2015-10-30 15:32:48 +00:00
frequent:true,
restart:true,
2015-10-29 17:36:14 +00:00
},
initshow_draw:{
name:'首亮摸牌',
item:{
'0':'无',
'1':'一张',
'2':'两张',
2015-11-07 09:20:15 +00:00
'3':'三张',
2015-10-29 17:36:14 +00:00
},
init:'2',
frequent:true,
},
zhulian:{
name:'珠联璧合',
init:true,
frequent:true,
},
double_hp:{
name:'双将体力上限',
init:'pingjun',
item:{
hejiansan:'和减三',
pingjun:'平均值',
zuidazhi:'最大值',
zuixiaozhi:'最小值',
zonghe:'相加',
},
restart:true,
2015-11-18 03:39:14 +00:00
},
ban_strong:{
name:'屏蔽强将',
init:false,
restart:true,
2015-10-29 17:36:14 +00:00
},
free_choose:{
name:'自由选将',
init:true,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('free_choose',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat2&&get.config('free_choose')) ui.create.cheat2();
else if(ui.cheat2&&!get.config('free_choose')){
ui.cheat2.close();
delete ui.cheat2;
if(ui.cheat2x){
ui.cheat2x.close();
delete ui.cheat2;
}
}
}
},
change_identity:{
name:'自由选择座位',
init:true,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('change_identity',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
var dialog;
if(ui.cheat2&&ui.cheat2.backup) dialog=ui.cheat2.backup;
else dialog=_status.event.dialog;
if(!dialog.querySelector('table')&&get.config('change_identity')) _status.event.parent.addSetting(dialog);
else _status.event.parent.removeSetting(dialog);
ui.update();
}
},
change_choice:{
name:'开启换将卡',
init:false,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('change_choice',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat&&get.config('change_choice')) ui.create.cheat();
else if(ui.cheat&&!get.config('change_choice')){
ui.cheat.close();
delete ui.cheat;
}
}
},
change_card:{
name:'开启手气卡',
init:false,
},
dierestart:{
name:'死亡后显示重来',
init:true,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('dierestart',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(get.config('dierestart')){
if(!ui.restart&&game.me.isDead()){
ui.restart=ui.create.control('restart',game.reload);
}
}
else if(ui.restart){
ui.restart.close();
delete ui.restart;
}
}
},
2015-11-06 10:05:08 +00:00
// swap:{
// name:'死亡后显示换人',
// init:true,
// onclick:function(bool){
// game.saveConfig('swap',bool,this._link.config.mode);
// if(get.config('swap')){
// if(!ui.swap&&game.me.isDead()){
// ui.swap=ui.create.control('换人',ui.click.dieswap);
// }
// }
// else if(ui.swap){
// ui.swap.close();
// delete ui.swap;
// }
// }
// },
2015-10-29 17:36:14 +00:00
revive:{
name:'死亡后显示复活',
init:false,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('revive',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(get.config('revive')){
if(!ui.revive&&game.me.isDead()){
ui.revive=ui.create.control('revive',ui.click.dierevive);
}
}
else if(ui.revive){
ui.revive.close();
delete ui.revive;
}
}
},
difficulty:{
name:'AI对人类态度',
init:'normal',
item:{
easy:'友好',
normal:'一般',
hard:'仇视',
}
2015-11-28 07:19:04 +00:00
},
choice_num:{
name:'候选武将数',
init:'7',
restart:true,
item:{
'5':'五',
'6':'六',
'7':'七',
'8':'八',
'9':'九',
'10':'十',
}
},
2015-10-29 17:36:14 +00:00
}
},
versus:{
name:'对决',
config:{
change_choice:{
name:'开启换将卡',
init:false,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('change_choice',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat&&get.config('change_choice')) ui.create.cheat();
else if(ui.cheat&&!get.config('change_choice')){
ui.cheat.close();
delete ui.cheat;
}
},
frequent:true,
},
ban_weak:{
name:'屏蔽弱将',
init:false,
restart:true,
frequent:true,
2015-11-18 03:39:14 +00:00
},
ban_strong:{
name:'屏蔽强将',
init:false,
restart:true,
frequent:true,
2015-10-29 17:36:14 +00:00
},
}
},
boss:{
name:'挑战',
config:{
free_choose:{
name:'自由选将',
init:true,
frequent:true,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('free_choose',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat2&&get.config('free_choose')) ui.create.cheat2();
else if(ui.cheat2&&!get.config('free_choose')){
ui.cheat2.close();
delete ui.cheat2;
if(ui.cheat2x){
ui.cheat2x.close();
delete ui.cheat2;
}
}
}
},
change_choice:{
name:'开启换将卡',
init:false,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('change_choice',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat&&get.config('change_choice')) ui.create.cheat();
else if(ui.cheat&&!get.config('change_choice')){
ui.cheat.close();
delete ui.cheat;
}
},
frequent:true,
},
ban_weak:{
name:'屏蔽弱将',
init:false,
restart:true,
frequent:true,
},
2015-11-18 03:39:14 +00:00
ban_strong:{
name:'屏蔽强将',
init:false,
restart:true,
frequent:true,
},
2015-10-29 17:36:14 +00:00
}
},
chess:{
name:'战棋',
config:{
chess_mode:{
name:'游戏模式',
init:'combat',
item:{
combat:'对战',
2015-12-09 05:29:35 +00:00
leader:'君主',
2015-11-12 01:12:03 +00:00
tafang:'塔防'
2015-10-29 17:36:14 +00:00
},
restart:true,
frequent:true,
},
update:function(config,map){
2015-11-12 01:12:03 +00:00
if(config.chess_mode=='leader'){
map.chess_leader_save.show();
map.chess_leader_clear.show();
map.chess_character.hide();
}
else{
2015-10-29 17:36:14 +00:00
map.chess_leader_save.hide();
map.chess_leader_clear.hide();
2015-11-12 01:12:03 +00:00
map.chess_character.show();
}
if(config.chess_mode=='combat'){
2015-10-29 17:36:14 +00:00
map.battle_number.show();
map.chess_ordered.show();
2015-11-12 01:12:03 +00:00
map.free_choose.show();
map.change_choice.show();
2015-10-29 17:36:14 +00:00
}
else{
map.battle_number.hide();
map.chess_ordered.hide();
2015-11-12 01:12:03 +00:00
map.free_choose.hide();
map.change_choice.hide();
}
if(config.chess_mode=='tafang'){
map.chess_treasure.hide();
map.chess_obstacle.hide();
map.tafang_size.show();
2015-11-13 01:43:16 +00:00
map.tafang_turn.show();
2015-11-14 05:29:22 +00:00
map.tafang_difficulty.show();
2015-11-12 01:12:03 +00:00
}
else{
map.chess_treasure.show();
map.chess_obstacle.show();
map.tafang_size.hide();
2015-11-13 01:43:16 +00:00
map.tafang_turn.hide();
2015-11-14 05:29:22 +00:00
map.tafang_difficulty.hide();
2015-11-12 01:12:03 +00:00
}
if(config.chess_mode=='combat'||config.chess_mode=='tafang'){
map.ban_weak.show();
}
else{
map.ban_weak.hide();
}
},
2015-11-13 01:43:16 +00:00
tafang_turn:{
name:'游戏胜利',
init:'20',
frequent:true,
item:{
'10':'十回合',
'20':'二十回合',
'30':'三十回合',
'1000':'无限',
}
},
2015-11-12 01:12:03 +00:00
tafang_size:{
name:'战场大小',
init:'9',
frequent:true,
item:{
'6':'小',
'9':'中',
'12':'大',
2015-10-29 17:36:14 +00:00
}
},
2015-11-13 09:12:47 +00:00
tafang_difficulty:{
name:'战斗难度',
init:'2',
frequent:true,
item:{
'1':'简单',
'2':'普通',
'3':'困难',
}
},
2015-10-29 17:36:14 +00:00
chess_leader_save:{
name:'选择历程',
init:'save1',
item:{
save1:'一',
save2:'二',
save3:'三',
save4:'四',
save5:'五',
},
restart:true,
frequent:true,
},
chess_leader_clear:{
name:'清除进度',
onclick:function(){
var node=this;
if(node._clearing){
game.save(get.config('chess_leader_save'),null);
window.location.reload();
return;
}
node._clearing=true;
node.innerHTML='单击以确认 (3)';
setTimeout(function(){
node.innerHTML='单击以确认 (2)';
setTimeout(function(){
node.innerHTML='单击以确认 (1)';
setTimeout(function(){
node.innerHTML='清除进度';
delete node._clearing;
},1000);
},1000);
},1000);
},
clear:true,
frequent:true,
},
battle_number:{
name:'对战人数',
init:'3',
frequent:true,
item:{
'2':'2v2',
'3':'3v3',
'4':'4v4',
'6':'6v6',
'8':'8v8',
},
onclick:function(num){
2015-10-30 15:32:48 +00:00
game.saveConfig('battle_number',num,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(_status.event.parent.changeDialog){
_status.event.parent.changeDialog();
}
},
},
2015-11-09 03:15:16 +00:00
chess_treasure:{
2015-11-11 02:41:42 +00:00
name:'战场机关',
2015-11-09 03:15:16 +00:00
init:'0.2',
frequent:true,
item:{
'0':'关闭',
'0.1':'较少出现',
'0.2':'偶尔出现',
'0.333':'时常出现',
'0.5':'频繁出现',
}
},
chess_obstacle:{
name:'随机路障',
init:'0.333',
item:{
'0':'关闭',
'0.2':'少量',
'0.333':'中量',
'0.5':'大量',
},
frequent:true,
},
2015-11-09 17:04:18 +00:00
attack_move:{
name:'击退效果',
init:true,
// frequent:true,
},
2015-11-09 03:15:16 +00:00
show_distance:{
name:'显示距离',
init:true,
// frequent:true,
},
2015-10-29 17:36:14 +00:00
chess_ordered:{
name:'交替行动',
init:true,
2015-11-09 03:15:16 +00:00
// frequent:true,
2015-10-29 17:36:14 +00:00
},
chess_character:{
name:'战棋武将',
init:true,
2015-11-09 03:15:16 +00:00
// frequent:true,
2015-10-29 17:36:14 +00:00
},
2015-11-09 03:15:16 +00:00
chess_card:{
name:'战棋卡牌',
init:true,
// frequent:true,
2015-10-29 17:36:14 +00:00
},
free_choose:{
name:'自由选将',
init:true,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('free_choose',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat2&&get.config('free_choose')) ui.create.cheat2();
else if(ui.cheat2&&!get.config('free_choose')){
ui.cheat2.close();
delete ui.cheat2;
if(ui.cheat2x){
ui.cheat2x.close();
delete ui.cheat2;
}
}
},
},
change_choice:{
name:'开启换将卡',
init:false,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('change_choice',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat&&get.config('change_choice')) ui.create.cheat();
else if(ui.cheat&&!get.config('change_choice')){
ui.cheat.close();
delete ui.cheat;
}
},
},
ban_weak:{
name:'屏蔽弱将',
init:false,
restart:true,
2015-11-18 03:39:14 +00:00
},
ban_strong:{
name:'屏蔽强将',
init:false,
restart:true,
2015-10-29 17:36:14 +00:00
},
2015-11-09 03:15:16 +00:00
chessscroll_speed:{
name:'边缘滚动速度',
init:'20',
item:{
'0':'不滚动',
'10':'10格/秒',
'20':'20格/秒',
'30':'30格/秒',
}
},
2015-10-29 17:36:14 +00:00
}
},
stone:{
2015-12-09 05:29:35 +00:00
name:'统率',
2015-10-29 17:36:14 +00:00
config:{
battle_number:{
name:'出场人数',
init:'3',
frequent:true,
item:{
'2':'两人',
'3':'三人',
'4':'四人',
'6':'六人',
'8':'八人',
'10':'十人',
},
onclick:function(num){
2015-10-30 15:32:48 +00:00
game.saveConfig('battle_number',num,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(_status.event.parent.changeDialog){
_status.event.parent.changeDialog();
}
},
},
free_choose:{
name:'自由选将',
init:true,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('free_choose',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat2&&get.config('free_choose')) ui.create.cheat2();
else if(ui.cheat2&&!get.config('free_choose')){
ui.cheat2.close();
delete ui.cheat2;
if(ui.cheat2x){
ui.cheat2x.close();
delete ui.cheat2;
}
}
},
frequent:true,
},
change_choice:{
name:'开启换将卡',
init:false,
onclick:function(bool){
2015-10-30 15:32:48 +00:00
game.saveConfig('change_choice',bool,this._link.config.mode);
2015-10-29 17:36:14 +00:00
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat&&get.config('change_choice')) ui.create.cheat();
else if(ui.cheat&&!get.config('change_choice')){
ui.cheat.close();
delete ui.cheat;
}
},
frequent:true,
},
ban_weak:{
name:'屏蔽弱将',
init:false,
restart:true,
frequent:true,
2015-11-18 03:39:14 +00:00
},
ban_strong:{
name:'屏蔽强将',
init:false,
restart:true,
frequent:true,
2015-10-29 17:36:14 +00:00
},
}
}
},
2015-04-29 03:25:17 +00:00
status:{
running:false,
canvas:false,
time:0,
delayed:0,
frameId:0,
2015-11-04 01:59:00 +00:00
videoId:0,
2015-04-29 03:25:17 +00:00
},
help:{
2015-10-30 15:32:48 +00:00
'游戏选项':'<ul><li>控制台命令<br>开启后可用浏览器控制台控制游戏<li>自动确认<br>开启后当候选目标仅有1个时点击目标无需再点击确定<li>'+
'触屏模式<br>可消除iOS等设备上300ms的点击延迟但开启后无法使用鼠标<li>滚轮控制手牌<br>开启后滚轮可控制手牌的左右滚动建议Mac等具备横向滚动功能的设备关闭此选项'+
2015-12-09 04:55:37 +00:00
'<li>游戏玩法<br>为游戏增加不同玩法,开启后可在帮助中查看介绍',
'游戏操作':'<ul><li>长按/鼠标悬停/右键单击(需在设置中开启)显示信息<li>触屏模式中,双指点击切换暂停;下划显示菜单,上划切换托管<li>键盘快捷键<br>'+
2015-10-30 15:32:48 +00:00
'<table><tr><td>a<td>切换托管<tr><td>c<td>打开设置<tr><td>w<td>切换不询问无懈<tr><td>▭<td>暂停</ul>',
'游戏命令':'<div style="margin:10px">变量名</div><ul style="margin-top:0"><li>场上角色<br>game.players<li>阵亡角色<br>game.dead'+
'<li>玩家<br>game.me<li>玩家的上/下家<br>game.me.previous/next'+
'<li>玩家的上/下家(含阵亡)<br>game.me.previousSeat/<br>nextSeat'+
'<li>牌堆<br>ui.cardPile<li>弃牌堆<br>ui.discardPile</ul>'+
'<div style="margin:10px">角色属性</div><ul style="margin-top:0"><li>体力值<br>player.hp'+
'<li>体力上限<br>player.maxHp<li>身份<br>player.identity<li>手牌<br>player.get("h")<li>装备牌<br>player.get("e")<li>判定牌<br>player.get("j")'+
'<li>是否存活/横置/翻面<br>player.isAlive()/isLinked()/<br>isTurnedOver()</ul>'+
'<div style="margin:10px">角色操作</div><ul style="margin-top:0"><li>受到伤害<br>player.damage(source,<br>num)'+
'<li>回复体力<br>player.recover(num)<li>摸牌<br>player.draw(num)<li>获得牌<br>player.gain(cards)<li>弃牌<br>player.discard(cards)'+
'<li>使用卡牌<br>player.useCard(card,<br>targets)<li>死亡<br>player.die()<li>复活<br>player.revive(hp)</ul>'+
2015-10-31 03:20:59 +00:00
'<div style="margin:10px">游戏操作</div><ul style="margin-top:0"><li>在命令输入框中输出结果<br>game.print(str)<li>游戏结束<br>game.over(bool)'+
2015-11-07 09:20:15 +00:00
'<li>角色资料<br>lib.character<li>卡牌资料<br>lib.card',
2015-11-21 05:30:26 +00:00
'身份模式':'<div style="margin:10px">选项</div><ul style="margin-top:0"><li>加强主公<br>反贼人数多于2时主公会额外增加一个技能每个主公的额外技能固定非常备主公增加天命</ul>'+
'<div style="margin:10px">明忠</div><ul style="margin-top:0"><li>本模式需要8名玩家进行游戏使用的身份牌为1主公、2忠臣、4反贼和1内奸。游戏开始时每名玩家随机获得一个身份由系统随机选择一名忠臣身份的玩家亮出身份将忠臣牌正面朝上放在面前其他身份包括主公的玩家不亮出身份。<li>'+
2015-11-07 09:20:15 +00:00
'首先由亮出身份的忠臣玩家随机获得六张武将牌,挑选一名角色,并将选好的武将牌展示给其他玩家。之后其余每名玩家随机获得三张武将牌,各自从其中挑选一张同时亮出<li>'+
'亮出身份牌的忠臣增加1点体力上限。角色濒死和死亡的结算及胜利条件与普通身份局相同。',
2015-12-01 05:46:28 +00:00
},
help2:{
2015-11-09 03:15:16 +00:00
'战棋模式':
'<div style="margin:10px">对阵模式</div><ul style="margin-top:0"><li>n人对战n人的模式由单人控制开始游戏后随机分配位置与出牌顺序<li>'+
2015-11-09 17:04:18 +00:00
'每人在出牌阶段有一次移动的机会可移动的最大距离为2<li>'+
2015-11-07 09:20:15 +00:00
'任何卡牌或技能无法指定位置相隔8个格以上的角色为目标<li>'+
'杀死对方阵营的角色可摸一张牌,杀死本方阵营无惩罚<li>'+
2015-11-09 03:15:16 +00:00
'开启交替行动时双方无论存活角色角色多少都将轮流进行行动。在一方所有角色行动完毕进行下一轮行动时若其人数比另一方少另一方可指定至多X名角色名摸一张牌X为人数之差<li>'+
2015-11-11 02:41:42 +00:00
'开启战场机关后每个回合结束时有一定机率出现一个机关该机关不参与战斗并有一个影响周围或全体角色的效果。机关在出现后的5〜10个回合内消失<li>'+
2015-11-12 01:12:03 +00:00
'开启击退效果后,当一名角色对距离两格以内且在同一直线上的目标造成伤害后,受伤害角色将沿反方向移动一格<li>'+
2015-11-09 17:04:18 +00:00
'战场上可设置出现随机路障,角色无法移动到路障处。当一名角色的周围四格有至少三格为路障或在战场外时,其可以在回合内清除一个相邻路障</ul>'+
2015-12-09 05:29:35 +00:00
'<div style="margin:10px">君主模式</div><ul style="margin-top:0"><li>收集武将进行战斗,根据战斗难度及我方出场武将的强度,战斗胜利后将获得数量不等的金钱。没有君主出场时,获得的金钱较多<li>'+
2015-11-07 09:20:15 +00:00
'金钱可以用来招募随机武将,招到已有武将,或遣返不需要的武将时可得到招募令<li>'+
'战斗中有君主出场时可招降敌将成功率取决于敌将的稀有度、剩余体力值以及手牌数。成功后战斗立即结束且没有金钱奖励。每发动一次招降无论成功还是失败都会扣除10招募令<li>'+
'挑战武将会与该武将以及与其强度相近的武将进行战斗敌方人数与我方出场人数相同但不少于3。胜利后可通过招募令招募该武将<li>'+
2015-11-13 09:12:47 +00:00
'竞技场:<br>随机选择9名武将每次派出1〜3名武将参战。战斗中阵亡的武将不能再次上场。<br><br>战斗后武将进入疲劳状态,若立即再次出场则初始体力值-1。<br><br>战斗中本方武将行动时可召唤后援,令一名未出场的已方武将加入战斗。后援武将在战斗结束后无论存活与否均不能再次出场<br><br>当取得12场胜利或所有武将全部阵亡后结束并根据胜场数获得随机奖励</ul>'+
2015-11-13 01:43:16 +00:00
'<div style="margin:10px">塔防模式</div><ul style="margin-top:0"><li>阻上敌人到达最下方的出口,坚持到给定的回合数即获得胜利<li>'+
2015-11-13 09:12:47 +00:00
'每轮可获得10个行动点用来布置机关、招募武将或令武将行动。游戏难度将影响不同操作消耗的行动点数。未用完的行动点将减半并累积到下一轮<li>'+
'每一轮在最上方的一个随机位置增加一名敌人,若最上方已有角色,则将其下移一格<li>'+
'战场上最多出现3个相同的机关每个机关在置入战场3轮后消失。战场上最多招募10名友方角色。<li>'+
'敌方角色到达底部出口时游戏失败,已方角色到达底部出口,将被移出游戏',
2015-12-09 05:29:35 +00:00
'统率模式':'<ul><li>游戏流程类似1v1场上有两名主将进行对抗'+
2015-11-07 09:20:15 +00:00
'<li>主将出牌阶段的出牌数量行动值有上限先手为2后手为3装备牌不计入出牌上限<li>游戏每进行一轮,主将的出牌上限+1超过6时减至2并重新累加'+
'<li>牌堆中随机加入总量1/3的随从牌使用之可召唤一个随从随从出场时背面朝上。每一方在场的随从数不能超过4<li>随从于摸牌阶段摸牌基数为1随从的随从牌均视为闪装备牌均视为杀<li>'+
'随从与其他所有角色相互距离基数为1<li>'+
'主将杀死对方随从后获得一个额外的行动值并摸两张牌,杀死己方随从无惩罚,随从杀死随从无效果'+
'<li>牌堆中随机加入总量1/6的法术牌效果主要与随从有关法术牌根据强度不同可能会消耗额外的行动值'+
'<li>主将可重铸随从牌但回合内总的重铸次数不能超过3随从不能重铸任何牌包括铁索等默认可以重铸的牌'+
'<li>嘲讽:若一方阵营中有嘲讽角色,则同阵营的无嘲讽角色不以能成为杀或决斗的目标'+
'<li>行动顺序为先主将后随从。主将或随从死亡后立即移出游戏主将死亡后替补登场替补登场时摸2+X张牌X为对方存活的随从数无替补时游戏结束'
2015-04-29 03:25:17 +00:00
},
setPopped:function(node,func,width,height){
2015-04-30 03:09:07 +00:00
node._poppedfunc=func;
node._poppedwidth=width;
node._poppedheight=height;
2015-11-13 09:12:47 +00:00
if(lib.config.touchscreen){
node.listen(ui.click.hoverpopped);
}
else{
node.addEventListener('mouseenter',ui.click.hoverpopped);
2015-11-21 05:30:26 +00:00
// node.addEventListener('mouseleave',ui.click.hoverpopped_leave);
2015-11-13 09:12:47 +00:00
}
2015-04-30 03:09:07 +00:00
},
2015-04-29 03:25:17 +00:00
placePoppedDialog:function(dialog,e){
if(e.touches&&e.touches[0]){
e=e.touches[0];
}
dialog.style.height=Math.min(ui.window.offsetHeight-20,dialog.content.scrollHeight)+'px';
if(e.clientX<ui.window.offsetWidth/2){
dialog.style.left=(e.clientX+10)+'px';
}
else{
dialog.style.left=(e.clientX-dialog.offsetWidth-10)+'px';
}
var idealtop=e.clientY-dialog.offsetHeight/2;
if(idealtop<10){
idealtop=10;
}
else if(idealtop+dialog.offsetHeight+10>ui.window.offsetHeight){
idealtop=ui.window.offsetHeight-10-dialog.offsetHeight;
}
dialog.style.top=idealtop+'px';
},
2015-10-31 10:14:14 +00:00
isMobileMe:function(player){
2015-10-31 16:18:20 +00:00
return (lib.config.layout=='mobile'||lib.config.layout=='phone')&&lib.config.mode!='chess'&&player.dataset.position==0;
2015-10-31 10:14:14 +00:00
},
isNewLayout:function(){
if(lib.config.layout!='default') return true;
if(lib.config.layoutfixed.contains(lib.config.mode)) return true;
return false;
},
isSingleHandcard:function(){
2015-10-31 16:18:20 +00:00
if(game.singleHandcard||lib.config.layout=='mobile'||lib.config.layout=='phone'){
2015-10-31 10:14:14 +00:00
return true;
}
2015-12-10 15:57:45 +00:00
if(lib.config.layout=='default'&&lib.config.layoutfixed.contains(lib.config.mode)){
return true;
}
2015-10-31 10:14:14 +00:00
return false;
},
2015-04-29 03:25:17 +00:00
setHover:function(node,func,hoveration,width){
node._hoverfunc=func;
if(typeof hoveration=='number'){
node._hoveration=hoveration;
}
if(typeof width=='number'){
node._hoverwidth=width
}
node.addEventListener('mouseenter',ui.click.mouseenter);
node.addEventListener('mouseleave',ui.click.mouseleave);
node.addEventListener('mousedown',ui.click.mousedown);
node.addEventListener('mousemove',ui.click.mousemove);
return node;
},
2015-10-31 03:20:59 +00:00
setScroll:function(node){
node.ontouchstart=ui.click.touchStart;
node.ontouchmove = ui.click.touchScroll;
node.style.WebkitOverflowScrolling='touch';
return node;
},
2015-04-29 03:25:17 +00:00
setLongPress:function(node,func){
node.addEventListener('touchstart',ui.click.longpressdown);
node.addEventListener('touchend',ui.click.longpresscancel);
// node.addEventListener('mouseleave',ui.click.longpresscancel);
node._longpresscallback=func;
return node;
},
updateCanvas:function(time){
if(lib.canvasUpdates.length===0){
lib.status.canvas=false;
return false;
}
ui.canvas.width=ui.arena.offsetWidth;
ui.canvas.height=ui.arena.offsetHeight;
var ctx=ui.ctx;
ctx.shadowBlur=5;
ctx.shadowColor='rgba(0,0,0,0.3)';
ctx.strokeStyle='white';
2015-07-10 14:52:50 +00:00
// ctx.lineCap='round';
2015-04-29 03:25:17 +00:00
ctx.lineWidth=3;
ctx.save();
for(var i=0;i<lib.canvasUpdates.length;i++){
ctx.restore();
ctx.save();
var update=lib.canvasUpdates[i];
if(!update.starttime){
update.starttime=time;
}
if(update(time-update.starttime,ctx)===false){
lib.canvasUpdates.splice(i--,1);
}
}
},
run:function(time){
lib.status.time=time;
for(var i=0;i<lib.updates.length;i++){
if(!lib.updates[i].hasOwnProperty('_time')){
lib.updates[i]._time=time;
}
if(lib.updates[i](time-lib.updates[i]._time-lib.status.delayed)===false){
lib.updates.splice(i--,1);
}
}
if(lib.updates.length){
lib.status.frameId=requestAnimationFrame(lib.run);
}
else{
lib.status.time=0;
lib.status.delayed=0;
}
},
2015-11-04 01:59:00 +00:00
getUTC:function(date){
return date.getTime();
},
2015-11-06 10:05:08 +00:00
saveVideo:function(){
if(_status.videoToSave){
game.export(lib.init.encode(JSON.stringify(_status.videoToSave)),
'无名杀 - 录像 - '+_status.videoToSave.name[0]+' - '+_status.videoToSave.name[1]);
}
},
2015-04-29 03:25:17 +00:00
init:{
init:function(){
lib.config={};
var config2;
2015-05-11 11:57:44 +00:00
var config=window.config;
2015-04-29 03:25:17 +00:00
for(var i in config){
lib.config[i]=lib.init.eval(config[i]);
}
try{
config2=JSON.parse(localStorage.getItem(lib.configprefix+'config'));
if(!config2||typeof config2!='object') throw 'err'
}
catch(err){
config2={};
localStorage.setItem(lib.configprefix+'config',JSON.stringify({}));
}
if(config2.mode) lib.config.mode=config2.mode;
if(lib.config.mode_config[lib.config.mode]==undefined) lib.config.mode_config[lib.config.mode]={};
for(var i in lib.config.mode_config.global){
if(lib.config.mode_config[lib.config.mode][i]==undefined){
lib.config.mode_config[lib.config.mode][i]=lib.config.mode_config.global[i];
}
}
if(lib.config.characters){
lib.config.defaultcharacters=lib.config.characters.slice(0);
}
if(lib.config.cards){
lib.config.defaultcards=lib.config.cards.slice(0);
}
for(var i in config2){
2015-10-29 17:36:14 +00:00
if(i.indexOf('_mode_config')!=-1){
var thismode=i.substr(i.indexOf('_mode_config')+13);
if(!lib.config.mode_config[thismode]){
lib.config.mode_config[thismode]={};
}
lib.config.mode_config[thismode][i.substr(0,i.indexOf('_mode_config'))]=config2[i];
2015-04-29 03:25:17 +00:00
}
2015-04-29 05:58:19 +00:00
else{
2015-04-29 08:41:00 +00:00
lib.config[i]=config2[i];
2015-04-29 05:58:19 +00:00
}
2015-04-29 08:41:00 +00:00
2015-04-29 03:25:17 +00:00
}
for(var i in lib.config.translate){
lib.translate[i]=lib.config.translate[i];
}
2015-06-13 07:57:52 +00:00
2015-06-13 06:53:40 +00:00
lib.config.all.characters=[];
lib.config.all.cards=[];
lib.config.all.plays=[];
2015-12-01 05:46:28 +00:00
lib.config.all.mode=[];
2015-11-21 13:23:23 +00:00
var charlist=['standard','wind','fire','woods','mountain','guozhan','sp','yijiang','extra','refresh'];
2015-06-13 06:53:40 +00:00
for(i in character.pack){
2015-12-06 15:23:47 +00:00
if(lib.config.hiddenCharacterPack.indexOf(i)==-1){
lib.config.all.characters.push(i);
lib.translate[i+'_character_config']=character.pack[i];
}
2015-06-13 06:53:40 +00:00
}
for(i in card.pack){
2015-12-06 15:23:47 +00:00
if(lib.config.hiddenCardPack.indexOf(i)==-1){
lib.config.all.cards.push(i);
lib.translate[i+'_card_config']=card.pack[i];
}
2015-06-13 06:53:40 +00:00
}
for(i in play.pack){
lib.config.all.plays.push(i);
lib.translate[i+'_play_config']=play.pack[i];
}
2015-12-01 05:46:28 +00:00
for(i in mode.pack){
2015-12-06 15:23:47 +00:00
if(lib.config.hiddenModePack.indexOf(i)==-1){
lib.config.all.mode.push(i);
lib.translate[i]=mode.pack[i];
}
2015-12-01 05:46:28 +00:00
}
2015-11-24 15:52:05 +00:00
if(background&&background.pack){
for(i in background.pack){
lib.configMenu.appearence.config.image_background.item[i]=background.pack[i];
}
2015-12-01 05:46:28 +00:00
}
if(music&&music.pack){
for(i in music.pack){
lib.configMenu.audio.config.background_music.item[i]=music.pack[i];
}
2015-12-04 05:50:54 +00:00
lib.configMenu.audio.config.background_music.item.music_random='随机';
lib.configMenu.audio.config.background_music.item.music_off='关闭';
2015-12-12 08:37:15 +00:00
if(lib.config.touchscreen){
delete lib.configMenu.audio.config.background_music.item.music_custom;
}
2015-11-24 15:52:05 +00:00
}
2015-06-13 06:53:40 +00:00
delete character.pack;
delete card.pack;
delete play.pack;
2015-12-01 05:46:28 +00:00
delete mode.pack;
delete window.background;
delete window.music;
if(lib.config.all.mode.indexOf('chess')!=-1){
for(var i in lib.help2){
lib.help[i]=lib.help2[i];
}
}
delete lib.help2;
2015-06-13 06:53:40 +00:00
2015-12-06 15:23:47 +00:00
if(localStorage.getItem(lib.configprefix+'playbackmode')){
lib.init.js('mode',lib.config.mode);
}
else if((localStorage.getItem(lib.configprefix+'directstart')||!lib.config.show_splash)
&&lib.config.all.mode.indexOf(lib.config.mode)!=-1){
lib.init.js('mode',lib.config.mode);
}
2015-04-29 03:25:17 +00:00
lib.init.js('card',lib.config.all.cards);
lib.init.js('character',lib.config.all.characters);
lib.init.js('play',lib.config.plays);
2015-10-29 17:36:14 +00:00
lib.init.js('character','rank');
2015-04-29 03:25:17 +00:00
ui.css={};
2015-10-29 17:36:14 +00:00
lib.init.css('layout/default','menu');
2015-10-31 10:14:14 +00:00
var layout=lib.config.layout;
2015-05-11 11:57:44 +00:00
if(lib.config.layoutfixed.indexOf(lib.config.mode)!==-1){
2015-10-31 10:14:14 +00:00
if(layout=='default'){
2015-12-10 15:57:45 +00:00
layout='mobile';
2015-10-31 10:14:14 +00:00
}
2015-04-29 03:25:17 +00:00
}
2015-10-31 10:14:14 +00:00
ui.css.layout=lib.init.css('layout/'+layout,'layout');
2015-12-02 15:34:34 +00:00
// if(lib.config.fold_card) ui.css.fold=lib.init.css('layout/default','fold');
// if(lib.config.threed_card) ui.css.threed=lib.init.css('layout/default','fold2');
2015-04-29 03:25:17 +00:00
if(lib.config.blur_ui) ui.css.blur_ui=lib.init.css('layout/default','blur');
ui.css.theme=lib.init.css('theme/'+lib.config.theme,'style');
2015-11-18 03:39:14 +00:00
ui.css.card_style=lib.init.css('theme/style/card',lib.config.card_style);
ui.css.cardback_style=lib.init.css('theme/style/cardback',lib.config.cardback_style);
ui.css.hp_style=lib.init.css('theme/style/hp',lib.config.hp_style);
2015-10-30 09:13:19 +00:00
lib.config.duration=500;
2015-11-04 01:59:00 +00:00
2015-11-06 10:05:08 +00:00
var ua=navigator.userAgent.toLowerCase();
if(ua.indexOf('iphone')!=-1||ua.indexOf('ipad')!=-1||ua.indexOf('android')!=-1){
if(!lib.config.totouched&&!lib.config.touchscreen){
var totouch=window.confirm('您似乎在使用触屏设备,是否切换到触屏模式?');
game.saveConfig('totouched',true);
if(totouch){
game.saveConfig('touchscreen',true);
2015-11-24 15:44:21 +00:00
game.saveConfig('low_performance',true);
2015-12-04 03:16:44 +00:00
game.saveConfig('layout','phone');
2015-11-06 10:05:08 +00:00
game.reload();
}
}
}
else if(ua.indexOf('macintosh')!=-1&&!lib.config.toscrolled){
game.saveConfig('toscrolled',true);
game.saveConfig('mousewheel',false);
}
2015-11-04 01:59:00 +00:00
if(window.indexedDB){
2015-12-06 15:23:47 +00:00
var request = window.indexedDB.open(lib.configprefix+'data',3);
2015-11-04 01:59:00 +00:00
request.onupgradeneeded=function(e){
var db=e.target.result;
2015-12-02 10:40:25 +00:00
if(!db.objectStoreNames.contains('video')){
db.createObjectStore('video',{keyPath:'time'});
}
if(!db.objectStoreNames.contains('image')){
db.createObjectStore('image');
}
2015-12-03 16:28:06 +00:00
if(!db.objectStoreNames.contains('audio')){
db.createObjectStore('audio');
}
2015-12-02 10:40:25 +00:00
if(!db.objectStoreNames.contains('character')){
db.createObjectStore('character');
}
if(!db.objectStoreNames.contains('card')){
db.createObjectStore('card');
}
if(!db.objectStoreNames.contains('skill')){
db.createObjectStore('skill');
}
2015-11-04 01:59:00 +00:00
};
request.onsuccess=function(e){
var db=e.target.result;
lib.db=db;
for(var i=0;i<lib._onDB.length;i++){
lib._onDB[i]();
}
2015-12-06 15:23:47 +00:00
game.getDB('skill',null,function(skills){
if(skills){
for(var i in skills){
try{
eval('lib.skill["'+i+'"]={'+skills[i].content+'}');
}
catch(e){
console.log(e);
lib.skill[i]={};
}
lib.skill[i].createInfo=skills[i];
lib.setTranslate(i);
lib.translate[i+'_info']=skills[i].description;
}
game.finishCards();
}
game.getDB('character',null,function(list){
for(var i in list){
if(!list[i][4]) list[i][4]=[];
2015-12-07 11:15:35 +00:00
// for(var j=0;j<list[i][3].length;j++){
// if(!lib.skill[list[i][3][j]]){
// alert(list[i][3][j]);
// list[i][3].splice(j--,1);
// }
// }
2015-12-06 15:23:47 +00:00
lib.character[i]=list[i];
lib.customCharacters.push(i);
lib.setTranslate(i);
}
_status.characterLoaded=true;
if(_status.waitingForCharacters){
game.resume();
}
if(lib.onCharacterLoad){
lib.onCharacterLoad();
delete lib.onCharacterLoad;
}
});
});
2015-11-04 01:59:00 +00:00
}
}
2015-12-03 16:28:06 +00:00
lib.cardSelectObserver=new MutationObserver(function(mutations){
for(var i=0;i<mutations.length;i++){
if(mutations[i].attributeName=='class'){
var node=mutations[i].target;
if(node._transform&&node.parentNode&&node.parentNode.parentNode&&
node.parentNode.parentNode.parentNode==ui.me){
if(node.classList.contains('selected')){
setTimeout((function(node){
return function(){
if(node._transform&&node.parentNode&&node.parentNode.parentNode&&
node.parentNode.parentNode.parentNode==ui.me){
if(node.classList.contains('selected')&&
!node.parentNode.parentNode.classList.contains('scrollh')){
node.style.transform=node._transform+' translateY(-20px)';
}
else{
node.style.transform=node._transform;
}
}
}
}(node)),200);
}
else{
node.style.transform=node._transform;
}
}
}
}
});
2015-12-07 11:15:35 +00:00
var scripts=document.head.querySelectorAll('script');
for(var i=0;i<scripts.length;i++){
if(scripts[i].src&&scripts[i].src.indexOf('game/game.js')!=-1){
2015-12-10 15:57:45 +00:00
if(scripts[i].src.indexOf('ios')!=-1){
var ua=navigator.userAgent.toLowerCase();
if(ua.indexOf('ipad')!=-1){
window.isIpad=true;
}
else{
var metas=document.head.querySelectorAll('meta');
for(var i=0;i<metas.length;i++){
if(metas[i].name=='viewport'){
metas[i].content="user-scalable=no, initial-scale=0.6, maximum-scale=0.6, minimum-scale=0.6, width=device-width, height=device-height";
}
2015-12-07 11:15:35 +00:00
}
}
}
}
}
2015-04-29 03:25:17 +00:00
},
css:function(path,file,before){
var style = document.createElement("link");
style.rel = "stylesheet";
style.href = path+'/'+file+".css";
if(before){
document.head.insertBefore(style,before);
}
else{
document.head.appendChild(style);
}
return style;
},
2015-12-06 15:23:47 +00:00
js:function(path,file,onload){
2015-04-29 03:25:17 +00:00
if(typeof file=='object'){
for(var i=0;i<file.length;i++){
lib.init.js(path,file[i]);
}
}
else{
var script=document.createElement('script');
script.src = path+'/'+file+".js";
document.head.appendChild(script);
2015-12-06 15:23:47 +00:00
if(typeof onload=='function'){
script.addEventListener('load',onload);
}
2015-10-20 17:44:00 +00:00
return script;
2015-04-29 03:25:17 +00:00
}
},
2015-11-25 10:25:18 +00:00
layout:function(layout){
game.saveConfig('layout',layout);
ui.arena.hide();
setTimeout(function(){
var layout=ui.css.layout;
ui.css.layout=lib.init.css('layout/'+lib.config.layout,'layout',layout);
if(lib.config.layout=='mobile'||lib.config.layout=='phone'){
ui.arena.classList.add('mobile');
if(game.me&&game.me.node.handcards2.childNodes.length){
while(game.me.node.handcards2.childNodes.length){
game.me.node.handcards1.appendChild(game.me.node.handcards2.firstChild);
}
}
}
else{
ui.arena.classList.remove('mobile');
}
if(lib.config.layout=='default'){
ui.arena.classList.add('oldlayout');
}
else{
ui.arena.classList.remove('oldlayout');
}
if(lib.config.layout=='default'&&lib.config.hp_style=='official'){
ui.arena.classList.add('hpimage');
}
else{
ui.arena.classList.remove('hpimage');
}
2015-11-29 11:46:51 +00:00
if(lib.config.layout=='phone'){
ui.roundmenu.style.display='';
}
else{
ui.roundmenu.style.display='none';
}
2015-11-25 10:25:18 +00:00
setTimeout(function(){
layout.remove();
ui.arena.show();
if(game.me) game.me.update();
setTimeout(function(){
ui.updatex();
},500);
setTimeout(function(){
ui.updatec();
},1000);
},100);
},500);
},
2015-04-29 03:25:17 +00:00
parse:function(func){
var k,func2;
var str='(';
str+=func.toString();
if(str.indexOf('step 0')==-1){
str=str.replace(/\{/,'{{if(event.step==1) {event.finish();return;}');
}
else{
for(k=1;k<99;k++){
if(str.indexOf('step '+k)==-1) break;
str=str.replace(new RegExp("'step "+k+"'",'g'),"break;case "+k+":");
str=str.replace(new RegExp('"step '+k+'"','g'),"break;case "+k+":");
}
str=str.replace(/'step 0'|"step 0"/,'if(event.step=='+k+') {event.finish();return;}switch(step){case 0:');
}
str+='})';
return str;
},
eval:function(func){
if(typeof func=='function'){
return eval('('+func.toString()+')');
}
else if(typeof func=='object'){
for(var i in func){
if(func.hasOwnProperty(i)){
func[i]=lib.init.eval(func[i]);
}
}
}
return func;
},
encode:function(strUni){
var strUtf = strUni.replace(
/[\u0080-\u07ff]/g,function(c){
var cc = c.charCodeAt(0);
return String.fromCharCode(0xc0 | cc>>6, 0x80 | cc&0x3f);
});
strUtf = strUtf.replace(
/[\u0800-\uffff]/g,function(c) {
var cc = c.charCodeAt(0);
return String.fromCharCode(0xe0 | cc>>12, 0x80 | cc>>6&0x3F, 0x80 | cc&0x3f);
});
return btoa(strUtf);
},
decode:function(str){
var strUtf=atob(str);
var strUni = strUtf.replace(
/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g,function(c) {
var cc = ((c.charCodeAt(0)&0x0f)<<12) | ((c.charCodeAt(1)&0x3f)<<6) | ( c.charCodeAt(2)&0x3f);
return String.fromCharCode(cc);
});
strUni = strUni.replace(
/[\u00c0-\u00df][\u0080-\u00bf]/g,function(c){
var cc = (c.charCodeAt(0)&0x1f)<<6 | c.charCodeAt(1)&0x3f;
return String.fromCharCode(cc);
});
return strUni;
2015-12-06 15:23:47 +00:00
},
stringify:function(obj){
var str='{'
for(var i in obj){
str+='"'+i+'":'
if(Object.prototype.toString.call(obj[i])=='[object Object]'){
str+=lib.init.stringify(obj[i]);
}
else if(typeof obj[i]=='function'){
str+=obj[i].toString();
}
else{
str+=JSON.stringify(obj[i]);
}
str+=','
}
str+='}';
return str;
},
2015-04-29 03:25:17 +00:00
},
translate:{
'default':"默认",
2015-08-15 09:10:06 +00:00
zhenfa:'阵法',
2015-04-29 03:25:17 +00:00
heart:"♥︎",
diamond:"♦︎",
spade:"♠︎",
club:"♣︎",
2015-06-27 16:21:25 +00:00
ghujia:'护甲',
ghujia_bg:'甲',
2015-04-29 03:25:17 +00:00
heart2:"红桃",
diamond2:"方片",
spade2:"黑桃",
club2:"梅花",
red:'红色',
black:'黑色',
ok:"确定",
cancel:"取消",
restart:"重新开始",
setting:"设置",
start:"开始",
random:"随机",
_phasebegin:'回合开始',
_out:'无效',
agree:'同意',
refuse:'拒绝',
fire:"火",
thunder:"雷",
poison:"毒",
wei:'魏',
shu:'蜀',
wu:'吴',
qun:'群',
male:'男',
female:'女',
2015-05-13 10:26:54 +00:00
mad:'混乱',
mad_bg:'疯',
2015-04-29 03:25:17 +00:00
draw_card:'摸牌',
discard_card:'弃牌',
reset_character:'重置武将牌',
recover_hp:'回复体力',
lose_hp:'流失体力',
get_damage:'受伤害',
weiColor:"#b0d0e2",
shuColor:"#ffddb9",
wuColor:"#b2d9a9",
qunColor:"#f6f6f6",
basic:'基本',
equip:'装备',
trick:'锦囊',
delay:'延迟锦囊',
character:'角色',
revive:'复活',
equip1:'武器',
equip2:'防具',
equip3:'防御马',
equip4:'攻击马',
equip5:'宝物',
zero:'零',
one:'一',
two:'二',
three:'三',
four:'四',
five:'五',
six:'六',
seven:'七',
eight:'八',
nine:'九',
ten:'十',
},
element:{
playerproto:{
phase:function(){
"step 0"
2015-11-21 05:30:26 +00:00
if(player.node.judges.childElementCount){
player.popup('判定阶段');
}
2015-04-29 03:25:17 +00:00
player.phaseJudge();
"step 1"
player.phaseDraw();
2015-10-30 09:13:19 +00:00
if(player==game.me){
game.delay();
}
else{
game.delayx();
}
2015-04-29 03:25:17 +00:00
"step 2"
2015-11-23 10:59:44 +00:00
// if(!player.skipList.contains('phaseUse')) player.popup('出牌阶段');
2015-04-29 03:25:17 +00:00
player.phaseUse();
"step 3"
2015-11-30 13:08:29 +00:00
if(ui.tempnowuxie){
ui.tempnowuxie.close();
delete ui.tempnowuxie;
}
2015-04-29 03:25:17 +00:00
player.phaseDiscard()
2015-11-05 02:34:35 +00:00
game.delayx();
2015-12-08 13:54:44 +00:00
delete player.using;
2015-12-04 10:18:00 +00:00
delete player._noSkill;
2015-04-29 03:25:17 +00:00
},
phaseJudge:function(){
"step 0"
if(player.node.judges.childElementCount){
event.card=player.node.judges.firstChild;
player.lose(event.card);
2015-05-08 08:07:38 +00:00
player.$phaseJudge(event.card);
2015-04-29 03:25:17 +00:00
event.cancelled=false;
event.trigger('phaseJudge');
}
else event.finish();
"step 1"
if(!event.cancelled) player.judge(event.card);
"step 2"
var name=event.card.viewAs||event.card.name;
if(event.cancelled&&!event.direct){
if(lib.card[name].cancel){
var next=game.createEvent(name+'Cancelled');
next.content=lib.card[name].cancel;
next.card=event.card;
next.player=player;
}
}
else{
var next=game.createEvent(name);
next.content=lib.card[name].effect;
next._result=result;
next.card=event.card;
next.player=player;
}
ui.clear();
event.goto(0);
},
phaseDraw:function(){
player.draw(event.num);
},
phaseUse:function(){
"step 0";
2015-11-30 13:08:29 +00:00
player.chooseToUse();
2015-04-29 03:25:17 +00:00
"step 1"
if(result.bool){
event.goto(0);
}
2015-12-07 11:15:35 +00:00
if(ui.tempnowuxie){
ui.tempnowuxie.close();
delete ui.tempnowuxie;
}
2015-12-08 13:54:44 +00:00
delete player.using;
2015-04-29 03:25:17 +00:00
},
phaseDiscard:function(){
"step 0"
event.num=player.num('h')-game.checkMod(player,player.hp,'maxHandcard',player.get('s'));
if(event.num<=0) event.finish();
2015-11-21 05:30:26 +00:00
else{
player.popup('弃牌阶段');
}
2015-04-29 03:25:17 +00:00
event.trigger('phaseDiscard');
"step 1"
player.chooseToDiscard(num,true);
"step 2"
event.cards=result.cards;
},
chooseToUse:function(){
"step 0"
var ok=game.check();
if(event.isMine()){
if(!ok||!lib.config.auto_confirm){
game.pause();
}
if(typeof event.prompt=='string'){
if(!ok) event.dialog=ui.create.dialog(event.prompt);
}
else if(event.prompt=='function'){
if(!ok) event.dialog=ui.create.dialog(event.prompt(event));
}
else if(event.prompt==undefined){
var str;
if(typeof event.filterCard=='object'){
str='请使用'+get.cnNumber(event.selectCard[0])+'张'
if(filter.name){
str+=get.translation(filter.name);
}
else{
str+='牌';
}
}
else{
str='请选择要使用的牌';
}
if(!ok){
if(event.openskilldialog){
event.skillDialog=ui.create.dialog(event.openskilldialog);
delete event.openskilldialog;
event.dialog=str;
}
else if(typeof event.skillDialog!='string'){
event.dialog=ui.create.dialog(str);
}
else{
event.dialog=str;
}
}
}
}
else{
if(ok){
ui.click.ok();
}
else if(ai.basic.chooseCard(event.ai1)){
if(ai.basic.chooseTarget(event.ai2)){
ui.click.ok();
_status.event.aiexclude.length=0;
}
else{
2015-12-09 03:05:36 +00:00
if(!event.norestore){
if(event.skill){
var skill=event.skill;
ui.click.cancel();
event.aiexclude.add(skill);
}
else{
get.card().aiexclude();
game.uncheck();
}
event.redo();
game.resume();
2015-04-29 03:25:17 +00:00
}
else{
2015-12-09 03:05:36 +00:00
ui.click.cancel();
2015-04-29 03:25:17 +00:00
}
}
}
2015-12-09 03:05:36 +00:00
else if(event.skill&&!event.norestore){
2015-04-29 03:25:17 +00:00
var skill=event.skill;
ui.click.cancel();
event.aiexclude.add(skill);
event.redo();
game.resume();
}
else{
ui.click.cancel();
}
}
"step 1"
if(event.skillDialog&&get.objtype(event.skillDialog)=='div'){
event.skillDialog.close();
}
if(event.result.bool){
2015-11-21 05:30:26 +00:00
if(event.logSkill){
if(typeof event.logSkill=='string'){
player.logSkill(event.logSkill);
}
else if(Array.isArray(event.logSkill)){
player.logSkill.apply(player,event.logSkill);
}
}
2015-04-29 03:25:17 +00:00
if(event.result.card||!event.result.skill){
player.useCard(event.result.card,event.result.cards,event.result.targets,event.result.skill);
}
else if(event.result.skill){
player.useSkill(event.result.skill,event.result.cards,event.result.targets);
}
}
if(event.dialog&&typeof event.dialog=='object') event.dialog.close();
},
chooseToRespond:function(){
"step 0"
if(event.responded){
delete event.dialog;
return;
}
if(event.autochoose&&event.autochoose()){
event.result={bool:false};
}
else{
game.check();
if(event.isMine()){
game.pause();
if(event.dialog) event.dialog=ui.create.dialog(event.dialog);
}
else{
if(ai.basic.chooseCard(event.ai)||forced){
ui.click.ok();
}
else if(event.skill){
var skill=event.skill;
ui.click.cancel();
event.aiexclude.add(skill);
event.redo();
game.resume();
}
else{
ui.click.cancel();
}
}
}
"step 1"
if(event.result.bool){
player.respond(event.result.cards,event.result.card,event.animate,event.result.skill,event.source);
}
if(event.dialog&&event.dialog.close) event.dialog.close();
},
chooseToDiscard:function(){
"step 0"
if(event.autochoose()){
event.result={
bool:true,
cards:player.get(event.position||'h')
}
}
else{
var range=get.select(event.selectCard);
game.check();
if(event.isMine()){
game.pause();
if(range[1]>1){
event.promptdiscard=ui.create.control('提示',function(){
ai.basic.chooseCard(event.ai);
if(_status.event.custom.add.card){
_status.event.custom.add.card();
}
});
}
if(event.prompt!=false){
var str;
if(typeof(event.prompt)=='string') str=event.prompt;
else{
str='请弃置';
if(range[0]==range[1]) str+=get.cnNumber(range[0]);
else if(range[1]==Infinity) str+='至少'+get.cnNumber(range[0]);
else str+=get.cnNumber(range[0])+'至'+get.cnNumber(range[1]);
str+='张';
if(event.position=='h'||event.position==undefined) str+='手';
if(event.position=='e') str+='装备';
str+='牌';
}
event.dialog=ui.create.dialog(str);
event.dialog.add('0/'+event.selectCard[1]);
event.custom.add.card=function(){
_status.event.dialog.content.childNodes[1].innerHTML=
ui.selected.cards.length+'/'+_status.event.selectCard[1];
}
}
else if(get.itemtype(event.dialog)=='dialog'){
2015-05-08 08:07:38 +00:00
event.dialog.style.display='';
2015-04-29 03:25:17 +00:00
event.dialog.open();
}
}
else{
if(ai.basic.chooseCard(event.ai)||forced){
ui.click.ok();
}
else if(event.skill){
var skill=event.skill;
ui.click.cancel();
event.aiexclude.add(skill);
event.redo();
game.resume();
}
else{
ui.click.cancel();
}
}
}
"step 1"
if(event.promptdiscard){
event.promptdiscard.close();
}
2015-11-21 05:30:26 +00:00
if(event.logSkill&&event.result.bool){
if(typeof event.logSkill=='string'){
player.logSkill(event.logSkill);
}
else if(Array.isArray(event.logSkill)){
player.logSkill.apply(player,event.logSkill);
}
}
2015-04-29 03:25:17 +00:00
player.discard(event.result.cards);
if(event.dialog) event.dialog.close();
},
chooseToCompare:function(){
"step 0"
if(player.num('h')==0||target.num('h')==0){
event.result={cancelled:true,bool:false}
event.finish();
return;
}
2015-12-08 13:54:44 +00:00
game.log(player,'对',target,'发起拼点');
2015-04-29 03:25:17 +00:00
player.chooseCard('请选择拼点牌',true).ai=event.ai;
"step 1"
event.card1=result.cards[0];
target.chooseCard('请选择拼点牌',true).ai=event.ai;
"step 2"
event.card2=result.cards[0];
2015-09-03 03:49:14 +00:00
if(event.card2.number>=10||event.card2.number<=4){
if(target.num('h')>2){
event.addToAI=true;
}
}
2015-04-29 03:25:17 +00:00
player.lose(event.card1);
target.lose(event.card2);
"step 3"
2015-11-06 10:05:08 +00:00
ui.arena.classList.add('thrownhighlight');
game.addVideo('thrownhighlight1');
2015-04-29 03:25:17 +00:00
player.$compare(event.card1,target,event.card2);
// player.$throw(event.card1);
// target.$throw(event.card2);
2015-12-08 13:54:44 +00:00
game.log(player,'的拼点牌为',event.card1);
game.log(target,'的拼点牌为',event.card2);
2015-04-29 03:25:17 +00:00
event.result={
player:event.card1,
target:event.card2,
}
if(get.number(event.card1)>get.number(event.card2)){
event.result.bool=true;
setTimeout(function(){
event.dialog=ui.create.dialog(get.translation(player.name)+'拼点成功');
2015-05-09 02:56:55 +00:00
event.dialog.classList.add('center');
2015-04-29 03:25:17 +00:00
player.popup('胜');
target.popup('负');
game.resume();
},1500);
}
else{
event.result.bool=false;
if(get.number(event.card1)>get.number(event.card2)){
event.result.tie=true;
setTimeout(function(){
event.dialog=ui.create.dialog(get.translation(player.name)+'拼点失败');
2015-05-09 02:56:55 +00:00
event.dialog.classList.add('center');
2015-04-29 03:25:17 +00:00
player.popup('平');
target.popup('平');
game.resume();
},1500);
}
else{
setTimeout(function(){
event.dialog=ui.create.dialog(get.translation(player.name)+'拼点失败');
2015-05-09 02:56:55 +00:00
event.dialog.classList.add('center');
2015-04-29 03:25:17 +00:00
player.popup('负');
target.popup('胜');
game.resume();
},1500);
}
}
game.pause();
"step 4"
game.delay(2);
"step 5"
2015-09-03 03:49:14 +00:00
if(typeof event.target.ai.shown=='number'&&event.target.ai.shown<=0.85&&event.addToAI){
2015-04-29 03:25:17 +00:00
event.target.ai.shown+=0.1;
}
2015-11-06 10:05:08 +00:00
ui.arena.classList.remove('thrownhighlight');
game.addVideo('thrownhighlight2');
2015-04-29 03:25:17 +00:00
if(event.clear!==false) ui.clear();
event.dialog.close();
},
chooseButton:function(){
"step 0"
if(event.dialog==undefined) event.dialog=ui.dialog;
if(event.isMine()){
2015-05-08 08:07:38 +00:00
event.dialog.style.display='';
2015-04-29 03:25:17 +00:00
event.dialog.open();
}
game.check();
if(event.isMine()){
game.pause();
}
else{
if(ai.basic.chooseButton(event.ai)||forced) ui.click.ok();
else ui.click.cancel();
}
"step 1"
if(event.closeDialog){
event.dialog.close();
}
},
chooseCard:function(){
"step 0"
game.check();
if(event.isMine()){
game.pause();
if(event.prompt!=false){
var str;
if(typeof event.prompt=='string') str=event.prompt;
else{
str='请选择'
var range=get.select(event.selectCard);
if(range[0]==range[1]) str+=get.cnNumber(range[0]);
else if(range[1]==Infinity) str+='至少'+get.cnNumber(range[0]);
else str+=get.cnNumber(range[0])+'至'+get.cnNumber(range[1]);
str+='张';
if(event.position=='h'||event.position==undefined) str+='手';
if(event.position=='e') str+='装备';
str+='牌';
}
event.dialog=ui.create.dialog(str);
event.dialog.add('0/'+event.selectCard[1]);
event.custom.add.card=function(){
_status.event.dialog.content.childNodes[1].innerHTML=
ui.selected.cards.length+'/'+_status.event.selectCard[1];
}
}
}
else{
if(ai.basic.chooseCard(event.ai)||forced){
ui.click.ok();
}
else if(event.skill){
var skill=event.skill;
ui.click.cancel();
event.aiexclude.add(skill);
event.redo();
game.resume();
}
else{
ui.click.cancel();
}
}
"step 1"
if(event.dialog) event.dialog.close();
},
chooseTarget:function(){
"step 0"
game.check();
if(event.isMine()){
game.pause();
if(event.prompt!=false){
var str;
if(typeof event.prompt=='string') str=event.prompt;
else{
str='请选择'
var range=get.select(event.selectTarget);
if(range[0]==range[1]) str+=get.cnNumber(range[0]);
else if(range[1]==Infinity) str+='至少'+get.cnNumber(range[0]);
else str+=get.cnNumber(range[0])+'至'+get.cnNumber(range[1]);
str+='个目标';
}
event.dialog=ui.create.dialog(str);
event.dialog.add('0/'+event.selectTarget[1]);
event.custom.add.target=function(){
_status.event.dialog.content.childNodes[1].innerHTML=
ui.selected.targets.length+'/'+_status.event.selectTarget[1];
}
}
else if(get.itemtype(event.dialog)=='dialog'){
event.dialog.open();
}
}
else{
if(ai.basic.chooseTarget(event.ai)||forced){
ui.click.ok();
}
else{
ui.click.cancel();
}
}
"step 1"
if(event.result.bool){
for(var i=0;i<event.result.targets.length;i++){
event.result.targets[i].animate('target');
}
}
if(event.dialog) event.dialog.close();
},
chooseCardTarget:function(){
"step 0"
game.check();
if(event.isMine()){
game.pause();
if(event.prompt!=false){
event.dialog=ui.create.dialog(event.prompt||'请选择卡牌和目标');
}
}
else{
if(ai.basic.chooseCard(event.ai1)){
if(ai.basic.chooseTarget(event.ai2)){
ui.click.ok();
_status.event.aiexclude.length=0;
}
else{
get.card().aiexclude();
game.uncheck();
event.redo();
game.resume();
}
}
else{
ui.click.cancel();
}
}
"step 1"
if(event.result.bool){
for(var i=0;i<event.result.targets.length;i++){
event.result.targets[i].animate('target');
}
}
if(event.dialog) event.dialog.close();
},
chooseControl:function(){
"step 0"
if(event.controls.length==0){
event.finish();
return;
}
if(event.isMine()){
event.controlbar=ui.create.control(event.controls);
if(event.dialog){
event.dialog.open();
}
else if(event.prompt){
event.dialog=ui.create.dialog(event.prompt);
}
game.pause();
_status.imchoosing=true;
}
else{
event.result={};
if(event.ai){
var result=event.ai(event.parent,player);
if(typeof result=='number') event.result.control=event.controls[result];
else event.result.control=result;
}
else event.result.control=event.controls[event.choice];
}
"step 1"
_status.imchoosing=false;
if(event.dialog) event.dialog.close();
if(event.controlbar) event.controlbar.close();
},
chooseBool:function(){
"step 0"
if(event.isMine()){
ui.create.confirm('oc');
2015-06-19 15:31:36 +00:00
if(event.dialog){
event.dialog.open();
}
else if(event.prompt){
2015-04-29 03:25:17 +00:00
event.dialog=ui.create.dialog(event.prompt);
}
_status.imchoosing=true;
game.pause();
}
else{
if(event.ai){
event.choice=event.ai(event.parent,player);
}
event.result={bool:event.choice};
}
"step 1"
_status.imchoosing=false;
if(event.dialog) event.dialog.close();
},
choosePlayerCard:function(){
"step 0"
if(!event.dialog) event.dialog=ui.create.dialog('hidden');
else if(!event.isMine){
event.dialog.style.display='none';
}
if(event.prompt){
event.dialog.add(event.prompt);
}
else{
event.dialog.add('选择'+get.translation(target)+'的一张牌');
}
for(var i=0;i<event.position.length;i++){
if(event.position[i]=='h'&&target.num('h')){
event.dialog.add('手牌');
var hs=target.get('h');
2015-05-03 15:17:15 +00:00
hs.randomSort();
2015-12-06 15:23:47 +00:00
if(event.visible||target==player){
2015-04-29 03:25:17 +00:00
event.dialog.add(hs);
}
else{
event.dialog.add([hs,'blank']);
}
}
else if(event.position[i]=='e'&&target.num('e')){
event.dialog.add('装备牌');
event.dialog.add(target.get('e'));
}
else if(event.position[i]=='j'&&target.num('j')){
event.dialog.add('判定牌');
event.dialog.add(target.get('j'));
}
}
if(event.dialog.buttons.length==0){
event.finish();
return;
}
if(event.isMine()){
event.dialog.open();
}
game.check();
if(event.isMine()){
game.pause();
}
else{
if(ai.basic.chooseButton(event.ai)||forced) ui.click.ok();
else ui.click.cancel();
}
"step 1"
event.dialog.close();
},
discardPlayerCard:function(){
"step 0"
if(!event.dialog) event.dialog=ui.create.dialog('hidden');
else if(!event.isMine){
event.dialog.style.display='none';
}
if(event.prompt==undefined){
var str='弃置'+get.translation(target);
var range=get.select(event.selectButton);
if(range[0]==range[1]) str+=get.cnNumber(range[0]);
else if(range[1]==Infinity) str+='至少'+get.cnNumber(range[0]);
else str+=get.cnNumber(range[0])+'至'+get.cnNumber(range[1]);
str+='张';
if(event.position=='h'||event.position==undefined) str+='手';
if(event.position=='e') str+='装备';
str+='牌';
event.prompt=str;
}
if(event.prompt){
event.dialog.add(event.prompt);
}
for(var i=0;i<event.position.length;i++){
if(event.position[i]=='h'&&target.num('h')){
event.dialog.add('手牌');
var hs=target.get('h');
2015-05-03 15:17:15 +00:00
hs.randomSort();
2015-04-29 03:25:17 +00:00
if(event.visible){
event.dialog.add(hs);
}
else{
event.dialog.add([hs,'blank']);
}
}
else if(event.position[i]=='e'&&target.num('e')){
event.dialog.add('装备牌');
event.dialog.add(target.get('e'));
}
else if(event.position[i]=='j'&&target.num('j')){
event.dialog.add('判定牌');
event.dialog.add(target.get('j'));
}
}
if(event.dialog.buttons.length==0){
event.finish();
return;
}
if(event.isMine()){
event.dialog.open();
}
game.check();
if(event.isMine()){
game.pause();
}
else{
if(ai.basic.chooseButton(event.ai)||forced) ui.click.ok();
else ui.click.cancel();
}
"step 1"
event.dialog.close();
"step 2"
if(event.result.bool&&event.result.buttons){
var cards=[];
for(var i=0;i<event.result.buttons.length;i++){
cards.push(event.result.buttons[i].link);
}
target.discard(cards);
}
},
gainPlayerCard:function(){
"step 0"
if(!event.dialog) event.dialog=ui.create.dialog('hidden');
else if(!event.isMine){
event.dialog.style.display='none';
}
if(event.prompt==undefined){
var str='获得'+get.translation(target);
var range=get.select(event.selectButton);
if(range[0]==range[1]) str+=get.cnNumber(range[0]);
else if(range[1]==Infinity) str+='至少'+get.cnNumber(range[0]);
else str+=get.cnNumber(range[0])+'至'+get.cnNumber(range[1]);
str+='张';
if(event.position=='h'||event.position==undefined) str+='手';
if(event.position=='e') str+='装备';
str+='牌';
event.prompt=str;
}
if(event.prompt){
event.dialog.add(event.prompt);
}
for(var i=0;i<event.position.length;i++){
if(event.position[i]=='h'&&target.num('h')){
event.dialog.add('手牌');
var hs=target.get('h');
2015-05-03 15:17:15 +00:00
hs.randomSort();
2015-04-29 03:25:17 +00:00
if(event.visible){
event.dialog.add(hs);
}
else{
event.dialog.add([hs,'blank']);
}
}
else if(event.position[i]=='e'&&target.num('e')){
event.dialog.add('装备牌');
event.dialog.add(target.get('e'));
}
else if(event.position[i]=='j'&&target.num('j')){
event.dialog.add('判定牌');
event.dialog.add(target.get('j'));
}
}
if(event.dialog.buttons.length==0){
event.dialog.close();
event.finish();
return;
}
if(event.isMine()){
event.dialog.open();
}
game.check();
if(event.isMine()){
game.pause();
}
else{
if(ai.basic.chooseButton(event.ai)||forced) ui.click.ok();
else ui.click.cancel();
}
"step 1"
event.dialog.close();
"step 2"
var cards=[];
for(var i=0;i<event.result.buttons.length;i++){
cards.push(event.result.buttons[i].link);
}
2015-05-01 09:34:01 +00:00
target.lose(cards);
event.cards=cards;
2015-04-29 03:25:17 +00:00
var hs=[],oths=[];
for(var i=0;i<cards.length;i++){
if(get.position(cards[i])=='h'){
hs.push(cards[i]);
}
else{
oths.push(cards[i]);
}
}
if(hs.length){
target.$give(hs.length,player);
}
2015-05-01 09:34:01 +00:00
if(oths.length){
2015-04-29 03:25:17 +00:00
target.$give(oths,player);
}
2015-05-01 09:34:01 +00:00
"step 3"
if(player==game.me){
game.delay(2);
}
else{
2015-11-05 02:34:35 +00:00
game.delayx();
2015-05-01 09:34:01 +00:00
}
player.gain(event.cards);
2015-04-29 03:25:17 +00:00
},
showHandcards:function(){
"step 0"
if(player.num('h')==0){
event.finish();
return;
}
var cards=player.get('h');
2015-11-04 01:59:00 +00:00
var str=get.translation(player.name)+'的手牌';
event.dialog=ui.create.dialog(str,cards);
2015-12-08 13:54:44 +00:00
game.log(player,'展示了',cards);
2015-11-04 01:59:00 +00:00
game.addVideo('showCards',player,[str,get.cardsInfo(cards)]);
2015-11-05 02:34:35 +00:00
game.delayx(2);
2015-04-29 03:25:17 +00:00
"step 1"
event.dialog.close();
},
showCards:function(){
"step 0"
if(get.itemtype(cards)!='cards'){
event.finish();
return;
}
2015-06-27 16:21:25 +00:00
if(!event.str){
event.str=get.translation(player.name)+'展示的牌';
}
event.dialog=ui.create.dialog(event.str,cards);
2015-12-08 13:54:44 +00:00
game.log(player,'展示了',cards);
2015-11-05 02:34:35 +00:00
game.delayx(2);
2015-11-04 01:59:00 +00:00
game.addVideo('showCards',player,[event.str,get.cardsInfo(cards)]);
2015-04-29 03:25:17 +00:00
"step 1"
event.dialog.close();
},
viewHandcards:function(){
"step 0"
if(player==game.me&&target){
event.dialog=ui.create.dialog(get.translation(target.name)+'的手牌',target.get('h'));
if(event.isMine()){
game.pause();
_status.imchoosing=true;
ui.create.confirm('o');
}
else{
event.finish();
setTimeout(function(){
event.dialog.close();
},2*lib.config.duration);
2015-11-05 02:34:35 +00:00
game.delayx(2);
2015-04-29 03:25:17 +00:00
}
}
else{
event.finish();
}
"step 1"
_status.imchoosing=false;
event.dialog.close();
},
useCard:function(){
"step 0"
2015-06-16 13:24:35 +00:00
if(!card){
console.log('err: no card',get.translation(event.player));
event.finish();
return;
}
2015-04-29 03:25:17 +00:00
player.lose(cards);
2015-12-08 00:56:54 +00:00
player.using=cards;
2015-06-13 07:57:52 +00:00
var cardaudio=true;
2015-04-29 03:25:17 +00:00
if(event.skill){
2015-06-13 07:57:52 +00:00
if(lib.skill[event.skill].audio){
cardaudio=false;
}
2015-05-04 03:17:03 +00:00
player.logSkill(event.skill);
2015-05-03 15:17:15 +00:00
player.popup(event.card.name);
2015-04-29 03:25:17 +00:00
}
2015-06-13 07:57:52 +00:00
if(cardaudio&&lib.config.background_audio){
2015-04-29 14:56:33 +00:00
var sex=player.sex=='female'?'female':'male';
2015-05-08 08:07:38 +00:00
if(lib.card[card.name].audio||lib.config.background_ogg){
if(card.name=='sha'&&(card.nature=='fire'||card.nature=='thunder')){
game.playAudio('card',sex,card.name+'_'+card.nature);
}
else{
game.playAudio('card',sex,card.name);
}
2015-04-29 14:56:33 +00:00
}
2015-05-14 09:23:45 +00:00
else if(get.type(card)!='equip'){
2015-05-08 08:07:38 +00:00
game.playAudio('card/default');
2015-04-29 14:56:33 +00:00
}
}
2015-04-29 03:25:17 +00:00
if(event.animate!=false){
if(card.name=='wuxie'&&event.parent.source){
2015-12-06 15:23:47 +00:00
var lining=event.parent.source2||event.parent.source;
if(Array.isArray(lining)&&event.parent.parent._trigger.name=='jiedao'){
player.line(lining[0],'green');
}
else{
player.line(lining,'green');
}
2015-04-29 03:25:17 +00:00
}
else{
var config={};
if(card.nature=='fire'||
(card.classList&&card.classList.contains('fire'))){
config.color='fire';
}
else if(card.nature=='thunder'||
(card.classList&&card.classList.contains('thunder'))){
config.color='thunder';
}
if(get.info(card).multitarget&&targets.length>1&&!get.info(card).multiline){
player.line2(targets,config);
}
else{
player.line(targets,config);
}
}
player.$throw(cards);
}
event.trigger('useCard');
2015-11-06 10:05:08 +00:00
// if(event.card.name=='sha'&&lib.config.animation){
// player.$sha(event.card.nature);
// }
2015-04-29 03:25:17 +00:00
if(get.type(card)!='equip'){
2015-12-08 13:54:44 +00:00
var str='';
2015-04-29 03:25:17 +00:00
if(targets.length){
2015-12-08 13:54:44 +00:00
str+='对<span class="bluetext">'+(targets[0]==player?'自己':get.translation(targets[0]));
2015-04-29 03:25:17 +00:00
for(var i=1;i<targets.length;i++){
str+='、'+(targets[i]==player?'自己':get.translation(targets[i]));
}
2015-12-08 13:54:44 +00:00
str+='</span>'
2015-04-29 03:25:17 +00:00
}
2015-12-08 13:54:44 +00:00
str+='使用了';
2015-04-29 03:25:17 +00:00
if(cards.length&&(cards.length>1||cards[0]!=card)){
2015-12-08 13:54:44 +00:00
game.log(player,str,card,'',cards,'');
}
else{
game.log(player,str,card);
2015-04-29 03:25:17 +00:00
}
}
if(event.addCount!=false){
if(player.stat[player.stat.length-1].card[card.name]==undefined){
player.stat[player.stat.length-1].card[card.name]=1;
}
else{
player.stat[player.stat.length-1].card[card.name]++;
}
if(event.skill){
if(player.stat[player.stat.length-1].skill[event.skill]==undefined){
player.stat[player.stat.length-1].skill[event.skill]=1;
}
else{
player.stat[player.stat.length-1].skill[event.skill]++;
}
}
}
"step 1"
if(get.info(card).contentBefore){
var next=game.createEvent(card.name+'ContentBefore');
next.content=get.info(card).contentBefore;
next.targets=targets;
next.card=card;
next.cards=cards;
next.player=player;
}
"step 2"
if(targets[num]&&targets[num].isDead()) return;
if(targets[num]&&targets[num].isOut()) return;
if(targets[num]&&targets[num].removed) return;
var info=get.info(card);
if(targets.length==0&&!info.notarget) return;
var next=game.createEvent(card.name);
next.content=info.content;
next.targets=targets;
next.card=card;
next.cards=cards;
next.player=player;
next.num=num;
next.type='card';
next.skill=event.skill;
next.multitarget=info.multitarget;
2015-11-04 01:59:00 +00:00
next.preResult=event.preResult;
2015-04-29 03:25:17 +00:00
if(num==0&&next.targets.length>1){
if(!info.multitarget){
lib.tempSortSeat=player;
targets.sort(lib.sort.seat);
delete lib.tempSortSeat;
for(var i=0;i<targets.length;i++){
targets[i].animate('target');
}
}
else{
for(var i=0;i<targets.length;i++){
targets[i].animate('target');
}
}
}
next.target=targets[num];
if(next.target&&!info.multitarget){
if(num==0&&targets.length>1){
// var ttt=next.target;
// setTimeout(function(){ttt.animate('target');},0.5*lib.config.duration);
}
else{
next.target.animate('target');
}
}
if(event.animate!=false||num>0){
2015-11-21 05:30:26 +00:00
if(num==0){
2015-12-02 10:40:25 +00:00
if(event.delayx!==false){
game.delayx();
}
2015-11-21 05:30:26 +00:00
}
2015-10-30 09:13:19 +00:00
else game.delayx(0.5);
2015-04-29 03:25:17 +00:00
}
"step 3"
if(!get.info(event.card).multitarget&&num<targets.length-1){
event.num++;
event.goto(2);
}
"step 4"
if(get.info(card).contentAfter){
var next=game.createEvent(card.name+'contentAfter');
next.content=get.info(card).contentAfter;
next.targets=targets;
next.card=card;
next.cards=cards;
next.player=player;
2015-11-04 01:59:00 +00:00
next.preResult=event.preResult;
2015-04-29 03:25:17 +00:00
}
"step 5"
2015-12-08 00:56:54 +00:00
delete player.using;
2015-04-29 03:25:17 +00:00
if(document.getElementsByClassName('thrown').length){
2015-11-21 05:30:26 +00:00
if(event.delayx!==false) game.delayx();
2015-04-29 03:25:17 +00:00
}
else{
event.finish();
}
"step 6"
2015-11-09 03:15:16 +00:00
if(event.card.name!='wuxie') ui.clear();
2015-11-26 08:15:28 +00:00
if(ui.tempnowuxie&&ui.tempnowuxie._origin==event){
ui.tempnowuxie.close();
delete ui.tempnowuxie;
}
2015-04-29 03:25:17 +00:00
},
useSkill:function(){
"step 0"
var info=get.info(event.skill);
2015-05-12 15:10:35 +00:00
event._skill=event.skill;
2015-06-16 13:52:39 +00:00
if(lib.config.background_speak&&
(!lib.skill.global.contains(event.skill)||lib.skill[event.skill].forceaudio)){
2015-05-14 09:23:45 +00:00
if(typeof info.audio=='number'){
game.playAudio('skill',event.skill+Math.ceil(info.audio*Math.random()));
}
2015-05-14 09:23:45 +00:00
else if(info.audio){
2015-05-08 08:07:38 +00:00
game.playAudio('skill',event.skill);
}
2015-11-23 10:59:44 +00:00
else if(lib.config.background_ogg&&info.audio!==false){
2015-05-16 11:22:27 +00:00
game.playSkillAudio(event.skill);
}
2015-04-29 14:56:33 +00:00
}
2015-04-29 03:25:17 +00:00
if(player.checkShow){
player.checkShow(event.skill);
}
if(info.discard!=false&&info.lose!=false&&!info.viewAs){
player.discard(cards).delay=false;
}
else{
if(info.lose!=false){
player.lose(cards,ui.special);
}
if(info.prepare){
info.prepare(cards,player,targets);
}
else if(info.viewAs){
player.$throw(cards);
}
}
if((info.line||info.discard!=false)&&targets.length){
var config={};
if(info.line=='fire'){
config.color='fire';
}
else if(info.line=='thunder'){
config.color='thunder';
}
2015-05-16 11:40:11 +00:00
else if(info.line===undefined){
config.color='green';
}
2015-04-29 03:25:17 +00:00
if(info.multitarget&&!info.multiline&&targets.length>1){
player.line2(targets,config);
}
else{
player.line(targets,config);
}
}
2015-12-08 13:54:44 +00:00
var str='';
2015-04-29 03:25:17 +00:00
if(targets&&targets.length){
2015-12-08 13:54:44 +00:00
str+='对<span class="bluetext">'+(targets[0]==player?'自己':get.translation(targets[0]));
2015-04-29 03:25:17 +00:00
for(var i=1;i<targets.length;i++){
str+='、'+(targets[i]==player?'自己':get.translation(targets[i]));
}
2015-12-08 13:54:44 +00:00
str+='</span>'
2015-04-29 03:25:17 +00:00
}
2015-12-08 13:54:44 +00:00
str+='发动了';
2015-04-29 03:25:17 +00:00
if(!info.direct){
2015-12-08 13:54:44 +00:00
game.log(player,str,'【'+get.translation(skill)+'】');
2015-04-29 03:25:17 +00:00
player.popup(skill);
}
if(event.addCount!=false){
if(player.stat[player.stat.length-1].skill[skill]==undefined){
player.stat[player.stat.length-1].skill[skill]=1;
}
else{
player.stat[player.stat.length-1].skill[skill]++;
}
}
2015-12-04 10:18:00 +00:00
if(player.stat[player.stat.length-1].allSkills==undefined){
player.stat[player.stat.length-1].allSkills=1;
}
else{
player.stat[player.stat.length-1].allSkills++;
}
2015-04-29 03:25:17 +00:00
"step 1"
if(!event.skill){
console.log('error: no skill',get.translation(event.player),event.player.get('s'));
2015-05-12 15:10:35 +00:00
if(event._skill){
event.skill=event._skill;
console.log(event._skill);
}
else{
event.finish();
return;
}
2015-04-29 03:25:17 +00:00
}
var info=get.info(event.skill);
if(targets[num]&&targets[num].isDead()||
targets[num]&&targets[num].isOut()||
targets[num]&&targets[num].removed){
if(!info.multitarget&&num<targets.length-1){
event.num++;
event.redo();
}
return;
}
var next=game.createEvent(event.skill);
next.content=info.content;
next.targets=targets;
next.cards=cards;
next.player=player;
next.num=num;
next.multitarget=info.multitarget;
if(num==0&&next.targets.length>1){
if(!info.multitarget){
lib.tempSortSeat=player;
targets.sort(lib.sort.seat);
delete lib.tempSortSeat;
}
for(var i=0;i<targets.length;i++){
targets[i].animate('target');
}
}
next.target=targets[num];
if(next.target&&!info.multitarget){
if(num==0&&targets.length>1){
// var ttt=next.target;
// setTimeout(function(){ttt.animate('target');},0.5*lib.config.duration);
}
else{
next.target.animate('target');
}
}
if(num==0){
if(typeof info.delay=='number') game.delay(info.delay);
2015-10-30 09:13:19 +00:00
else if(info.delay!==false&&info.delay!==0) game.delayx();
2015-04-29 03:25:17 +00:00
}
2015-10-30 09:13:19 +00:00
else game.delayx(0.5);
2015-04-29 03:25:17 +00:00
if(!info.multitarget&&num<targets.length-1){
event.num++;
event.redo();
}
"step 2"
2015-12-04 10:18:00 +00:00
if(player.getStat().allSkills>200){
player._noSkill=true;
console.log(player.name,event.skill);
}
2015-04-29 03:25:17 +00:00
if(document.getElementsByClassName('thrown').length){
2015-11-05 02:34:35 +00:00
if(event.skill&&get.info(event.skill).delay!==0) game.delayx();
2015-04-29 03:25:17 +00:00
}
else{
event.finish();
}
"step 3"
ui.clear();
},
draw:function(){
if(lib.config.background_audio){
game.playAudio('effect','draw');
}
if(event.log!=false){
2015-12-08 13:54:44 +00:00
game.log(player,'摸了'+get.cnNumber(num)+'张牌');
}
2015-04-29 03:25:17 +00:00
var cards=get.cards(num);
if(event.animate!=false){
player.gain(cards,'draw');
}
else{
player.gain(cards);
}
event.result=cards;
},
discard:function(){
"step 0"
if(lib.config.background_audio){
game.playAudio('effect','discard');
}
2015-12-08 13:54:44 +00:00
game.log(player,'弃置了',cards);
2015-04-29 03:25:17 +00:00
player.lose(cards);
if(event.animate!=false) player.$throw(cards,1000);
event.trigger('discard');
"step 1"
2015-11-05 02:34:35 +00:00
if(event.delay!=false) game.delayx();
2015-04-29 03:25:17 +00:00
},
respond:function(){
2015-06-13 07:57:52 +00:00
var cardaudio=true;
2015-04-29 03:25:17 +00:00
if(event.skill){
2015-06-13 07:57:52 +00:00
if(lib.skill[event.skill].audio){
cardaudio=false;
}
2015-04-30 08:24:57 +00:00
player.logSkill(event.skill);
2015-04-29 03:25:17 +00:00
if(player.checkShow){
player.checkShow(event.skill);
}
}
2015-06-13 07:57:52 +00:00
if(cardaudio&&event.parent.parent.parent.name=='useCard'){
if(lib.config.background_audio){
2015-04-29 14:56:33 +00:00
var sex=player.sex=='female'?'female':'male';
2015-05-08 08:07:38 +00:00
if(lib.card[card.name].audio||lib.config.background_ogg){
game.playAudio('card',sex,card.name);
}
else{
game.playAudio('card/default');
}
2015-04-29 14:56:33 +00:00
}
}
2015-04-29 03:25:17 +00:00
if(cards.length&&(cards.length>1||cards[0].name!=card.name)){
2015-12-08 13:54:44 +00:00
game.log(player,'打出了',card,'',cards,'');
}
else{
game.log(player,'打出了',card);
2015-04-29 03:25:17 +00:00
}
for(var i=0;i<cards.length;i++){
player.lose(cards[i]);
if(event.animate!=false) player.$throw(cards[i]);
2015-11-06 10:05:08 +00:00
if(event.highlight){
cards[i].clone.classList.add('thrownhighlight');
game.addVideo('highlightnode',player,get.cardInfo(cards[i]));
}
2015-04-29 03:25:17 +00:00
var name='';
if(event.skill) name=get.translation(event.skill)+'';
if(event.card) name+=get.translation(event.card.name);
}
event.trigger('respond');
2015-10-30 09:13:19 +00:00
game.delayx(0.5);
2015-04-29 03:25:17 +00:00
},
gain:function(){
"step 0"
if(cards){
event.source=get.owner(cards[0]);
if(event.source){
2015-05-01 09:34:01 +00:00
event.source.lose(cards,ui.special);
2015-04-29 03:25:17 +00:00
}
}
else{
event.finish();
}
"step 1"
2015-11-05 02:34:35 +00:00
if(event.source) game.delayx();
2015-04-29 03:25:17 +00:00
"step 2"
if(player.getStat().gain==undefined){
player.getStat().gain=cards.length;
}
else{
player.getStat().gain+=cards.length;
}
"step 3"
var j,sort,position;
var frag1=document.createDocumentFragment();
var frag2=document.createDocumentFragment();
2015-11-04 01:59:00 +00:00
var hs=player.get('h');
for(var i=0;i<cards.length;i++){
if(hs.contains(cards[i])){
cards.splice(i--,1);
}
}
2015-04-29 03:25:17 +00:00
for(var num=0;num<cards.length;num++){
sort=lib.config.sort_card(cards[num]);
if(lib.config.reverse_sort) sort=-sort;
cards[num].fix();
2015-11-24 00:50:54 +00:00
cards[num].style.transform='';
2015-12-02 15:34:34 +00:00
if(player==game.me){
2015-11-24 00:50:54 +00:00
cards[num].classList.add('drawinghidden');
}
2015-05-13 10:26:54 +00:00
2015-10-31 10:14:14 +00:00
if(lib.isSingleHandcard()||sort>0) frag1.appendChild(cards[num]);
2015-05-13 10:26:54 +00:00
else frag2.appendChild(cards[num]);
2015-04-29 03:25:17 +00:00
}
2015-11-04 01:59:00 +00:00
var addv=function(){
if(player==game.me){
game.addVideo('gain12',player,[get.cardsInfo(frag1.childNodes),get.cardsInfo(frag2.childNodes)]);
}
};
2015-05-13 10:26:54 +00:00
if(event.animate=='draw'){
player.$draw(cards.length);
2015-11-05 02:34:35 +00:00
game.delayx(1,500);
2015-05-13 10:26:54 +00:00
setTimeout(function(){
2015-11-04 01:59:00 +00:00
addv();
2015-04-29 03:25:17 +00:00
player.node.handcards1.insertBefore(frag1,player.node.handcards1.firstChild);
player.node.handcards2.insertBefore(frag2,player.node.handcards2.firstChild);
player.update();
2015-11-24 15:44:21 +00:00
if(player==game.me) ui.updatehl();
2015-05-13 10:26:54 +00:00
},500);
}
else if(event.animate=='gain'){
player.$gain(cards);
2015-11-05 02:34:35 +00:00
game.delayx(1,700);
2015-05-13 10:26:54 +00:00
setTimeout(function(){
2015-11-04 01:59:00 +00:00
addv();
2015-05-13 10:26:54 +00:00
player.node.handcards1.insertBefore(frag1,player.node.handcards1.firstChild);
player.node.handcards2.insertBefore(frag2,player.node.handcards2.firstChild);
player.update();
2015-11-24 15:44:21 +00:00
if(player==game.me) ui.updatehl();
2015-05-13 10:26:54 +00:00
},700);
}
else if(event.animate=='gain2'||event.animate=='draw2'){
player.$gain2(cards);
2015-11-05 02:34:35 +00:00
game.delayx(1,500);
2015-05-13 10:26:54 +00:00
setTimeout(function(){
2015-11-04 01:59:00 +00:00
addv();
2015-05-13 10:26:54 +00:00
player.node.handcards1.insertBefore(frag1,player.node.handcards1.firstChild);
player.node.handcards2.insertBefore(frag2,player.node.handcards2.firstChild);
player.update();
2015-11-24 15:44:21 +00:00
if(player==game.me) ui.updatehl();
2015-05-13 10:26:54 +00:00
},500);
}
else{
2015-11-04 01:59:00 +00:00
addv();
2015-05-13 10:26:54 +00:00
player.node.handcards1.insertBefore(frag1,player.node.handcards1.firstChild);
player.node.handcards2.insertBefore(frag2,player.node.handcards2.firstChild);
player.update();
2015-11-24 15:44:21 +00:00
if(player==game.me) ui.updatehl();
2015-04-29 03:25:17 +00:00
}
},
lose:function(){
"step 0"
2015-11-04 01:59:00 +00:00
var hs=[],es=[],js=[];
2015-04-29 03:25:17 +00:00
for(var i=0;i<cards.length;i++){
if(cards[i].parentNode){
if(cards[i].parentNode.classList.contains('equips')){
cards[i].original='e';
2015-11-04 01:59:00 +00:00
es.push(cards[i]);
2015-04-29 03:25:17 +00:00
}
else if(cards[i].parentNode.classList.contains('judges')){
cards[i].original='j';
2015-11-04 01:59:00 +00:00
js.push(cards[i]);
2015-04-29 03:25:17 +00:00
}
2015-11-24 15:44:21 +00:00
else if(cards[i].parentNode.classList.contains('handcards')){
2015-04-29 03:25:17 +00:00
cards[i].original='h';
2015-11-04 01:59:00 +00:00
hs.push(cards[i]);
2015-04-29 03:25:17 +00:00
}
else{
cards[i].original=null;
}
2015-04-29 03:25:17 +00:00
}
2015-12-02 15:34:34 +00:00
cards[i].style.transform+=' scale(0.2)';
2015-04-29 03:25:17 +00:00
if(event.position){
cards[i].goto(event.position);
}
else{
2015-11-23 10:59:44 +00:00
cards[i].delete();
2015-04-29 03:25:17 +00:00
}
}
2015-11-24 15:44:21 +00:00
if(player==game.me) ui.updatehl();
2015-11-04 01:59:00 +00:00
game.addVideo('lose',player,[get.cardsInfo(hs),get.cardsInfo(es),get.cardsInfo(js)]);
2015-04-29 03:25:17 +00:00
player.update();
2015-11-04 01:59:00 +00:00
game.addVideo('loseAfter',player);
2015-04-29 03:25:17 +00:00
for(var i=player.node.handcards1.childNodes.length-1;i>0;i--){
if(player.node.handcards1.childNodes[i].classList.contains('removing')==false){
player.node.handcards1.childNodes[i].animate('last');
break;
}
}
for(var i=player.node.handcards2.childNodes.length-1;i>0;i--){
if(player.node.handcards2.childNodes[i].classList.contains('removing')==false){
player.node.handcards2.childNodes[i].animate('last');
break;
}
}
event.num=0;
"step 1"
if(num<cards.length){
if(cards[num].original=='e'){
var info=get.info(cards[num]);
if(info.onLose&&(!info.filterLose||info.filterLose(cards[num],player))){
event.goto(2);
return;
}
}
event.num++;
event.redo();
}
else{
event.finish();
}
"step 2"
player.popup(cards[num].name);
var next=game.createEvent('lose_'+cards[num].name);
var info=get.info(cards[num]);
next.content=info.onLose;
next.player=player;
next.card=cards[num];
2015-11-05 02:34:35 +00:00
game.delayx();
2015-04-29 03:25:17 +00:00
event.num++;
event.goto(1);
},
damage:function(){
"step 0"
2015-11-10 10:13:53 +00:00
if(num<0) num=0;
2015-06-27 16:21:25 +00:00
if(num>0&&player.hujia&&!player.hasSkillTag('nohujia')){
if(num>=player.hujia){
num-=player.hujia;
2015-12-08 13:54:44 +00:00
game.log(player,'的护甲抵挡了'+get.cnNumber(player.hujia)+'点伤害');
2015-06-27 16:21:25 +00:00
player.hujia=0;
}
else{
player.hujia-=num;
2015-12-08 13:54:44 +00:00
game.log(player,'的护甲抵挡了'+get.cnNumber(num)+'点伤害');
2015-06-27 16:21:25 +00:00
num=0;
}
event.hujia=true;
player.update();
}
event.num=num;
2015-04-29 14:56:33 +00:00
if(lib.config.background_audio){
2015-05-14 09:23:45 +00:00
game.playAudio('effect','damage'+(num>1?'2':''));
2015-04-29 14:56:33 +00:00
}
2015-12-08 13:54:44 +00:00
var str='受到了';
if(source) str+='来自<span class="bluetext">'+(source==player?'自己':get.translation(source))+'</span>的';
2015-04-29 03:25:17 +00:00
str+=get.cnNumber(num)+'点';
if(event.nature) str+=get.translation(event.nature)+'属性';
str+='伤害';
2015-12-08 13:54:44 +00:00
game.log(player,str);
2015-04-29 03:25:17 +00:00
if(player.stat[player.stat.length-1].damaged==undefined){
player.stat[player.stat.length-1].damaged=num;
}
else{
player.stat[player.stat.length-1].damaged+=num;
}
if(source){
if(source.stat[source.stat.length-1].damage==undefined){
source.stat[source.stat.length-1].damage=num;
}
else{
source.stat[source.stat.length-1].damage+=num;
}
}
player.changeHp(-num,false);
2015-09-25 00:26:16 +00:00
if(event.animate!==false){
player.$damage(source);
2015-11-23 10:59:44 +00:00
if(lib.config.animation&&!lib.config.low_performance){
2015-09-25 00:26:16 +00:00
if(event.nature=='fire'){
player.$fire();
}
else if(event.nature=='thunder'){
player.$thunder();
}
2015-12-02 10:40:25 +00:00
player.$damagepop(-num,event.nature);
}
else{
player.popup(-num,event.nature);
2015-09-25 00:26:16 +00:00
}
}
2015-08-15 09:10:06 +00:00
// if(source){
// if(player._damagetimeout!=source){
// player.$damage(source);
// player._damagetimeout=source;
// setTimeout(function(){
// delete player._damagetimeout;
// },500);
// }
// if(player._damagepopup){
// player._damagepopup-=num;
// player._damagenature=event.nature;
// }
// else{
// player._damagepopup=-num;
// player._damagenature=event.nature;
// setTimeout(function(){
// player.popup(player._damagepopup,player._damagenature);
// delete player._damagepopup;
// delete player._damagenature;
// },300);
// }
// }
// else{
// player.$damage();
// }
2015-04-29 03:25:17 +00:00
event.trigger('damage');
"step 1"
if(player.hp<=0&&player.isAlive()){
2015-11-05 02:34:35 +00:00
game.delayx();
2015-04-29 03:25:17 +00:00
player.dying(event);
}
},
recover:function(){
if(lib.config.background_audio){
game.playAudio('effect','recover');
}
2015-04-29 03:25:17 +00:00
if(num>player.maxHp-player.hp) num=player.maxHp-player.hp;
if(num>0){
2015-09-26 13:11:55 +00:00
player.changeHp(num,false);
2015-11-23 10:59:44 +00:00
if(lib.config.animation&&!lib.config.low_performance){
2015-09-26 13:11:55 +00:00
player.$recover();
2015-12-02 10:40:25 +00:00
player.$damagepop(num,'wood');
}
else{
player.popup('+'+num);
2015-09-26 13:11:55 +00:00
}
2015-12-08 13:54:44 +00:00
game.log(player,'回复了'+get.cnNumber(num)+'点体力')
2015-04-29 03:25:17 +00:00
}
},
loseHp:function(){
"step 0"
2015-05-14 09:23:45 +00:00
if(lib.config.background_audio){
game.playAudio('effect','loseHp');
}
2015-12-08 13:54:44 +00:00
game.log(player,'失去了'+get.cnNumber(num)+'点体力')
2015-04-29 03:25:17 +00:00
player.changeHp(-num);
"step 1"
if(player.hp<=0){
2015-11-05 02:34:35 +00:00
game.delayx();
2015-04-29 03:25:17 +00:00
player.dying(event);
}
},
2015-04-29 10:02:31 +00:00
doubleDraw:function(){
2015-04-29 03:25:17 +00:00
"step 0"
2015-04-29 10:02:31 +00:00
player.chooseBool('你的武将牌上有单独的阴阳鱼,是否摸一张牌?');
"step 1"
if(result.bool){
player.draw();
2015-04-29 03:25:17 +00:00
}
2015-04-29 10:02:31 +00:00
},
loseMaxHp:function(){
"step 0"
2015-12-08 13:54:44 +00:00
game.log(player,'失去了'+get.cnNumber(num)+'点体力上限');
2015-04-29 10:02:31 +00:00
if(!event.forced&&typeof player.singleHp==='boolean'){
if(player.singleHp){
player.singleHp=false;
player.maxHp-=num-1;
}
else{
player.singleHp=true;
player.maxHp-=num;
}
2015-04-29 07:54:48 +00:00
}
else{
2015-04-29 03:25:17 +00:00
player.maxHp-=num;
}
2015-04-29 07:54:48 +00:00
player.update();
2015-04-29 03:25:17 +00:00
"step 1"
if(player.maxHp<=0){
player.die();
}
2015-04-29 10:02:31 +00:00
"step 2"
if(!event.forced&&player.singleHp===true&&
!player.classList.contains('unseen')&&!player.classList.contains('unseen2')){
player.doubleDraw();
}
2015-04-29 03:25:17 +00:00
},
gainMaxHp:function(){
2015-04-29 10:02:31 +00:00
"step 0"
2015-12-08 13:54:44 +00:00
game.log(player,'获得了'+get.cnNumber(num)+'点体力上限');
2015-04-29 10:02:31 +00:00
if(typeof player.singleHp==='boolean'){
if(player.singleHp){
player.singleHp=false;
player.maxHp+=num;
}
else{
player.singleHp=true;
player.maxHp+=num-1;
}
2015-04-29 07:54:48 +00:00
}
else{
2015-04-29 03:25:17 +00:00
player.maxHp+=num;
}
2015-04-29 07:54:48 +00:00
player.update();
2015-04-29 10:02:31 +00:00
"step 1"
if(player.singleHp===true&&!player.classList.contains('unseen')&&!player.classList.contains('unseen2')){
player.doubleDraw();
}
2015-04-29 03:25:17 +00:00
},
changeHp:function(){
player.hp+=num;
if(player.hp>player.maxHp) player.hp=player.maxHp;
player.update();
if(event.popup!==false){
player.popup(num);
}
event.trigger('changeHp');
},
dying:function(){
"step 0"
_status.dying=player;
event.trigger('dying');
2015-12-08 13:54:44 +00:00
game.log(player,'濒死')
2015-04-29 03:25:17 +00:00
"step 1"
if(_status.dying==player) delete _status.dying;
if(player.hp<=0) player.die(event.reason);
},
die:function(){
if(source){
2015-12-08 13:54:44 +00:00
game.log(player,'被',source,'杀害');
2015-04-29 03:25:17 +00:00
if(source.stat[source.stat.length-1].kill==undefined){
source.stat[source.stat.length-1].kill=1;
}
else{
source.stat[source.stat.length-1].kill++;
}
}
else{
2015-12-08 13:54:44 +00:00
game.log(player,'遇难')
2015-04-29 03:25:17 +00:00
}
event.cards=player.get('hej');
2015-09-03 03:49:14 +00:00
event.playerCards=player.get('he');
2015-04-29 03:25:17 +00:00
if(event.cards.length){
2015-05-12 09:51:40 +00:00
for(var i=0;i<event.cards.length;i++){
2015-04-29 03:25:17 +00:00
event.cards[i].goto(ui.discardPile);
}
player.$throw(event.cards,1000);
2015-12-08 13:54:44 +00:00
game.log(player,'弃置了',event.cards);
2015-04-29 03:25:17 +00:00
}
2015-05-03 15:17:15 +00:00
if(!game.reserveDead){
for(var mark in player.marks){
player.unmarkSkill(mark);
}
while(player.node.marks.childNodes.length){
player.node.marks.firstChild.remove();
}
2015-04-29 03:25:17 +00:00
}
2015-05-12 09:51:40 +00:00
for(var i in player.tempSkills){
player.skills.remove(i);
delete player.tempSkills[i];
}
2015-04-29 03:25:17 +00:00
player.classList.add('dead');
2015-12-02 10:40:25 +00:00
// player.classList.remove('linked');
2015-04-29 03:25:17 +00:00
player.classList.remove('turnedover');
player.classList.remove('out');
2015-11-05 02:34:35 +00:00
player.node.count.innerHTML='0';
player.node.hp.hide();
player.node.equips.hide();
player.node.count.hide();
2015-04-29 03:25:17 +00:00
player.previous.next=player.next;
player.next.previous=player.previous;
game.players.remove(player);
game.dead.push(player);
2015-04-29 14:56:33 +00:00
if(lib.config.background_speak){
2015-05-11 03:43:37 +00:00
if(lib.character[player.name]&&
2015-04-29 14:56:33 +00:00
lib.character[player.name][4].contains('die_audio')){
game.playAudio('die',player.name);
}
else if(lib.config.background_ogg){
2015-11-18 03:39:14 +00:00
game.playAudio('die',player.name.slice(player.name.indexOf('_')+1));
2015-04-29 14:56:33 +00:00
}
2015-11-01 07:54:42 +00:00
// else if(lib.config.background_audio){
// game.playAudio('effect','die_'+(player.sex==='female'?'female':'male'));
// }
2015-04-30 08:24:57 +00:00
}
2015-10-20 17:44:00 +00:00
if(player==game.me&&!_status.over&&!game.controlOver){
2015-04-29 03:25:17 +00:00
ui.control.show();
2015-11-06 10:05:08 +00:00
// if(get.config('swap')&&lib.config.mode_choice.contains('swap')){
// ui.swap=ui.create.control('换人',ui.click.dieswap);
// }
2015-05-04 03:17:03 +00:00
if(get.config('revive')&&lib.config.mode_choice.contains('revive')){
2015-04-29 03:25:17 +00:00
ui.revive=ui.create.control('revive',ui.click.dierevive);
}
2015-05-04 03:17:03 +00:00
if(get.config('dierestart')&&lib.config.mode_choice.contains('dierestart')){
2015-04-29 08:41:00 +00:00
ui.restart=ui.create.control('restart',game.reload);
2015-04-29 03:25:17 +00:00
}
}
2015-10-20 17:44:00 +00:00
if(player==game.me&&!game.modeSwapPlayer){
2015-11-06 10:05:08 +00:00
// _status.auto=false;
2015-11-05 02:34:35 +00:00
if(ui.auto){
2015-11-06 10:05:08 +00:00
// ui.auto.classList.remove('glow');
2015-11-05 02:34:35 +00:00
ui.auto.hide();
}
if(ui.wuxie) ui.wuxie.hide();
2015-04-29 03:25:17 +00:00
}
2015-11-04 01:59:00 +00:00
game.addVideo('diex',player);
2015-04-29 07:54:48 +00:00
player.$die(source);
2015-11-05 02:34:35 +00:00
if(player.dieAfter) player.dieAfter(source);
2015-11-26 08:15:28 +00:00
if(ui.tempnowuxie&&ui.tempnowuxie._origin&&ui.tempnowuxie._origin.player==player){
ui.tempnowuxie.close();
delete ui.tempnowuxie;
}
2015-04-29 03:25:17 +00:00
},
equip:function(){
"step 0"
2015-05-14 09:23:45 +00:00
if(get.owner(card)) get.owner(card).lose(card,ui.special);
2015-04-29 03:25:17 +00:00
if(card.clone){
2015-11-23 10:59:44 +00:00
card.clone.moveDelete(player);
2015-11-04 01:59:00 +00:00
game.addVideo('gain2',player,get.cardsInfo([card.clone]));
2015-04-29 03:25:17 +00:00
}
player.equiping=true;
player.lose(player.get('e',{subtype:get.subtype(card)}),false);
"step 1"
card.fix();
2015-11-24 00:50:54 +00:00
card.style.transform='';
2015-11-24 15:44:21 +00:00
card.classList.remove('drawinghidden');
2015-05-03 15:17:15 +00:00
if(player.isMin()){
event.finish();
ui.discardPile.appendChild(card);
delete player.equiping;
return;
}
2015-04-30 08:24:57 +00:00
if(lib.config.background_audio){
game.playAudio('effect',get.subtype(card));
}
2015-11-04 01:59:00 +00:00
player.$equip(card);
game.addVideo('equip',player,get.cardInfo(card));
2015-12-08 13:54:44 +00:00
game.log(player,'装备了',card);
2015-04-29 03:25:17 +00:00
"step 2"
var info=get.info(card);
if(info.onEquip&&(!info.filterEquip||info.filterEquip(card,player))){
var next=game.createEvent('equip_'+card.name);
next.content=info.onEquip;
next.player=player;
next.card=card;
2015-11-05 02:34:35 +00:00
game.delayx();
2015-04-29 03:25:17 +00:00
}
delete player.equiping;
},
addJudge:function(){
"step 0"
if(cards&&get.owner(cards[0])) get.owner(cards[0]).lose(cards);
"step 1"
2015-04-30 08:24:57 +00:00
if(lib.config.background_audio){
game.playAudio('effect','judge');
}
2015-04-29 03:25:17 +00:00
cards[0].fix();
2015-11-24 00:50:54 +00:00
cards[0].style.transform='';
2015-11-24 15:44:21 +00:00
cards[0].classList.remove('drawinghidden');
2015-04-29 03:25:17 +00:00
var viewAs=typeof card=='string'?card:card.name;
if(!lib.card[viewAs]||!lib.card[viewAs].effect){
ui.discardPile.appendChild(cards[0]);
}
else{
2015-11-24 00:50:54 +00:00
cards[0].style.transform='';
2015-04-29 03:25:17 +00:00
player.node.judges.insertBefore(cards[0],player.node.judges.firstChild);
2015-11-23 10:59:44 +00:00
if(cards[0].clone&&cards[0].clone.parentNode==player.parentNode){
cards[0].clone.moveDelete(player);
game.addVideo('gain2',target,get.cardsInfo(cards));
}
// player.$gain2(cards);
2015-04-29 03:25:17 +00:00
if(get.itemtype(card)!='card'){
if(typeof card=='string') cards[0].viewAs=card;
else cards[0].viewAs=card.name;
}
else{
delete cards[0].viewAs;
}
if(cards[0].viewAs&&cards[0].viewAs!=cards[0].name){
2015-12-08 13:54:44 +00:00
game.log(player,'被贴上了<span class="yellowtext">'+get.translation(cards[0].viewAs)+'</span>',cards,'');
2015-04-29 03:25:17 +00:00
}
else{
2015-12-08 13:54:44 +00:00
game.log(player,'被贴上了',cards);
2015-04-29 03:25:17 +00:00
}
2015-11-04 01:59:00 +00:00
game.addVideo('addJudge',player,[get.cardInfo(cards[0]),cards[0].viewAs]);
2015-04-29 03:25:17 +00:00
}
},
judge:function(){
"step 0"
2015-11-04 01:59:00 +00:00
var judgestr=get.translation(player)+'的'+event.judgestr+'判定';
event.videoId=lib.status.videoId++;
2015-12-12 08:37:15 +00:00
player.judging.unshift(get.cards()[0]);
game.addVideo('judge1',player,[get.cardInfo(player.judging[0]),judgestr,event.videoId]);
2015-11-06 10:05:08 +00:00
if(lib.config.mode=='chess'){
2015-12-12 08:37:15 +00:00
event.node=player.judging[0].copy('thrown','center',ui.arena).animate('start');
2015-11-06 10:05:08 +00:00
}
else{
2015-12-12 08:37:15 +00:00
event.node=player.$throwordered(player.judging[0].copy(),true);
2015-11-06 10:05:08 +00:00
}
event.node.classList.add('thrownhighlight');
ui.arena.classList.add('thrownhighlight');
2015-11-04 01:59:00 +00:00
event.dialog=ui.create.dialog(judgestr);
2015-05-09 02:56:55 +00:00
event.dialog.classList.add('center');
2015-12-12 08:37:15 +00:00
game.log(player,'进行'+event.judgestr+'判定,亮出的判定牌为',player.judging[0]);
2015-04-29 03:25:17 +00:00
game.delay(2);
event.trigger('judge');
"step 1"
event.result={
2015-12-12 08:37:15 +00:00
card:player.judging[0],
number:get.number(player.judging[0]),
suit:get.suit(player.judging[0]),
color:get.color(player.judging[0]),
judge:event.judge(player.judging[0]),
2015-04-29 03:25:17 +00:00
node:event.node,
};
if(event.result.judge>0) event.result.bool=true;
if(event.result.judge<0) event.result.bool=false;
2015-12-12 08:37:15 +00:00
player.judging.shift();
2015-04-29 03:25:17 +00:00
if(event.result.judge>0){
player.popup('洗具');
}
else if(event.result.judge<0){
player.popup('杯具');
}
if(event.clearArena!=false) ui.clear();
event.dialog.close();
2015-11-04 01:59:00 +00:00
game.addVideo('judge2',null,event.videoId);
2015-11-06 10:05:08 +00:00
ui.arena.classList.remove('thrownhighlight');
2015-12-08 13:54:44 +00:00
game.log(player,'的判定结果为',event.result.card);
2015-04-29 03:25:17 +00:00
if(!get.owner(event.result.card)) event.position.appendChild(event.result.card);
},
turnOver:function(){
2015-12-08 13:54:44 +00:00
game.log(player,'翻面');
2015-04-29 03:25:17 +00:00
player.classList.toggle('turnedover');
2015-11-04 01:59:00 +00:00
game.addVideo('turnOver',player,player.classList.contains('turnedover'));
2015-04-29 03:25:17 +00:00
},
link:function(){
if(player.isLinked()){
2015-12-08 13:54:44 +00:00
game.log(player,'解除连环');
2015-04-29 03:25:17 +00:00
}
else{
2015-12-08 13:54:44 +00:00
game.log(player,'被连环');
2015-04-29 03:25:17 +00:00
}
2015-05-14 14:28:29 +00:00
if(lib.config.background_audio){
game.playAudio('effect','link');
}
2015-12-08 13:54:44 +00:00
player.classList.remove('target');
2015-04-29 03:25:17 +00:00
player.classList.toggle('linked');
2015-11-04 01:59:00 +00:00
game.addVideo('link',player,player.classList.contains('linked'));
2015-04-29 03:25:17 +00:00
},
},
player:{
init:function(character,character2,skill){
2015-12-06 15:23:47 +00:00
if(!lib.character[character]) return;
2015-04-29 03:25:17 +00:00
if(character2==false){
skill=false;
character2=null;
}
var info=lib.character[character];
var skills=info[3];
this.skills.length=0;
2015-11-25 10:25:18 +00:00
this.classList.add('fullskin');
2015-11-25 12:34:54 +00:00
if(!game.minskin&&lib.isNewLayout()&&!info[4].contains('minskin')){
2015-05-03 15:17:15 +00:00
this.classList.remove('minskin');
2015-11-25 10:25:18 +00:00
this.node.avatar.setBackground(character,'character');
2015-04-29 03:25:17 +00:00
}
else{
2015-11-25 10:25:18 +00:00
this.node.avatar.setBackground(character,'character');
2015-05-11 03:43:37 +00:00
if(info[4].contains('minskin')){
2015-05-03 15:17:15 +00:00
this.classList.add('minskin');
}
2015-05-08 08:07:38 +00:00
else if(game.minskin){
this.classList.add('minskin');
}
2015-11-25 10:25:18 +00:00
else{
this.classList.remove('minskin');
}
2015-04-29 03:25:17 +00:00
}
this.node.avatar.show();
this.node.count.show();
2015-11-05 02:34:35 +00:00
this.node.equips.show();
2015-04-29 03:25:17 +00:00
this.name=character;
this.sex=info[0];
this.group=info[1];
this.hp=info[2];
this.maxHp=info[2];
2015-06-27 16:21:25 +00:00
this.hujia=0;
2015-04-29 03:25:17 +00:00
this.node.intro.innerHTML=lib.config.intro;
2015-11-25 12:34:54 +00:00
switch(this.group){
case 'wei':this.node.name.dataset.nature='watermm';break;
case 'shu':this.node.name.dataset.nature='soilmm';break;
case 'wu':this.node.name.dataset.nature='woodmm';break;
case 'qun':this.node.name.dataset.nature='metalmm';break;
}
2015-04-29 03:25:17 +00:00
if(lib.config.touchscreen){
lib.setLongPress(this,ui.click.intro);
}
2015-11-13 09:12:47 +00:00
else{
if(lib.config.hover_all){
lib.setHover(this,ui.click.hoverplayer);
}
if(lib.config.right_info){
this.oncontextmenu=ui.click.rightplayer;
}
2015-04-29 03:25:17 +00:00
}
2015-12-08 00:56:54 +00:00
// var name=get.translation(character);
this.node.name.innerHTML=get.slimName(character);
2015-04-29 03:25:17 +00:00
if(!lib.config.show_name){
this.node.name.style.display='none';
}
2015-12-08 00:56:54 +00:00
// for(var i=0;i<name.length;i++){
// if(name[i]!='s'&&name[i]!='p')
// this.node.name.innerHTML+=name[i]+'<br/>';
// }
2015-12-06 15:23:47 +00:00
if(character2&&lib.character[character2]){
2015-04-29 03:25:17 +00:00
var info2=lib.character[character2];
2015-11-25 10:25:18 +00:00
this.classList.add('fullskin2');
this.node.avatar2.setBackground(character2,'character');
2015-04-29 03:25:17 +00:00
this.node.avatar2.show();
this.name2=character2;
2015-04-29 10:02:31 +00:00
var hp1=info[2],hp2=info2[2];
switch(get.config('double_hp')){
case 'pingjun':{
this.maxHp=Math.floor((hp1+hp2)/2);
this.singleHp=((hp1+hp2)%2===1);
break;
}
case 'zuidazhi':this.maxHp=Math.max(hp1,hp2);break;
case 'zuixiaozhi':this.maxHp=Math.min(hp1,hp2);break;
case 'zonghe':this.maxHp=hp1+hp2;break;
default:this.maxHp=hp1+hp2-3;
2015-04-29 03:25:17 +00:00
}
2015-04-29 10:02:31 +00:00
this.hp=this.maxHp;
2015-04-29 03:25:17 +00:00
this.node.count.classList.add('p2');
skills=skills.concat(info2[3]);
2015-11-30 13:08:29 +00:00
2015-12-08 00:56:54 +00:00
// var name=get.translation(character2);
this.node.name2.innerHTML=get.slimName(character2);;
2015-11-30 13:08:29 +00:00
if(!lib.config.show_name){
this.node.name2.style.display='none';
}
2015-12-08 00:56:54 +00:00
// for(var i=0;i<name.length;i++){
// this.node.name2.innerHTML+=name[i]+'<br/>';
// }
2015-04-29 03:25:17 +00:00
}
if(skill!=false){
for(var i=0;i<skills.length;i++){
this.addSkill(skills[i]);
}
}
lib.group.add(this.group);
if(this.inits){
for(var i=0;i<lib.element.player.inits.length;i++){
lib.element.player.inits[i](this);
}
}
this.update();
return this;
},
2015-05-05 14:57:35 +00:00
uninit:function(){
2015-04-29 03:25:17 +00:00
var that=this;
this.node.avatar.hide();
this.node.count.hide();
if(this.node.wuxing){
this.node.wuxing.hide();
}
delete this.name;
delete this.sex;
delete this.group;
delete this.hp;
delete this.maxHp;
2015-06-27 16:21:25 +00:00
delete this.hujia;
2015-04-29 03:25:17 +00:00
this.skills.length=0;
this.node.identity.style.backgroundColor='';
this.node.intro.innerHTML='';
this.node.name.innerHTML='';
this.node.hp.innerHTML='';
2015-11-05 02:34:35 +00:00
this.node.count.innerHTML='0';
2015-04-29 03:25:17 +00:00
if(this.name2){
this.node.avatar2.hide();
delete this.name2;
this.node.count.classList.remove('p2');
}
for(var mark in this.marks){
this.marks[mark].remove();
}
this.skipList=[];
this.skills=[];
this.initedSkills=[];
this.additionalSkills={};
this.disabledSkills={};
this.hiddenSkills=[];
this.forbiddenSkills=[];
this.modeSkills=[];
2015-05-05 14:57:35 +00:00
this.stat=[{card:{},skill:{}}];
2015-04-29 03:25:17 +00:00
this.tempSkills={};
this.storage={};
this.marks={};
this.ai={friend:[],enemy:[],neutral:[]};
return this;
},
update:function(){
2015-11-04 01:59:00 +00:00
if(_status.video&&arguments.length==0) return;
2015-04-29 03:25:17 +00:00
if(this.hp>=this.maxHp) this.hp=this.maxHp;
var hp=this.node.hp;
hp.style.transition='none';
2015-11-04 01:59:00 +00:00
if(!_status.video){
if(this.hujia){
this.markSkill('ghujia');
}
else{
this.unmarkSkill('ghujia');
}
2015-06-27 16:21:25 +00:00
}
2015-04-29 03:25:17 +00:00
if(lib.config.layout=='default'&&this.maxHp>14){
hp.innerHTML=this.hp+'/'+this.maxHp;
hp.classList.add('text');
}
2015-10-31 10:14:14 +00:00
else if(lib.isNewLayout()&&
(
this.maxHp>9||
(this.maxHp>5&&this.classList.contains('minskin'))||
2015-10-31 16:18:20 +00:00
((lib.config.layout=='mobile'||lib.config.layout=='phone')&&this.dataset.position==0&&this.maxHp>7)
2015-10-31 10:14:14 +00:00
)){
2015-05-11 11:57:44 +00:00
hp.innerHTML=this.hp+'<br>/<br>'+this.maxHp;
hp.classList.add('text');
hp.classList.remove('long');
}
2015-04-29 03:25:17 +00:00
else{
hp.innerHTML='';
hp.classList.remove('text');
while(this.maxHp>hp.childNodes.length){
ui.create.div(hp);
}
while(this.maxHp<hp.childNodes.length){
hp.removeChild(hp.lastChild);
}
for(var i=0;i<this.maxHp;i++){
if(i<this.hp){
hp.childNodes[i].classList.remove('lost');
}
else{
hp.childNodes[i].classList.add('lost');
}
}
2015-05-11 11:57:44 +00:00
if(this.maxHp==9){
hp.classList.add('long');
2015-05-03 15:17:15 +00:00
}
else{
2015-05-11 11:57:44 +00:00
hp.classList.remove('long');
2015-05-03 15:17:15 +00:00
}
2015-04-29 03:25:17 +00:00
}
2015-05-11 11:57:44 +00:00
if(this.hp==0){
hp.dataset.condition='';
}
else if(this.hp>Math.round(this.maxHp/2)||this.hp===this.maxHp){
hp.dataset.condition='high';
2015-04-29 03:25:17 +00:00
}
else if(this.hp>Math.floor(this.maxHp/3)){
2015-05-11 11:57:44 +00:00
hp.dataset.condition='mid';
2015-04-29 03:25:17 +00:00
}
else{
2015-05-11 11:57:44 +00:00
hp.dataset.condition='low';
2015-04-29 03:25:17 +00:00
}
setTimeout(function(){
hp.style.transition='';
});
var numh=this.num('h');
2015-11-04 01:59:00 +00:00
if(_status.video){
numh=arguments[0];
}
2015-04-29 03:25:17 +00:00
if(numh>=10){
numh=numh.toString();
this.node.count.dataset.condition='low';
this.node.count.innerHTML=numh[0]+'<br>'+numh[1];
}
else{
if(numh>5){
this.node.count.dataset.condition='higher';
}
else if(numh>2){
this.node.count.dataset.condition='high';
}
else if(numh>0){
this.node.count.dataset.condition='mid';
}
else{
this.node.count.dataset.condition='none';
}
this.node.count.innerHTML=numh;
}
2015-11-14 15:48:04 +00:00
// this.node.equips.dataset.number=this.num('e');
2015-12-02 15:34:34 +00:00
// if(this==game.me){
// ui.updateh();
// }
2015-04-29 03:25:17 +00:00
if(this.updates){
for(var i=0;i<lib.element.player.updates.length;i++){
lib.element.player.updates[i](this);
}
}
2015-11-04 01:59:00 +00:00
if(!_status.video){
game.addVideo('update',this,[this.num('h'),this.hp,this.maxHp,this.hujia]);
}
2015-11-21 13:23:23 +00:00
if(this.node.jiu&&!this.skills.contains('jiu')){
this.node.jiu.delete();
this.node.jiu2.delete();
delete this.node.jiu;
delete this.node.jiu2;
}
2015-11-28 03:45:23 +00:00
this.updateMarks();
2015-04-29 03:25:17 +00:00
return this;
},
2015-11-28 03:45:23 +00:00
updateMarks:function(){
for(var i in this.marks){
if(i=='ghujia'||(!this.marks[i].querySelector('.image')&&lib.skill[i]&&
lib.skill[i].intro&&this.storage[i])){
this.marks[i].classList.add('overflowmark')
var num;
if(i=='ghujia'){
num=this.hujia;
}
else if(typeof this.storage[i]=='number'){
num=this.storage[i];
}
else if(Array.isArray(this.storage[i])){
num=this.storage[i].length;
}
if(num){
if(!this.marks[i].markcount){
this.marks[i].markcount=ui.create.div('.markcount.menubutton',this.marks[i]);
}
this.marks[i].markcount.innerHTML=num;
}
else if(this.marks[i].markcount){
this.marks[i].markcount.delete();
delete this.marks[i].markcount;
}
}
2015-11-30 17:37:10 +00:00
else if(this.marks[i].markcount){
this.marks[i].markcount.delete();
delete this.marks[i].markcount;
}
2015-11-28 03:45:23 +00:00
}
},
2015-04-29 03:25:17 +00:00
num:function(arg1,arg2,arg3){
var i,j,k;
if(get.itemtype(arg1)=='position'){
return this.get(arg1,arg2,arg3).length;
}
else if(arg1=='s'){
if(typeof arg2=='boolean'){
return game.expandSkills(this.get('s',arg2).concat(lib.skill.global)).contains(arg3);
}
else{
return game.expandSkills(this.get('s').concat(lib.skill.global)).contains(arg2);
}
}
},
line:function(target,config){
if(get.itemtype(target)=='players'){
for(var i=0;i<target.length;i++){
this.line(target[i],config);
}
}
else if(get.itemtype(target)=='player'){
if(target==this) return;
2015-11-04 01:59:00 +00:00
game.addVideo('line',this,[target.dataset.position,config]);
2015-04-29 03:25:17 +00:00
game.linexy([
this.offsetLeft+this.offsetWidth/2,
this.offsetTop+this.offsetHeight/2,
target.offsetLeft+target.offsetWidth/2,
target.offsetTop+target.offsetHeight/2
2015-05-08 08:07:38 +00:00
],config,true);
2015-04-29 03:25:17 +00:00
}
},
2015-11-04 01:59:00 +00:00
line2:function(targets,config,init){
2015-04-29 03:25:17 +00:00
this.line(targets[0],config);
targets=targets.slice(0);
for(var i=1;i<targets.length;i++){
(function(j){
setTimeout(function(){
targets[j-1].line(targets[j],config);
},lib.config.duration*i);
}(i));
}
},
get:function(arg1,arg2,arg3,arg4){
var i,j;
if(arg1=='s'){
this.checkConflict();
var skills=this.skills.slice(0);
for(var i in this.additionalSkills){
if(Array.isArray(this.additionalSkills[i])){
for(j=0;j<this.additionalSkills[i].length;j++){
if(this.additionalSkills[i][j]){
skills.add(this.additionalSkills[i][j]);
}
}
}
else if(this.additionalSkills[i]&&typeof this.additionalSkills[i]=='string'){
skills.add(this.additionalSkills[i]);
}
}
if(arg2) skills=skills.concat(this.hiddenSkills);
if(arg3!==false){
for(i=0;i<this.node.equips.childNodes.length;i++){
2015-11-21 13:23:23 +00:00
if(this.node.equips.childNodes[i].classList.contains('removing')) continue;
2015-04-29 03:25:17 +00:00
if(get.info(this.node.equips.childNodes[i]).skills){
skills=skills.concat(get.info(this.node.equips.childNodes[i]).skills);
}
}
}
for(i=0;i<this.forbiddenSkills.length;i++){
skills.remove(this.forbiddenSkills[i]);
}
if(arg4!==false){
skills=game.filterSkills(skills,this);
}
return skills;
}
else if(get.itemtype(arg1)=='position'){
var cards=[],cards1=[];
for(i=0;i<arg1.length;i++){
if(arg1[i]=='h'){
for(j=0;j<this.node.handcards1.childNodes.length;j++){
cards.push(this.node.handcards1.childNodes[j]);
}
for(j=0;j<this.node.handcards2.childNodes.length;j++){
cards.push(this.node.handcards2.childNodes[j]);
}
}
else if(arg1[i]=='e'){
for(j=0;j<this.node.equips.childNodes.length;j++){
cards.push(this.node.equips.childNodes[j]);
}
if(arguments.length==2&&typeof arg2=='string'&&/1|2|3|4|5/.test(arg2)){
for(j=0;j<cards.length;j++){
if(get.subtype(cards[j])=='equip'+arg2) return cards[j];
}
return;
}
}
else if(arg1[i]=='j'){
for(j=0;j<this.node.judges.childNodes.length;j++){
cards.push(this.node.judges.childNodes[j]);
if(this.node.judges.childNodes[j].viewAs){
this.node.judges.childNodes[j].tempJudge=this.node.judges.childNodes[j].name;
this.node.judges.childNodes[j].name=this.node.judges.childNodes[j].viewAs;
cards1.push(this.node.judges.childNodes[j]);
}
}
}
}
for(i=0;i<cards.length;i++){
if(cards[i].classList.contains('removing')){
cards.splice(i,1);i--;
}
}
if(arg2!=undefined){
if(typeof arg3=='function'){
var cards2=cards.slice(0);
cards.sort(function(a,b){
return arg3(b,cards2)-arg3(a,cards2);
});
}
if(typeof arg2=='string'){
for(i=0;i<cards.length;i++){
if(cards[i].name!=arg2){
cards.splice(i,1);i--;
}
}
}
else if(typeof arg2=='object'){
for(i=0;i<cards.length;i++){
for(j in arg2){
if(j=='type'){
if(typeof arg2[j]=='object'){
if(arg2[j].contains(get.type(cards[i]))==false){
cards.splice(i,1);i--;break;
}
}
else if(typeof arg2[j]=='string'){
if(get.type(cards[i])!=arg2[j]){
cards.splice(i,1);i--;break;
}
}
}
else if(j=='subtype'){
if(typeof arg2[j]=='object'){
if(arg2[j].contains(get.subtype(cards[i]))==false){
cards.splice(i,1);i--;break;
}
}
else if(typeof arg2[j]=='string'){
if(get.subtype(cards[i])!=arg2[j]){
cards.splice(i,1);i--;break;
}
}
}
else if(j=='color'){
if(typeof arg2[j]=='object'){
if(arg2[j].contains(get.color(cards[i]))==false){
cards.splice(i,1);i--;break;
}
}
else if(typeof arg2[j]=='string'){
if(get.color(cards[i])!=arg2[j]){
cards.splice(i,1);i--;break;
}
}
}
else if(j=='suit'){
if(typeof arg2[j]=='object'){
if(arg2[j].contains(get.suit(cards[i]))==false){
cards.splice(i,1);i--;break;
}
}
else if(typeof arg2[j]=='string'){
if(get.suit(cards[i])!=arg2[j]){
cards.splice(i,1);i--;break;
}
}
}
else if(j=='number'){
if(typeof arg2[j]=='object'){
if(arg2[j].contains(get.number(cards[i]))==false){
cards.splice(i,1);i--;break;
}
}
else if(typeof arg2[j]=='string'){
if(get.number(cards[i])!=arg2[j]){
cards.splice(i,1);i--;break;
}
}
}
else if(typeof arg2[j]=='object'){
if(arg2[j].contains(cards[i][j])==false){
cards.splice(i,1);i--;break;
}
}
else if(typeof arg2[j]=='string'){
if(cards[i][j]!=arg2[j]){
cards.splice(i,1);i--;break;
}
}
}
}
}
else if(typeof arg2=='number'&&arg2>0){
cards.splice(arg2);
}
else if(typeof arg2=='function'){
for(i=0;i<cards.length;i++){
if(!arg2(cards[i])){
cards.splice(i,1);i--;
}
}
}
}
for(i=0;i<cards1.length;i++){
if(cards1[i].tempJudge){
cards1[i].name=cards1[i].tempJudge;
delete cards1[i].tempJudge;
}
}
if(arg2===0) return cards[0];
if(typeof arg3=='number'){
if(arg3==0) return cards[0];
cards.splice(arg3);
}
if(typeof arg4=='number'){
if(arg4==0) return cards[0];
cards.splice(arg4);
}
return cards;
}
},
2015-11-21 05:30:26 +00:00
syncStorage:function(skill){
switch(get.itemtype(this.storage[skill])){
case 'cards':game.addVideo('storage',this,[skill,get.cardsInfo(this.storage[skill]),'cards']);break;
case 'card':game.addVideo('storage',this,[skill,get.cardInfo(this.storage[skill]),'cards']);break;
default:game.addVideo('storage',this,[skill,this.storage[skill]]);
}
},
2015-11-09 03:15:16 +00:00
playerfocus:function(time){
time=time||1000;
this.classList.add('playerfocus');
ui.arena.classList.add('playerfocus');
var that=this;
setTimeout(function(){
that.classList.remove('playerfocus');
ui.arena.classList.remove('playerfocus');
},1000);
game.addVideo('playerfocus',this,time);
return this;
},
2015-06-27 16:21:25 +00:00
changeHujia:function(num){
if(typeof num!='number'){
num=1;
}
this.hujia+=num;
if(num>0){
2015-12-08 13:54:44 +00:00
game.log(this,'获得了'+get.cnNumber(num)+'点护甲值');
2015-06-27 16:21:25 +00:00
}
if(this.hujia<0){
this.hujia=0;
}
this.update();
},
2015-04-29 03:25:17 +00:00
setIdentity:function(identity){
if(!identity) identity=this.identity;
this.node.identity.firstChild.innerHTML=get.translation(identity);
this.node.identity.dataset.color=identity;
},
phase:function(){
var next=game.createEvent('phase');
next.player=this;
next.content=lib.element.playerproto.phase;
},
phaseJudge:function(){
var next=game.createEvent('phaseJudge');
next.player=this;
next.content=lib.element.playerproto.phaseJudge;
},
phaseDraw:function(){
var next=game.createEvent('phaseDraw');
next.player=this;
next.num=2;
next.content=lib.element.playerproto.phaseDraw;
},
phaseUse:function(){
var next=game.createEvent('phaseUse');
next.player=this;
next.content=lib.element.playerproto.phaseUse;
},
phaseDiscard:function(){
var next=game.createEvent('phaseDiscard');
next.player=this;
next.content=lib.element.playerproto.phaseDiscard;
},
chooseToUse:function(use){
var next=game.createEvent('chooseToUse');
next.player=this;
if(arguments.length==1){
for(var i in use){
next[i]=use[i];
}
}
else{
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='number'||get.itemtype(arguments[i])=='select'){
next.selectTarget=arguments[i];
}
else if(typeof arguments[i]=='object'||typeof arguments[i]=='function'){
if(get.itemtype(arguments[i])=='player'||next.filterCard){
next.filterTarget=arguments[i];
}
else next.filterCard=arguments[i];
}
else if(typeof arguments[i]=='boolean'){
next.forced=arguments[i];
}
else if(typeof arguments[i]=='string'){
next.prompt=arguments[i];
}
}
}
if(typeof next.filterCard=='object'){
next.filterCard=get.filter(next.filterCard);
}
if(typeof next.filterTarget=='object'){
next.filterTarget=get.filter(next.filterTarget,2);
}
if(next.filterCard==undefined){
next.filterCard=lib.filter.filterCard;
}
if(next.selectCard==undefined){
next.selectCard=lib.filter.selectCard;
}
if(next.filterTarget==undefined){
next.filterTarget=lib.filter.filterTarget;
}
if(next.selectTarget==undefined){
next.selectTarget=lib.filter.selectTarget;
}
if(next.ai1==undefined) next.ai1=ai.get.order;
if(next.ai2==undefined) next.ai2=ai.get.effect;
next.content=lib.element.playerproto.chooseToUse;
return next;
},
chooseToRespond:function(){
var next=game.createEvent('chooseToRespond');
next.player=this;
2015-05-11 11:57:44 +00:00
var filter;
2015-04-29 03:25:17 +00:00
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='number'){
next.selectCard=[arguments[i],arguments[i]];
}
else if(get.itemtype(arguments[i])=='select'){
next.selectCard=arguments[i];
}
else if(typeof arguments[i]=='boolean'){
next.forced=arguments[i];
}
else if(get.itemtype(arguments[i])=='position'){
next.position=arguments[i];
}
else if(typeof arguments[i]=='function'){
if(next.filterCard) next.ai=arguments[i];
else next.filterCard=arguments[i];
}
else if(typeof arguments[i]=='object'){
next.filterCard=get.filter(arguments[i]);
2015-05-11 11:57:44 +00:00
filter=arguments[i];
2015-04-29 03:25:17 +00:00
}
else if(arguments[i]=='nosource'){
next.nosource=true;
}
else if(typeof arguments[i]=='string'){
next.prompt=arguments[i];
}
}
if(next.filterCard==undefined) next.filterCard=lib.filter.all;
if(next.selectCard==undefined) next.selectCard=[1,1];
if(next.source==undefined&&!next.nosource) next.source=_status.event.player;
if(next.ai==undefined) next.ai=ai.get.unuseful2;
if(next.prompt!=false){
if(typeof next.prompt=='string'){
next.dialog=next.prompt;
}
else{
var str='请打出'+get.cnNumber(next.selectCard[0])+'张'
if(filter){
if(filter.name){
str+=get.translation(filter.name);
}
else{
str+='牌';
}
}
else{
str+='牌';
}
next.dialog=str;
}
}
next.content=lib.element.playerproto.chooseToRespond;
return next;
},
chooseToDiscard:function(){
var next=game.createEvent('chooseToDiscard');
next.player=this;
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='number'){
next.selectCard=[arguments[i],arguments[i]];
}
else if(get.itemtype(arguments[i])=='select'){
next.selectCard=arguments[i];
}
else if(get.itemtype(arguments[i])=='dialog'){
next.dialog=arguments[i];
next.prompt=false;
}
else if(typeof arguments[i]=='boolean'){
next.forced=arguments[i];
}
else if(get.itemtype(arguments[i])=='position'){
next.position=arguments[i];
}
else if(typeof arguments[i]=='function'){
if(next.filterCard) next.ai=arguments[i];
else next.filterCard=arguments[i];
}
else if(typeof arguments[i]=='object'){
next.filterCard=get.filter(arguments[i]);
}
else if(typeof arguments[i]=='string'){
next.prompt=arguments[i];
}
}
if(next.isMine()==false&&next.dialog) next.dialog.style.display='none';
if(next.filterCard==undefined) next.filterCard=lib.filter.all;
if(next.selectCard==undefined) next.selectCard=[1,1];
if(next.ai==undefined) next.ai=ai.get.unuseful;
next.autochoose=function(){
if(!this.forced) return false;
return get.select(this.selectCard)[0]>=this.player.num(this.position||'h');
}
next.content=lib.element.playerproto.chooseToDiscard;
return next;
},
chooseToCompare:function(target,check){
var next=game.createEvent('chooseToCompare');
next.player=this;
next.target=target;
if(check) next.ai=check;
else next.ai=function(card){
var player=get.owner(card);
var event=_status.event.parent;
2015-05-01 09:34:01 +00:00
var to=(player==event.player?event.target:event.player);
2015-05-01 07:35:43 +00:00
var addi=(ai.get.value(card)>=8&&get.type(card)!='equip')?-10:0;
if(player==event.player){
2015-05-01 09:34:01 +00:00
if(ai.get.attitude(player,to)>0&&event.small){
return -get.number(card)-ai.get.value(card)/2+addi;
}
return get.number(card)-ai.get.value(card)/2+addi;
2015-04-29 03:25:17 +00:00
}
2015-05-01 09:34:01 +00:00
else{
if(ai.get.attitude(player,to)>0&&!event.small){
return -get.number(card)-ai.get.value(card)/2+addi;
}
2015-05-01 09:34:01 +00:00
return get.number(card)-ai.get.value(card)/2+addi;
}
2015-04-29 03:25:17 +00:00
}
next.content=lib.element.playerproto.chooseToCompare;
return next;
},
chooseCardButton:function(){
var cards,prompt,forced,select;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='cards') cards=arguments[i];
else if(typeof arguments[i]=='boolean') forced=arguments[i];
else if(typeof arguments[i]=='string') prompt=arguments[i];
else if(get.itemtype(arguments[i])=='select'||typeof arguments[i]=='number') select=arguments[i];
}
if(prompt==undefined) prompt='请选择卡牌';
return this.chooseButton(ui.create.dialog(prompt,cards),forced,select,'hidden');
},
chooseButton:function(){
var next=game.createEvent('chooseButton');
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='boolean'){
next.forced=arguments[i];
}
else if(get.itemtype(arguments[i])=='dialog'){
next.dialog=arguments[i];
next.closeDialog=true;
}
else if(get.itemtype(arguments[i])=='select'){
next.selectButton=arguments[i];
}
else if(typeof arguments[i]=='number'){
next.selectButton=[arguments[i],arguments[i]];
}
else if(typeof arguments[i]=='function'){
if(next.ai) next.filterButton=arguments[i];
else next.ai=arguments[i];
}
}
next.player=this;
if(next.isMine()==false&&next.dialog) next.dialog.style.display='none';
if(next.filterButton==undefined) next.filterButton=lib.filter.filterButton;
if(next.selectButton==undefined) next.selectButton=[1,1];
if(next.ai==undefined) next.ai=function(){return 1};
next.content=lib.element.playerproto.chooseButton;
return next;
},
chooseCard:function(){
var next=game.createEvent('chooseCard');
next.player=this;
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='number'){
next.selectCard=[arguments[i],arguments[i]];
}
else if(get.itemtype(arguments[i])=='select'){
next.selectCard=arguments[i];
}
else if(typeof arguments[i]=='boolean'){
next.forced=arguments[i];
}
else if(get.itemtype(arguments[i])=='position'){
next.position=arguments[i];
}
else if(typeof arguments[i]=='function'){
if(next.filterCard) next.ai=arguments[i];
else next.filterCard=arguments[i];
}
else if(typeof arguments[i]=='object'){
next.filterCard=get.filter(arguments[i]);
}
else if(typeof arguments[i]=='string'){
next.prompt=arguments[i];
}
}
if(next.filterCard==undefined) next.filterCard=lib.filter.all;
if(next.selectCard==undefined) next.selectCard=[1,1];
if(next.ai==undefined) next.ai=ai.get.unuseful2;
next.content=lib.element.playerproto.chooseCard;
return next;
},
chooseTarget:function(){
var next=game.createEvent('chooseTarget');
next.player=this;
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='number'){
next.selectTarget=[arguments[i],arguments[i]];
}
else if(get.itemtype(arguments[i])=='select'){
next.selectTarget=arguments[i];
}
else if(get.itemtype(arguments[i])=='dialog'){
next.dialog=arguments[i];
next.prompt=false;
}
else if(typeof arguments[i]=='boolean'){
next.forced=arguments[i];
}
else if(typeof arguments[i]=='function'){
if(next.filterTarget) next.ai=arguments[i];
else next.filterTarget=arguments[i];
}
else if(typeof arguments[i]=='string'){
next.prompt=arguments[i];
}
}
if(next.filterTarget==undefined) next.filterTarget=lib.filter.all;
if(next.selectTarget==undefined) next.selectTarget=[1,1];
if(next.ai==undefined) next.ai=ai.get.attitude2;
next.content=lib.element.playerproto.chooseTarget;
return next;
},
chooseCardTarget:function(choose){
var next=game.createEvent('chooseCardTarget');
next.player=this;
if(arguments.length==1){
for(var i in choose){
next[i]=choose[i];
}
}
if(typeof next.filterCard=='object'){
next.filterCard=get.filter(next.filterCard);
}
if(typeof next.filterTarget=='object'){
next.filterTarget=get.filter(next.filterTarget,2);
}
if(next.filterCard==undefined||next.filterCard===true){
next.filterCard=lib.filter.all;
}
if(next.selectCard==undefined){
next.selectCard=1;
}
if(next.filterTarget==undefined||next.filterTarget===true){
next.filterTarget=lib.filter.all;
}
if(next.selectTarget==undefined){
next.selectTarget=1;
}
if(next.ai1==undefined) next.ai1=ai.get.unuseful2;
if(next.ai2==undefined) next.ai2=ai.get.attitude2;
next.content=lib.element.playerproto.chooseCardTarget;
return next;
},
chooseControl:function(){
var next=game.createEvent('chooseControl');
next.controls=[];
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='string'){
next.controls.push(arguments[i]);
}
else if(get.objtype(arguments[i])=='array'){
next.controls=next.controls.concat(arguments[i]);
}
else if(typeof arguments[i]=='function'){
next.ai=arguments[i];
}
else if(typeof arguments[i]=='number'){
next.choice=arguments[i];
}
else if(get.itemtype(arguments[i])=='dialog'){
next.dialog=arguments[i];
}
}
next.player=this;
if(next.choice==undefined) next.choice=0;
next.content=lib.element.playerproto.chooseControl;
return next;
},
chooseBool:function(){
var next=game.createEvent('chooseBool');
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='boolean'){
next.choice=arguments[i];
}
else if(typeof arguments[i]=='function'){
next.ai=arguments[i];
}
else if(typeof arguments[i]=='string'){
next.prompt=arguments[i];
}
2015-06-19 15:31:36 +00:00
else if(get.itemtype(arguments[i])=='dialog'){
next.dialog=arguments[i];
}
2015-04-29 03:25:17 +00:00
if(next.choice==undefined) next.choice=true;
}
next.player=this;
next.content=lib.element.playerproto.chooseBool;
return next;
},
choosePlayerCard:function(){
var next=game.createEvent('choosePlayerCard');
next.player=this;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='player'){
next.target=arguments[i];
}
else if(typeof arguments[i]=='number'){
next.selectButton=[arguments[i],arguments[i]];
}
else if(get.itemtype(arguments[i])=='select'){
next.selectButton=arguments[i];
}
else if(typeof arguments[i]=='boolean'){
next.forced=arguments[i];
}
else if(get.itemtype(arguments[i])=='position'){
next.position=arguments[i];
}
else if(arguments[i]=='visible'){
next.visible=true;
}
else if(typeof arguments[i]=='function'){
if(next.ai) next.filterButton=arguments[i];
else next.ai=arguments[i];
}
else if(typeof arguments[i]=='object'){
next.filterButton=get.filter(arguments[i]);
}
else if(typeof arguments[i]=='string'){
next.prompt=arguments[i];
}
}
if(next.filterButton==undefined) next.filterButton=lib.filter.all;
if(next.position==undefined) next.position='hej';
if(next.selectButton==undefined) next.selectButton=[1,1];
if(next.ai==undefined) next.ai=function(button){
var val=ai.get.buttonValue(button);
if(ai.get.attitude(_status.event.player,get.owner(button.link))>0) return -val;
return val;
};
next.content=lib.element.playerproto.choosePlayerCard;
return next;
},
discardPlayerCard:function(){
var next=game.createEvent('discardPlayerCard');
next.player=this;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='player'){
next.target=arguments[i];
}
else if(typeof arguments[i]=='number'){
next.selectButton=[arguments[i],arguments[i]];
}
else if(get.itemtype(arguments[i])=='select'){
next.selectButton=arguments[i];
}
else if(typeof arguments[i]=='boolean'){
next.forced=arguments[i];
}
else if(get.itemtype(arguments[i])=='position'){
next.position=arguments[i];
}
else if(arguments[i]=='visible'){
next.visible=true;
}
else if(typeof arguments[i]=='function'){
if(next.ai) next.filterButton=arguments[i];
else next.ai=arguments[i];
}
else if(typeof arguments[i]=='object'){
next.filterButton=get.filter(arguments[i]);
}
else if(typeof arguments[i]=='string'){
next.prompt=arguments[i];
}
}
if(next.filterButton==undefined) next.filterButton=lib.filter.all;
if(next.position==undefined) next.position='hej';
if(next.selectButton==undefined) next.selectButton=[1,1];
if(next.ai==undefined) next.ai=function(button){
var val=ai.get.buttonValue(button);
if(ai.get.attitude(_status.event.player,get.owner(button.link))>0) return -val;
return val;
};
next.content=lib.element.playerproto.discardPlayerCard;
return next;
},
gainPlayerCard:function(){
var next=game.createEvent('gainPlayerCard');
next.player=this;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='player'){
next.target=arguments[i];
}
else if(typeof arguments[i]=='number'){
next.selectButton=[arguments[i],arguments[i]];
}
else if(get.itemtype(arguments[i])=='select'){
next.selectButton=arguments[i];
}
else if(typeof arguments[i]=='boolean'){
next.forced=arguments[i];
}
else if(get.itemtype(arguments[i])=='position'){
next.position=arguments[i];
}
else if(arguments[i]=='visible'){
next.visible=true;
}
else if(typeof arguments[i]=='function'){
if(next.ai) next.filterButton=arguments[i];
else next.ai=arguments[i];
}
else if(typeof arguments[i]=='object'){
next.filterButton=get.filter(arguments[i]);
}
else if(typeof arguments[i]=='string'){
next.prompt=arguments[i];
}
}
if(next.filterButton==undefined) next.filterButton=lib.filter.all;
if(next.position==undefined) next.position='h';
if(next.selectButton==undefined) next.selectButton=[1,1];
if(next.ai==undefined) next.ai=function(button){
var val=ai.get.buttonValue(button);
if(ai.get.attitude(_status.event.player,get.owner(button.link))>0) return -val;
return val;
};
next.content=lib.element.playerproto.gainPlayerCard;
return next;
},
showHandcards:function(){
var next=game.createEvent('showHandcards');
next.player=this;
next.content=lib.element.playerproto.showHandcards;
},
2015-06-27 16:21:25 +00:00
showCards:function(cards,str){
2015-04-29 03:25:17 +00:00
var next=game.createEvent('showCards');
next.player=this;
2015-06-27 16:21:25 +00:00
next.str=str;
2015-04-29 03:25:17 +00:00
if(get.itemtype(cards)=='card') next.cards=[cards];
else if(get.itemtype(cards)=='cards') next.cards=cards;
else _status.event.next.remove(next);
next.content=lib.element.playerproto.showCards;
},
viewHandcards:function(target){
var next=game.createEvent('viewHandcards');
next.player=this;
next.target=target;
next.content=lib.element.playerproto.viewHandcards;
},
useCard:function(){
var next=game.createEvent('useCard');
next.player=this;
next.num=0;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='cards'){
next.cards=arguments[i];
}
else if(get.itemtype(arguments[i])=='players'){
next.targets=arguments[i];
}
else if(get.itemtype(arguments[i])=='player'){
next.targets=[arguments[i]];
}
else if(get.itemtype(arguments[i])=='card'){
next.card=arguments[i];
}
else if(typeof arguments[i]=='object'&&arguments[i].name){
next.card=arguments[i];
}
else if(typeof arguments[i]=='string'){
next.skill=arguments[i];
}
else if(typeof arguments[i]=='boolean'){
next.addCount=arguments[i];
}
}
if(next.cards==undefined){
if(get.itemtype(next.card)=='card'){
next.cards=[next.card];
}
else next.cards=[];
}
else if(next.card==undefined){
if(next.cards){
next.card=next.cards[0];
}
}
if(!next.targets){
next.targets=[];
}
for(var i=0;i<next.targets.length;i++){
if(ai.get.attitude(this,next.targets[i])>=-1&&ai.get.attitude(this,next.targets[i])<0){
if(!this.ai.tempIgnore) this.ai.tempIgnore=[];
this.ai.tempIgnore.add(next.targets[i]);
}
}
if(typeof this.logAi=='function'){
this.logAi(next.targets,next.card);
}
next.content=lib.element.playerproto.useCard;
return next;
},
useSkill:function(){
var next=game.createEvent('useSkill');
next.player=this;
next.num=0;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='cards'){
next.cards=arguments[i];
}
else if(get.itemtype(arguments[i])=='players'){
next.targets=arguments[i];
}
else if(get.itemtype(arguments[i])=='card'){
next.card=arguments[i];
}
else if(typeof arguments[i]=='string'){
next.skill=arguments[i];
}
else if(typeof arguments[i]=='boolean'){
next.addCount=arguments[i];
}
}
if(next.cards==undefined){
next.cards=[];
}
if(next.targets){
for(var i=0;i<next.targets.length;i++){
if(ai.get.attitude(this,next.targets[i])>=-1&&ai.get.attitude(this,next.targets[i])<0){
if(!this.ai.tempIgnore) this.ai.tempIgnore=[];
this.ai.tempIgnore.add(next.targets[i]);
}
}
if(typeof this.logAi=='function'){
this.logAi(next.targets,next.skill);
}
}
else{
next.targets=[];
}
next.content=lib.element.playerproto.useSkill;
},
draw:function(){
var next=game.createEvent('draw');
next.player=this;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='player'){
next.source=arguments[i];
}
else if(typeof arguments[i]=='number'){
next.num=arguments[i];
}
else if(typeof arguments[i]=='boolean'){
next.animate=arguments[i];
}
}
if(next.num==undefined) next.num=1;
if(next.num==0) _status.event.next.remove(next);
next.content=lib.element.playerproto.draw;
return next;
},
discard:function(){
var next=game.createEvent('discard');
next.player=this;
next.num=0;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='player'){
next.source=arguments[i];
}
else if(get.itemtype(arguments[i])=='cards'){
next.cards=arguments[i];
}
else if(get.itemtype(arguments[i])=='card'){
next.cards=[arguments[i]];
}
else if(typeof arguments[i]=='boolean'){
next.animate=arguments[i];
}
}
if(next.cards==undefined) _status.event.next.remove(next);
next.content=lib.element.playerproto.discard;
return next;
},
respond:function(){
var next=game.createEvent('respond');
next.player=this;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='cards'){
next.cards=arguments[i];
}
else if(get.itemtype(arguments[i])=='card'){
next.card=arguments[i];
}
else if(get.itemtype(arguments[i])=='player'){
next.source=arguments[i];
}
else if(typeof arguments[i]=='object'&&arguments[i].name){
next.card=arguments[i];
}
else if(typeof arguments[i]=='boolean') next.animate=arguments[i];
2015-11-06 10:05:08 +00:00
else if(arguments[i]=='highlight') next.highlight=true;
2015-04-29 03:25:17 +00:00
else if(typeof arguments[i]=='string') next.skill=arguments[i];
}
if(next.cards==undefined){
if(get.itemtype(next.card)=='card'){
next.cards=[next.card];
}
else{
next.cards=[];
}
}
else if(next.card==undefined){
if(next.cards){
next.card=next.cards[0];
}
}
next.content=lib.element.playerproto.respond;
},
2015-11-05 02:34:35 +00:00
directgain:function(cards,animate){
2015-11-04 01:59:00 +00:00
var hs=this.get('h');
for(var i=0;i<cards.length;i++){
if(hs.contains(cards[i])){
cards.splice(i--,1);
}
}
2015-05-13 10:26:54 +00:00
for(var i=0;i<cards.length;i++){
2015-11-25 10:25:18 +00:00
cards[i].fix();
2015-05-13 10:26:54 +00:00
var sort=lib.config.sort_card(cards[i]);
2015-12-02 15:34:34 +00:00
if(this==game.me){
2015-11-24 00:50:54 +00:00
cards[i].classList.add('drawinghidden');
}
2015-10-31 10:14:14 +00:00
if(lib.isSingleHandcard()||sort>0){
2015-11-05 02:34:35 +00:00
this.node.handcards1.appendChild(cards[i]);
2015-05-13 10:26:54 +00:00
}
else{
2015-11-05 02:34:35 +00:00
this.node.handcards2.appendChild(cards[i]);
2015-05-13 10:26:54 +00:00
}
}
2015-11-25 12:34:54 +00:00
if(this==game.me||_status.video) ui.updatehl();
2015-11-04 01:59:00 +00:00
if(!_status.video){
game.addVideo('directgain',this,get.cardsInfo(cards));
this.update();
}
2015-05-13 10:26:54 +00:00
return this;
},
2015-04-29 03:25:17 +00:00
gain:function(){
var next=game.createEvent('gain');
next.player=this;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='player'){
next.source=arguments[i];
}
else if(get.itemtype(arguments[i])=='cards'){
next.cards=arguments[i];
}
else if(get.itemtype(arguments[i])=='card'){
next.cards=[arguments[i]];
}
else if(typeof arguments[i]=='string'){
next.animate=arguments[i];
}
}
next.content=lib.element.playerproto.gain;
return next;
},
lose:function(){
var next=game.createEvent('lose');
next.player=this;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='player'){
next.source=arguments[i];
}
else if(get.itemtype(arguments[i])=='cards'){
next.cards=arguments[i];
}
else if(get.itemtype(arguments[i])=='card'){
next.cards=[arguments[i]];
}
else if(get.objtype(arguments[i])=='div'){
next.position=arguments[i];
}
}
if(next.cards==undefined) _status.event.next.remove(next);
if(next.position==undefined) next.position=ui.discardPile;
next.content=lib.element.playerproto.lose;
return next;
},
damage:function(){
var next=game.createEvent('damage');
next.player=this;
var nocard,nosource;
var event=_status.event;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='cards'){
next.cards=arguments[i];
}
else if(get.itemtype(arguments[i])=='card'){
next.card=arguments[i];
}
else if(typeof arguments[i]=='number'){
next.num=arguments[i];
}
else if(get.itemtype(arguments[i])=='player'){
next.source=arguments[i];
}
else if(typeof arguments[i]=='object'&&arguments[i].name){
next.card=arguments[i];
}
else if(arguments[i]=='nocard'){
nocard=true;
}
else if(arguments[i]=='nosource'){
nosource=true;
}
else if(get.itemtype(arguments[i])=='nature'){
next.nature=arguments[i];
}
}
if(next.card==undefined&&!nocard) next.card=event.card;
if(next.cards==undefined&&!nocard) next.cards=event.cards;
if(next.source==undefined&&!nosource) next.source=event.player;
if(next.num==undefined) next.num=1;
if(next.nature=='poison') delete next._triggered;
next.content=lib.element.playerproto.damage;
2015-09-25 00:26:16 +00:00
return next;
2015-04-29 03:25:17 +00:00
},
recover:function(){
var next=game.createEvent('recover');
next.player=this;
var nocard,nosource;
var event=_status.event;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='cards'){
next.cards=arguments[i];
}
else if(get.itemtype(arguments[i])=='card'){
next.card=arguments[i];
}
else if(get.itemtype(arguments[i])=='player'){
next.source=arguments[i];
}
2015-11-01 07:54:42 +00:00
else if(typeof arguments[i]=='object'&&arguments[i].name){
next.card=arguments[i];
}
2015-04-29 03:25:17 +00:00
else if(typeof arguments[i]=='number'){
next.num=arguments[i];
}
else if(arguments[i]=='nocard'){
nocard=true;
}
else if(arguments[i]=='nosource'){
nosource=true;
}
}
if(next.card==undefined&&!nocard) next.card=event.card;
if(next.cards==undefined&&!nocard) next.cards=event.cards;
if(next.source==undefined&&!nosource) next.source=event.player;
if(next.num==undefined) next.num=1;
if(next.num<=0) _status.event.next.remove(next);
next.content=lib.element.playerproto.recover;
2015-11-01 07:54:42 +00:00
return next;
2015-04-29 03:25:17 +00:00
},
2015-04-29 10:02:31 +00:00
doubleDraw:function(){
var next=game.createEvent('doubleDraw');
next.player=this;
next.content=lib.element.playerproto.doubleDraw;
return next;
},
2015-04-29 03:25:17 +00:00
loseHp:function(num){
var next=game.createEvent('loseHp');
next.num=num;
next.player=this;
if(next.num==undefined) next.num=1;
next.content=lib.element.playerproto.loseHp;
},
2015-04-29 10:02:31 +00:00
loseMaxHp:function(){
2015-04-29 03:25:17 +00:00
var next=game.createEvent('loseMaxHp');
next.player=this;
2015-04-29 10:02:31 +00:00
next.num=1;
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]==='number'){
next.num=arguments[i];
}
else if(typeof arguments[i]==='boolean'){
next.forced=arguments[i];
}
}
2015-04-29 03:25:17 +00:00
next.content=lib.element.playerproto.loseMaxHp;
},
gainMaxHp:function(num){
var next=game.createEvent('gainMaxHp');
next.num=num;
next.player=this;
if(next.num==undefined) next.num=1;
next.content=lib.element.playerproto.gainMaxHp;
},
changeHp:function(num,popup){
var next=game.createEvent('changeHp',false);
next.num=num;
if(popup!=undefined) next.popup=popup;
next.player=this;
next.content=lib.element.playerproto.changeHp;
},
dying:function(reason){
var next=game.createEvent('dying',false);
next.player=this;
next.reason=reason;
next.source=reason.source;
next.content=lib.element.playerproto.dying;
},
die:function(reason){
var next=game.createEvent('die');
next.player=this;
next.reason=reason;
if(reason) next.source=reason.source;
next.content=lib.element.playerproto.die;
2015-05-05 09:23:31 +00:00
return next;
2015-04-29 03:25:17 +00:00
},
revive:function(hp){
2015-12-08 13:54:44 +00:00
game.log(this,'复活');
2015-04-29 03:25:17 +00:00
if(this.maxHp<1) this.maxHp=1;
if(hp) this.hp=hp;
2015-11-01 07:54:42 +00:00
else{
this.hp=1;
}
2015-11-04 01:59:00 +00:00
game.addVideo('revive',this);
2015-04-29 03:25:17 +00:00
this.classList.remove('dead');
this.removeAttribute('style');
2015-11-05 02:34:35 +00:00
this.node.avatar.style.transform='';
this.node.avatar2.style.transform='';
this.node.hp.show();
this.node.equips.show();
this.node.count.show();
2015-04-29 03:25:17 +00:00
this.update();
var player;
player=this.previousSeat;
while(player.isDead()) player=player.previousSeat;
player.next=this;
this.previous=player;
player=this.nextSeat;
while(player.isDead()) player=player.nextSeat;
player.previous=this;
this.next=player;
game.players.add(this);
game.dead.remove(this);
if(this==game.me){
if(ui.auto) ui.auto.show();
if(ui.wuxie) ui.wuxie.show();
2015-04-29 03:25:17 +00:00
if(ui.revive){
ui.revive.close();
delete ui.revive;
}
if(ui.swap){
ui.swap.close();
delete ui.swap;
}
if(ui.restart){
ui.restart.close();
delete ui.restart;
}
}
},
2015-05-13 10:26:54 +00:00
isMad:function(){
return this.skills.contains('mad');
},
goMad:function(){
this.addSkill('mad');
2015-12-08 13:54:44 +00:00
game.log(this,'进入混乱状态');
2015-05-13 10:26:54 +00:00
},
unMad:function(){
this.removeSkill('mad');
2015-12-08 13:54:44 +00:00
game.log(this,'解除混乱状态');
2015-05-13 10:26:54 +00:00
},
2015-04-29 03:25:17 +00:00
equip:function(card){
var next=game.createEvent('equip');
next.card=card;
next.player=this;
next.content=lib.element.playerproto.equip;
},
addJudge:function(card,cards){
var next=game.createEvent('addJudge');
next.card=card;
next.cards=cards;
if(next.cards==undefined) next.cards=[card];
if(get.itemtype(next.cards)=='card') next.cards=[next.cards];
next.player=this;
next.content=lib.element.playerproto.addJudge;
},
judge:function(){
var next=game.createEvent('judge');
next.player=this;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='card'){
next.card=arguments[i];
}
else if(typeof arguments[i]=='string'){
next.skill=arguments[i];
}
else if(typeof arguments[i]=='function'){
next.judge=arguments[i];
}
else if(typeof arguments[i]=='boolean'){
next.clearArena=arguments[i];
}
else if(get.objtype(arguments[i])=='div'){
next.position=arguments[i];
}
}
if(next.card&&next.judge==undefined){
next.judge=get.judge(next.card);
}
if(next.judge==undefined) next.judge=function(){return 0};
if(next.position==undefined) next.position=ui.discardPile;
var str='';
if(next.card) str=get.translation(next.card.viewAs||next.card.name);
else if(next.skill) str=get.translation(next.skill);
else str=get.translation(_status.event.name);
next.judgestr=str;
next.content=lib.element.playerproto.judge;
},
turnOver:function(){
var next=game.createEvent('turnOver');
next.player=this;
next.content=lib.element.playerproto.turnOver;
},
out:function(bool){
if(this.lockOut) return;
if(this.isOut()){
2015-12-08 13:54:44 +00:00
game.log(this,'进入游戏');
2015-04-29 03:25:17 +00:00
}
else{
2015-12-08 13:54:44 +00:00
game.log(this,'离开游戏');
2015-04-29 03:25:17 +00:00
}
this.classList.toggle('out');
if(bool) this.lockOut=bool;
},
link:function(){
var next=game.createEvent('link');
next.player=this;
next.content=lib.element.playerproto.link;
},
skip:function(name){
this.skipList.add(name);
},
logSkill:function(name,targets,nature){
if(get.itemtype(targets)=='player') targets=[targets];
2015-08-15 09:10:06 +00:00
var nopop=false;
if(Array.isArray(name)){
this.popup(name[1]);
name=name[0];
nopop=true;
}
2015-05-04 03:17:03 +00:00
if(lib.translate[name]){
2015-08-15 09:10:06 +00:00
if(!nopop) this.popup(name);
2015-05-04 03:17:03 +00:00
if(typeof targets=='object'&&targets.length){
2015-12-08 13:54:44 +00:00
game.log(this,'对',targets,'发动了','【'+get.translation(name)+'】');
2015-04-29 03:25:17 +00:00
}
2015-05-04 03:17:03 +00:00
else{
2015-12-08 13:54:44 +00:00
game.log(this,'发动了','【'+get.translation(name)+'】');
2015-04-29 03:25:17 +00:00
}
}
2015-05-04 03:17:03 +00:00
if(nature!=false){
2015-05-16 11:40:11 +00:00
if(nature===undefined){
nature='green';
}
2015-05-04 03:17:03 +00:00
this.line(targets,nature);
2015-04-29 03:25:17 +00:00
}
if(lib.skill[name]&&lib.skill[name].ai&&lib.skill[name].ai.expose!=undefined&&this.logAi){
this.logAi(lib.skill[name].ai.expose);
}
if(this.checkShow){
this.checkShow(name);
}
2015-04-29 14:56:33 +00:00
var info=lib.skill[name];
if(info&&lib.config.background_speak){
2015-05-14 09:23:45 +00:00
if(typeof info.audio==='number'){
game.playAudio('skill',name+Math.ceil(info.audio*Math.random()));
}
else if(info.audio){
game.playAudio('skill',name);
}
else{
2015-11-23 10:59:44 +00:00
if(lib.config.background_ogg&&info.audio!==false){
2015-05-16 11:22:27 +00:00
game.playSkillAudio(name);
2015-05-08 08:07:38 +00:00
}
}
2015-04-29 14:56:33 +00:00
}
2015-05-08 08:07:38 +00:00
if(lib.config.mode=='chess'){
this.chessFocus();
}
2015-04-29 03:25:17 +00:00
},
unprompt:function(){
if(this.node.prompt){
this.node.prompt.delete();
delete this.node.prompt;
}
},
prompt:function(name2,className){
var node;
if(this.node.prompt){
node=this.node.prompt;
node.innerHTML='';
node.className='popup';
}
else{
2015-05-08 08:07:38 +00:00
node=ui.create.div('.popup',this.parentNode);
2015-04-29 03:25:17 +00:00
this.node.prompt=node;
}
node.dataset.position=this.dataset.position;
2015-05-04 03:17:03 +00:00
if(this.dataset.position==0||parseInt(this.dataset.position)==parseInt(ui.arena.dataset.number)/2||
2015-05-03 15:17:15 +00:00
typeof name2=='number'||this.classList.contains('minskin')){
2015-04-29 03:25:17 +00:00
node.innerHTML=name2;
}
else{
for(var i=0;i<name2.length;i++){
node.innerHTML+=name2[i]+'<br/>';
}
}
if(className){
node.classList.add(className);
}
},
popup:function(name,className){
var name2=get.translation(name);
2015-05-08 08:07:38 +00:00
var node=ui.create.div('.popup',this.parentNode);
2015-08-15 09:10:06 +00:00
if(!name2){
node.remove();
return node;
}
2015-11-04 01:59:00 +00:00
game.addVideo('popup',this,[name,className]);
2015-04-29 03:25:17 +00:00
node.dataset.position=this.dataset.position;
2015-05-04 03:17:03 +00:00
if(this.dataset.position==0||parseInt(this.dataset.position)==parseInt(ui.arena.dataset.number)/2||
2015-05-03 15:17:15 +00:00
typeof name2=='number'||this.classList.contains('minskin')){
2015-04-29 03:25:17 +00:00
node.innerHTML=name2;
}
else{
for(var i=0;i<name2.length;i++){
node.innerHTML+=name2[i]+'<br/>';
}
}
if(className){
node.classList.add(className);
}
this.popups.push(node);
if(this.popups.length>1){
node.hide();
}
else{
var that=this;
setTimeout(function(){that._popup();},1000);
}
2015-06-12 05:35:29 +00:00
return node;
2015-04-29 03:25:17 +00:00
},
_popup:function(){
if(this.popups.length){
this.popups.shift().delete();
if(this.popups.length){
this.popups[0].show();
var that=this;
setTimeout(function(){that._popup();},1000);
}
}
},
markSkill:function(name,info,card){
2015-11-04 01:59:00 +00:00
if(get.itemtype(card)=='card'){
game.addVideo('markSkill',this,[name,get.cardInfo(card)]);
}
else{
game.addVideo('markSkill',this,[name]);
}
2015-04-29 03:25:17 +00:00
if(!info){
if(this.marks[name]){
return this;
}
if(lib.skill[name]){
info=lib.skill[name].intro;
}
if(!info){
return this;
}
}
if(this.marks[name]){
this.marks[name].info=info;
2015-11-28 03:45:23 +00:00
this.updateMarks();
2015-04-29 03:25:17 +00:00
}
else{
if(card){
this.marks[name]=this.mark(card,info,name);
}
else{
this.marks[name]=this.mark(name,info);
}
}
return this;
},
unmarkSkill:function(name){
2015-11-04 01:59:00 +00:00
game.addVideo('unmarkSkill',this,name);
2015-04-29 03:25:17 +00:00
if(this.marks[name]){
this.marks[name].delete();
delete this.marks[name];
var info=lib.skill[name];
if(info&&info.intro&&info.intro.onunmark){
info.intro.onunmark(this.storage[name],this);
}
}
},
markCharacter:function(name,info,learn,learn2){
if(typeof name=='object'){
name=name.name;
}
if(!lib.character[name]) return this;
var node=ui.create.div('.card.mark',this.node.marks).setBackground(name,'character');
node.name=name+'_charactermark';
if(!info){
info={};
}
if(!info.name){
info.name=get.translation(name);
}
if(!info.content){
info.content=get.skillintro(name,learn,learn2)
}
node.info=info;
if(lib.config.touchscreen){
lib.setLongPress(node,ui.click.intro);
}
2015-11-13 09:12:47 +00:00
else{
if(lib.config.hover_all){
lib.setHover(node,ui.click.hoverplayer);
}
if(lib.config.right_info){
node.oncontextmenu=ui.click.rightplayer;
}
2015-04-29 03:25:17 +00:00
}
return node;
},
mark:function(name,info,skill){
if(get.itemtype(name)=='cards'){
var marks=[];
for(var i=0;i<name.length;i++){
marks.push(this.mark(name[i],info));
}
return marks;
}
else{
var node;
if(get.itemtype(name)=='card'){
node=name.copy('mark',this.node.marks);
node.suit=name.suit;
node.number=name.number;
name=name.name;
}
else{
node=ui.create.div('.card.mark',this.node.marks);
var str=lib.translate[name+'_bg'];
if(!str||str[0]=='+'||str[0]=='-'){
str=get.translation(name)[0];
}
ui.create.div('.background.skillmark',node).innerHTML=str;
// node.style.fontFamily=lib.config.card_font;
}
node.name=name;
node.skill=skill||name;
if(typeof info=='object'){
node.info=info;
}
else if(typeof info=='string'){
node.markidentifer=info;
}
if(lib.config.touchscreen){
lib.setLongPress(node,ui.click.intro);
}
2015-11-13 09:12:47 +00:00
else{
if(lib.config.hover_all){
lib.setHover(node,ui.click.hoverplayer);
}
if(lib.config.right_info){
node.oncontextmenu=ui.click.rightplayer;
}
2015-04-29 03:25:17 +00:00
}
2015-11-28 03:45:23 +00:00
this.updateMarks();
2015-04-29 03:25:17 +00:00
return node;
}
},
unmark:function(name,info){
2015-11-04 01:59:00 +00:00
game.addVideo('unmarkname',this,name);
2015-04-29 03:25:17 +00:00
if(get.itemtype(name)=='card'){
this.unmark(name.name,info);
}
else if(get.itemtype(name)=='cards'){
for(var i=0;i<name.length;i++){
this.unmark(name[i].name,info);
}
}
else{
for(var i=0;i<this.node.marks.childNodes.length;i++){
if(this.node.marks.childNodes[i].name==name&&
(!info||this.node.marks.childNodes[i].markidentifer==info)){
this.node.marks.childNodes[i].delete();
return;
}
}
}
},
canUse:function(card,player,distance,includecard){
if(typeof card=='string') card={name:card};
if(includecard&&!lib.filter.filterCard(card,this)) return false;
if(distance==false) return lib.filter.targetEnabled(card,this,player);
return lib.filter.filterTarget(card,this,player);
},
addSkill:function(skill){
if(get.objtype(skill)=='array'){
for(var i=0;i<skill.length;i++){
this.addSkill(skill[i]);
}
}
else{
if(!lib.skill[skill]) return;
if(this.skills.contains(skill)) return;
this.skills.add(skill);
if(lib.skill[skill].global){
if(typeof lib.skill[skill].global=='string'){
lib.skill.global.add(lib.skill[skill].global);
}
else{
for(var j=0;j<lib.skill[skill].global.length;j++){
lib.skill.global.add(lib.skill[skill].global[j])
}
}
}
if(lib.skill[skill].init){
if(!this.initedSkills.contains(skill)){
lib.skill[skill].init(this);
this.initedSkills.push(skill);
}
}
if(lib.skill[skill].init2){
lib.skill[skill].init2(this);
}
if(lib.skill[skill].mark){
if(lib.skill[skill].mark=='card'&&
2015-06-10 09:10:24 +00:00
get.itemtype(this.storage[skill])=='card'){
this.markSkill(skill,null,this.storage[skill]);
}
else if(lib.skill[skill].mark=='image'){
this.markSkill(skill,null,ui.create.card(null,'noclick').init([null,null,skill]));
2015-04-29 03:25:17 +00:00
}
else{
this.markSkill(skill);
}
}
}
this.checkConflict();
return skill;
},
checkMarks:function(){
var skills=this.get('s');
for(var i in this.marks){
if(!skills.contains(i)&&!this.marks[i].info.fixed){
this.unmarkSkill(i);
}
}
return this;
},
removeSkill:function(skill){
this.unmarkSkill(skill);
this.skills.remove(skill);
this.checkConflict();
return skill;
},
addTempSkill:function(skill,expire){
if(this.skills.contains(skill)&&this.tempSkills[skill]==undefined) return;
this.addSkill(skill);
this.tempSkills[skill]=expire;
this.checkConflict();
return skill;
},
attitudeTo:function(target){
if(typeof ai.get.attitude=='function') return ai.get.attitude(this,target);
return 0;
},
clearSkills:function(){
var list=[];
var exclude=[];
for(var i=0;i<arguments.length;i++) exclude.push(arguments[i]);
for(i=0;i<this.skills.length;i++){
if(this.modeSkills.contains(this.skills[i])==false&&
exclude.contains(this.skills[i])==false){
list.push(this.skills[i]);
}
}
this.skills.remove(list);
this.checkConflict();
this.checkMarks();
return list;
},
checkConflict:function(){
if(this.name&&this.name2){
this.forbiddenSkills.length=0;
var forbid=[];
2015-10-30 09:13:19 +00:00
var getName=function(arr){
var str='';
for(var i=0;i<arr.length;i++){
str+=arr[i]+'+';
}
return str.slice(0,str.length-1);
}
2015-04-29 03:25:17 +00:00
for(var i=0;i<lib.config.forbid.length;i++){
2015-10-30 09:13:19 +00:00
if(!lib.config.forbidlist.contains(getName(lib.config.forbid[i]))){
2015-04-29 03:25:17 +00:00
for(var j=0;j<lib.config.forbid[i].length;j++){
if(this.skills.contains(lib.config.forbid[i][j])==false) break;
}
if(j==lib.config.forbid[i].length) forbid.push(lib.config.forbid[i]);
}
}
for(var i=0;i<forbid.length;i++){
this.forbiddenSkills.add(forbid[i][0]);
}
}
},
getStat:function(key){
if(!key) return this.stat[this.stat.length-1];
return this.stat[this.stat.length-1][key];
},
queue:function(time){
if(time==false){
clearTimeout(this.queueTimeout);
this.queueCount=0;
return;
}
if(time==undefined) time=500;
var player=this;
player.queueCount++;
this.queueTimeout=setTimeout(function(){
player.queueCount--;
if(player.queueCount==0){
player.removeAttribute('style');
2015-10-31 10:14:14 +00:00
player.node.avatar.style.transform='';
2015-11-04 01:59:00 +00:00
player.node.avatar2.style.transform='';
2015-04-29 03:25:17 +00:00
if(player==game.me) ui.me.removeAttribute('style');
}
},time)
},
isAlive:function(){
return this.classList.contains('dead')==false;
},
isDead:function(){
return this.classList.contains('dead');
},
isLinked:function(){
return this.classList.contains('linked');
},
isTurnedOver:function(){
return this.classList.contains('turnedover');
},
isOut:function(){
return this.classList.contains('out');
},
2015-05-12 09:51:40 +00:00
isMin:function(distance){
if(distance&&lib.config.mode!='stone') return false;
if(this.forcemin) return true;
2015-05-08 08:07:38 +00:00
return this.classList.contains('minskin')&&lib.config.mode!='chess';
2015-05-03 15:17:15 +00:00
},
2015-04-29 03:25:17 +00:00
isIn:function(){
return this.classList.contains('dead')==false&&this.classList.contains('out')==false&&!this.removed;
},
2015-05-01 07:35:43 +00:00
isUnderControl:function(){
2015-05-08 08:07:38 +00:00
if(this===game.me) return false;
2015-05-13 10:26:54 +00:00
if(this.isMad()) return false;
2015-05-01 07:35:43 +00:00
if(lib.config.mode=='versus'){
return ui.autoreplace&&ui.autoreplace.classList.contains('on')&&
2015-05-08 08:07:38 +00:00
this.side==game.me.side;
}
2015-05-13 10:26:54 +00:00
else if(lib.config.mode=='chess'||lib.config.mode=='boss'){
2015-05-08 08:07:38 +00:00
return this.side==game.me.side;
2015-05-01 07:35:43 +00:00
}
return false;
2015-04-29 03:25:17 +00:00
},
hasSkillTag:function(tag,hidden){
var skills=game.expandSkills(this.get('s',hidden));
for(var i=0;i<skills.length;i++){
var info=lib.skill[skills[i]];
2015-05-04 03:17:03 +00:00
if(info&&info.ai){
if(info.ai.skillTagFilter&&
info.ai.skillTagFilter(this,tag)===false) continue;
if(info.ai[tag]) return true;
}
2015-04-29 03:25:17 +00:00
}
return false;
},
hasJudge:function(name){
var judges=this.node.judges.childNodes;
for(var i=0;i<judges.length;i++){
if((judges[i].viewAs||judges[i].name)==name){
return true;
}
}
return false;
},
2015-05-05 14:57:35 +00:00
hasFriend:function(){
for(var i=0;i<game.players.length;i++){
if(game.players[i]!=this&&ai.get.attitude(game.players[i],this)>=0){
return true;
}
}
return false;
},
2015-05-02 06:59:31 +00:00
getJudge:function(name){
var judges=this.node.judges.childNodes;
for(var i=0;i<judges.length;i++){
if((judges[i].viewAs||judges[i].name)==name){
return judges[i];
}
}
return null;
},
2015-11-24 15:44:21 +00:00
$draw:function(num,init,config){
// if(lib.config.low_performance&&lib.config.mode!='chess'){
2015-11-23 10:59:44 +00:00
// this.$gain(num,false,init);
// return;
// }
2015-04-29 03:25:17 +00:00
var cards,node;
if(get.itemtype(num)=='cards'){
cards=num;
num=cards.length;
}
else if(get.itemtype(num)=='card'){
cards=[num];
num=1;
}
2015-11-04 01:59:00 +00:00
if(init!==false){
if(cards){
game.addVideo('drawCard',this,get.cardsInfo(cards));
}
else{
game.addVideo('draw',this,num);
}
}
2015-04-29 03:25:17 +00:00
if(cards){
cards=cards.slice(0);
2015-11-14 05:29:22 +00:00
node=cards.shift().copy('thrown');
2015-04-29 03:25:17 +00:00
}
else{
2015-11-14 05:29:22 +00:00
node=ui.create.div('.card.thrown');
2015-04-29 03:25:17 +00:00
}
node.fixed=true;
2015-11-14 05:29:22 +00:00
node.hide();
2015-11-24 15:44:21 +00:00
2015-11-14 05:29:22 +00:00
node.style.left='calc(50% - 52px)';
node.style.top='calc(50% - 52px)';
2015-11-24 15:44:21 +00:00
2015-05-08 08:07:38 +00:00
this.parentNode.appendChild(node);
2015-11-27 09:20:02 +00:00
node.style.transitionDuration='0.8s';
2015-11-14 05:29:22 +00:00
ui.refresh(node);
var dx=this.offsetLeft+this.offsetWidth/2-52-node.offsetLeft;
var dy=this.offsetTop+this.offsetHeight/2-52-node.offsetTop;
2015-11-24 15:44:21 +00:00
var num3;
2015-11-25 15:59:24 +00:00
if(typeof num=='number'&&init!==false){
2015-11-24 15:44:21 +00:00
config={
total:num,
current:1
}
}
if(config&&config.total>1){
var total=config.total,current=config.current;
var dxtotal;
if(total<=5){
dxtotal=Math.min(80,(total-1)*20);
dx+=-dxtotal+2*dxtotal*(current-1)/(total-1)
}
else{
var total2=Math.floor(total/2);
if(current<=total2){
total=total2;
dy-=20;
}
else{
current-=total2;
total-=total2;
dy+=20;
}
dxtotal=Math.min(80,(total-1)*20);
dx+=-dxtotal+2*dxtotal*(current-1)/(total-1)
}
config.current++;
}
2015-11-21 05:30:26 +00:00
if(node.style.transform&&node.style.transform!='none'&&node.style.transform.indexOf('translate')==-1){
2015-11-15 05:54:58 +00:00
node.style.transform+=' translate('+dx+'px,'+dy+'px)';
}
else{
node.style.transform='translate('+dx+'px,'+dy+'px)';
}
2015-11-14 05:29:22 +00:00
node.show();
2015-11-24 15:44:21 +00:00
node.addEventListener('webkitTransitionEnd',function(){
2015-11-25 10:25:18 +00:00
node.style.transitionDuration='0.5s';
ui.refresh(node);
2015-11-14 05:29:22 +00:00
node.delete();
2015-11-24 15:44:21 +00:00
});
2015-04-29 03:25:17 +00:00
var that=this;
if(num&&num>1){
2015-11-24 15:44:21 +00:00
if(config&&config.total>1){
setTimeout(function(){
if(cards){
that.$draw(cards,false,config)
}
else{
that.$draw(num-1,false,config)
}
},50)
}
else{
setTimeout(function(){
if(cards){
that.$draw(cards,false,config)
}
else{
that.$draw(num-1,false,config)
}
},200);
}
2015-04-29 03:25:17 +00:00
}
},
$compare:function(card1,target,card2){
2015-11-04 01:59:00 +00:00
game.addVideo('compare',this,[get.cardInfo(card1),target.dataset.position,get.cardInfo(card2)]);
2015-04-29 03:25:17 +00:00
var player=this;
2015-11-23 10:59:44 +00:00
var node1=player.$throwxy2(card1,
'calc(50% - 114px)','calc(50% - 52px)','perspective(600px) rotateY(180deg)',true
2015-04-29 03:25:17 +00:00
);
2015-12-07 11:15:35 +00:00
if(lib.config.cardback_style!='default'){
node1.style.transitionProperty='none';
ui.refresh(node1);
node1.classList.add('infohidden');
ui.refresh(node1);
node1.style.transitionProperty='';
}
else{
node1.classList.add('infohidden');
}
2015-11-05 02:34:35 +00:00
node1.style.transform='perspective(600px) rotateY(180deg) translateX(0)';
2015-11-26 00:50:57 +00:00
var onEnd01=function(){
node1.removeEventListener('webkitTransitionEnd',onEnd01);
2015-04-29 03:25:17 +00:00
setTimeout(function(){
node1.style.transition='all ease-in 0.3s';
2015-11-05 02:34:35 +00:00
node1.style.transform='perspective(600px) rotateY(270deg) translateX(52px)';
var onEnd=function(){
2015-04-29 03:25:17 +00:00
node1.classList.remove('infohidden');
2015-11-23 10:59:44 +00:00
node1.style.transition='all 0s';
ui.refresh(node1);
node1.style.transform='perspective(600px) rotateY(-90deg) translateX(52px)';
ui.refresh(node1);
2015-04-29 03:25:17 +00:00
node1.style.transition='';
2015-11-23 10:59:44 +00:00
ui.refresh(node1);
node1.style.transform='';
2015-11-15 05:54:58 +00:00
node1.removeEventListener('webkitTransitionEnd',onEnd);
2015-11-05 02:34:35 +00:00
}
node1.addEventListener('webkitTransitionEnd',onEnd);
2015-11-26 00:50:57 +00:00
},300);
};
node1.addEventListener('webkitTransitionEnd',onEnd01);
setTimeout(function(){
2015-11-23 10:59:44 +00:00
var node2=target.$throwxy2(card2,
'calc(50% + 10px)','calc(50% - 52px)','perspective(600px) rotateY(180deg)',true
2015-04-29 03:25:17 +00:00
);
2015-12-07 11:15:35 +00:00
if(lib.config.cardback_style!='default'){
node2.style.transitionProperty='none';
ui.refresh(node2);
node2.classList.add('infohidden');
ui.refresh(node2);
node2.style.transitionProperty='';
}
else{
node2.classList.add('infohidden');
}
2015-11-05 02:34:35 +00:00
node2.style.transform='perspective(600px) rotateY(180deg) translateX(0)';
2015-11-26 00:50:57 +00:00
var onEnd02=function(){
node2.removeEventListener('webkitTransitionEnd',onEnd02);
setTimeout(function(){
node2.style.transition='all ease-in 0.3s';
node2.style.transform='perspective(600px) rotateY(270deg) translateX(52px)';
var onEnd=function(){
node2.classList.remove('infohidden');
node2.style.transition='all 0s';
ui.refresh(node2);
node2.style.transform='perspective(600px) rotateY(-90deg) translateX(52px)';
ui.refresh(node2);
node2.style.transition='';
ui.refresh(node2);
node2.style.transform='';
node2.removeEventListener('webkitTransitionEnd',onEnd);
}
node2.addEventListener('webkitTransitionEnd',onEnd);
},200);
};
node2.addEventListener('webkitTransitionEnd',onEnd02);
2015-04-29 03:25:17 +00:00
},200);
},
2015-11-04 01:59:00 +00:00
$throw:function(card,time,init){
if(init!==false){
if(get.itemtype(card)!='cards'){
if(get.itemtype(card)=='card'){
card=[card];
}
else{
return;
}
}
game.addVideo('throw',this,[get.cardsInfo(card),time]);
}
2015-04-29 03:25:17 +00:00
if(get.itemtype(card)=='cards'){
2015-11-23 10:59:44 +00:00
var node;
2015-04-29 03:25:17 +00:00
for(var i=0;i<card.length;i++){
2015-11-23 10:59:44 +00:00
node=this.$throw(card[i],time,false);
2015-04-29 03:25:17 +00:00
}
2015-11-23 10:59:44 +00:00
return node;
2015-04-29 03:25:17 +00:00
}
else{
if(card==undefined||card.length==0) return;
2015-11-23 10:59:44 +00:00
if(false){
2015-11-15 05:54:58 +00:00
var left=-52+(Math.random()<0.5?1:-1)*Math.random()*100;
var top=-52+(Math.random()<0.5?1:-1)*Math.random()*80;
var node=this.$throwxy2(card,
'calc(50% '+(left>0?'+':'-')+' '+Math.abs(left)+'px)',
'calc(50% '+(top>0?'+':'-')+' '+Math.abs(top)+'px)'
2015-11-06 10:05:08 +00:00
);
}
else{
var node=this.$throwordered(card.copy('thrown'));
}
2015-04-29 03:25:17 +00:00
if(time!=undefined){
node.fixed=true;
setTimeout(function(){node.delete()},time);
}
2015-11-23 10:59:44 +00:00
lib.listenEnd(node);
return node;
2015-04-29 03:25:17 +00:00
}
},
2015-11-23 10:59:44 +00:00
$throwordered:function(){
if(lib.config.low_performance){
return this.$throwordered2.apply(this,arguments);
}
else{
return this.$throwordered1.apply(this,arguments);
}
},
$throwordered1:function(node,nosource){
2015-11-06 10:05:08 +00:00
node.classList.add('thrown');
node.hide();
node.style.transitionProperty='left,top,opacity,transform';
for(var i=0;i<ui.thrown.length;i++){
if(ui.thrown[i].parentNode!=ui.arena||
ui.thrown[i].classList.contains('removing')){
ui.thrown.splice(i--,1);
}
}
ui.thrown.push(node);
var uithrowns=ui.thrown.slice(0);
var row=0;
var tops;
switch(Math.floor((ui.thrown.length-1)/4)){
case 0:
tops=['calc(50% - 52px)'];
break;
case 1:
tops=['calc(50% - 109px)','calc(50% + 5px)'];
break;
case 2:
tops=['calc(50% - 166px)','calc(50% - 52px)','calc(50% + 62px)'];
break;
default:
tops=['calc(50% - 223px)','calc(50% - 109px)',
'calc(50% + 5px)','calc(50% + 119px)'];
}
while(uithrowns.length){
var throwns=uithrowns.splice(0,Math.min(uithrowns.length,4));
switch(throwns.length){
case 1:
throwns[0].style.left='calc(50% - 52px)';
break;
case 2:
throwns[0].style.left='calc(50% - 109px)';
throwns[1].style.left='calc(50% + 5px)';
break;
case 3:
throwns[0].style.left='calc(50% - 166px)';
throwns[1].style.left='calc(50% - 52px)';
throwns[2].style.left='calc(50% + 62px)';
break;
case 4:
throwns[0].style.left='calc(50% - 223px)';
throwns[1].style.left='calc(50% - 109px)';
throwns[2].style.left='calc(50% + 5px)';
throwns[3].style.left='calc(50% + 119px)';
break;
}
var top;
if(tops.length){
top=tops.shift();
}
else{
top='calc(50% - 52px)';
}
for(var i=0;i<throwns.length;i++){
throwns[i].style.top=top;
}
}
2015-11-14 05:29:22 +00:00
if(nosource){
node.style.transform='scale(0)';
node.classList.add('center');
}
else{
var parseCalc=function(str){
var per=str.slice(str.indexOf('calc(')+5,str.indexOf('%'));
var add=str.slice(str.indexOf('%')+1,str.indexOf('px')).replace(/\s/g,'');
return [parseInt(per),parseInt(add)];
}
var nx=parseCalc(node.style.left);
var ny=parseCalc(node.style.top);
nx=nx[0]*ui.arena.offsetWidth/100+nx[1];
ny=ny[0]*ui.arena.offsetHeight/100+ny[1];
var dx=this.offsetLeft+this.offsetWidth/2-52-nx;
var dy=this.offsetTop+this.offsetHeight/2-52-ny;
2015-11-21 05:30:26 +00:00
if(node.style.transform&&node.style.transform!='none'&&node.style.transform.indexOf('translate')==-1){
2015-11-15 05:54:58 +00:00
node.style.transform+=' translate('+dx+'px,'+dy+'px)';
}
else{
node.style.transform='translate('+dx+'px,'+dy+'px)';
}
2015-11-14 05:29:22 +00:00
}
ui.arena.appendChild(node);
ui.refresh(node);
node.style.transform='';
node.show();
2015-11-23 10:59:44 +00:00
lib.listenEnd(node);
return node;
},
$throwordered2:function(node,nosource){
node.classList.add('thrown');
node.classList.add('center');
node.hide();
node.style.transitionProperty='left,top,opacity,transform';
if(nosource){
// node.style.transform='scale(0)';
}
else{
var nx=[50,-52];
var ny=[50,-52];
nx=nx[0]*ui.arena.offsetWidth/100+nx[1];
ny=ny[0]*ui.arena.offsetHeight/100+ny[1];
var dx=this.offsetLeft+this.offsetWidth/2-52-nx;
var dy=this.offsetTop+this.offsetHeight/2-52-ny;
if(node.style.transform&&node.style.transform!='none'&&node.style.transform.indexOf('translate')==-1){
node.style.transform+=' translate('+dx+'px,'+dy+'px)';
}
else{
node.style.transform='translate('+dx+'px,'+dy+'px)';
}
}
ui.arena.appendChild(node);
ui.refresh(node);
for(var i=0;i<ui.thrown.length;i++){
if(ui.thrown[i].parentNode!=ui.arena||
ui.thrown[i].classList.contains('removing')){
ui.thrown.splice(i--,1);
}
}
ui.thrown.push(node);
var uithrowns=ui.thrown.slice(0);
var row=0;
var tops;
switch(Math.floor((ui.thrown.length-1)/4)){
case 0:
tops=[0];
break;
case 1:
tops=[-57,57];
break;
case 2:
tops=[-114,0,114];
break;
default:
tops=[-171,-57,57,171];
}
while(uithrowns.length){
var throwns=uithrowns.splice(0,Math.min(uithrowns.length,4));
switch(throwns.length){
case 1:
throwns[0]._transthrown='translate(0px,';
break;
case 2:
throwns[0]._transthrown='translate(-57px,';
throwns[1]._transthrown='translate(57px,';
break;
case 3:
throwns[0]._transthrown='translate(-114px,';
throwns[1]._transthrown='translate(0,';
throwns[2]._transthrown='translate(114px,';
break;
case 4:
throwns[0]._transthrown='translate(-171px,';
throwns[1]._transthrown='translate(-57px,';
throwns[2]._transthrown='translate(57px,';
throwns[3]._transthrown='translate(171px,';
break;
}
var top;
if(tops.length){
top=tops.shift();
}
else{
top=0;
}
for(var i=0;i<throwns.length;i++){
throwns[i].style.transform=throwns[i]._transthrown+top+'px)';
delete throwns[i]._transthrown;
}
}
node.show();
lib.listenEnd(node);
2015-11-06 10:05:08 +00:00
return node;
},
2015-11-14 05:29:22 +00:00
$throwxy:function(card,left,top){
2015-11-23 10:59:44 +00:00
var node=card.copy('thrown','thrownhighlight');
2015-04-29 03:25:17 +00:00
node.dataset.position=this.dataset.position;
node.hide();
node.style.transitionProperty='left,top,opacity';
2015-11-15 05:54:58 +00:00
2015-04-29 03:25:17 +00:00
ui.arena.appendChild(node);
ui.refresh(node);
node.show();
node.style.left=left;
node.style.top=top;
2015-11-23 10:59:44 +00:00
lib.listenEnd(node);
2015-04-29 03:25:17 +00:00
return node;
},
2015-11-23 10:59:44 +00:00
$throwxy2:function(card,left,top,trans,flipx,flipy){
if(lib.config.mode=='chess'){
return this.$throwxy.apply(this,arguments);
}
var node=card.copy('thrown','thrownhighlight');
2015-11-15 05:54:58 +00:00
node.style.left=left;
node.style.top=top;
node.hide();
2015-11-23 10:59:44 +00:00
// node.style.transitionProperty='left,top,opacity,transform';
2015-11-15 05:54:58 +00:00
var parseCalc=function(str){
var per=str.slice(str.indexOf('calc(')+5,str.indexOf('%'));
var add=str.slice(str.indexOf('%')+1,str.indexOf('px')).replace(/\s/g,'');
return [parseInt(per),parseInt(add)];
}
var nx=parseCalc(node.style.left);
var ny=parseCalc(node.style.top);
nx=nx[0]*ui.arena.offsetWidth/100+nx[1];
ny=ny[0]*ui.arena.offsetHeight/100+ny[1];
var dx=this.offsetLeft+this.offsetWidth/2-52-nx;
var dy=this.offsetTop+this.offsetHeight/2-52-ny;
2015-11-23 10:59:44 +00:00
if(flipx) dx=-dx;
if(flipy) dy=-dy;
if(trans){
node.style.transform=trans+' translate('+dx+'px,'+dy+'px)';
2015-11-15 05:54:58 +00:00
}
else{
node.style.transform='translate('+dx+'px,'+dy+'px)';
}
ui.arena.appendChild(node);
ui.refresh(node);
node.show();
2015-11-23 10:59:44 +00:00
// node.style.transform=trans||'';
lib.listenEnd(node);
2015-11-15 05:54:58 +00:00
return node;
},
2015-11-04 01:59:00 +00:00
$give:function(card,player,log,init){
if(init!==false){
if(typeof card=='number'&&card>=0){
game.addVideo('give',this,[card,player.dataset.position]);
}
else{
if(get.itemtype(card)=='card'){
card=[card];
}
if(get.itemtype(card)=='cards'){
game.addVideo('giveCard',this,[get.cardsInfo(card),player.dataset.position]);
}
}
}
2015-04-29 03:25:17 +00:00
if(get.itemtype(card)=='cards'){
if(log!=false){
2015-12-08 13:54:44 +00:00
game.log(player,'从',this,'获得了',card);
2015-04-29 03:25:17 +00:00
}
2015-05-08 08:07:38 +00:00
if(this.$givemod){
this.$givemod(card,player);
}
else{
for(var i=0;i<card.length;i++){
2015-11-04 01:59:00 +00:00
this.$give(card[i],player,false,false);
2015-05-08 08:07:38 +00:00
}
2015-04-29 03:25:17 +00:00
}
}
2015-05-04 03:17:03 +00:00
else if(typeof card=='number'&&card>=0){
2015-04-29 03:25:17 +00:00
if(log!=false){
2015-12-08 13:54:44 +00:00
game.log(player,'从',this,'获得了'+get.cnNumber(card)+'张牌');
2015-04-29 03:25:17 +00:00
}
2015-05-08 08:07:38 +00:00
if(this.$givemod){
this.$givemod(card,player);
}
else{
2015-11-04 01:59:00 +00:00
while(card--) this.$give('',player,false,false);
2015-05-08 08:07:38 +00:00
}
2015-04-29 03:25:17 +00:00
}
else{
if(log!=false){
if(get.itemtype(card)=='card'&&log!=false){
2015-12-08 13:54:44 +00:00
game.log(player,'从',this,'获得了',card);
2015-04-29 03:25:17 +00:00
}
else{
2015-12-08 13:54:44 +00:00
game.log(player,'从',this,'获得了一张牌');
2015-04-29 03:25:17 +00:00
}
}
2015-05-08 08:07:38 +00:00
if(this.$givemod){
this.$givemod(card,player);
2015-04-29 03:25:17 +00:00
}
else{
2015-05-08 08:07:38 +00:00
var node;
if(get.itemtype(card)=='card'){
node=card.copy('card','thrown',false);
}
else{
node=ui.create.div('.card.thrown');
}
2015-11-14 05:29:22 +00:00
// node.dataset.position=this.dataset.position;
2015-05-08 08:07:38 +00:00
node.fixed=true;
2015-11-06 10:05:08 +00:00
this.$throwordered(node);
2015-12-08 13:54:44 +00:00
// lib.listenEnd(node);
2015-11-06 10:05:08 +00:00
// node.hide();
// node.style.transitionProperty='left,top,opacity';
//
// node.style.transform='rotate('+(Math.random()*16-8)+'deg)';
//
// ui.arena.appendChild(node);
// ui.refresh(node);
// node.show();
// node.style.left='calc(50% - 52px '+((Math.random()-0.5<0)?'+':'-')+' '+Math.random()*100+'px)';
// node.style.top='calc(50% - 52px '+((Math.random()-0.5<0)?'+':'-')+' '+Math.random()*80+'px)';
2015-05-08 08:07:38 +00:00
2015-11-24 15:44:21 +00:00
node.addEventListener('webkitTransitionEnd',function(){
2015-11-14 05:29:22 +00:00
var dx=player.offsetLeft+player.offsetWidth/2-52-node.offsetLeft;
var dy=player.offsetTop+player.offsetHeight/2-52-node.offsetTop;
2015-11-21 05:30:26 +00:00
if(node.style.transform&&node.style.transform!='none'&&node.style.transform.indexOf('translate')==-1){
2015-11-15 05:54:58 +00:00
node.style.transform+=' translate('+dx+'px,'+dy+'px)';
}
else{
node.style.transform='translate('+dx+'px,'+dy+'px)';
}
2015-11-14 05:29:22 +00:00
2015-05-08 08:07:38 +00:00
node.delete();
2015-11-24 15:44:21 +00:00
});
// setTimeout(function(){
// // node.removeAttribute('style');
// // node.dataset.position=player.dataset.position;
// var dx=player.offsetLeft+player.offsetWidth/2-52-node.offsetLeft;
// var dy=player.offsetTop+player.offsetHeight/2-52-node.offsetTop;
// if(node.style.transform&&node.style.transform!='none'&&node.style.transform.indexOf('translate')==-1){
// node.style.transform+=' translate('+dx+'px,'+dy+'px)';
// }
// else{
// node.style.transform='translate('+dx+'px,'+dy+'px)';
// }
//
// node.delete();
// },700);
2015-05-08 08:07:38 +00:00
}
2015-04-29 03:25:17 +00:00
}
},
2015-11-04 01:59:00 +00:00
$equip:function(card){
2015-11-24 00:50:54 +00:00
card.style.transform='';
2015-11-04 01:59:00 +00:00
var player=this;
var equipNum=get.equipNum(card);
var equipped=false;
for(var i=0;i<player.node.equips.childNodes.length;i++){
if(get.equipNum(player.node.equips.childNodes[i])>=equipNum){
player.node.equips.insertBefore(card,player.node.equips.childNodes[i]);
equipped=true;
break;
}
}
if(!equipped){
player.node.equips.appendChild(card);
}
return player;
},
$gain:function(card,log,init){
if(init!==false){
if(typeof card=='number'&&card>=0){
game.addVideo('gain',this,card);
}
else{
if(get.itemtype(card)=='card'){
card=[card];
}
if(get.itemtype(card)=='cards'){
game.addVideo('gainCard',this,get.cardsInfo(card));
}
else{
game.addVideo('gain',this,1);
}
}
}
2015-04-29 03:25:17 +00:00
if(get.itemtype(card)=='cards'){
if(log!=false){
2015-12-08 13:54:44 +00:00
game.log(this,'获得了',card);
2015-04-29 03:25:17 +00:00
}
2015-05-08 08:07:38 +00:00
if(this.$gainmod){
this.$gainmod(card);
}
else{
for(var i=0;i<card.length;i++){
2015-11-04 01:59:00 +00:00
this.$gain(card[i],false,false);
2015-05-08 08:07:38 +00:00
}
2015-04-29 03:25:17 +00:00
}
}
else if(typeof card=='number'&&card>1){
if(log!=false){
2015-12-08 13:54:44 +00:00
game.log(this,'获得了'+get.cnNumber(card)+'张牌');
2015-04-29 03:25:17 +00:00
}
2015-05-08 08:07:38 +00:00
if(this.$gainmod){
this.$gainmod(card);
}
else{
for(var i=0;i<card;i++){
2015-11-04 01:59:00 +00:00
this.$gain(1,false,false);
2015-05-08 08:07:38 +00:00
}
2015-04-29 03:25:17 +00:00
}
}
else{
if(get.itemtype(card)=='card'&&log!=false){
2015-12-08 13:54:44 +00:00
game.log(this,'获得了',card);
2015-04-29 03:25:17 +00:00
}
2015-05-08 08:07:38 +00:00
if(this.$gainmod){
this.$gainmod(card);
2015-04-29 03:25:17 +00:00
}
else{
2015-05-08 08:07:38 +00:00
var node;
if(get.itemtype(card)=='card'){
2015-11-24 00:50:54 +00:00
// node=this.$throwordered(card.copy(),true);
node=card.copy('thrown',false);
2015-05-08 08:07:38 +00:00
}
else{
2015-11-24 00:50:54 +00:00
// node=this.$throwordered(ui.create.div('.card.thrown'),true);
node=ui.create.div('.card.thrown');
2015-05-08 08:07:38 +00:00
node.moveTo=lib.element.card.moveTo;
2015-11-23 10:59:44 +00:00
node.moveDelete=lib.element.card.moveDelete;
2015-05-08 08:07:38 +00:00
}
2015-11-24 00:50:54 +00:00
node.fixed=true;
node.style.left='calc(50% - 52px '+((Math.random()-0.5<0)?'+':'-')+' '+Math.random()*100+'px)';
node.style.top='calc(50% - 52px '+((Math.random()-0.5<0)?'+':'-')+' '+Math.random()*100+'px)';
node.style.transform='scale(0)';
node.hide();
ui.arena.appendChild(node);
ui.refresh(node);
node.show();
node.style.transform='';
2015-11-23 10:59:44 +00:00
lib.listenEnd(node);
2015-05-08 08:07:38 +00:00
var player=this;
setTimeout(function(){
2015-11-23 10:59:44 +00:00
node.moveDelete(player);
2015-05-08 08:07:38 +00:00
},700);
}
2015-04-29 03:25:17 +00:00
}
},
$gain2:function(cards,log){
if(get.itemtype(cards)=='card') cards=[cards];
else if(get.itemtype(cards)!='cards') return;
2015-11-04 01:59:00 +00:00
var list=[],list2=[];
2015-04-29 03:25:17 +00:00
for(var i=0;i<cards.length;i++){
2015-11-23 10:59:44 +00:00
if(cards[i].clone&&
(cards[i].clone.parentNode==this.parentNode||
cards[i].clone.parentNode==ui.arena)&&
2015-11-05 02:34:35 +00:00
parseFloat(getComputedStyle(cards[0].clone).opacity)>0.3){
2015-11-23 10:59:44 +00:00
cards[i].clone.moveDelete(this);
2015-11-04 01:59:00 +00:00
list2.push(cards[i].clone);
2015-04-29 03:25:17 +00:00
}
else{
list.push(cards[i]);
}
}
2015-11-04 01:59:00 +00:00
if(list2.length){
game.addVideo('gain2',this,get.cardsInfo(list2));
}
2015-04-29 03:25:17 +00:00
if(list.length) this.$draw(list);
},
2015-09-25 00:26:16 +00:00
$fire:function(){
2015-11-04 01:59:00 +00:00
game.addVideo('flame',this,'fire');
2015-09-30 07:24:45 +00:00
var left,top;
if(lib.config.mode=='chess'){
var rect=this.getBoundingClientRect();
left=rect.left;
top=rect.top;
}
else{
left=this.offsetLeft;
top=this.offsetTop;
}
game.animate.flame(left+this.offsetWidth/2,
top+this.offsetHeight-20,700,'fire');
2015-09-25 00:26:16 +00:00
},
$thunder:function(){
2015-11-04 01:59:00 +00:00
game.addVideo('flame',this,'thunder');
2015-09-30 07:24:45 +00:00
var left,top;
if(lib.config.mode=='chess'){
var rect=this.getBoundingClientRect();
left=rect.left;
top=rect.top;
}
else{
left=this.offsetLeft;
top=this.offsetTop;
}
game.animate.flame(left+this.offsetWidth/2,
top+this.offsetHeight-30,700,'thunder');
2015-09-25 00:26:16 +00:00
},
2015-11-09 03:15:16 +00:00
$rare2:function(){
game.addVideo('flame',this,'rare2');
var rect=this.getBoundingClientRect();
var left=rect.left;
var top=rect.top+15;
game.animate.flame(left+this.offsetWidth/2,
top+this.offsetHeight-30,700,'rare');
},
$epic2:function(){
game.addVideo('flame',this,'epic2');
var rect=this.getBoundingClientRect();
var left=rect.left;
var top=rect.top+15;
game.animate.flame(left+this.offsetWidth/2,
top+this.offsetHeight-30,700,'epic');
},
$legend2:function(){
game.addVideo('flame',this,'legend2');
var rect=this.getBoundingClientRect();
var left=rect.left;
var top=rect.top+15;
game.animate.flame(left+this.offsetWidth/2,
top+this.offsetHeight-30,700,'legend');
},
2015-10-20 17:44:00 +00:00
$rare:function(){
2015-11-04 01:59:00 +00:00
game.addVideo('flame',this,'rare');
2015-11-07 09:20:15 +00:00
var left,top;
if(lib.config.mode=='chess'){
left=this.offsetLeft-ui.arena.offsetLeft;
top=this.offsetTop-ui.arena.offsetTop;
}
else{
left=this.offsetLeft;
top=this.offsetTop;
}
2015-10-20 17:44:00 +00:00
if(this.classList.contains('minskin')){
top+=15;
}
game.animate.flame(left+this.offsetWidth/2,
top+this.offsetHeight-30,700,'rare');
},
$epic:function(){
2015-11-04 01:59:00 +00:00
game.addVideo('flame',this,'epic');
2015-11-07 09:20:15 +00:00
var left,top;
if(lib.config.mode=='chess'){
left=this.offsetLeft-ui.arena.offsetLeft;
top=this.offsetTop-ui.arena.offsetTop;
}
else{
left=this.offsetLeft;
top=this.offsetTop;
}
2015-10-20 17:44:00 +00:00
if(this.classList.contains('minskin')){
top+=15;
}
game.animate.flame(left+this.offsetWidth/2,
top+this.offsetHeight-30,700,'epic');
},
$legend:function(){
2015-11-04 01:59:00 +00:00
game.addVideo('flame',this,'legend');
2015-11-07 09:20:15 +00:00
var left,top;
if(lib.config.mode=='chess'){
left=this.offsetLeft-ui.arena.offsetLeft;
top=this.offsetTop-ui.arena.offsetTop;
}
else{
left=this.offsetLeft;
top=this.offsetTop;
}
2015-10-20 17:44:00 +00:00
if(this.classList.contains('minskin')){
top+=15;
}
game.animate.flame(left+this.offsetWidth/2,
top+this.offsetHeight-30,700,'legend');
},
$coin:function(){
2015-11-04 01:59:00 +00:00
game.addVideo('flame',this,'coin');
2015-10-20 17:44:00 +00:00
var left=this.offsetLeft-ui.arena.offsetLeft;
var top=this.offsetTop-ui.arena.offsetTop;
if(this.classList.contains('minskin')){
top+=15;
}
top-=25;
game.animate.flame(left+this.offsetWidth/2,
top+this.offsetHeight-30,700,'coin');
},
$dust:function(){
2015-11-04 01:59:00 +00:00
game.addVideo('flame',this,'dust');
2015-10-20 17:44:00 +00:00
var left=this.offsetLeft-ui.arena.offsetLeft;
var top=this.offsetTop-ui.arena.offsetTop;
if(this.classList.contains('minskin')){
top+=15;
}
top-=25;
game.animate.flame(left+this.offsetWidth/2,
top+this.offsetHeight-30,700,'dust');
},
2015-09-26 13:11:55 +00:00
$recover:function(){
2015-11-04 01:59:00 +00:00
game.addVideo('flame',this,'recover');
2015-09-30 07:24:45 +00:00
var left,top;
if(lib.config.mode=='chess'){
var rect=this.getBoundingClientRect();
left=rect.left;
top=rect.top;
}
else{
left=this.offsetLeft;
top=this.offsetTop;
}
game.animate.flame(left+this.offsetWidth/2,
top+this.offsetHeight-30,700,'recover');
2015-09-26 13:11:55 +00:00
},
2015-11-06 10:05:08 +00:00
$sha:function(nature){
if(this._shaing){
return;
}
this._shaing=true;
var player=this;
setTimeout(function(){
player._shaing=false;
},1000);
var node=ui.create.div('.cardeffect',this);
node.innerHTML='殺';
node.dataset.nature=nature||'black';
return node;
},
2015-09-26 13:11:55 +00:00
$damagepop:function(num,nature){
if(typeof num=='number'){
2015-11-04 01:59:00 +00:00
game.addVideo('damagepop',this,[num,nature]);
2015-09-26 13:11:55 +00:00
var node=ui.create.div('.damage');
if(num>0){
num='+'+num;
}
node.innerHTML=num;
this.damagepopups.push(node);
node.dataset.nature=nature||'soil';
if(this.damagepopups.length==1){
this.$damagepop();
}
}
else if(this.damagepopups.length){
var node=this.damagepopups[0];
this.appendChild(node);
ui.refresh(node);
node.classList.add('damageadded');
2015-11-29 11:46:51 +00:00
node.addEventListener('webkitTransitionEnd',function(){
setTimeout(function(){
node.delete();
},200);
});
// setTimeout(function(){
// node.delete();
// },500);
2015-09-26 13:11:55 +00:00
var that=this;
setTimeout(function(){
that.damagepopups.shift();
that.$damagepop();
},500);
}
},
2015-04-29 03:25:17 +00:00
$damage:function(source){
2015-11-04 01:59:00 +00:00
if(get.itemtype(source)=='player'){
game.addVideo('damage',this,source.dataset.position);
}
else{
game.addVideo('damage',this);
}
2015-11-18 03:39:14 +00:00
if(source&&source!=this&&lib.config.damage_shake){
2015-04-29 03:25:17 +00:00
var left,top;
if(source.offsetTop==this.offsetTop){
left=20;
top=0;
}
else{
var ratio=(source.offsetLeft-this.offsetLeft)/(source.offsetTop-this.offsetTop);
left=Math.abs(20*ratio/Math.sqrt(1+ratio*ratio));
top=Math.abs(20/Math.sqrt(1+ratio*ratio));
}
if(source.offsetLeft-this.offsetLeft>0) left=-left;
if(source.offsetTop-this.offsetTop>0) top=-top;
2015-10-31 10:14:14 +00:00
if(lib.isMobileMe(this)){
if(this.isLinked()){
2015-11-05 02:34:35 +00:00
this.node.avatar.style.transform='translate('+left+'px,'+top+'px) rotate(-90deg)';
this.node.avatar2.style.transform='translate('+left+'px,'+top+'px) rotate(-90deg)';
2015-10-31 10:14:14 +00:00
}
else{
2015-11-05 02:34:35 +00:00
this.node.avatar.style.transform='translate('+left+'px,'+top+'px)';
this.node.avatar2.style.transform='translate('+left+'px,'+top+'px)';
2015-10-31 10:14:14 +00:00
}
}
else if(this.isLinked()&&lib.isNewLayout()){
2015-11-05 02:34:35 +00:00
this.style.transform='translate('+left+'px,'+top+'px) rotate(-90deg)';
2015-04-29 03:25:17 +00:00
}
else{
2015-11-05 02:34:35 +00:00
this.style.transform='translate('+left+'px,'+top+'px)';
2015-04-29 03:25:17 +00:00
}
}
else{
2015-11-21 05:30:26 +00:00
var zoom1=0.9,zoom2=0.95;
if(arguments[1]=='phase'){
zoom1=1.05;
zoom2=1.05;
}
2015-10-31 10:14:14 +00:00
if(lib.isMobileMe(this)){
if(this.isLinked()){
2015-11-21 05:30:26 +00:00
this.node.avatar.style.transform='scale('+zoom1+') rotate(-90deg)';
this.node.avatar2.style.transform='scale('+zoom1+') rotate(-90deg)';
2015-10-31 10:14:14 +00:00
}
else{
2015-11-21 05:30:26 +00:00
this.node.avatar.style.transform='scale('+zoom1+')';
this.node.avatar2.style.transform='scale('+zoom1+')';
2015-10-31 10:14:14 +00:00
}
}
else if(this.isLinked()&&lib.isNewLayout()){
2015-11-21 05:30:26 +00:00
this.style.transform='scale('+zoom2+') rotate(-90deg)';
2015-04-29 03:25:17 +00:00
}
else{
2015-11-21 05:30:26 +00:00
this.style.transform='scale('+zoom2+')';
2015-04-29 03:25:17 +00:00
}
}
this.queue();
},
$die:function(){
2015-11-04 01:59:00 +00:00
game.addVideo('die',this);
2015-11-26 08:15:28 +00:00
if(lib.config.die_flip){
var top0=ui.window.offsetHeight/2;
var left0=ui.window.offsetWidth/2;
var ratio=(left0-this.offsetLeft)/(top0-this.offsetTop);
var left=Math.abs(50*ratio/Math.sqrt(1+ratio*ratio));
var top=Math.abs(50/Math.sqrt(1+ratio*ratio));
if(left0-this.offsetLeft>0) left=-left;
if(top0-this.offsetTop>0) top=-top;
if(lib.isMobileMe(this)){
left=-Math.random()*5-10;
top=Math.random()*5+10;
}
var transform='translate('+left+'px,'+top+'px) '+
'rotate('+(Math.random()*20-10)+'deg) '+
((Math.random()-0.5<0)?'rotateX(180deg)':'rotateY(180deg)');
if(lib.isMobileMe(this)){
this.node.avatar.style.transform=transform;
this.node.avatar2.style.transform=transform;
}
else{
this.style.transform=transform;
}
this.queue(false);
2015-11-05 02:34:35 +00:00
}
2015-04-29 03:25:17 +00:00
},
2015-05-08 08:07:38 +00:00
$phaseJudge:function(card){
2015-11-04 01:59:00 +00:00
game.addVideo('phaseJudge',this,get.cardInfo(card));
2015-05-08 08:07:38 +00:00
var player=this;
2015-11-23 10:59:44 +00:00
var clone;
// var clone=card.copy('thrown','thrownhighlight',ui.arena);
2015-11-30 13:08:29 +00:00
if(true){
2015-11-23 10:59:44 +00:00
clone=player.$throw(card);
}
else{
clone=card.copy('thrown','thrownhighlight',ui.arena).animate('judgestart');
clone.style.opacity=0.6;
clone.style.left='calc(50% - 52px '+((Math.random()-0.5<0)?'+':'-')+' '+Math.random()*50+'px)';
clone.style.top='calc(50% - 52px '+((Math.random()-0.5<0)?'+':'-')+' '+Math.random()*40+'px)';
game.linexy([
clone.offsetLeft+clone.offsetWidth/2,
clone.offsetTop+clone.offsetHeight/2,
player.offsetLeft+player.offsetWidth/2,
player.offsetTop+player.offsetHeight/2
],{opacity:0.5,dashed:true});
}
2015-05-08 08:07:38 +00:00
game.delay();
2015-11-23 10:59:44 +00:00
2015-05-08 08:07:38 +00:00
}
2015-04-29 03:25:17 +00:00
},
card:{
init:function(card){
var bg=card[2];
if(!lib.config.hide_card_image&&lib.card[card[2]].fullskin){
this.classList.add('fullskin');
this.node.image.style.backgroundImage='url("image/card/'+card[2]+'.png")'
}
else if(lib.card[card[2]].image=='background'){
if(card[3]) this.node.background.setBackground(bg+'_'+card[3],'card');
else this.node.background.setBackground(bg,'card');
}
else if(lib.card[card[2]].image=='card'){
if(card[3]) this.setBackground(bg+'_'+card[3],'card');
else this.setBackground(bg,'card');
}
else if(typeof lib.card[card[2]].image=='string'){
this.setBackground(lib.card[card[2]].image);
}
else{
this.node.background.innerHTML=lib.translate[bg+'_bg']||get.translation(bg)[0];
// this.node.background.style.fontFamily=lib.config.card_font;
if(this.node.background.innerHTML.length>1) this.node.background.classList.add('tight');
else this.node.background.classList.remove('tight');
}
2015-09-22 03:53:35 +00:00
if(lib.card[card[2]].noname){
this.node.name.style.display='none';
}
2015-04-29 03:25:17 +00:00
if(lib.card[card[2]].color){
this.style.color=lib.card[card[2]].color;
}
if(lib.card[card[2]].textShadow){
this.style.textShadow=lib.card[card[2]].textShadow;
}
if(lib.card[card[2]].opacity){
this.node.info.style.opacity=lib.card[card[2]].opacity;
this.node.name.style.opacity=lib.card[card[2]].opacity;
}
2015-05-04 14:27:10 +00:00
if(lib.card[card[2]].modinfo){
this.node.info.innerHTML=lib.card[card[2]].modinfo;
}
else{
2015-12-06 15:23:47 +00:00
this.node.info.innerHTML=get.translation(card[0])+'<span> </span>'+card[1];
2015-05-04 14:27:10 +00:00
}
if(lib.card[card[2]].addinfo){
this.node.addinfo=ui.create.div('.addinfo',this);
this.node.addinfo.innerHTML=lib.card[card[2]].addinfo;
}
2015-04-29 03:25:17 +00:00
if(card[0]=='heart'||card[0]=='diamond'){
this.node.info.classList.add('red');
}
this.node.name.innerHTML='';
var name=get.translation(card[2]);
if(card[2]=='sha'){
if(card[3]=='fire'){
name='火'+name;
this.node.image.classList.add('fire');
}
else if(card[3]=='thunder'){
name='雷'+name;
this.node.image.classList.add('thunder');
}
}
for(var i=0;i<name.length;i++){
this.node.name.innerHTML+=name[i]+'<br/>';
}
2015-11-30 13:08:29 +00:00
// if(lib.card[card[2]].subtype=='equip3'){
// this.node.name.innerHTML+='+';
// }
// else if(lib.card[card[2]].subtype=='equip4'){
// this.node.name.innerHTML+='-';
// }
2015-04-29 03:25:17 +00:00
this.node.name2.innerHTML=get.translation(card[0])+card[1]+' '+name;
this.suit=card[0];
this.number=card[1];
this.name=card[2];
this.classList.add('card');
if(card[3]){
if(lib.nature.contains(card[3])) this.nature=card[3];
this.classList.add(card[3]);
}
if(lib.card[card[2]].subtype) this.classList.add(lib.card[card[2]].subtype);
if(this.inits){
for(var i=0;i<lib.element.card.inits.length;i++){
lib.element.card.inits[i](this);
}
}
if(typeof lib.card[card[2]].init=='function') lib.card[card[2]].init();
2015-11-30 13:08:29 +00:00
switch(get.subtype(this)){
case 'equip1':
var added=false;
if(lib.card[this.name]&&lib.card[this.name].distance){
var dist=lib.card[this.name].distance;
if(dist.attackFrom){
added=true;
this.node.range.innerHTML='范围: '+(-dist.attackFrom+1);
}
}
if(!added){
this.node.range.innerHTML='范围: 1';
}
break;
case 'equip3':this.node.range.innerHTML='防御: 1';break;
case 'equip4':this.node.range.innerHTML='进攻: 1';break;
}
2015-04-29 03:25:17 +00:00
return this;
},
aiexclude:function(){
_status.event.aiexclude.add(this);
},
2015-11-23 10:59:44 +00:00
moveDelete:function(player){
2015-12-08 13:54:44 +00:00
this.fixed=true;
2015-11-23 10:59:44 +00:00
if(!this._listeningEnd||this._transitionEnded){
this.moveTo(player).delete();
}
else{
this._onEndMoveDelete=player;
}
},
2015-04-29 03:25:17 +00:00
moveTo:function(player,method){
this.fixed=true;
2015-11-23 10:59:44 +00:00
var dx,dy;
if(this.classList.contains('center')){
var nx=[50,-52];
var ny=[50,-52];
nx=nx[0]*ui.arena.offsetWidth/100+nx[1];
ny=ny[0]*ui.arena.offsetHeight/100+ny[1];
dx=player.offsetLeft+player.offsetWidth/2-52-nx;
dy=player.offsetTop+player.offsetHeight/2-52-ny;
}
else{
this.style.left=this.offsetLeft+'px';
this.style.top=this.offsetTop+'px';
dx=player.offsetLeft+player.offsetWidth/2-52-this.offsetLeft;
dy=player.offsetTop+player.offsetHeight/2-52-this.offsetTop;
}
2015-11-14 05:29:22 +00:00
2015-11-21 05:30:26 +00:00
if(this.style.transform&&this.style.transform!='none'&&this.style.transform.indexOf('translate')==-1){
2015-11-15 05:54:58 +00:00
this.style.transform+=' translate('+dx+'px,'+dy+'px)';
}
else{
this.style.transform='translate('+dx+'px,'+dy+'px)';
}
2015-11-14 05:29:22 +00:00
// this.dataset.position=player.dataset.position;
2015-11-18 03:39:14 +00:00
// if(method=='flip'){
// this.style.transition='all 0.5s';
// this.style.transform='rotate'+(Math.random()<0.5?'X':'Y')+'(180deg) perspective(1000px)';
// }
// else if(method=='rotate'){
// this.style.transition='all 0.5s';
// this.style.transform='rotate(180deg)';
// }
2015-04-29 03:25:17 +00:00
return this;
},
copy:function(){
var node=this.cloneNode(true);
2015-11-24 00:50:54 +00:00
node.style.transform='';
2015-11-04 01:59:00 +00:00
node.name=this.name;
node.suit=this.suit;
node.number=this.number;
2015-04-29 03:25:17 +00:00
node.classList.remove('hidden');
node.classList.remove('start');
node.classList.remove('thrown');
node.classList.remove('selectable');
node.classList.remove('selected');
node.classList.remove('removing');
2015-11-24 15:44:21 +00:00
node.classList.remove('drawinghidden');
2015-04-29 03:25:17 +00:00
node.node={
name:node.querySelector('.name'),
info:node.querySelector('.info'),
intro:node.querySelector('.intro'),
background:node.querySelector('.background'),
image:node.querySelector('.image'),
}
var clone=true;
var position;
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='string') node.classList.add(arguments[i]);
else if(get.objtype(arguments[i])=='div') position=arguments[i];
else if(typeof arguments[i]=='boolean') clone=arguments[i];
}
node.moveTo=lib.element.card.moveTo;
2015-11-23 10:59:44 +00:00
node.moveDelete=lib.element.card.moveDelete;
2015-04-29 03:25:17 +00:00
if(clone) this.clone=node;
if(position) position.appendChild(node);
return node;
}
},
button:{
exclude:function(){
if(_status.event.excludeButton==undefined){
_status.event.excludeButton=[];
}
_status.event.excludeButton.add(this);
}
},
event:{
finish:function(){
this.finished=true;
},
goto:function(step){
this.step=step-1;
},
redo:function(){
this.step--;
},
backup:function(skill){
this._backup={
filterButton:this.filterButton,
selectButton:this.selectButton,
filterTarget:this.filterTarget,
selectTarget:this.selectTarget,
filterCard:this.filterCard,
selectCard:this.selectCard,
position:this.position,
forced:this.forced,
aiexclude:this.aiexclude
}
if(skill){
var info=get.info(skill);
this.skill=skill;
this.aiexclude=[];
if(info.viewAs){
if(info.filterButton!=undefined) this.filterButton=get.filter(info.filterButton);
if(info.selectButton!=undefined) this.selectButton=info.selectButton;
if(info.filterTarget!=undefined) this.filterTarget=get.filter(info.filterTarget);
if(info.selectTarget!=undefined) this.selectTarget=info.selectTarget;
if(info.filterCard!=undefined) this.filterCard=get.filter(info.filterCard);
if(info.selectCard!=undefined) this.selectCard=info.selectCard;
if(info.position!=undefined) this.position=info.position;
if(info.forced!=undefined) this.forced=info.forced;
}
else{
this.filterButton=info.filterButton?get.filter(info.filterButton):undefined;
this.selectButton=info.selectButton;
this.filterTarget=info.filterTarget?get.filter(info.filterTarget):undefined;
this.selectTarget=info.selectTarget;
this.filterCard=info.filterCard?get.filter(info.filterCard):undefined;
this.selectCard=info.selectCard;
this.position=info.position;
this.forced=info.forced;
}
}
},
restore:function(){
if(this._backup){
this.filterButton=this._backup.filterButton;
this.selectButton=this._backup.selectButton;
this.filterTarget=this._backup.filterTarget;
this.selectTarget=this._backup.selectTarget;
this.filterCard=this._backup.filterCard;
this.selectCard=this._backup.selectCard;
this.position=this._backup.position;
this.forced=this._backup.forced;
this.aiexclude=this._backup.aiexclude;
}
delete this.skill;
},
isMine:function(){
2015-05-13 10:26:54 +00:00
return (this.player&&this.player==game.me&&!_status.auto&&!this.player.isMad());
2015-04-29 03:25:17 +00:00
},
trigger:function(name){
2015-11-04 01:59:00 +00:00
if(_status.video) return;
2015-04-29 03:25:17 +00:00
var event=this;
2015-05-04 03:17:03 +00:00
var i,j,iwhile,next,add;
var totalPopulation=game.players.length+game.dead.length+1;
2015-04-29 03:25:17 +00:00
if(event.player&&event.player.removed) return;
if(!event.player&&name!='gameStart') return;
event._endTrigger=event.player||game.me;
2015-05-12 09:51:40 +00:00
if(!game.players.contains(event._endTrigger)){
event._endTrigger=game.findNext(event._endTrigger);
2015-04-29 03:25:17 +00:00
}
2015-05-12 09:51:40 +00:00
2015-04-29 03:25:17 +00:00
var player=event._endTrigger;
var list=[],others=[];
for(i=0;i<game.players.length;i++){
for(j in game.players[i].tempSkills){
var expire=game.players[i].tempSkills[j];
if(expire==name||
(get.objtype(expire)=='array'&&expire.contains(name))||
(typeof expire=='function'&&expire(event,game.players[i],name))){
delete game.players[i].tempSkills[j];
game.players[i].removeSkill(j);
}
else if(typeof expire=='object'){
if(expire.player==name&&event.player==game.players[i]||
expire.target==name&&event.target==game.players[i]||
expire.source==name&&event.source==game.players[i]){
delete game.players[i].tempSkills[j];
game.players[i].removeSkill(j);
}
}
}
}
2015-05-04 03:17:03 +00:00
for(iwhile=0;iwhile<totalPopulation;iwhile++){
2015-04-29 03:25:17 +00:00
var skills=player.get('s',true).concat(lib.skill.global);
game.expandSkills(skills);
for(i=0;i<skills.length;i++){
var trigger=get.info(skills[i]).trigger;
if(trigger){
add=false;
if(player==event.player&&trigger.player){
if(typeof trigger.player=='string'){
if(trigger.player==name) add=true;
}
else if(trigger.player.contains(name)) add=true;
}
if((player==event.target||
(event.multitarget&&event.targets&&event.targets.contains(player)))&&
trigger.target){
if(typeof trigger.target=='string'){
if(trigger.target==name) add=true;
}
else if(trigger.target.contains(name)) add=true;
}
if(player==event.source&&trigger.source){
if(typeof trigger.source=='string'){
if(trigger.source==name) add=true;
}
else if(trigger.source.contains(name)) add=true;
}
if(trigger.global){
if(typeof trigger.global=='string'){
if(trigger.global==name) add=true;
}
else if(trigger.global.contains(name)) add=true;
}
if(add&&player.isOut()==false) list.push([skills[i],player]);
}
}
player=player.next;
2015-05-12 09:51:40 +00:00
if(!player||player==event._endTrigger){
2015-05-04 03:17:03 +00:00
break;
}
2015-04-29 03:25:17 +00:00
}
if(list.length){
list.sort(lib.sort.priority);
for(i=0;i<list.length;i++){
if(list[i][1].isOut()||list[i][1].isDead()||list[i][1].removed) continue;
var next=game.createEvent('trigger',false);
next.skill=list[i][0];
next.player=list[i][1];
next.triggername=name;
next._trigger=event;
next.content=function(){
"step 0"
var info=get.info(event.skill);
if(info.filter&&!info.filter(trigger,player,event.triggername)){
event.finish();
}
2015-12-12 08:37:15 +00:00
else if(event._trigger.notrigger.contains(player)&&!lib.skill.global.contains(event.skill)){
event.finish();
}
2015-04-29 03:25:17 +00:00
else{
var hidden=player.hiddenSkills.slice(0);
game.expandSkills(hidden);
if(hidden.contains(event.skill)&&!get.info(event.skill).direct){
event.trigger('triggerHidden');
}
}
"step 1"
if(event.cancelled){
event.finish();
}
else{
event.trigger('triggerBefore');
}
"step 2"
if(event.cancelled){
event.finish();
return;
}
if(!event.revealed&&!get.info(event.skill).forced){
2015-05-01 09:34:01 +00:00
if(get.info(event.skill).direct&&player.isUnderControl()){
game.modeSwapPlayer(player);
2015-04-29 03:25:17 +00:00
event._result={bool:true};
}
else if(get.info(event.skill).frequent&&!lib.config.autoskilllist.contains(event.skill)){
event._result={bool:true};
}
else if(get.info(event.skill).direct&&player==game.me&&!_status.auto){
event._result={bool:true};
}
else{
var str;
var check=get.info(event.skill).check;
if(get.info(event.skill).prompt) str=get.info(event.skill).prompt;
else str='是否发动【'+get.translation(event.skill)+'】?';
if(typeof str=='function'){str=str(trigger,player)}
player.chooseBool(str).ai=function(){
return !check||check(trigger,player);
};
}
}
"step 3"
if(result&&result.bool==false) return;
var info=get.info(event.skill);
var next=game.createEvent(event.skill);
next.player=player;
next._trigger=trigger;
next.content=info.content;
if(info.popup!=false&&!info.direct){
if(info.popup){
player.popup(info.popup);
2015-12-09 05:52:03 +00:00
game.log(player,'发动了','【'+get.translation(event.skill)+'】');
2015-04-29 03:25:17 +00:00
}
else{
player.logSkill(event.skill);
}
}
}
}
}
},
2015-12-12 08:37:15 +00:00
untrigger:function(all,player){
2015-04-29 03:25:17 +00:00
if(all){
this.next.length=0;
this._triggered=5;
}
2015-12-12 08:37:15 +00:00
else if(player){
this.notrigger.add(player);
for(var i=0;i<this.next.length;i++){
if(this.next[i].player==player) this.next.splice(i--,1);
}
}
2015-04-29 03:25:17 +00:00
else{
for(var i=0;i<this.next.length;i++){
2015-12-12 08:37:15 +00:00
if(this.next[i]._trigger==this) this.next.splice(i--,1);
2015-04-29 03:25:17 +00:00
}
}
}
},
dialog:{
add:function(item,noclick,zoom){
if(typeof item=='string'){
if(noclick){
var strstr=item;
item=ui.create.div('',this.content);
item.innerHTML=strstr;
}
else{
item=ui.create.caption(item,this.content);
}
}
else if(get.objtype(item)=='div'){
this.content.appendChild(item);
}
else if(get.itemtype(item)=='cards'){
var buttons=ui.create.div('.buttons',this.content);
if(zoom) buttons.classList.add('smallzoom');
this.buttons=this.buttons.concat(ui.create.buttons(item,'card',buttons,noclick));
}
else if(get.itemtype(item)=='players'){
var buttons=ui.create.div('.buttons',this.content);
if(zoom) buttons.classList.add('smallzoom');
this.buttons=this.buttons.concat(ui.create.buttons(item,'player',buttons,noclick));
}
else{
var buttons=ui.create.div('.buttons',this.content);
if(zoom) buttons.classList.add('smallzoom');
2015-05-02 09:54:39 +00:00
this.buttons=this.buttons.concat(ui.create.buttons(item[0],item[1],buttons,noclick));
2015-04-29 03:25:17 +00:00
}
ui.update();
return item;
},
addSmall:function(item,noclick){
return this.add(item,noclick,true);
},
open:function(){
2015-05-12 09:51:40 +00:00
if(this.noopen) return;
2015-04-29 03:25:17 +00:00
for(var i=0;i<ui.dialogs.length;i++){
2015-04-29 10:02:31 +00:00
if(ui.dialogs[i]==this){
this.show();
this.refocus();
ui.dialogs.remove(this);
ui.dialogs.unshift(this);
ui.update();
return this;
}
2015-04-29 03:25:17 +00:00
if(ui.dialogs[i].static) ui.dialogs[i].unfocus();
else ui.dialogs[i].hide();
}
ui.dialog=this;
ui.arena.appendChild(this);
ui.dialogs.unshift(this);
ui.update();
return this;
},
close:function(){
ui.dialogs.remove(this);
this.delete();
if(ui.dialogs.length>0){
ui.dialog=ui.dialogs[0];
ui.dialog.show();
ui.dialog.refocus();
ui.update();
}
2015-12-08 13:54:44 +00:00
// if(ui.arenalog){
// ui.arenalog.classList.remove('withdialog');
// }
2015-04-29 03:25:17 +00:00
return this;
},
setCaption:function(str){
this.querySelector('.caption').innerHTML=str;
return this;
}
},
control:{
add:function(item){
var node=document.createElement('div');
this.appendChild(node);
node.link=item;
node.innerHTML=get.translation(item);
node.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.control);
2015-11-14 15:48:04 +00:00
if(lib.config.button_press){
node.addEventListener(lib.config.touchscreen?'touchstart':'mousedown',function(e){
node.classList.add('controlthundertext');
node.parentNode.classList.add('controlpressdown');
2015-11-15 05:54:58 +00:00
node.parentNode.classList.add('controlpressdownx');
2015-11-14 15:48:04 +00:00
});
node.addEventListener(lib.config.touchscreen?'touchend':'mouseup',function(e){
node.classList.remove('controlthundertext');
node.parentNode.classList.remove('controlpressdown');
2015-11-16 01:59:54 +00:00
node.parentNode.classList.remove('controlpressdownx');
// setTimeout(function(){
// if(node.parentNode)
// },200);
2015-11-14 15:48:04 +00:00
});
node.addEventListener(lib.config.touchscreen?'touchmove':'mousemove',function(e){
node.classList.remove('controlthundertext');
node.parentNode.classList.remove('controlpressdown');
2015-11-16 01:59:54 +00:00
node.parentNode.classList.remove('controlpressdownx');
2015-11-14 15:48:04 +00:00
});
}
2015-04-29 03:25:17 +00:00
},
close:function(){
ui.controls.remove(this);
2015-11-23 10:59:44 +00:00
this.delete();
2015-11-15 05:54:58 +00:00
2015-11-30 13:08:29 +00:00
setTimeout(ui.updatec,100);
2015-11-15 05:54:58 +00:00
2015-04-29 03:25:17 +00:00
if(ui.confirm==this) delete ui.confirm;
if(ui.skills==this) delete ui.skills;
2015-11-30 13:08:29 +00:00
if(ui.skills2==this) delete ui.skills2;
if(ui.skills3==this) delete ui.skills3;
2015-04-29 03:25:17 +00:00
},
replace:function(){
2015-05-04 03:17:03 +00:00
while(this.childNodes.length) this.firstChild.remove();
2015-04-29 03:25:17 +00:00
var i,controls;
if(get.objtype(arguments[0])=='array') controls=arguments[0];
else controls=arguments;
delete this.custom;
for(i=0;i<controls.length;i++){
if(typeof controls[i]=='function'){
this.custom=controls[i];
}
else{
this.add(controls[i]);
}
}
if(this.childNodes.length){
var width=0;
for(i=0;i<this.childNodes.length;i++) width+=this.childNodes[i].offsetWidth;
2015-10-13 11:15:02 +00:00
ui.refresh(this);
2015-04-29 03:25:17 +00:00
this.style.width=width+'px';
2015-10-13 11:15:02 +00:00
var that=this;
2015-04-29 03:25:17 +00:00
}
2015-11-24 15:44:21 +00:00
ui.updatec();
2015-04-29 03:25:17 +00:00
return this;
}
},
},
card:{
list:[],
},
filter:{
all:function(){
return true;
},
buttonIncluded:function(button){
return !(_status.event.excludeButton&&_status.event.excludeButton.contains(button));
},
filterButton:function(button){
return true;
},
cardEnabled:function(card,player,event){
if(player==undefined) player=_status.event.player;
var filter=get.info(card).enable;
if(!filter) return;
var mod=game.checkMod(card,player,'unchanged','cardEnabled',player.get('s'));
if(mod!='unchanged') return mod;
if(typeof filter=='boolean') return filter;
if(typeof filter=='function') return filter(card,player);
},
cardRespondable:function(card,player){
if(_status.event.name!='chooseToRespond') return true;
if(player==undefined) player=_status.event.player;
var mod=game.checkMod(card,player,'unchanged','cardRespondable',player.get('s'));
if(mod!='unchanged') return mod;
return true;
},
cardUsable:function(card,player,event){
if(player!=_status.event.player) return true;
event=event||_status.event;
if(event.parent.name!='phaseUse') return true;
if(event.parent.player!=player) return true;
var num=get.info(card).usable;
if(typeof num=='function') num=num(card,player);
num=game.checkMod(card,player,num,'cardUsable',player.get('s'));
if(typeof num!='number') return true;
else return(get.cardCount(card,player)<num);
},
cardAiIncluded:function(card){
if(_status.event.isMine()) return true;
return (_status.event.aiexclude.contains(card)==false);
},
filterCard:function(card,player,event){
return (lib.filter.cardEnabled(card,player,event)&&
lib.filter.cardUsable(card,player,event));
},
targetEnabled:function(card,player,target){
if(card==undefined) return false;
var filter=get.info(card).filterTarget;
var mod=game.checkMod(card,player,target,'unchanged','playerEnabled',player.get('s'));
if(mod==false) return false;
var mod=game.checkMod(card,player,target,'unchanged','targetEnabled',target.get('s'));
if(mod!='unchanged') return mod;
if(typeof filter=='boolean') return filter;
if(typeof filter=='function') return filter(card,player,target);
},
targetInRange:function(card,player,target){
var mod=game.checkMod(card,player,target,'unchanged','targetInRange',player.get('s'));
var extra=0;
if(mod!='unchanged'){
if(typeof mod=='boolean') return mod;
if(typeof mod=='number') extra=mod;
}
var range=get.info(card).range;
if(range==undefined) return true;
for(var i in range){
if(range[i]<get.distance(player,target,i)+extra) return false;
}
return true;
},
filterTarget:function(card,player,target){
return (lib.filter.targetEnabled(card,player,target)&&
lib.filter.targetInRange(card,player,target));
},
notMe:function(card,player,target){
return (player!=target)
},
isMe:function(card,player,target){
return (player==target)
},
selectCard:function(){
return [1,1];
},
selectTarget:function(){
var card=get.card(),player=get.player();
if(card==undefined) return;
var range;
var select=get.info(card).selectTarget;
if(select==undefined){
if(get.info(card).filterTarget==undefined) return[0,0];
range=[1,1];
}
else if(typeof select=='number') range=[select,select];
else if(get.itemtype(select)=='select') range=select;
else if(typeof select=='function') range=select(card,player);
game.checkMod(card,player,range,'selectTarget',player.get('s'));
return range;
},
judge:function(card,player,target){
var judges=target.get('j');
for(var i=0;i<judges.length;i++){
if(judges[i].name==card.name||judges[i].viewAs==card.name) return false;
}
return true;
},
autoRespondSha:function(){
if(this.player.num('h','sha')) return false;
if(this.player.num('h','hufu')) return false;
if(this.player.hasSkillTag('respondSha',true)) return false;
return true;
},
autoRespondShan:function(){
if(this.player.num('h','shan')) return false;
if(this.player.num('h','hufu')) return false;
if(this.player.hasSkillTag('respondShan',true)) return false;
return true;
},
},
sort:{
random:function(){
return (Math.random()-0.5);
},
seat:function(a,b){
var player=lib.tempSortSeat||_status.event.player;
2015-05-04 03:17:03 +00:00
var delta=get.distance(player,a,'absolute')-get.distance(player,b,'absolute');
if(delta) return delta;
delta=parseInt(a.dataset.position)-parseInt(b.dataset.position);
if(player.side==game.me.side) return delta;
return -delta;
2015-04-29 03:25:17 +00:00
},
position:function(a,b){
return parseInt(a.dataset.position)-parseInt(b.dataset.position);
},
priority:function(a,b){
var i1=get.info(a[0]),i2=get.info(b[0]);
if(i1.priority==undefined) i1.priority=0;
if(i2.priority==undefined) i2.priority=0;
if(i1.priority==i2.priority){
if(i1.forced==undefined&&i2.forced==undefined) return 0;
if(i1.forced&&i2.forced) return 0;
if(i1.forced) return 1;
if(i2.forced) return -1;
}
return i2.priority-i1.priority;
},
number:function(a,b){
return get.number(a)-get.number(b);
},
number2:function(a,b){
return get.number(b)-get.number(a);
},
},
skill:{
global:[],
storage:{},
unequip:{},
2015-05-13 10:26:54 +00:00
mad:{
mark:true,
intro:{
content:'已进入混乱状态',
name:'混乱'
}
},
2015-06-27 16:21:25 +00:00
ghujia:{
intro:{
content:function(content,player){
2015-12-06 15:23:47 +00:00
return '已有'+get.cnNumber(player.hujia)+'点护甲值<p>每点护甲可以抵挡一点伤害</p>';
2015-06-27 16:21:25 +00:00
}
}
},
2015-04-29 03:25:17 +00:00
_recoverCheck:{
trigger:{player:'recoverBefore'},
forced:true,
priority:20,
popup:false,
filter:function(event,player){
return player.hp>=player.maxHp;
},
content:function(){
trigger.untrigger();
trigger.finish();
},
},
_turnover:{
trigger:{player:'phaseBefore'},
forced:true,
priority:20,
popup:false,
// filter:function(event,player){
// return player.isTurnedOver();
// },
content:function(){
if(player.isTurnedOver()){
trigger.untrigger();
trigger.finish();
player.turnOver();
player.phaseSkipped=true;
}
else{
player.phaseSkipped=false;
}
},
},
_out:{
trigger:{target:'useCardToBefore',player:['damageBefore','phaseBefore']},
forced:true,
popup:false,
priority:20,
filter:function(event,player){
return player.isOut();
},
content:function(){
trigger.untrigger();
trigger.finish();
},
ai:{
effect:{
target:function(card,player,target){
if(target.isOut()) return 0;
}
},
threaten:function(player,target){
if(target.isOut()) return 0;
}
}
},
_phasebegin:{
trigger:{player:'phaseBegin'},
forced:true,
priority:20,
popup:false,
content:function(){
player.popup('_phasebegin');
2015-11-06 10:05:08 +00:00
if(lib.config.glow_phase){
if(_status.currentPhase){
_status.currentPhase.classList.remove('glow_phase');
}
player.classList.add('glow_phase');
2015-11-28 07:19:04 +00:00
// player.dataset.glow_phase=lib.config.glow_phase;
2015-11-21 05:30:26 +00:00
// player.animate('playerbright',500);
2015-11-06 10:05:08 +00:00
}
2015-11-21 05:30:26 +00:00
// player.$damage(null,'phase')
2015-11-06 10:05:08 +00:00
game.addVideo('phaseChange',player);
2015-04-29 03:25:17 +00:00
_status.currentPhase=player;
game.log();
2015-12-08 13:54:44 +00:00
game.log(player,'的回合开始');
2015-04-29 03:25:17 +00:00
game.phaseNumber++;
2015-11-07 09:20:15 +00:00
if(get.config('identity_mode')!='zhong'){
var num;
switch(get.config('auto_identity')){
case 'one':num=1;break;
case 'two':num=2;break;
case 'three':num=3;break;
case 'always':num=-1;break;
default:num=0;break;
}
if(num&&!_status.identityShown&&game.phaseNumber>game.players.length*num&&game.showIdentity){
if(!_status.video) player.popup('显示身份');
_status.identityShown=true;
game.showIdentity(false);
}
2015-04-29 03:25:17 +00:00
}
player.ai.tempIgnore=[];
player.stat.push({card:{},skill:{}});
},
},
_save:{
trigger:{source:'dying',player:'dying'},
priority:5,
forced:true,
popup:false,
filter:function(event,player){
if(event.player.hp>0) return false;
if(event.source&&event.source!=player) return false;
return true;
},
content:function(){
"step 0"
event.dying=_status.dying;
"step 1"
trigger.start=trigger.source||trigger.player;
var str=get.translation(trigger.player.name)+'濒死,是否帮助?';
_status.dying=event.dying;
2015-11-15 05:54:58 +00:00
if(lib.config.tao_enemy&&event.dying.side!=player.side&&lib.config.mode!='identity'&&lib.config.mode!='guozhan'){
event._result={bool:false}
}
else if(player.hasSkillTag('save',true)||player.num('h','tao')||
2015-04-29 03:25:17 +00:00
(player==event.dying&&(player.num('h','jiu')||player.num('h','hufu')||player.num('h','tianxianjiu')))){
player.chooseToUse({
filterCard:function(card,player){
var mod=game.checkMod(card,player,'unchanged','cardSavable',player.get('s'));
if(mod!='unchanged') return mod;
var savable=get.info(card).savable;
if(typeof savable=='function') savable=savable(card,player,event.dying);
return savable;
},
filterTarget:trigger.player,
prompt:str,
ai1:function(){return 1;},
ai2:ai.get.effect,
type:'dying',
2015-05-08 13:37:34 +00:00
targetRequired:true,
2015-04-29 03:25:17 +00:00
dying:event.dying
});
}
else{
event._result={bool:false}
}
"step 2"
if(result.bool){
if(trigger.player.hp<=0&&trigger.player.isAlive()&&!trigger.player.isOut()&&!trigger.player.removed) event.goto(0);
else trigger.untrigger();
}
else{
for(var i=0;i<20;i++){
if(event.player.next!=trigger.start){
event.player=event.player.next;
if(!event.player.isOut()){
event.goto(1);
break;
}
}
else{
break;
}
}
}
}
},
2015-05-13 10:26:54 +00:00
_ismin:{
mod:{
cardEnabled:function(card,player){
if(player.isMin()){
if(get.type(card)=='equip') return false;
}
}
}
},
2015-04-29 03:25:17 +00:00
_chongzhu:{
enable:'phaseUse',
2015-10-21 05:11:55 +00:00
prompt:'将要重铸的牌置于弃牌堆并摸一张牌',
2015-04-29 03:25:17 +00:00
filter:function(event,player){
2015-05-13 10:26:54 +00:00
if(player.isMin()&&lib.config.mode=='stone') return false;
2015-04-29 03:25:17 +00:00
return (player.get('h',function(card){
return get.info(card).chongzhu;
}).length);
},
filterCard:function(card){
return get.info(card).chongzhu;
},
prepare:function(cards,player){
player.$throw(cards,1000);
},
discard:false,
delay:0.5,
content:function(){
"step 0"
player.draw();
"step 1"
for(var i=0;i<cards.length;i++){
ui.discardPile.appendChild(cards[i]);
}
},
ai:{
basic:{
order:6
},
result:{
player:1,
},
}
},
_lianhuan:{
trigger:{player:'damageAfter'},
filter:function(event,player){
return (event.nature&&lib.linked.contains(event.nature)&&event.player.classList.contains('linked'));
},
forced:true,
popup:false,
content:function(){
"step 0"
player.link();
"step 1"
var players=game.players.slice(0);
lib.tempSortSeat=player;
players.sort(lib.sort.seat);
delete lib.tempSortSeat;
for(var i=0;i<players.length;i++){
if(players[i].classList.contains('linked')){
if(trigger.source){
players[i].damage(trigger.num,trigger.nature,trigger.source,trigger.cards,trigger.card);
}
else{
players[i].damage(trigger.num,trigger.nature,'nosource',trigger.cards,trigger.card);
}
return;
}
}
}
},
_lianhuan2:{
trigger:{global:'damageAfter'},
filter:function(event,player){
return (event.nature&&lib.linked.contains(event.nature)&&event.player.classList.contains('linked')&&
event.player.classList.contains('dead')&&player.classList.contains('linked'));
},
forced:true,
content:function(){
"step 0"
trigger.player.classList.remove('linked');
"step 1"
if(trigger.source){
player.damage(trigger.num,trigger.nature,trigger.source,trigger.cards,trigger.card);
}
else{
player.damage(trigger.num,trigger.nature,'nosource',trigger.cards,trigger.card);
}
}
},
2015-12-02 10:40:25 +00:00
_lianhuan3:{
trigger:{global:'damageAfter'},
priority:-10,
forced:true,
popup:false,
filter:function(event,player){
return event.player.classList.contains('dead');
},
content:function(){
trigger.player.classList.remove('linked');
}
2015-12-07 11:15:35 +00:00
},
_lianhuan4:{
trigger:{global:'dieAfter'},
priority:-10,
forced:true,
popup:false,
filter:function(event,player){
return event.player.classList.contains('dead')&&event.parent.parent.name!='damage';
},
content:function(){
window.x=event;
trigger.player.classList.remove('linked');
}
2015-12-02 10:40:25 +00:00
}
2015-04-29 03:25:17 +00:00
},
character:{},
perfectPair:{},
2015-11-28 03:45:23 +00:00
cardPile:{},
2015-04-29 03:25:17 +00:00
group:['wei','shu','wu','qun'],
nature:['fire','thunder','poison'],
linked:['fire','thunder'],
};
var game={
2015-04-29 14:56:33 +00:00
playAudio:function(){
2015-11-30 13:08:29 +00:00
if(_status.video&&arguments[1]!='video') return;
2015-04-29 14:56:33 +00:00
var str='';
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]==='string'||typeof arguments[i]=='number'){
str+='/'+arguments[i];
}
2015-12-02 10:40:25 +00:00
if(_status.video) break;
2015-04-29 14:56:33 +00:00
}
2015-11-01 07:54:42 +00:00
if(_status.skillaudio.contains(str)) return;
_status.skillaudio.add(str);
2015-11-25 12:34:54 +00:00
game.addVideo('playAudio',null,str);
2015-11-01 07:54:42 +00:00
setTimeout(function(){
_status.skillaudio.remove(str);
},1000);
2015-04-29 14:56:33 +00:00
var audio=document.createElement('audio');
audio.autoplay=true;
2015-04-30 03:09:07 +00:00
audio.volume=lib.config.volumn_audio/8;
2015-04-29 14:56:33 +00:00
audio.src='audio'+str+'.mp3';
audio.addEventListener('ended',function(){
this.remove();
});
2015-04-30 03:09:07 +00:00
audio.onerror=function(){
2015-05-16 14:18:03 +00:00
if(this._changed){
this.remove();
2015-05-16 11:22:27 +00:00
}
else{
2015-05-16 14:18:03 +00:00
this.src='audio'+str+'.ogg';
this._changed=true;
2015-05-16 11:22:27 +00:00
}
2015-04-30 03:09:07 +00:00
};
2015-04-30 08:24:57 +00:00
ui.window.appendChild(audio);
2015-04-29 14:56:33 +00:00
},
2015-05-16 11:22:27 +00:00
playSkillAudio:function(name){
2015-11-30 13:08:29 +00:00
if(_status.video&&arguments[1]!='video') return;
2015-11-01 07:54:42 +00:00
if(_status.skillaudio.contains(name)) return;
2015-11-25 12:34:54 +00:00
game.addVideo('playSkillAudio',null,name);
2015-11-01 07:54:42 +00:00
_status.skillaudio.add(name);
setTimeout(function(){
_status.skillaudio.remove(name);
},1000);
2015-05-16 11:22:27 +00:00
var str='audio/skill/';
var audio=document.createElement('audio');
audio.autoplay=true;
audio.volume=lib.config.volumn_audio/8;
2015-05-16 11:22:27 +00:00
audio.src=str+name+'.mp3';
audio.addEventListener('ended',function(){
this.remove();
});
2015-05-16 14:18:03 +00:00
audio._changed=1;
2015-05-16 11:22:27 +00:00
audio.onerror=function(){
2015-05-16 14:18:03 +00:00
switch(this._changed){
case 1:{
audio.src=str+name+'.ogg';
this._changed=2;
break;
}
case 2:{
audio.src=str+name+Math.ceil(Math.random()*2)+'.mp3';
this._changed=3;
break;
}
case 3:{
audio.src=str+name+Math.ceil(Math.random()*2)+'.ogg';
this._changed=4;
break;
}
default:{
this.remove();
}
2015-05-16 11:22:27 +00:00
}
};
ui.window.appendChild(audio);
},
2015-04-29 14:56:33 +00:00
playBackgroundMusic:function(){
if(lib.config.background_music=='music_off'){
ui.backgroundMusic.src='';
}
else{
var music=lib.config.background_music;
if(music=='music_random'){
music=lib.config.all.background_music.randomGet('music_off','music_random',_status.currentMusic);
}
_status.currentMusic=music;
2015-12-08 00:56:54 +00:00
if(music=='music_custom'){
if(_status.background_music_src){
ui.backgroundMusic.src=_status.background_music_src;
}
else if(lib.db){
game.getDB('audio','background',function(fileToLoad){
if(!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var data = fileLoadedEvent.target.result;
if(data){
_status.background_music_src=data;
ui.backgroundMusic.src=_status.background_music_src;
}
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
}
}
else{
ui.backgroundMusic.src='audio/background/'+music+'.mp3';
}
2015-04-29 14:56:33 +00:00
}
},
2015-12-06 15:23:47 +00:00
import:function(type,obj){
if(type=='character'){
if(lib.config.customCharacterPack[obj.name]){
alert('武将包已存在');
return;
}
var pack={
name:obj.name,
character:[],
skill:[],
};
for(var i in obj.character){
if(lib.checkCharacterName(i)){
alert('武将名重复:'+i);
continue;
}
game.putDB('character',i,obj.character[i]);
lib.character[i]=obj.character[i];
lib.customCharacters.add(i);
pack.character.push(i);
lib.setTranslate(i);
}
for(var i in obj.skill){
if(lib.checkSkillName(i)){
alert('技能名重复:'+i);
continue;
}
var info=obj.skill[i];
try{
eval('lib.skill["'+info.name+'"]={'+info.content+'}');
}
catch(e){
console.log(e);
lib.skill[info.name]={};
}
lib.skill[info.name].createInfo=info;
lib.setTranslate(i);
lib.translate[info.name+'_info']=info.description;
game.putDB('skill',info.name,info);
pack.skill.push(i);
}
lib.config.customCharacterPack[obj.name]=pack;
game.saveConfig('customCharacterPack',lib.config.customCharacterPack);
}
game.importedPack=obj;
},
2015-11-04 01:59:00 +00:00
export:function(textToWrite,name){
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
var fileNameToSaveAs = name||'noname';
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.click();
},
2015-12-07 11:15:35 +00:00
exportCharacters:function(packname,list,callback){
2015-12-06 15:23:47 +00:00
var zipReady=function(){
var zip=new JSZip();
var imageLoaded=0;
var character={
name:packname||'noname',
character:{},
skill:{},
};
var load=function(img){
var blob = zip.generate({type:"blob"});
var fileNameToSaveAs = packname||'noname';
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = window.URL.createObjectURL(blob);
downloadLink.click();
2015-12-07 11:15:35 +00:00
if(typeof callback=='function'){
callback(character);
}
2015-12-06 15:23:47 +00:00
};
for(var i=0;i<lib.customCharacters.length;i++){
var name=lib.customCharacters[i];
if(lib.checkCharacterName(name)) continue;
if(list&&!list.contains(name)){
imageLoaded++;
continue;
}
character.character[name]=lib.character[name];
for(var j=0;j<lib.character[name][3].length;j++){
var skillname=lib.character[name][3][j];
if(lib.skill[skillname].createInfo){
character.skill[skillname]=lib.skill[skillname].createInfo;
}
}
(function(name){
game.getDB('image','character:'+name,function(img){
imageLoaded++;
zip.file(name+'.jpg',img.slice(img.indexOf('base64,')+7),{base64:true});
if(imageLoaded==lib.customCharacters.length){
load();
}
});
}(name));
}
zip.file('pack.js','game.import("character",'+lib.init.stringify(character)+')');
}
if(!window.JSZip){
lib.init.js('game','jszip',zipReady);
}
else{
zipReady();
}
},
2015-11-04 01:59:00 +00:00
playVideo:function(time,mode){
2015-11-05 02:34:35 +00:00
if(!_status.replayvideo){
localStorage.setItem(lib.configprefix+'playbackmode',lib.config.mode);
}
2015-11-04 01:59:00 +00:00
game.saveConfig('mode',mode);
localStorage.setItem(lib.configprefix+'playback',time);
game.reload();
},
playVideoContent:function(video){
var next=game.createEvent('video',false);
next.video=video;
ui.system.style.display='none';
ui.system.hide();
ui.arena.style.display='none';
ui.arena.hide();
_status.event=next;
_status.paused=false;
_status.paused2=false;
_status.over=false;
_status.video=true;
clearTimeout(_status.timeout);
for(var i in lib.characterPack){
for(var j in lib.characterPack[i]){
lib.character[j]=lib.character[j]||lib.characterPack[i][j];
}
}
next.content=function(){
'step 0'
game.delay(0,500);
'step 1'
if(lib.config.mode!='chess'){
ui.control.innerHTML='';
var nodes=[];
for(var i=0;i<ui.arena.childNodes.length;i++){
nodes.push(ui.arena.childNodes[i]);
}
for(var i=0;i<nodes.length;i++){
if(nodes[i]==ui.canvas) continue;
if(nodes[i]==ui.control) continue;
if(nodes[i]==ui.mebg) continue;
if(nodes[i]==ui.me) continue;
2015-11-29 11:46:51 +00:00
if(nodes[i]==ui.roundmenu) continue;
2015-11-04 01:59:00 +00:00
nodes[i].remove();
}
2015-11-24 15:44:21 +00:00
// ui.me.f.innerHTML='';
2015-11-04 01:59:00 +00:00
ui.sidebar.innerHTML='';
ui.cardPile.innerHTML='';
ui.discardPile.innerHTML='';
ui.special.innerHTML='';
}
ui.system.firstChild.innerHTML='';
ui.system.lastChild.innerHTML='';
2015-11-05 02:34:35 +00:00
ui.system.firstChild.appendChild(ui.config2);
if(ui.updateVideoMenu){
ui.updateVideoMenu();
}
2015-11-04 01:59:00 +00:00
_status.videoDuration=1;
2015-11-05 02:34:35 +00:00
ui.create.system('返回',function(){
var mode=localStorage.getItem(lib.configprefix+'playbackmode');
if(mode){
game.saveConfig('mode',mode);
}
game.reload();
});
2015-11-04 01:59:00 +00:00
ui.create.system('重播',function(){
2015-11-05 02:34:35 +00:00
_status.replayvideo=true;
2015-11-04 01:59:00 +00:00
game.playVideo(_status.playback,lib.config.mode);
});
ui.create.system('暂停',ui.click.pause,true);
var slow=ui.create.system('减速',function(){
_status.videoDuration*=1.5;
updateDuration();
},true);
var fast=ui.create.system('加速',function(){
_status.videoDuration/=1.5;
updateDuration();
},true);
var updateDuration=function(){
if(_status.videoDuration>1){
slow.classList.add('glow');
}
else{
slow.classList.remove('glow');
}
if(_status.videoDuration<1){
fast.classList.add('glow');
}
else{
fast.classList.remove('glow');
}
}
ui.system.style.display='';
ui.refresh(ui.system);
ui.system.show();
2015-12-12 08:37:15 +00:00
ui.window.show();
2015-11-04 01:59:00 +00:00
if(lib.config.mode!='versus'&&lib.config.mode!='boss'){
ui.arena.style.display='';
ui.refresh(ui.arena);
ui.arena.show();
}
if(lib.config.mode!='chess'){
game.playerMap={};
}
'step 2'
if(event.video.length){
var content=event.video.shift();
// console.log(content);
if(content.type=='delay'){
game.delay(content.content);
}
2015-11-09 23:11:17 +00:00
else if(content.type=='play'){
window.play={};
if(!event.playtoload){
event.playtoload=1;
}
else{
event.playtoload++;
}
var script=lib.init.js('play',content.name);
script.addEventListener('load',function(){
var play=window.play[content.name]
if(play&&play.video){
play.video(content.init);
}
event.playtoload--;
if(event.playtoload==0){
delete window.play;
}
});
}
2015-11-09 03:15:16 +00:00
else if(typeof content.player=='string'&&game.playerMap[content.player]&&
game.playerMap[content.player].classList&&
!game.playerMap[content.player].classList.contains('obstacle')){
2015-11-04 01:59:00 +00:00
game.videoContent[content.type](game.playerMap[content.player],content.content);
}
else{
game.videoContent[content.type](content.content);
}
if(event.video.length){
game.delay(0,_status.videoDuration*Math.min(2000,event.video[0].delay));
}
event.redo();
}
else{
_status.over=true;
ui.system.lastChild.hide();
setTimeout(function(){
ui.system.lastChild.innerHTML='';
},500);
}
}
game.loop();
},
videoContent:{
init:function(players){
if(lib.config.mode=='chess') return;
ui.arena.dataset.number=players.length;
ui.arena.classList.add('video');
game.players.length=0;
game.dead.length=0;
ui.create.players(players.length);
game.me=game.players[0];
ui.handcards1=game.me.node.handcards1;
ui.handcards2=game.me.node.handcards2;
2015-11-24 15:44:21 +00:00
ui.handcards1Container.appendChild(ui.handcards1);
ui.handcards2Container.appendChild(ui.handcards2);
2015-11-04 01:59:00 +00:00
if(lib.config.mode=='versus'){
if(players.bool){
ui.arena.dataset.number=parseInt(ui.arena.dataset.number)+1;
for(var i=0;i<game.players.length;i++){
game.players[i].dataset.position=parseInt(game.players[i].dataset.position)+1;
}
game.singleHandcard=true;
ui.arena.classList.add('single-handcard');
ui.fakeme=ui.create.div('.player.controlfakeme');
ui.fakeme.line=lib.element.player.line;
ui.fakemebg=ui.create.div('.avatar',ui.fakeme).hide();
}
ui.arena.style.display='';
ui.refresh(ui.arena);
ui.arena.show();
}
else if(lib.config.mode=='boss'){
if(!players.boss){
game.singleHandcard=true;
ui.arena.classList.add('single-handcard');
ui.fakeme=ui.create.div('.player.controlfakeme');
ui.fakeme.dataset.position=0;
ui.fakeme.line=lib.element.player.line;
ui.fakemebg=ui.create.div('.avatar',ui.fakeme).hide();
ui.refresh(ui.fakemebg);
}
ui.arena.dataset.number=8;
}
2015-12-02 15:34:34 +00:00
ui.updatehl();
2015-11-04 01:59:00 +00:00
for(var i=0;i<players.length;i++){
if(lib.config.mode=='identity'){
game.players[i].init(players[i].name,players[i].name2);
game.players[i].setIdentity(players[i].identity);
}
else if(lib.config.mode=='stone'){
game.players[i].init(players[i].name,players[i].name2);
game.players[i].classList.add('noidentity');
game.players[i].updateActCount(null,players[i].count,0);
}
else if(lib.config.mode=='boss'){
game.players[i].init(players[i].name,players[i].name2);
game.players[i].setIdentity(players[i].identity);
game.players[i].dataset.position=players[i].position;
2015-11-06 10:05:08 +00:00
game.players[i].node.action.innerHTML='行动';
2015-11-04 01:59:00 +00:00
}
else if(lib.config.mode=='versus'){
game.players[i].init(players[i].name,players[i].name2);
game.players[i].node.identity.firstChild.innerHTML=players[i].identity;
game.players[i].node.identity.dataset.color=players[i].color;
2015-11-06 10:05:08 +00:00
game.players[i].node.action.innerHTML='行动';
2015-11-04 01:59:00 +00:00
}
else if(lib.config.mode=='guozhan'){
game.players[i].name=players[i].name;
game.players[i].name1=players[i].name1;
game.players[i].name2=players[i].name2;
game.players[i].sex='unknown';
game.players[i].identity='unknown';
lib.translate[game.players[i].name]=players[i].translate;
game.players[i].init(players[i].name1,players[i].name2,false);
game.players[i].classList.add('unseen');
game.players[i].classList.add('unseen2');
if(game.players[i]!=game.me){
game.players[i].node.identity.firstChild.innerHTML='猜';
game.players[i].node.identity.dataset.color='unknown';
}
else{
game.players[i].setIdentity(game.players[i].group);
}
}
}
for(var i=0;i<game.players.length;i++){
game.playerMap[game.players[i].dataset.position]=game.players[i];
}
if(lib.config.mode=='versus'){
if(players.bool){
ui.fakemebg.show();
game.onSwapControl();
}
}
else if(lib.config.mode=='boss'){
if(!players.boss){
game.onSwapControl();
ui.fakemebg.show();
}
ui.arena.style.display='';
ui.refresh(ui.arena);
ui.arena.show();
2015-12-02 15:34:34 +00:00
ui.updatehl();
2015-11-04 01:59:00 +00:00
}
},
2015-11-25 12:34:54 +00:00
playAudio:function(str){
2015-11-30 13:08:29 +00:00
game.playAudio(str,'video');
2015-11-25 12:34:54 +00:00
},
playSkillAudio:function(name){
2015-11-30 13:08:29 +00:00
game.playSkillAudio(name,'video');
2015-11-25 12:34:54 +00:00
},
2015-11-06 10:05:08 +00:00
phaseChange:function(player){
if(player){
var glowing=document.querySelector('.glow_phase');
if(glowing){
glowing.classList.remove('glow_phase');
}
if(lib.config.glow_phase){
player.classList.add('glow_phase');
2015-11-28 07:19:04 +00:00
// player.dataset.glow_phase=lib.config.glow_phase;
2015-11-06 10:05:08 +00:00
}
}
else{
console.log(player);
}
},
2015-11-09 03:15:16 +00:00
playerfocus:function(player,time){
if(player&&player.playerfocus){
player.playerfocus(time);
2015-11-07 09:20:15 +00:00
}
else{
console.log(player);
}
},
2015-11-04 01:59:00 +00:00
chessSwap:function(content){
var me=game.playerMap[content[0]];
var player=game.playerMap[content[1]];
if(me){
2015-12-01 05:46:28 +00:00
me.classList.remove('current_action');
2015-11-04 01:59:00 +00:00
}
if(player){
2015-12-01 05:46:28 +00:00
player.classList.add('current_action');
2015-11-04 01:59:00 +00:00
}
},
chessgainmod:function(player,num){
if(Array.isArray(num)){
num=get.infoCards(num);
}
2015-11-05 02:34:35 +00:00
if(player&&player.$gainmod){
player.$gainmod(num);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
moveTo:function(player,pos){
2015-11-05 02:34:35 +00:00
if(player&&player.moveTo&&pos){
player.moveTo(pos[0],pos[1]);
}
else{
console.log(player)
}
2015-11-04 01:59:00 +00:00
},
2015-11-09 03:15:16 +00:00
addObstacle:function(pos){
if(pos){
game.addObstacle(pos[0],pos[1]);
}
else{
console.log(pos)
}
},
removeObstacle:function(pos){
game.removeObstacle(pos);
},
2015-11-04 01:59:00 +00:00
moveTox:function(player,pos){
2015-11-05 02:34:35 +00:00
if(player&&player.dataset){
delete lib.posmap[player.dataset.position];
player.dataset.position=pos;
lib.posmap[pos]=player;
game.delay();
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
2015-11-06 10:05:08 +00:00
thrownhighlight1:function(){
ui.arena.classList.add('thrownhighlight');
},
thrownhighlight2:function(){
ui.arena.classList.remove('thrownhighlight');
},
2015-11-04 01:59:00 +00:00
chessFocus:function(player){
2015-11-05 02:34:35 +00:00
if(player){
player.chessFocus();
}
else{
console.log('chessFocus');
}
2015-11-04 01:59:00 +00:00
},
2015-11-09 03:15:16 +00:00
removeTreasure:function(pos){
if(game.playerMap[pos]){
game.playerMap[pos].delete();
delete game.playerMap[pos];
}
else{
console.log(pos);
}
},
initobs:function(obs){
if(obs){
for(var i=0;i<obs.length;i++){
game.addObstacle(obs[i]);
}
}
else{
console.log(obs);
}
},
2015-11-04 01:59:00 +00:00
stonePosition:function(content){
var player=game.playerMap[content[0]];
if(player){
delete game.playerMap[content[0]];
player.dataset.position=content[1];
game.playerMap[content[1]]=player;
}
2015-11-05 02:34:35 +00:00
else{
console.log(content);
}
2015-11-04 01:59:00 +00:00
},
stoneSwap:function(info){
var player=ui.create.player();
player.classList.add('noidentity');
player.dataset.position=info.position;
player.animate(info.me?'replaceme':'replaceenemy');
player.actcount=info.actcount;
player.init(info.name,info.name2);
game.players.push(player);
player.updateActCount(null,info.actcount,0);
ui.arena.appendChild(player);
game.playerMap[player.dataset.position]=player;
game.arrangePlayers();
},
2015-11-05 02:34:35 +00:00
chess_tongshuai:function(player,content){
if(player&&player.storage){
player.storage.tongshuai.owned=content;
}
else{
console.log(player);
}
},
chess_tongshuai_skill:function(player,content){
if(player&&content){
if(player.marks.tongshuai.firstChild){
player.marks.tongshuai.firstChild.remove();
}
player.marks.tongshuai.setBackground(content[0],'character');
player.additionalSkills.tongshuai=content[1];
}
else{
console.log(player);
}
},
2015-11-04 01:59:00 +00:00
reinit:function(source,content){
2015-11-05 02:34:35 +00:00
if(source&&content){
source.uninit();
source.init(content[0]);
source.node.identity.dataset.color=content[1];
}
else{
console.log(source);
}
2015-11-04 01:59:00 +00:00
},
skill:function(player,content){
if(typeof content=='string'){
lib.skill[content].video(player);
}
else if(Array.isArray(content)){
lib.skill[content[0]].video(player,content[1]);
}
2015-11-05 02:34:35 +00:00
else{
console.log(player,content)
}
2015-11-04 01:59:00 +00:00
},
addFellow:function(content){
var player=game.addFellow(content[0],content[1]);
game.playerMap[player.dataset.position]=player;
},
updateActCount:function(player,content){
2015-11-05 02:34:35 +00:00
if(player&&content){
player.updateActCount(content[0],content[1],content[2]);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
showCharacter:function(player,num){
2015-11-05 02:34:35 +00:00
if(player&&player.classList){
switch(num){
case 0:
player.classList.remove('unseen');
break;
case 1:
player.classList.remove('unseen2');
break;
case 2:
player.classList.remove('unseen');
player.classList.remove('unseen2');
break;
}
}
else{
console.log(num);
2015-11-04 01:59:00 +00:00
}
},
popup:function(player,info){
2015-11-05 02:34:35 +00:00
if(player&&info){
player.popup(info[0],info[1]);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
log:function(str){
game.log(str);
},
draw:function(player,info){
2015-11-05 02:34:35 +00:00
if(player&&player.$draw){
player.$draw(info);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
drawCard:function(player,info){
2015-11-05 02:34:35 +00:00
if(player&&info){
player.$draw(get.infoCards(info));
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
throw:function(player,info){
2015-11-05 02:34:35 +00:00
if(player&&info){
player.$throw(get.infoCards(info[0]),info[1]);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
compare:function(player,info){
2015-11-05 02:34:35 +00:00
if(player&&info){
player.$compare(get.infoCard(info[0]),game.playerMap[info[1]],get.infoCard(info[2]));
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
give:function(player,info){
2015-11-05 02:34:35 +00:00
if(player&&info){
player.$give(info[0],game.playerMap[info[1]]);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
giveCard:function(player,info){
2015-11-05 02:34:35 +00:00
if(player&&info){
player.$give(get.infoCards(info[0]),game.playerMap[info[1]]);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
gain:function(player,info){
2015-11-05 02:34:35 +00:00
if(player&&player.$gain){
player.$gain(info);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
gainCard:function(player,info){
2015-11-05 02:34:35 +00:00
if(player&&info){
player.$gain(get.infoCards(info));
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
gain2:function(player,cards){
2015-11-05 02:34:35 +00:00
if(player&&player.$draw){
var nodeList=document.querySelectorAll('#arena>.card,#chess>.card');
var nodes=[];
for(var i=0;i<nodeList.length;i++){
nodes.push(nodeList[i]);
}
for(var i=0;i<cards.length;i++){
for(var j=0;j<nodes.length;j++){
if(cards[i][2]==nodes[j].name&&cards[i][0]==nodes[j].suit&&cards[i][1]==nodes[j].number){
2015-11-23 10:59:44 +00:00
nodes[j].moveDelete(player);
2015-11-05 02:34:35 +00:00
cards.splice(i--,1);
nodes.splice(j--,1);
break;
}
2015-11-04 01:59:00 +00:00
}
}
2015-11-05 02:34:35 +00:00
if(cards.length){
player.$draw(get.infoCards(cards));
}
2015-11-04 01:59:00 +00:00
}
2015-11-05 02:34:35 +00:00
else{
console.log(player);
2015-11-04 01:59:00 +00:00
}
},
deletenode:function(player,cards){
2015-11-05 02:34:35 +00:00
if(cards){
var nodeList=document.querySelectorAll('#arena>.card,#chess>.card');
var nodes=[];
for(var i=0;i<nodeList.length;i++){
nodes.push(nodeList[i]);
}
for(var i=0;i<cards.length;i++){
for(var j=0;j<nodes.length;j++){
if(cards[i][2]==nodes[j].name&&cards[i][0]==nodes[j].suit&&cards[i][1]==nodes[j].number){
nodes[j].delete();
cards.splice(i--,1);
nodes.splice(j--,1);
break;
}
2015-11-04 01:59:00 +00:00
}
}
}
2015-11-05 02:34:35 +00:00
else{
console.log(player,cards);
}
2015-11-04 01:59:00 +00:00
},
2015-11-06 10:05:08 +00:00
highlightnode:function(player,card){
if(card){
var nodeList=document.querySelectorAll('#arena>.card,#chess>.card');
var nodes=[];
for(var i=0;i<nodeList.length;i++){
nodes.push(nodeList[i]);
}
for(var j=nodes.length-1;j>=0;j--){
if(card[2]==nodes[j].name&&card[0]==nodes[j].suit&&card[1]==nodes[j].number){
nodes[j].classList.add('thrownhighlight');
break;
}
}
}
else{
console.log(player,cards);
}
},
2015-11-04 01:59:00 +00:00
uiClear:function(){
ui.clear();
},
judge1:function(player,content){
2015-11-05 02:34:35 +00:00
if(player&&content){
var judging=get.infoCard(content[0]);
2015-11-06 10:05:08 +00:00
if(lib.config.mode=='chess'){
judging.copy('thrown','center','thrownhighlight',ui.arena).animate('start');
}
else{
player.$throwordered(judging.copy('thrownhighlight'),true);
}
2015-11-05 02:34:35 +00:00
ui.create.dialog(content[1]).videoId=content[2];
2015-11-06 10:05:08 +00:00
ui.arena.classList.add('thrownhighlight');
2015-11-05 02:34:35 +00:00
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
centernode:function(content){
2015-11-06 10:05:08 +00:00
get.infoCard(content).copy('thrown','center','thrownhighlight',ui.arena).animate('start');
2015-11-04 01:59:00 +00:00
},
judge2:function(videoId){
for(var i=0;i<ui.dialogs.length;i++){
if(ui.dialogs[i].videoId==videoId){
ui.dialogs[i].close();
}
}
2015-11-06 10:05:08 +00:00
ui.arena.classList.remove('thrownhighlight');
2015-11-04 01:59:00 +00:00
},
unmarkname:function(player,name){
2015-11-05 02:34:35 +00:00
if(player&&player.unmark){
player.unmark(name);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
unmark:function(player,name){
2015-11-05 02:34:35 +00:00
if(player&&player.marks&&player.marks[name]){
2015-11-04 01:59:00 +00:00
player.marks[name].delete();
delete player.marks[name];
}
},
flame:function(player,type){
2015-11-05 02:34:35 +00:00
if(player&&type){
player['$'+type]();
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
line:function(player,content){
2015-11-05 02:34:35 +00:00
if(player&&content){
player.line(game.playerMap[content[0]],content[1]);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
damagepop:function(player,content){
2015-11-05 02:34:35 +00:00
if(player&&content){
player.$damagepop(content[0],content[1]);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
damage:function(player,source){
2015-11-05 02:34:35 +00:00
if(player&&player.$damage){
player.$damage(game.playerMap[source]);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
diex:function(player){
2015-11-05 02:34:35 +00:00
if(!player){
console.log('diex');
return;
}
2015-11-04 01:59:00 +00:00
var cards=player.get('hej');
for(var i=0;i<cards.length;i++){
cards[i].goto(ui.discardPile);
}
while(player.node.marks.childNodes.length){
player.node.marks.firstChild.remove();
}
player.classList.add('dead');
player.classList.remove('turnedover');
player.classList.remove('out');
2015-11-05 02:34:35 +00:00
player.node.count.innerHTML='0';
player.node.hp.hide();
player.node.equips.hide();
player.node.count.hide();
2015-11-04 01:59:00 +00:00
player.previous.next=player.next;
player.next.previous=player.previous;
game.players.remove(player);
game.dead.push(player);
if(lib.config.mode=='stone'){
setTimeout(function(){
player.delete();
},500);
}
},
2015-11-13 01:43:16 +00:00
tafangMe:function(player){
if(player){
game.me=player;
ui.me.lastChild.show();
ui.create.fakeme();
ui.handcards1=player.node.handcards1.animate('start').fix();
ui.handcards2=player.node.handcards2.animate('start').fix();
2015-11-24 15:44:21 +00:00
ui.handcards1Container.appendChild(ui.handcards1);
ui.handcards2Container.appendChild(ui.handcards2);
2015-12-02 15:34:34 +00:00
ui.updatehl();
2015-11-13 01:43:16 +00:00
game.setChessInfo();
}
},
deleteChessPlayer:function(player){
if(player){
player.delete();
delete game.playerMap[player.dataset.position];
2015-11-13 09:12:47 +00:00
game.players.remove(player);
for(var i=0;i<ui.phasequeue.length;i++){
if(ui.phasequeue[i].link==player){
ui.phasequeue[i].remove();
ui.phasequeue.splice(i,1);
break;
}
}
2015-11-13 01:43:16 +00:00
}
},
2015-11-04 01:59:00 +00:00
addChessPlayer:function(content){
game.addChessPlayer.apply(this,content);
},
die:function(player){
2015-11-05 02:34:35 +00:00
if(!player){
console.log('die');
return;
}
2015-11-04 01:59:00 +00:00
player.$die();
if(lib.config.mode=='chess'){
delete lib.posmap[player.dataset.position];
setTimeout(function(){
player.delete();
},500);
for(var i=0;i<ui.phasequeue.length;i++){
if(ui.phasequeue[i].link==player){
ui.phasequeue[i].remove();
ui.phasequeue.splice(i,1);
break;
}
}
}
},
revive:function(player){
2015-11-05 02:34:35 +00:00
if(!player){
console.log('revive');
return;
}
2015-11-04 01:59:00 +00:00
player.classList.remove('dead');
2015-11-05 02:34:35 +00:00
player.node.hp.show();
player.node.equips.show();
player.node.count.show();
player.node.avatar.style.transform='';
player.node.avatar2.style.transform='';
2015-11-04 01:59:00 +00:00
player.removeAttribute('style');
},
update:function(player,info){
2015-11-05 02:34:35 +00:00
if(player&&info){
2015-11-04 01:59:00 +00:00
player.hp=info[1];
player.maxHp=info[2];
player.hujia=info[3];
player.update(info[0]);
}
2015-11-05 02:34:35 +00:00
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
phaseJudge:function(player,card){
2015-11-05 02:34:35 +00:00
if(player&&card){
player.$phaseJudge(get.infoCard(card));
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
directgain:function(player,cards){
2015-11-05 02:34:35 +00:00
if(player&&cards){
player.directgain(get.infoCards(cards));
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
gain12:function(player,cards12){
2015-11-05 02:34:35 +00:00
if(player&&cards12){
var cards1=get.infoCards(cards12[0]);
var cards2=get.infoCards(cards12[1]);
for(var i=0;i<cards1.length;i++){
2015-12-02 15:34:34 +00:00
cards1[i].classList.add('drawinghidden');
2015-11-05 02:34:35 +00:00
player.node.handcards1.insertBefore(cards1[i],player.node.handcards1.firstChild);
}
for(var i=0;i<cards2.length;i++){
2015-12-02 15:34:34 +00:00
cards2[i].classList.add('drawinghidden');
2015-11-05 02:34:35 +00:00
player.node.handcards2.insertBefore(cards2[i],player.node.handcards2.firstChild);
}
2015-11-24 15:44:21 +00:00
ui.updatehl();
2015-11-04 01:59:00 +00:00
}
2015-11-05 02:34:35 +00:00
else{
console.log(player);
2015-11-04 01:59:00 +00:00
}
},
equip:function(player,card){
2015-11-05 02:34:35 +00:00
if(player&&card){
player.equip(get.infoCard(card));
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
addJudge:function(player,content){
2015-11-05 02:34:35 +00:00
if(player&&content){
var card=get.infoCard(content[0]);
card.viewAs=content[1];
player.node.judges.insertBefore(card,player.node.judges.firstChild);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
markCharacter:function(player,content){
2015-11-05 02:34:35 +00:00
if(player&&content){
if(game.playerMap[content.target]){
content.target=game.playerMap[content.target];
}
var mark=player.markCharacter(content.target,content);
if(content.id){
player.marks[content.id]=mark;
}
2015-11-04 01:59:00 +00:00
}
2015-11-05 02:34:35 +00:00
else{
console.log(player);
2015-11-04 01:59:00 +00:00
}
},
mark:function(player,content){
if(player&&content){
var mark=player.mark(content.id,content);
}
2015-11-05 02:34:35 +00:00
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
markSkill:function(player,content){
if(player&&content){
if(content[1]){
player.markSkill(content[0],null,get.infoCard(content[1]));
}
else{
player.markSkill(content[0]);
}
}
2015-11-05 02:34:35 +00:00
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
unmarkSkill:function(player,name){
2015-11-09 03:15:16 +00:00
if(player&&player.unmarkSkill){
2015-11-04 01:59:00 +00:00
player.unmarkSkill(name);
}
2015-11-05 02:34:35 +00:00
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
storage:function(player,content){
if(player&&content){
if(content[2]){
switch(content[2]){
case 'cards':content[1]=get.infoCards(content[1]);break;
case 'card':content[1]=get.infoCard(content[1]);break;
}
}
player.storage[content[0]]=content[1];
}
2015-11-05 02:34:35 +00:00
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
markId:function(player,content){
2015-11-05 02:34:35 +00:00
if(player&&content){
player.mark(get.infoCard(content[0]),content[1]);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
unmarkId:function(player,content){
2015-11-05 02:34:35 +00:00
if(player&&content){
player.unmark(get.infoCard(content[0]),content[1]);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
lose:function(player,info){
2015-11-05 02:34:35 +00:00
if(player&&info){
var hs=info[0],es=info[1],js=info[2];
var phs=player.get('h'),pes=player.get('e'),pjs=player.get('j');
var checkMatch=function(l1,l2){
for(var i=0;i<l1.length;i++){
for(var j=0;j<l2.length;j++){
if(l2[j].suit==l1[i][0]&&l2[j].number==l1[i][1]&&l2[j].name==l1[i][2]){
l2[j].delete();
2015-11-21 05:30:26 +00:00
l2.splice(j--,1);
2015-11-05 02:34:35 +00:00
break;
}
2015-11-04 01:59:00 +00:00
}
}
}
2015-11-05 02:34:35 +00:00
checkMatch(hs,phs);
checkMatch(es,pes);
checkMatch(js,pjs);
2015-11-25 12:34:54 +00:00
ui.updatehl();
2015-11-05 02:34:35 +00:00
}
else{
console.log(player);
2015-11-04 01:59:00 +00:00
}
},
loseAfter:function(player){
2015-11-05 02:34:35 +00:00
if(!player){
console.log('loseAfter');
return;
}
2015-11-04 01:59:00 +00:00
for(var i=player.node.handcards1.childNodes.length-1;i>0;i--){
if(player.node.handcards1.childNodes[i].classList.contains('removing')==false){
player.node.handcards1.childNodes[i].animate('last');
break;
}
}
for(var i=player.node.handcards2.childNodes.length-1;i>0;i--){
if(player.node.handcards2.childNodes[i].classList.contains('removing')==false){
player.node.handcards2.childNodes[i].animate('last');
break;
}
}
},
link:function(player,bool){
2015-11-05 02:34:35 +00:00
if(player&&player.classList){
if(bool){
player.classList.add('linked');
}
else{
player.classList.remove('linked');
}
2015-11-04 01:59:00 +00:00
}
else{
2015-11-05 02:34:35 +00:00
console.log(player);
2015-11-04 01:59:00 +00:00
}
},
turnOver:function(player,bool){
2015-11-05 02:34:35 +00:00
if(player&&player.classList){
if(bool){
player.classList.add('turnedover');
}
else{
player.classList.remove('turnedover');
}
2015-11-04 01:59:00 +00:00
}
else{
2015-11-05 02:34:35 +00:00
console.log(player);
2015-11-04 01:59:00 +00:00
}
},
showCards:function(player,info){
2015-11-05 02:34:35 +00:00
if(info){
var dialog=ui.create.dialog(info[0],get.infoCards(info[1]));
setTimeout(function(){
dialog.close();
},1000);
}
else{
console.log(player);
}
2015-11-04 01:59:00 +00:00
},
cardDialog:function(content){
if(Array.isArray(content)){
ui.create.dialog(content[0],get.infoCards(content[1])).videoId=content[2];
}
else if(typeof content=='number'){
for(var i=0;i<ui.dialogs.length;i++){
if(ui.dialogs[i].videoId==content){
ui.dialogs[i].close();
return;
}
}
}
},
dialogCapt:function(content){
for(var i=0;i<ui.dialogs.length;i++){
if(ui.dialogs[i].videoId==content[0]){
ui.dialogs[i].content.firstChild.innerHTML=content[1];
return;
}
}
},
swapSeat:function(content){
var player1=game.playerMap[content[0]];
var player2=game.playerMap[content[1]];
2015-11-05 02:34:35 +00:00
if(!player1||!player2){
console.log(content);
return;
}
2015-11-04 01:59:00 +00:00
var temp1,pos,i,num;
temp1=player1.dataset.position;
player1.dataset.position=player2.dataset.position;
player2.dataset.position=temp1;
game.arrangePlayers();
if(player1.dataset.position=='0'||player2.dataset.position=='0'){
pos=parseInt(player1.dataset.position);
if(pos==0) pos=parseInt(player2.dataset.position);
num=game.players.length+game.dead.length;
for(i=0;i<game.players.length;i++){
temp1=parseInt(game.players[i].dataset.position)-pos;
if(temp1<0) temp1+=num;
game.players[i].dataset.position=temp1;
}
for(i=0;i<game.dead.length;i++){
temp1=parseInt(game.dead[i].dataset.position)-pos;
if(temp1<0) temp1+=num;
game.dead[i].dataset.position=temp1;
}
}
game.playerMap={};
var players=game.players.concat(game.dead);
for(var i=0;i<players.length;i++){
game.playerMap[players[i].dataset.position]=players[i];
}
},
swapControl:function(player,hs){
2015-11-05 02:34:35 +00:00
if(player&&player.node){
var cards=get.infoCards(hs);
player.node.handcards1.innerHTML='';
player.node.handcards2.innerHTML='';
player.directgain(cards,false);
2015-12-01 05:46:28 +00:00
game.me.node.handcards1.remove();
game.me.node.handcards2.remove();
2015-11-05 02:34:35 +00:00
ui.handcards1=player.node.handcards1.animate('start').fix();
ui.handcards2=player.node.handcards2.animate('start').fix();
2015-11-25 12:34:54 +00:00
ui.handcards1Container.insertBefore(ui.handcards1,ui.handcards1Container.firstChild);
ui.handcards2Container.insertBefore(ui.handcards2,ui.handcards2Container.firstChild);
2015-11-04 01:59:00 +00:00
2015-11-25 12:34:54 +00:00
game.me=player;
2015-12-02 15:34:34 +00:00
ui.updatehl();
2015-11-05 02:34:35 +00:00
if(lib.config.mode=='chess'){
ui.create.fakeme();
}
}
else{
console.log(player);
2015-11-04 01:59:00 +00:00
}
},
onSwapControl:function(){
game.onSwapControl();
},
swapPlayer:function(player,hs){
2015-11-05 02:34:35 +00:00
if(player&&player.node){
var cards=get.infoCards(hs);
player.node.handcards1.innerHTML='';
player.node.handcards2.innerHTML='';
player.directgain(cards,false);
var pos=parseInt(player.dataset.position);
var num=game.players.length+game.dead.length;
var players=game.players.concat(game.dead);
var temp;
for(var i=0;i<players.length;i++){
temp=parseInt(players[i].dataset.position)-pos;
if(temp<0) temp+=num;
players[i].dataset.position=temp;
}
game.me.node.handcards1.delete();
game.me.node.handcards2.delete();
game.me=player;
ui.handcards1=player.node.handcards1.animate('start').fix();
ui.handcards2=player.node.handcards2.animate('start').fix();
2015-11-24 15:44:21 +00:00
ui.handcards1Container.appendChild(ui.handcards1);
ui.handcards2Container.appendChild(ui.handcards2);
2015-11-04 01:59:00 +00:00
2015-12-02 15:34:34 +00:00
ui.updatehl();
2015-11-04 01:59:00 +00:00
2015-11-05 02:34:35 +00:00
game.playerMap={};
var players=game.players.concat(game.dead);
for(var i=0;i<players.length;i++){
game.playerMap[players[i].dataset.position]=players[i];
}
}
else{
console.log(player);
2015-11-04 01:59:00 +00:00
}
},
over:function(str){
var dialog=ui.create.dialog('hidden');
dialog.content.innerHTML=str;
dialog.open();
2015-11-13 01:43:16 +00:00
if(lib.config.mode=='chess'){
dialog.classList.add('center');
}
2015-11-04 01:59:00 +00:00
}
},
2015-04-29 08:41:00 +00:00
reload:function(){
if(_status){
_status.reloading=true;
}
2015-11-05 02:34:35 +00:00
if(_status.video&&!_status.replayvideo){
localStorage.removeItem(lib.configprefix+'playbackmode');
}
2015-04-29 08:41:00 +00:00
window.location.reload();
},
2015-04-29 03:25:17 +00:00
update:function(func){
lib.updates.push(func);
if(lib.updates.length===1){
game.run();
}
2015-05-11 11:57:44 +00:00
return func;
},
unupdate:function(func){
lib.updates.remove(func);
2015-04-29 03:25:17 +00:00
},
stop:function(){
cancelAnimationFrame(lib.status.frameId);
},
run:function(){
if(lib.updates.length){
cancelAnimationFrame(lib.status.frameId);
lib.status.frameId=requestAnimationFrame(function(time){
if(lib.status.time!==0){
lib.status.delayed+=time-lib.status.time;
}
lib.status.frameId=requestAnimationFrame(lib.run);
});
}
},
2015-11-04 01:59:00 +00:00
addVideo:function(type,player,content){
if(_status.video) return;
if(!_status.videoInited) return;
2015-11-30 17:37:10 +00:00
if(type=='storage'&&player&&player.updateMarks){
2015-11-28 03:45:23 +00:00
player.updateMarks();
}
2015-11-04 01:59:00 +00:00
if(game.getVideoName){
var time=get.time();
if(!_status.lastVideoLog){
_status.lastVideoLog=time;
}
if(get.itemtype(player)=='player'){
player=player.dataset.position;
}
lib.video.push({
type:type,
player:player,
content:content,
delay:time-_status.lastVideoLog
});
_status.lastVideoLog=time;
}
},
2015-04-29 03:25:17 +00:00
draw:function(func){
lib.canvasUpdates.push(func);
if(!lib.status.canvas){
lib.status.canvas=true;
game.update(lib.updateCanvas);
}
2015-09-25 00:26:16 +00:00
},
animate:{
flame:function(x,y,duration,type){
var particles=[];
var particle_count=50;
2015-09-26 13:11:55 +00:00
if(type=='thunder'||type=='recover'){
2015-09-25 05:05:26 +00:00
particle_count=30;
2015-09-25 00:26:16 +00:00
}
2015-10-20 17:44:00 +00:00
else if(type=='coin'||type=='dust'){
particle_count=50;
}
else if(type=='legend'){
particle_count=120;
}
else if(type=='epic'){
particle_count=80;
}
else if(type=='rare'){
particle_count=50;
}
2015-09-25 00:26:16 +00:00
for(var i = 0; i < particle_count; i++) {
particles.push(new particle());
}
function particle() {
this.speed = {x: -1+Math.random()*2, y: -5+Math.random()*5};
2015-10-20 17:44:00 +00:00
if(type=='thunder'||type=='coin'||type=='dust'){
2015-09-25 05:05:26 +00:00
this.speed.y=-3+Math.random()*5;
this.speed.x=-2+Math.random()*4;
}
2015-10-20 17:44:00 +00:00
if(type=='legend'||type=='rare'||type=='epic'){
this.speed.x*=3;
this.speed.y*=1.5;
}
2015-09-25 00:26:16 +00:00
this.location = {x: x, y: y};
this.radius = .5+Math.random()*1;
this.life = 10+Math.random()*10;
this.death = this.life;
switch(type){
case 'thunder':{
this.b = 255;
this.r = Math.round(Math.random()*255);
this.g = Math.round(Math.random()*255);
2015-09-25 05:05:26 +00:00
this.x+=Math.random()*20-10;
this.y+=Math.random()*20-10;
2015-09-25 00:26:16 +00:00
break;
}
case 'fire':{
this.r = 255;
this.g = Math.round(Math.random()*155);
this.b = 0;
break;
}
2015-10-20 17:44:00 +00:00
case 'coin':{
this.r = 255;
this.g = Math.round(Math.random()*25+230);
this.b = Math.round(Math.random()*100+50);
this.location.x+=Math.round(Math.random()*60)-30;
this.location.y+=Math.round(Math.random()*40)-20;
if(this.location.x<x){
this.speed.x=-Math.abs(this.speed.x);
}
else if(this.location.x>x){
this.speed.x=Math.abs(this.speed.x);
}
this.life*=1.3;
this.death*=1.3;
break;
}
case 'dust':{
this.r = Math.round(Math.random()*55)+105;
this.g = Math.round(Math.random()*55)+150;
this.b = 255;
this.location.x+=Math.round(Math.random()*60)-30;
this.location.y+=Math.round(Math.random()*40)-20;
if(this.location.x<x){
this.speed.x=-Math.abs(this.speed.x);
}
else if(this.location.x>x){
this.speed.x=Math.abs(this.speed.x);
}
this.life*=1.3;
this.death*=1.3;
break;
}
case 'legend':{
this.r = 255;
this.g = Math.round(Math.random()*100+155);
this.b = Math.round(Math.random()*100+50);
this.location.x+=Math.round(Math.random()*60)-30;
this.location.y+=Math.round(Math.random()*40)-20;
if(this.location.x<x){
this.speed.x=-Math.abs(this.speed.x);
}
else if(this.location.x>x){
this.speed.x=Math.abs(this.speed.x);
}
this.speed.x/=2;
this.speed.y/=2;
this.life*=2;
this.death*=2;
break;
}
case 'epic':{
this.r = Math.round(Math.random()*55)+200;
this.g = Math.round(Math.random()*100)+55;
this.b = 255;
this.location.x+=Math.round(Math.random()*60)-30;
this.location.y+=Math.round(Math.random()*40)-20;
if(this.location.x<x){
this.speed.x=-Math.abs(this.speed.x);
}
else if(this.location.x>x){
this.speed.x=Math.abs(this.speed.x);
}
this.speed.x/=2;
this.speed.y/=2;
this.life*=2;
this.death*=2;
break;
}
case 'rare':{
this.r = Math.round(Math.random()*55)+105;
this.g = Math.round(Math.random()*55)+150;
this.b = 255;
this.location.x+=Math.round(Math.random()*60)-30;
this.location.y+=Math.round(Math.random()*40)-20;
if(this.location.x<x){
this.speed.x=-Math.abs(this.speed.x);
}
else if(this.location.x>x){
this.speed.x=Math.abs(this.speed.x);
}
this.speed.x/=2;
this.speed.y/=2;
this.life*=2;
this.death*=2;
break;
}
2015-09-26 13:11:55 +00:00
case 'recover':{
this.g = 255;
this.r = Math.round(Math.random()*200+55);
this.b = Math.round(Math.random()*155+55);
this.location.x+=Math.round(Math.random()*60)-30;
this.location.y+=Math.round(Math.random()*40)-20;
if(this.location.x<x){
this.speed.x=-Math.abs(this.speed.x);
}
else if(this.location.x>x){
this.speed.x=Math.abs(this.speed.x);
}
this.speed.x/=2;
this.speed.y/=2;
this.life*=2;
this.death*=2;
break;
}
2015-09-25 00:26:16 +00:00
default:{
this.r = 255;
this.g = Math.round(Math.random()*155);
this.b = 0;
}
}
}
game.draw(function(time,surface){
surface.globalCompositeOperation = "source-over";
surface.globalCompositeOperation = "lighter";
for(var i = 0; i < particles.length; i++)
{
var p = particles[i];
surface.beginPath();
2015-09-25 05:05:26 +00:00
var middle=0.5;
var radius=p.radius;
2015-10-20 17:44:00 +00:00
if(type=='recover'||type=='legend'||type=='rare'||
type=='epic'||type=='coin'||type=='dust'){
2015-09-26 13:11:55 +00:00
middle=0.7;
radius/=3;
}
2015-09-25 00:26:16 +00:00
p.opacity = Math.round(p.death/p.life*100)/100
var gradient = surface.createRadialGradient(p.location.x, p.location.y, 0, p.location.x, p.location.y, p.radius);
gradient.addColorStop(0, "rgba("+p.r+", "+p.g+", "+p.b+", "+p.opacity+")");
2015-09-25 05:05:26 +00:00
gradient.addColorStop(middle, "rgba("+p.r+", "+p.g+", "+p.b+", "+p.opacity+")");
2015-09-25 00:26:16 +00:00
gradient.addColorStop(1, "rgba("+p.r+", "+p.g+", "+p.b+", 0)");
surface.fillStyle = gradient;
2015-09-25 05:05:26 +00:00
surface.arc(p.location.x, p.location.y, radius, Math.PI*2, false);
2015-09-25 00:26:16 +00:00
surface.fill();
p.death--;
2015-09-26 13:11:55 +00:00
if(type=='recover'){
p.radius+=0.5;
}
2015-10-20 17:44:00 +00:00
else if(type=='coin'||type=='dust'){
p.radius+=0.7;
}
else if(type=='legend'||type=='rare'||type=='epic'){
p.radius+=0.5;
}
2015-09-26 13:11:55 +00:00
else {
p.radius++;
}
2015-09-25 00:26:16 +00:00
p.location.x += (p.speed.x);
p.location.y += (p.speed.y);
if(p.death < 0 || p.radius < 0){
if(typeof duration=='number'&&time+500>=duration){
particles.splice(i--,1);
}
else{
particles[i] = new particle();
}
}
}
if(particles.length==0){
return false;
}
});
}
2015-04-29 03:25:17 +00:00
},
linexy:function(path){
2015-11-23 10:59:44 +00:00
// if(lib.config.mode=='chess'){
// return game._linexy.apply(this,arguments);
// }
var from=[path[0],path[1]];
var to=[path[2],path[3]];
var total=typeof arguments[1]==='number'?arguments[1]:lib.config.duration*2;
var opacity=1;
var color=[255,255,255];
2015-11-25 10:25:18 +00:00
// var dashed=lib.config.line_dash;
var dashed=false;
2015-11-23 10:59:44 +00:00
if(typeof arguments[1]=='object'){
for(var i in arguments[1]){
switch(i){
case 'opacity':opacity=arguments[1][i];break;
case 'color':color=arguments[1][i];break;
case 'dashed':dashed=arguments[1][i];break;
case 'duration':total=arguments[1][i];break;
}
}
}
else if(arguments[1]=='fire'||arguments[1]=='thunder'||arguments[1]=='green'){
color=arguments[1];
}
if(color=='fire'){
color=[255, 146, 68];
}
else if(color=='thunder'){
color=[141, 216, 255];
}
else if(color=='green'){
color=[141, 255, 216];
}
var node=ui.create.div('.linexy.hidden');
node.style.transitionDuration=(total/3000)+'s';
node.style.left=from[0]+'px';
node.style.top=from[1]+'px';
node.style.backgroundColor='rgba('+color.toString()+','+opacity+')';
var dy=to[1]-from[1];
var dx=to[0]-from[0];
var deg=Math.atan(Math.abs(dy)/Math.abs(dx))/Math.PI*180;
if(dx>=0){
if(dy<=0){
deg+=90;
}
else{
deg=90-deg;
}
}
else{
if(dy<=0){
deg=270-deg;
}
else{
deg+=270;
}
}
node.style.transform='rotate('+(-deg)+'deg) scaleY(0)';
node.style.height=get.xyDistance(from,to)+'px';
if(lib.config.mode=='chess'){
ui.chess.appendChild(node);
}
else{
ui.arena.appendChild(node);
}
ui.refresh(node);
node.show();
node.style.transform='rotate('+(-deg)+'deg) scaleY(1)';
setTimeout(function(){
node.delete();
},total/1.5);
},
_linexy:function(path){
2015-04-29 03:25:17 +00:00
var from=[path[0],path[1]];
var to=[path[2],path[3]];
var total=typeof arguments[1]==='number'?arguments[1]:lib.config.duration*2;
var opacity=1;
var color=[255,255,255];
2015-11-25 10:25:18 +00:00
// var dashed=lib.config.line_dash;
var dashed=false;
2015-04-29 03:25:17 +00:00
if(typeof arguments[1]=='object'){
for(var i in arguments[1]){
switch(i){
case 'opacity':opacity=arguments[1][i];break;
case 'color':color=arguments[1][i];break;
case 'dashed':dashed=arguments[1][i];break;
case 'duration':total=arguments[1][i];break;
}
}
}
else if(arguments[1]=='fire'||arguments[1]=='thunder'||arguments[1]=='green'){
color=arguments[1];
}
if(color=='fire'){
color=[255, 146, 68];
}
else if(color=='thunder'){
color=[141, 216, 255];
}
else if(color=='green'){
color=[141, 255, 216];
}
2015-05-08 08:07:38 +00:00
var drawfunc=function(time,ctx){
2015-04-29 03:25:17 +00:00
var current;
if(time<total/3){
ctx.strokeStyle='rgba('+color.toString()+','+opacity*(time/(total/3))+')';
current=[from[0]+(to[0]-from[0])*time/(total/3),
from[1]+(to[1]-from[1])*time/(total/3)];
}
else if(time<=total){
current=to;
if(time>total/1.5){
ctx.strokeStyle='rgba('+color.toString()+','+opacity*(1-(time-total/1.5)/(total-total/1.5))+')';
}
else{
ctx.strokeStyle='rgba('+color.toString()+','+opacity+')';
}
}
else{
return false;
}
ctx.beginPath();
2015-08-15 09:10:06 +00:00
if(dashed){
2015-07-09 05:21:22 +00:00
ctx.lineCap='butt';
2015-04-29 03:25:17 +00:00
ctx.setLineDash([8,2]);
}
2015-08-15 09:10:06 +00:00
else{
ctx.lineCap='round';
}
2015-04-29 03:25:17 +00:00
ctx.moveTo(from[0],from[1]);
ctx.lineTo(current[0],current[1]);
ctx.stroke();
2015-05-08 08:07:38 +00:00
};
if(arguments[2]&&lib.config.mode=='chess'){
game.draw2(drawfunc);
}
else{
game.draw(drawfunc);
}
2015-04-29 03:25:17 +00:00
},
createEvent:function(name,trigger){
var next={
name:name,
step:0,
finished:false,
next:[],
aiexclude:[],
2015-12-12 08:37:15 +00:00
notrigger:[],
2015-04-29 03:25:17 +00:00
custom:{
add:{},
replace:{}
},
_result:{}
}
if(trigger!==false) next._triggered=0;
for(var i in lib.element.event){
next[i]=lib.element.event[i];
}
_status.event.next.push(next);
return next;
},
2015-08-15 09:10:06 +00:00
createCard:function(name,suit,number){
if(typeof name!='string'){
name='sha';
}
if(typeof suit!='string'){
suit=['heart','diamond','club','spade'].randomGet();
}
2015-11-10 10:13:53 +00:00
else if(suit=='black'){
suit=Math.random()<0.5?'club':'spade';
}
else if(suit=='red'){
suit=Math.random()<0.5?'diamond':'heart';
}
2015-08-15 09:10:06 +00:00
if(typeof number!='number'){
number=Math.ceil(Math.random()*13);
}
return ui.create.card(ui.special).init([suit,number,name]);
},
2015-04-29 03:25:17 +00:00
over:function(result){
var i,j,k,num,table,tr,td,dialog;
_status.over=true;
ui.control.show();
ui.clear();
2015-05-14 09:23:45 +00:00
if(lib.config.background_audio){
if(result===true){
game.playAudio('effect','win');
}
else if(result===false){
game.playAudio('effect','lose');
}
else{
game.playAudio('effect','tie');
}
}
2015-04-29 03:25:17 +00:00
if(result===true) result='战斗胜利';
if(result===false) result='战斗失败';
if(result==undefined) result='战斗结束';
dialog=ui.create.dialog(result);
2015-10-20 17:44:00 +00:00
if(game.addOverDialog){
game.addOverDialog(dialog,result);
}
2015-04-29 07:54:48 +00:00
if(true){
2015-04-29 03:25:17 +00:00
if(game.players.length){
table=document.createElement('table');
tr=document.createElement('tr');
tr.appendChild(document.createElement('td'));
td=document.createElement('td');
td.innerHTML='伤害';
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML='受伤';
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML='摸牌';
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML='出牌';
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML='杀敌';
tr.appendChild(td);
table.appendChild(tr);
for(i=0;i<game.players.length;i++){
tr=document.createElement('tr');
td=document.createElement('td');
td.innerHTML=get.translation(game.players[i]);
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.players[i].stat.length;j++){
if(game.players[i].stat[j].damage!=undefined) num+=game.players[i].stat[j].damage;
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.players[i].stat.length;j++){
if(game.players[i].stat[j].damaged!=undefined) num+=game.players[i].stat[j].damaged;
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.players[i].stat.length;j++){
if(game.players[i].stat[j].gain!=undefined) num+=game.players[i].stat[j].gain;
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.players[i].stat.length;j++){
for(k in game.players[i].stat[j].card){
num+=game.players[i].stat[j].card[k];
}
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.players[i].stat.length;j++){
if(game.players[i].stat[j].kill!=undefined) num+=game.players[i].stat[j].kill;
}
td.innerHTML=num;
tr.appendChild(td);
table.appendChild(tr);
}
dialog.add(ui.create.div('.placeholder'));
dialog.content.appendChild(table);
}
if(game.dead.length){
table=document.createElement('table');
table.style.opacity='0.5';
if(game.players.length==0){
tr=document.createElement('tr');
tr.appendChild(document.createElement('td'));
td=document.createElement('td');
td.innerHTML='伤害';
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML='受伤';
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML='摸牌';
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML='出牌';
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML='杀敌';
tr.appendChild(td);
table.appendChild(tr);
}
for(i=0;i<game.dead.length;i++){
tr=document.createElement('tr');
td=document.createElement('td');
td.innerHTML=get.translation(game.dead[i]);
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.dead[i].stat.length;j++){
if(game.dead[i].stat[j].damage!=undefined) num+=game.dead[i].stat[j].damage;
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.dead[i].stat.length;j++){
if(game.dead[i].stat[j].damaged!=undefined) num+=game.dead[i].stat[j].damaged;
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.dead[i].stat.length;j++){
if(game.dead[i].stat[j].gain!=undefined) num+=game.dead[i].stat[j].gain;
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.dead[i].stat.length;j++){
for(k in game.dead[i].stat[j].card){
num+=game.dead[i].stat[j].card[k];
}
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.dead[i].stat.length;j++){
if(game.dead[i].stat[j].kill!=undefined) num+=game.dead[i].stat[j].kill;
}
td.innerHTML=num;
tr.appendChild(td);
table.appendChild(tr);
}
dialog.add(ui.create.div('.placeholder'));
dialog.content.appendChild(table);
}
2015-05-05 14:57:35 +00:00
if(game.additionaldead&&game.additionaldead.length){
table=document.createElement('table');
table.style.opacity='0.5';
for(i=0;i<game.additionaldead.length;i++){
tr=document.createElement('tr');
td=document.createElement('td');
td.innerHTML=get.translation(game.additionaldead[i]);
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.additionaldead[i].stat.length;j++){
if(game.additionaldead[i].stat[j].damage!=undefined) num+=game.additionaldead[i].stat[j].damage;
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.additionaldead[i].stat.length;j++){
if(game.additionaldead[i].stat[j].damaged!=undefined) num+=game.additionaldead[i].stat[j].damaged;
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.additionaldead[i].stat.length;j++){
if(game.additionaldead[i].stat[j].gain!=undefined) num+=game.additionaldead[i].stat[j].gain;
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.additionaldead[i].stat.length;j++){
for(k in game.additionaldead[i].stat[j].card){
num+=game.additionaldead[i].stat[j].card[k];
}
}
td.innerHTML=num;
tr.appendChild(td);
td=document.createElement('td');
num=0;
for(j=0;j<game.additionaldead[i].stat.length;j++){
if(game.additionaldead[i].stat[j].kill!=undefined) num+=game.additionaldead[i].stat[j].kill;
}
td.innerHTML=num;
tr.appendChild(td);
table.appendChild(tr);
}
dialog.add(ui.create.div('.placeholder'));
dialog.content.appendChild(table);
}
2015-04-29 03:25:17 +00:00
}
dialog.add(ui.create.div('.placeholder'));
dialog.add(ui.create.div('.placeholder'));
2015-11-04 01:59:00 +00:00
game.addVideo('over',null,dialog.content.innerHTML);
var vinum=parseInt(lib.config.video);
if(!_status.video&&vinum&&game.getVideoName&&window.indexedDB){
var store=lib.db.transaction(['video'],'readwrite').objectStore('video');
2015-11-28 03:45:23 +00:00
var videos=lib.videos.slice(0);
for(var i=0;i<videos.length;i++){
if(videos[i].starred){
videos.splice(i--,1);
}
}
for(var deletei=0;deletei<5;deletei++){
if(videos.length>=vinum){
var toremove=videos.pop();
lib.videos.remove(toremove);
store.delete(toremove.time);
}
else{
break;
}
2015-11-04 01:59:00 +00:00
}
var newvid={
name:game.getVideoName(),
mode:lib.config.mode,
video:lib.video,
win:result=='战斗胜利',
name1:game.me.name1||game.me.name,
name2:game.me.name2,
time:lib.getUTC(new Date())
};
lib.videos.unshift(newvid);
store.put(newvid);
2015-11-06 10:05:08 +00:00
lib.createVideoNode(newvid,true);
2015-11-04 01:59:00 +00:00
}
2015-11-06 10:05:08 +00:00
// _status.auto=false;
2015-11-05 02:34:35 +00:00
if(ui.auto){
2015-11-06 10:05:08 +00:00
// ui.auto.classList.remove('glow');
2015-11-05 02:34:35 +00:00
ui.auto.hide();
}
2015-10-20 17:44:00 +00:00
if(ui.wuxie) ui.wuxie.hide();
2015-11-04 01:59:00 +00:00
if(lib.storage.test){
setTimeout(game.reload,500);
}
2015-10-20 17:44:00 +00:00
if(game.controlOver){
game.controlOver();return;
}
2015-11-06 10:05:08 +00:00
// if(!ui.savevideo&&lib.db&&lib.config.savevideo){
// ui.savevideo=ui.create.control('保存录像',game.saveVideo);
// }
2015-04-29 03:25:17 +00:00
if(!ui.restart){
2015-04-29 08:41:00 +00:00
ui.restart=ui.create.control('restart',game.reload);
2015-04-29 03:25:17 +00:00
}
if(ui.revive){
ui.revive.close();
delete ui.revive;
}
if(ui.swap){
ui.swap.close();
delete ui.swap;
}
if(game.onOver) game.onOver(result);
},
loop:function(){
var event=_status.event;
var step=event.step;
var source=event.source;
var player=event.player;
var target=event.target;
var targets=event.targets;
var card=event.card;
var cards=event.cards;
var skill=event.skill;
var forced=event.forced;
var num=event.num;
var trigger=event._trigger;
var result=event._result;
2015-11-04 01:59:00 +00:00
if(_status.paused2||_status.imchoosing){
if(!lib.status.dateDelaying){
lib.status.dateDelaying=new Date();
}
2015-04-29 03:25:17 +00:00
}
2015-11-04 01:59:00 +00:00
if(_status.paused||_status.paused2||_status.over){
2015-04-29 03:25:17 +00:00
return;
}
2015-11-04 01:59:00 +00:00
if(lib.status.dateDelaying){
lib.status.dateDelayed+=lib.getUTC(new Date())-lib.getUTC(lib.status.dateDelaying);
delete lib.status.dateDelaying;
}
2015-04-29 03:25:17 +00:00
if(event.next.length>0){
var next=event.next.shift();
if(next.player&&next.player.skipList.contains(next.name)){
next.player.skipList.remove(next.name);
}
else{
next.parent=event;
_status.event=next;
}
}
else if(event.finished){
if(event._triggered==1){
if(event.type=='card') event.trigger('useCardToCancelled');
event.trigger(event.name+'Cancelled');
event._triggered=4;
}
else if(event._triggered==2){
if(event.type=='card') event.trigger('useCardToEnd');
event.trigger(event.name+'End');
event._triggered=3;
}
else if(event._triggered==3){
if(event.type=='card') event.trigger('useCardToAfter');
event.trigger(event.name+'After');
event._triggered++;
}
else{
if(event.parent){
if(event.result){
event.parent._result=event.result;
}
_status.event=event.parent;
}
else{
return;
}
}
}
else{
if(event._triggered==0){
if(event.type=='card') event.trigger('useCardToBefore');
event.trigger(event.name+'Before');
event._triggered++;
}
else if(event._triggered==1){
if(event.type=='card') event.trigger('useCardToBegin');
event.trigger(event.name+'Begin');
event._triggered++;
}
else{
if(player&&player.classList.contains('dead')&&event.name!='phaseLoop'){
2015-11-09 03:15:16 +00:00
while(_status.dieClose.length){
_status.dieClose.shift().close();
}
2015-04-29 03:25:17 +00:00
event.finish();
}
else if(player&&player.removed&&event.name!='phaseLoop'){
event.finish();
}
else if(player&&player.isOut()&&event.name!='phaseLoop'){
event.finish();
}
else{
eval(lib.init.parse(event.content))();
}
event.step++;
}
}
game.loop();
},
pause:function(){
clearTimeout(_status.timeout);
_status.paused=true;
},
pause2:function(){
_status.paused2=true;
},
resume:function(){
if(_status.paused){
_status.paused=false;
game.loop();
}
},
resume2:function(){
if(_status.paused2){
_status.paused2=false;
game.loop();
}
},
delay:function(time,time2){
if(_status.paused) return;
game.pause();
if(time==undefined) time=1;
if(time2==undefined) time2=0;
time=time*lib.config.duration+time2;
2015-11-21 13:23:23 +00:00
if(lib.config.speed=='vvfast') time/=3;
2015-04-29 03:25:17 +00:00
_status.timeout=setTimeout(game.resume,time);
},
2015-11-05 02:34:35 +00:00
delayx:function(time,time2){
2015-10-30 09:13:19 +00:00
if(typeof time!='number') time=1;
switch(lib.config.game_speed){
case 'vslow':time*=2.5;break;
case 'slow':time*=1.5;break;
case 'fast':time*=0.7;break;
case 'vfast':time*=0.4;break;
2015-11-21 13:23:23 +00:00
case 'vvfast':time*=0.2;break;
2015-10-30 09:13:19 +00:00
}
2015-11-05 02:34:35 +00:00
return game.delay(time,time2);
2015-10-30 09:13:19 +00:00
},
2015-04-29 03:25:17 +00:00
check:function(event){
var i,j,range;
if(event==undefined) event=_status.event;
var custom=event.custom||{};
var ok=true,auto=true;
var player=event.player;
if(!event.filterButton&&!event.filterCard&&!event.filterTarget&&!event.skill) return;
if(event.filterButton){
var dialog=event.dialog;
range=get.select(event.selectButton);
if(range[0]!=range[1]||range[0]>1) auto=false;
for(i=0;i<dialog.buttons.length;i++){
if(event.filterButton(dialog.buttons[i],player)&&lib.filter.buttonIncluded(dialog.buttons[i])){
if(ui.selected.buttons.length<range[1]){
dialog.buttons[i].classList.add('selectable');
}
else if(range[1]==-1){
dialog.buttons[i].classList.add('selected');
ui.selected.buttons.add(dialog.buttons[i]);
}
else{
dialog.buttons[i].classList.remove('selectable');
}
}
else{
dialog.buttons[i].classList.remove('selectable');
if(range[1]==-1){
dialog.buttons[i].classList.remove('selected');
ui.selected.buttons.remove(dialog.buttons[i]);
}
}
if(dialog.buttons[i].classList.contains('selected')){
dialog.buttons[i].classList.add('selectable');
}
}
if(ui.selected.buttons.length<range[0]){
if(!event.forced||get.selectableButtons().length)
ok=false;
if(event.complexSelect||event.parent.name=='chooseCharacter') ok=false;
}
if(custom.add.button){
custom.add.button();
}
}
if(event.filterCard){
if(ok==false){
game.uncheck('card');
}
else{
var cards;
if(event.position){
cards=player.get(event.position);
}
else{
cards=player.get('h');
}
range=get.select(event.selectCard);
if(range[0]!=range[1]||range[0]>1) auto=false;
for(i=0;i<cards.length;i++){
if(event.filterCard(cards[i],player)&&
lib.filter.cardAiIncluded(cards[i])&&
(player.isOut()==false||event.includeOutCard)&&
lib.filter.cardRespondable(cards[i],player)){
if(ui.selected.cards.length<range[1]){
cards[i].classList.add('selectable');
}
else if(range[1]==-1){
cards[i].classList.add('selected');
ui.selected.cards.add(cards[i]);
}
else{
cards[i].classList.remove('selectable');
}
}
else{
cards[i].classList.remove('selectable');
if(range[1]==-1){
cards[i].classList.remove('selected');
ui.selected.cards.remove(cards[i]);
}
}
if(cards[i].classList.contains('selected')){
cards[i].classList.add('selectable');
}
}
if(ui.selected.cards.length<range[0]){
if(!event.forced||get.selectableCards().length)
ok=false;
if(event.complexSelect) ok=false;
}
}
if(custom.add.card){
custom.add.card();
}
}
if(event.filterTarget){
if(ok==false){
game.uncheck('target');
}
else{
var card=get.card();
range=get.select(event.selectTarget);
if(range[0]!=range[1]||range[0]>1) auto=false;
for(i=0;i<game.players.length;i++){
2015-05-08 08:07:38 +00:00
var nochess=true;
2015-10-08 06:16:37 +00:00
if(lib.config.mode=='chess'&&!event.chessForceAll){
2015-05-08 08:07:38 +00:00
if(player&&get.distance(player,game.players[i],'pure')>7){
nochess=false;
}
}
2015-11-09 03:15:16 +00:00
if(event.filterTarget(card,player,game.players[i])&&!game.players[i].forceout&&
2015-05-08 08:07:38 +00:00
(game.players[i].isOut()==false||event.includeOutTarget)&&nochess){
2015-04-29 03:25:17 +00:00
if(ui.selected.targets.length<range[1]){
game.players[i].classList.add('selectable');
}
else if(range[1]==-1){
game.players[i].classList.add('selected');
ui.selected.targets.add(game.players[i]);
}
else{
game.players[i].classList.remove('selectable');
}
}
else{
game.players[i].classList.remove('selectable');
if(range[1]==-1){
game.players[i].classList.remove('selected');
ui.selected.targets.remove(game.players[i]);
}
}
if(game.players[i].classList.contains('selected')){
game.players[i].classList.add('selectable');
}
2015-05-11 11:57:44 +00:00
if(game.players[i].instance){
if(game.players[i].classList.contains('selected')){
game.players[i].instance.classList.add('selected');
}
else{
game.players[i].instance.classList.remove('selected');
}
if(game.players[i].classList.contains('selectable')){
game.players[i].instance.classList.add('selectable');
}
else{
game.players[i].instance.classList.remove('selectable');
}
}
2015-04-29 03:25:17 +00:00
}
if(ui.selected.targets.length<range[0]){
if(!event.forced||get.selectableTargets().length)
ok=false;
if(event.complexSelect) ok=false;
}
2015-05-08 13:37:34 +00:00
if(range[1]==-1&&ui.selected.targets.length==0&&event.targetRequired){
ok=false;
}
2015-04-29 03:25:17 +00:00
}
if(custom.add.target){
custom.add.target();
}
}
if(!event.skill&&get.noSelected()&&!_status.noconfirm){
var skills=[],enable,info;
var skills2=player.get('s').concat(player.hiddenSkills).concat(lib.skill.global);
game.expandSkills(skills2);
for(i=0;i<skills2.length;i++){
info=get.info(skills2[i]);
enable=false;
if(typeof info.enable=='function') enable=info.enable(event);
else if(typeof info.enable=='object') enable=info.enable.contains(event.name);
else if(info.enable=='phaseUse') enable=(event.parent.name=='phaseUse');
else if(typeof info.enable=='string') enable=(info.enable==event.name);
if(enable){
if(info.filter&&info.filter(event,player)==false) enable=false;
if(info.viewAs&&event.filterCard&&!event.filterCard(info.viewAs,player)) enable=false;
2015-06-27 16:21:25 +00:00
if(info.viewAs&&info.viewAsFilter&&info.viewAsFilter(player)==false) enable=false;
2015-04-29 03:25:17 +00:00
if(event.aiexclude.contains(skills2[i])) enable=false;
if(info.usable&&get.skillCount(skills2[i])>=info.usable) enable=false;
}
if(enable){
skills.add(skills2[i]);
}
}
2015-11-30 13:08:29 +00:00
var globalskills=[];
2015-11-30 17:37:10 +00:00
var globallist=lib.skill.global.slice(0);
game.expandSkills(globallist);
2015-11-30 13:08:29 +00:00
for(var i=0;i<skills.length;i++){
2015-11-30 17:37:10 +00:00
if(globallist.contains(skills[i])){
2015-11-30 13:08:29 +00:00
globalskills.push(skills.splice(i--,1)[0]);
}
}
var equipskills=[];
var ownedskills=player.get('s',true,false);
2015-11-30 17:37:10 +00:00
game.expandSkills(ownedskills);
2015-11-30 13:08:29 +00:00
for(var i=0;i<skills.length;i++){
if(!ownedskills.contains(skills[i])){
equipskills.push(skills.splice(i--,1)[0]);
}
}
if(equipskills.length){
ui.create.skills3(equipskills);
}
else if(ui.skills3){
ui.skills3.close();
}
2015-04-29 03:25:17 +00:00
if(skills.length){
ui.create.skills(skills);
}
else if(ui.skills){
ui.skills.close();
}
2015-11-30 13:08:29 +00:00
if(globalskills.length){
ui.create.skills2(globalskills);
}
else if(ui.skills2){
ui.skills2.close();
}
2015-04-29 03:25:17 +00:00
}
2015-11-30 13:08:29 +00:00
else{
if(ui.skills){
ui.skills.close()
}
if(ui.skills2){
ui.skills2.close()
}
if(ui.skills3){
ui.skills3.close()
}
2015-04-29 03:25:17 +00:00
}
_status.multitarget=false;
2015-05-10 05:34:37 +00:00
var skillinfo=get.info(_status.event.skill);
2015-04-29 03:25:17 +00:00
if(_status.event.name=='chooseToUse'){
if(skillinfo&&skillinfo.multitarget&&!skillinfo.multiline){
_status.multitarget=true;
}
if((skillinfo&&skillinfo.viewAs)||!_status.event.skill){
var cardinfo=get.info(get.card());
if(cardinfo&&cardinfo.multitarget&&!cardinfo.multiline){
_status.multitarget=true;
}
}
}
else if(_status.event.multitarget){
_status.multitarget=true;
}
if(event.isMine()){
2015-11-09 03:15:16 +00:00
if(lib.config.mode=='chess'&&game.me&&get.config('show_distance')){
for(var i=0;i<game.players.length;i++){
if(game.players[i]==game.me){
game.players[i].node.action.hide();
}
else{
game.players[i].node.action.show();
var dist=get.distance(game.me,game.players[i],'pure');
var dist2=get.distance(game.me,game.players[i]);
game.players[i].node.action.innerHTML='距离:'+dist2+'/'+dist;
if(dist>7){
game.players[i].node.action.classList.add('thunder');
}
else{
game.players[i].node.action.classList.remove('thunder');
}
}
}
}
2015-12-03 16:28:06 +00:00
if(ok&&auto&&lib.config.auto_confirm&&(!_status.mousedragging||!_status.mouseleft)&&
!_status.mousedown&&!_status.touchnocheck){
2015-05-10 05:34:37 +00:00
if(ui.confirm){
if(!skillinfo||!skillinfo.preservecancel){
ui.confirm.close();
}
}
2015-04-29 03:25:17 +00:00
if(event.skillDialog==true) event.skillDialog=false;
ui.click.ok();
_status.mousedragging=null;
}
else{
ui.arena.classList.add('selecting');
_status.imchoosing=true;
2015-11-21 05:30:26 +00:00
if(!_status.noconfirm&&!_status.event.noconfirm){
2015-04-29 03:25:17 +00:00
if(!_status.mousedown||_status.mouseleft){
var str='';
if(ok) str+='o';
if(!event.forced&&get.noSelected()) str+='c';
ui.create.confirm(str);
}
2015-11-23 10:59:44 +00:00
}
}
if(ui.confirm&&ui.confirm.lastChild.link=='cancel'){
if(_status.event.parent.name=='phaseUse'&&!_status.event.skill){
ui.confirm.lastChild.innerHTML='结束';
}
else{
ui.confirm.lastChild.innerHTML='取消';
2015-04-29 03:25:17 +00:00
}
}
}
return ok;
},
uncheck:function(){
2015-11-29 11:46:51 +00:00
// ui.roundmenu.show();
2015-04-29 03:25:17 +00:00
var i,j;
2015-05-08 13:37:34 +00:00
if(false){
if(lib.config.mode=='chess'){
var shadows=ui.chessContainer.getElementsByClassName('playergrid temp');
while(shadows.length){
shadows[0].remove();
}
}
}
2015-04-29 03:25:17 +00:00
if(arguments.length==0){
while(document.getElementsByClassName('selectable').length>0){
document.getElementsByClassName('selectable')[0].classList.remove('selectable');
}
while(document.getElementsByClassName('selected').length>0){
document.getElementsByClassName('selected')[0].classList.remove('selected');
}
if(_status.event.player){
var cards=_status.event.player.get('hej');
for(j=0;j<cards.length;j++){
cards[j].classList.remove('selected');
cards[j].classList.remove('selectable');
}
}
ui.selected.buttons.length=0;
ui.selected.cards.length=0;
ui.selected.targets.length=0;
}
else{
for(i=0;i<arguments.length;i++){
if(arguments[i]=='target'){
for(j=0;j<game.players.length;j++){
game.players[j].classList.remove('selected');
game.players[j].classList.remove('selectable');
2015-05-11 11:57:44 +00:00
if(game.players[j].instance){
game.players[j].instance.classList.remove('selected');
game.players[j].instance.classList.remove('selectable');
}
2015-04-29 03:25:17 +00:00
}
ui.selected.targets.length=0;
}
else if(arguments[i]=='card'){
var cards=_status.event.player.get('hej');
for(j=0;j<cards.length;j++){
cards[j].classList.remove('selected');
cards[j].classList.remove('selectable');
}
ui.selected.cards.length=0;
}
}
}
2015-07-09 05:21:22 +00:00
if(arguments[0]!='target'&&arguments[0]!='card'&&arguments[0]!='button'){
ui.arena.classList.remove('selecting');
_status.imchoosing=false;
_status.lastdragchange.length=0;
_status.mousedragging=null;
_status.mousedragorigin=null;
2015-12-03 16:28:06 +00:00
while(ui.touchlines.length){
ui.touchlines.shift().delete();
}
2015-07-09 05:21:22 +00:00
}
2015-04-29 03:25:17 +00:00
ui.canvas.width=ui.arena.offsetWidth;
ui.canvas.height=ui.arena.offsetHeight;
for(var i=0;i<game.players.length;i++){
game.players[i].unprompt();
}
},
swapSeat:function(player1,player2,prompt,behind){
if(behind){
2015-05-04 03:17:03 +00:00
var totalPopulation=game.players.length+game.dead.length+1;
2015-05-05 14:57:35 +00:00
for(var iwhile=0;iwhile<totalPopulation;iwhile++){
2015-05-04 03:17:03 +00:00
if(player1.next!=player2){
game.swapSeat(player1,player1.next,false,false);
}
else{
break;
}
2015-04-29 03:25:17 +00:00
}
if(prompt!=false){
2015-12-08 13:54:44 +00:00
game.log(player1,'将座位移至',player2,'后');
2015-04-29 03:25:17 +00:00
}
}
else{
2015-11-04 01:59:00 +00:00
game.addVideo('swapSeat',null,[player1.dataset.position,player2.dataset.position]);
2015-04-29 03:25:17 +00:00
var temp1,pos,i,num;
temp1=player1.dataset.position;
player1.dataset.position=player2.dataset.position;
player2.dataset.position=temp1;
game.arrangePlayers();
2015-05-08 08:07:38 +00:00
if(lib.config.mode!='chess'){
if(player1.dataset.position=='0'||player2.dataset.position=='0'){
pos=parseInt(player1.dataset.position);
if(pos==0) pos=parseInt(player2.dataset.position);
num=game.players.length+game.dead.length;
for(i=0;i<game.players.length;i++){
temp1=parseInt(game.players[i].dataset.position)-pos;
if(temp1<0) temp1+=num;
game.players[i].dataset.position=temp1;
}
for(i=0;i<game.dead.length;i++){
temp1=parseInt(game.dead[i].dataset.position)-pos;
if(temp1<0) temp1+=num;
game.dead[i].dataset.position=temp1;
}
2015-04-29 03:25:17 +00:00
}
}
if(prompt!=false){
2015-12-08 13:54:44 +00:00
game.log(player1,'和',player2,'交换了座位');
2015-04-29 03:25:17 +00:00
}
}
},
swapPlayer:function(player,player2){
if(player2){
if(player==game.me) game.swapPlayer(player2);
else if(player2==game.me) game.swapPlayer(player);
}
else{
if(player==game.me) return;
2015-11-04 01:59:00 +00:00
game.addVideo('swapPlayer',player,get.cardsInfo(player.get('h')));
2015-04-29 03:25:17 +00:00
var pos=parseInt(player.dataset.position);
var num=game.players.length+game.dead.length;
var players=game.players.concat(game.dead);
var temp;
for(var i=0;i<players.length;i++){
temp=parseInt(players[i].dataset.position)-pos;
if(temp<0) temp+=num;
players[i].dataset.position=temp;
}
game.me.node.handcards1.delete();
game.me.node.handcards2.delete();
game.me=player;
2015-04-29 14:56:33 +00:00
ui.handcards1=player.node.handcards1.animate('start').fix();
ui.handcards2=player.node.handcards2.animate('start').fix();
2015-11-24 15:44:21 +00:00
ui.handcards1Container.appendChild(ui.handcards1);
ui.handcards2Container.appendChild(ui.handcards2);
2015-04-29 03:25:17 +00:00
2015-12-02 15:34:34 +00:00
ui.updatehl();
2015-04-29 03:25:17 +00:00
}
if(game.me.isAlive()){
if(ui.auto) ui.auto.show();
if(ui.wuxie) ui.wuxie.show();
2015-04-29 03:25:17 +00:00
if(ui.revive){
ui.revive.close();
delete ui.revive;
}
if(ui.swap){
ui.swap.close();
delete ui.swap;
}
if(ui.restart){
ui.restart.close();
delete ui.restart;
}
}
2015-10-31 10:14:14 +00:00
if(lib.config.mode=='identity'){
game.me.setIdentity(game.me.identity);
}
2015-04-29 03:25:17 +00:00
},
swapControl:function(player){
if(player==game.me) return;
2015-12-01 05:46:28 +00:00
game.me.node.handcards1.remove();
game.me.node.handcards2.remove();
2015-04-29 03:25:17 +00:00
game.me=player;
2015-04-29 14:56:33 +00:00
ui.handcards1=player.node.handcards1.animate('start').fix();
ui.handcards2=player.node.handcards2.animate('start').fix();
2015-11-25 12:34:54 +00:00
ui.handcards1Container.insertBefore(ui.handcards1,ui.handcards1Container.firstChild);
ui.handcards2Container.insertBefore(ui.handcards2,ui.handcards2Container.firstChild);
2015-12-02 15:34:34 +00:00
ui.updatehl();
2015-11-04 01:59:00 +00:00
game.addVideo('swapControl',player,get.cardsInfo(player.get('h')));
2015-05-05 09:23:31 +00:00
if(game.me.isAlive()){
if(ui.auto) ui.auto.show();
if(ui.wuxie) ui.wuxie.show();
2015-05-05 09:23:31 +00:00
if(ui.revive){
ui.revive.close();
delete ui.revive;
}
if(ui.swap){
ui.swap.close();
delete ui.swap;
}
if(ui.restart){
ui.restart.close();
delete ui.restart;
}
}
2015-04-29 03:25:17 +00:00
},
2015-05-12 09:51:40 +00:00
findNext:function(player){
var players=get.players(lib.sort.position);
var position=parseInt(player.dataset.position);
for(var i=0;i<players.length;i++){
if(parseInt(players[i].dataset.position)>=position){
return players[i];
}
}
return players[0];
},
2015-04-29 03:25:17 +00:00
phaseLoop:function(player){
var next=game.createEvent('phaseLoop');
next.player=player;
next.content=function(){
"step 0"
player.phase();
"step 1"
2015-05-12 09:51:40 +00:00
if(!game.players.contains(event.player.next)){
event.player=game.findNext(event.player.next);
2015-04-29 03:25:17 +00:00
}
else{
event.player=event.player.next;
}
event.goto(0);
}
},
gameDraw:function(player,num){
var next=game.createEvent('gameDraw');
next.player=player;
if(num==undefined) next.num=4;
else next.num=num;
next.content=function(){
"step 0"
var end=player;
2015-12-12 08:37:15 +00:00
var numx=num;
2015-04-29 03:25:17 +00:00
do{
2015-12-12 08:37:15 +00:00
if(typeof num=='function'){
numx=num(player);
}
player.directgain(get.cards(numx));
2015-11-09 17:04:18 +00:00
if(player.singleHp===true&&lib.config.mode!='guozhan'){
2015-04-29 10:02:31 +00:00
player.doubleDraw();
}
2015-04-29 03:25:17 +00:00
player=player.next;
}
while(player!=end);
"step 1"
if(get.config('change_card')){
event.dialog=ui.create.dialog('是否使用手气卡?');
ui.create.confirm('oc');
event.custom.replace.confirm=function(bool){
_status.event.bool=bool;
game.resume();
}
}
else{
event.finish();
}
"step 2"
game.pause();
"step 3"
if(event.bool){
game.me.lose(game.me.get('h'))._triggered=null;
2015-04-29 03:25:17 +00:00
}
else{
event.dialog.close();
ui.confirm.close();
event.finish();
}
"step 4"
game.delay();
game.me.gain(get.cards(4))._triggered=null;
2015-04-29 03:25:17 +00:00
"step 5"
event.goto(2);
}
},
asyncDraw:function(players,num){
for(var i=0;i<players.length;i++){
var num2=1;
if(typeof num=='number'){
num2=num;
}
else if(Array.isArray(num)){
num2=num[i];
}
players[i].draw(num2,false);
players[i].$draw(num2);
}
},
finishCards:function(){
var i,j,k;
for(i in lib.card){
var card=lib.card[i];
if(card.type=='equip'){
if(card.enable==undefined) card.enable=true;
if(card.selectTarget==undefined) card.selectTarget=-1;
if(card.filterTarget==undefined) card.filterTarget=function(card,player,target){
return target==player;
};
if(card.content==undefined) card.content=function(){
target.equip(card);
};
if(card.ai==undefined) card.ai={basic:{}};
if(card.ai.basic==undefined) card.ai.basic={};
if(card.ai.result==undefined) card.ai.result={target:1.5};
2015-11-06 10:05:08 +00:00
if(card.ai.basic.order==undefined) card.ai.basic.order=function(card,player){
return 8+ai.get.equipValue(card,player)/20;
};
2015-04-29 03:25:17 +00:00
if(card.ai.basic.useful==undefined) card.ai.basic.useful=2;
if(card.subtype=='equip3'){
if(card.ai.basic.equipValue==undefined) card.ai.basic.equipValue=6;
}
else if(card.subtype=='equip4'){
if(card.ai.basic.equipValue==undefined) card.ai.basic.equipValue=5;
}
else{
if(card.ai.basic.equipValue==undefined) card.ai.basic.equipValue=1;
}
if(card.ai.basic.value==undefined)card.ai.basic.value=function(card,player){
var value=0;
var info=get.info(card);
if(player.get('e',info.subtype[5])&&card!=player.get('e',info.subtype[5])){
value=ai.get.value(player.get('e',info.subtype[5]),player);
}
var equipValue=info.ai.equipValue||info.ai.basic.equipValue;
if(typeof equipValue=='function') return equipValue(card,player)-value;
return equipValue-value;
}
card.ai.result.target=function(player,target){
var card=get.card();
if(card==undefined) return 0;
var value1=ai.get.value(card,target);
var value2=0;
if(target[get.subtype(card)]&&target[get.subtype(card)]!=card)
value2=ai.get.value(target[get.subtype(card)],target);
if(value1>value2) return 1;
return -1;
};
}
else if(card.type=='delay'){
if(card.enable==undefined) card.enable=true;
if(card.filterTarget==undefined) card.filterTarget=lib.filter.judge;
if(card.content==undefined) card.content=function(){
target.addJudge(card,cards);
};
}
}
for(i in lib.skill){
if(lib.skill[i].forbid&&lib.skill[i].forbid.contains(lib.config.mode)){
lib.skill[i]={};
if(lib.translate[i+'_info']){
lib.translate[i+'_info']='此模式下不可用';
}
continue;
}
if(lib.skill[i].mode&&lib.skill[i].mode.contains(lib.config.mode)==false){
lib.skill[i]={};
if(lib.translate[i+'_info']){
lib.translate[i+'_info']='此模式下不可用';
}
continue;
}
if(lib.skill[i].viewAs){
if(lib.skill[i].ai==undefined) lib.skill[i].ai={};
var skill=lib.skill[i].ai;
var card=lib.card[lib.skill[i].viewAs.name].ai;
for(j in card){
if(skill[j]==undefined) skill[j]=card[j];
else if(typeof skill[j]=='object'){
for(var k in card[j]){
if(skill[j][k]==undefined) skill[j][k]=card[j][k];
}
}
}
}
if(lib.skill[i].inherit){
var skill=lib.skill[lib.skill[i].inherit];
for(j in skill){
if(lib.skill[i][j]==undefined) lib.skill[i][j]=skill[j];
}
if(lib.translate[i+'_info']==undefined){
lib.translate[i+'_info']=lib.translate[lib.skill[i].inherit+'_info'];
}
}
2015-12-11 05:07:11 +00:00
if(lib.skill[i].subSkill){
for(var j in lib.skill[i].subSkill){
lib.skill[i+'_'+j]=lib.skill[i].subSkill[j];
2015-12-06 15:23:47 +00:00
lib.translate[i+'_'+j]=lib.translate[i];
}
}
2015-04-29 03:25:17 +00:00
if(i[0]=='_'){
lib.skill.global.add(i);
}
}
},
checkMod:function(){
var name=arguments[arguments.length-2];
var skills=arguments[arguments.length-1].concat(lib.skill.global);
game.expandSkills(skills);
var arg=[],i,info;
for(i=0;i<arguments.length-2;i++){
arg.push(arguments[i]);
}
for(i=0;i<skills.length;i++){
info=get.info(skills[i]);
if(info.mod&&info.mod[name]){
var result=info.mod[name].apply(this,arg);
if(typeof arg[arg.length-1]!='object'&&result!=undefined) arg[arg.length-1]=result;
}
}
return arg[arg.length-1];
},
prepareArena:function(num){
ui.create.players(num);
ui.create.me();
ui.create.cards();
game.finishCards();
},
log:function(str){
2015-12-08 13:54:44 +00:00
var str='';
for(var i=0;i<arguments.length;i++){
var itemtype=get.itemtype(arguments[i]);
if(itemtype=='player'||itemtype=='players'){
if(lib.config.log_highlight){
str+='<span class="bluetext">'+get.translation(arguments[i])+'</span>';
}
else{
str+=get.translation(arguments[i]);
}
}
else if(itemtype=='cards'||itemtype=='card'||(typeof arguments[i]=='object'&&arguments[i].name)){
if(lib.config.log_highlight){
str+='<span class="yellowtext">'+get.translation(arguments[i])+'</span>';
}
else{
str+=get.translation(arguments[i]);
}
}
else if(typeof arguments[i]=='object'){
str+=get.translation(arguments[i]);
}
else if(typeof arguments[i]=='string'&&arguments[i][0]=='【'&&arguments[i][arguments[i].length-1]=='】'){
if(lib.config.log_highlight){
str+='<span class="greentext">'+get.translation(arguments[i])+'</span>';
}
else{
str+=get.translation(arguments[i]);
}
}
else{
str+=arguments[i];
}
}
2015-04-29 03:25:17 +00:00
var node=ui.create.div();
node.innerHTML=str;
ui.sidebar.insertBefore(node,ui.sidebar.firstChild);
2015-11-04 01:59:00 +00:00
game.addVideo('log',null,str);
2015-04-29 03:25:17 +00:00
if(lib.config.title) document.title=str;
2015-12-07 11:15:35 +00:00
if(lib.config.show_log!='off'&&lib.config.mode!='chess'){
ui.arenalog.insertBefore(node.cloneNode(true),ui.arenalog.firstChild);
while(ui.arenalog.childNodes.length&&ui.arenalog.scrollHeight>ui.arenalog.offsetHeight){
ui.arenalog.lastChild.remove();
}
}
2015-04-29 03:25:17 +00:00
},
2015-12-02 10:40:25 +00:00
putDB:function(type,id,item,callback){
if(!lib.db) return item;
var put=lib.db.transaction([type],'readwrite').objectStore(type).put(item,id);
if(callback){
put.onsuccess=callback;
}
},
getDB:function(type,id,callback){
if(!lib.db){
callback(null);
return;
}
if(!callback) return;
var store=lib.db.transaction([type],'readwrite').objectStore(type);
if(id){
store.get(id).onsuccess=function(e){
callback(e.target.result);
};
}
else{
var obj={};
store.openCursor().onsuccess=function(e){
var cursor=e.target.result;
if(cursor){
obj[cursor.key]=cursor.value;
cursor.continue();
}
else{
callback(obj);
}
}
}
},
deleteDB:function(type,id,callback){
if(!lib.db){
callback(false);
return;
}
var store=lib.db.transaction([type],'readwrite').objectStore(type);
store.delete(id).onsuccess=callback;
},
2015-04-29 03:25:17 +00:00
save:function(key,value){
2015-04-29 08:41:00 +00:00
if(_status.reloading) return;
2015-04-29 03:25:17 +00:00
var config={};
if(arguments.length>0){
try{
config=JSON.parse(localStorage.getItem(lib.configprefix+lib.config.mode));
if(typeof config!='object') throw 'err';
}
catch(err){
config={};
}
if(value==undefined){
delete config[key];
delete lib.storage[key];
}
else{
config[key]=value;
lib.storage[key]=value;
}
}
2015-11-30 13:08:29 +00:00
config.version=lib.version;
2015-04-29 03:25:17 +00:00
localStorage.setItem(lib.configprefix+lib.config.mode,JSON.stringify(config));
},
2015-11-30 13:08:29 +00:00
showChangeLog:function(){
if(lib.version!=lib.config.version){
game.saveConfig('version',lib.version);
var ul=document.createElement('ul');
ul.style.textAlign='left';
for(var i=0;i<lib.changeLog.length;i++){
var li=document.createElement('li');
li.innerHTML=lib.changeLog[i];
ul.appendChild(li);
}
2015-12-09 08:49:22 +00:00
var dialog=ui.create.dialog(lib.version+'更新内容','hidden');
2015-11-30 13:08:29 +00:00
dialog.content.appendChild(ul);
2015-12-09 08:49:22 +00:00
dialog.open();
2015-11-30 13:08:29 +00:00
var hidden=false;
if(!ui.auto.classList.contains('hidden')){
ui.auto.hide();
hidden=true;
}
game.pause();
var control=ui.create.control('确定',function(){
dialog.close();
control.close();
if(hidden) ui.auto.show();
game.resume();
});
}
},
2015-04-29 03:25:17 +00:00
updateSave:function(){
2015-04-29 08:41:00 +00:00
if(_status.reloading) return;
2015-04-29 03:25:17 +00:00
localStorage.setItem(lib.configprefix+lib.config.mode,JSON.stringify(lib.storage));
},
saveConfig:function(key,value,local){
2015-04-29 08:41:00 +00:00
if(_status.reloading) return;
2015-04-29 03:25:17 +00:00
var config;
try{
config=JSON.parse(localStorage.getItem(lib.configprefix+'config'));
if(!config||typeof config!='object') throw 'err'
}
catch(err){
config={};
}
if(local){
2015-10-29 17:36:14 +00:00
var localmode;
if(typeof local=='string'){
localmode=local;
}
else{
localmode=lib.config.mode;
}
if(!lib.config.mode_config[localmode]){
lib.config.mode_config[localmode]={};
}
lib.config.mode_config[localmode][key]=value;
key+='_mode_config_'+localmode;
2015-04-29 03:25:17 +00:00
}
else{
2015-04-29 07:54:48 +00:00
lib.config[key]=value;
2015-04-29 03:25:17 +00:00
}
config[key]=value;
localStorage.setItem(lib.configprefix+'config',JSON.stringify(config));
},
addPlayer:function(position,character,character2){
if(position<0||position>game.players.length+game.dead.length||position==undefined){
position=Math.ceil(Math.random()*(game.players.length+game.dead.length));
}
var players=game.players.concat(game.dead);
ui.arena.dataset.number=players.length+1;
for(var i=0;i<players.length;i++){
if(parseInt(players[i].dataset.position)>=position){
players[i].dataset.position=parseInt(players[i].dataset.position)+1;
}
}
var player=ui.create.player(ui.arena).animate('start');
if(character) player.init(character,character2);
game.players.push(player);
player.dataset.position=position;
game.arrangePlayers();
return player;
},
2015-05-03 15:17:15 +00:00
addFellow:function(position,character){
2015-11-04 01:59:00 +00:00
game.addVideo('addFellow',null,[position,character]);
2015-05-03 15:17:15 +00:00
var player=ui.create.player(ui.arena).animate('start');
player.dataset.position=position||game.players.length+game.dead.length;
if(character) player.init(character);
game.players.push(player);game.arrangePlayers();
return player;
},
2015-04-29 03:25:17 +00:00
restorePlayer:function(player){
if(game.players.contains(player)||game.dead.contains(player)) return;
var position=parseInt(player.dataset.position);
if(position<0||position>game.players.length+game.dead.length||position==undefined){
position=Math.ceil(Math.random()*(game.players.length+game.dead.length));
}
var players=game.players.concat(game.dead);
ui.arena.dataset.number=players.length+1;
for(var i=0;i<players.length;i++){
if(parseInt(players[i].dataset.position)>=position){
players[i].dataset.position=parseInt(players[i].dataset.position)+1;
}
}
game.players.push(player);
delete player.removed;
player.removeAttribute('style');
player.animate('start');
ui.arena.appendChild(player);
game.arrangePlayers();
return player;
},
removePlayer:function(player){
var players=game.players.concat(game.dead);
player.style.top=player.offsetTop+'px';
player.style.left=player.offsetLeft+'px';
if(player==undefined) player=game.dead[0]||game.me.next;
var position=parseInt(player.dataset.position);
for(var i=0;i<players.length;i++){
if(parseInt(players[i].dataset.position)>position){
players[i].dataset.position=parseInt(players[i].dataset.position)-1;
}
}
if(player.isAlive()){
player.next.previous=player.previous;
player.previous.next=player.next;
}
player.nextSeat.previousSeat=player.previousSeat;
player.previousSeat.nextSeat=player.nextSeat;
player.delete();
game.players.remove(player);
game.dead.remove(player);
ui.arena.dataset.number=players.length-1;
player.removed=true;
if(player==game.me){
ui.me.hide();
ui.auto.hide();
ui.wuxie.hide();
2015-04-29 03:25:17 +00:00
}
setTimeout(function(){
player.removeAttribute('style');
},500);
return player;
},
replacePlayer:function(player,character,character2){
player.removed=true;
var position=parseInt(player.dataset.position);
game.players.remove(player);
game.dead.remove(player);
player.delete();
var player2=ui.create.player(ui.arena).animate('start');
if(character) player2.init(character,character2);
game.players.push(player2);
player2.dataset.position=position;
player2.nextSeat=player.nextSeat;
player2.previousSeat=player.previousSeat;
player2.nextSeat.previousSeat=player2;
player2.previousSeat.nextSeat=player2;
var player3=player2.nextSeat;
while(player3.isDead()) player3=player3.nextSeat;
player3.previous=player2;
player2.next=player3;
var player4=player2.previousSeat;
while(player4.isDead()) player4=player4.previousSeat;
player4.next=player2;
player2.previous=player4;
return player2;
},
arrangePlayers:function(){
game.players.sort(lib.sort.position);
var players=game.players.concat(game.dead);
players.sort(lib.sort.position);
for(var i=0;i<players.length;i++){
if(i==0){
players[i].previousSeat=players[players.length-1];
}
else{
players[i].previousSeat=players[i-1];
}
if(i==players.length-1){
players[i].nextSeat=players[0];
}
else{
players[i].nextSeat=players[i+1];
}
}
for(var i=0;i<game.players.length;i++){
if(i==0){
game.players[i].previous=game.players[game.players.length-1];
}
else{
game.players[i].previous=game.players[i-1];
}
if(i==game.players.length-1){
game.players[i].next=game.players[0];
}
else{
game.players[i].next=game.players[i+1];
}
}
},
filterSkills:function(skills,player){
var out=skills.slice(0);
var filter=[];
for(var i in player.disabledSkills){
if(typeof player.disabledSkills[i]=='string'){
filter.add(player.disabledSkills[i]);
}
else if(Array.isArray(player.disabledSkills[i])){
for(var j=0;j<player.disabledSkills[i].length;j++){
filter.add(player.disabledSkills[i][j]);
}
}
}
for(var i=0;i<filter.length;i++){
if(filter[i]){
out.remove(filter[i]);
}
}
return out;
},
expandSkills:function(skills){
var skills2=[];
for(var i=0;i<skills.length;i++){
if(get.info(skills[i]).group) skills2=skills2.concat(get.info(skills[i]).group);
}
for(var i=0;i<skills2.length;i++){
skills.add(skills2[i]);
}
return skills;
},
css:function(style){
for(var i in style){
if(ui.style[i]) ui.style[i].innerHTML=i+JSON.stringify(style[i]).replace(/"/g,"");
else{
ui.style[i]=document.createElement('style');
ui.style[i].innerHTML=i+JSON.stringify(style[i]).replace(/"/g,"");
document.head.appendChild(ui.style[i]);
}
}
},
players:[],
dead:[],
imported:[],
phaseNumber:0
};
var ui={
updates:[],
2015-11-06 10:05:08 +00:00
thrown:[],
2015-12-03 16:28:06 +00:00
touchlines:[],
2015-04-29 03:25:17 +00:00
refresh:function(node){
void window.getComputedStyle(node, null).getPropertyValue("opacity");
},
create:{
2015-10-29 17:36:14 +00:00
div:function(){
var str,innerHTML,position,position2,style,divposition,listen;
2015-04-29 03:25:17 +00:00
for(var i=0;i<arguments.length;i++){
2015-10-29 17:36:14 +00:00
if(typeof arguments[i]=='string'){
if(typeof str=='string'){
innerHTML=arguments[i];
}
else{
str=arguments[i];
}
}
2015-04-29 03:25:17 +00:00
else if(get.objtype(arguments[i])=='div'||
get.objtype(arguments[i])=='table'||
get.objtype(arguments[i])=='tr'||
get.objtype(arguments[i])=='td'||
get.objtype(arguments[i])=='body') position=arguments[i];
else if(typeof arguments[i]=='number') position2=arguments[i];
else if(get.itemtype(arguments[i])=='divposition') divposition=arguments[i];
else if(typeof arguments[i]=='object') style=arguments[i];
2015-10-29 17:36:14 +00:00
else if(typeof arguments[i]=='function') listen=arguments[i];
2015-04-29 03:25:17 +00:00
}
if(str==undefined) str='';
var node=document.createElement('div');
for(var i=0;i<str.length;i++){
if(str[i]=='.'){
if(node.className.length!=0){
node.className+=' ';
}
while(str[i+1]!='.'&&str[i+1]!='#'&&i+1<str.length){
node.className+=str[i+1];
i++;
}
}
else if(str[i]=='#'){
while(str[i+1]!='.'&&str[i+1]!='#'&&i+1<str.length){
node.id+=str[i+1];
i++;
}
}
}
if(position){
if(typeof position2=='number'&&position.childNodes.length>position2){
position.insertBefore(node,position.childNodes[position2]);
}
else{
position.appendChild(node);
}
}
if(style) node.css(style);
if(divposition) node.setPosition(divposition);
2015-10-29 17:36:14 +00:00
if(innerHTML) node.innerHTML=innerHTML;
if(listen) node.listen(listen);
2015-04-29 03:25:17 +00:00
return node;
},
2015-11-28 03:45:23 +00:00
selectlist:function(list,init,position){
var select=document.createElement('select');
for(var i=0;i<list.length;i++){
var option=document.createElement('option');
if(Array.isArray(list[i])){
option.value=list[i][0];
option.innerHTML=list[i][1];
}
else{
option.value=list[i];
option.innerHTML=list[i];
}
if(init==list[i]){
option.selected='selected';
}
select.appendChild(option);
}
if(position){
position.appendChild(select);
}
return select;
},
2015-04-29 03:25:17 +00:00
table:function(){
var str,row,col,position,position2,fixed,style,divposition;
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='string') str=arguments[i];
else if(typeof arguments[i]=='number'){
if(typeof row=='number'){
if(typeof col=='number') position2=arguments[i];
else col=arguments[i];
}
else row=arguments[i];
}
else if(get.objtype(arguments[i])=='div'||
get.objtype(arguments[i])=='table'||
get.objtype(arguments[i])=='tr'||
get.objtype(arguments[i])=='td'||
get.objtype(arguments[i])=='body') position=arguments[i];
else if(typeof arguments[i]=='boolean') fixed=arguments[i];
else if(get.itemtype(arguments[i])=='divposition') divposition=arguments[i];
else if(typeof arguments[i]=='object') style=arguments[i];
}
if(str==undefined) str='';
var node=document.createElement('table');
for(var i=0;i<str.length;i++){
if(str[i]=='.'){
if(node.className.length!=0){
node.className+=' ';
}
while(str[i+1]!='.'&&str[i+1]!='#'&&i+1<str.length){
node.className+=str[i+1];
i++;
}
}
else if(str[i]=='#'){
while(str[i+1]!='.'&&str[i+1]!='#'&&i+1<str.length){
node.id+=str[i+1];
i++;
}
}
}
var tr,td;
for(var i=0;i<row;i++){
tr=document.createElement('tr');
if(fixed) tr.style.height=(100/row)+'%';
node.appendChild(tr);
for(var j=0;j<col;j++){
td=document.createElement('td');
tr.appendChild(td);
}
}
if(position){
if(typeof position2=='number'&&position.childNodes.length>position2){
position.insertBefore(node,position.childNodes[position2]);
}
else{
position.appendChild(node);
}
}
return node;
},
2015-05-02 09:54:39 +00:00
groupControl:function(dialog){
return ui.create.control('wei','shu','wu','qun',function(link,node){
if(link=='全部'){
dialog.currentcapt='';
dialog.currentgroup='';
for(var i=0;i<dialog.buttons.length;i++){
dialog.buttons[i].style.display='';
}
}
else{
if(node.classList.contains('thundertext')){
dialog.currentgroup=null;
dialog.currentgroupnode=null;
node.classList.remove('thundertext');
for(var i=0;i<dialog.buttons.length;i++){
if(dialog.currentcapt&&dialog.buttons[i].capt!=dialog.currentcapt){
dialog.buttons[i].style.display='none';
}
else{
dialog.buttons[i].style.display='';
}
}
}
else{
if(dialog.currentgroupnode){
dialog.currentgroupnode.classList.remove('thundertext');
}
dialog.currentgroup=link;
dialog.currentgroupnode=node;
node.classList.add('thundertext');
for(var i=0;i<dialog.buttons.length;i++){
if(dialog.buttons[i].group!=link||
(dialog.currentcapt&&dialog.buttons[i].capt!=dialog.currentcapt)){
dialog.buttons[i].style.display='none';
}
else{
dialog.buttons[i].style.display='';
}
}
}
}
});
},
cardDialog:function(){
var args=['thisiscard'];
for(var i=0;i<arguments.length;i++){
args.push(arguments[i]);
}
return ui.create.characterDialog.apply(this,args);
},
characterDialog:function(){
var filter,str,noclick,thisiscard;
for(var i=0;i<arguments.length;i++){
if(arguments[i]==='thisiscard'){
thisiscard=true;
}
else if(typeof arguments[i]==='string'){
str=arguments[i];
}
else if(typeof arguments[i]==='function'){
filter=arguments[i];
}
else if(typeof arguments[i]=='boolean'){
noclick=arguments[i];
}
}
var list=[];
var dialog;
var node=ui.create.div('.caption');
var namecapt=[];
var getCapt=function(str){
2015-12-06 15:23:47 +00:00
if(lib.customCharacters.contains(str)){
return '★';
}
var capt;
2015-05-02 09:54:39 +00:00
if(str.indexOf('_')==-1){
2015-12-06 15:23:47 +00:00
capt=str[0];
}
else{
capt=str[str.indexOf('_')+1];
}
capt=capt.toLowerCase();
if(!/[a-z]/i.test(capt)){
capt='★';
2015-05-02 09:54:39 +00:00
}
2015-12-06 15:23:47 +00:00
return capt;
2015-05-02 09:54:39 +00:00
}
if(thisiscard){
for(var i in lib.card){
if(!lib.translate[i+'_info']) continue;
if(filter&&filter(i)) continue;
list.push(['',get.translation(lib.card[i].type),i]);
if(namecapt.indexOf(getCapt(i))==-1){
namecapt.push(getCapt(i));
}
}
}
else{
for(var i in lib.character){
2015-05-11 03:43:37 +00:00
if(lib.character[i][4].contains('minskin')) continue;
2015-11-28 03:45:23 +00:00
if(lib.character[i][4].contains('boss')&&!
lib.character[i][4].contains('bossallowed')) continue;
2015-12-01 05:46:28 +00:00
if(lib.character[i][4].contains('hiddenboss')&&!
lib.character[i][4].contains('bossallowed')) continue;
2015-12-06 15:23:47 +00:00
if(lib.config.banned.contains(i)) continue;
2015-05-02 09:54:39 +00:00
if(filter&&filter(i)) continue;
list.push(i);
if(namecapt.indexOf(getCapt(i))==-1){
namecapt.push(getCapt(i));
}
}
}
namecapt.sort(function(a,b){
return a>b?1:-1;
});
var clickCapt=function(e){
if(_status.dragged) return;
if(this.classList.contains('thundertext')){
dialog.currentcapt=null;
dialog.currentcaptnode=null;
this.classList.remove('thundertext');
for(var i=0;i<dialog.buttons.length;i++){
if(dialog.currentgroup&&dialog.buttons[i].group!=dialog.currentgroup){
dialog.buttons[i].style.display='none';
}
else{
dialog.buttons[i].style.display='';
}
}
}
else{
if(dialog.currentcaptnode){
dialog.currentcaptnode.classList.remove('thundertext');
}
dialog.currentcapt=this.link;
dialog.currentcaptnode=this;
this.classList.add('thundertext');
for(var i=0;i<dialog.buttons.length;i++){
if(dialog.buttons[i].capt!=dialog.currentcapt||
(dialog.currentgroup&&dialog.buttons[i].group!=dialog.currentgroup)){
dialog.buttons[i].style.display='none';
}
else{
dialog.buttons[i].style.display='';
}
}
}
e.stopPropagation();
};
for(i=0;i<namecapt.length;i++){
var span=document.createElement('span');
span.innerHTML=' '+namecapt[i].toUpperCase()+' ';
span.link=namecapt[i];
span.addEventListener(lib.config.touchscreen?'touchend':'click',clickCapt);
node.appendChild(span);
}
var groupSort;
if(thisiscard){
2015-05-03 15:17:15 +00:00
groupSort=function(name){
if(lib.card[name[2]].type=='basic') return 0;
2015-06-16 13:24:35 +00:00
if(lib.card[name[2]].type=='stonecard') return 0.5;
2015-11-21 05:30:26 +00:00
if(lib.card[name[2]].type=='mengjing') return 0.3;
2015-05-03 15:17:15 +00:00
if(lib.card[name[2]].type=='stonecharacter') return 1;
2015-05-10 05:34:37 +00:00
if(lib.card[name[2]].type=='chess') return 1.5;
2015-05-03 15:17:15 +00:00
if(lib.card[name[2]].type=='trick') return 2;
if(lib.card[name[2]].type=='delay') return 3;
if(lib.card[name[2]].type=='equip') return 4;
if(lib.card[name[2]].type=='zhenfa') return 5;
return 6;
};
2015-05-02 09:54:39 +00:00
}
else{
groupSort=function(name){
if(lib.character[name][1]=='wei') return 0;
if(lib.character[name][1]=='shu') return 1;
if(lib.character[name][1]=='wu') return 2;
if(lib.character[name][1]=='qun') return 3;
}
}
list.sort(function(a,b){
var del=groupSort(a)-groupSort(b);
if(del!=0) return del;
var aa=a,bb=b;
if(a.indexOf('_')!=-1){
a=a.slice(a.indexOf('_')+1);
}
if(b.indexOf('_')!=-1){
b=b.slice(b.indexOf('_')+1);
}
if(a!=b){
return a>b?1:-1;
}
return aa>bb?1:-1;
});
dialog=ui.create.dialog('hidden');
if(str){
dialog.add(str);
}
dialog.add(node);
if(thisiscard){
dialog.add([list,'vcard'],noclick);
}
else{
dialog.add([list,'character'],noclick);
}
dialog.add(ui.create.div('.placeholder'));
for(i=0;i<dialog.buttons.length;i++){
if(thisiscard){
dialog.buttons[i].capt=getCapt(dialog.buttons[i].link[2]);
}
else{
dialog.buttons[i].group=lib.character[dialog.buttons[i].link][1];
dialog.buttons[i].capt=getCapt(dialog.buttons[i].link);
}
}
return dialog;
},
2015-04-29 03:25:17 +00:00
dialog:function(){
var i;
var hidden=false;
var dialog=ui.create.div('.dialog');
dialog.contentContainer=ui.create.div('.content-container',dialog);
dialog.content=ui.create.div('.content',dialog.contentContainer);
dialog.bar1=ui.create.div('.bar.top',dialog);
dialog.bar2=ui.create.div('.bar.bottom',dialog);
dialog.buttons=[];
for(i in lib.element.dialog){
dialog[i]=lib.element.dialog[i];
}
for(i=0;i<arguments.length;i++){
if(typeof arguments[i]=='boolean') dialog.static=arguments[i];
else if(arguments[i]=='hidden') hidden=true;
else dialog.add(arguments[i]);
}
if(!hidden){
dialog.open();
}
2015-12-08 13:54:44 +00:00
// if(!lib.config.touchscreen) dialog.contentContainer.onscroll=ui.update;
2015-04-29 03:25:17 +00:00
dialog.contentContainer.ontouchstart=ui.click.touchStart;
dialog.contentContainer.ontouchmove = ui.click.touchScroll;
dialog.contentContainer.style.WebkitOverflowScrolling='touch';
2015-12-12 08:37:15 +00:00
dialog.ontouchstart=ui.click.dragtouchdialog;
2015-04-29 03:25:17 +00:00
return dialog;
},
line2:function(){
var node=ui.create.line.apply(this,arguments);
node.classList.add('line2');
return node;
},
line:function(){
var two=false,func;
var node=ui.create.div('.config');
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='string'||typeof arguments[i]=='number'){
if(two) ui.create.div('.toggle',node).innerHTML=arguments[i];
else {
ui.create.div(node).innerHTML=arguments[i];
two=true;
}
}
else if(typeof arguments[i]=='function') func=arguments[i];
}
if(func){
for(var i=0;i<node.childNodes.length;i++) node.childNodes[i].listen(func);
}
return node;
},
switcher:function(name,current,current2){
var func;
var node=ui.create.div('.config');
ui.create.div(node).innerHTML=get.translation(name+'_config');
var switcher=ui.create.div('.toggle',node);
switcher.name=name;
for(var i=0;i<arguments.length;i++){
if(typeof arguments[i]=='function'){
func=arguments[i];break;
}
}
if(typeof current=='string'){
switcher.link=current;
switcher.innerHTML=get.translation(current);
switcher.contentEditable=true;
switcher.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.editor);
}
else if(typeof current=='object'){
switcher.link=current2||current[0];
switcher.innerHTML=get.translation(switcher.link);
switcher.choice=current;
switcher.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.switcher);
}
else{
if(current){
switcher.classList.add('on');
}
switcher.classList.add('onoff');
ui.create.div(ui.create.div(switcher));
switcher.link=current?true:false;
switcher.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.toggle);
}
if(func) switcher.additionalCommand=func;
return node;
},
caption:function(str,position){
var caption=ui.create.div('.caption',position);
caption.innerHTML=str;
return caption;
},
control:function(){
2015-11-16 01:59:54 +00:00
var nc=(ui.control.childNodes.length==0);
2015-11-30 13:08:29 +00:00
// for(var i=0;i<ui.control.childNodes.length;i++){
// if(ui.control.childNodes[i].classList.contains('removing')){
// var that=ui.control.childNodes[i];
// var width=that.offsetWidth;
// that.style.marginLeft=(-width/2)+'px';
// that.style.marginRight=(-width/2)+'px';
// that.style.transitionDuration=0.8*parseFloat(getComputedStyle(that).opacity)+'s';
// }
// }
2015-04-29 03:25:17 +00:00
var i,controls;
2015-10-20 17:44:00 +00:00
var nozoom=false;
2015-04-29 03:25:17 +00:00
if(get.objtype(arguments[0])=='array') controls=arguments[0];
else controls=arguments;
2015-05-10 05:34:37 +00:00
var control=ui.create.div('.control');
2015-09-03 03:49:14 +00:00
ui.control.insertBefore(control,_status.createControl||ui.confirm);
2015-04-29 03:25:17 +00:00
for(i in lib.element.control){
control[i]=lib.element.control[i];
}
for(i=0;i<controls.length;i++){
if(typeof controls[i]=='function'){
control.custom=controls[i];
}
2015-10-20 17:44:00 +00:00
else if(controls[i]=='nozoom'){
nozoom=true;
}
2015-04-29 03:25:17 +00:00
else{
control.add(controls[i]);
}
}
ui.controls.unshift(control);
2015-11-15 05:54:58 +00:00
if(nc){
2015-11-30 13:08:29 +00:00
ui.control.animate('nozoom',100);
2015-10-20 17:44:00 +00:00
}
2015-11-30 13:08:29 +00:00
// if(ui.control.classList.contains('nozoom')){
// nozoom=true;
// }
// if(nozoom){
// control.classList.add('nozoom');
// }
2015-04-29 03:25:17 +00:00
if(control.childNodes.length){
2015-11-30 13:08:29 +00:00
// if(nozoom||true){
control.style.transition='opacity 0.5s';
// }
// else{
// control.style.transition='';
// control.style.transform='scale(0.8)';
// }
2015-05-01 03:25:06 +00:00
ui.refresh(control);
2015-11-30 13:08:29 +00:00
control.style.transform='translateX(-'+(control.offsetWidth/2)+'px)';
2015-05-01 03:25:06 +00:00
control.style.opacity=1;
2015-10-20 17:44:00 +00:00
ui.refresh(control);
control.style.transition='';
2015-04-29 03:25:17 +00:00
}
2015-12-01 05:46:28 +00:00
ui.updatec();
2015-04-29 03:25:17 +00:00
return control;
},
confirm:function(str,func){
if(ui.confirm&&ui.confirm.str==str){
return;
}
if(str=='o'){
if(ui.confirm){
ui.confirm.replace('ok');
}
else{
ui.confirm=ui.create.control('ok');
}
}
else if(str=='oc'||str=='co'){
if(ui.confirm){
ui.confirm.replace('ok','cancel');
}
else{
ui.confirm=ui.create.control('ok','cancel');
}
}
else if(str=='c'){
if(ui.confirm){
ui.confirm.replace('cancel');
}
else{
ui.confirm=ui.create.control('cancel');
}
}
else if(ui.confirm){
ui.confirm.close();
delete ui.confirm;
}
if(ui.confirm){
ui.confirm.str=str;
if(func) ui.confirm.custom=func;
else delete ui.confirm.custom;
}
},
skills:function(skills){
var i,same;
if(ui.skills){
if(ui.skills.skills.length==skills.length&&ui.skills.style.display!='none'){
same=true;
for(i=0;i<skills.length;i++){
if(ui.skills.skills.contains(skills[i])==false){
same=false;
break;
}
}
}
if(same) return;
ui.skills.close();
delete ui.skills;
}
if(skills==undefined||skills.length==0) return;
2015-12-01 05:46:28 +00:00
if(!_status.event.isMine()){
_status.noupdatec=true;
}
ui.skills=ui.create.control(skills.concat([ui.click.skill]));
2015-05-01 03:25:06 +00:00
if(!_status.event.isMine()){
2015-04-29 03:25:17 +00:00
ui.skills.style.display='none';
}
2015-11-30 17:37:10 +00:00
else{
ui.updatec();
}
2015-12-01 05:46:28 +00:00
_status.noupdatec=false;
2015-04-29 03:25:17 +00:00
ui.skills.skills=skills;
return ui.skills;
},
2015-11-30 13:08:29 +00:00
skills2:function(skills){
var i,same;
if(ui.skills2){
if(ui.skills2.skills.length==skills.length&&ui.skills2.style.display!='none'){
same=true;
for(i=0;i<skills.length;i++){
if(ui.skills2.skills.contains(skills[i])==false){
same=false;
break;
}
}
}
if(same) return;
ui.skills2.close();
delete ui.skills2;
}
if(skills==undefined||skills.length==0) return;
2015-12-01 05:46:28 +00:00
if(!_status.event.isMine()){
_status.noupdatec=true;
}
ui.skills2=ui.create.control(skills.concat([ui.click.skill]));
2015-11-30 13:08:29 +00:00
if(!_status.event.isMine()){
ui.skills2.style.display='none';
}
2015-11-30 17:37:10 +00:00
else{
ui.updatec();
}
2015-12-01 05:46:28 +00:00
_status.noupdatec=false;
2015-11-30 13:08:29 +00:00
ui.skills2.skills=skills;
return ui.skills2;
},
skills3:function(skills){
var i,same;
if(ui.skills3){
if(ui.skills3.skills.length==skills.length&&ui.skills3.style.display!='none'){
same=true;
for(i=0;i<skills.length;i++){
if(ui.skills3.skills.contains(skills[i])==false){
same=false;
break;
}
}
}
if(same) return;
ui.skills3.close();
delete ui.skills3;
}
if(skills==undefined||skills.length==0) return;
2015-12-01 05:46:28 +00:00
if(!_status.event.isMine()){
_status.noupdatec=true;
}
ui.skills3=ui.create.control(skills.concat([ui.click.skill]));
2015-11-30 13:08:29 +00:00
if(!_status.event.isMine()){
ui.skills3.style.display='none';
}
2015-11-30 17:37:10 +00:00
else{
ui.updatec();
}
2015-12-01 05:46:28 +00:00
_status.noupdatec=false;
2015-11-30 13:08:29 +00:00
ui.skills3.skills=skills;
return ui.skills3;
},
2015-04-29 03:25:17 +00:00
arena:function(){
var i,j;
2015-12-06 15:23:47 +00:00
ui.window=ui.create.div('#window.hidden',document.body);
2015-12-07 11:15:35 +00:00
if(window.isIpad){
ui.window.classList.add('ipad');
delete window.isIpad;
}
2015-12-06 15:23:47 +00:00
ui.refresh(ui.window);
2015-12-12 08:37:15 +00:00
if(!localStorage.getItem(lib.configprefix+'playback')){
ui.window.show();
}
else{
setTimeout(function(){
ui.window.show();
},1000);
}
2015-04-29 03:25:17 +00:00
ui.window.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.window);
ui.system=ui.create.div("#system.",ui.window);
ui.arena=ui.create.div('#arena',ui.window);
2015-12-06 15:23:47 +00:00
2015-10-31 16:18:20 +00:00
if(lib.config.layout=='mobile'||lib.config.layout=='phone'){
2015-10-31 10:14:14 +00:00
ui.arena.classList.add('mobile');
}
2015-11-21 05:30:26 +00:00
if(lib.config.layout=='default'){
ui.arena.classList.add('oldlayout');
}
2015-11-24 00:50:54 +00:00
if(lib.config.low_performance){
ui.arena.classList.add('low_performance');
}
2015-11-30 13:08:29 +00:00
if(lib.config.slim_player){
ui.arena.classList.add('slim_player');
}
2015-11-18 03:39:14 +00:00
if(lib.config.layout=='default'&&lib.config.hp_style=='official'){
ui.arena.classList.add('hpimage');
}
2015-11-30 13:08:29 +00:00
ui.arena.dataset.name_font=lib.config.name_font||'xinwei';
ui.arena.dataset.identity_font=lib.config.identity_font||'huangcao';
ui.arena.dataset.global_font=lib.config.global_font||'default';
// ui.arena.dataset.font_size=lib.config.font_size||'16';
2015-11-28 07:19:04 +00:00
ui.arena.dataset.glow_phase=lib.config.glow_phase;
2015-04-29 14:56:33 +00:00
ui.backgroundMusic=document.createElement('audio');
2015-04-30 03:09:07 +00:00
ui.backgroundMusic.volume=lib.config.volumn_background/8;
2015-04-29 14:56:33 +00:00
game.playBackgroundMusic();
ui.backgroundMusic.autoplay=true;
ui.backgroundMusic.addEventListener('ended',game.playBackgroundMusic);
ui.window.appendChild(ui.backgroundMusic);
2015-12-07 11:15:35 +00:00
ui.arenalog=ui.create.div('#arenalog',ui.arena);
if(lib.config.show_log=='off'){
ui.arenalog.style.display='none';
}
2015-12-09 13:16:20 +00:00
else{
ui.arenalog.dataset.position=lib.config.show_log;
}
2015-12-07 11:15:35 +00:00
2015-11-29 11:46:51 +00:00
ui.roundmenu=ui.create.div('#roundmenu.roundarenabutton.menubutton.round',ui.arena);
ui.roundmenu._position=[180,210];
ui.create.div(ui.roundmenu);
ui.create.div(ui.roundmenu);
ui.create.div(ui.roundmenu);
ui.create.div(ui.roundmenu);
ui.create.div(ui.roundmenu);
ui.create.div(ui.roundmenu);
var resetround=function(e){
_status.draggingroundmenu=false;
ui.roundmenu.style.transform='';
ui.roundmenu._dragtransform=[0,0];
ui.roundmenu.style.transition='all 0.3s';
delete ui.roundmenu._dragtouches;
delete ui.roundmenu._dragorigin;
delete ui.roundmenu._dragorigintransform;
setTimeout(function(){
ui.roundmenu.style.transition='';
},500);
game.saveConfig('roundmenu_transform',[0,0]);
e.stopPropagation();
return false;
};
if(lib.config.touchscreen){
ui.roundmenu.addEventListener('touchstart',function(e){
_status.draggingroundmenu=true;
ui.roundmenu._dragorigin={
clientX:e.touches[0].clientX,
clientY:e.touches[0].clientY,
};
if(!ui.roundmenu._dragtransform){
ui.roundmenu._dragtransform=[0,0];
}
ui.roundmenu._dragorigintransform=ui.roundmenu._dragtransform.slice(0);
ui.roundmenu._resetTimeout=setTimeout(function(){
resetround();
delete ui.roundmenu._resetTimeout;
},1000);
});
}
else{
ui.roundmenu.oncontextmenu=resetround;
}
if(lib.config.roundmenu_transform){
var translate=lib.config.roundmenu_transform;
ui.roundmenu._dragtransform=translate;
ui.roundmenu.style.transform='translate('+translate[0]+'px,'+translate[1]+'px)';
ui.click.checkroundtranslate();
}
if(lib.config.layout!='phone'){
ui.roundmenu.style.display='none';
}
2015-04-30 03:09:07 +00:00
2015-04-29 03:25:17 +00:00
ui.sidebar=ui.create.div('#sidebar');
ui.sidebar3=ui.create.div('#sidebar3');
2015-04-29 03:25:17 +00:00
ui.canvas=document.createElement('canvas');
2015-11-25 10:25:18 +00:00
// if(lib.config.bottom_line){
// ui.canvas.style.zIndex=0;
// }
2015-08-15 09:10:06 +00:00
2015-04-29 03:25:17 +00:00
ui.arena.appendChild(ui.canvas);
ui.canvas.id='canvas';
ui.ctx=ui.canvas.getContext('2d');
2015-05-01 07:35:43 +00:00
ui.configbg=ui.create.div("#click");
ui.configbg.listen(ui.click.config2);
2015-11-14 09:02:14 +00:00
if(!lib.config.touchscreen){
ui.configbg.oncontextmenu=ui.click.config2;
}
2015-04-29 03:25:17 +00:00
ui.config=ui.create.div('#sidebar2.content');
2015-05-02 06:59:31 +00:00
ui.config.listen(function(){
2015-05-08 08:07:38 +00:00
if(_status.reloading) return;
if(_status.choosing){
if(!_status.choosing.expand){
_status.choosing.parentNode.style.height='';
_status.choosing.nextSibling.delete();
_status.choosing.previousSibling.show();
delete _status.choosing;
}
}
_status.clicked=true;
if(ui.arena.classList.contains('selecting')){
game.check();
}
2015-04-30 08:24:57 +00:00
});
2015-11-14 09:02:14 +00:00
if(!lib.config.touchscreen){
ui.config.oncontextmenu=function(e){
e.stopPropagation();
return false;
};
}
2015-04-29 07:54:48 +00:00
2015-04-29 03:25:17 +00:00
ui.sidebar.ontouchstart=ui.click.touchStart;
ui.config.ontouchstart=ui.click.touchStart;
ui.sidebar.ontouchmove = ui.click.touchScroll;
ui.config.ontouchmove = ui.click.touchScroll;
ui.sidebar.style.WebkitOverflowScrolling='touch';
ui.config.style.WebkitOverflowScrolling='touch';
2015-10-29 17:36:14 +00:00
if(false&&lib.config.right_sidebar){
ui.sidebar.classList.add('right');
ui.sidebar3.classList.add('left');
2015-04-29 03:25:17 +00:00
ui.config.classList.add('right');
}
2015-12-06 15:23:47 +00:00
2015-10-30 09:13:19 +00:00
switch(lib.config.ui_zoom){
case 'esmall':ui.window.style.zoom=0.8;break;
case 'vsmall':ui.window.style.zoom=0.9;break;
case 'small':ui.window.style.zoom=0.95;break;
case 'big':ui.window.style.zoom=1.05;break;
case 'vbig':ui.window.style.zoom=1.1;break;
2015-11-05 02:34:35 +00:00
case 'ebig':ui.window.style.zoom=1.2;break;
2015-10-30 09:13:19 +00:00
default:ui.window.style.zoom=1;
}
2015-12-06 15:23:47 +00:00
2015-10-30 09:13:19 +00:00
var autoskill={};
2015-05-01 07:35:43 +00:00
ui.autoskill=autoskill;
2015-12-06 15:23:47 +00:00
2015-04-29 03:25:17 +00:00
if(!lib.config.autoskilllist){
lib.config.autoskilllist=[];
}
var nodex;
for(i in lib.skill){
if(lib.skill[i].frequent&&lib.translate[i]){
lib.translate[i+'_forbid_config']=lib.translate[i];
nodex=ui.create.switcher(i+'_forbid',
!lib.config.autoskilllist.contains(i),ui.click.sidebar.autoskill);
nodex.link=i;
2015-10-30 09:13:19 +00:00
autoskill[i]=nodex;
2015-04-29 03:25:17 +00:00
}
}
2015-10-31 16:18:20 +00:00
ui.system1=ui.create.div('#system1',ui.system);
ui.system2=ui.create.div('#system2',ui.system);
2015-04-29 08:41:00 +00:00
ui.replay=ui.create.system('重来',game.reload,true);
2015-10-29 17:36:14 +00:00
ui.config2=ui.create.system('选项',ui.click.config);
2015-11-05 02:34:35 +00:00
ui.pause=ui.create.system('暂停',ui.click.pause);
2015-04-30 08:24:57 +00:00
if(!lib.config.touchscreen){
lib.setPopped(ui.pause,ui.click.pausehistory,220,400);
2015-04-30 08:24:57 +00:00
}
2015-04-29 03:25:17 +00:00
if(!lib.config.show_pause){
ui.pause.style.display='none';
}
2015-11-28 03:45:23 +00:00
ui.cardPileButton=ui.create.system('牌堆',null,true);
lib.setPopped(ui.cardPileButton,ui.click.cardPileButton,220);
2015-10-28 03:47:35 +00:00
ui.wuxie=ui.create.system('不询问无懈',ui.click.wuxie,true);
2015-04-30 08:24:57 +00:00
if(!lib.config.touchscreen){
2015-05-08 08:07:38 +00:00
lib.setPopped(ui.config2,ui.click.pauseconfig,170);
2015-10-29 17:36:14 +00:00
// lib.setPopped(ui.wuxie,ui.click.wuxieconfig,170);
2015-04-30 08:24:57 +00:00
}
2015-04-29 03:25:17 +00:00
ui.auto=ui.create.system('托管',ui.click.auto);
2015-04-30 08:24:57 +00:00
ui.volumn=ui.create.system('♫');
lib.setPopped(ui.volumn,ui.click.volumn,200);
// if(lib.config.show_pause) ui.auto.style.marginLeft='10px';
2015-04-30 03:09:07 +00:00
if(!lib.config.show_volumn){
ui.volumn.style.display='none';
}
2015-04-29 03:25:17 +00:00
if(!lib.config.show_auto){
ui.auto.style.display='none';
}
if(!lib.config.show_wuxie){
ui.wuxie.style.display='none';
}
2015-11-28 03:45:23 +00:00
if(!lib.config.show_cardpile){
ui.cardPileButton.style.display='none';
}
2015-04-29 03:25:17 +00:00
if(lib.config.touchscreen&&!lib.config.confirmtouch){
var backtomouse=ui.create.system('返回鼠标模式');
backtomouse.addEventListener('click',function(){
game.saveConfig('touchscreen',false);
2015-04-29 08:41:00 +00:00
game.reload();
2015-04-29 03:25:17 +00:00
});
var keeptouch=ui.create.system('确认触屏');
keeptouch.addEventListener('touchend',function(){
game.saveConfig('confirmtouch',true);
keeptouch.remove();
backtomouse.remove();
});
}
ui.playerids=ui.create.system('显示身份',function(){
if(game.showIdentity){
game.showIdentity();
_status.identityShown=true;
}
},true);
2015-05-08 08:07:38 +00:00
if(!lib.config.show_playerids||!game.showIdentity){
2015-04-29 03:25:17 +00:00
ui.playerids.style.display='none';
}
if(!lib.config.show_replay){
ui.replay.style.display='none';
}
2015-11-15 05:54:58 +00:00
ui.control=ui.create.div('#control',ui.arena).animate('nozoom');
2015-04-29 03:25:17 +00:00
ui.cardPile=ui.create.div('#cardPile');
ui.discardPile=ui.create.div('#discardPile');
ui.special=ui.create.div('#special');
ui.dialogs=[];
ui.controls=[];
ui.style={};
2015-10-29 17:36:14 +00:00
(function(){
var menu,menuContainer;
var startButton;
var popupContainer;
var closeMenu=function(){
popupContainer.classList.add('hidden');
if(popupContainer.onclose){
popupContainer.onclose();
}
};
popupContainer=ui.create.div('.popup-container.hidden',ui.window,closeMenu);
var openMenu=function(node,e,onclose){
popupContainer.innerHTML='';
if(e){
node.style.left=e.x+'px';
node.style.top=e.y+'px';
}
popupContainer.appendChild(node);
popupContainer.classList.remove('hidden');
popupContainer.onclose=onclose;
};
var clickToggle=function(){
this.classList.toggle('on');
var config=this._link.config;
if(config.onclick){
config.onclick.call(this,this.classList.contains('on'));
}
if(config.update){
config.update();
}
};
var clickSwitcher=function(){
var node=this;
this.classList.add('on');
if(this._link.menu){
var pos1=this.lastChild.getBoundingClientRect();
var pos2=ui.window.getBoundingClientRect();
openMenu(this._link.menu,{
x:pos1.left+pos1.width+5-pos2.left,
y:pos1.top-pos2.top
},function(){
node.classList.remove('on');
});
}
};
var clickContainer=function(){
2015-11-21 05:30:26 +00:00
// if(this.animating){
// return;
// }
// this.animating=true;
// menu.classList.add('zoomout');
// menu.classList.remove('zoomin');
// setTimeout(function(){
// menuContainer.classList.add('hidden');
// menuContainer.animating=false;
// },300);
menuContainer.classList.add('hidden');
2015-10-29 17:36:14 +00:00
game.resume2();
if(game.onresume2){
game.onresume2();
}
2015-11-06 10:05:08 +00:00
ui.arena.classList.remove('menupaused');
2015-11-14 15:48:04 +00:00
ui.config2.classList.remove('pressdown2');
2015-10-29 17:36:14 +00:00
};
var clickMenuItem=function(){
var node=this.parentNode._link;
var config=node._link.config;
node._link.current=this.link;
node.lastChild.innerHTML=config.item[this._link];
if(config.onclick){
config.onclick.call(node,this._link);
}
if(config.update){
config.update();
}
};
var createMenu=function(tabs,config){
var createPage=function(position){
var node=ui.create.div(position);
2015-10-31 03:20:59 +00:00
lib.setScroll(ui.create.div('.left.pane',node));
lib.setScroll(ui.create.div('.right.pane',node));
2015-10-29 17:36:14 +00:00
return node;
};
var menu=ui.create.div('.main.menu.dialog.popped.static',config.position,function(e){
e.stopPropagation();
});
var menuTab=ui.create.div('.menu-tab',menu);
var menuTabBar=ui.create.div('.menu-tab-bar',menu);
menuTabBar.style.left=(config.bar||0)+'px';
var menuContent=ui.create.div('.menu-content',menu);
var clickTab=function(){
2015-11-05 02:34:35 +00:00
if(this.classList.contains('disabled')) return;
2015-10-29 17:36:14 +00:00
var active=this.parentNode.querySelector('.active');
if(active){
active.classList.remove('active');
active._link.remove();
}
this.classList.add('active');
menuTabBar.style.left=this.offsetLeft+'px';
menuContent.appendChild(this._link);
};
2015-11-25 10:25:18 +00:00
ui.click.menuTab=function(tab){
for(var i=0;i<menuTab.childNodes.length;i++){
if(menuTab.childNodes[i].innerHTML==tab){
clickTab.call(menuTab.childNodes[i]);
return;
}
}
};
2015-10-29 17:36:14 +00:00
var pages=[];
for(var i=0;i<tabs.length;i++){
var active=(i===(config.init||0));
pages[i]=createPage(active?menuContent:null);
ui.create.div(active?'.active':'',tabs[i],menuTab,clickTab)._link=pages[i];
}
return {
menu:menu,
pages:pages
};
};
var createConfig=function(config,position){
var node=ui.create.div('.config',config.name);
node._link={config:config};
if(config.item){
if(Array.isArray(config.init)){
}
else{
node.classList.add('switcher');
2015-10-31 16:26:25 +00:00
node.listen(clickSwitcher);
2015-10-29 17:36:14 +00:00
ui.create.div('',config.item[config.init],node);
node._link.menu=ui.create.div('.menu');
node._link.menu._link=node;
node._link.current=config.init;
for(var i in config.item){
ui.create.div('',config.item[i],node._link.menu,clickMenuItem)._link=i;
}
}
}
else if(config.range){
}
else if(config.clear){
node.listen(clickToggle);
}
else{
node.classList.add('toggle');
node.listen(clickToggle);
ui.create.div(ui.create.div(node));
if(config.init==true){
node.classList.add('on');
}
}
if(position){
position.appendChild(node);
}
return node;
};
2015-10-30 15:32:48 +00:00
var menuUpdates=[];
2015-10-29 17:36:14 +00:00
menuContainer=ui.create.div('.menu-container.hidden',ui.window,clickContainer);
2015-10-30 15:32:48 +00:00
ui.menuContainer=menuContainer;
2015-10-29 17:36:14 +00:00
ui.click.configMenu=function(){
if(menuContainer.classList.contains('hidden')){
2015-11-15 05:54:58 +00:00
ui.config2.classList.add('pressdown2');
ui.arena.classList.add('menupaused');
2015-11-21 05:30:26 +00:00
// menu.classList.remove('zoomout');
// menu.classList.add('zoomin');
2015-10-29 17:36:14 +00:00
menuContainer.classList.remove('hidden');
2015-11-21 05:30:26 +00:00
// menuContainer.animating=true;
// setTimeout(function(){
// menuContainer.animating=false;
// },300);
2015-10-30 15:32:48 +00:00
for(var i=0;i<menuUpdates.length;i++){
menuUpdates[i]();
}
2015-10-29 17:36:14 +00:00
}
else{
clickContainer.call(menuContainer);
}
}
2015-10-30 09:13:19 +00:00
var menux=createMenu(['开始','选项','武将','卡牌','战局','帮助'],{
2015-10-29 17:36:14 +00:00
position:menuContainer,bar:40
});
menu=menux.menu;
var copyObj=function(obj){
var copy={};
for(var i in obj){
if(get.objtype(obj[i])=='object'){
copy[i]=util.copy(obj[i]);
}
else if(Array.isArray(obj[i])){
copy[i]=obj[i].slice(0);
}
else{
copy[i]=obj[i];
}
}
return copy;
};
(function(){
var start=menux.pages[0];
var rightPane=start.lastChild;
startButton=ui.create.div('.menubutton.round.highlight','启',start,function(){
if(this.animating||this.classList.contains('dim')){
return;
}
var active=this.parentNode.querySelector('.active');
if(active){
game.saveConfig('mode',active.mode);
2015-12-06 15:23:47 +00:00
localStorage.setItem(lib.configprefix+'directstart',true);
2015-10-29 17:36:14 +00:00
game.reload();
}
});
var clickMode=function(){
var active=this.parentNode.querySelector('.active');
if(active===this){
return;
}
active.classList.remove('active');
active.link.remove();
active=this;
this.classList.add('active');
rightPane.appendChild(this.link);
};
var createModeConfig=function(mode,position){
var info=lib.mode[mode];
var page=ui.create.div('');
var node=ui.create.div('.menubutton.large',info.name,position,clickMode);
node.link=page;
node.mode=mode;
if(mode==lib.config.mode){
node.classList.add('active');
}
var map={};
if(info.config){
var hiddenNodes=[];
for(var j in info.config){
if(j==='update'){
continue;
}
var cfg=copyObj(info.config[j]);
cfg._name=j;
2015-10-30 15:32:48 +00:00
cfg.mode=mode;
2015-10-29 17:36:14 +00:00
var config=lib.config.mode_config[mode]||{};
if(!config.hasOwnProperty(j)){
game.saveConfig(j,cfg.init,mode);
}
else{
cfg.init=config[j];
}
if(!cfg.onclick){
cfg.onclick=function(result){
var cfg=this._link.config;
game.saveConfig(cfg._name,result,mode);
if(cfg.onsave){
cfg.onsave.call(this,result);
}
if(cfg.restart){
startButton.classList.add('glowing');
}
};
}
if(info.config.update){
cfg.update=function(){
info.config.update(config,map);
};
}
var cfgnode=createConfig(cfg);
map[j]=cfgnode;
if(cfg.frequent){
page.appendChild(cfgnode);
}
else{
cfgnode.classList.add('auto-hide');
hiddenNodes.push(cfgnode);
}
}
var expanded=false;
2015-12-06 15:23:47 +00:00
var hasexpand=true;
2015-10-29 17:36:14 +00:00
if(hiddenNodes.length){
ui.create.div('.config.more','更多 <div>&gt;</div>',page,function(){
if(expanded){
this.classList.remove('on');
this.parentNode.classList.remove('expanded');
}
else{
this.classList.add('on');
this.parentNode.classList.add('expanded');
}
expanded=!expanded;
});
for(var k=0;k<hiddenNodes.length;k++){
page.appendChild(hiddenNodes[k]);
}
}
2015-12-06 15:23:47 +00:00
else{
hasexpand=false;
}
var hidemode=ui.create.div('.config.more','隐藏此模式',page,function(){
if(this.innerHTML=='隐藏此模式'){
this.innerHTML='此模式将在重启后隐藏';
lib.config.hiddenModePack.add(mode);
}
else{
this.innerHTML='隐藏此模式';
lib.config.hiddenModePack.remove(mode);
}
game.saveConfig('hiddenModePack',lib.config.hiddenModePack);
});
if(hasexpand){
hidemode.classList.add('auto-hide');
}
2015-10-29 17:36:14 +00:00
if(info.config.update){
info.config.update(config,map);
}
}
return node;
};
for(var i in lib.mode){
2015-11-28 08:29:42 +00:00
if(lib.config.all.mode.contains(i)){
createModeConfig(i,start.firstChild);
}
2015-10-29 17:36:14 +00:00
}
var active=start.firstChild.querySelector('.active');
if(!active){
active=start.firstChild.firstChild;
active.classList.add('active');
}
rightPane.appendChild(active.link);
}());
(function(){
var start=menux.pages[1];
var rightPane=start.lastChild;
var clickMode=function(){
var active=this.parentNode.querySelector('.active');
if(active===this){
return;
}
active.classList.remove('active');
active.link.remove();
active=this;
this.classList.add('active');
rightPane.appendChild(this.link);
};
2015-10-30 09:13:19 +00:00
var clickAutoSkill=function(bool){
var name=this._link.config._name;
var list=lib.config.autoskilllist;
if(bool){
list.remove(name);
}
else{
list.add(name);
}
game.saveConfig('autoskilllist',list);
};
for(var i in lib.skill){
2015-11-06 10:05:08 +00:00
if(!lib.skilllist.contains(i)) continue;
2015-10-30 09:13:19 +00:00
if(lib.skill[i].frequent&&lib.translate[i]){
lib.configMenu.skill.config[i]={
name:lib.translate[i],
init:true,
type:'autoskill',
onclick:clickAutoSkill
}
}
}
var clickBanSkill=function(bool){
var name=this._link.config._name;
var list=lib.config.forbidlist;
if(bool){
list.remove(name);
}
else{
list.add(name);
}
game.saveConfig('forbidlist',list);
};
var forbid=lib.config.forbid;
lib.config.forbidmap={};
if(!lib.config.forbidlist){
game.saveConfig('forbidlist',[]);
}
for(var i=0;i<forbid.length;i++){
2015-11-06 10:05:08 +00:00
var skip=false;
2015-10-30 09:13:19 +00:00
var str='';
var str2='';
for(var j=0;j<forbid[i].length;j++){
2015-11-06 10:05:08 +00:00
if(!lib.skilllist.contains(forbid[i][j])){
skip=true;
break;
}
2015-10-30 09:13:19 +00:00
str+=get.translation(forbid[i][j])+'+';
str2+=forbid[i][j]+'+';
}
2015-11-06 10:05:08 +00:00
if(skip) continue;
2015-10-30 09:13:19 +00:00
lib.config.forbidmap[str2]=forbid[i];
str=str.slice(0,str.length-1);
str2=str2.slice(0,str2.length-1);
lib.configMenu.skill.config[str2]={
name:str,
init:true,
type:'banskill',
onclick:clickBanSkill
}
}
2015-10-29 17:36:14 +00:00
var createModeConfig=function(mode,position){
var info=lib.configMenu[mode];
var page=ui.create.div('');
var node=ui.create.div('.menubutton.large',info.name,position,clickMode);
node.link=page;
node.mode=mode;
var map={};
if(info.config){
var hiddenNodes=[];
2015-10-30 09:13:19 +00:00
var autoskillNodes=[];
var banskillNodes=[];
var banskill;
2015-11-09 23:11:17 +00:00
if(mode=='playpack'){
page.style.paddingBottom='10px';
}
else if(mode=='skill'){
2015-10-30 09:13:19 +00:00
var autoskillexpanded=false;
var banskillexpanded=false;
ui.create.div('.config.more','自动发动 <div>&gt;</div>',page,function(){
if(autoskillexpanded){
this.classList.remove('on');
for(var k=0;k<autoskillNodes.length;k++){
2015-11-28 03:45:23 +00:00
autoskillNodes[k].style.display='none';
2015-10-30 09:13:19 +00:00
}
}
else{
this.classList.add('on');
for(var k=0;k<autoskillNodes.length;k++){
2015-11-28 03:45:23 +00:00
autoskillNodes[k].style.display='';
2015-10-30 09:13:19 +00:00
}
}
autoskillexpanded=!autoskillexpanded;
});
banskill=ui.create.div('.config.more','双将禁配 <div>&gt;</div>',page,function(){
if(banskillexpanded){
this.classList.remove('on');
for(var k=0;k<banskillNodes.length;k++){
2015-11-28 03:45:23 +00:00
banskillNodes[k].style.display='none';
2015-10-30 09:13:19 +00:00
}
}
else{
this.classList.add('on');
for(var k=0;k<banskillNodes.length;k++){
2015-11-28 03:45:23 +00:00
banskillNodes[k].style.display='';
2015-10-30 09:13:19 +00:00
}
}
banskillexpanded=!banskillexpanded;
});
2015-11-06 10:05:08 +00:00
page.style.paddingBottom='10px';
2015-10-30 09:13:19 +00:00
}
2015-10-29 17:36:14 +00:00
for(var j in info.config){
if(j==='update'){
continue;
}
var cfg=copyObj(info.config[j]);
cfg._name=j;
var config=lib.config;
if(!config.hasOwnProperty(j)){
2015-11-05 02:34:35 +00:00
if(cfg.type!='autoskill'&&cfg.type!='banskill'){
game.saveConfig(j,cfg.init);
}
2015-10-29 17:36:14 +00:00
}
else{
cfg.init=config[j];
}
if(!cfg.onclick){
cfg.onclick=function(result){
var cfg=this._link.config;
game.saveConfig(cfg._name,result);
if(cfg.onsave){
cfg.onsave.call(this,result);
}
};
}
if(info.config.update){
cfg.update=function(){
info.config.update(config,map);
};
}
var cfgnode=createConfig(cfg);
2015-10-30 09:13:19 +00:00
if(cfg.type=='autoskill'){
autoskillNodes.push(cfgnode);
2015-11-28 03:45:23 +00:00
// cfgnode.style.transition='all 0s';
2015-10-30 09:13:19 +00:00
cfgnode.classList.add('indent');
2015-11-28 03:45:23 +00:00
// cfgnode.hide();
cfgnode.style.display='none';
2015-10-30 09:13:19 +00:00
}
else if(cfg.type=='banskill'){
banskillNodes.push(cfgnode);
2015-11-28 03:45:23 +00:00
// cfgnode.style.transition='all 0s';
2015-10-30 09:13:19 +00:00
cfgnode.classList.add('indent');
2015-11-28 03:45:23 +00:00
// cfgnode.hide();
cfgnode.style.display='none';
2015-10-30 09:13:19 +00:00
}
if(j=='import_data_button'){
ui.import_data_button=cfgnode;
cfgnode.hide();
cfgnode.querySelector('button').onclick=function(){
2015-12-02 10:40:25 +00:00
var fileToLoad=this.previousSibling.files[0];
if(fileToLoad){
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var data = fileLoadedEvent.target.result;
if(!data) return;
try{
data=JSON.parse(lib.init.decode(data));
localStorage.clear();
for(var i in data){
localStorage.setItem(i,data[i]);
}
2015-10-30 09:13:19 +00:00
}
2015-12-02 10:40:25 +00:00
catch(e){
2015-12-06 15:23:47 +00:00
console.log(e);
2015-12-02 10:40:25 +00:00
alert('导入失败');
return;
}
alert('导入成功');
game.reload();
};
fileReader.readAsText(fileToLoad, "UTF-8");
}
}
}
else if(j=='import_background'){
cfgnode.querySelector('button').onclick=function(){
var fileToLoad=this.previousSibling.files[0];
if(fileToLoad){
game.putDB('image','background',fileToLoad);
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var data = fileLoadedEvent.target.result;
ui.background.style.backgroundImage='url('+data+')';
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
}
else{
game.deleteDB('image','background');
ui.background.style.backgroundImage='none';
}
2015-10-30 09:13:19 +00:00
}
}
2015-12-08 00:56:54 +00:00
else if(j=='import_music'){
cfgnode.querySelector('button').onclick=function(){
delete _status.background_music_src;
var fileToLoad=this.previousSibling.files[0];
if(fileToLoad){
game.putDB('audio','background',fileToLoad);
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var data = fileLoadedEvent.target.result;
_status.background_music_src=data;
game.playBackgroundMusic();
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
}
else{
game.deleteDB('audio','background');
delete _status.background_music_src;
ui.backgroundMusic.src='';
}
}
}
2015-10-29 17:36:14 +00:00
map[j]=cfgnode;
if(!cfg.unfrequent){
2015-10-30 09:13:19 +00:00
if(cfg.type=='autoskill'){
page.insertBefore(cfgnode,banskill);
}
else{
page.appendChild(cfgnode);
}
2015-10-29 17:36:14 +00:00
}
else{
2015-12-07 11:15:35 +00:00
// cfgnode.classList.add('auto-hide');
2015-10-29 17:36:14 +00:00
hiddenNodes.push(cfgnode);
}
}
var expanded=false;
if(hiddenNodes.length){
2015-12-07 11:15:35 +00:00
// ui.create.div('.config.more','更多 <div>&gt;</div>',page,function(){
// if(expanded){
// this.classList.remove('on');
// this.parentNode.classList.remove('expanded');
// }
// else{
// this.classList.add('on');
// this.parentNode.classList.add('expanded');
// }
// expanded=!expanded;
// });
page.classList.add('morenodes');
2015-10-29 17:36:14 +00:00
for(var k=0;k<hiddenNodes.length;k++){
page.appendChild(hiddenNodes[k]);
}
}
if(info.config.update){
info.config.update(config,map);
}
}
return node;
};
for(var i in lib.configMenu){
createModeConfig(i,start.firstChild);
}
var active=start.firstChild.querySelector('.active');
if(!active){
active=start.firstChild.firstChild;
active.classList.add('active');
}
rightPane.appendChild(active.link);
}());
2015-10-30 15:32:48 +00:00
(function(){
var start=menux.pages[2];
var rightPane=start.lastChild;
var clickMode=function(){
var active=this.parentNode.querySelector('.active');
2015-12-06 15:23:47 +00:00
if(active){
if(active===this){
return;
}
active.classList.remove('active');
active.link.remove();
2015-10-30 15:32:48 +00:00
}
this.classList.add('active');
rightPane.appendChild(this.link);
};
var updateNodes=function(){
for(var i=0;i<start.firstChild.childNodes.length;i++){
var node=start.firstChild.childNodes[i];
if(node.link){
2015-11-09 03:15:16 +00:00
if(node.mode.indexOf('mode_')==0) continue;
2015-12-02 10:40:25 +00:00
if(node.mode=='custom') continue;
2015-12-06 15:23:47 +00:00
if(lib.config.customCharacterPack[node.mode]) continue;
2015-10-30 15:32:48 +00:00
if(lib.config.characters.contains(node.mode)){
node.classList.remove('off');
node.link.firstChild.classList.add('on');
}
else{
node.classList.add('off');
node.link.firstChild.classList.remove('on');
}
}
}
}
var togglePack=function(bool){
var name=this._link.config._name;
if(bool){
lib.config.characters.add(name);
}
else{
lib.config.characters.remove(name);
}
game.saveConfig('characters',lib.config.characters);
updateNodes();
};
2015-12-06 15:23:47 +00:00
var createModeConfig=function(mode,position,position2){
2015-10-30 15:32:48 +00:00
var info=lib.characterPack[mode];
var page=ui.create.div('');
var node=ui.create.div('.menubutton.large',lib.translate[mode+'_character_config'],position,clickMode);
2015-12-06 15:23:47 +00:00
if(position2){
position.insertBefore(node,position2);
}
2015-10-30 15:32:48 +00:00
node.link=page;
node.mode=mode;
var list=[];
for(var i in info){
list.push(i);
}
var cfgnode=createConfig({
name:'开启',
_name:mode,
init:lib.config.characters.contains(mode),
onclick:togglePack
});
2015-12-06 15:23:47 +00:00
if(mode.indexOf('mode_')!=0&&!lib.config.customCharacterPack[mode]){
2015-11-09 03:15:16 +00:00
page.appendChild(cfgnode);
}
2015-10-30 15:32:48 +00:00
var banCharacter=function(){
2015-11-30 13:08:29 +00:00
if(_status.clicked){
_status.clicked=false;
return;
}
2015-11-09 03:15:16 +00:00
if(mode.indexOf('mode_')==0){
return;
}
2015-10-30 15:32:48 +00:00
this.classList.toggle('unselectable');
if(this.classList.contains('unselectable')){
lib.config.banned.add(this.link);
2015-11-21 05:30:26 +00:00
this.node.hp._innerHTML=this.node.hp.innerHTML;
this.node.hp.innerHTML='已禁用';
this.node.hp.style.top='8px';
2015-10-30 15:32:48 +00:00
}
else{
lib.config.banned.remove(this.link);
2015-11-21 05:30:26 +00:00
this.node.hp.innerHTML=this.node.hp._innerHTML;
this.node.hp.style.top='';
2015-10-30 15:32:48 +00:00
}
game.saveConfig('banned',lib.config.banned);
};
var buttons=ui.create.buttons(list,'character',page);
for(var i=0;i<buttons.length;i++){
buttons[i].classList.add('noclick');
buttons[i].listen(banCharacter);
2015-11-21 05:30:26 +00:00
buttons[i].node.hp.style.transition='all 0s';
2015-10-30 15:32:48 +00:00
if(lib.config.banned.contains(buttons[i].link)){
buttons[i].classList.add('unselectable');
2015-11-21 05:30:26 +00:00
buttons[i].node.hp._innerHTML=buttons[i].node.hp.innerHTML;
buttons[i].node.hp.innerHTML='已禁用';
buttons[i].node.hp.style.top='8px';
2015-10-30 15:32:48 +00:00
}
}
page.classList.add('menu-buttons');
2015-12-06 15:23:47 +00:00
if(lib.config.customCharacterPack[mode]){
2015-12-07 11:15:35 +00:00
ui.create.div('.config.more','编辑武将包',page,function(){
if(this.innerHTML=='编辑武将包'){
this.innerHTML='确认编辑';
var that=this;
setTimeout(function(){
that.innerHTML='编辑武将包';
},1000);
}
else{
var pack=lib.config.customCharacterPack[mode];
delete lib.config.customCharacterPack[mode];
game.saveConfig('customCharacterPack',lib.config.customCharacterPack);
page.remove();
node.remove();
lib.recreateCustomCharacters();
var active=ui.customCharacter;
active.classList.add('active');
rightPane.appendChild(active.link);
}
});
2015-12-06 15:23:47 +00:00
ui.create.div('.config.more','删除武将包',page,function(){
if(this.innerHTML=='删除武将包'){
this.innerHTML='确认删除';
var that=this;
setTimeout(function(){
that.innerHTML='删除武将包';
},1000);
}
else{
var pack=lib.config.customCharacterPack[mode];
delete lib.config.customCharacterPack[mode];
game.saveConfig('customCharacterPack',lib.config.customCharacterPack);
page.remove();
node.remove();
for(var i=0;i<pack.character.length;i++){
2015-12-07 11:15:35 +00:00
lib.customCharacters.remove(pack.character[i]);
delete lib.character[pack.character[i]];
2015-12-06 15:23:47 +00:00
game.deleteDB('character',pack.character[i]);
game.deleteDB('image','character:'+pack.character[i]);
2015-12-07 11:15:35 +00:00
lib.config.banned.remove(pack.character[i])
2015-12-06 15:23:47 +00:00
}
2015-12-07 11:15:35 +00:00
game.saveConfig('banned',lib.config.banned);
2015-12-06 15:23:47 +00:00
for(var i=0;i<pack.skill.length;i++){
game.deleteDB('skill',pack.skill[i]);
}
}
2015-12-07 11:15:35 +00:00
}).style.marginTop='5px';
2015-12-06 15:23:47 +00:00
}
else if(mode.indexOf('mode_')!=0){
ui.create.div('.config.more','隐藏武将包',page,function(){
if(this.innerHTML=='隐藏武将包'){
this.innerHTML='武将包将在重启后隐藏';
lib.config.hiddenCharacterPack.add(mode);
}
else{
this.innerHTML='隐藏武将包';
lib.config.hiddenCharacterPack.remove(mode);
}
game.saveConfig('hiddenCharacterPack',lib.config.hiddenCharacterPack);
});
}
2015-10-30 15:32:48 +00:00
return node;
};
for(var i=0;i<lib.config.all.characters.length;i++){
createModeConfig(lib.config.all.characters[i],start.firstChild);
}
2015-11-09 03:15:16 +00:00
for(var i in lib.characterPack){
if(i.indexOf('mode_')==0){
createModeConfig(i,start.firstChild);
}
}
2015-10-30 15:32:48 +00:00
var active=start.firstChild.querySelector('.active');
if(!active){
active=start.firstChild.firstChild;
active.classList.add('active');
}
rightPane.appendChild(active.link);
2015-12-02 10:40:25 +00:00
lib.onDB(function(){
var page=ui.create.div('.menu-buttons');
2015-12-06 15:23:47 +00:00
var node=ui.create.div('.menubutton.large','自定义',clickMode);
2015-12-07 11:15:35 +00:00
ui.customCharacter=node;
2015-12-06 15:23:47 +00:00
start.firstChild.insertBefore(node,start.firstChild.querySelector('.lefttext'));
2015-12-02 10:40:25 +00:00
node.link=page;
node.mode='custom';
2015-12-06 15:23:47 +00:00
var currentEditing=null;
var packExporting=false;
var clickButton=function(){
if(packExporting){
this.classList.toggle('selected');
return;
}
resetImport();
resetEditor();
if(currentEditing==this){
currentEditing=null;
return;
}
else{
currentEditing=this;
}
toggle.classList.add('on');
newCharacter.style.display='';
fakeme.classList.add('inited');
delete fakeme.image;
fakeme.setBackground(this.link,'character');
newCharacter.querySelector('.new_name').value=this.link;
var info=lib.character[this.link];
newCharacter.querySelector('.new_hp').value=info[2];
sexes.value=info[0];
groups.value=info[1];
2015-12-07 11:15:35 +00:00
if(info[4]){
for(var i=0;i<options.childNodes.length-1;i++){
if(info[4].contains(options.childNodes[i].lastChild.name)){
options.childNodes[i].lastChild.checked=true;
}
}
}
2015-12-06 15:23:47 +00:00
var skills=info[3];
for(var i=0;i<skills.length;i++){
var node=ui.create.div(skillList.firstChild);
node.skill=skills[i];
ui.create.div('',lib.translate[skills[i]],node,editnode);
2015-12-07 11:15:35 +00:00
ui.create.div('','×',node,deletenode);
2015-12-06 15:23:47 +00:00
if(lib.skill[skills[i]].createInfo){
node.createInfo=lib.skill[skills[i]].createInfo;
}
}
toggle.innerHTML='编辑武将 <div>&gt;</div>';
var confirm=newCharacter.querySelector('.menubutton.large');
confirm.innerHTML='编辑武将';
2015-12-10 15:57:45 +00:00
confirm._origin=this;
2015-12-06 15:23:47 +00:00
var button=this;
2015-12-10 15:57:45 +00:00
var delnodefunc=function(){
2015-12-06 15:23:47 +00:00
button.remove();
2015-12-09 03:05:36 +00:00
lib.customCharacters.remove(button.link);
2015-12-06 15:23:47 +00:00
game.deleteDB('character',button.link);
game.deleteDB('image','character:'+button.link);
var skills=lib.character[button.link][3];
2015-12-10 15:57:45 +00:00
delete lib.character[button.link];
2015-12-06 15:23:47 +00:00
for(var i=0;i<skills.length;i++){
if(!lib.checkSkillName(skills[i])){
var keep=false;
for(var j=0;j<lib.customCharacters.length;j++){
if(lib.customCharacters[j]==button.link) continue;
if(lib.character[lib.customCharacters[j]][3].contains(skills[i])){
keep=true;break;
}
}
if(!keep){
game.deleteDB('skill',skills[i]);
}
}
}
resetEditor();
2015-12-10 15:57:45 +00:00
};
var delnode=ui.create.div('.menubutton.large','删除',confirm.parentNode,delnodefunc);
2015-12-06 15:23:47 +00:00
delnode.style.marginLeft='25px';
}
var createButton=function(name){
var button=ui.create.button(name,'character');
button.listen(clickButton);
2015-12-07 11:15:35 +00:00
button.classList.add('noclick');
2015-12-06 15:23:47 +00:00
page.insertBefore(button,page.firstChild);
}
var cl=function(){
for(var i in lib.config.customCharacterPack){
lib.characterPack[i]={};
lib.translate[i+'_character_config']=i;
for(var j=0;j<lib.config.customCharacterPack[i].character.length;j++){
var namej=lib.config.customCharacterPack[i].character[j];
lib.characterPack[i][namej]=lib.character[namej];
}
createModeConfig(i,start.firstChild,node);
}
for(var i=0;i<lib.customCharacters.length;i++){
2015-12-07 11:15:35 +00:00
var clname=lib.customCharacters[i];
for(var j=0;j<lib.character[clname][3].length;j++){
if(!lib.skill[lib.character[clname][3][j]]){
lib.character[clname][3].splice(j--,1);
}
}
if(!lib.checkCharacterName(clname))
createButton(clname);
2015-12-06 15:23:47 +00:00
}
}
if(_status.characterLoaded){
cl();
}
else{
lib.onCharacterLoad=cl;
}
2015-12-07 11:15:35 +00:00
lib.recreateCustomCharacters=function(){
var buttons=page.querySelectorAll('.button.character');
var list=[];
for(var i=0;i<buttons.length;i++){
list.push(buttons[i]);
}
for(var i=0;i<list.length;i++){
list[i].remove();
}
for(var i=0;i<lib.customCharacters.length;i++){
if(!lib.checkCharacterName(lib.customCharacters[i]))
createButton(lib.customCharacters[i]);
}
resetEditor();
resetImport();
resetExport();
}
2015-12-06 15:23:47 +00:00
var importCharacter;
var toggle3=ui.create.div('.config.more','导入武将包 <div>&gt;</div>',page,function(){
this.classList.toggle('on');
if(this.classList.contains('on')){
importCharacter.style.display='';
resetEditor();
resetExport();
currentEditing=null;
}
else{
importCharacter.style.display='none';
}
});
var resetImport=function(){
importCharacter.style.display='none';
toggle3.classList.remove('on')
}
importCharacter=ui.create.div('.new_character.export.import',page);
importCharacter.style.display='none';
ui.create.div('','<input type="file" accept="application/zip"><button>确定</button>',importCharacter);
importCharacter.firstChild.lastChild.onclick=function(){
var fileToLoad=this.previousSibling.files[0];
if(fileToLoad){
var zipReady=function(){
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var data = fileLoadedEvent.target.result;
var zip=new JSZip();
zip.load(data);
var str=zip.file('pack.js').asText();
try{
eval(str);
if(!game.importedPack) throw('err');
for(var i in game.importedPack.character){
var buttons=page.querySelectorAll('.button.character');
for(var j=0;j<buttons.length;j++){
if(buttons[j].link==i){
buttons[j].remove();
break;
}
}
var str=zip.file(i+'.jpg').asArrayBuffer();
if(str){
var blob=new Blob([str]);
var fileReader=new FileReader();
fileReader.onload = (function(i){
return function(fileLoadedEvent)
{
var data = fileLoadedEvent.target.result;
game.putDB('image','character:'+i,data);
};
}(i))
fileReader.readAsDataURL(blob, "UTF-8");
}
}
var name=game.importedPack.name;
setTimeout(function(){
lib.characterPack[name]={};
lib.translate[name+'_character_config']=name;
for(var j=0;j<lib.config.customCharacterPack[name].character.length;j++){
var namej=lib.config.customCharacterPack[name].character[j];
lib.characterPack[name][namej]=lib.character[namej];
}
2015-12-07 11:15:35 +00:00
clickMode.call(createModeConfig(name,start.firstChild,node));
2015-12-06 15:23:47 +00:00
},500);
delete game.importedPack;
}
catch(e){
console.log(e);
alert('导入失败');
}
resetImport();
};
fileReader.readAsArrayBuffer(fileToLoad, "UTF-8");
}
if(!window.JSZip){
lib.init.js('game','jszip',zipReady);
}
else{
zipReady();
}
}
}
var exportCharacter;
var toggle2=ui.create.div('.config.more','导出武将包 <div>&gt;</div>',page,function(){
this.classList.toggle('on');
if(this.classList.contains('on')){
exportCharacter.style.display='';
resetEditor();
resetImport();
currentEditing=null;
packExporting=true;
}
else{
2015-12-09 03:05:36 +00:00
resetExport();
2015-12-06 15:23:47 +00:00
}
});
var resetExport=function(){
packExporting=false;
exportCharacter.style.display='none';
toggle2.classList.remove('on');
var selected=page.querySelectorAll('.button.character.selected');
var list=[];
for(var i=0;i<selected.length;i++){
list.push(selected[i]);
}
for(var i=0;i<list.length;i++){
list[i].classList.remove('selected');
}
}
exportCharacter=ui.create.div('.new_character.export',page);
exportCharacter.style.display='none';
ui.create.div('','名称:<input type="text"><button>确定</button>',exportCharacter);
exportCharacter.firstChild.lastChild.onclick=function(){
var name=this.previousSibling.value;
var selected=page.querySelectorAll('.button.character.selected');
var list=[];
var list2=[];
for(var i=0;i<selected.length;i++){
list.push(selected[i].link);
list2.push(selected[i]);
}
for(var i=0;i<list2.length;i++){
list2[i].classList.remove('selected');
}
2015-12-07 11:15:35 +00:00
if(name) game.exportCharacters(name,list.length?list:null,function(result){
game.import('character',result);
for(var i in result.character){
var buttons=page.querySelectorAll('.button.character');
for(var j=0;j<buttons.length;j++){
if(buttons[j].link==i){
buttons[j].remove();
break;
}
}
}
lib.characterPack[name]={};
lib.translate[name+'_character_config']=name;
for(var j=0;j<lib.config.customCharacterPack[name].character.length;j++){
var namej=lib.config.customCharacterPack[name].character[j];
lib.characterPack[name][namej]=lib.character[namej];
}
clickMode.call(createModeConfig(name,start.firstChild,node));
resetExport();
delete game.importedPack;
});
2015-12-06 15:23:47 +00:00
}
var newCharacter;
var toggle=ui.create.div('.config.more','创建武将 <div>&gt;</div>',page,function(){
2015-12-02 10:40:25 +00:00
this.classList.toggle('on');
2015-12-06 15:23:47 +00:00
if(this.classList.contains('on')){
newCharacter.style.display='';
resetExport();
resetImport();
}
else{
newCharacter.style.display='none';
}
});
var resetEditor=function(){
toggle.classList.remove('on');
newCharacter.style.display='none';
fakeme.classList.remove('inited');
delete fakeme.image;
fakeme.style.backgroundImage='';
var inputs=newCharacter.querySelectorAll('input');
for(var i=0;i<inputs.length;i++){
inputs[i].value='';
}
inputs=newCharacter.querySelectorAll('textarea');
for(var i=0;i<inputs.length;i++){
inputs[i].value='';
}
skillList.firstChild.innerHTML='';
toggle.innerHTML='创建武将 <div>&gt;</div>';
var node=newCharacter.querySelector('.menubutton.large');
node.innerHTML='创建武将';
2015-12-10 15:57:45 +00:00
delete node._origin;
2015-12-06 15:23:47 +00:00
if(node.nextSibling){
node.nextSibling.remove();
}
}
newCharacter=ui.create.div('.new_character',page);
newCharacter.style.display='none';
var fakeme=ui.create.div('.avatar',newCharacter);
var input=document.createElement('input');
input.type='file';
input.accept='image/jpeg';
input.onchange=function(){
var fileToLoad=input.files[0];
if(fileToLoad){
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var data = fileLoadedEvent.target.result;
fakeme.image=data;
fakeme.style.backgroundImage='url('+data+')';
fakeme.classList.add('inited');
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
}
}
fakeme.appendChild(input);
ui.create.div('.select_avatar','选择头像',fakeme);
ui.create.div('.indent','姓名:<input class="new_name" type="text">',newCharacter).style.paddingTop='10px';
ui.create.div('.indent','体力:<input class="new_hp" type="text">',newCharacter).style.paddingTop='10px';
var sexes=ui.create.selectlist([
['male','男'],
['female','女'],
['none','无'],
],null,ui.create.div('.indent','性别:',newCharacter));
var groups=ui.create.selectlist([
['wei','魏'],
['shu','蜀'],
['wu','吴'],
['qun','群'],
],null,ui.create.div('.indent','势力:',newCharacter));
2015-12-07 11:15:35 +00:00
var options=ui.create.div('.add_skill.options','<span>主公<input type="checkbox" name="zhu"></span><span>BOSS<input type="checkbox" name="boss"></span><span>AI禁选<input type="checkbox" name="forbidai"></span><br>',newCharacter);
2015-12-06 15:23:47 +00:00
var addSkill=ui.create.div('.add_skill','添加技能<br>',newCharacter);
var list=[];
for(var i in lib.character){
2015-12-07 11:15:35 +00:00
if(!lib.customCharacters.contains(i)&&lib.character[i][3].length);
2015-12-06 15:23:47 +00:00
list.push([i,lib.translate[i]]);
}
list.sort(function(a,b){
a=a[0];b=b[0];
var aa=a,bb=b;
if(aa.indexOf('_')!=-1){
aa=aa.slice(aa.indexOf('_')+1);
}
if(bb.indexOf('_')!=-1){
bb=bb.slice(bb.indexOf('_')+1);
}
if(aa!=bb){
return aa>bb?1:-1;
}
return a>b?1:-1;
});
var list2=[];
var skills=lib.character[list[0][0]][3];
for(var i=0;i<skills.length;i++){
list2.push([skills[i],lib.translate[skills[i]]]);
}
ui.create.selectlist(list,list[0],addSkill).onchange=function(){
var skills=lib.character[this.value][3];
skillopt.innerHTML='';
for(var i=0;i<skills.length;i++){
var option=document.createElement('option');
option.value=skills[i];
option.innerHTML=lib.translate[skills[i]];
skillopt.appendChild(option);
}
};
var skillopt=ui.create.selectlist(list2,list2[0],addSkill);
var addSkillButton=document.createElement('button');
addSkillButton.innerHTML='添加';
addSkill.appendChild(addSkillButton);
2015-12-07 11:15:35 +00:00
var deletenode=function(){
2015-12-06 15:23:47 +00:00
this.parentNode.remove();
}
var editnode=function(){
var info=this.parentNode.createInfo;
if(info){
createSkill.lastChild.classList.remove('hidden');
createSkill.firstChild.innerHTML='创建技能';
2015-12-07 11:15:35 +00:00
skillList.style.top='435px';
2015-12-06 15:23:47 +00:00
createSkill.lastChild.querySelector('.skillname').value=info.name;
createSkill.lastChild.querySelector('.skilldescription').value=info.description;
createSkill.lastChild.querySelector('textarea').value=info.content;
}
}
addSkillButton.onclick=function(){
for(var i=0;i<skillList.firstChild.childNodes.length;i++){
if(skillList.firstChild.childNodes[i].skill==skillopt.value) return;
}
var node=ui.create.div(skillList.firstChild);
node.skill=skillopt.value;
ui.create.div('',lib.translate[skillopt.value],node,editnode);
2015-12-07 11:15:35 +00:00
ui.create.div('','×',node,deletenode);
2015-12-06 15:23:47 +00:00
if(lib.skill[skillopt.value].createInfo){
node.createInfo=lib.skill[skillopt.value].createInfo;
}
}
var createSkill=ui.create.div('.add_skill.create','<div>创建技能...</div><br><div class="hidden"></div>',newCharacter);
createSkill.firstChild.listen(function(){
createSkill.lastChild.classList.toggle('hidden');
if(createSkill.lastChild.classList.contains('hidden')){
this.innerHTML='创建技能...';
skillList.style.top='';
}
else{
this.innerHTML='创建技能';
2015-12-07 11:15:35 +00:00
skillList.style.top='435px';
2015-12-06 15:23:47 +00:00
}
});
var newSkill=document.createElement('textarea');
createSkill.lastChild.appendChild(newSkill);
createSkill.lastChild.innerHTML+='<br>';
ui.create.div('','技能名称:<input class="skillname" type="text">',createSkill.lastChild);
createSkill.lastChild.innerHTML+='<br>';
2015-12-07 11:15:35 +00:00
ui.create.div('','技能描述:<input class="skilldescription" type="text"><br><button>确定</button><button>取消</button>',createSkill.lastChild);
createSkill.lastChild.lastChild.lastChild.previousSibling.style.marginTop='5px';
createSkill.lastChild.lastChild.lastChild.previousSibling.style.marginRight='3px';
createSkill.lastChild.lastChild.lastChild.previousSibling.onclick=function(){
2015-12-06 15:23:47 +00:00
var node;
var name=createSkill.lastChild.querySelector('.skillname').value;
var description=createSkill.lastChild.querySelector('.skilldescription').value;
var content=createSkill.lastChild.querySelector('textarea').value;
if(!name||!description) return;
if(lib.checkSkillName(name)){
alert('技能名重复');
return;
}
for(var i=0;i<skillList.firstChild.childNodes.length;i++){
if(skillList.firstChild.childNodes[i].skill==name){
node=skillList.firstChild.childNodes[i];
}
}
if(!node){
node=ui.create.div(skillList.firstChild);
node.skill=name;
var name2=name;
if(name.indexOf(':')!=-1){
name2=name2.slice(name2.indexOf(':')+1);
}
ui.create.div('',name2,node,editnode);
2015-12-07 11:15:35 +00:00
ui.create.div('','×',node,deletenode);
2015-12-06 15:23:47 +00:00
}
node.createInfo={
name:name,
description:description,
content:content
}
2015-12-07 11:15:35 +00:00
createSkill.lastChild.querySelector('.skillname').value='';
createSkill.lastChild.querySelector('.skilldescription').value='';
createSkill.lastChild.querySelector('textarea').value='';
createSkill.lastChild.classList.add('hidden');
createSkill.firstChild.innerHTML='创建技能...';
skillList.style.top='';
2015-12-06 15:23:47 +00:00
}
2015-12-07 11:15:35 +00:00
createSkill.lastChild.lastChild.lastChild.onclick=function(){
createSkill.lastChild.querySelector('.skillname').value='';
createSkill.lastChild.querySelector('.skilldescription').value='';
createSkill.lastChild.querySelector('textarea').value='';
createSkill.lastChild.classList.add('hidden');
createSkill.firstChild.innerHTML='创建技能...';
skillList.style.top='';
};
2015-12-06 15:23:47 +00:00
var skillList=ui.create.div('.skill_list',newCharacter);
ui.create.div(skillList);
ui.create.div('.menubutton.large','创建武将',ui.create.div(skillList),function(){
var image=fakeme.image;if(!image&&this.innerHTML!='编辑武将') return;
var name=newCharacter.querySelector('.new_name').value;if(!name) return;
if(lib.checkCharacterName(name)){
alert('武将名重复');return;
}
var hp=newCharacter.querySelector('.new_hp').value;
hp=parseInt(hp);
if(!hp) hp=1;
var skills=[];
2015-12-10 15:57:45 +00:00
var dontcreate=false;
if(this.innerHTML=='编辑武将'&&this._origin&&this._origin.link!=name){
dontcreate=true;
var origin=this._origin;
game.getDB('image','character:'+this._origin.link,function(data){
if(data){
game.putDB('image','character:'+name,data);
origin.remove();
lib.customCharacters.remove(origin.link);
game.deleteDB('character',origin.link);
game.deleteDB('image','character:'+origin.link);
if(lib.character[origin.link]){
var skills=lib.character[origin.link][3];
delete lib.character[origin.link];
for(var i=0;i<skills.length;i++){
if(!lib.checkSkillName(skills[i])){
var keep=false;
for(var j=0;j<lib.customCharacters.length;j++){
if(lib.customCharacters[j]==origin.link) continue;
if(lib.character[lib.customCharacters[j]][3].contains(skills[i])){
keep=true;break;
}
}
if(!keep){
game.deleteDB('skill',skills[i]);
}
}
}
}
}
createButton(name);
});
2015-12-06 15:23:47 +00:00
}
2015-12-10 15:57:45 +00:00
else{
if(image){
game.putDB('image','character:'+name,image);
}
}
2015-12-06 15:23:47 +00:00
for(var i=0;i<skillList.firstChild.childNodes.length;i++){
2015-12-07 11:15:35 +00:00
if(skillList.firstChild.childNodes[i].createInfo&&
lib.checkSkillName(skillList.firstChild.childNodes[i].skill)) continue;
2015-12-06 15:23:47 +00:00
skills.add(skillList.firstChild.childNodes[i].skill);
var info=skillList.firstChild.childNodes[i].createInfo;
if(info){
try{
eval('lib.skill["'+info.name+'"]={'+info.content+'}');
}
catch(e){
console.log(e);
lib.skill[info.name]={};
}
lib.skill[info.name].createInfo=info;
lib.setTranslate(info.name);
lib.translate[info.name+'_info']=info.description;
game.putDB('skill',info.name,info);
}
}
2015-12-07 11:15:35 +00:00
var tags=[];
for(var i=0;i<options.childNodes.length-1;i++){
if(options.childNodes[i].lastChild.checked){
tags.push(options.childNodes[i].lastChild.name);
}
}
if(tags.contains('boss')){
tags.add('bossallowed');
}
var charinfo=[sexes.value,groups.value,hp,skills,tags];
2015-12-06 15:23:47 +00:00
game.putDB('character',name,charinfo);
lib.character[name]=charinfo;
lib.customCharacters.add(name);
lib.setTranslate(name);
if(this.innerHTML=='编辑武将'){
var buttons=page.querySelectorAll('.button.character');
for(var i=0;i<buttons.length;i++){
if(buttons[i].link==name){
buttons[i].remove();
break;
}
}
}
2015-12-10 15:57:45 +00:00
if(!dontcreate) createButton(name);
2015-12-06 15:23:47 +00:00
resetEditor();
currentEditing=null;
2015-12-10 15:57:45 +00:00
delete this._origin;
2015-12-02 10:40:25 +00:00
});
});
2015-10-30 15:32:48 +00:00
var node1=ui.create.div('.lefttext','全部开启',start.firstChild,function(){
game.saveConfig('characters',lib.config.all.characters);
updateNodes();
});
var node2=ui.create.div('.lefttext','恢复默认',start.firstChild,function(){
game.saveConfig('characters',lib.config.defaultcharacters);
updateNodes();
});
node1.style.marginTop='12px';
node2.style.marginTop='7px';
updateNodes();
}());
(function(){
var start=menux.pages[3];
var rightPane=start.lastChild;
var clickMode=function(){
var active=this.parentNode.querySelector('.active');
if(active===this){
return;
}
active.classList.remove('active');
active.link.remove();
active=this;
this.classList.add('active');
rightPane.appendChild(this.link);
};
var updateNodes=function(){
for(var i=0;i<start.firstChild.childNodes.length;i++){
var node=start.firstChild.childNodes[i];
if(node.link){
2015-11-09 03:15:16 +00:00
if(node.mode.indexOf('mode_')==0) continue;
2015-10-30 15:32:48 +00:00
if(lib.config.cards.contains(node.mode)){
node.classList.remove('off');
node.link.firstChild.classList.add('on');
}
else{
node.classList.add('off');
node.link.firstChild.classList.remove('on');
}
}
}
}
var togglePack=function(bool){
var name=this._link.config._name;
if(bool){
lib.config.cards.add(name);
}
else{
lib.config.cards.remove(name);
}
game.saveConfig('cards',lib.config.cards);
updateNodes();
};
2015-11-28 03:45:23 +00:00
var toggleCardPile=function(bool){
var name=this._link.config._name;
var number=this._link.config._number;
if(bool){
lib.config.bannedpile[name].remove(number);
}
else{
lib.config.bannedpile[name].add(number);
}
game.saveConfig('bannedpile',lib.config.bannedpile);
}
2015-10-30 15:32:48 +00:00
var createModeConfig=function(mode,position){
var info=lib.cardPack[mode];
var page=ui.create.div('');
var node=ui.create.div('.menubutton.large',lib.translate[mode+'_card_config'],position,clickMode);
node.link=page;
node.mode=mode;
var list=[];
for(var i=0;i<info.length;i++){
list.push(['',get.translation(get.type(info[i],'trick')),info[i]]);
}
var cfgnode=createConfig({
name:'开启',
_name:mode,
init:lib.config.cards.contains(mode),
onclick:togglePack
});
2015-11-09 03:15:16 +00:00
if(mode.indexOf('mode_')!=0){
page.appendChild(cfgnode);
}
2015-10-30 15:32:48 +00:00
var banCard=function(){
2015-11-30 13:08:29 +00:00
if(_status.clicked){
_status.clicked=false;
return;
}
2015-11-09 03:15:16 +00:00
if(mode.indexOf('mode_')==0){
return;
}
2015-10-30 15:32:48 +00:00
this.classList.toggle('unselectable');
if(this.classList.contains('unselectable')){
lib.config.bannedcards.add(this.link[2]);
2015-11-21 05:30:26 +00:00
this.node.info._innerHTML=this.node.info.innerHTML;
this.node.info.innerHTML='已禁用';
2015-10-30 15:32:48 +00:00
}
else{
lib.config.bannedcards.remove(this.link[2]);
2015-11-21 05:30:26 +00:00
this.node.info.innerHTML=this.node.info._innerHTML;
this.node.info.style.top='';
2015-10-30 15:32:48 +00:00
}
game.saveConfig('bannedcards',lib.config.bannedcards);
};
var buttons=ui.create.buttons(list,'vcard',page);
for(var i=0;i<buttons.length;i++){
buttons[i].classList.add('noclick');
buttons[i].listen(banCard);
if(lib.config.bannedcards.contains(buttons[i].link[2])){
buttons[i].classList.add('unselectable');
2015-11-21 05:30:26 +00:00
buttons[i].node.info._innerHTML=buttons[i].node.info.innerHTML;
buttons[i].node.info.innerHTML='已禁用';
2015-10-30 15:32:48 +00:00
}
}
page.classList.add('menu-buttons');
2015-12-06 15:23:47 +00:00
if(mode.indexOf('mode_')!=0&&!lib.config.customCardPack[mode]){
ui.create.div('.config.more','隐藏卡牌包',page,function(){
if(this.innerHTML=='隐藏卡牌包'){
this.innerHTML='卡牌包将在重启后隐藏';
lib.config.hiddenCardPack.add(mode);
}
else{
this.innerHTML='隐藏卡牌包';
lib.config.hiddenCardPack.remove(mode);
}
game.saveConfig('hiddenCardPack',lib.config.hiddenCardPack);
});
}
2015-11-28 03:45:23 +00:00
if(mode.indexOf('mode_')!=0&&lib.cardPile[mode]){
var cardpileNodes=[];
var cardpileexpanded=false;
if(!lib.config.bannedpile[mode]){
lib.config.bannedpile[mode]=[];
}
if(!lib.config.addedpile[mode]){
lib.config.addedpile[mode]=[];
}
ui.create.div('.config.more','编辑牌堆 <div>&gt;</div>',page,function(){
if(cardpileexpanded){
this.classList.remove('on');
for(var k=0;k<cardpileNodes.length;k++){
cardpileNodes[k].style.display='none';
}
}
else{
this.classList.add('on');
for(var k=0;k<cardpileNodes.length;k++){
cardpileNodes[k].style.display='';
}
}
cardpileexpanded=!cardpileexpanded;
});
var cfgnode=createConfig({
name:'添加...',
clear:true,
onclick:function(){
this.nextSibling.classList.toggle('hidden');
}
});
cardpileNodes.push(cfgnode);
cfgnode.style.display='none';
cfgnode.classList.add('cardpilecfg');
cfgnode.classList.add('toggle');
cfgnode.style.marginTop='5px';
page.appendChild(cfgnode);
var cardpileadd=ui.create.div('.config.toggle.hidden.cardpilecfg.cardpilecfgadd',page);
var pileaddlist=[];
for(var i=0;i<lib.config.cards.length;i++){
if(!lib.cardPack[lib.config.cards[i]]) continue;
for(var j=0;j<lib.cardPack[lib.config.cards[i]].length;j++){
var cname=lib.cardPack[lib.config.cards[i]][j];
pileaddlist.push([cname,get.translation(cname)]);
}
}
var cardpileaddname=ui.create.selectlist(pileaddlist,null,cardpileadd);
cardpileaddname.style.width='75px';
cardpileaddname.style.marginRight='2px';
cardpileaddname.style.marginLeft='-1px';
var cardpileaddsuit=ui.create.selectlist([
['heart','红桃'],
['diamond','方片'],
['club','梅花'],
['spade','黑桃'],
],null,cardpileadd);
cardpileaddsuit.style.width='53px';
cardpileaddsuit.style.marginRight='2px';
var cardpileaddnumber=ui.create.selectlist([
1,2,3,4,5,6,7,8,9,10,11,12,13
],null,cardpileadd);
cardpileaddnumber.style.width='43px';
cardpileaddnumber.style.marginRight='2px';
var button=document.createElement('button');
button.innerHTML='确定';
button.style.width='40px';
var deletecard=function(){
this.parentNode.remove();
var info=this.parentNode._info;
var list=lib.config.addedpile[mode];
for(var i=0;i<list.length;i++){
if(list[i][0]==info[0]&&list[i][1]==info[1]&&list[i][2]==info[2]){
list.splice(i,1);break;
}
}
game.saveConfig('addedpile',lib.config.addedpile);
};
button.onclick=function(){
var card=[
cardpileaddsuit.value,
cardpileaddnumber.value,
cardpileaddname.value,
];
lib.config.addedpile[mode].push(card);
game.saveConfig('addedpile',lib.config.addedpile);
var cfgnode=ui.create.div('.config.toggle.cardpilecfg');
cfgnode._info=card;
cfgnode.innerHTML=get.translation(card[2])+' '+get.translation(card[0])+card[1];
var cfgnodedelete=document.createElement('span');
cfgnodedelete.classList.add('cardpiledelete');
cfgnodedelete.innerHTML='删除';
cfgnodedelete.onclick=deletecard;
cfgnode.appendChild(cfgnodedelete);
page.insertBefore(cfgnode,cardpileadd.nextSibling);
};
cardpileadd.appendChild(button);
cardpileadd.style.whiteSpace='nowrap';
cardpileNodes.push(cardpileadd);
for(var i=0;i<lib.config.addedpile[mode].length;i++){
var card=lib.config.addedpile[mode][i];
var cfgnode=ui.create.div('.config.toggle.cardpilecfg');
cfgnode._info=card;
cfgnode.innerHTML=get.translation(card[2])+' '+get.translation(card[0])+card[1];
var cfgnodedelete=document.createElement('span');
cfgnodedelete.classList.add('cardpiledelete');
cfgnodedelete.innerHTML='删除';
cfgnodedelete.onclick=deletecard;
cfgnode.appendChild(cfgnodedelete);
cfgnode.style.display='none';
cardpileNodes.push(cfgnode);
page.appendChild(cfgnode);
}
for(var i=0;i<lib.cardPile[mode].length;i++){
var card=lib.cardPile[mode][i];
var cfgnode=createConfig({
name:get.translation(card[2])+' '+get.translation(card[0])+card[1],
_number:i,
_name:mode,
init:!lib.config.bannedpile[mode].contains(i),
onclick:toggleCardPile
});
cardpileNodes.push(cfgnode);
cfgnode.style.display='none';
cfgnode.classList.add('cardpilecfg');
page.appendChild(cfgnode);
}
}
2015-10-30 15:32:48 +00:00
return node;
};
for(var i=0;i<lib.config.all.cards.length;i++){
createModeConfig(lib.config.all.cards[i],start.firstChild);
}
2015-11-09 03:15:16 +00:00
for(var i in lib.cardPack){
if(i.indexOf('mode_')==0){
createModeConfig(i,start.firstChild);
}
}
2015-10-30 15:32:48 +00:00
var active=start.firstChild.querySelector('.active');
if(!active){
active=start.firstChild.firstChild;
active.classList.add('active');
}
rightPane.appendChild(active.link);
var node1=ui.create.div('.lefttext','全部开启',start.firstChild,function(){
game.saveConfig('cards',lib.config.all.cards);
updateNodes();
});
var node2=ui.create.div('.lefttext','恢复默认',start.firstChild,function(){
game.saveConfig('cards',lib.config.defaultcards);
updateNodes();
});
node1.style.marginTop='12px';
node2.style.marginTop='7px';
updateNodes();
}());
(function(){
var start=menux.pages[4];
var rightPane=start.lastChild;
var cheatButton=ui.create.div('.menubutton.round.highlight','作',start);
var runButton=ui.create.div('.menubutton.round.highlight','执',start);
2015-11-01 07:54:42 +00:00
runButton.style.display='none';
2015-11-04 01:59:00 +00:00
var playButton=ui.create.div('.menubutton.round.highlight','播',start);
playButton.style.display='none';
playButton.style.left='215px';
var deleteButton=ui.create.div('.menubutton.round.highlight','删',start);
deleteButton.style.display='none';
deleteButton.style.left='275px';
var saveButton=ui.create.div('.menubutton.round.highlight','存',start);
saveButton.style.display='none';
2015-10-30 15:32:48 +00:00
var clickMode=function(){
if(this.classList.contains('off')) return;
var active=this.parentNode.querySelector('.active');
if(active===this){
return;
}
active.classList.remove('active');
active.link.remove();
active=this;
this.classList.add('active');
rightPane.appendChild(this.link);
if(this.type=='cheat'){
cheatButton.style.display='';
}
else{
cheatButton.style.display='none';
}
if(this.type=='cmd'){
runButton.style.display='';
}
else{
runButton.style.display='none';
}
2015-11-04 01:59:00 +00:00
if(this.type=='video'){
playButton.style.display='';
saveButton.style.display='';
deleteButton.style.display='';
}
else{
playButton.style.display='none';
saveButton.style.display='none';
deleteButton.style.display='none';
}
2015-10-30 15:32:48 +00:00
};
(function(){
var checkCheat=function(){
if(currentrow1&&currentrow2&&row3.querySelector('.glow')){
cheatButton.classList.add('glowing');
return true;
}
else{
cheatButton.classList.remove('glowing');
return false;
}
}
cheatButton.listen(function(){
if(checkCheat()){
var num;
switch(currentrow2.innerHTML){
case '一':num=1;break;
case '二':num=2;break;
case '三':num=3;break;
case '四':num=4;break;
case '五':num=5;break;
}
var targets=[];
var buttons=row3.querySelectorAll('.glow');
for(var i=0;i<buttons.length;i++){
targets.push(buttons[i].link);
}
while(targets.length){
var target=targets.shift();
switch(currentrow1.innerHTML){
case '伤害':target.damage(num,'nosource');break;
case '回复':target.recover(num,'nosource');break;
case '摸牌':target.draw(num);break;
case '弃牌':
var hs=target.get('he');
if(hs.length){
target.discard(hs.randomGets(num));
}
break;
}
}
clickContainer.call(menuContainer);
}
});
var page=ui.create.div('');
var node=ui.create.div('.menubutton.large','作弊',start.firstChild,clickMode);
node.link=page;
node.type='cheat';
page.classList.add('menu-sym');
var currentrow1=null;
var row1=ui.create.div('.menu-cheat',page);
var clickrow1=function(){
if(currentrow1==this){
this.classList.remove('selecting');
currentrow1=null;
}
else{
this.classList.add('selecting');
if(currentrow1){
currentrow1.classList.remove('selecting');
}
currentrow1=this;
}
checkCheat();
};
var nodedamage=ui.create.div('.menubutton','伤害',row1,clickrow1);
var noderecover=ui.create.div('.menubutton','回复',row1,clickrow1);
var nodedraw=ui.create.div('.menubutton','摸牌',row1,clickrow1);
var nodediscard=ui.create.div('.menubutton','弃牌',row1,clickrow1);
var currentrow2=null;
var row2=ui.create.div('.menu-cheat',page);
var clickrow2=function(){
if(currentrow2==this){
this.classList.remove('selecting');
currentrow2=null;
}
else{
this.classList.add('selecting');
if(currentrow2){
currentrow2.classList.remove('selecting');
}
currentrow2=this;
}
checkCheat();
};
var nodex1=ui.create.div('.menubutton','一',row2,clickrow2);
var nodex2=ui.create.div('.menubutton','二',row2,clickrow2);
var nodex3=ui.create.div('.menubutton','三',row2,clickrow2);
var nodex4=ui.create.div('.menubutton','四',row2,clickrow2);
var nodex5=ui.create.div('.menubutton','五',row2,clickrow2);
var row3=ui.create.div('.menu-buttons',page);
row3.style.marginTop='3px';
var clickrow3=function(){
this.classList.toggle('glow');
checkCheat();
};
menuUpdates.push(function(){
2015-11-05 02:34:35 +00:00
if(_status.video){
node.classList.add('off');
node.classList.remove('active');
node.remove();
page.remove();
cheatButton.style.display='none';
return;
}
2015-10-30 15:32:48 +00:00
var list=[];
for(var i=0;i<game.players.length;i++){
if(lib.character[game.players[i].name]&&game.players[i].isAlive()){
list.push(game.players[i]);
}
else if(game.players[i]==game.me&&game.me.name1){
list.push(game.me);
}
}
if(list.length){
row1.show();
row2.show();
row3.innerHTML='';
var buttons=ui.create.buttons(list,'player',row3,true);
for(var i=0;i<buttons.length;i++){
buttons[i].listen(clickrow3);
}
}
else{
row1.hide();
row2.hide();
}
checkCheat();
});
}());
(function(){
var page=ui.create.div('');
var node=ui.create.div('.menubutton.large','换人',start.firstChild,clickMode);
node.link=page;
page.classList.add('menu-sym');
var caption=ui.create.div('','选择一个换人目标',page);
caption.style.margin='5px';
caption.style.marginTop='6px';
var row3=ui.create.div('.menu-buttons',page);
row3.style.marginTop='3px';
var currentrow3=null;
var clickrow3=function(){
game.swapPlayer(this.link);
};
menuUpdates.push(function(){
2015-12-06 15:23:47 +00:00
if(lib.config.mode!='identity'&&lib.config.mode!='guozhan'){
node.classList.add('off');
var active=start.firstChild.querySelector('.active');
if(active==node){
node.classList.remove('active');
node.link.remove();
active=start.firstChild.firstChild;
active.classList.add('active');
rightPane.appendChild(active.link);
cheatButton.style.display='';
}
}
2015-10-30 15:32:48 +00:00
var list=[];
for(var i=0;i<game.players.length;i++){
if(lib.character[game.players[i].name]&&
game.players[i].isAlive()&&game.players[i]!=game.me){
list.push(game.players[i]);
}
}
2015-11-05 02:34:35 +00:00
if(_status.video){
node.remove();
}
if(!_status.video&&list.length&&game.phaseNumber&&!_status.event.isMine()){
2015-10-30 15:32:48 +00:00
node.classList.remove('off');
row3.innerHTML='';
var buttons=ui.create.buttons(list,'player',row3,true);
for(var i=0;i<buttons.length;i++){
buttons[i].listen(clickrow3);
}
}
else{
node.classList.add('off');
var active=start.firstChild.querySelector('.active');
if(active==node){
node.classList.remove('active');
node.link.remove();
active=start.firstChild.firstChild;
active.classList.add('active');
rightPane.appendChild(active.link);
cheatButton.style.display='';
}
}
});
}());
(function(){
var page=ui.create.div('');
var node=ui.create.div('.menubutton.large','命令',start.firstChild,clickMode);
node.type='cmd';
node.link=page;
page.classList.add('menu-sym');
var caption=ui.create.div('','输入要执行的命令',page);
caption.style.margin='6px';
var text=document.createElement('textarea');
text.style.width='200px';
text.style.height='80px';
text.style.resize='none';
page.appendChild(text);
2015-10-31 03:20:59 +00:00
var textstr='';
var perserveMenu=false;
2015-11-11 03:14:32 +00:00
game.print=function(){
for(var i=0;i<arguments.length;i++){
2015-11-26 08:15:28 +00:00
if(arguments[i]!==undefined){
2015-11-11 03:14:32 +00:00
textstr+=arguments[i]+' '
}
}
textstr+='\n';
2015-10-31 03:20:59 +00:00
text.value=textstr;
2015-12-12 08:37:15 +00:00
// perserveMenu=true;
2015-10-31 03:20:59 +00:00
}
2015-10-30 15:32:48 +00:00
runButton.listen(function(){
2015-10-31 03:20:59 +00:00
textstr='';
2015-12-12 08:37:15 +00:00
// perserveMenu=false;
2015-10-30 15:32:48 +00:00
try{
2015-12-12 08:37:15 +00:00
eval('text.value='+text.value);
2015-10-30 15:32:48 +00:00
}
2015-11-12 01:12:03 +00:00
catch(e){
text.value=e;
2015-12-12 08:37:15 +00:00
// perserveMenu=true;
2015-10-31 03:20:59 +00:00
}
2015-12-12 08:37:15 +00:00
// if(!perserveMenu){
// text.value='';
// clickContainer.call(menuContainer);
// }
2015-10-30 15:32:48 +00:00
});
}());
2015-11-04 01:59:00 +00:00
(function(){
if(!window.indexedDB) return;
var page=ui.create.div('');
var node=ui.create.div('.menubutton.large','录像',start.firstChild,clickMode);
node.type='video';
node.link=page;
lib.onDB(function(){
var store=lib.db.transaction(['video'],'readwrite').objectStore('video');
lib.videos=[];
store.openCursor().onsuccess=function(e){
var cursor=e.target.result;
if(cursor){
lib.videos.push(cursor.value);
cursor.continue();
}
else{
lib.videos.sort(function(a,b){
return parseInt(b.time)-parseInt(a.time);
});
var clickcapt=function(){
var current=this.parentNode.querySelector('.videonode.active');
if(current&&current!=this){
current.classList.remove('active');
}
this.classList.toggle('active');
};
2015-11-28 03:45:23 +00:00
var staritem=function(){
this.parentNode.classList.toggle('starred');
var store=lib.db.transaction(['video'],'readwrite').objectStore('video');
if(this.parentNode.classList.contains('starred')){
this.parentNode.link.starred=true;
}
else{
this.parentNode.link.starred=false;
}
store.put(this.parentNode.link);
}
2015-11-04 01:59:00 +00:00
var createNode=function(video,before){
var node=ui.create.div('.videonode.menubutton.large',clickcapt);
node.link=video;
ui.create.div('.menubutton.videoavatar',node).setBackground(video.name1,'character');
if(video.name2){
ui.create.div('.menubutton.videoavatar2',node).setBackground(video.name2,'character');
}
var date=new Date(video.time);
var str=date.getFullYear()+'.'+(date.getMonth()+2)+'.'+(date.getDay()+1)+' '+
date.getHours()+':';
var minutes=date.getMinutes();
if(minutes<10){
str+='0';
}
str+=minutes;
ui.create.div('.caption',video.name[0],node);
ui.create.div('.text',str+'<br>'+video.name[1],node);
if(video.win){
ui.create.div('.victory','胜',node);
}
if(before){
page.insertBefore(node,page.firstChild);
}
else{
page.appendChild(node);
}
2015-11-28 03:45:23 +00:00
ui.create.div('.video_star','★',node,staritem);
if(video.starred){
node.classList.add('starred');
}
2015-11-04 01:59:00 +00:00
}
for(var i=0;i<lib.videos.length;i++){
createNode(lib.videos[i]);
}
2015-11-06 10:05:08 +00:00
lib.createVideoNode=createNode;
2015-11-04 01:59:00 +00:00
var importVideoNode=ui.create.div('.config.switcher',
'<span class="underlinenode slim">导入录像...</span>',function(){
this.nextSibling.classList.toggle('hidden');
},page);
importVideoNode.style.marginLeft='12px';
importVideoNode.style.marginTop='3px';
var importVideo=ui.create.div('.config.hidden',page);
importVideo.style.whiteSpace='nowrap';
importVideo.style.marginBottom='80px';
importVideo.style.marginLeft='13px';
importVideo.style.width='calc(100% - 30px)';
importVideo.innerHTML='<input type="file" style="width:calc(100% - 40px)">'+
'<button style="width:40px">确定</button>';
importVideo.lastChild.onclick=function(){
var fileToLoad = importVideo.firstChild.files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var data = fileLoadedEvent.target.result;
if(!data) return;
try{
data=JSON.parse(lib.init.decode(data));
}
catch(e){
2015-12-06 15:23:47 +00:00
console.log(e);
2015-11-04 01:59:00 +00:00
alert('导入失败');
return;
}
var store=lib.db.transaction(['video'],'readwrite').objectStore('video');
2015-11-28 03:45:23 +00:00
var videos=lib.videos.slice(0);
for(var i=0;i<videos.length;i++){
if(videos[i].starred){
videos.splice(i--,1);
}
}
for(var deletei=0;deletei<5;deletei++){
if(videos.length>=parseInt(lib.config.video)&&videos.length){
var toremove=videos.pop();
lib.videos.remove(toremove);
store.delete(toremove.time);
for(var i=0;i<page.childNodes.length;i++){
if(page.childNodes[i].link==toremove){
page.childNodes[i].remove();
break;
}
2015-11-04 01:59:00 +00:00
}
}
2015-11-28 03:45:23 +00:00
else{
break;
}
2015-11-04 01:59:00 +00:00
}
for(var i=0;i<lib.videos.length;i++){
if(lib.videos[i].time==data.time){
alert('录像已存在');
return;
}
}
lib.videos.unshift(data);
store.put(data);
createNode(data,true);
};
fileReader.readAsText(fileToLoad, "UTF-8");
}
playButton.listen(function(){
var current=this.parentNode.querySelector('.videonode.active');
if(current){
game.playVideo(current.link.time,current.link.mode);
}
});
deleteButton.listen(function(){
var current=this.parentNode.querySelector('.videonode.active');
if(current){
lib.videos.remove(current.link);
var store=lib.db.transaction(['video'],'readwrite').objectStore('video');
store.delete(current.link.time);
current.remove();
}
});
saveButton.listen(function(){
var current=this.parentNode.querySelector('.videonode.active');
if(current){
2015-11-05 02:34:35 +00:00
game.export(lib.init.encode(JSON.stringify(current.link)),
'无名杀 - 录像 - '+current.link.name[0]+' - '+current.link.name[1]);
2015-11-04 01:59:00 +00:00
}
});
2015-11-05 02:34:35 +00:00
ui.updateVideoMenu=function(){
node.classList.add('active');
rightPane.appendChild(page);
playButton.style.display='';
deleteButton.style.display='';
saveButton.style.display='';
}
2015-11-04 01:59:00 +00:00
}
};
});
}());
2015-10-30 15:32:48 +00:00
var active=start.firstChild.querySelector('.active');
if(!active){
active=start.firstChild.firstChild;
active.classList.add('active');
}
rightPane.appendChild(active.link);
}());
2015-11-04 01:59:00 +00:00
2015-10-30 15:32:48 +00:00
(function(){
var start=menux.pages[5];
var rightPane=start.lastChild;
var clickMode=function(){
if(this.classList.contains('off')) return;
var active=this.parentNode.querySelector('.active');
if(active===this){
return;
}
active.classList.remove('active');
active.link.remove();
active=this;
this.classList.add('active');
rightPane.appendChild(this.link);
};
for(var i in lib.help){
var page=ui.create.div('');
var node=ui.create.div('.menubutton.large',i,start.firstChild,clickMode);
node.link=page;
page.classList.add('menu-help');
page.innerHTML=lib.help[i];
}
var active=start.firstChild.querySelector('.active');
if(!active){
active=start.firstChild.firstChild;
active.classList.add('active');
}
rightPane.appendChild(active.link);
}());
2015-10-29 17:36:14 +00:00
}());
2015-10-31 10:14:14 +00:00
// ui.systemButton=ui.create.div('.menubutton.round.highlight#systembutton','设',ui.arena,function(){
//
// });
2015-11-04 01:59:00 +00:00
lib.status.date=new Date();
lib.status.dateDelayed=0;
2015-11-09 09:05:28 +00:00
while(lib.arenaReady.length){
2015-11-13 01:43:16 +00:00
(lib.init.eval(lib.arenaReady.shift()))();
2015-11-09 09:05:28 +00:00
}
delete lib.arenaReady;
2015-10-30 09:13:19 +00:00
clearTimeout(window.resetGameTimeout);
delete window.resetGameTimeout;
2015-04-29 03:25:17 +00:00
},
system:function(str,func,right){
var node=ui.create.div(right?ui.system2:ui.system1);
node.innerHTML=str;
if(func){
node.addEventListener(lib.config.touchscreen?'touchend':'click',function(e){
if(_status.dragged) return;
func.call(this,e);
});
}
2015-11-14 15:48:04 +00:00
if(lib.config.button_press){
node.addEventListener(lib.config.touchscreen?'touchstart':'mousedown',function(e){
2015-11-25 10:25:18 +00:00
if(!node.classList.contains('hidden')) node.classList.add('pressdown');
2015-11-14 15:48:04 +00:00
});
node.addEventListener(lib.config.touchscreen?'touchend':'mouseup',function(e){
node.classList.remove('pressdown');
});
node.addEventListener(lib.config.touchscreen?'touchmove':'mousemove',function(e){
node.classList.remove('pressdown');
});
}
2015-04-29 03:25:17 +00:00
return node;
},
pause:function(){
2015-04-29 03:44:48 +00:00
if(_status.pausing) return;
2015-04-29 03:25:17 +00:00
var node=ui.create.div("#paused",ui.window);
2015-04-29 03:44:48 +00:00
_status.pausing=true;
setTimeout(function(){
_status.pausing=false;
},500);
2015-04-29 03:25:17 +00:00
if(lib.config.touchscreen){
setTimeout(function(){
node.addEventListener('touchend',ui.click.resume);
},500);
}
else{
node.addEventListener('click',ui.click.resume);
}
2015-11-14 09:02:14 +00:00
if(!lib.config.touchscreen){
node.oncontextmenu=ui.click.resume;
}
2015-04-29 03:25:17 +00:00
var node2=ui.create.div('#paused2',node);
node2.innerHTML='已暂停';
2015-10-28 03:47:35 +00:00
2015-10-10 14:38:33 +00:00
// node2.listen(function(){
// _status.clicked=true;
// if(ui.sidebar.classList.contains('hidden')){
// ui.sidebar.show();
// ui.sidebar3.show();
// }
// else{
// ui.sidebar.hide();
// ui.sidebar3.hide();
// }
// });
2015-04-29 03:25:17 +00:00
return node;
},
button:function(item,type,position,noclick){
var node;
switch(type){
case 'blank':
node=ui.create.div('.button.card',position);
node.link=item;
break;
case 'card':
2015-11-24 15:44:21 +00:00
if(typeof item.copy=='function'){
node=item.copy();
}
else{
node=item.cloneNode(true);
}
2015-04-29 03:25:17 +00:00
node.classList.add('button');
position.appendChild(node);
node.link=item;
if(item.style.backgroundImage){
node.style.backgroundImage=item.style.backgroundImage;
node.style.backgroundSize='cover';
}
if(item.style.color){
node.style.color=item.style.color;
}
if(item.nature){
node.classList.add(item.nature);
}
break;
case 'vcard':
2015-05-02 09:54:39 +00:00
node=ui.create.card(position,'noclick',noclick).init(item);
2015-04-29 03:25:17 +00:00
node.classList.add('button');
node.link=item;
break;
case 'character':case 'player':
node=ui.create.div('.button.character',position);
node.link=item;
if(type=='character'){
node.setBackground(item,'character');
node.node={
name:ui.create.div('.name',node),
hp:ui.create.div('.hp',node),
intro:ui.create.div('.intro',node),
group:ui.create.div('.identity',node)
}
2015-10-30 15:32:48 +00:00
var infoitem=lib.character[item];
if(!infoitem){
for(var itemx in lib.characterPack){
if(lib.characterPack[itemx][item]){
infoitem=lib.characterPack[itemx][item];break;
}
}
}
if(infoitem[2]>14){
node.node.hp.innerHTML=infoitem[2];
2015-05-13 10:26:54 +00:00
node.node.hp.classList.add('text');
}
else{
2015-10-30 15:32:48 +00:00
for(var i =0;i<infoitem[2];i++){
2015-05-13 10:26:54 +00:00
ui.create.div('',node.node.hp);
}
2015-04-29 03:25:17 +00:00
}
2015-11-25 12:34:54 +00:00
if(!lib.config.show_name){
2015-04-29 03:25:17 +00:00
node.node.name.style.display='none';
2015-11-25 12:34:54 +00:00
}
2015-12-08 00:56:54 +00:00
// var name=get.translation(item);
node.node.name.innerHTML=get.slimName(item);
// for(var i=0;i<name.length;i++){
// node.node.name.innerHTML+=name[i]+'<br/>';
// }
2015-04-29 03:25:17 +00:00
node.node.intro.innerHTML=lib.config.intro;
2015-05-02 09:54:39 +00:00
if(!noclick){
if(lib.config.touchscreen){
lib.setLongPress(node,ui.click.intro);
}
2015-11-13 09:12:47 +00:00
else{
if(lib.config.hover_all){
lib.setHover(node,ui.click.hoverplayer);
}
if(lib.config.right_info){
node.oncontextmenu=ui.click.rightplayer;
}
2015-05-02 09:54:39 +00:00
}
2015-04-29 03:25:17 +00:00
}
2015-11-09 03:15:16 +00:00
if(infoitem[1]){
node.node.group.innerHTML='<div>'+get.translation(infoitem[1])+'</div>';
node.node.group.style.backgroundColor=get.translation(infoitem[1]+'Color');
}
else{
node.node.group.style.display='none';
}
2015-04-29 03:25:17 +00:00
}
else{
2015-11-12 01:12:03 +00:00
node.node={
name:ui.create.div('.name',node),
intro:ui.create.div('.intro',node)
}
2015-04-29 03:25:17 +00:00
if(item.name.indexOf('unknown')==0){
node.setBackground(item.name1,'character');
}
else{
node.setBackground(item.name,'character');
}
}
break;
case 'text':
node=ui.create.div('.button.text',position);
node.innerHTML=lib.get.translate(item);
break;
}
if(!noclick){
node.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.button);
}
else{
node.classList.add('noclick');
if(node.querySelector('.intro')){
node.querySelector('.intro').remove();
}
}
for(var i in lib.element.button){
node[i]=lib.element.button[i];
}
return node;
},
buttons:function(list,type,position,noclick,zoom){
var buttons=[];
for(var i=0;i<list.length;i++){
buttons.push(ui.create.button(list[i],type,position,noclick));
}
return buttons;
},
player:function(position){
var node=ui.create.div('.player',position);
node.node={
2015-11-23 10:59:44 +00:00
avatar:ui.create.div('.avatar',node,ui.click.avatar).hide(),
avatar2:ui.create.div('.avatar2',node,ui.click.avatar2).hide(),
2015-04-29 03:25:17 +00:00
intro:ui.create.div('.intro',node),
identity:ui.create.div('.identity',node),
hp:ui.create.div('.hp',node),
name:ui.create.div('.name',node),
2015-11-30 13:08:29 +00:00
name2:ui.create.div('.name.name2',node),
2015-04-29 03:25:17 +00:00
count:ui.create.div('.count',node).hide(),
2015-11-05 02:34:35 +00:00
equips:ui.create.div('.equips',node).hide(),
2015-04-29 03:25:17 +00:00
judges:ui.create.div('.judges',node),
marks:ui.create.div('.marks',node),
2015-11-24 15:44:21 +00:00
handcards1:ui.create.div('.handcards'),
handcards2:ui.create.div('.handcards'),
2015-04-29 03:25:17 +00:00
};
2015-11-06 10:05:08 +00:00
node.node.action=ui.create.div('.action',node.node.avatar);
2015-04-29 03:25:17 +00:00
node.skipList=[];
node.skills=[];
node.initedSkills=[];
node.additionalSkills={};
node.disabledSkills={};
node.hiddenSkills=[];
node.forbiddenSkills=[];
node.modeSkills=[];
node.popups=[];
2015-09-26 13:11:55 +00:00
node.damagepopups=[];
2015-12-12 08:37:15 +00:00
node.judging=[];
2015-04-29 03:25:17 +00:00
node.stat=[{card:{},skill:{}}];
node.tempSkills={};
node.storage={};
node.marks={};
node.ai={friend:[],enemy:[],neutral:[]};
node.queueCount=0;
for(var i in lib.element.player){
node[i]=lib.element.player[i];
}
ui.create.div(node.node.identity);
node.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.target);
node.node.identity.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.identity);
2015-12-03 16:28:06 +00:00
if(lib.config.touchscreen){
node.addEventListener('touchstart',ui.click.playertouchstart);
}
2015-04-29 03:25:17 +00:00
return node;
},
players:function(num){
2015-05-08 08:07:38 +00:00
if(num===0){
return;
}
2015-04-29 03:25:17 +00:00
if(num==undefined) num=lib.config.mode_config[lib.config.mode].player_number;
2015-10-29 17:36:14 +00:00
if(typeof num=='string'){
num=parseInt(num);
}
if(!num) num=5;
2015-04-29 03:25:17 +00:00
for(var i=0;i<num;i++){
var player=ui.create.player(ui.arena).animate('start');
game.players.push(player);
player.dataset.position=i;
}
var players=game.players;
for(var i=0;i<players.length;i++){
if(i>0){
players[i].previous=players[i-1];
players[i].previousSeat=players[i-1];
}
if(i<players.length-1){
players[i].next=players[i+1];
players[i].nextSeat=players[i+1];
}
}
players[0].previous=players[players.length-1];
players[0].previousSeat=players[players.length-1];
players[players.length-1].next=players[0];
players[players.length-1].nextSeat=players[0];
ui.arena.dataset.number=num;
2015-11-04 01:59:00 +00:00
return players;
2015-04-29 03:25:17 +00:00
},
me:function(){
ui.mebg=ui.create.div('#mebg',ui.arena);
ui.me=ui.create.div('#me',ui.arena).animate('start');
2015-11-24 15:44:21 +00:00
ui.handcards1Container=ui.create.div('#handcards1',ui.me);
ui.handcards2Container=ui.create.div('#handcards2',ui.me);
2015-11-25 15:42:29 +00:00
if(lib.config.mousewheel&&!lib.config.touchscreen){
ui.handcards1Container.onmousewheel=ui.click.mousewheel;
ui.handcards2Container.onmousewheel=ui.click.mousewheel;
}
ui.handcards1Container.ontouchstart = ui.click.touchStart;
ui.handcards2Container.ontouchstart = ui.click.touchStart;
ui.handcards1Container.ontouchmove = ui.click.touchScroll;
ui.handcards2Container.ontouchmove = ui.click.touchScroll;
ui.handcards1Container.style.WebkitOverflowScrolling='touch';
ui.handcards2Container.style.WebkitOverflowScrolling='touch';
2015-05-08 08:07:38 +00:00
if(game.players.length){
game.me=game.players[0];
ui.handcards1=game.me.node.handcards1;
ui.handcards2=game.me.node.handcards2;
2015-11-24 15:44:21 +00:00
ui.handcards1Container.appendChild(ui.handcards1);
ui.handcards2Container.appendChild(ui.handcards2);
2015-12-02 15:34:34 +00:00
ui.updatehl();
2015-05-08 08:07:38 +00:00
}
2015-04-29 03:25:17 +00:00
},
2015-05-02 09:54:39 +00:00
card:function(position,info,noclick){
2015-04-29 03:25:17 +00:00
var node=ui.create.div('.card',position);
node.node={
image:ui.create.div('.image',node),
info:ui.create.div('.info',node),
name:ui.create.div('.name',node),
name2:ui.create.div('.name2',node),
background:ui.create.div('.background',node),
intro:ui.create.div('.intro',node),
2015-11-30 13:08:29 +00:00
range:ui.create.div('.range',node),
2015-04-29 03:25:17 +00:00
}
for(var i in lib.element.card){
node[i]=lib.element.card[i];
}
node.node.intro.innerHTML=lib.config.intro;
2015-05-02 09:54:39 +00:00
if(!noclick){
if(lib.config.touchscreen){
lib.setLongPress(node,ui.click.intro);
}
2015-11-13 09:12:47 +00:00
else{
if(lib.config.hover_all){
lib.setHover(node,ui.click.hoverplayer);
}
if(lib.config.right_info){
node.oncontextmenu=ui.click.rightplayer;
}
2015-05-02 09:54:39 +00:00
}
2015-04-29 03:25:17 +00:00
}
node.storage={};
if(info!='noclick'){
node.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.card);
2015-12-03 16:28:06 +00:00
if(lib.config.touchscreen){
node.addEventListener('touchstart',ui.click.cardtouchstart);
node.addEventListener('touchmove',ui.click.cardtouchmove);
}
if(lib.cardSelectObserver){
lib.cardSelectObserver.observe(node,{attributes:true});
}
2015-04-29 03:25:17 +00:00
}
return node;
},
cards:function(random){
if(!random){
2015-05-03 15:17:15 +00:00
lib.card.list.randomSort();
2015-04-29 03:25:17 +00:00
}
for(var i=0;i<lib.card.list.length;i++){
if(lib.card[lib.card.list[i][2]]){
2015-10-30 15:32:48 +00:00
if(lib.config.bannedcards.contains(lib.card.list[i][2])) continue;
2015-04-29 03:25:17 +00:00
ui.create.card(ui.cardPile).init(lib.card.list[i]);
}
}
},
},
click:{
2015-12-12 08:37:15 +00:00
dragtouchdialog:function(e){
if(e.touches.length>1&&
!this.classList.contains('popped')&&
!this.classList.contains('fixed')){
_status.draggingtouchdialog=this;
this._dragorigin={
clientX:e.touches[0].clientX,
clientY:e.touches[0].clientY,
};
if(!this._dragtransform){
this._dragtransform=[0,0];
}
this._dragorigintransform=this._dragtransform.slice(0);
e.preventDefault();
e.stopPropagation();
}
},
2015-11-30 13:08:29 +00:00
identity:function(){
if(_status.dragged) return;
_status.clicked=true;
if(!game.getIdentityList) return;
if(_status.clickingidentity){
for(var i=0;i<_status.clickingidentity[1].length;i++){
_status.clickingidentity[1][i].delete();
_status.clickingidentity[1][i].style.transform='';
}
if(_status.clickingidentity[0]==this.parentNode){
delete _status.clickingidentity;
return;
}
}
var list=game.getIdentityList(this.parentNode);
if(!list) return;
var nodes=[];
_status.clickingidentity=[this.parentNode,nodes];
var num=1;
for(var i in list){
if(this.firstChild.innerHTML!=list[i]){
var node=ui.create.div('.identity.hidden',this.parentNode,ui.click.identity2);
ui.create.div(node).innerHTML=list[i];
node.dataset.color=i;
ui.refresh(node);
node.show();
2015-11-30 17:37:10 +00:00
if(lib.config.layout=='phone'){
node.style.transform='scale(1.3) translateY('+((num++)*30)+'px)';
}
else{
node.style.transform='translateY('+((num++)*30)+'px)';
}
2015-11-30 13:08:29 +00:00
nodes.push(node);
}
}
},
identity2:function(){
if(_status.clickingidentity){
_status.clicked=true;
var player=_status.clickingidentity[0];
var nodes=_status.clickingidentity[1];
player.node.identity.dataset.color=this.dataset.color;
player.node.identity.firstChild.innerHTML=this.firstChild.innerHTML;
for(var i=0;i<nodes.length;i++){
nodes[i].delete();
nodes[i].style.transform='';
}
delete _status.clickingidentity;
}
},
2015-10-31 16:18:20 +00:00
system:function(){
if(lib.config.layout!='phone') return;
_status.clicked=true;
2015-11-09 17:04:18 +00:00
this.classList.add('shown');
if(this._tempclicking){
ui.arena.classList.add('phonetop');
2015-10-31 16:18:20 +00:00
}
2015-11-09 17:04:18 +00:00
else{
this._tempclicking=true;
var that=this;
setTimeout(function(){
that._tempclicking=false;
},300);
}
if(this.nextSibling) this.nextSibling.classList.remove('shown');
if(this.previousSibling) this.previousSibling.classList.remove('shown');
2015-10-31 16:18:20 +00:00
},
2015-11-29 11:46:51 +00:00
roundmenu:function(){
switch(lib.config.round_menu_func){
case 'system':
if((_status.removinground&&lib.config.touchscreen)||
ui.system2.classList.contains('shown')){
2015-12-07 11:15:35 +00:00
_status.removinground=false;
game.pause2();
ui.click.configMenu();
2015-11-29 11:46:51 +00:00
ui.system1.classList.remove('shown');
ui.system2.classList.remove('shown');
}
else{
ui.system1.classList.add('shown');
ui.system2.classList.add('shown');
}
break;
case 'menu':
game.pause2();
ui.click.configMenu();
ui.system1.classList.remove('shown');
ui.system2.classList.remove('shown');
break;
case 'pause':
ui.click.pause();
break;
case 'auto':
ui.click.auto();
if(!ui.system1.classList.contains('shown')){
ui.system1.classList.add('shown');
}
break;
}
_status.clicked=true;
},
2015-04-30 08:24:57 +00:00
pausehistory:function(){
2015-11-05 02:34:35 +00:00
if(!lib.config.auto_popped_history) return;
2015-04-30 08:24:57 +00:00
if(!ui.sidebar.childNodes.length) return;
var uiintro=ui.create.dialog('hidden');
uiintro.style.maxHeight='400px';
2015-04-30 08:24:57 +00:00
uiintro.add(ui.sidebar);
return uiintro;
},
2015-10-28 03:47:35 +00:00
wuxieconfig:function(){
if(!lib.config.auto_popped) return;
2015-10-29 17:36:14 +00:00
// if(!ui.config.childNodes.length) return;
2015-10-28 03:47:35 +00:00
var uiintro=ui.create.dialog('hidden');
2015-10-29 17:36:14 +00:00
var node=ui.create.switcher('wuxie_self',lib.config.wuxie_self,ui.click.sidebar.global);
2015-10-28 03:47:35 +00:00
uiintro.add(node);
return uiintro;
},
2015-04-30 08:24:57 +00:00
pauseconfig:function(){
2015-11-05 02:34:35 +00:00
if(!lib.config.auto_popped_config) return;
2015-10-29 17:36:14 +00:00
// if(!ui.config.childNodes.length) return;
2015-04-30 08:24:57 +00:00
var uiintro=ui.create.dialog('hidden');
2015-11-09 17:04:18 +00:00
uiintro.listen(function(e){
e.stopPropagation();
});
2015-05-08 08:07:38 +00:00
var rows=Math.ceil(lib.config.all.mode.length/3);
2015-10-29 17:36:14 +00:00
uiintro.type='config';
2015-05-08 08:07:38 +00:00
for(var k=0;k<rows;k++){
var node=ui.create.div('.newgame');
for(var i=0;i<3&&i+k*3<lib.config.all.mode.length;i++){
var thismode=lib.config.all.mode[i+k*3];
var div=ui.create.div(thismode==lib.config.mode?'.underlinenode.on':'.underlinenode',node);
div.innerHTML=lib.translate[thismode];
div.link=thismode;
div.addEventListener(lib.config.touchscreen?'touchend':'click',function(){
game.saveConfig('mode',this.link);
2015-12-06 15:23:47 +00:00
localStorage.setItem(lib.configprefix+'directstart',true);
2015-05-08 08:07:38 +00:00
game.reload();
});
}
uiintro.add(node);
}
2015-11-05 02:34:35 +00:00
if(_status.video) return uiintro;
2015-05-01 07:35:43 +00:00
var auto=null;
2015-05-08 08:07:38 +00:00
var ng=null;
2015-05-01 07:35:43 +00:00
var sks=[];
var autoskill=ui.autoskill;
if(game.players){
for(var i=0;i<game.players.length;i++){
if(game.players[i]==game.me||game.players[i].isUnderControl()){
sks=sks.concat(game.expandSkills(game.players[i].get('s')));
}
}
}
2015-10-30 09:13:19 +00:00
for(var i=0;i<sks.length;i++){
if(autoskill[sks[i]]){
2015-05-01 07:35:43 +00:00
if(!auto){
2015-05-08 08:07:38 +00:00
ng=ui.create.div('.text');
ng.style.marginBottom=0;
ng.innerHTML='新游戏';
uiintro.content.insertBefore(ng,uiintro.content.firstChild);
2015-05-01 07:35:43 +00:00
auto=ui.create.div('.text');
auto.style.marginBottom=0;
auto.innerHTML='自动发动';
uiintro.add(auto);
}
2015-10-30 09:13:19 +00:00
autoskill[sks[i]].style.display='';
uiintro.add(autoskill[sks[i]]);
2015-05-01 07:35:43 +00:00
}
}
2015-04-30 08:24:57 +00:00
return uiintro;
},
2015-11-28 03:45:23 +00:00
cardPileButton:function(){
var uiintro=ui.create.dialog('hidden');
uiintro.listen(function(e){
e.stopPropagation();
});
uiintro.add('剩余 <span style="font-family:'+'xinwei'+'">'+ui.cardPile.childNodes.length);
uiintro.add('<div class="text center">弃牌堆</div>');
if(ui.discardPile.childNodes.length){
var list=[];
for(var i=0;i<ui.discardPile.childNodes.length;i++){
list.push(ui.discardPile.childNodes[i]);
}
uiintro.addSmall([list,'card']);
}
else{
uiintro.add('<div class="text center" style="padding-bottom:3px">无</div>');
}
return uiintro;
},
2015-04-30 03:09:07 +00:00
volumn:function(){
var uiintro=ui.create.dialog('hidden');
2015-11-09 17:04:18 +00:00
uiintro.listen(function(e){
e.stopPropagation();
});
2015-04-30 03:09:07 +00:00
uiintro.add('背景音乐');
var vol1=ui.create.div('.volumn');
uiintro.add(vol1);
for(var i=0;i<8;i++){
var span=document.createElement('span');
span.link=i+1;
span.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.volumn_background);
if(i<lib.config.volumn_background){
span.innerHTML='●';
}
else{
span.innerHTML='○';
}
vol1.appendChild(span);
}
uiintro.add('游戏音效');
var vol2=ui.create.div('.volumn');
uiintro.add(vol2);
for(var i=0;i<8;i++){
var span=document.createElement('span');
span.link=i+1;
span.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.volumn_audio);
if(i<lib.config.volumn_audio){
span.innerHTML='●';
}
else{
span.innerHTML='○';
}
vol2.appendChild(span);
}
uiintro.add(ui.create.div('.placeholder'));
return uiintro;
},
volumn_background:function(e){
if(_status.dragged) return;
2015-05-16 14:27:14 +00:00
var volume=this.link;
if(volume===1&&lib.config.volumn_background===1){
volume=0;
}
game.saveConfig('volumn_background',volume);
ui.backgroundMusic.volume=volume/8;
2015-04-30 03:09:07 +00:00
for(var i=0;i<8;i++){
if(i<lib.config.volumn_background){
this.parentNode.childNodes[i].innerHTML='●';
}
else{
this.parentNode.childNodes[i].innerHTML='○';
}
}
e.stopPropagation();
},
volumn_audio:function(e){
if(_status.dragged) return;
2015-05-16 14:27:14 +00:00
var volume=this.link;
if(volume===1&&lib.config.volumn_audio===1){
volume=0;
}
game.saveConfig('volumn_audio',volume);
2015-04-30 03:09:07 +00:00
for(var i=0;i<8;i++){
if(i<lib.config.volumn_audio){
this.parentNode.childNodes[i].innerHTML='●';
}
else{
this.parentNode.childNodes[i].innerHTML='○';
}
}
e.stopPropagation();
},
hoverpopped:function(){
if(this._uiintro){
return;
}
if(!this._poppedfunc){
return;
}
2015-11-21 05:30:26 +00:00
// if(this._poppedalready){
// return;
// }
2015-11-09 17:04:18 +00:00
if(lib.config.touchscreen){
_status.touchpopping=true;
setTimeout(function(){
_status.touchpopping=false;
},500);
}
2015-04-30 08:24:57 +00:00
var uiintro=this._poppedfunc();
if(!uiintro) return;
2015-04-30 03:09:07 +00:00
if(ui.currentpopped&&ui.currentpopped._uiintro){
ui.currentpopped._uiintro.delete();
delete ui.currentpopped._uiintro;
}
2015-11-21 05:30:26 +00:00
// this._poppedalready=true;
2015-04-30 03:09:07 +00:00
ui.currentpopped=this;
uiintro.classList.add('popped');
uiintro.classList.add('static');
this._uiintro=uiintro;
ui.window.appendChild(uiintro);
var width=this._poppedwidth||330;
uiintro.style.width=width+'px';
var height=this._poppedheight||uiintro.content.scrollHeight;
uiintro.style.height=Math.min(ui.window.offsetHeight-260,height)+'px';
2015-11-28 07:19:04 +00:00
if(lib.config.layout=='phone'){
uiintro.style.top='70px';
}
else{
uiintro.style.top='50px';
}
2015-04-30 03:09:07 +00:00
var left=this.parentNode.offsetLeft+this.offsetLeft+this.offsetWidth/2-width/2;
if(left<10){
left=10;
}
else if(left+width>ui.window.offsetWidth-10){
left=ui.window.offsetWidth-width-10;
}
uiintro.style.left=left+'px';
uiintro._poppedorigin=this;
2015-11-13 09:12:47 +00:00
if(!lib.config.touchscreen){
uiintro.addEventListener('mouseleave',ui.click.leavehoverpopped);
}
2015-04-30 03:09:07 +00:00
},
2015-11-21 05:30:26 +00:00
hoverpopped_leave:function(){
this._poppedalready=false;
},
2015-04-30 03:09:07 +00:00
leavehoverpopped:function(){
if(_status.dragged) return;
this.delete();
2015-10-29 17:36:14 +00:00
var button=this._poppedorigin;
var uiintro=this;
2015-04-30 03:09:07 +00:00
setTimeout(function(){
2015-10-29 17:36:14 +00:00
if(button._uiintro==uiintro){
delete button._uiintro;
}
2015-04-30 03:09:07 +00:00
},500);
2015-10-29 17:36:14 +00:00
2015-04-30 03:09:07 +00:00
},
2015-04-29 03:25:17 +00:00
dierevive:function(){
if(game.me.isDead()){
2015-10-29 17:36:14 +00:00
game.me.revive(Math.max(1,game.me.maxHp));
2015-04-29 03:25:17 +00:00
game.me.draw(2);
}
else{
if(ui.revive){
ui.revive.close();
delete ui.revive;
}
}
},
dieswap:function(){
if(game.me.isDead()){
_status.clicked=true;
var i,translation,intro,str;
if(ui.intro){
ui.intro.close();
if(ui.intro.source=='dieswap'){
delete ui.intro;
ui.control.show();
game.resume2();
return;
}
}
game.pause2();
ui.control.hide();
ui.intro=ui.create.dialog();
ui.intro.source='dieswap';
var players=[];
for(var i=0;i<game.players.length;i++){
if(game.players[i].isAlive()){
players.push(game.players[i]);
}
}
ui.intro.add(players,true);
var buttons=ui.intro.querySelectorAll('.button');
for(var i=0;i<buttons.length;i++){
buttons[i].addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.dieswap2);
}
}
else{
if(ui.swap){
ui.swap.close();
delete ui.swap;
}
}
},
dieswap2:function(){
if(_status.dragged) return;
game.swapPlayer(this.link);
},
2015-11-26 08:15:28 +00:00
windowtouchstart:function(e){
2015-12-06 15:23:47 +00:00
if(window.inSplash) return;
2015-12-12 08:37:15 +00:00
if(e.touches[0]&&lib.config.swipe&&e.touches.length<2){
2015-11-29 11:46:51 +00:00
_status._swipeorigin={
clientX:e.touches[0].clientX,
clientY:e.touches[0].clientY,
time:get.currentTime()
2015-11-26 08:15:28 +00:00
}
}
},
windowtouchmove:function(e){
2015-11-29 11:46:51 +00:00
e.preventDefault();
2015-12-06 15:23:47 +00:00
if(window.inSplash) return;
2015-11-29 11:46:51 +00:00
if(_status.draggingroundmenu){
delete _status._swipeorigin;
if(ui.roundmenu._dragorigin&&ui.roundmenu._dragtransform&&e.touches.length){
var translate=ui.roundmenu._dragtransform.slice(0);
var dx=e.touches[0].clientX-ui.roundmenu._dragorigin.clientX;
var dy=e.touches[0].clientY-ui.roundmenu._dragorigin.clientY;
translate[0]+=dx;
translate[1]+=dy;
if(dx*dx+dy*dy>100){
if(ui.roundmenu._resetTimeout){
clearTimeout(ui.roundmenu._resetTimeout);
delete ui.roundmenu._resetTimeout;
}
}
ui.roundmenu._dragtouches=e.touches[0];
ui.click.checkroundtranslate(translate);
2015-11-26 08:15:28 +00:00
}
2015-11-29 11:46:51 +00:00
_status.clicked=true;
}
2015-12-12 08:37:15 +00:00
else if(_status.draggingtouchdialog){
delete _status._swipeorigin;
if(_status.draggingtouchdialog._dragorigin&&_status.draggingtouchdialog._dragtransform&&e.touches.length){
var translate=_status.draggingtouchdialog._dragtransform.slice(0);
var dx=e.touches[0].clientX-_status.draggingtouchdialog._dragorigin.clientX;
var dy=e.touches[0].clientY-_status.draggingtouchdialog._dragorigin.clientY;
translate[0]+=dx;
translate[1]+=dy;
_status.draggingtouchdialog._dragtouches=e.touches[0];
_status.draggingtouchdialog.style.transform='translate('+translate[0]+'px,'+translate[1]+'px)';
}
_status.clicked=true;
}
2015-11-29 11:46:51 +00:00
else if(_status._swipeorigin&&e.touches[0]){
_status._swipeorigin.touches=e.touches[0];
2015-11-26 08:15:28 +00:00
}
2015-12-03 16:28:06 +00:00
if(_status.mousedragging&&e.touches.length){
e.preventDefault();
var item=document.elementFromPoint(e.touches[0].clientX,e.touches[0].clientY);
while(item){
if(lib.config.enable_touchdragline&&_status.mouseleft&&lib.config.mode!='chess'){
ui.canvas.width=ui.arena.offsetWidth;
ui.canvas.height=ui.arena.offsetHeight;
var ctx=ui.ctx;
ctx.shadowBlur=5;
ctx.shadowColor='rgba(0,0,0,0.3)';
ctx.strokeStyle='white';
ctx.lineWidth=3;
ctx.setLineDash([8,2]);
ctx.beginPath();
ctx.moveTo(_status.mousedragging.clientX-ui.arena.offsetLeft,_status.mousedragging.clientY-ui.arena.offsetTop);
if(_status.multitarget){
for(var i=0;i<_status.lastdragchange.length;i++){
var exy=_status.lastdragchange[i]._lastdragchange;
ctx.lineTo(exy[0],exy[1]);
}
}
if(!_status.selectionfull){
ctx.lineTo(e.touches[0].clientX-ui.arena.offsetLeft,e.touches[0].clientY-ui.arena.offsetTop);
}
ctx.stroke();
if(!_status.multitarget){
for(var i=0;i<_status.lastdragchange.length;i++){
ctx.moveTo(_status.mousedragging.clientX-ui.arena.offsetLeft,_status.mousedragging.clientY-ui.arena.offsetTop);
var exy=_status.lastdragchange[i]._lastdragchange;
ctx.lineTo(exy[0],exy[1]);
ctx.stroke();
}
}
}
if(item==_status.mousedragorigin){
if(_status.mouseleft){
_status.mousedragging=null;
_status.mousedragorigin=null;
_status.clicked=false;
game.uncheck();
game.check();
ui.canvas.width=ui.arena.offsetWidth;
ui.canvas.height=ui.arena.offsetHeight;
_status.clicked=true;
}
return;
}
var itemtype=get.itemtype(item);
if(itemtype=='card'||itemtype=='button'||itemtype=='player'){
_status.mouseleft=true;
var ex=e.touches[0].clientX-ui.arena.offsetLeft;
var ey=e.touches[0].clientY-ui.arena.offsetTop;
var exx=ex,eyy=ey;
if(lib.config.mode=='chess'){
ex-=-ui.chessContainer.scrollLeft+ui.chess.offsetLeft;
ey-=-ui.chessContainer.scrollTop+ui.chess.offsetTop;
}
if(itemtype!='player'||(ex>item.offsetLeft&&ex<item.offsetLeft+item.offsetWidth&&
ey>item.offsetTop&&ey<item.offsetTop+item.offsetHeight)){
var targetfixed=false;
if(itemtype=='player'){
if(get.select(_status.event.selectTarget)[1]==-1){
targetfixed=true;
}
}
if(!targetfixed&&item.classList.contains('selectable')&&_status.dragstatuschanged!=item){
_status.mouseleft=true;
_status.dragstatuschanged=item;
_status.clicked=false;
_status.dragged=false;
var notbefore=itemtype=='player'&&!item.classList.contains('selected');
ui.click[itemtype].call(item);
if(item.classList.contains('selected')){
if(notbefore){
_status.lastdragchange.push(item);
item._lastdragchange=[exx,eyy];
if(false){
var from=[_status.mousedragging.clientX-ui.arena.offsetLeft,_status.mousedragging.clientY-ui.arena.offsetTop];
var to=[exx,eyy];
var node=ui.create.div('.linexy.hidden');
node.style.left=from[0]+'px';
node.style.top=from[1]+'px';
node.style.transitionDuration='0.3s';
node.style.backgroundColor='white';
var dy=to[1]-from[1];
var dx=to[0]-from[0];
var deg=Math.atan(Math.abs(dy)/Math.abs(dx))/Math.PI*180;
if(dx>=0){
if(dy<=0){
deg+=90;
}
else{
deg=90-deg;
}
}
else{
if(dy<=0){
deg=270-deg;
}
else{
deg+=270;
}
}
node.style.transform='rotate('+(-deg)+'deg) scaleY(0)';
node.style.height=get.xyDistance(from,to)+'px';
if(lib.config.mode=='chess'){
ui.chess.appendChild(node);
}
else{
ui.arena.appendChild(node);
}
ui.refresh(node);
node.show();
node.style.transform='rotate('+(-deg)+'deg) scaleY(1)';
ui.touchlines.push(node);
node._origin=item;
}
}
}
else{
_status.lastdragchange.remove(item);
for(var i=0;i<ui.touchlines.length;i++){
if(ui.touchlines[i]._origin==item){
ui.touchlines[i].delete();
ui.touchlines.splice(i--,1);
}
}
}
_status.selectionfull=true;
if(_status.event.filterButton&&ui.selected.buttons.length<get.select(_status.event.selectButton)[1]){
_status.selectionfull=false;
}
else if(_status.event.filterCard&&ui.selected.cards.length<get.select(_status.event.selectCard)[1]){
_status.selectionfull=false;
}
else if(_status.event.filterTarget&&ui.selected.targets.length<get.select(_status.event.selectTarget)[1]){
_status.selectionfull=false;
}
}
}
return;
}
item=item.parentNode;
}
_status.mouseleft=true;
_status.dragstatuschanged=null;
}
2015-11-26 08:15:28 +00:00
},
windowtouchend:function(e){
2015-12-06 15:23:47 +00:00
if(window.inSplash) return;
2015-12-12 08:37:15 +00:00
if(e.touches.length==1&&!_status.dragged&&!_status.draggingtouchdialog){
2015-11-26 08:15:28 +00:00
ui.click.pause();
}
2015-11-29 11:46:51 +00:00
if(_status.draggingroundmenu){
delete _status._swipeorigin;
if(ui.roundmenu._resetTimeout){
clearTimeout(ui.roundmenu._resetTimeout);
delete ui.roundmenu._resetTimeout;
}
if(ui.roundmenu._dragorigin&&ui.roundmenu._dragtransform&&ui.roundmenu._dragtouches){
var dx=ui.roundmenu._dragtouches.clientX-ui.roundmenu._dragorigin.clientX;
var dy=ui.roundmenu._dragtouches.clientY-ui.roundmenu._dragorigin.clientY;
if(dx*dx+dy*dy<1000){
ui.click.roundmenu();
ui.roundmenu._dragtransform=ui.roundmenu._dragorigintransform;
var translate=ui.roundmenu._dragtransform;
ui.roundmenu.style.transform='translate('+translate[0]+'px,'+translate[1]+'px)';
2015-11-26 08:15:28 +00:00
}
else{
2015-11-29 11:46:51 +00:00
var translate=ui.roundmenu._dragtransform;
translate[0]+=dx;
translate[1]+=dy;
ui.click.checkroundtranslate();
2015-11-26 08:15:28 +00:00
}
2015-11-29 11:46:51 +00:00
delete ui.roundmenu._dragorigin;
2015-11-26 08:15:28 +00:00
}
2015-11-29 11:46:51 +00:00
else{
ui.click.roundmenu();
2015-11-26 08:15:28 +00:00
}
2015-11-29 11:46:51 +00:00
_status.clicked=false;
game.saveConfig('roundmenu_transform',translate);
delete _status.draggingroundmenu;
}
2015-12-12 08:37:15 +00:00
else if(_status.draggingtouchdialog){
delete _status._swipeorigin;
if(_status.draggingtouchdialog._dragorigin&&_status.draggingtouchdialog._dragtransform&&_status.draggingtouchdialog._dragtouches){
var dx=_status.draggingtouchdialog._dragtouches.clientX-_status.draggingtouchdialog._dragorigin.clientX;
var dy=_status.draggingtouchdialog._dragtouches.clientY-_status.draggingtouchdialog._dragorigin.clientY;
var translate=_status.draggingtouchdialog._dragtransform;
translate[0]+=dx;
translate[1]+=dy;
_status.draggingtouchdialog.style.transform='translate('+translate[0]+'px,'+translate[1]+'px)';
delete _status.draggingtouchdialog._dragorigin;
}
_status.clicked=false;
delete _status.draggingtouchdialog;
_status.justdragged=true;
setTimeout(function(){
_status.justdragged=false;
},500);
}
2015-12-03 16:28:06 +00:00
else if(_status._swipeorigin&&!_status.paused2&&!_status.mousedragging){
2015-11-29 11:46:51 +00:00
if(get.currentTime()-_status._swipeorigin.time<500){
2015-11-30 13:08:29 +00:00
var dx=_status._swipeorigin.touches.clientX-_status._swipeorigin.clientX;
var dy=_status._swipeorigin.touches.clientY-_status._swipeorigin.clientY;
2015-12-07 11:15:35 +00:00
var goswipe=function(action){
switch(action){
case 'system':
if(ui.system2.classList.contains('shown')||
lib.config.layout!='phone'){
game.pause2();
ui.click.configMenu();
ui.system1.classList.remove('shown');
ui.system2.classList.remove('shown');
}
else{
ui.system1.classList.add('shown');
ui.system2.classList.add('shown');
}
break;
case 'menu':
game.pause2();
ui.click.configMenu();
ui.system1.classList.remove('shown');
ui.system2.classList.remove('shown');
break;
case 'pause':
ui.click.pause();
break;
case 'auto':
ui.click.auto();
if(!ui.system1.classList.contains('shown')){
ui.system1.classList.add('shown');
}
break;
}
}
2015-11-30 13:08:29 +00:00
if(Math.abs(dx)<100){
if(dy<-200){
2015-12-07 11:15:35 +00:00
goswipe(lib.config.swipe_up);
2015-11-29 11:46:51 +00:00
}
else if(dy>200){
2015-12-07 11:15:35 +00:00
goswipe(lib.config.swipe_down);
2015-11-29 11:46:51 +00:00
}
}
2015-12-07 11:15:35 +00:00
else if(Math.abs(dy)<100){
if(dx<-200){
goswipe(lib.config.swipe_left);
}
else if(dx>200){
goswipe(lib.config.swipe_right);
}
}
2015-11-29 11:46:51 +00:00
}
}
2015-12-03 16:28:06 +00:00
var tmpflag=false;
_status.mousedown=false;
_status.clicked=false;
if(_status.mousedragging&&_status.mouseleft){
if(game.check()){
if(ui.confirm){
ui.confirm.close();
}
ui.click.ok();
}
else{
game.uncheck();
game.check();
}
}
else if(_status.mousedragging&&_status.mousedragorigin){
tmpflag=_status.mousedragorigin;
}
_status.lastdragchange.length=0;
_status.mousedragging=null;
_status.mouseleft=false;
_status.mousedragorigin=null;
_status.dragstatuschanged=false;
while(ui.touchlines.length){
ui.touchlines.shift().delete();
}
ui.canvas.width=ui.arena.offsetWidth;
ui.canvas.height=ui.arena.offsetHeight;
if(tmpflag){
game.check();
}
_status.dragged=false;
_status.clicked=false;
2015-11-29 11:46:51 +00:00
},
checkroundtranslate:function(translate){
var translate=translate||ui.roundmenu._dragtransform;
if(translate[1]+ui.roundmenu._position[1]+50+ui.arena.offsetTop>ui.window.offsetHeight){
translate[1]=ui.window.offsetHeight-(ui.roundmenu._position[1]+50)-ui.arena.offsetTop;
}
else if(translate[1]+ui.roundmenu._position[1]+ui.arena.offsetTop<0){
translate[1]=-ui.roundmenu._position[1]-ui.arena.offsetTop;
}
if(translate[0]+ui.roundmenu._position[0]+50+ui.arena.offsetLeft>ui.window.offsetWidth){
translate[0]=ui.window.offsetWidth-(ui.roundmenu._position[0]+50)-ui.arena.offsetLeft;
}
else if(translate[0]+ui.roundmenu._position[0]+ui.arena.offsetLeft<0){
translate[0]=-ui.roundmenu._position[0]-ui.arena.offsetLeft;
2015-11-26 08:15:28 +00:00
}
2015-11-29 11:46:51 +00:00
ui.roundmenu.style.transform='translate('+translate[0]+'px,'+translate[1]+'px)';
2015-11-26 08:15:28 +00:00
},
2015-10-29 17:36:14 +00:00
windowmousewheel:function(e){
_status.tempunpopup=e;
},
2015-04-29 03:25:17 +00:00
windowmousemove:function(e){
2015-12-06 15:23:47 +00:00
if(window.inSplash) return;
2015-10-29 17:36:14 +00:00
if(_status.tempunpopup){
if(get.evtDistance(_status.tempunpopup,e)>5){
delete _status.tempunpopup;
}
}
2015-04-29 03:25:17 +00:00
if(e.button==2) return;
if(!Array.isArray(e.path)) return;
var dialogs=document.querySelectorAll('#window>.dialog.popped:not(.static)');
for(var i=0;i<dialogs.length;i++){
dialogs[i].delete();
}
var node=_status.currentmouseenter;
if(_status.mousedragging){
2015-05-08 08:07:38 +00:00
e.preventDefault();
2015-12-03 16:28:06 +00:00
if(lib.config.enable_dragline){
ui.canvas.width=ui.arena.offsetWidth;
ui.canvas.height=ui.arena.offsetHeight;
var ctx=ui.ctx;
ctx.shadowBlur=5;
ctx.shadowColor='rgba(0,0,0,0.3)';
ctx.strokeStyle='white';
ctx.lineWidth=3;
ctx.setLineDash([8,2]);
2015-04-29 03:25:17 +00:00
2015-12-03 16:28:06 +00:00
ctx.beginPath();
2015-04-29 03:25:17 +00:00
2015-12-03 16:28:06 +00:00
ctx.moveTo(_status.mousedragging.x-ui.arena.offsetLeft,_status.mousedragging.y-ui.arena.offsetTop);
if(_status.multitarget){
for(var i=0;i<_status.lastdragchange.length;i++){
var exy=_status.lastdragchange[i]._lastdragchange;
ctx.lineTo(exy[0],exy[1]);
}
2015-04-29 03:25:17 +00:00
}
2015-12-03 16:28:06 +00:00
if(!_status.selectionfull){
ctx.lineTo(e.x-ui.arena.offsetLeft,e.y-ui.arena.offsetTop);
}
ctx.stroke();
if(!_status.multitarget){
for(var i=0;i<_status.lastdragchange.length;i++){
ctx.moveTo(_status.mousedragging.x-ui.arena.offsetLeft,_status.mousedragging.y-ui.arena.offsetTop);
var exy=_status.lastdragchange[i]._lastdragchange;
ctx.lineTo(exy[0],exy[1]);
ctx.stroke();
}
2015-04-29 03:25:17 +00:00
}
}
for(var i=0;i<e.path.length;i++){
if(e.path[i]==_status.mousedragorigin){
if(_status.mouseleft){
_status.mousedragging=null;
_status.mousedragorigin=null;
_status.clicked=false;
game.uncheck();
game.check();
ui.canvas.width=ui.arena.offsetWidth;
ui.canvas.height=ui.arena.offsetHeight;
_status.clicked=true;
}
return;
}
var itemtype=get.itemtype(e.path[i]);
if(itemtype=='card'||itemtype=='button'||itemtype=='player'){
_status.mouseleft=true;
var item=e.path[i];
var ex=e.x-ui.arena.offsetLeft;
var ey=e.y-ui.arena.offsetTop;
2015-05-08 08:07:38 +00:00
var exx=ex,eyy=ey;
if(lib.config.mode=='chess'){
ex-=-ui.chessContainer.scrollLeft+ui.chess.offsetLeft;
ey-=-ui.chessContainer.scrollTop+ui.chess.offsetTop;
}
2015-04-29 03:25:17 +00:00
if(itemtype!='player'||(ex>item.offsetLeft&&ex<item.offsetLeft+item.offsetWidth&&
ey>item.offsetTop&&ey<item.offsetTop+item.offsetHeight)){
2015-07-09 05:21:22 +00:00
var targetfixed=false;
if(itemtype=='player'){
if(get.select(_status.event.selectTarget)[1]==-1){
targetfixed=true;
}
}
if(!targetfixed&&item.classList.contains('selectable')&&_status.dragstatuschanged!=item){
2015-04-29 03:25:17 +00:00
_status.mouseleft=true;
_status.dragstatuschanged=item;
_status.clicked=false;
var notbefore=itemtype=='player'&&!item.classList.contains('selected');
ui.click[itemtype].call(item);
if(item.classList.contains('selected')){
if(notbefore){
_status.lastdragchange.push(item);
2015-05-08 08:07:38 +00:00
e.path[i]._lastdragchange=[exx,eyy];
2015-04-29 03:25:17 +00:00
}
}
else{
_status.lastdragchange.remove(item);
}
_status.selectionfull=true;
if(_status.event.filterButton&&ui.selected.buttons.length<get.select(_status.event.selectButton)[1]){
_status.selectionfull=false;
}
else if(_status.event.filterCard&&ui.selected.cards.length<get.select(_status.event.selectCard)[1]){
_status.selectionfull=false;
}
else if(_status.event.filterTarget&&ui.selected.targets.length<get.select(_status.event.selectTarget)[1]){
_status.selectionfull=false;
}
}
}
return;
}
}
_status.mouseleft=true;
_status.dragstatuschanged=null;
}
else{
if(e.path.contains(node)&&!node._mouseentercreated){
ui.click.mouseentercancel();
var hoveration;
if(typeof node._hoveration=='number'){
hoveration=node._hoveration;
}
else{
2015-10-30 09:13:19 +00:00
hoveration=parseInt(lib.config.hoveration);
2015-04-29 03:25:17 +00:00
if(node.classList.contains('button')||
(node.parentNode&&node.parentNode.parentNode)==ui.me){
hoveration+=500;
}
}
_status._mouseentertimeout=setTimeout(function(){
2015-10-29 17:36:14 +00:00
if(_status.currentmouseenter!=node||node._mouseentercreated||_status.tempunpopup||
2015-04-29 03:25:17 +00:00
_status.mousedragging||_status.mousedown||!node.offsetWidth||!node.offsetHeight){
return;
}
2015-10-20 17:44:00 +00:00
if(node._hoverfunc&&!node._nopup){
2015-04-29 03:25:17 +00:00
var dialog=node._hoverfunc.call(node,e);
dialog.classList.add('popped');
ui.window.appendChild(dialog);
lib.placePoppedDialog(dialog,e);
if(node._hoverwidth){
dialog.style.width=node._hoverwidth+'px';
dialog._hovercustomed=true;
}
node._mouseenterdialog=dialog;
node._mouseentercreated=true;
}
},hoveration);
}
2015-05-08 08:07:38 +00:00
if(_status.draggingdialog){
var ddialog=_status.draggingdialog;
if(ddialog._dragorigin&&ddialog._dragtransform){
var translate=ddialog._dragtransform.slice(0);
translate[0]+=e.x-ddialog._dragorigin.x;
translate[1]+=e.y-ddialog._dragorigin.y;
2015-11-05 02:34:35 +00:00
ddialog.style.transform='translate('+translate[0]+'px,'+translate[1]+'px)'
2015-05-08 08:07:38 +00:00
}
2015-06-14 05:07:39 +00:00
_status.clicked=true;
2015-05-08 08:07:38 +00:00
}
2015-11-29 11:46:51 +00:00
if(_status.draggingroundmenu){
if(ui.roundmenu._dragorigin&&ui.roundmenu._dragtransform){
var translate=ui.roundmenu._dragtransform.slice(0);
translate[0]+=e.x-ui.roundmenu._dragorigin.x;
translate[1]+=e.y-ui.roundmenu._dragorigin.y;
ui.click.checkroundtranslate(translate);
}
_status.clicked=true;
}
2015-04-29 03:25:17 +00:00
}
},
windowmousedown:function(e){
2015-12-06 15:23:47 +00:00
if(window.inSplash) return;
2015-04-29 03:25:17 +00:00
if(e.button==2) return;
_status.mousedown=true;
var dialogs=ui.window.querySelectorAll('#window>.dialog.popped:not(.static)');
for(var i=0;i<dialogs.length;i++){
dialogs[i].delete();
}
2015-09-03 03:49:14 +00:00
if(e.path){
for(var i=0;i<e.path.length;i++){
var itemtype=get.itemtype(e.path[i]);
if(itemtype=='button') break;
2015-10-20 17:44:00 +00:00
if(itemtype=='dialog'&&
!e.path[i].classList.contains('popped')&&
!e.path[i].classList.contains('fixed')){
2015-09-03 03:49:14 +00:00
var ddialog=e.path[i];
_status.draggingdialog=ddialog;
ddialog._dragorigin=e;
if(!ddialog._dragtransform){
ddialog._dragtransform=[0,0];
}
return;
2015-05-08 08:07:38 +00:00
}
2015-11-29 11:46:51 +00:00
if(e.path[i]==ui.roundmenu){
_status.draggingroundmenu=true;
ui.roundmenu._dragorigin=e;
if(!ui.roundmenu._dragtransform){
ui.roundmenu._dragtransform=[0,0];
}
}
2015-05-08 08:07:38 +00:00
}
}
2015-04-29 03:25:17 +00:00
var evt=_status.event;
if(!lib.config.enable_drag) return;
if(!ui.arena.classList.contains('selecting')) return;
if(!evt.isMine()) return;
if(!Array.isArray(e.path)) return;
for(var i=0;i<e.path.length;i++){
var itemtype=get.itemtype(e.path[i]);
if(itemtype=='card'||itemtype=='button'||itemtype=='player'){
if(e.path[i].classList.contains('selectable')&&
!e.path[i].classList.contains('selected')&&
!e.path[i].classList.contains('noclick')){
_status.clicked=false;
ui.click[itemtype].call(e.path[i]);
if(e.path[i].classList.contains('selected')){
_status.mousedragging=e;
_status.mousedragorigin=e.path[i];
_status.mouseleft=false;
_status.selectionfull=false;
_status.multitarget=false;
2015-10-20 17:44:00 +00:00
// if(ui.confirm&&ui.confirm.str=='c') ui.confirm.close();
}
2015-04-29 03:25:17 +00:00
}
return;
}
}
},
2015-12-03 16:28:06 +00:00
cardtouchstart:function(e){
if(e.touches.length!=1) return;
if(!lib.config.enable_drag) return;
if(!this.parentNode) return;
if(!this.parentNode.parentNode) return;
if(this.parentNode.parentNode.parentNode!=ui.me) return;
if(this.parentNode.parentNode.classList.contains('scrollh')) return;
if(this.classList.contains('selectable')&&
!this.classList.contains('selected')&&
!this.classList.contains('noclick')){
this._waitingfordrag={clientX:e.touches[0].clientX,clientY:e.touches[0].clientY};
}
},
cardtouchmove:function(e){
if(this._longpresstimeout){
clearTimeout(this._longpresstimeout);
delete this._longpresstimeout;
}
if(this._waitingfordrag){
var drag=this._waitingfordrag;
_status.clicked=false;
_status.touchnocheck=true;
ui.click.card.call(this);
_status.touchnocheck=false;
if(this.classList.contains('selected')){
_status.mousedragging=drag;
_status.mousedragorigin=this;
_status.mouseleft=false;
_status.selectionfull=false;
_status.multitarget=false;
}
delete this._waitingfordrag;
}
},
2015-04-29 03:25:17 +00:00
windowmouseup:function(e){
2015-12-06 15:23:47 +00:00
if(window.inSplash) return;
2015-05-08 08:07:38 +00:00
if(_status.draggingdialog){
var ddialog=_status.draggingdialog;
if(ddialog._dragorigin&&ddialog._dragtransform){
var translate=ddialog._dragtransform;
translate[0]+=e.x-ddialog._dragorigin.x;
translate[1]+=e.y-ddialog._dragorigin.y;
2015-11-05 02:34:35 +00:00
ddialog.style.transform='translate('+translate[0]+'px,'+translate[1]+'px)';
2015-05-08 08:07:38 +00:00
delete ddialog._dragorigin;
}
delete _status.draggingdialog;
}
2015-11-29 11:46:51 +00:00
if(_status.draggingroundmenu){
if(ui.roundmenu._dragorigin&&ui.roundmenu._dragtransform){
var dx=e.x-ui.roundmenu._dragorigin.x;
var dy=e.y-ui.roundmenu._dragorigin.y;
if(dx*dx+dy*dy<25){
ui.click.roundmenu();
}
var translate=ui.roundmenu._dragtransform;
translate[0]+=dx;
translate[1]+=dy;
ui.click.checkroundtranslate();
delete ui.roundmenu._dragorigin;
}
game.saveConfig('roundmenu_transform',translate);
delete _status.draggingroundmenu;
}
2015-04-29 03:25:17 +00:00
if(e.button==2){
if(_status.mousedragging){
_status.mousedragging=null;
_status.mouseleft=false;
_status.mousedragorigin=null;
_status.dragstatuschanged=false;
ui.canvas.width=ui.arena.offsetWidth;
ui.canvas.height=ui.arena.offsetHeight;
game.uncheck();
game.check();
_status.noright=true;
}
}
else{
var tmpflag=false;
_status.mousedown=false;
if(_status.mousedragging&&_status.mouseleft){
if(game.check()){
if(ui.confirm){
ui.confirm.close();
}
ui.click.ok();
}
else{
game.uncheck();
game.check();
}
}
else if(_status.mousedragging&&_status.mousedragorigin){
tmpflag=_status.mousedragorigin;
}
_status.lastdragchange.length=0;
_status.mousedragging=null;
_status.mouseleft=false;
_status.mousedragorigin=null;
_status.dragstatuschanged=false;
ui.canvas.width=ui.arena.offsetWidth;
ui.canvas.height=ui.arena.offsetHeight;
if(tmpflag){
ui.click[get.itemtype(tmpflag)].call(tmpflag);
game.check();
}
2015-12-03 16:28:06 +00:00
// ui.updatehl();
2015-04-29 03:25:17 +00:00
}
},
mousemove:function(){
if(!lib.config.hover_handcard&&this.parentNode&&this.parentNode.parentNode==ui.me){
return;
}
if(!_status.currentmouseenter){
_status.currentmouseenter=this;
}
},
mouseenter:function(){
if(!lib.config.hover_handcard&&this.parentNode&&this.parentNode.parentNode==ui.me){
return;
}
_status.currentmouseenter=this;
},
mouseleave:function(){
ui.click.mouseentercancel();
if(_status.currentmouseenter==this){
_status.currentmouseenter=null;
}
this._mouseentercreated=false;
},
mousedown:function(){
ui.click.mouseentercancel();
if(_status.currentmouseenter==this){
_status.currentmouseenter=null;
}
this._mouseentercreated=true;
},
mouseentercancel:function(){
if(_status._mouseentertimeout){
clearTimeout(_status._mouseentertimeout);
delete _status._mouseentertimeout
}
},
hoverplayer:function(e){
2015-12-06 15:23:47 +00:00
var node=get.nodeintro(this,true);
node.style.zIndex=21;
return node;
2015-04-29 03:25:17 +00:00
},
longpressdown:function(e){
if(_status.longpressed) return;
if(this._longpresstimeout){
clearTimeout(this._longpresstimeout);
}
var func=this._longpresscallback;
var node=this;
this._longpresstimeout=setTimeout(function(){
delete node._longpresstimeout;
if(_status.mousedragging&&_status.mouseleft) return;
if(!_status.longpressed){
_status.longpressed=true;
setTimeout(function(){
_status.longpressed=false;
},500);
func.call(node,e);
2015-12-03 16:28:06 +00:00
if(lib.config.touchscreen&&lib.config.enable_drag&&!node._waitingfordrag){
_status.mousedragging=null;
_status.mousedragorigin=null;
_status.clicked=false;
game.uncheck();
game.check();
ui.canvas.width=ui.arena.offsetWidth;
ui.canvas.height=ui.arena.offsetHeight;
_status.clicked=true;
}
2015-04-29 03:25:17 +00:00
}
},500);
},
longpresscancel:function(){
if(this._longpresstimeout){
clearTimeout(this._longpresstimeout);
delete this._longpresstimeout;
}
},
window:function(){
2015-05-13 10:26:54 +00:00
var clicked=_status.clicked;
2015-04-29 03:25:17 +00:00
if(_status.dragged) return;
2015-11-09 17:04:18 +00:00
if(_status.touchpopping) return;
2015-05-05 14:57:35 +00:00
if(_status.reloading) return;
2015-04-29 03:25:17 +00:00
if(_status.clicked){
_status.clicked=false;
}
2015-05-01 07:35:43 +00:00
else{
2015-11-30 13:08:29 +00:00
if(ui.controls.length){
ui.updatec();
}
2015-05-01 07:35:43 +00:00
if(_status.editing){
if(_status.editing.innerHTML.length){
_status.editing.link=_status.editing.innerHTML;
}
_status.editing.innerHTML=get.translation(_status.editing.link);
delete _status.editing;
2015-04-29 03:25:17 +00:00
}
2015-05-02 06:59:31 +00:00
else if(_status.choosing){
if(!_status.choosing.expand){
_status.choosing.parentNode.style.height='';
_status.choosing.nextSibling.delete();
_status.choosing.previousSibling.show();
delete _status.choosing;
}
}
2015-05-01 07:35:43 +00:00
else if(ui.intro){
ui.intro.close();
delete ui.intro;
ui.control.show();
game.resume2();
2015-04-29 03:25:17 +00:00
}
2015-05-01 07:35:43 +00:00
else if(_status.event.isMine()){
if(_status.event.custom.replace.window){
_status.event.custom.replace.window();
2015-04-29 03:25:17 +00:00
}
else{
2015-05-01 07:35:43 +00:00
if(_status.event.skill&&_status.event.name=='chooseToUse'){
ui.click.cancel();
}
else{
game.uncheck();
game.check();
}
2015-04-29 03:25:17 +00:00
}
}
2015-11-12 01:12:03 +00:00
if(lib.config.layout=='phone'&&ui.menuContainer.classList.contains('hidden')){
2015-11-29 11:46:51 +00:00
if(ui.system2.classList.contains('shown')){
_status.removinground=true;
setTimeout(function(){
_status.removinground=false;
},200);
}
2015-11-09 17:04:18 +00:00
ui.arena.classList.remove('phonetop');
2015-10-31 16:18:20 +00:00
ui.system1.classList.remove('shown');
ui.system2.classList.remove('shown');
2015-11-12 01:12:03 +00:00
// if(ui.chessinfo){
// ui.chessinfo.classList.remove('zoomed');
// }
2015-10-31 16:18:20 +00:00
}
2015-04-29 03:25:17 +00:00
}
2015-05-01 07:35:43 +00:00
if(_status.tempunpop){
_status.tempunpop=false;
}
else{
2015-05-02 09:54:39 +00:00
if(ui.currentpopped){
if(ui.currentpopped._uiintro){
ui.currentpopped._uiintro.delete();
delete ui.currentpopped._uiintro;
}
2015-05-01 07:35:43 +00:00
delete ui.currentpopped;
}
2015-04-30 03:09:07 +00:00
}
2015-04-29 03:25:17 +00:00
if(_status.event.custom.add.window){
2015-05-13 10:26:54 +00:00
_status.event.custom.add.window(clicked);
2015-04-29 03:25:17 +00:00
}
},
toggle:function(){
if(_status.dragged) return;
if(this.parentNode.classList.contains('disabled')) return;
2015-05-01 07:35:43 +00:00
_status.tempunpop=true;
2015-04-29 03:25:17 +00:00
if(this.link){
this.link=false;
this.classList.remove('on');
if(this.additionalCommand) this.additionalCommand(false,this.parentNode);
}
else{
this.link=true;
this.classList.add('on');
if(this.additionalCommand) this.additionalCommand(true,this.parentNode);
}
},
editor:function(){
if(_status.dragged) return;
if(_status.editing) return;
_status.clicked=true;
this.innerHTML='';
_status.editing=this;
if(this.additionalCommand) this.additionalCommand(this);
},
switcher:function(){
if(_status.dragged) return;
2015-05-11 11:57:44 +00:00
if(this.parentNode.classList.contains('disabled')) return;
2015-04-29 03:25:17 +00:00
if(_status.choosing) return;
_status.clicked=true;
2015-05-01 07:35:43 +00:00
_status.tempunpop=true;
2015-04-29 03:25:17 +00:00
this.previousSibling.hide();
var node=ui.create.div('.switcher',this.parentNode).animate('start');
for(var i=0;i<this.choice.length;i++){
var choice=ui.create.div(node);
choice.innerHTML=get.translation(this.choice[i]);
choice.link=this.choice[i];
choice.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.choice);
}
this.parentNode.style.height=(node.offsetHeight)+'px';
_status.choosing=this;
2015-05-02 06:59:31 +00:00
if(!_status.choosing.expand){
_status.choosing.expand=true;
setTimeout(function(){
_status.choosing.expand=false;
},500);
}
2015-04-29 03:25:17 +00:00
},
choice:function(){
if(_status.dragged) return;
2015-04-29 07:54:48 +00:00
if(!_status.choosing) return;
2015-04-29 03:25:17 +00:00
_status.choosing.link=this.link;
_status.choosing.innerHTML=get.translation(this.link);
this.parentNode.parentNode.style.height='';
this.parentNode.delete();
_status.choosing.previousSibling.show();
delete _status.choosing;
if(this.parentNode.parentNode.querySelector('.toggle').additionalCommand){
this.parentNode.parentNode.querySelector('.toggle').additionalCommand(this.link,this.parentNode.parentNode);
}
},
button:function(){
if(_status.dragged) return;
if(_status.clicked) return;
2015-11-14 15:48:04 +00:00
if(_status.tempNoButton) return;
2015-12-12 08:37:15 +00:00
if(_status.draggingtouchdialog) return;
2015-05-13 10:26:54 +00:00
if(this.classList.contains('noclick')) return;
2015-12-12 08:37:15 +00:00
if(_status.justdragged) return;
2015-04-29 03:25:17 +00:00
_status.clicked=true;
var custom=_status.event.custom;
if(custom.replace.button){
custom.replace.button(this);
return;
}
if(this.classList.contains('selectable')==false) return;
if(this.classList.contains('selected')){
ui.selected.buttons.remove(this);
if(_status.multitarget){
game.uncheck();
game.check();
}
}
else{
ui.selected.buttons.add(this);
}
this.classList.toggle('selected');
if(custom.add.button){
custom.add.button();
}
game.check();
},
card:function(){
2015-12-03 16:28:06 +00:00
delete this._waitingfordrag;
2015-04-29 03:25:17 +00:00
if(_status.dragged) return;
if(_status.clicked) return;
if(ui.intro) return;
_status.clicked=true;
var custom=_status.event.custom;
if(custom.replace.card){
custom.replace.card(this);
return;
}
if(this.classList.contains('selectable')==false) return;
2015-12-03 16:28:06 +00:00
var notoggle=false;
2015-04-29 03:25:17 +00:00
if(this.classList.contains('selected')){
ui.selected.cards.remove(this);
if(_status.multitarget){
game.uncheck();
game.check();
2015-12-03 16:28:06 +00:00
notoggle=true;
2015-04-29 03:25:17 +00:00
}
}
else{
ui.selected.cards.add(this);
}
2015-12-03 16:28:06 +00:00
if(!notoggle){
this.classList.toggle('selected');
}
2015-05-08 13:37:34 +00:00
if(false){
if(lib.config.mode=='chess'&&!_status.event.skill&&this.classList.contains('selected')&&
_status.event.isMine()&&_status.event.name=='chooseToUse'){
var player=_status.event.player;
var range=get.info(this).range;
if(range){
if(typeof range.attack==='number'){
player.createRangeShadow(get.attackRange(player)+range.attack-1);
}
else if(typeof range.global==='number'){
player.createRangeShadow(get.globalFrom(player)+range.global);
}
}
}
}
2015-04-29 03:25:17 +00:00
if(custom.add.card){
custom.add.card();
}
game.check();
},
2015-11-23 10:59:44 +00:00
avatar:function(){
if(!lib.config.change_skin) return;
if(this.parentNode.classList.contains('unseen')) return;
var avatar=this;
var player=this.parentNode;
if(!this._doubleClicking){
this._doubleClicking=true;
setTimeout(function(){
avatar._doubleClicking=false;
},500);
return;
}
var num=1;
if(lib.config.skin[player.name]){
num=lib.config.skin[player.name]+1;
}
var img=new Image();
img.onload=function(){
lib.config.skin[player.name]=num;
game.saveConfig('skin',lib.config.skin);
avatar.style.backgroundImage='url("'+img.src+'")';
2015-11-30 17:37:10 +00:00
if(lib.config.animation&&!lib.config.low_performance){
player.$rare();
}
2015-11-23 10:59:44 +00:00
}
img.onerror=function(){
2015-11-30 17:37:10 +00:00
if(lib.config.skin[player.name]){
if(lib.config.animation&&!lib.config.low_performance){
player.$rare();
}
}
2015-11-23 10:59:44 +00:00
delete lib.config.skin[player.name];
game.saveConfig('skin',lib.config.skin);
2015-11-25 10:25:18 +00:00
avatar.setBackground(player.name,'character');
2015-11-23 10:59:44 +00:00
}
2015-11-25 10:25:18 +00:00
img.src='image/skin/'+player.name+'/'+num+'.jpg';
2015-11-23 10:59:44 +00:00
},
avatar2:function(){
if(!lib.config.change_skin) return;
if(this.parentNode.classList.contains('unseen2')) return;
var avatar=this;
var player=this.parentNode;
if(!this._doubleClicking){
this._doubleClicking=true;
setTimeout(function(){
avatar._doubleClicking=false;
},500);
return;
}
var num=1;
if(lib.config.skin[player.name2]){
num=lib.config.skin[player.name2]+1;
}
var img=new Image();
img.onload=function(){
lib.config.skin[player.name2]=num;
game.saveConfig('skin',lib.config.skin);
avatar.style.backgroundImage='url("'+img.src+'")';
2015-11-30 17:37:10 +00:00
if(lib.config.animation&&!lib.config.low_performance){
player.$rare();
}
2015-11-23 10:59:44 +00:00
}
img.onerror=function(){
2015-11-30 17:37:10 +00:00
if(lib.config.skin[player.name2]){
if(lib.config.animation&&!lib.config.low_performance){
player.$rare();
}
}
2015-11-23 10:59:44 +00:00
delete lib.config.skin[player.name2];
game.saveConfig('skin',lib.config.skin);
2015-11-25 10:25:18 +00:00
avatar.setBackground(player.name2,'character');
2015-11-23 10:59:44 +00:00
}
2015-11-25 10:25:18 +00:00
img.src='image/skin/'+player.name2+'/'+num+'.jpg';
2015-11-23 10:59:44 +00:00
},
2015-04-29 03:25:17 +00:00
player:function(){
return ui.click.target.apply(this,arguments);
},
2015-05-12 09:51:40 +00:00
target:function(e){
2015-04-29 03:25:17 +00:00
if(_status.dragged) return;
if(_status.clicked) return;
if(ui.intro) return;
_status.clicked=true;
var custom=_status.event.custom;
if(custom.replace.target){
2015-05-12 09:51:40 +00:00
custom.replace.target(this,e);
2015-04-29 03:25:17 +00:00
return;
}
if(this.classList.contains('selectable')==false) return;
this.unprompt();
if(this.classList.contains('selected')){
ui.selected.targets.remove(this);
if(_status.multitarget){
game.uncheck();
game.check();
}
else{
this.classList.remove('selected');
}
}
else{
ui.selected.targets.add(this);
2015-05-12 09:51:40 +00:00
if(_status.event.name=='chooseToUse'){
var targetprompt=null;
if(_status.event.targetprompt){
targetprompt=_status.event.targetprompt;
2015-04-29 03:25:17 +00:00
}
2015-05-12 09:51:40 +00:00
else if(_status.event.skill&&!get.info(_status.event.skill).viewAs){
targetprompt=get.info(_status.event.skill).targetprompt;
2015-04-29 03:25:17 +00:00
}
2015-05-12 09:51:40 +00:00
else{
var currentcard=get.card();
if(currentcard){
targetprompt=get.info(currentcard).targetprompt;
}
2015-04-29 03:25:17 +00:00
}
2015-05-12 09:51:40 +00:00
if(targetprompt){
if(Array.isArray(targetprompt)){
targetprompt=targetprompt[Math.min(targetprompt.length-1,ui.selected.targets.indexOf(this))];
}
else if(typeof targetprompt=='function'){
targetprompt=targetprompt(this);
}
if(targetprompt&&typeof targetprompt=='string'){
this.prompt(targetprompt);
}
2015-04-29 03:25:17 +00:00
}
}
this.classList.add('selected');
}
if(custom.add.target){
custom.add.target();
}
game.check();
},
control:function(){
if(_status.dragged) return;
if(ui.control.classList.contains('hidden')) return;
var node=this.parentNode;
if(node){
if(node._doubleclick){
return;
}
else{
node._doubleclick=true;
setTimeout(function(){
node._doubleclick=false;
},500);
}
}
if(this.parentNode.classList.contains('hidden')) return;
if(ui.intro){
ui.intro.close();
delete ui.intro;
}
_status.clicked=true;
if(this.parentNode.custom){
this.parentNode.custom(this.link,this);
return;
}
if(this.link=='ok'){
ui.click.ok(this);
}
else if(this.link=='cancel'){
ui.click.cancel(this);
}
else{
_status.event.result={
buttons:ui.selected.buttons.slice(0),
cards:ui.selected.cards.slice(0),
targets:ui.selected.targets.slice(0),
control:this.link,
links:get.links(ui.selected.buttons)
};
if(this.parentNode.close!=false){
game.uncheck();
this.parentNode.close();
}
game.resume();
}
},
skill:function(skill){
var info=get.info(skill);
var event=_status.event;
event.backup(skill);
if(typeof event.skillDialog=='object'){
event.skillDialog.close();
}
if(event.isMine()){
event.skillDialog=true;
}
game.uncheck();
game.check();
if(event.skillDialog){
var str=get.translation(skill);
if(info.prompt){
if(typeof info.prompt=='function'){
str+=''+info.prompt(event);
}
else{
str+=''+info.prompt;
}
event.skillDialog=ui.create.dialog(str);
}
2015-10-20 17:44:00 +00:00
else if(info.promptfunc){
event.skillDialog=ui.create.dialog(str,'<div><div style="width:100%">'+info.promptfunc(event,event.player)+'</div></div>');
}
2015-04-29 03:25:17 +00:00
else if(lib.translate[skill+'_info']){
event.skillDialog=ui.create.dialog(str,'<div><div style="width:100%">'+lib.translate[skill+'_info']+'</div></div>');
}
}
},
ok:function(node){
var event=_status.event;
if(event.custom.replace.confirm){
event.custom.replace.confirm(true);return;
}
event.result={
buttons:ui.selected.buttons.slice(0),
cards:ui.selected.cards.slice(0),
targets:ui.selected.targets.slice(0),
confirm:'ok',
bool:true,
links:get.links(ui.selected.buttons)
};
if(node){
node.parentNode.close();
}
if(event.skill){
event.result.skill=event.skill;
event.result.card=get.info(event.skill).viewAs;
if(event.result.cards.length==1&&event.result.card){
event.result.card.suit=event.result.cards[0].suit;
}
if(event.skillDialog&&get.objtype(event.skillDialog)=='div'){
event.skillDialog.close();
}
event.restore();
}
if(ui.skills) ui.skills.close();
2015-11-30 13:08:29 +00:00
if(ui.skills2) ui.skills2.close();
if(ui.skills3) ui.skills3.close();
2015-04-29 03:25:17 +00:00
game.uncheck();
if(event.custom.add.confirm){
event.custom.add.confirm(true);
}
game.resume();
},
cancel:function(node){
var event=_status.event;
if(event.custom.replace.confirm){
event.custom.replace.confirm(false);return;
}
2015-12-09 03:05:36 +00:00
if(event.skill&&!event.norestore){
2015-04-29 03:25:17 +00:00
if(event.skillDialog&&get.objtype(event.skillDialog)=='div'){
event.skillDialog.close();
}
if(typeof event.dialog=='string'&&event.isMine()){
event.dialog=ui.create.dialog(event.dialog);
}
event.restore();
game.uncheck();
game.check();
return;
}
event.result={
confirm:'cancel',
bool:false
};
if(node){
node.parentNode.close();
}
if(ui.skills) ui.skills.close();
2015-11-30 13:08:29 +00:00
if(ui.skills2) ui.skills2.close();
if(ui.skills3) ui.skills3.close();
2015-04-29 03:25:17 +00:00
game.uncheck();
if(event.custom.add.confirm){
event.custom.add.confirm(true);
}
game.resume();
},
oldintro:function(e){
if(_status.dragged) return;
_status.clicked=true;
if(this.classList.contains('player')&&!this.name){
return;
}
var i,translation,intro,str;
ui.click.intro2.call(this);
game.pause2();
ui.control.hide();
ui.intro=get.nodeintro(this).open();
ui.intro.source=this;
},
intro:function(e){
if(_status.dragged) return;
_status.clicked=true;
if(this.classList.contains('player')&&!this.name){
return;
}
var uiintro=get.nodeintro(this);
uiintro.classList.add('popped');
uiintro.classList.add('static');
ui.window.appendChild(uiintro);
var layer=ui.create.div('.poplayer',ui.arena);
var clicklayer=function(e){
uiintro.delete();
this.remove();
game.resume2();
e.stopPropagation();
return false;
}
layer.addEventListener(lib.config.touchscreen?'touchend':'click',clicklayer);
2015-11-14 09:02:14 +00:00
if(!lib.config.touchscreen) layer.oncontextmenu=clicklayer;
2015-04-29 03:25:17 +00:00
lib.placePoppedDialog(uiintro,e);
uiintro.style.zIndex=21;
var clickintro=function(){
layer.remove();
this.delete();
game.resume2();
};
uiintro.addEventListener('mouseleave',clickintro);
uiintro.addEventListener('click',clickintro);
game.pause2();
2015-05-02 09:54:39 +00:00
return uiintro;
2015-04-29 03:25:17 +00:00
},
intro2:function(){
if(ui.intro){
ui.intro.close();
if(ui.intro.source==this){
delete ui.intro;
ui.control.show();
game.resume2();
return;
}
}
},
auto:function(){
if(ui.auto.classList.contains('hidden')) return;
if(!_status.auto){
_status.auto=true;
// ui.auto.innerHTML='手动';
ui.auto.classList.add('glow');
if(ui.confirm) ui.confirm.close();
ui.control.hide();
if(_status.event.switchToAuto){
_status.event.switchToAuto();
}
else{
if(_status.paused&&_status.imchoosing){
game.uncheck();
_status.event.redo();
}
}
game.resume();
}
else{
ui.control.show();
_status.auto=false;
ui.auto.classList.remove('glow');
// ui.auto.innerHTML='托管';
}
},
wuxie:function(){
2015-04-30 03:09:07 +00:00
if(this.classList.contains('hidden')) return;
2015-04-29 03:25:17 +00:00
this.classList.toggle('glow');
if(this.classList.contains('glow')&&
(_status.event.parent.name=='_wuxie1'||_status.event.parent.name=='_wuxie2')&&
_status.event.isMine()&&ui.confirm){
ui.click.cancel(ui.confirm.lastChild);
}
},
2015-11-26 08:15:28 +00:00
tempnowuxie:function(){
if(this.classList.contains('hidden')) return;
this.classList.toggle('glow');
if(this.classList.contains('glow')&&
(_status.event.parent.name=='_wuxie1'||_status.event.parent.name=='_wuxie2')&&
_status.event.isMine()&&ui.confirm){
ui.click.cancel(ui.confirm.lastChild);
}
},
2015-04-29 03:25:17 +00:00
pause:function(){
if(_status.paused2) return;
ui.system.hide();
game.pause2();
var node=ui.create.pause().animate('start');
ui.sidebar3.innerHTML='';
2015-05-01 09:34:01 +00:00
if(lib.config.show_discardpile){
for(var i=0;i<ui.discardPile.childNodes.length;i++){
var div=ui.create.div(ui.sidebar3);
div.innerHTML=get.translation(ui.discardPile.childNodes[i]);
ui.sidebar3.insertBefore(div,ui.sidebar3.firstChild);
}
}
2015-04-29 03:25:17 +00:00
node.appendChild(ui.sidebar);
node.appendChild(ui.sidebar3);
2015-04-29 03:25:17 +00:00
ui.arena.classList.add('paused');
2015-05-11 11:57:44 +00:00
if(game.onpause){
game.onpause();
}
2015-04-29 03:25:17 +00:00
},
resume:function(e){
2015-04-29 03:44:48 +00:00
if(_status.pausing) return;
2015-04-29 03:25:17 +00:00
if(_status.dragged) return;
if(_status.clicked) return;
this.delete();
ui.system.show();
ui.arena.classList.remove('paused');
game.resume2();
e.stopPropagation();
2015-05-11 11:57:44 +00:00
if(game.onresume){
game.onresume();
}
2015-04-29 03:25:17 +00:00
return false;
},
config:function(){
if(_status.paused2) _status.config2=false;
else _status.config2=true;
2015-05-01 07:35:43 +00:00
2015-04-29 03:25:17 +00:00
_status.clicked=true;
game.pause2();
2015-10-29 17:36:14 +00:00
if(lib.config.config_menu){
ui.click.configMenu();
2015-11-29 11:46:51 +00:00
ui.system1.classList.remove('shown');
ui.system2.classList.remove('shown');
2015-10-29 17:36:14 +00:00
}
else{
ui.system.hide();
if(false&&lib.config.right_sidebar) ui.arena.classList.add('left');
else ui.arena.classList.add('right');
ui.window.appendChild(ui.configbg);
setTimeout(function(){
ui.config.animate('start');
ui.window.appendChild(ui.config);
},100);
if(game.onpause2){
game.onpause2();
}
2015-05-11 11:57:44 +00:00
}
2015-04-29 03:25:17 +00:00
},
2015-04-29 07:54:48 +00:00
config2:function(e){
2015-04-29 03:25:17 +00:00
_status.clicked=true;
ui.system.show();
ui.arena.classList.remove('right');
ui.arena.classList.remove('left');
2015-05-02 09:54:39 +00:00
ui.arena.classList.remove('paused2');
2015-04-29 03:25:17 +00:00
// ui.arena.classList.remove('paused');
this.remove();
2015-05-02 09:54:39 +00:00
if(ui.gameviewdialog){
if(ui.gameviewdialog.popped){
ui.gameviewdialog.popped.delete();
delete ui.gameviewdialog.popped;
}
ui.gameviewdialog.close();
delete ui.gameviewdialog;
ui.currentgameview.classList.remove('thundertext');
}
2015-04-29 03:25:17 +00:00
ui.config.delete();
if(_status.config2){
game.resume2();
}
2015-05-02 14:43:52 +00:00
// e.stopPropagation();
2015-05-11 11:57:44 +00:00
if(game.onresume2){
game.onresume2();
}
2015-04-29 07:54:48 +00:00
return false;
2015-04-29 03:25:17 +00:00
},
swap:function(){
if(_status.dragged) return;
if(this.classList.contains('dead')) return;
if(_status.over) return;
if(ui.auto) ui.auto.show();
if(ui.wuxie) ui.wuxie.show();
2015-04-29 03:25:17 +00:00
game.swapPlayer(this);
},
2015-05-11 11:57:44 +00:00
mousewheel:function(evt){
2015-12-02 15:34:34 +00:00
if(this.firstChild&&this.firstChild.classList.contains('handcards')&&
!this.classList.contains('scrollh')) return;
2015-04-29 03:25:17 +00:00
var node=this;
2015-05-11 11:57:44 +00:00
var num=this._scrollnum||6;
var speed=this._scrollspeed||16;
2015-04-29 03:25:17 +00:00
clearInterval(node.interval);
if(evt.detail > 0 || evt.wheelDelta < 0){
node.interval=setInterval(function(){
2015-05-11 11:57:44 +00:00
if(num--&&Math.abs(node.scrollLeft+node.clientWidth-node.scrollWidth)>0){
node.scrollLeft +=speed;
2015-04-29 03:25:17 +00:00
}
else{
clearInterval(node.interval);
}
2015-05-11 11:57:44 +00:00
},16);
2015-04-29 03:25:17 +00:00
}
else{
node.interval=setInterval(function(){
if(num--&&node.scrollLeft>0){
2015-05-11 11:57:44 +00:00
node.scrollLeft -=speed;
2015-04-29 03:25:17 +00:00
}
else{
clearInterval(node.interval);
}
2015-05-11 11:57:44 +00:00
},16);
2015-04-29 03:25:17 +00:00
}
},
touchStart:function(e){
this.startX=e.touches[0].clientX;
this.startY=e.touches[0].clientY;
_status.dragged=false;
},
touchScroll:function(e) {
2015-11-26 08:15:28 +00:00
if(_status.mousedragging) return;
2015-12-12 08:37:15 +00:00
if(_status.draggingtouchdialog) return;
2015-04-29 03:25:17 +00:00
if(!_status.dragged){
if (Math.abs(e.touches[0].clientX - this.startX) > 10 ||
Math.abs(e.touches[0].clientY - this.startY) > 10) {
_status.dragged=true;
}
}
2015-11-29 11:46:51 +00:00
if(this.scrollWidth<=this.offsetWidth+5&&
this.scrollHeight<=this.offsetHeight+5){
2015-04-29 03:25:17 +00:00
e.preventDefault();
}
else{
2015-11-29 11:46:51 +00:00
delete _status._swipeorigin;
2015-04-29 03:25:17 +00:00
e.stopPropagation();
}
},
sidebar:{
2015-04-29 07:54:48 +00:00
local:function(item){
game.saveConfig(this.name,item,true);
},
local2:function(item){
game.saveConfig(this.name,item,true);
ui.sidebarrestart.classList.add('thundertext');
},
2015-10-28 03:47:35 +00:00
wuxie_self:function(item){
ui.wuxie_self.lastChild.click();
},
2015-04-29 07:54:48 +00:00
global:function(item){
game.saveConfig(this.name,item);
},
global2:function(item){
game.saveConfig(this.name,item);
ui.sidebarrestart.classList.add('thundertext');
},
2015-04-29 14:56:33 +00:00
background_music:function(item){
game.saveConfig(this.name,item);
game.playBackgroundMusic();
},
2015-04-29 03:25:17 +00:00
cheat:function(bool){
if(lib.config.cheat&&bool==false){
lib.cheat=window.cheat;
delete window.cheat;
delete window.game;
delete window.ui;
delete window.get;
delete window.ai;
delete window.lib;
delete window._status;
}
else if(!lib.config.cheat&&bool){
window.cheat=lib.cheat;
window.cheat.i();
}
game.saveConfig('cheat',bool);
},
free_choose:function(bool){
game.saveConfig('free_choose',bool,true);
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat2&&get.config('free_choose')) ui.create.cheat2();
else if(ui.cheat2&&!get.config('free_choose')){
ui.cheat2.close();
delete ui.cheat2;
2015-05-08 08:07:38 +00:00
if(ui.cheat2x){
ui.cheat2x.close();
delete ui.cheat2;
}
2015-04-29 03:25:17 +00:00
}
},
change_identity:function(bool){
game.saveConfig('change_identity',bool,true);
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
var dialog;
if(ui.cheat2&&ui.cheat2.backup) dialog=ui.cheat2.backup;
else dialog=_status.event.dialog;
if(!dialog.querySelector('table')&&get.config('change_identity')) _status.event.parent.addSetting(dialog);
else _status.event.parent.removeSetting(dialog);
2015-04-29 03:25:17 +00:00
ui.update();
},
2015-05-04 03:17:03 +00:00
battle_number:function(num){
game.saveConfig('battle_number',num,true);
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(_status.event.parent.changeDialog){
_status.event.parent.changeDialog();
}
},
2015-04-29 03:25:17 +00:00
change_choice:function(bool){
game.saveConfig('change_choice',bool,true);
if(!_status.event.parent.showConfig&&!_status.event.showConfig) return;
if(!ui.cheat&&get.config('change_choice')) ui.create.cheat();
else if(ui.cheat&&!get.config('change_choice')){
ui.cheat.close();
delete ui.cheat;
}
},
player_number:function(num){
game.saveConfig('player_number',num,true);
2015-04-29 08:41:00 +00:00
game.reload();
2015-04-29 03:25:17 +00:00
},
2015-10-29 17:36:14 +00:00
auto_identity:function(item){
2015-04-29 03:25:17 +00:00
game.saveConfig('auto_identity',bool,true);
var num;
2015-10-29 17:36:14 +00:00
switch(item){
case 'one':num=1;break;
case 'two':num=2;break;
case 'three':num=3;break;
case 'always':num=-1;break;
2015-04-29 03:25:17 +00:00
default:num=0;break;
}
if(num&!_status.identityShown&&game.phaseNumber>game.players.length*num&&game.showIdentity){
_status.identityShown=true;
2015-11-01 07:54:42 +00:00
game.showIdentity(false);
2015-04-29 03:25:17 +00:00
}
},
swap:function(bool){
game.saveConfig('swap',bool,true);
if(get.config('swap')){
if(!ui.swap&&game.me.isDead()){
ui.swap=ui.create.control('换人',ui.click.dieswap);
}
}
else if(ui.swap){
ui.swap.close();
delete ui.swap;
}
},
revive:function(bool){
game.saveConfig('revive',bool,true);
if(get.config('revive')){
if(!ui.revive&&game.me.isDead()){
ui.revive=ui.create.control('revive',ui.click.dierevive);
}
}
else if(ui.revive){
ui.revive.close();
delete ui.revive;
}
},
hover_all:function(bool){
game.saveConfig('hover_all',bool);
if(!lib.config.hover_all) ui.hoverhandcardconfig.classList.add('disabled');
else ui.hoverhandcardconfig.classList.remove('disabled');
ui.sidebarrestart.classList.add('thundertext');
},
theme:function(theme){
game.saveConfig('theme',theme);
ui.arena.hide();
setTimeout(function(){
var theme=ui.css.theme;
ui.css.theme=lib.init.css('theme/'+lib.config.theme,'style');
theme.remove();
setTimeout(function(){ui.arena.show();},100);
},500);
},
layout:function(layout){
game.saveConfig('layout',layout);
2015-05-08 08:07:38 +00:00
if(lib.config.mode!='chess'){
ui.arena.hide();
setTimeout(function(){
var layout=ui.css.layout;
ui.css.layout=lib.init.css('layout/'+lib.config.layout,'layout',layout);
2015-04-29 03:25:17 +00:00
2015-05-08 08:07:38 +00:00
setTimeout(function(){layout.remove();ui.arena.show();},100);
},500);
}
2015-04-29 03:25:17 +00:00
},
2015-04-29 07:54:48 +00:00
image_background:function(background){
var animate=lib.config.image_background=='default';
game.saveConfig('image_background',background);
2015-04-29 03:25:17 +00:00
ui.background.delete();
ui.background=ui.create.div('.background');
2015-04-29 07:54:48 +00:00
switch (lib.config.image_background_filter){
2015-11-05 02:34:35 +00:00
case 'blur':
ui.background.style.filter='blur(8px)';
ui.background.style.webkitFilter='blur(8px)';
ui.background.style.transform='scale(1.05)';break;
case 'gray':
ui.background.style.filter='grayscale(1)';
ui.background.style.webkitFilter='grayscale(1)';
break;
case 'sepia':
ui.background.style.filter='sepia(0.5)';
ui.background.style.webkitFilter='sepia(0.5)';
break;
case 'invert':
ui.background.style.filter='invert(1)';
ui.background.style.webkitFilter='invert(1)';
break;
case 'saturate':
ui.background.style.filter='saturate(5)';
ui.background.style.webkitFilter='saturate(5)';
break;
case 'contrast':
ui.background.style.filter='contrast(1.4)';
ui.background.style.webkitFilter='contrast(1.4)';
break;
case 'hue':
ui.background.style.filter='hue-rotate(180deg)';
ui.background.style.webkitFilter='hue-rotate(180deg)';
break;
case 'brightness':
ui.background.style.filter='brightness(5)';
ui.background.style.webkitFilter='brightness(5)';
break;
default:
ui.background.style.filter='';
ui.background.style.webkitFilter='';
ui.background.style.transform='';
2015-04-29 03:25:17 +00:00
}
2015-04-29 07:54:48 +00:00
2015-04-29 03:25:17 +00:00
document.body.insertBefore(ui.background,document.body.firstChild);
if(animate) ui.background.animate('start');
2015-04-29 07:54:48 +00:00
if(lib.config.image_background=='default'){
2015-04-29 03:25:17 +00:00
ui.background.style.backgroundImage="none";
}
2015-12-02 10:40:25 +00:00
else if(lib.config.image_background=='custom'){
ui.background.style.backgroundImage="none";
game.getDB('image','background',function(fileToLoad){
if(!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var data = fileLoadedEvent.target.result;
ui.background.style.backgroundImage='url('+data+')';
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
}
2015-04-29 03:25:17 +00:00
else{
2015-04-29 07:54:48 +00:00
ui.background.style.backgroundImage="url('image/background/"+lib.config.image_background+".jpg')";
2015-04-29 03:25:17 +00:00
}
2015-04-29 07:54:48 +00:00
ui.background.style.backgroundSize='cover';
2015-04-29 03:25:17 +00:00
},
2015-04-29 07:54:48 +00:00
image_background_filter:function(filter){
game.saveConfig('image_background_filter',filter);
ui.click.sidebar.image_background(lib.config.image_background);
2015-04-29 03:25:17 +00:00
},
ui_zoom:function(zoom){
game.saveConfig('ui_zoom',zoom);
switch(zoom){
case '极小':ui.window.style.zoom=0.8;break;
case '很小':ui.window.style.zoom=0.9;break;
case '较小':ui.window.style.zoom=0.95;break;
case '较大':ui.window.style.zoom=1.05;break;
case '很大':ui.window.style.zoom=1.1;break;
default:ui.window.style.zoom=1;
}
},
show_name:function(bool){
game.saveConfig('show_name',bool);
var players=get.players(false,true);
if(lib.config.show_name){
for(var i=0;i<players.length;i++){
game.players[i].node.name.style.display='';
}
}
else{
for(var i=0;i<players.length;i++){
game.players[i].node.name.style.display='none';
}
}
},
show_replay:function(bool){
game.saveConfig('show_replay',bool);
if(lib.config.show_replay){
ui.replay.style.display='';
}
else{
ui.replay.style.display='none';
}
},
2015-08-15 09:10:06 +00:00
bottom_line:function(bool){
game.saveConfig('bottom_line',bool);
if(lib.config.bottom_line){
ui.canvas.style.zIndex=0;
}
else{
ui.canvas.style.zIndex='';
}
},
2015-04-29 03:25:17 +00:00
show_playerids:function(bool){
game.saveConfig('show_playerids',bool);
if(lib.config.show_playerids){
ui.playerids.style.display='';
}
else{
ui.playerids.style.display='none';
}
},
show_auto:function(bool){
game.saveConfig('show_auto',bool);
if(lib.config.show_auto){
ui.auto.style.display='';
}
else{
ui.auto.style.display='none';
}
},
2015-04-30 03:09:07 +00:00
show_volumn:function(bool){
game.saveConfig('show_volumn',bool);
if(lib.config.show_volumn){
ui.volumn.style.display='';
}
else{
ui.volumn.style.display='none';
}
},
2015-04-29 03:25:17 +00:00
show_wuxie:function(bool){
game.saveConfig('show_wuxie',bool);
if(lib.config.show_wuxie){
ui.wuxie.style.display='';
}
else{
ui.wuxie.style.display='none';
}
},
show_pause:function(bool){
game.saveConfig('show_pause',bool);
if(lib.config.show_pause){
ui.pause.style.display='';
ui.auto.style.marginLeft='10px';
}
else{
ui.pause.style.display='none';
ui.auto.style.marginLeft='';
}
},
show_scrollbar:function(bool){
game.saveConfig('show_scrollbar',bool);
if(lib.config.touchscreen) return;
if(bool){
ui.css.scrollbar=lib.init.css('layout/default','scrollbar');
}
else{
ui.css.scrollbar.remove();
}
},
2015-04-29 07:54:48 +00:00
touchscreen:function (bool){
2015-04-29 03:25:17 +00:00
game.saveConfig('touchscreen',bool);
if(bool){
game.saveConfig('confirmtouch',false);
ui.handcardmousewheel.classList.add('disabled');
}
else{
ui.handcardmousewheel.classList.remove('disabled');
}
ui.sidebarrestart.classList.add('thundertext');
},
blur_ui:function(bool){
game.saveConfig('blur_ui',bool);
if(bool){
ui.css.blur_ui=lib.init.css('layout/default','blur');
}
else if(ui.css.blur_ui){
ui.css.blur_ui.remove();
}
},
right_sidebar:function(bool){
game.saveConfig('right_sidebar',bool);
if(bool){
ui.config.classList.add('right');
ui.sidebar.classList.add('right');
ui.sidebar3.classList.add('left');
2015-04-29 03:25:17 +00:00
ui.arena.classList.add('left');
ui.arena.classList.remove('right');
ui.system.appendChild(ui.system1);
}
else{
ui.config.classList.remove('right');
ui.sidebar.classList.remove('right');
ui.sidebar3.classList.remove('left');
2015-04-29 03:25:17 +00:00
ui.arena.classList.add('right');
ui.arena.classList.remove('left');
ui.system.appendChild(ui.system2);
}
},
title:function(bool){
game.saveConfig('title',bool);
if(!lib.config.title) document.title='无名杀';
},
characters:function(bool,node){
2015-04-29 08:41:00 +00:00
var name=node.link.slice(0,node.link.length-10);
if(bool){
lib.config.characters.add(name);
}
else{
lib.config.characters.remove(name);
}
game.saveConfig('characters',lib.config.characters);
2015-04-29 03:25:17 +00:00
ui.sidebarrestart.classList.add('thundertext');
},
cards:function(bool,node){
2015-04-29 08:41:00 +00:00
var name=node.link.slice(0,node.link.length-5);
if(bool){
lib.config.cards.add(name);
}
else{
lib.config.cards.remove(name);
}
game.saveConfig('cards',lib.config.cards);
2015-04-29 03:25:17 +00:00
ui.sidebarrestart.classList.add('thundertext');
},
plays:function(bool,node){
2015-04-29 08:41:00 +00:00
var name=node.link.slice(0,node.link.length-5);
if(bool){
lib.config.plays.add(name);
}
else{
lib.config.plays.remove(name);
}
game.saveConfig('plays',lib.config.plays);
2015-04-29 03:25:17 +00:00
ui.sidebarrestart.classList.add('thundertext');
},
forbid:function(bool,node){
var list=lib.config.forbidlist;
list[node.link]=bool;
game.saveConfig('forbidlist',list);
ui.sidebarrestart.classList.add('thundertext');
},
autoskill:function(bool,node){
var list=lib.config.autoskilllist;
if(bool){
list.remove(node.link);
}
else{
list.add(node.link);
}
game.saveConfig('autoskilllist',list);
},
sort:function(func){
game.saveConfig('sort',func);
lib.config.sort_card=get.sortCard(lib.config.sort);
var i,cards=game.me.get('h');
for(i=0;i<cards.length;i++) cards[i].remove();
cards.sort(function(a,b){
if(get.config('reverse_sort')) return lib.config.sort_card(a)-lib.config.sort_card(b);
return lib.config.sort_card(b)-lib.config.sort_card(a);
});
2015-10-31 10:14:14 +00:00
if(!lib.isSingleHandcard()){
2015-05-08 08:07:38 +00:00
for(i=0;i<cards.length;i++){
if(lib.config.sort_card(cards[i])>0){
game.me.node.handcards1.appendChild(cards[i]);
}
else{
game.me.node.handcards2.appendChild(cards[i]);
}
2015-04-29 03:25:17 +00:00
}
}
},
reverse_sort:function(bool){
game.saveConfig('reverse_sort',bool,true);
var cards1=[];
var cards2=[];
var i;
for(i=0;i<game.me.node.handcards1.childNodes.length;i++){
cards1.unshift(game.me.node.handcards1.childNodes[i]);
}
for(i=0;i<game.me.node.handcards2.childNodes.length;i++){
cards2.unshift(game.me.node.handcards2.childNodes[i]);
}
2015-10-31 10:14:14 +00:00
if(!lib.isSingleHandcard()){
2015-05-08 08:07:38 +00:00
var cards=game.me.num('h');
for(var i=0;i<cards.length;i++) cards[i].remove();
for(i=0;i<cards1.length;i++){
game.me.node.handcards2.appendChild(cards1[i]);
}
for(i=0;i<cards2.length;i++){
game.me.node.handcards1.appendChild(cards2[i]);
}
2015-04-29 03:25:17 +00:00
}
}
},
rightplayer:function(e){
2015-10-20 17:44:00 +00:00
if(this._nopup) return false;
2015-04-29 03:25:17 +00:00
if(_status.clickedplayer){
return false;
}
2015-11-29 11:46:51 +00:00
// if(this._mouseentercreated){
// this._mouseentercreated=false;
// ui.click.window();
// }
// else{
// ui.click.intro.call(this,e);
// }
if(this._mouseenterdialog&&this._mouseenterdialog.parentNode){
this._mouseenterdialog.delete();
}
else{
ui.click.intro.call(this,e);
}
2015-04-29 03:25:17 +00:00
_status.clickedplayer=true;
_status.clicked=false;
ui.click.longpresscancel.call(this);
return false;
},
right:function(){
2015-12-06 15:23:47 +00:00
if(window.inSplash) return false;
2015-11-13 09:12:47 +00:00
if(lib.config.touchscreen) return;
2015-04-29 03:25:17 +00:00
if(_status.noright){
_status.noright=false;
return false;
}
if(_status.clickedplayer){
_status.clickedplayer=false;
return;
}
2015-11-05 02:34:35 +00:00
if(ui.currentpopped){
if(ui.currentpopped._uiintro){
ui.currentpopped._uiintro.delete();
delete ui.currentpopped._uiintro;
}
delete ui.currentpopped;
}
2015-04-29 03:25:17 +00:00
switch(lib.config.right_click){
case 'pause':ui.click.pause();break;
case 'auto':ui.click.auto();break;
case 'config':ui.click.config();break;
}
return false;
}
},
selected:{
buttons:[],cards:[],targets:[]
},
clear:function(){
2015-11-04 01:59:00 +00:00
game.addVideo('uiClear');
2015-04-29 03:25:17 +00:00
var thrown=document.getElementsByClassName('thrown');
var nodes=[];
var i;
for(i=0;i<thrown.length;i++){
nodes.push(thrown[i]);
}
for(i=0;i<nodes.length;i++){
if(!nodes[i].fixed) nodes[i].delete();
}
},
2015-11-24 15:44:21 +00:00
updatec:function(){
2015-12-01 05:46:28 +00:00
if(_status.noupdatec) return;
2015-11-24 15:44:21 +00:00
var length=0;
var controls=[];
var widths=[];
for(var i=0;i<ui.control.childNodes.length;i++){
if(ui.control.childNodes[i].classList.contains('removing')) continue;
var thiswidth=parseInt(ui.control.childNodes[i].style.width);
if(thiswidth){
thiswidth+=8;
length+=thiswidth;
widths.push(thiswidth);
}
else{
length+=ui.control.childNodes[i].offsetWidth;
widths.push(ui.control.childNodes[i].offsetWidth);
}
controls.push(ui.control.childNodes[i]);
if(i>0){
2015-11-30 13:08:29 +00:00
if(lib.config.layout=='phone'){
width+=12;
}
else{
width+=6;
}
2015-11-24 15:44:21 +00:00
}
}
if(!controls.length) return;
var offset=-length/2;
var control=controls.shift();
control.style.transform='translateX('+offset+'px)';
while(controls.length){
var control=controls.shift();
var width=widths.shift();
offset+=width+6;
2015-11-30 13:08:29 +00:00
if(lib.config.layout=='phone'){
offset+=6;
}
2015-11-24 15:44:21 +00:00
control.style.transform='translateX('+offset+'px)';
}
},
2015-05-07 04:48:00 +00:00
updatex:function(){
ui.update.apply(this,arguments);
2015-12-02 15:34:34 +00:00
ui.updatehl();
2015-05-07 04:48:00 +00:00
},
2015-11-24 15:44:21 +00:00
updatehl:function(){
if(!game.me) return;
2015-11-26 16:12:42 +00:00
if(!ui.handcards1Container||!ui.handcards2Container) return;
2015-12-09 03:05:36 +00:00
if(!ui.handcards1Container.childNodes.length) return;
2015-11-24 00:50:54 +00:00
var hs1=[],hs2=[];
2015-11-24 15:44:21 +00:00
for(var i=0;i<ui.handcards1Container.firstChild.childElementCount;i++){
if(!ui.handcards1Container.firstChild.childNodes[i].classList.contains('removing')){
hs1.push(ui.handcards1Container.firstChild.childNodes[i]);
2015-11-24 00:50:54 +00:00
}
}
2015-11-24 15:44:21 +00:00
for(var i=0;i<ui.handcards2Container.firstChild.childElementCount;i++){
if(!ui.handcards2Container.firstChild.childNodes[i].classList.contains('removing')){
hs2.push(ui.handcards2Container.firstChild.childNodes[i]);
2015-11-24 00:50:54 +00:00
}
}
2015-12-06 15:23:47 +00:00
var offset1,offset12=0;
2015-12-04 04:43:06 +00:00
if(!lib.config.fold_card){
offset1=112;
2015-12-02 15:34:34 +00:00
ui.handcards1Container.classList.add('scrollh');
}
else{
2015-12-04 04:43:06 +00:00
offset1=Math.min(112,(ui.handcards1Container.offsetWidth-128)/(hs1.length-1));
if(offset1<32){
offset1=32;
ui.handcards1Container.classList.add('scrollh');
}
else{
ui.handcards1Container.classList.remove('scrollh');
}
2015-12-02 15:34:34 +00:00
}
2015-12-06 15:23:47 +00:00
if(offset1<100){
offset12=100-offset1;
}
2015-11-24 00:50:54 +00:00
for(var i=0;i<hs1.length;i++){
2015-12-02 15:34:34 +00:00
hs1[i].style.transform='translateX('+(i*offset1)+'px)';
2015-12-03 16:28:06 +00:00
hs1[i]._transform='translateX('+(i*offset1)+'px)';
2015-11-24 00:50:54 +00:00
ui.refresh(hs1[i]);
hs1[i].classList.remove('drawinghidden');
2015-12-06 15:23:47 +00:00
if(offset12>40){
offset12=90-hs1[i].node.info.offsetWidth;
hs1[i].node.name.style.transform='translateY(17px)';
}
else{
hs1[i].node.name.style.transform='';
}
hs1[i].node.info.style.transform='translateX(-'+offset12+'px)';
2015-11-24 00:50:54 +00:00
}
2015-12-02 15:34:34 +00:00
ui.handcards1Container.firstChild.style.width=(offset1*(hs1.length-1)+118)+'px';
2015-12-04 04:43:06 +00:00
2015-12-06 15:23:47 +00:00
var offset2,offset22=0;
2015-12-04 04:43:06 +00:00
if(!lib.config.fold_card){
offset2=112;
2015-12-02 15:34:34 +00:00
ui.handcards2Container.classList.add('scrollh');
}
else{
2015-12-04 04:43:06 +00:00
offset2=Math.min(112,(ui.handcards2Container.offsetWidth-128)/(hs2.length-1));
if(offset2<32){
offset2=32;
ui.handcards2Container.classList.add('scrollh');
}
else{
ui.handcards2Container.classList.remove('scrollh');
}
2015-12-02 15:34:34 +00:00
}
2015-12-06 15:23:47 +00:00
if(offset2<100){
offset22=100-offset2;
}
2015-11-24 00:50:54 +00:00
for(var i=0;i<hs2.length;i++){
2015-12-02 15:34:34 +00:00
hs2[i].style.transform='translateX('+(i*offset2)+'px)';
2015-12-03 16:28:06 +00:00
hs2[i]._transform='translateX('+(i*offset2)+'px)';
2015-11-24 00:50:54 +00:00
ui.refresh(hs2[i]);
hs2[i].classList.remove('drawinghidden');
2015-12-06 15:23:47 +00:00
if(offset22>40){
offset22=90-hs2[i].node.info.offsetWidth;
hs2[i].node.name.style.transform='translateY(17px)';
}
else{
hs2[i].node.name.style.transform='';
}
hs2[i].node.info.style.transform='translateX(-'+offset22+'px)';
2015-11-24 00:50:54 +00:00
}
2015-12-02 15:34:34 +00:00
ui.handcards2Container.firstChild.style.width=(offset2*(hs2.length-1)+118)+'px';
2015-11-24 00:50:54 +00:00
},
2015-05-07 04:48:00 +00:00
updateh:function(compute){
2015-05-08 08:07:38 +00:00
if(!game.me) return;
2015-11-28 07:19:04 +00:00
if(!ui.handcards1Container) return;
2015-11-24 15:44:21 +00:00
if(lib.config.low_performance){
2015-11-25 12:34:54 +00:00
if(compute){
ui.updatehl();
setTimeout(ui.updatehl,1000);
}
2015-11-24 15:44:21 +00:00
return;
}
2015-05-07 04:48:00 +00:00
if(compute){
2015-11-24 15:44:21 +00:00
ui.handcards1Container._handcardsWidth=ui.handcards1Container.offsetWidth;
ui.handcards2Container._handcardsWidth=ui.handcards2Container.offsetWidth;
2015-05-07 04:48:00 +00:00
}
ui.updatehx(game.me.node.handcards1);
ui.updatehx(game.me.node.handcards2);
},
updatehx:function(node){
2015-11-24 15:44:21 +00:00
var width=node.parentNode._handcardsWidth;
2015-05-07 04:48:00 +00:00
var num=node.childElementCount-node.getElementsByClassName('removing').length;
2015-11-14 05:29:22 +00:00
node.classList.remove('fold0');
node.classList.remove('fold1');
node.classList.remove('fold2');
node.classList.remove('fold3');
2015-05-07 04:48:00 +00:00
if(num*78+40>=width){
2015-11-14 05:29:22 +00:00
// node.dataset.fold=3;
node.classList.add('fold3');
2015-05-07 04:48:00 +00:00
}
else if(num*93+25>=width){
2015-11-14 05:29:22 +00:00
// node.dataset.fold=2;
node.classList.add('fold2');
2015-05-07 04:48:00 +00:00
}
else if(num*112+6>=width){
2015-11-14 05:29:22 +00:00
// node.dataset.fold=1;
node.classList.add('fold1');
2015-05-07 04:48:00 +00:00
}
else{
2015-11-14 05:29:22 +00:00
// node.dataset.fold=0;
node.classList.add('fold0');
2015-05-07 04:48:00 +00:00
}
},
2015-04-29 03:25:17 +00:00
update:function(){
for(var i=0;i<ui.updates.length;i++){
ui.updates[i]();
}
2015-11-12 01:12:03 +00:00
if(ui.dialog&&!ui.dialog.classList.contains('noupdate')){
2015-05-08 08:07:38 +00:00
if(lib.config.mode=='chess'){
2015-12-09 08:49:22 +00:00
if(ui.dialog.content.scrollHeight<240&&(!ui.dialog.buttons||!ui.dialog.buttons.length)){
2015-05-08 08:07:38 +00:00
ui.dialog.style.height=ui.dialog.content.offsetHeight+'px';
2015-05-09 02:56:55 +00:00
ui.dialog.classList.add('slim');
2015-05-08 08:07:38 +00:00
}
else{
ui.dialog.style.height='';
2015-05-09 02:56:55 +00:00
ui.dialog.classList.remove('slim');
2015-05-08 08:07:38 +00:00
}
}
2015-12-08 13:54:44 +00:00
else{
if(!ui.dialog.buttons||!ui.dialog.buttons.length){
ui.dialog.classList.add('nobutton');
if(ui.dialog.content.offsetHeight<240){
2015-12-09 03:05:36 +00:00
if(!ui.dialog._heightset){
ui.dialog._heightset=ui.dialog.style.height||true;
}
2015-12-08 13:54:44 +00:00
ui.dialog.style.height=ui.dialog.content.offsetHeight+'px';
if(lib.config.show_log!='off'){
ui.dialog.classList.add('scroll1');
ui.dialog.classList.add('scroll2');
return;
}
}
else{
2015-12-09 03:05:36 +00:00
if(typeof ui.dialog._heightset=='string'){
ui.dialog.style.height=ui.dialog._heightset;
}
else if(ui.dialog._heightset){
ui.dialog.style.height='';
}
delete ui.dialog._heightset;
2015-12-08 13:54:44 +00:00
}
}
else{
2015-12-09 03:05:36 +00:00
if(typeof ui.dialog._heightset=='string'){
ui.dialog.style.height=ui.dialog._heightset;
}
else if(ui.dialog._heightset){
ui.dialog.style.height='';
}
delete ui.dialog._heightset;
2015-12-08 13:54:44 +00:00
ui.dialog.classList.remove('nobutton');
}
}
2015-10-31 10:14:14 +00:00
if(false&&lib.config.layout=='mobile'){
ui.dialog.style.height='';
if(ui.dialog.contentContainer.offsetHeight>=ui.dialog.content.offsetHeight){
ui.dialog.style.height=ui.dialog.content.offsetHeight+'px';
}
else{
ui.dialog.style.height='';
}
if(ui.dialog.content.offsetHeight<240){
ui.dialog.classList.add('slim');
ui.dialog.classList.remove('scroll1');
ui.dialog.classList.remove('scroll2');
}
else{
ui.dialog.classList.remove('slim');
ui.dialog.classList.add('scroll1');
ui.dialog.classList.add('scroll2');
}
2015-04-29 03:25:17 +00:00
}
else{
2015-10-31 10:14:14 +00:00
if(ui.dialog.content.offsetHeight<=240||
ui.dialog.contentContainer.offsetHeight>=ui.dialog.content.offsetHeight){
ui.dialog.classList.remove('scroll1');
ui.dialog.classList.remove('scroll2');
}
else{
ui.dialog.classList.add('scroll1');
ui.dialog.classList.add('scroll2');
}
2015-04-29 03:25:17 +00:00
}
2015-11-01 09:56:48 +00:00
}
2015-04-29 03:25:17 +00:00
},
recycle:function(node,key){
if(!ui._recycle) ui._recycle={};
if(typeof node=='string'){
return ui._recycle[node]
}
ui._recycle[key]=node;
},
};
var get={
config:function(item){
if(!lib.config.mode_config[lib.config.mode]) return;
return lib.config.mode_config[lib.config.mode][item];
},
2015-11-04 01:59:00 +00:00
cardInfo:function(card){
return [card.suit,card.number,card.name,card.nature];
},
cardsInfo:function(cards){
var info=[];
for(var i=0;i<cards.length;i++){
info.push(get.cardInfo(cards[i]));
}
return info;
},
infoCard:function(info){
return ui.create.card().init(info);
},
infoCards:function(info){
var cards=[];
for(var i=0;i<info.length;i++){
cards.push(get.infoCard(info[i]));
}
return cards;
},
2015-12-09 06:08:16 +00:00
verticalStr:function(str,sp){
2015-12-01 05:46:28 +00:00
if(typeof str!='string') return '';
2015-12-09 06:08:16 +00:00
str=str.toUpperCase();
2015-12-01 05:46:28 +00:00
var str2='';
for(var i=0;i<str.length;i++){
str2+=str[i];
2015-12-09 06:08:16 +00:00
if(sp&&str[i]=='S'&&str[i+1]=='P') continue;
2015-12-01 05:46:28 +00:00
if(i<str.length-1){
str2+='<br>';
}
}
return str2;
},
2015-12-08 00:56:54 +00:00
slimName:function(str){
2015-12-09 05:29:35 +00:00
var str2=lib.translate[str];
if(!str2) return '';
if(str2.indexOf('sp')==0){
str2=str2.slice(2);
2015-12-08 00:56:54 +00:00
}
2015-12-09 05:29:35 +00:00
else if(str2.indexOf('界sp')==0){
str2=str2.slice(3);
2015-12-08 00:56:54 +00:00
}
2015-12-09 06:08:16 +00:00
return get.verticalStr(str2,true);
2015-12-08 00:56:54 +00:00
},
2015-11-04 01:59:00 +00:00
time:function(){
if(lib.status.dateDelaying){
return lib.getUTC(lib.status.dateDelaying)-lib.getUTC(lib.status.date)-lib.status.dateDelayed;
}
else{
return lib.getUTC(new Date())-lib.getUTC(lib.status.date)-lib.status.dateDelayed;
}
},
2015-11-29 11:46:51 +00:00
currentTime:function(){
return lib.getUTC(new Date());
},
2015-10-29 17:36:14 +00:00
evtDistance:function(e1,e2){
return Math.sqrt((e1.x-e2.x)*(e1.x-e2.x)+(e1.y-e2.y)*(e1.y-e2.y));
},
2015-11-23 10:59:44 +00:00
xyDistance:function(from,to){
return Math.sqrt((from[0]-to[0])*(from[0]-to[0])+(from[1]-to[1])*(from[1]-to[1]));
},
2015-04-29 03:25:17 +00:00
skillLocked:function(skill){
var info=lib.skill[skill];
if(info.locked==false) return false;
if(info.trigger&&info.forced) return true;
if(info.mod) return true;
if(info.locked) return true;
return false;
},
itemtype:function(obj){
var i,j;
if(typeof obj=='string'){
if(obj.length<=3){
for(i=0;i<obj.length;i++){
if(/h|e|j/.test(obj[i])==false) return;
}
return 'position';
}
if(lib.nature.contains(obj)) return 'nature';
}
if(get.objtype(obj)=='array'&&obj.length){
var isPlayers=true;
for(i=0;i<obj.length;i++){
if(get.itemtype(obj[i])!='player') {isPlayers=false;break;}
}
if(isPlayers) return 'players';
var isCards=true;
for(i=0;i<obj.length;i++){
if(get.itemtype(obj[i])!='card') {isCards=false;break;}
}
if(isCards) return 'cards';
if(obj.length==2){
if(typeof obj[0]=='number'&&typeof obj[1]=='number'){
if(obj[0]<=obj[1]) return 'select';
}
}
if(obj.length==4){
var isPosition=true;
for(i=0;i<obj.length;i++){
if(typeof obj[i]!='number') {isPosition=false;break;}
}
if(isPosition) return 'divposition';
}
}
if(get.objtype(obj)=='div'){
if(obj.classList.contains('button')) return 'button';
if(obj.classList.contains('card')) return 'card';
if(obj.classList.contains('player')) return 'player';
if(obj.classList.contains('dialog')) return 'dialog';
}
},
equipNum:function(card){
if(get.type(card)=='equip'){
return parseInt(get.subtype(card)[5]);
}
return 0;
},
objtype:function(obj){
if(Object.prototype.toString.call(obj) === '[object Array]') return 'array';
if(Object.prototype.toString.call(obj) === '[object HTMLDivElement]') return 'div';
if(Object.prototype.toString.call(obj) === '[object HTMLTableElement]') return 'table';
if(Object.prototype.toString.call(obj) === '[object HTMLTableRowElement]') return 'tr';
if(Object.prototype.toString.call(obj) === '[object HTMLTableCellElement]') return 'td';
if(Object.prototype.toString.call(obj) === '[object HTMLBodyElement]') return 'td';
},
type:function(obj,method){
2015-10-30 15:32:48 +00:00
if(typeof obj=='string') obj={name:obj};
2015-04-29 03:25:17 +00:00
if(typeof obj!='object') return;
if(!lib.card[obj.name]) return;
if(method=='trick'&&lib.card[obj.name].type=='delay') return 'trick';
return lib.card[obj.name].type;
},
subtype:function(obj){
if(!lib.card[obj.name]) return;
return lib.card[obj.name].subtype;
},
suit:function(card){
if(get.itemtype(card)=='cards'){
var suit=get.suit(card[0])
for(var i=1;i<card.length;i++){
if(get.suit(card[i])!=suit) return 'none';
}
return suit;
}
else{
if(get.owner(card)){
return game.checkMod(card,card.suit,'suit',get.owner(card).get('s'));
}
return card.suit;
}
},
color:function(card){
if(get.itemtype(card)=='cards'){
var color=get.color(card[0])
for(var i=1;i<card.length;i++){
if(get.color(card[i])!=color) return 'none';
}
return color;
}
else{
if(get.suit(card)=='spade'||get.suit(card)=='club') return 'black';
if(get.suit(card)=='heart'||get.suit(card)=='diamond') return 'red';
return 'none';
}
},
number:function(card){
return card.number;
},
nature:function(card){
return card.nature;
},
cards:function(num){
var list=[];
var card=false;
2015-05-04 03:17:03 +00:00
if(typeof num!='number') num=1;
2015-04-29 03:25:17 +00:00
if(num==0) {card=true;num=1;}
while(num--){
if(ui.cardPile.hasChildNodes()==false){
if(_status.maxShuffle!=undefined){
if(_status.maxShuffle==0){
game.over('平局');
return;
}
_status.maxShuffle--;
}
var cards=[],i;
for(i=0;i<ui.discardPile.childNodes.length;i++){
cards.push(ui.discardPile.childNodes[i]);
}
2015-05-03 15:17:15 +00:00
cards.randomSort();
2015-04-29 03:25:17 +00:00
for(var i=0;i<cards.length;i++){
ui.cardPile.appendChild(cards[i]);
}
}
if(ui.cardPile.hasChildNodes()==false){
game.over('平局');
return;
}
list.push(ui.cardPile.removeChild(ui.cardPile.firstChild));
}
if(card) return list[0];
return list;
},
judge:function(card){
if(card.viewAs) return lib.card[card.viewAs].judge;
return get.info(card).judge;
},
distance:function(from,to,method){
if(from==to) return 0;
2015-05-04 03:17:03 +00:00
if(!game.players.contains(from)&&!game.dead.contains(from)) return Infinity;
if(!game.players.contains(to)&&!game.dead.contains(to)) return Infinity;
2015-04-29 03:25:17 +00:00
var player=from,m,n=1,i;
2015-05-08 08:07:38 +00:00
var fxy,txy;
if(lib.config.mode=='chess'){
fxy=from.getXY();
txy=to.getXY();
n=Math.abs(fxy[0]-txy[0])+Math.abs(fxy[1]-txy[1]);
if(method=='raw'||method=='pure'||method=='absolute') return n;
}
2015-05-12 09:51:40 +00:00
else if(to.isMin(true)||from.isMin(true)){
2015-05-08 08:07:38 +00:00
if(method=='raw'||method=='pure'||method=='absolute') return 1;
2015-04-29 03:25:17 +00:00
}
2015-05-03 15:17:15 +00:00
else{
var length=game.players.length;
2015-05-04 03:17:03 +00:00
var totalPopulation=game.players.length+game.dead.length+1;
2015-05-05 14:57:35 +00:00
for(var iwhile=0;iwhile<totalPopulation;iwhile++){
2015-05-04 03:17:03 +00:00
if(player.nextSeat!=to){
player=player.nextSeat;
2015-05-12 09:51:40 +00:00
if(player.isAlive()&&!player.isOut()&&!player.isMin(true)) n++;
2015-05-04 03:17:03 +00:00
}
else{
break;
}
2015-05-03 15:17:15 +00:00
}
for(i=0;i<game.players.length;i++){
2015-05-12 09:51:40 +00:00
if(game.players[i].isOut()||game.players[i].isMin(true)) length--;
2015-05-03 15:17:15 +00:00
}
if(method=='absolute') return n;
if(from.isDead()) length++;
if(to.isDead()) length++;
n=Math.min(n,length-n);
2015-05-08 08:07:38 +00:00
if(method=='raw'||method=='pure') return n;
2015-04-29 03:25:17 +00:00
}
n=game.checkMod(from,to,n,'globalFrom',from.get('s'));
n=game.checkMod(from,to,n,'globalTo',to.get('s'));
m=n;
m=game.checkMod(from,to,m,'attackFrom',from.get('s'));
m=game.checkMod(from,to,m,'attackTo',to.get('s'));
var equips1=from.get('e'),equips2=to.get('e');
for(i=0;i<equips1.length;i++){
var info=get.info(equips1[i]).distance;
if(!info) continue;
if(info.globalFrom){
m+=info.globalFrom;
n+=info.globalFrom;
}
if(info.attackFrom){
m+=info.attackFrom;
}
}
for(i=0;i<equips2.length;i++){
var info=get.info(equips2[i]).distance;
if(!info) continue;
if(info.globalTo){
m+=info.globalTo;
n+=info.globalTo;
}
if(info.attaclTo){
m+=info.attaclTo;
}
}
if(method=='attack') return m;
return n;
},
attackRange:function(player){
var range=0;
range=game.checkMod(player,player,range,'globalFrom',player.get('s'));
range=game.checkMod(player,player,range,'attackFrom',player.get('s'));
var equips=player.get('e');
for(var i=0;i<equips.length;i++){
var info=get.info(equips[i]).distance;
if(!info) continue;
if(info.globalFrom){
range+=info.globalFrom;
}
if(info.attackFrom){
range+=info.attackFrom;
}
}
return (1-range);
},
globalFrom:function(player){
var range=0;
range=game.checkMod(player,player,range,'globalFrom',player.get('s'));
var equips=player.get('e');
for(var i=0;i<equips.length;i++){
var info=get.info(equips[i]).distance;
if(!info) continue;
if(info.globalFrom){
range+=info.globalFrom;
}
}
return (-range);
},
globalTo:function(player){
var range=0;
range=game.checkMod(player,player,range,'globalTo',player.get('s'));
var equips=player.get('e');
for(var i=0;i<equips.length;i++){
var info=get.info(equips[i]).distance;
if(!info) continue;
if(info.globalTo){
range+=info.globalTo;
}
}
return (range);
},
info:function(item){
if(typeof item=='string'){
return lib.skill[item];
}
if(typeof item=='object'){
return lib.card[item.name];
}
},
select:function(select){
if(typeof select=='number') return [select,select];
if(get.itemtype(select)=='select') return select;
if(typeof select=='function') return get.select(select());
return [1,1]
},
card:function(){
if(_status.event.skill){
var card=get.info(_status.event.skill).viewAs;
if(card) return card;
}
return ui.selected.cards[0];
},
player:function(){
return _status.event.player;
},
players:function(sort,dead){
var players=game.players.slice(0);
if(sort!=false){
if(typeof sort=='function'){
players.sort(sort);
}
else{
if(get.itemtype(sort)!='player') lib.tempSortSeat=_status.event.player;
else lib.tempSortSeat=sort;
players.sort(lib.sort.seat);
delete lib.tempSortSeat;
lib.temp={};
}
}
if(dead) players=players.concat(game.dead);
return players;
},
position:function(card){
if(get.itemtype(card)=='player') return parseInt(card.dataset.position);
if(card.timeout&&card.destiny){
if(card.destiny.classList.contains('equips')) return 'e';
if(card.destiny.classList.contains('judges')) return 'j';
2015-11-24 15:44:21 +00:00
if(card.destiny.classList.contains('handcards')) return 'h';
2015-04-29 03:25:17 +00:00
if(card.destiny.id=='discardPile') return 'd';
if(card.destiny.id=='special') return 's';
return;
}
if(!card.parentNode) return;
if(card.parentNode.classList.contains('equips')) return 'e';
if(card.parentNode.classList.contains('judges')) return 'j';
2015-11-24 15:44:21 +00:00
if(card.parentNode.classList.contains('handcards')) return 'h';
2015-04-29 03:25:17 +00:00
if(card.parentNode.id=='discardPile') return 'd';
if(card.parentNode.id=='special') return 's';
},
translation:function(str,arg){
2015-05-04 14:27:10 +00:00
if(str&&typeof str=='object'&&str.name){
2015-04-29 03:25:17 +00:00
var str2;
if(arg=='viewAs'&&str.viewAs){
str2=get.translation(str.viewAs);
}
else{
str2=get.translation(str.name);
}
if(str2=='杀'){
if(str.nature=='fire'){
str2='火'+str2;
}
else if(str.nature=='thunder'){
str2='雷'+str2;
}
}
if(get.itemtype(str)=='card'&&str.suit&&str.number){
str2+='【'+get.translation(get.suit(str))+get.number(str)+'】'
}
return str2;
}
if(get.itemtype(str)=='cards'||get.itemtype(str)=='players'){
var str2=get.translation(str[0],arg);
for(var i=1;i<str.length;i++){
str2+='、'+get.translation(str[i],arg);
}
return str2;
}
return lib.translate[str]||str;
},
cnNumber:function(num,two){
if(num==Infinity) return '∞';
if(typeof num!='number') return num;
if(num<0||num>99) return num;
if(num<=10){
switch(num){
2015-05-11 11:57:44 +00:00
case 0:return '';
case 1:return '一';
case 2:return two?'二':'两';
case 3:return '三';
case 4:return '四';
case 5:return '五';
case 6:return '六';
case 7:return '七';
case 8:return '八';
case 9:return '九';
case 10:return '十';
2015-04-29 03:25:17 +00:00
}
}
if(num<20){
return '十'+get.cnNumber(num-10,true);
}
var x=Math.floor(num/10);
return get.cnNumber(x,true)+'十'+(num>10*x?get.cnNumber(num-10*x,true):'');
},
selectableButtons:function(sort){
if(!_status.event.player) return[];
var buttons=_status.event.dialog.buttons;
var selectable=[];
for(var i=0;i<buttons.length;i++){
if(buttons[i].classList.contains('selectable')&&
buttons[i].classList.contains('selected')==false){
selectable.push(buttons[i]);
}
}
if(sort){
selectable.sort(sort);
}
return selectable;
},
selectableCards:function(sort){
if(!_status.event.player) return[];
var cards=_status.event.player.get('hej');
var selectable=[];
for(var i=0;i<cards.length;i++){
if(cards[i].classList.contains('selectable')&&
cards[i].classList.contains('selected')==false){
selectable.push(cards[i]);
}
}
if(sort){
selectable.sort(sort);
}
return selectable;
},
skills:function(){
2015-11-30 13:08:29 +00:00
var skills=[];
if(ui.skills){
skills=skills.concat(ui.skills.skills);
}
if(ui.skills2){
skills=skills.concat(ui.skills2.skills);
}
if(ui.skills3){
skills=skills.concat(ui.skills3.skills);
}
return skills;
2015-04-29 03:25:17 +00:00
},
selectableTargets:function(sort){
var selectable=[];
for(var i=0;i<game.players.length;i++){
if(game.players[i].classList.contains('selectable')&&
game.players[i].classList.contains('selected')==false){
selectable.push(game.players[i]);
}
}
2015-05-03 15:17:15 +00:00
selectable.randomSort();
2015-04-29 03:25:17 +00:00
if(sort){
selectable.sort(sort);
}
return selectable;
},
filter:function(filter,i){
if(typeof filter=='function') return filter;
if(i==undefined) i=0;
return function(){
if(filter==arguments[i]) return true;
for(var j in filter){
if(filter.hasOwnProperty(j)){
if(get.itemtype(arguments[i])=='card'){
if(j=='type'){
if(typeof filter[j]=='object'){
if(filter[j].contains(get.type(arguments[i]))==false) return false;
}
else if(typeof filter[j]=='string'){
if(get.type(arguments[i])!=filter[j]) return false;
}
}
else if(j=='subtype'){
if(typeof filter[j]=='object'){
if(filter[j].contains(get.subtype(arguments[i]))==false) return false;
}
else if(typeof filter[j]=='string'){
if(get.subtype(arguments[i])!=filter[j]) return false;
}
}
else if(j=='color'){
if(typeof filter[j]=='object'){
if(filter[j].contains(get.color(arguments[i]))==false) return false;
}
else if(typeof filter[j]=='string'){
if(get.color(arguments[i])!=filter[j]) return false;
}
}
else if(j=='suit'){
if(typeof filter[j]=='object'){
if(filter[j].contains(get.suit(arguments[i]))==false) return false;
}
else if(typeof filter[j]=='string'){
if(get.suit(arguments[i])!=filter[j]) return false;
}
}
else if(j=='number'){
if(typeof filter[j]=='object'){
if(filter[j].contains(get.number(arguments[i]))==false) return false;
}
else if(typeof filter[j]=='string'){
if(get.number(arguments[i])!=filter[j]) return false;
}
}
else if(typeof filter[j]=='object'){
if(filter[j].contains(arguments[i][j])==false) return false;
}
else if(typeof filter[j]=='string'){
if(arguments[i][j]!=filter[j]) return false;
}
}
else{
if(arguments[i][j]!=filter[j]) return false;
}
}
}
return true;
}
},
cardCount:function(card,player){
var num;
if(card==true){
num=0;
var stat=player.getStat('card');
for(var i in stat){
if(typeof stat[i]=='number') num+=stat[i];
}
return num;
}
if(player==undefined) player=_status.event.player;
if(typeof card=='object'){
card=card.name;
}
num=player.getStat('card')[card];
if(num==undefined) return 0;
return num;
},
skillCount:function(skill,player){
if(player==undefined) player=_status.event.player;
var num=player.getStat('skill')[skill];
if(num==undefined) return 0;
return num;
},
owner:function(card){
for(var i=0;i<game.players.length;i++){
2015-12-12 08:37:15 +00:00
if(game.players[i].get('hej').contains(card)||game.players[i].judging[0]==card)
2015-04-29 03:25:17 +00:00
return game.players[i];
}
2015-12-08 00:56:54 +00:00
for(var i=0;i<game.players.length;i++){
if(game.players[i].using&&game.players[i].using.contains(card))
return game.players[i];
}
2015-04-29 03:25:17 +00:00
},
noSelected:function(){
return (ui.selected.buttons.length+ui.selected.cards.length+ui.selected.targets.length==0)
},
population:function(identity){
if(identity==undefined) return game.players.length+game.dead.length;
var i;
var num=0;
for(i=0;i<game.players.length;i++){
if(game.players[i].identity==identity) num++;
}
return num;
},
totalPopulation:function(identity){
if(identity==undefined) return game.players.length+game.dead.length;
var i,players=game.players.concat(game.dead);
var num=0;
for(i=0;i<players.length;i++){
if(players[i].identity==identity) num++;
}
return num;
},
tag:function(item,tag,item2){
if(get.info(item)&&get.info(item).ai&&get.info(item).ai.tag){
var result=get.info(item).ai.tag[tag];
}
if(typeof result=='function') return result(item,item2);
return result;
},
sortCard:function(sort){
var func;
if(sort=='type_sort'){
func=function(card){
2015-05-03 15:17:15 +00:00
if(get.type(card)=='basic') return 2;
2015-06-16 13:24:35 +00:00
if(get.type(card)=='stonecard') return -0.5;
2015-11-21 05:30:26 +00:00
if(get.type(card)=='mengjing') return 0.5;
2015-05-03 15:17:15 +00:00
if(get.type(card)=='stonecharacter') return 1;
2015-05-10 05:34:37 +00:00
if(get.type(card)=='chess') return 1.5;
2015-04-29 03:25:17 +00:00
if(get.type(card)=='trick') return -1;
if(get.type(card)=='delay') return -2;
if(get.type(card)=='equip') return -3;
return -4;
}
}
else if(sort=='suit_sort'){
func=function(card){
if(get.suit(card)=='heart') return 2;
if(get.suit(card)=='diamond') return 1;
if(get.suit(card)=='spade') return -1;
if(get.suit(card)=='club') return -2;
}
}
else if(sort=='number_sort'){
func=function(card){
return get.number(card)-7+0.5;
}
}
return func;
},
difficulty:function(){
switch(get.config('difficulty')){
case 'easy':return 1;
case 'normal':return 2;
case 'hard':return 3;
default: return 1;
}
},
cardPile:function(name){
2015-08-15 09:10:06 +00:00
var card;
2015-04-29 03:25:17 +00:00
for(var i=0;i<ui.cardPile.childNodes.length;i++){
2015-08-15 09:10:06 +00:00
card=ui.cardPile.childNodes[i];
if(typeof name=='string'){
if(card.name==name){
return card;
}
}
else if(typeof name=='function'){
if(name(card)){
return card;
}
2015-04-29 03:25:17 +00:00
}
}
for(var i=0;i<ui.discardPile.childNodes.length;i++){
2015-08-15 09:10:06 +00:00
card=ui.discardPile.childNodes[i];
if(typeof name=='string'){
if(card.name==name){
return card;
}
}
else if(typeof name=='function'){
if(name(card)){
return card;
}
2015-04-29 03:25:17 +00:00
}
}
2015-08-15 09:10:06 +00:00
return null;
2015-04-29 03:25:17 +00:00
},
aiStrategy:function(){
switch(get.config('ai_strategy')){
case 'ai_strategy_1':return 1;
case 'ai_strategy_2':return 2;
case 'ai_strategy_3':return 3;
case 'ai_strategy_4':return 4;
case 'ai_strategy_5':return 5;
case 'ai_strategy_6':return 6;
default: return 1;
}
},
skillintro:function(name,learn,learn2){
var str='';
2015-10-31 10:14:14 +00:00
var infoitem=lib.character[name];
2015-10-30 15:32:48 +00:00
if(!infoitem){
for(var itemx in lib.characterPack){
2015-10-31 10:14:14 +00:00
if(lib.characterPack[itemx][name]){
infoitem=lib.characterPack[itemx][name];break;
2015-10-30 15:32:48 +00:00
}
}
}
var skills=infoitem[3];
2015-04-29 03:25:17 +00:00
var opacity;
for(var i=0;i<skills.length;i++){
if(lib.translate[skills[i]]&&lib.translate[skills[i]+'_info']&&lib.skill[skills[i]]){
if(learn&&lib.skill[skills[i]].unique&&(learn2||!lib.skill[skills[i]].gainable)){
opacity='opacity:0.5';
}
else{
opacity='';
}
str+='<div class="skill" style="'+opacity+
'">【'+get.translation(skills[i]).slice(0,2)+'】</div><div style="'+opacity+'">'+
lib.translate[skills[i]+'_info']+'</div><div style="display:block;height:10px"></div>';
}
}
return str;
},
intro:function(name){
var info=lib.character[name];
var str='性别:'+get.translation(info[0])+'<br/>';
str+='势力:'+get.translation(info[1])+'<br/>';
str+='体力:'+get.translation(info[2])+'<br/>';
str+='技能:';
if(info[3].length){
str+=get.translation(info[3][0]);
for(var i=1;i<info[3].length;i++){
str+='、'+get.translation(info[3][i]);
}
}
return str;
},
storageintro:function(type,content,player,dialog){
switch(type){
case 'mark':{
if(content>0){
return '共有'+content+'个标记';
}
2015-05-11 11:57:44 +00:00
return false;
2015-04-29 03:25:17 +00:00
}
case 'turn':{
if(content>0){
return '还剩'+content+'个回合';
}
2015-05-11 11:57:44 +00:00
return false;
2015-04-29 03:25:17 +00:00
}
case 'time':{
if(content>0){
return '还剩'+content+'次';
}
2015-05-11 11:57:44 +00:00
return false;
2015-04-29 03:25:17 +00:00
}
case 'limited':{
if(content){
return '已发动';
}
2015-05-11 11:57:44 +00:00
return '未发动';
2015-04-29 03:25:17 +00:00
}
case 'cardCount':{
if(typeof content=='object'&&typeof content.length=='number'){
return '共有'+get.cnNumber(content.length)+'张牌';
}
2015-05-11 11:57:44 +00:00
return false;
2015-04-29 03:25:17 +00:00
}
case 'card':case 'cards':{
if(get.itemtype(content)=='card'){
content=[content];
}
if(dialog&&get.itemtype(content)=='cards'){
if(content.length>6&&!dialog._hovercustomed){
dialog.addSmall(content);
}
else{
dialog.add(content);
}
}
else{
if(content&&content.length){
return get.translation(content);
}
}
2015-05-11 11:57:44 +00:00
return false;
2015-04-29 03:25:17 +00:00
}
case 'player':case 'players':{
if(get.itemtype(content)=='player'){
content=[content];
}
if(dialog&&get.itemtype(content)=='players'){
if(content.length>6&&!dialog._hovercustomed){
dialog.addSmall(content);
}
else{
dialog.add(content);
}
return false;
}
else{
if(content&&content.length){
return get.translation(content);
}
2015-05-11 11:57:44 +00:00
return false;
2015-04-29 03:25:17 +00:00
}
2015-07-09 05:21:22 +00:00
break;
2015-04-29 03:25:17 +00:00
}
default:{
if(typeof type=='string'){
return type.replace(/#/g,content);
}
else if(typeof type=='function'){
return type(content,player);
}
return false;
}
}
},
nodeintro:function(node,simple){
var uiintro=ui.create.dialog('hidden');
if(node.classList.contains('player')&&!node.name){
return uiintro;
}
var i,translation,intro,str;
if(node.classList.contains('player')){
var capt=get.translation(node.name);
2015-11-09 03:15:16 +00:00
if(lib.character[node.name]&&lib.character[node.name][1]){
2015-04-29 03:25:17 +00:00
capt+='&nbsp;&nbsp;'+lib.translate[lib.character[node.name][1]];
}
uiintro.add(capt);
var skills=node.skills;
var skills2=game.filterSkills(node.skills,node);
for(i=0;i<skills.length;i++){
2015-09-22 03:53:35 +00:00
if(lib.skill[skills[i]]&&lib.skill[skills[i]].nopop) continue;
2015-04-29 03:25:17 +00:00
if(lib.translate[skills[i]+'_info']){
translation=get.translation(skills[i]).slice(0,2);
if(!skills2.contains(skills[i])){
uiintro.add('<div style="opacity:0.5"><div class="skill">【'+translation+'】</div><div>'+lib.translate[skills[i]+'_info']+'</div></div>');
}
else{
uiintro.add('<div><div class="skill">【'+translation+'】</div><div>'+lib.translate[skills[i]+'_info']+'</div></div>');
}
}
}
var forbidden=node.forbiddenSkills;
for(i=0;i<forbidden.length;i++){
if(lib.translate[forbidden[i]+'_info']){
translation=get.translation(forbidden[i]).slice(0,2);
uiintro.add('<div><div class="skill">【'+translation+'】</div><div>'+'已禁用'+'</div></div>');
}
}
2015-11-28 07:19:04 +00:00
if(!simple||lib.config.touchscreen){
2015-04-29 03:25:17 +00:00
var storage=node.storage;
for(i in storage){
if(get.info(i)&&get.info(i).intro){
intro=get.info(i).intro;
if(node.get('s').concat(lib.skill.global).contains(i)==false&&!intro.show) continue;
var name=intro.name?intro.name:get.translation(i);
if(typeof name=='function'){
name=name(storage[i],node);
}
translation='<div><div class="skill">『'+name[0]+name[1]+'』</div><div>';
var stint=get.storageintro(intro.content,storage[i],node);
if(stint){
translation+=stint+'</div></div>';
uiintro.add(translation);
}
}
}
2015-11-21 13:23:23 +00:00
var js=node.get('j');
for(var i=0;i<js.length;i++){
var name=lib.translate[js[i].viewAs||js[i].name];
translation='<div><div class="skill">『'+name[0]+name[1]+'』</div><div>'+
lib.translate[(js[i].viewAs||js[i].name)+'_info']+'</div></div>';
uiintro.add(translation);
}
2015-11-21 05:30:26 +00:00
if(false){
uiintro.add(ui.create.div('.placeholder'));
var table,tr,td;
table=document.createElement('table');
tr=document.createElement('tr');
table.appendChild(tr);
td=document.createElement('td');
td.innerHTML='攻击范围';
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML='进攻距离';
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML='防御距离';
tr.appendChild(td);
2015-04-29 03:25:17 +00:00
2015-11-21 05:30:26 +00:00
tr=document.createElement('tr');
table.appendChild(tr);
td=document.createElement('td');
td.innerHTML=get.attackRange(node);
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML=get.globalFrom(node);
tr.appendChild(td);
td=document.createElement('td');
td.innerHTML=get.globalTo(node);
tr.appendChild(td);
2015-04-29 03:25:17 +00:00
2015-11-21 05:30:26 +00:00
uiintro.content.appendChild(table);
}
2015-11-28 07:19:04 +00:00
if(lib.config.change_skin&&(
!node.classList.contains('unseen')||!node.classList.contains('unseen2')
)){
var num=1;
var introadded=false;
var loadImage=function(avatar2){
var img=new Image();
img.onload=function(){
num++;
loadImage(avatar2);
}
img.onerror=function(){
num--;
if(num){
if(!introadded){
introadded=true;
2015-11-29 11:46:51 +00:00
uiintro.add('<div class="text center">更改皮肤</div>');
2015-11-28 07:19:04 +00:00
}
var buttons=ui.create.div('.buttons.smallzoom');
for(var i=0;i<=num;i++){
var button=ui.create.div('.button.character',buttons,function(){
if(this._link){
if(avatar2){
lib.config.skin[node.name2]=this._link;
node.node.avatar2.style.backgroundImage=this.style.backgroundImage;
}
else{
lib.config.skin[node.name]=this._link;
node.node.avatar.style.backgroundImage=this.style.backgroundImage;
}
game.saveConfig('skin',lib.config.skin);
}
else{
if(avatar2){
delete lib.config.skin[node.name2];
node.node.avatar2.setBackground(node.name2,'character');
}
else{
delete lib.config.skin[node.name];
node.node.avatar.setBackground(node.name,'character');
}
game.saveConfig('skin',lib.config.skin);
}
});
button._link=i;
if(i){
button.style.backgroundImage='url("image/skin/'+(avatar2?node.name2:node.name)+'/'+i+'.jpg")';
}
else{
button.style.backgroundImage='url("image/character/'+(avatar2?node.name2:node.name)+'.jpg")';
}
}
uiintro.add(buttons);
}
if(!avatar2){
if(!node.classList.contains('unseen2')&&node.name2){
num=1;
loadImage(true);
}
}
}
img.src='image/skin/'+(avatar2?node.name2:node.name)+'/'+num+'.jpg';
}
if(!node.classList.contains('unseen')){
loadImage();
}
}
2015-04-29 03:25:17 +00:00
}
uiintro.add(ui.create.div('.placeholder.slim'));
}
else if(node.classList.contains('mark')&&node.info&&
node.parentNode&&node.parentNode.parentNode&&node.parentNode.parentNode.classList.contains('player')){
var info=node.info;
var player=node.parentNode.parentNode;
if(info.name){
if(typeof info.name=='function'){
var named=info.name(player.storage[node.skill],player);
if(named){
uiintro.add(named);
}
}
else{
uiintro.add(info.name);
}
}
else if(info.name!==false){
uiintro.add(get.translation(node.skill));
}
if(typeof info.mark=='function'){
var stint=info.mark(uiintro,player.storage[node.skill],player);
if(stint){
2015-09-22 03:53:35 +00:00
if(stint.length<=100){
2015-04-29 03:25:17 +00:00
uiintro.add('<div class="text center">'+stint+'</div>');
}
else{
uiintro.add('<div class="text">'+stint+'</div>');
}
}
}
else{
var stint=get.storageintro(info.content,player.storage[node.skill],player,uiintro);
if(stint){
2015-06-16 13:24:35 +00:00
if(stint[0]=='$'){
uiintro.add('<div class="caption">'+stint.slice(1)+'</div>');
}
2015-09-22 03:53:35 +00:00
else if(stint.length<=100){
2015-04-29 03:25:17 +00:00
uiintro.add('<div class="text center">'+stint+'</div>');
}
else{
uiintro.add('<div class="text">'+stint+'</div>');
}
}
}
uiintro.add(ui.create.div('.placeholder.slim'));
}
else if(node.classList.contains('card')){
var name=node.name;
if(get.position(node)=='j'&&node.viewAs&&node.viewAs!=name){
uiintro.add(get.translation(node.viewAs)+''+get.translation(node)+'');
name=node.viewAs;
}
else{
uiintro.add(get.translation(node));
}
if(node.name=='muniu'&&get.position(node)=='e'){
var num=0;
if(node.cards){
num=node.cards.length;
}
if(get.owner(node)==game.me&&num){
uiintro.add(node.cards,true,num>4);
}
else{
uiintro.add('<div class="text center">'+'共有'+get.cnNumber(num)+'张牌'+'</div>');
}
}
2015-09-03 03:49:14 +00:00
else if(node.name=='lianyaohu'&&get.position(node)=='e'){
var num=0;
if(node.storage.shouna){
num=node.storage.shouna.length;
}
if(num){
uiintro.add(node.storage.shouna,true,num>4);
}
else{
uiintro.add('<div class="text center">炼妖壶内没有牌</div>');
}
}
else if(lib.translate[name+'_info']){
2015-11-30 13:08:29 +00:00
if(get.subtype(node)=='equip1'){
var added=false;
if(lib.card[node.name]&&lib.card[node.name].distance){
var dist=lib.card[node.name].distance;
if(dist.attackFrom){
added=true;
uiintro.add('<div class="text center">攻击范围:'+(-dist.attackFrom+1)+'</div>');
}
}
if(!added){
uiintro.add('<div class="text center">攻击范围1</div>');
}
}
2015-09-22 03:53:35 +00:00
if(lib.translate[name+'_info'].length<=100){
uiintro.add('<div class="text center">'+lib.translate[name+'_info']+'</div>');
}
else{
uiintro.add('<div class="text">'+lib.translate[name+'_info']+'</div>');
}
2015-04-29 03:25:17 +00:00
}
uiintro.add(ui.create.div('.placeholder.slim'));
}
else if(node.classList.contains('character')){
var character=node.link;
uiintro.add(get.translation(character));
2015-10-30 15:32:48 +00:00
var infoitem=lib.character[character];
if(!infoitem){
for(var itemx in lib.characterPack){
if(lib.characterPack[itemx][character]){
infoitem=lib.characterPack[itemx][character];break;
}
}
}
var skills=infoitem[3];
2015-04-29 03:25:17 +00:00
for(i=0;i<skills.length;i++){
if(lib.translate[skills[i]+'_info']){
translation=get.translation(skills[i])[0]+get.translation(skills[i])[1];
uiintro.add('<div><div class="skill">【'+translation+'】</div><div>'+lib.translate[skills[i]+'_info']+'</div></div>');
}
}
uiintro.add(ui.create.div('.placeholder.slim'));
}
return uiintro;
},
groups:function(){
return ['wei','shu','wu','qun'];
},
types:function(){
var types=[];
for(var i in lib.card){
if(lib.card[i].mode&&lib.card[i].mode.contains(lib.config.mode)==false) continue;
if(lib.card[i].forbid&&lib.card[i].forbid.contains(lib.config.mode)) continue;
if(lib.card[i].type){
if(lib.card[i].type=='delay') types.add('trick');
else types.add(lib.card[i].type);
}
}
return types;
},
links:function(buttons){
var links=[];
for(var i=0;i<buttons.length;i++){
if(buttons[i].link!=undefined) links.push(buttons[i].link);
}
return links;
}
};
var ai={
basic:{
chooseButton:function(check){
var event=_status.event;
var i,j,range,buttons,buttons2;
var ok=false,forced=event.forced;
2015-05-04 03:17:03 +00:00
var iwhile=100;
while(iwhile--){
2015-04-29 03:25:17 +00:00
range=get.select(event.selectButton);
if(range[1]==-1){
j=0;
for(i=0;i<ui.selected.buttons.length;i++){
j+=check(ui.selected.buttons[i]);
}
return (j>0);
}
lib.temp={};
buttons=get.selectableButtons();
if(buttons.length==0){
return ok;
}
2015-12-08 13:54:44 +00:00
buttons2=buttons.slice(0);
var ix=0;
var checkix=check(buttons[0],buttons2);
for(i=1;i<buttons.length;i++){
var checkixtmp=check(buttons[i],buttons2);
if(checkixtmp>checkix){
ix=i;
checkix=checkixtmp;
}
}
// buttons.sort(function(a,b){
// return check(b,buttons2)-check(a,buttons2);
// });
if(check(buttons[ix])<=0){
2015-04-29 03:25:17 +00:00
if(!forced||ok){
return ok;
}
}
2015-12-08 13:54:44 +00:00
buttons[ix].classList.add('selected');
ui.selected.buttons.add(buttons[ix]);
2015-04-29 03:25:17 +00:00
game.check();
if(ui.selected.buttons.length>=range[0]){
ok=true;
}
if(ui.selected.buttons.length==range[1]){
return true;
}
}
},
chooseCard:function(check){
var event=_status.event;
if(event.filterCard==undefined) return (check()>0);
var i,j,range,cards,cards2,skills,check,effect;
var ok=false,forced=event.forced;
2015-05-04 03:17:03 +00:00
var iwhile=100;
while(iwhile--){
2015-04-29 03:25:17 +00:00
range=get.select(event.selectCard);
if(ui.selected.cards.length>=range[0]){
ok=true;
}
if(range[1]==-1){
if(ui.selected.cards.length==0) return true;
j=0;
for(i=0;i<ui.selected.cards.length;i++){
effect=check(ui.selected.cards[i]);
if(effect<0) j-=Math.sqrt(-effect);
else j+=Math.sqrt(effect);
}
return (j>0);
}
lib.temp={};
2015-12-04 10:18:00 +00:00
cards=get.selectableCards();
if(!_status.event.player._noSkill){
cards=cards.concat(get.skills());
}
2015-04-29 03:25:17 +00:00
if(cards.length==0){
return ok;
}
2015-12-08 13:54:44 +00:00
cards2=cards.slice(0);
// cards.sort(function(a,b){
// return (check(b,cards2)-check(a,cards2));
// });
var ix=0;
var checkix=check(cards[0],cards2);
for(i=1;i<cards.length;i++){
var checkixtmp=check(cards[i],cards2);
if(checkixtmp>checkix){
ix=i;
checkix=checkixtmp;
}
}
if(check(cards[ix])<=0){
2015-04-29 03:25:17 +00:00
if(!forced||ok){
return ok;
}
}
2015-12-08 13:54:44 +00:00
if(typeof cards[ix]=='string'){
ui.click.skill(cards[ix]);
2015-04-29 03:25:17 +00:00
var info=get.info(event.skill);
if(info.filterCard){
check=info.check||ai.get.unuseful2;
return (ai.basic.chooseCard(check));
}
else{
return true;
}
}
else{
2015-12-08 13:54:44 +00:00
cards[ix].classList.add('selected');
ui.selected.cards.add(cards[ix]);
2015-04-29 03:25:17 +00:00
game.check();
2015-12-08 13:54:44 +00:00
if(ui.selected.cards.length>=range[ix]){
2015-04-29 03:25:17 +00:00
ok=true;
}
if(ui.selected.cards.length==range[1]){
return true;
}
}
}
},
chooseTarget:function(check){
var event=_status.event;
if(event.filterTarget==undefined) return (check()>0);
var i,j,range,targets,targets2,effect;
var ok=false,forced=event.forced;
2015-05-04 03:17:03 +00:00
var iwhile=100;
while(iwhile--){
2015-04-29 03:25:17 +00:00
range=get.select(event.selectTarget);
if(range[1]==-1){
j=0;
for(i=0;i<ui.selected.targets.length;i++){
effect=check(ui.selected.targets[i]);
if(effect<0) j-=Math.sqrt(-effect);
else j+=Math.sqrt(effect);
}
return (j>0);
}
else if(range[1]==0){
return check()>0
}
lib.temp={};
targets=get.selectableTargets();
if(targets.length==0){
return ok;
}
2015-12-08 13:54:44 +00:00
targets2=targets.slice(0);
// targets.sort(function(a,b){
// return check(b)-check(a);
// });
var ix=0;
var checkix=check(targets[0],targets2);
for(i=1;i<targets.length;i++){
var checkixtmp=check(targets[i],targets2);
if(checkixtmp>checkix){
ix=i;
checkix=checkixtmp;
}
}
if(check(targets[ix])<=0){
2015-04-29 03:25:17 +00:00
if(!forced||ok){
return ok;
}
}
2015-12-08 13:54:44 +00:00
targets[ix].classList.add('selected');
ui.selected.targets.add(targets[ix]);
2015-04-29 03:25:17 +00:00
game.check();
if(ui.selected.targets.length>=range[0]){
ok=true;
}
if(ui.selected.targets.length==range[1]){
return true;
}
}
}
},
get:{
useful:function(card){
if(get.position(card)=='j') return -1;
if(get.position(card)=='e') return ai.get.equipValue(card);
if(lib.temp[card.name]==undefined) lib.temp[card.name]=[card];
else lib.temp[card.name].add(card);
var i=lib.temp[card.name].find(card);
var aii=get.info(card).ai;
var useful;
if(aii&&aii.useful) useful=aii.useful;
else if(aii&&aii.basic) useful=aii.basic.useful;
if(useful==undefined) return -1;
if(typeof useful=='function'){
return useful(card,i);
}
if(typeof useful=='number') return useful;
if(i<useful.length){
return useful[i];
}
return useful[useful.length-1];
},
unuseful:function(card){
return -ai.get.useful(card);
},
unuseful2:function(card){
return 10-ai.get.useful(card);
},
value:function(card,player,method){
var aii=get.info(card).ai;
var value;
if(aii&&aii.value) value=aii.value;
else if(aii&&aii.basic) value=aii.basic.value;
if(value==undefined) return 0;
if(player==undefined||get.itemtype(player)!='player') player=_status.event.player;
if(typeof value=='function') return value(card,player);
if(typeof value=='number') return value;
if(get.objtype(value)=='array'){
if(method=='raw') return value[0];
var num=0,i;
var cards=player.get('h');
for(i=0;i<cards.length;i++){
if(cards[i].name==card.name&&
cards[i]!=card&&
cards[i].classList.contains('selected')==false) num++;
}
if(num<value.length) return value[num];
return value[value.length-1];
}
return 0;
},
equipValue:function(card,player){
if(player==undefined||get.itemtype(player)!='player') player=get.owner(card);
if(player==undefined||get.itemtype(player)!='player') player=_status.event.player;
var info=get.info(card);
if(!info.ai) return 0;
var value=info.ai.equipValue;
if(value==undefined){
if(info.ai.basic&&info.ai.basic.equipValue!=undefined){
value=info.ai.basic.equipValue;
}
else return 0;
}
if(typeof value=='number') return value;
if(typeof value=='function') return value(card,player);
return 0;
},
disvalue:function(card,player){
return -ai.get.value(card,player);
},
2015-05-09 02:56:55 +00:00
skillthreaten:function(skill,player,target){
if(!lib.skill[skill]) return 1;
if(!lib.skill[skill].ai) return 1;
var threaten=lib.skill[skill].ai.threaten;
if(typeof threaten=='number') return threaten;
if(typeof threaten=='function'){
player=player||_status.event.player;
target=target||player;
return threaten(player,target);
}
return 1;
},
2015-04-29 03:25:17 +00:00
order:function(item){
var aii=get.info(item).ai;
var order;
if(aii&&aii.order) order=aii.order;
else if(aii&&aii.basic) order=aii.basic.order;
if(order==undefined) return -1;
if(typeof(order)=='function'){
return order(item,_status.event.player);
}
return order;
},
result:function(item){
var result;
if(get.info(item).ai) result=get.info(item).ai.result;
if(result==undefined) return {};
if(typeof(result)=='function') return result(item);
return result;
},
effect:function(target,card,player,player2){
var event=_status.event;
if(player==undefined) player=_status.event.player;
if(typeof card!='string'&&(typeof card!='object'||!card.name)){
if(event.skill&&get.info(event.skill).viewAs==undefined) card=_status.event.skill;
else card=get.card();
}
var result=ai.get.result(card);
var result1=result.player,result2=result.target;
if(typeof result1=='function') result1=result1(player,target,card);
if(typeof result2=='function') result2=result2(player,target,card);
if(typeof result1!='number') result1=0;
if(typeof result2!='number') result2=0;
var temp1,temp2,temp3,temp01=0,temp02=0,threaten=1;
var skills1=player.get('s').concat(lib.skill.global);
game.expandSkills(skills1);
var zerotarget=false,zeroplayer=false;
for(var i=0;i<skills1.length;i++){
temp1=get.info(skills1[i]).ai;
if(temp1&&typeof temp1.effect=='object'&&typeof temp1.effect.player=='function'){
temp1=temp1.effect.player(card,player,target,result1);
}
else temp1=undefined;
if(typeof temp1=='object'){
if(temp1.length==2||temp1.length==4){
result1*=temp1[0];
temp01+=temp1[1];
}
if(temp1.length==4){
result2*=temp1[2];
temp02+=temp1[3];
}
}
else if(typeof temp1=='number'){
result1*=temp1;
}
else if(temp1=='zeroplayer'){
zeroplayer=true;
}
else if(temp1=='zerotarget'){
zerotarget=true;
}
2015-11-06 10:05:08 +00:00
else if(temp1=='zeroplayertarget'){
zeroplayer=true;
zerotarget=true;
}
2015-04-29 03:25:17 +00:00
}
if(target){
var skills2=target.get('s').concat(lib.skill.global);
game.expandSkills(skills2);
for(var i=0;i<skills2.length;i++){
temp2=get.info(skills2[i]).ai;
if(temp2&&temp2.threaten) temp3=temp2.threaten;
else temp3=undefined;
if(temp2&&typeof temp2.effect=='function'){
temp2=temp2.effect(card,player,target,result2);
}
else if(temp2&&typeof temp2.effect=='object'&&typeof temp2.effect.target=='function'){
temp2=temp2.effect.target(card,player,target,result2);
}
else temp2=undefined;
if(typeof temp2=='object'){
if(temp2.length==2||temp2.length==4){
result2*=temp2[0];
temp02+=temp2[1];
}
if(temp2.length==4){
result1*=temp2[2];
temp01+=temp2[3];
}
}
else if(typeof temp2=='number'){
result2*=temp2;
}
else if(temp2=='zeroplayer'){
zeroplayer=true;
}
else if(temp2=='zerotarget'){
zerotarget=true;
}
2015-11-06 10:05:08 +00:00
else if(temp2=='zeroplayertarget'){
zeroplayer=true;
zerotarget=true;
}
2015-04-29 03:25:17 +00:00
if(typeof temp3=='function'&&temp3(player,target)!=undefined){
threaten*=temp3(player,target);
}
else if(typeof temp3=='object'){
if(typeof temp3.target=='number'){
threaten*=temp3;
}
else if(typeof temp3.target=='function'&&temp3(player,target)!=undefined){
threaten*=temp3(player,target);
}
}
else if(typeof temp3=='number'){
threaten*=temp3;
}
}
result2+=temp02;
result1+=temp01;
if(ai.get.attitude(player,target)<0){
result2*=threaten;
}
else{
result2*=Math.sqrt(threaten);
}
if(target.hp<=1) result2*=2;
if(target.hp==2) result2*=1.1;
if(target.num('h')==0){
result2*=1.1;
if(get.tag(card,'respondSha')||get.tag(card,'respondShan')) result2*=1.4;
}
if(target.num('h')==1) result2*=1.05;
if(target.num('h')==2) result2*=1.02;
if(target.num('h')>3) result2*=0.9;
if(target.hp==4) result2*=0.9;
if(target.hp==5) result2*=0.8;
if(target.hp>5) result2*=0.6;
}
else{
result2+=temp02;
result1+=temp01;
}
if(zeroplayer) result1=0;
if(zerotarget) result2=0;
if(player2){
return (result1*ai.get.attitude(player2,player)+(target?result2*ai.get.attitude(player2,target):0));
}
return (result1*ai.get.attitude(player,player)+(target?result2*ai.get.attitude(player,target):0));
},
damageEffect:function(target,player,viewer,nature){
if(!player){
player=target;
}
if(!viewer){
viewer=target;
}
var name='damage';
if(nature=='fire'){
name='firedamage';
}
else if(nature=='thunder'){
name='thunderdamage';
}
return ai.get.effect(target,{name:name},player,viewer);
},
recoverEffect:function(target,player,viewer){
if(target.hp==target.maxHp) return 0;
if(!player){
player=target;
}
if(!viewer){
viewer=target;
}
return ai.get.effect(target,{name:'recover'},player,viewer);
},
buttonValue:function(button){
var card=button.link;
var player=get.owner(card);
if(!player) player=_status.event.player;
if(player.get('j').contains(card)){
var efff=ai.get.effect(player,card,player,player);
if(efff>0) return 0.5;
if(efff==0) return 0;
return -1.5;
}
if(player.get('e').contains(card)){
return ai.get.equipValue(card)/3;
}
2015-05-12 09:51:40 +00:00
var nh=player.num('h');
switch(nh){
case 1:return 2;
case 2:return 1.6;
case 3:return 1;
case 4:return 0.8;
case 5:return 0.6;
default:return 0.4;
}
2015-04-29 03:25:17 +00:00
},
attitude2:function(to){
return ai.get.attitude(_status.event.player,to);
},
players:function(range,sort){
var players=[];
if(range.max==undefined) range.max=Infinity;
if(range.min==undefined) range.min=-Infinity;
if(range.player==undefined) range.player=_status.event.player;
for(var i=0;i<game.players.length;i++){
if(ai.get.attitude(range.player,game.players[i])<=range.max&&
ai.get.attitude(range.player,game.players[i])>=range.min){
players.push(game.players[i]);
}
}
if(sort) players.sort(sort);
return players;
}
},
};
2015-05-09 02:56:55 +00:00
lib.init.init();
2015-11-18 03:39:14 +00:00
HTMLDivElement.prototype.animate=function(name,time){
2015-04-29 03:25:17 +00:00
this.classList.add(name);
var that=this;
setTimeout(function(){
that.classList.remove(name);
2015-11-18 03:39:14 +00:00
},time||1000);
2015-04-29 03:25:17 +00:00
return this;
};
HTMLDivElement.prototype.hide=function(){
this.classList.add('hidden');
return this;
};
HTMLDivElement.prototype.unfocus=function(){
this.classList.add('transparent');
return this;
};
HTMLDivElement.prototype.refocus=function(){
this.classList.remove('transparent');
return this;
};
HTMLDivElement.prototype.show=function(){
this.classList.remove('hidden');
return this;
};
HTMLDivElement.prototype.delete=function(time){
2015-12-09 05:52:03 +00:00
if(this.timeout){
clearTimeout(this.timeout);
delete this.timeout;
}
2015-12-08 13:54:44 +00:00
if(!this._listeningEnd||this._transitionEnded){
2015-12-09 05:52:03 +00:00
if(typeof time!='number') time=500;
2015-12-08 13:54:44 +00:00
this.classList.add('removing');
var that=this;
this.timeout=setTimeout(function(){
that.remove();
that.classList.remove('removing');
},time);
}
else{
this._onEndDelete=true;
}
2015-04-29 03:25:17 +00:00
return this;
};
HTMLDivElement.prototype.goto=function(position,time){
2015-12-09 05:52:03 +00:00
if(this.timeout){
clearTimeout(this.timeout);
delete this.timeout;
}
if(typeof time!='number') time=500;
2015-11-23 10:59:44 +00:00
this.classList.add('removing');
2015-04-29 03:25:17 +00:00
var that=this;
this.timeout=setTimeout(function(){
position.appendChild(that);
that.classList.remove('removing');
delete that.destiny;
},time);
this.destiny=position;
return this;
};
HTMLDivElement.prototype.fix=function(){
clearTimeout(this.timeout);
2015-11-24 15:44:21 +00:00
delete this.timeout;
2015-04-29 03:25:17 +00:00
delete this.destiny;
this.classList.remove('removing');
return this;
};
2015-10-20 17:44:00 +00:00
HTMLDivElement.prototype.setBackground=function(name,type,ext,subfolder){
2015-04-29 03:25:17 +00:00
var src;
2015-10-13 11:15:02 +00:00
ext=ext||'.jpg';
2015-10-20 17:44:00 +00:00
subfolder=subfolder||'default'
2015-04-29 03:25:17 +00:00
if(type){
2015-12-06 15:23:47 +00:00
if(type=='character'&&lib.customCharacters.contains(name)){
src="";
var node=this;
game.getDB('image','character:'+name,function(src){
node.style.backgroundImage="url('"+src+"')";
});
}
else if(type=='character'&&lib.config.skin[name]){
2015-11-25 10:25:18 +00:00
src='image/skin/'+name+'/'+lib.config.skin[name]+ext;
2015-11-23 10:59:44 +00:00
}
else{
2015-11-25 10:25:18 +00:00
if(type=='character'){
src='image/character/'+name+ext;
}
else{
src='image/'+type+'/'+subfolder+'/'+name+ext;
}
2015-11-23 10:59:44 +00:00
}
2015-04-29 03:25:17 +00:00
}
else{
2015-10-13 11:15:02 +00:00
src='image/'+name+ext;
2015-04-29 03:25:17 +00:00
}
this.style.backgroundImage="url('"+src+"')";
this.style.backgroundSize="cover";
return this;
};
HTMLDivElement.prototype.listen=function(func){
this.addEventListener(lib.config.touchscreen?'touchend':'click',function(e){
if(_status.dragged) return;
func.call(this,e);
})
return this;
};
HTMLDivElement.prototype.setPosition=function(){
var position;
if(arguments.length==4){
position=[];
for(var i=0;i<arguments.length;i++) position.push(arguments[i]);
}
else if(arguments.length==1&&get.objtype(arguments[0])=='array'&&arguments[0].length==4){
position=arguments[0];
}
else{
return this;
}
var top='calc('+position[0]+'% ';
if(position[1]>0) top+='+ '+position[1]+'px)';
else top+='- '+Math.abs(position[1])+'px)';
var left='calc('+position[2]+'% ';
if(position[3]>0) left+='+ '+position[3]+'px)';
else left+='- '+Math.abs(position[3])+'px)';
this.style.top=top;
this.style.left=left;
return this;
};
HTMLDivElement.prototype.css=function(style){
for(var i in style){
if(i=='innerHTML'){
this.innerHTML=style[i];
}
else{
this.style[i]=style[i];
}
}
return this;
};
HTMLDivElement.prototype.transform=function(transform){
var str='';
for(var i in transform){
switch(i){
case 'scale':str+='scale('+transform[i]+') ';break;
case 'rotate':str+='rotate('+transform[i]+'deg) ';break;
}
}
if(typeof transform=='object'){
if(transform.left&&transform.top){
str+='translate('+parseInt(transform.left)+'px,'+parseInt(transform.top)+'px) ';
}
else if(transform.left){
str+='translate('+parseInt(transform.left)+'px) ';
}
else if(transform.top){
str+='translate(0,'+parseInt(transform.top)+'px) ';
}
}
2015-11-05 02:34:35 +00:00
this.style.transform=str;
2015-04-29 03:25:17 +00:00
return this;
};
HTMLTableElement.prototype.get=function(row,col){
if(row<this.childNodes.length){
return this.childNodes[row].childNodes[col];
}
};
Array.prototype.find=function(item){
return this.indexOf(item);
};
Array.prototype.contains=function(item){
return this.indexOf(item)!=-1;
};
Array.prototype.add=function(){
for(var i=0;i<arguments.length;i++){
if(this.contains(arguments[i])){
return false;
}
this.push(arguments[i]);
}
return this;
};
Array.prototype.remove=function(item){
if(get.objtype(item)=='array'){
for(var i=0;i<item.length;i++) this.remove(item[i]);
return;
}
var pos=this.find(item);
if(pos==-1){
return false;
}
this.splice(pos,1);
return this;
};
Array.prototype.randomGet=function(){
var arr=this.slice(0);
for(var i=0;i<arguments.length;i++) arr.remove(arguments[i]);
return arr[Math.floor(Math.random()*arr.length)];
};
Array.prototype.randomRemove=function(){
var num=Math.floor(Math.random()*this.length);
return this.splice(num,1)[0];
};
2015-05-03 15:17:15 +00:00
Array.prototype.randomSort=function(){
var list=[];
while(this.length){
list.push(this.randomRemove());
}
for(var i=0;i<list.length;i++){
this.push(list[i]);
}
return this;
};
2015-04-29 03:25:17 +00:00
Array.prototype.randomGets=function(num){
2015-09-03 03:49:14 +00:00
if(num>this.length){
num=this.length;
}
2015-04-29 03:25:17 +00:00
var arr=this.slice(0);
var list=[];
for(var i=0;i<num;i++){
list.push(arr.splice(Math.floor(Math.random()*arr.length),1)[0]);
}
return list;
};
window.cheat={
i:function(){
window.game=game;
window.ui=ui;
window.get=get;
window.ai=ai;
window.lib=lib;
window._status=_status;
},
2015-12-11 05:07:11 +00:00
u:function(){
var card={name:'sha'},source=game.me.next;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='player'){
source=arguments[i];
}
else if(typeof arguments[i]=='object'){
card=arguments[i];
}
else if(typeof arguments[i]=='string'){
card={name:arguments[i]}
}
}
source.useCard(card,game.me);
},
2015-11-21 05:30:26 +00:00
rank:function(){
var list=lib.rank.s.concat(lib.rank.ap).concat(lib.rank.a).concat(lib.rank.am).
concat(lib.rank.bp).concat(lib.rank.b).concat(lib.rank.bm).concat(lib.rank.c).concat(lib.rank.d);
for(var i in lib.character){
if(i!='zuoci'&&!list.contains(i)) console.log(i);
}
},
2015-06-12 07:15:23 +00:00
h:function(player){
console.log(get.translation(player.get('h')));
2015-04-29 03:25:17 +00:00
},
2015-09-25 05:05:26 +00:00
g:function(){
for(var i=0;i<arguments.length;i++){
if(i>0&&typeof arguments[i]=='number'){
for(var j=0;j<arguments[i]-1;j++){
cheat.gx(arguments[i-1]);
}
}
else{
cheat.gx(arguments[i]);
}
}
},
gx:function(name,target){
2015-04-29 03:25:17 +00:00
target=target||game.me;
2015-09-25 05:05:26 +00:00
var fire=false,thunder=false;
var suit=null;
var suits=['club','spade','diamond','heart'];
for(var i=0;i<suits.length;i++){
if(name.indexOf(suits[i])==0){
suit=suits[i];
name=name.slice(suits[i].length);
break;
}
}
if(name=='huosha'){
name='sha';
fire=true;
}
else if(name=='leisha'){
name='sha';
thunder=true;
}
2015-04-29 03:25:17 +00:00
for(var i=0;i<ui.cardPile.childNodes.length;i++){
2015-09-25 05:05:26 +00:00
if(fire&&ui.cardPile.childNodes[i].nature!='fire'){
continue;
}
if(thunder&&ui.cardPile.childNodes[i].nature!='thunder'){
continue;
}
if(suit&&ui.cardPile.childNodes[i].suit!=suit){
continue;
}
2015-04-29 03:25:17 +00:00
if(ui.cardPile.childNodes[i].name==name){
var card=ui.cardPile.childNodes[i];
target.node.handcards1.appendChild(card);
game.check();
target.update();
2015-11-24 15:44:21 +00:00
ui.updatehl();
2015-04-29 03:25:17 +00:00
return;
}
}
for(var i=0;i<ui.discardPile.childNodes.length;i++){
2015-09-25 05:05:26 +00:00
if(fire&&ui.cardPile.childNodes[i].nature!='fire'){
continue;
}
if(thunder&&ui.cardPile.childNodes[i].nature!='thunder'){
continue;
}
if(suit&&ui.cardPile.childNodes[i].suit!=suit){
continue;
}
2015-04-29 03:25:17 +00:00
if(ui.discardPile.childNodes[i].name==name){
var card=ui.discardPile.childNodes[i];
target.node.handcards1.appendChild(card);
game.check();
target.update();
2015-11-24 15:44:21 +00:00
ui.updatehl();
2015-04-29 03:25:17 +00:00
return;
}
}
},
ge:function(){
cheat.g('zhuge');
cheat.g('qilin');
cheat.g('bagua');
cheat.g('dilu');
cheat.g('chitu');
cheat.g('muniu');
},
gj:function(){
cheat.g('shandian');
cheat.g('huoshan');
cheat.g('hongshui');
cheat.g('lebu');
cheat.g('bingliang');
cheat.g('guiyoujie');
},
d:function(num,target){
if(num==undefined) num=1;
var cards=get.cards(num);
for(var i=0;i<num;i++){
var card=cards[i];
game.me.node.handcards1.appendChild(card);
game.check();
game.me.update();
2015-12-03 16:28:06 +00:00
ui.updatehl();
2015-04-29 03:25:17 +00:00
}
},
s:function(skill){
game.me.addSkill(skill);
game.check();
},
t:function(num){
if(num==undefined){
for(var i=0;i<game.players.length;i++) cheat.t(i);
return;
}
var player=game.players[num];
var cards=player.get('hej');
for(var i=0;i<cards.length;i++){
ui.discardPile.appendChild(cards[i]);
}
player.update();
},
k:function(i){
if(i==undefined) i=1;
game.players[i].hp=1;
cheat.t(i);
cheat.g('juedou');
},
z:function(name){
game.zhu.init(name);
game.zhu.maxHp++;
game.zhu.hp++;
game.zhu.update();
},
cp:function(){
cheat.z('caopi');
},
cc:function(){
2015-09-10 13:56:57 +00:00
cheat.z('re_caocao');
2015-04-29 03:25:17 +00:00
},
ls:function(){
cheat.z('liushan');
},
zj:function(){
2015-11-28 08:29:42 +00:00
cheat.z('sp_zhangjiao');
2015-09-10 13:56:57 +00:00
},
sc:function(){
cheat.z('sunce');
},
lc:function(){
cheat.z('liushan');
},
lb:function(){
cheat.z('liubei');
2015-04-29 03:25:17 +00:00
}
}
window.countGroups=function(){
var a=0,b=0,c=0,d=0;
var sa=0,sb=0,sc=0,sd=0;
for(var i in lib.character){
switch(lib.character[i][1]){
case 'wei':a++;if(lib.config.forbidsingle.contains(i)) sa++;break;
case 'shu':b++;if(lib.config.forbidsingle.contains(i)) sb++;break;
case 'wu':c++;if(lib.config.forbidsingle.contains(i)) sc++;break;
case 'qun':d++;if(lib.config.forbidsingle.contains(i)) sd++;break;
}
}
console.log('魏:'+(a-sa)+'/'+a);
console.log('蜀:'+(b-sb)+'/'+b);
console.log('吴:'+(c-sc)+'/'+c);
console.log('群:'+(d-sd)+'/'+d);
return ((a+b+c+d)-(sa+sb+sc+sd))+'/'+(a+b+c+d);
}
window.countSkills=function(){
for(var i in lib.skill){
if(lib.translate[i+'_info']){
console.log(lib.translate[i],lib.translate[i+'_info'])
}
}
}
window.countCards=function(){
var a=0,b=0,c=0,d=0;
var aa=0,bb=0,cc=0,dd=0;
var sa=0,sb=0,sc=0,sd=0;
var sha=0,shan=0,tao=0,jiu=0,wuxie=0,heisha=0,hongsha=0;
var num={1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0};
for(var i in lib.card){
if(typeof lib.card[i]=='object'){
switch(lib.card[i].type){
case 'basic':a++;break;
case 'trick':b++;break;
case 'equip':c++;break;
default:d++;break;
}
}
}
for(var i=0;i<lib.card.list.length;i++){
if(typeof lib.card[lib.card.list[i][2]]=='object'){
switch(lib.card[lib.card.list[i][2]].type){
case 'basic':aa++;break;
case 'trick':case 'delay':bb++;break;
case 'equip':cc++;break;
default:dd++;break;
}
switch(lib.card.list[i][0]){
case 'heart':sa++;break;
case 'diamond':sb++;break;
case 'club':sc++;break;
case 'spade':sd++;break;
}
if(lib.card.list[i][2]=='sha'){
sha++;
if(lib.card.list[i][0]=='club'||lib.card.list[i][0]=='spade'){
heisha++;
}
else{
hongsha++;
}
}
if(lib.card.list[i][2]=='shan'){
shan++;
}
if(lib.card.list[i][2]=='tao'){
tao++;
}
if(lib.card.list[i][2]=='jiu'){
jiu++;
}
if(lib.card.list[i][2]=='wuxie'){
wuxie++;
}
num[lib.card.list[i][1]]++;
}
}
var str='基本牌'+aa+' '+'锦囊牌'+bb+' '+'装备牌'+cc+' '+'其它牌'+dd
console.log(str);
str='红桃牌'+sa+' '+'方片牌'+sb+' '+'梅花牌'+sc+' '+'黑桃牌'+sd
console.log(str);
str='杀'+sha+' '+'黑杀'+heisha+' '+'红杀'+hongsha+' '+'闪'+shan+' '+'桃'+tao+' '+'酒'+jiu+' '+'无懈'+wuxie
console.log(str);
for(var i=1;i<=13;i++){
2015-09-16 02:45:45 +00:00
if(i<10){
console.log(i+' ',num[i]);
}
else{
console.log(i,num[i]);
}
2015-04-29 03:25:17 +00:00
}
return aa+bb+cc+dd;
}
window.onkeydown=function(e){
2015-11-25 15:59:24 +00:00
if(!ui.menuContainer||!ui.menuContainer.classList.contains('hidden')) return;
2015-10-28 03:47:35 +00:00
if(ui.currentpopped){
if(ui.currentpopped._uiintro){
ui.currentpopped._uiintro.delete();
delete ui.currentpopped._uiintro;
}
delete ui.currentpopped;
}
var dialogs=document.querySelectorAll('#window>.dialog.popped:not(.static)');
for(var i=0;i<dialogs.length;i++){
dialogs[i].delete();
}
2015-04-29 03:25:17 +00:00
if(e.keyCode==32){
var node=ui.window.querySelector('#paused');
if(node){
node.click();
}
else{
ui.click.pause();
}
}
else if(e.keyCode==65){
if(ui.auto) ui.auto.click();
}
else if(e.keyCode==87){
if(ui.wuxie&&ui.wuxie.style.display!='none'){
ui.wuxie.classList.toggle('glow')
}
}
else if(e.keyCode==67){
var node=ui.window.querySelector('#click');
if(node){
node.click();
}
else{
ui.click.config();
}
}
else if(e.keyCode==116||((e.ctrlKey||e.metaKey)&&e.keyCode==82)){
2015-04-29 08:41:00 +00:00
_status.reloading=true;
game.reload();
2015-04-29 03:25:17 +00:00
}
};
window.onload=function(){
2015-05-07 04:48:00 +00:00
document.body.onresize=ui.updatex;
2015-04-29 03:25:17 +00:00
if(lib.config.touchscreen){
document.body.addEventListener('touchstart',function(e){
this.startX=e.touches[0].clientX;
this.startY=e.touches[0].clientY;
_status.dragged=false;
});
document.body.addEventListener('touchmove',function(e){
if(_status.dragged) return;
if (Math.abs(e.touches[0].clientX - this.startX) > 10 ||
Math.abs(e.touches[0].clientY - this.startY) > 10) {
_status.dragged=true;
}
});
}
ui.background=document.querySelector('.background.static');
ui.background.classList.remove('static');
2015-12-02 10:40:25 +00:00
lib.onDB(function(){
if(lib.config.image_background=='custom'){
ui.background.style.backgroundImage="none";
game.getDB('image','background',function(fileToLoad){
if(!fileToLoad) return;
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var data = fileLoadedEvent.target.result;
ui.background.style.backgroundImage='url('+data+')';
};
fileReader.readAsDataURL(fileToLoad, "UTF-8");
});
}
});
2015-12-06 15:23:47 +00:00
var proceed=function(){
var i,j,k;
for(i in mode[lib.config.mode].element){
if(!lib.element[i]) lib.element[i]=[];
for(j in mode[lib.config.mode].element[i]){
if(j=='init'){
if(!lib.element[i].inits) lib.element[i].inits=[];
lib.element[i].inits.push(lib.init.eval(mode[lib.config.mode].element[i][j]));
}
else{
lib.element[i][j]=lib.init.eval(mode[lib.config.mode].element[i][j]);
}
}
}
for(i in mode[lib.config.mode].ai){
if(typeof mode[lib.config.mode].ai[i]=='object'){
if(ai[i]==undefined) ai[i]={};
for(j in mode[lib.config.mode].ai[i]){
ai[i][j]=lib.init.eval(mode[lib.config.mode].ai[i][j]);
}
2015-04-29 03:25:17 +00:00
}
else{
2015-12-06 15:23:47 +00:00
ai[i]=lib.init.eval(mode[lib.config.mode].ai[i]);
2015-04-29 03:25:17 +00:00
}
}
2015-12-06 15:23:47 +00:00
for(i in mode[lib.config.mode].ui){
if(typeof mode[lib.config.mode].ui[i]=='object'){
if(ui[i]==undefined) ui[i]={};
for(j in mode[lib.config.mode].ui[i]){
ui[i][j]=lib.init.eval(mode[lib.config.mode].ui[i][j]);
}
}
else{
ui[i]=lib.init.eval(mode[lib.config.mode].ui[i]);
2015-04-29 03:25:17 +00:00
}
}
2015-12-06 15:23:47 +00:00
for(i in mode[lib.config.mode].game){
game[i]=lib.init.eval(mode[lib.config.mode].game[i]);
2015-04-29 03:25:17 +00:00
}
2015-12-06 15:23:47 +00:00
for(i in mode[lib.config.mode].get){
get[i]=lib.init.eval(mode[lib.config.mode].get[i]);
2015-04-29 03:25:17 +00:00
}
2015-12-06 15:23:47 +00:00
lib.config.current_mode=mode[lib.config.mode].config||[];
lib.config.mode_choice=mode[lib.config.mode].config;
lib.rank=window.characterRank;
delete window.characterRank;
for(i in mode[lib.config.mode]){
if(i=='element') continue;
if(i=='game') continue;
if(i=='ai') continue;
if(i=='ui') continue;
if(i=='get') continue;
if(i=='config') continue;
if(lib[i]==undefined) lib[i]=(get.objtype(mode[lib.config.mode][i])=='array')?[]:{};
for(j in mode[lib.config.mode][i]){
lib[i][j]=lib.init.eval(mode[lib.config.mode][i][j]);
}
}
for(i in character){
if(character[i].character){
lib.characterPack[i]=character[i].character
}
if(character[i].forbid&&character[i].forbid.contains(lib.config.mode)) continue;
if(character[i].mode&&character[i].mode.contains(lib.config.mode)==false) continue;
for(j in character[i]){
if(j=='mode'||j=='forbid') continue;
if(j=='character'&&!lib.config.characters.contains(i)){
if(lib.config.mode=='chess'&&get.config('chess_mode')=='leader'){
for(k in character[i][j]){
2015-10-30 15:32:48 +00:00
lib.hiddenCharacters.push(k);
}
}
2015-12-06 15:23:47 +00:00
else if(lib.config.mode!='boss'||i!='boss'){
continue;
2015-11-06 10:05:08 +00:00
}
2015-04-29 03:25:17 +00:00
}
2015-12-06 15:23:47 +00:00
for(k in character[i][j]){
if(j=='character'){
if(!character[i][j][k][4]){
character[i][j][k][4]=[];
}
if(character[i][j][k][4].contains('boss')||
character[i][j][k][4].contains('hiddenboss')){
lib.config.forbidai.add(k);
}
if(lib.config.banned.contains(k)){
if(lib.config.mode=='chess'&&get.config('chess_mode')=='leader'){
lib.hiddenCharacters.push(k);
}
else{
continue;
}
}
for(var l=0;l<character[i][j][k][3].length;l++){
lib.skilllist.add(character[i][j][k][3][l]);
}
}
if(j=='translate'&&k==i){
lib[j][k+'_character_config']=character[i][j][k];
2015-06-13 06:53:40 +00:00
}
else{
2015-12-06 15:23:47 +00:00
if(lib[j][k]==undefined){
lib[j][k]=lib.init.eval(character[i][j][k]);
}
else{
alert('dublicate '+j+' in character '+i+':\n'+k+'\n'+': '+lib[j][k]+'\n'+character[i][j][k]);
}
2015-06-13 06:53:40 +00:00
}
2015-04-29 03:25:17 +00:00
}
}
}
2015-12-06 15:23:47 +00:00
for(i in card){
lib.cardPack[i]=[];
if(card[i].card){
for(var j in card[i].card){
if(card[i].translate[j+'_info']){
lib.cardPack[i].push(j);
}
2015-10-30 15:32:48 +00:00
}
}
2015-12-06 15:23:47 +00:00
if(card[i].forbid&&card[i].forbid.contains(lib.config.mode)) continue;
if(card[i].mode&&card[i].mode.contains(lib.config.mode)==false) continue;
for(j in card[i]){
if(j=='mode'||j=='forbid') continue;
if(j=='list'){
if(lib.config.cards.contains(i)){
var pile;
if(typeof card[i][j]=='function'){
pile=lib.init.eval(card[i][j])();
2015-11-28 03:45:23 +00:00
}
2015-12-06 15:23:47 +00:00
else{
pile=card[i][j];
2015-11-28 03:45:23 +00:00
}
2015-12-06 15:23:47 +00:00
lib.cardPile[i]=pile.slice(0);
if(lib.config.bannedpile[i]){
for(var k=0;k<lib.config.bannedpile[i].length;k++){
pile[lib.config.bannedpile[i][k]]=null;
}
}
for(var k=0;k<pile.length;k++){
if(!pile[k]){
pile.splice(k--,1);
}
}
if(lib.config.addedpile[i]){
for(var k=0;k<lib.config.addedpile[i].length;k++){
pile.push(lib.config.addedpile[i][k]);
}
}
lib.card.list=lib.card.list.concat(pile);
2015-11-28 03:45:23 +00:00
}
2015-12-06 15:23:47 +00:00
}
else{
for(k in card[i][j]){
if(j=='translate'&&k==i){
lib[j][k+'_card_config']=card[i][j][k];
}
else{
if(lib[j][k]==undefined) lib[j][k]=lib.init.eval(card[i][j][k]);
else alert('dublicate '+j+' in card '+i+':\n'+k+'\n'+lib[j][k]+'\n'+card[i][j][k]);
2015-11-28 03:45:23 +00:00
}
2015-04-29 03:25:17 +00:00
}
}
}
2015-12-06 15:23:47 +00:00
}
for(i in play){
if(play[i].forbid&&play[i].forbid.contains(lib.config.mode)) continue;
if(play[i].mode&&play[i].mode.contains(lib.config.mode)==false) continue;
for(j in play[i].element){
if(!lib.element[j]) lib.element[j]=[];
for(k in play[i].element[j]){
if(k=='init'){
if(!lib.element[j].inits) lib.element[j].inits=[];
lib.element[j].inits.push(lib.init.eval(play[i].element[j][k]));
2015-06-13 06:53:40 +00:00
}
else{
2015-12-06 15:23:47 +00:00
lib.element[j][k]=lib.init.eval(play[i].element[j][k]);
2015-06-13 06:53:40 +00:00
}
2015-04-29 03:25:17 +00:00
}
}
2015-12-06 15:23:47 +00:00
for(j in play[i].ui){
if(typeof play[i].ui[j]=='object'){
if(ui[j]==undefined) ui[j]={};
for(k in play[i].ui[j]){
ui[j][k]=lib.init.eval(play[i].ui[j][k]);
}
2015-04-29 03:25:17 +00:00
}
else{
2015-12-06 15:23:47 +00:00
ui[j]=lib.init.eval(play[i].ui[j]);
2015-04-29 03:25:17 +00:00
}
}
2015-12-06 15:23:47 +00:00
for(j in play[i].game){
game[j]=lib.init.eval(play[i].game[j]);
2015-04-29 03:25:17 +00:00
}
2015-12-06 15:23:47 +00:00
for(j in play[i].get){
get[j]=lib.init.eval(play[i].get[j]);
2015-04-29 03:25:17 +00:00
}
2015-12-06 15:23:47 +00:00
if(play[i].config){
lib.config.current_mode=lib.config.current_mode.concat(play[i].config);
}
for(j in play[i]){
if(j=='mode'||j=='forbid'||j=='init'||j=='element'||
j=='game'||j=='get'||j=='config'||j=='ui'||j=='arenaReady') continue;
for(k in play[i][j]){
if(j=='translate'&&k==i){
lib[j][k+'_play_config']=play[i][j][k];
}
else{
if(lib[j][k]!=undefined){
console.log('dublicate '+j+' in play '+i+':\n'+k+'\n'+': '+lib[j][k]+'\n'+play[i][j][k]);
}
lib[j][k]=lib.init.eval(play[i][j][k]);
2015-06-13 06:53:40 +00:00
}
2015-04-29 03:25:17 +00:00
}
}
2015-12-06 15:23:47 +00:00
if(typeof play[i].init=='function') (lib.init.eval(play[i].init))();
if(typeof play[i].arenaReady=='function') lib.arenaReady.push(play[i].arenaReady);
2015-04-29 03:25:17 +00:00
}
2015-12-06 15:23:47 +00:00
for(i=0;i<lib.card.list.length;i++){
if(!lib.card[lib.card.list[i][2]]){
lib.card.list.splice(i,1);i--;
}
else if(lib.card[lib.card.list[i][2]].mode&&
lib.card[lib.card.list[i][2]].mode.contains(lib.config.mode)==false){
lib.card.list.splice(i,1);i--;
}
2015-04-29 03:25:17 +00:00
}
2015-12-06 15:23:47 +00:00
try{
lib.storage=JSON.parse(localStorage.getItem(lib.configprefix+lib.config.mode));
if(typeof lib.storage!='object') throw('err');
if(lib.storage==null) throw('err');
2015-04-29 03:25:17 +00:00
}
2015-12-06 15:23:47 +00:00
catch(err){
lib.storage={};
localStorage.setItem(lib.configprefix+lib.config.mode,"{}");
}
if(lib.config.cheat) cheat.i();
else{
lib.cheat=window.cheat;
delete window.cheat;
}
lib.config.sort_card=get.sortCard(lib.config.sort);
delete window.config;
delete window.mode;
delete window.card;
delete window.character;
delete window.play;
ui.create.arena();
game.start();
game.loop();
2015-04-29 03:25:17 +00:00
}
2015-12-09 03:05:36 +00:00
var goon=function(){
if(!mode[lib.config.mode]){
window.inSplash=true;
var clickNode=function(){
lib.config.mode=this.link;
splash.delete();
delete window.inSplash;
lib.init.js('mode',lib.config.mode).onload=proceed;
}
var splash=ui.create.div('#splash',document.body);
for(var i=0;i<lib.config.all.mode.length;i++){
var node=ui.create.div(splash,'.hidden',clickNode);
node.link=lib.config.all.mode[i];
ui.create.div(node,'.splashtext',get.verticalStr(get.translation(lib.config.all.mode[i])));
ui.create.div(node,'.avatar').style.backgroundImage='url("image/splash/'+lib.config.all.mode[i]+'.jpg")';
ui.refresh(node);
setTimeout((function(node){
return function(){
node.show();
}
}(node)),i*100);
}
}
else{
proceed();
}
localStorage.removeItem(lib.configprefix+'directstart');
};
if(lib.version==1.7&&!lib.config.birthdayshown){
game.saveConfig('birthdayshown',true);
2015-12-06 15:23:47 +00:00
window.inSplash=true;
2015-12-09 03:05:36 +00:00
var container=ui.create.div(document.body);
container.style.width='100%';
container.style.height='100%';
container.style.left=0;
container.style.top=0;
var createName=function(str){
var node=ui.create.div('',str);
node.style.fontSize='200px';
node.style.color='white';
node.style.fontFamily='huangcao,xinwei';
node.style.opacity=0;
node.style.transform='scale(3)';
node.style.top='calc(50% - 100px)';
node.style.textShadow='black 0 0 2px';
container.appendChild(node);
2015-12-06 15:23:47 +00:00
ui.refresh(node);
2015-12-09 03:05:36 +00:00
node.style.opacity=1;
node.style.transform='scale(1)';
return node;
2015-12-06 15:23:47 +00:00
}
2015-12-09 03:05:36 +00:00
createName('无').style.left='calc(50% - 300px)';
setTimeout(function(){
createName('名').style.left='calc(50% - 100px)';
},500);
setTimeout(function(){
createName('杀').style.left='calc(50% + 100px)';
},1000);
setTimeout(function(){
var node4=ui.create.div('','两周年');
node4.style.color='white';
node4.style.textShadow='black 0 0 2px';
node4.style.fontFamily='huangcao,xinwei';
node4.style.fontSize='60px';
node4.style.webkitAnimation='flip3t 1s';
node4.style.letterSpacing='-10px';
node4.style.top='calc(50% + 100px)';
node4.style.left='calc(50% + 180px)';
node4.style.border='2px solid white';
node4.style.borderRadius='8px';
node4.style.boxShadow='black 0 0 2px';
node4.style.transform='rotate(-10deg)';
node4.style.animationTimingFunction="linear"
container.appendChild(node4);
setTimeout(function(){
container.style.transform='scale(0.5)';
container.delete();
window.inSplash=false;
},2500);
},1500);
setTimeout(goon,4500);
2015-04-29 03:25:17 +00:00
}
else{
2015-12-09 03:05:36 +00:00
goon();
2015-12-06 15:23:47 +00:00
}
2015-04-29 03:25:17 +00:00
};
2015-11-14 09:02:14 +00:00
if(!lib.config.touchscreen){
2015-11-21 13:23:23 +00:00
document.onmousewheel=ui.click.windowmousewheel;
document.onmousemove=ui.click.windowmousemove;
document.onmousedown=ui.click.windowmousedown;
document.onmouseup=ui.click.windowmouseup;
2015-11-14 09:02:14 +00:00
document.oncontextmenu=ui.click.right;
}
2015-11-26 00:50:57 +00:00
else{
2015-11-29 11:46:51 +00:00
document.ontouchstart=ui.click.windowtouchstart;
document.ontouchend=ui.click.windowtouchend;
document.ontouchmove=ui.click.windowtouchmove;
2015-04-29 03:25:17 +00:00
}
2015-11-21 13:23:23 +00:00
window.onbeforeunload=function(){
if(lib.config.confirm_exit&&!_status.reloading){
return '是否离开游戏?'
}
else{
return null;
}
}
2015-04-29 03:25:17 +00:00
}());