Let’s make a game using the JavaScript library jQuery! Part 2: “Making a simple role-playing game with jQuery” (English version)

Let's make a game using the JavaScript library jQuery! Part 2: "Making a simple role-playing game with jQuery" (English version)
提供:ぴぽや倉庫

I tried to make something like a role-playing game (RPG) using the JavaScript library “jQuery”.

I am not using any library. Made with only jquery (javascript).

I made it because I admired “Romancing Saga (for Super Nintendo Entertainment System)” ヽ(^o^)丿

As a result, I ended up with a strange game that didn’t look like it at all.

Making games is really hard. I felt keenly (>_<)

That aside.

But for the time being, I can do it ヽ(^o^)丿

It may be buggy, but I would appreciate it if you could play it.

 ・Depending on the device, you may not be able to play. I’m sorry.

 ・You can clear it quickly, but the final boss is a little strong (laughs), so the priest who casts recovery magic has a high defense power.

 ・Music flows with the BGM button.

Materials related to the images are used from “Pipoya Warehouse (https://pipoya.net/)”.
Music material is used from “OtoLogic (https://otologic.jp)”.

The code is dirty anyway because I was coding (programming) little by little when I forgot. *Comments between code are like scribbles.

Here are the essential elements for making this game:

■clip

Crop property of an element in css. This game has one image file for each character. In other words, you have to extract the character facing right, the character facing left, etc. from one image file depending on the situation. That’s where this property comes into play. Use clip: rect(, , , ) to cut out only a part of the image file you need.

for example···

JavaScriptライブラリ『jQuery』で画像を切り抜こう
『ぴぽや倉庫(ぴぽや https://pipoya.net/)』様

Since 1 frame (1 game character) consists of a 32px square, specify the cutout position in 32px units.

In other words, if you want to cut out the characters in the red frame, do as follows.

$('.character_1').css({
    //Trimming settings
    'clip':'rect('+
        32 + 'px,' + //Up
        32 + 'px,' + //right
        64 + 'px,' + //under
        0 + 'px' +   //left
    ')'
});

■ setTimeout and setInterval

setTimeout is a JavaScript function that creates an asynchronous timer event. This feature allows you to execute a desired function after a specified amount of time has passed.

setInterval is a type of JavaScript function that allows you to repeat a target function at regular time intervals. This function is called asynchronously every specified time interval.

For example, if you want the music to play after 0.9 seconds, use setTimeout like this:

<audio src="https://likehuman.info/wp-content/uploads/2023/05/bgm_knockdown.mp3" class="bgm_knockdown">
 
setTimeout(function(){
     $(".bgm_knockdown").get(0).currentTime = 0;
     $(".bgm_knockdown").get(0).play();
},900);//0.9 seconds at 900, 9 seconds at 9000

Next, if you use setInterval, you can use it if you want to repeatedly play a very short music file (such as ending in 0.2 seconds) every few seconds. For example, if you want to express the sound of a machine gun firing, do the following.

<audio src="https://likehuman.info/wp-content/uploads/2022/12/attack_sword_heavy.mp3" class="bgm_attach_sword_heavy"></audio>

// Processing to repeatedly play the above music file (short song) at setInterval every 0.3 seconds.

let gg = setInterval(function(){
         // restore playback position
         $("bgm_attack_sword_heavy").get(0).currentTime = 0;
         // change playback speed
         $("bgm_attack_sword_heavy").get(0).playbackRate = 2.5;
         //play music
         $("bgm_attack_sword_heavy").get(0).play();
},300);

// stop after 1 second
setTimeout(function(){
         clearTimeout (gg).
},1000);

SetInterval repeats the music every 0.3 seconds, and setTimeout stops after 1 second.

By doing this, “bang! (about 0.2 seconds)” is repeated for 1 second, making it look like a machine gun.

By the way, if you want to repeat your own function (recursive processing), it is as follows.

function charDirectionDecide_1(i){
             // process 1
             // process 2
             // process 3
             // By writing ↓ at the end, this function itself (characterDirectionDecide_1) can be recursively processed every 2 seconds. i will be the argument of this function.
             stop_character_id_1[i] = setTimeout(characterDirectionDecide_1, 2000,i);
         }
 
// stop above processing
clearTimeout(stop_walk_id_1[i]);

And above all, by executing setTimeout and setInterval on the clipped image with the above clip property, you can add movement to the character and effect image!(^^)!

setTimeout and setInterval are super important functions that add “movement” to the game.

■ Position

I think many people are confused by the word “position”, but I’m not particularly advanced. Position the character left: 100px, top: 50px, or start combat when the character enters the enemy’s radius of 30px. That’s it.

For example, if you want to display an image that is 100 pixels from the left edge and 200 pixels from the top, you can do:
$(".character_move_"+i).css({
            'left'  : 100 + 'px',
            'top'  : 200 + 'px'
}); 

■ music

Music is played with the audio element .get(0).play() . Music is also important to enjoy the game.

For example, to stop or play a song with class name bgm_talk:

<audio src="https://likehuman.info/wp-content/uploads/2022/12/Cyber14-2.mp3" class="bgm_talk"></audio>
        
// to stop the song
$(".bgm_talk").get(0).pause();//Stop
 
// when playing a song
$(".bgm_talk").currentTime = 0;//Restore playback position
$(".bgm_talk").get(0).play();//play the song
$(".bgm_talk").get(0).loop = true;//Loop (repeat the song)

■ button

Below is an example of a button implementation. Mousedown and touchstart make it possible to press the button on both PC and smartphone.

<button type="button" class="right_btn"></button>
//If you want to implement a button created in HTML like the one above, do the following:    
 
//Press the button...
$(".right_btn").on('mousedown touchstart', function(event){
    event.preventDefault();//Cancel the browser's default behavior
    // Processing content
           // make the character walk right
           //Move the cursor to the right in the battle menu, etc.
});
//When you release the button...
$(".right_btn").on('mouseup mouseleave touchend', function(){
    //Processing content
});

animate()

The animate() function, like the setTimeout() and setInterval() functions, is an important function that adds “movement” to the game. However, it’s a little hard to understand, so I think it’s better to actually try it and understand it.
It is a very convenient function that can be used in any scene!(^^)!
For example, in this game the cursor spins like a spinning top over the character’s head. This cursor is rendered using the setInterval() and animate() functions.
Below is a clip of the animation process.

stop_m_arrow_timer = setInterval(function(){
	$('.m_select_arrow_img_' + i).css({'opacity': '1'});
	//CSS properties other than opacity are OK as we are just using numbers that change from 1 to 2.
	$('.m_select_arrow_img_' + i).animate({opacity: 2 },{
		//change over 1.7 seconds
		duration:1700,
		//step・・・How to change over time
		step:function(o){
		//Rotate the image around the Y axis by 1080 x 2 degrees (360 degrees x 6), i.e. 6 rotations
		$(this).css({transform:'rotateY(' + (o * 1080) + 'deg)'});
		//↑The variable [o] contains the values 1.1, 1.2, 1.3 ... 2.0 where the opacity changes from 1 to 2.
		},
		//Completion process... No need to write
	},2000);
})


//Processing to stop the above animation
clearInterval(stop_m_arrow_timer);	

The cursor image is rotated 6 times around the vertical axis in 1.7 seconds. That process is repeated every 2 seconds with the setInterval() function.
As a result, you can rotate the cursor like a spinning top above the character’s head.

Of course there are others, but please understand that I will explain in detail next time.

For now, I’ll paste the entire code.

If you like dot games and want to become a programmer, please try to make one\(^o^)/

It’s a fun way to learn, and above all, I think it’s the fastest way to learn.

HTMLとCSS

<html lang="ja">
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>


/* プレイ画面の親 CSS     */
.game{
	position: relative;
}
	
.game_container{
    position: relative;
    align-items: center;
    height: 300px;
    width: 100%;
	margin-bottom: 0;
/* 	
	background-image: url(https://likehuman.info/wp-content/uploads/2022/11/grass.png);
	background-repeat: repeat; */
}

/* メインキャラ(hero) のスプライト */
.main_character{
    position: absolute;
	top: 32px;
	left: 0px;
    clip: rect(32px, 32px, 64px, 0px);
}
/* 	wordpress(テーマの方?)では、
	max-widthが100パーセントに設定される。
	描画に支障をきたすので解除 */
img{
    max-width: unset;
}
/* コントローラー各種の親CSS */
.control_container{
	display: flex;
	margin-top: 40px;
	align-items: left;
	width: 100%;
	/* top:460px; */
	position: relative;
}
/* 十字キー */
.cross_key_container{
	margin-right: auto;
    margin-left: auto;
    display: grid;
    gap: 10%;
    width: 50%;
    grid-template-columns: 30% 30% 30%;
    grid-template-rows: 160% 160% 160%;
}
.up_btn{
	grid-row: 1/2;
    grid-column: 2/3;
}
.left_btn{
	grid-row: 2/3;
    grid-column: 1/2;
}
.right_btn{
	grid-row: 2/3;
    grid-column: 3/4;
}
.down_btn{
	grid-row: 3/4;
    grid-column: 2/3;
}
.up_btn,.left_btn,.right_btn,.down_btn{
	border: none;
    border-bottom: solid 5px #a9a9a9;
    border-radius: 8px;
}
.up_btn:active,.left_btn:active,.right_btn:active,.down_btn:active{
    border-bottom: solid 2px #a9a9a9;
}
/* BGM、A、Bボタン */
.a_and_b_btn{
    display: grid;
    margin-right: auto;
    margin-left: 20%;
    font-size: 0.5em;
    row-gap: 50%;
    width: 50%;
    grid-template-columns: 30% 30% 30%;
    grid-template-rows: 160% 160% 160%;

}
.bgm_btn{
	grid-row: 1/2;
    grid-column: 2/3;
	background-color: aliceblue;	
}
.a_btn{
	grid-row: 2/3;
    grid-column: 1/2;
	background-color: pink;
}
.b_btn{
	grid-row: 2/3;
    grid-column: 3/4;
	background-color: lightskyblue;	
}
.bgm_btn,.a_btn,.b_btn{
    border-radius: 80%;
    border: none;
    border-bottom: solid 5px #a9a9a9;
    font-size: 1.5em;
}
.bgm_btn:active,.a_btn:active,.b_btn:active{
    border-bottom: solid 2px #a9a9a9;
}
/* 会話画面の親CSS */
.conversation_container{
   margin: 0 auto;
   position: relative;
}
/* 会話画面 */
.conversation{
	width: 0;
	height: 0;
	background: black;
	display: none;
	left: 50%;
	border: 5px solid #249dec;
	position: relative;
	font-size: 0.7em;
	color: white;
	margin-top: 0;
		
}
.game_btn{
	background-color: black;
	color: white;
	border: none;
	cursor: pointer;
	outline: none;
	padding: 0;
	appearance: none;
	font-size: 1em;
}
.battle_container{
    position: relative;
    align-items: center;	
    height: 300px;
    width: 100%;
	margin-bottom: 0;
	background-image: url(https://likehuman.info/wp-content/uploads/2022/11/battle001.jpg);
	background-repeat: round;
	background-size:  cover;
	z-index: 90;
	/* はみ出した要素は非表示 */
	white-space: nowrap;
	overflow: hidden;
}
.battle_menu{
    position: relative;
    display: flex;
    margin-right: auto;
    margin-left: auto;
    width: 0;
    height: 0;
    width: 100%;
    font-size: 0.7em;
	margin-top: 0.2%;
    justify-content: center;
    align-items: center;	
}
.battle_monster{
	display: grid;
    margin-left: 1%;
    width: 35%;
    height: 200px;
    border: 5px solid #249dec;
    background-color: black;
    color: white;
}	
.battle_tactics{
    display: grid;
    /* gap: 0%; */
    width: 25%;
    height: 200px;
    border: 5px solid #249dec;
    background-color: black;
    grid-template-columns: 2fr 2fr;
}
.battle_status{
    display: grid;
    place-items: center;
    gap: 1%;
    /* margin-left: 5%; */
    height: 200px;
    border: 5px solid #249dec;
    width: 40%;
    /* grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr; */
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr ;	
    background-color: black;
    color: white;
}
.battle_skill_command{
	display: grid;
	place-items: center;
    gap: 1%;
    height: 200px;
    width: 40%;	
    border: 5px solid #249dec;	
	/* margin-left: 5%; */
	margin-right: 5%;	
	width: 50%;	
	/* スキルを増やしたい時はここを追加 */	
	grid-template-columns: 3fr 3fr;	
	background-color: black;
    color: white;
}
.battle_message,.battle_message2{
    background-color: black;
    color: white;
	font-size:  0.5em;
    border: 5px solid #249dec;		
}

.style21 {
	display: inline-block;		/* インライン要素:横並び配置、ブロック要素:幅や高さ・余白の指定可 */
	position: relative;
	color: rgba(0,0,0,0);		/* 透明 */
	top:0;
	left: 0;
}
.style21 span:nth-of-type(1){
	position: absolute;
	color: rgba(0,0,0,0);		/* 透明 */
	text-shadow:
		#75B6FE 1px 1px 3px, #95F8EE -1px 1px 3px,
		#75B6FE 1px -1px 3px, #95F8EE -1px -1px 3px;
	top: 0;
	left: 0;
	-webkit-text-stroke-width: 1px;
	z-index: 10;
}
.style21 span:nth-of-type(2){
	position: absolute;
	margin: 0;
	top: 0;
	left: 0;
	color: #FFF;				/* 白 */
	text-stroke-width: 0px ;
	z-index: 20;
}
.style16 {
	display: inline-block;		/* インライン要素:横並び配置、ブロック要素:幅や高さ・余白の指定可 */
	position: relative;
	color: rgba(0,0,0,0);		/* 透明 */
	top:0;
	left: 0;
}
.style16 span:nth-of-type(1){
	position: absolute;
	top: 0;
	left: 0;
	color: rgba(0,0,0,0);
	background: -webkit-linear-gradient(120deg, #EB77DD 10%, #C86CD3, #8827C7, #2499D7, #15D57F 90%) ;
	-webkit-background-clip: text;
	-webkit-text-stroke-width: 6px;
	z-index: 10;
}
.style16 span:nth-of-type(2){
	position: absolute;
	margin: 0;
	color: #FFF;				/* 白 */
	text-stroke-width: 0px ;
	top: 0;
	left: 0;
	z-index: 20;
}

.fontStyle01{
	font-family: Georgia,游明朝,"Yu Mincho",YuMincho,"Hiragino Mincho ProN",HGS明朝E,メイリオ,Meiryo,serif;
	font-size: 20px;
	color: rgba(0,0,0,0);		/* 透明 */
}
.title_position{
	top: 20px;
	left: 20px;	
}
.title2_position{
	top: 100px;
	left: 150px;
}	
/* 空白領域 */
.blank{
	height: 100px;
}
/* wordpressで正常に表示されない、または動かない時にチェックする項目
・クラスやIDの名称の重複
・wordpress標準、またはテーマのCSSによる影響 
上記には注意すること
*/



</style>
</head>
<body>

	<div class="game">
		<div class="game_container">

		</div>

		<div class="control_container">
			<div class="cross_key_container">
				<button type="button" class="up_btn"></button>
				<button type="button" class="left_btn"></button><button type="button" class="right_btn"></button>
				<button type="button" class="down_btn"></button>			
			</div>
			<div class="a_and_b_btn">
				<button type="button" class="bgm_btn">BGM</button>		
				<button type="button" class="a_btn"> A </button>
				<button type="button" class="b_btn"> B </button>
			</div>
		</div>

	</div>
	<div class="blank"></div>


</body>
</html>	

jQuery

Full text of jQuery. I don’t think there is anyone who pastes everything like me (*_*) Japanese comments and dirty code. really sorry.

<script type="text/javascript">

/*
レトロRPG(ドットによるゲーム)
・フィールドを歩く
・サブキャラとの会話
・BGMを流す
*/
jQuery(document).ready(function ($) {
	
	//タイトル画面かどうか
	let title_flag = true;
	//デバイスに配慮した画面表示をするための変数
	let view_w = $(".game_container").width() - 20;
	let view_h = $(".game_container").height() - 70;
	
	/* 	
	メンキャラに関する変数
	基本的には「ぴぽや https://pipoya.net/」様からダウンロードしたキャラクターチップでスプライトを生成 
	するための座標を格納
	*/
	let mainchara_rect_top = 0;//32
	let mainchara_rect_right = 32;//32
	let mainchara_rect_bottom= 32;//64
	let mainchara_rect_left = 0;//0
	let mainchara_position_left = view_w / 2;
	let mainchara_position_top = view_h * 0.7;
	let stop_up_mainchar_id = 0;
	let stop_left_mainchar_id = 0;
	let stop_right_mainchar_id = 0;
	let stop_down_mainchar_id = 0;
	let stop_move_mainchar_id = 0;
	let get_position_maincharacter;
	let conversationv_flag = false;
	/* 	
	サブキャラに関する変数
	基本的には「ぴぽや https://pipoya.net/」様からダウンロードしたキャラクターチップでスプライトを生成 
	するための座標を格納
	*/
	let new_character_list = [];
	let character_position_left_1 = [50,140,(view_w * 2 / 3)];
	let character_position_top_1 = [50,200,170];
	let stop_move_id_1 = [0,0,0];
	let stop_chara_id_1 = [0,0,0];
	let stop_walk_id_1 = [0,0,0];	
	let character_rect_1 = [[32,32,0,64],[32,32,0,64],[32,32,0,64]];//上、右、左、下
	let get_position_character_1 = [];
	/* 	
	共通して使用する変数
	・キャラクターチップの切り抜き割合
	・当たり判定
	・会話可能範囲判定
	・BGMフラグ(使用した音素材:OtoLogic(https://otologic.jp))
	・描画範囲
	・キャラクターチップの設定
	*/
	const cut_percentage = 32;
	let title_ef_timer = 0;
	let continuous_click_prevention = 0;//連続クリック防止
	let target_field_chara = 0;
	let hit_flag = [false,false,false];
	let talk_range = [false,false,false];
	let hit_range = [[false,false,false,false],[false,false,false,false],[false,false,false,false]];
	let bgm_village_flag = false;
	let chara_1 = ' style="position: absolute;" name="banditman" src="https://likehuman.info/wp-content/uploads/2022/11/ぴぽや_男005_盗賊.png" >';
	let chara_2 = ' style="position: absolute;" name="maidwoman" src="https://likehuman.info/wp-content/uploads/2022/11/ぴぽや_女006_メイド.png">';
	let chara_3 = ' style="position: absolute;" name="childgirl" src="https://likehuman.info/wp-content/uploads/2022/11/ぴぽや_子供_女001_一般人.png">';
	let chara_4 = ' style="position: absolute;" name="Princess" src="https://likehuman.info/wp-content/uploads/2023/05/queen.png">';
	let monster_1 = ' style="position: absolute;" name="monster_1" src="https://likehuman.info/wp-content/uploads/2023/05/monster01.png" >';
	let monster_2 = ' style="position: absolute;" name="monster_2" src="https://likehuman.info/wp-content/uploads/2023/05/monster02.png" >';
	let monster_3 = ' style="position: absolute;" name="monster_3" src="https://likehuman.info/wp-content/uploads/2023/05/monster03.png" >';
	let monster_4 = ' style="position: absolute;" name="monster_4" src="https://likehuman.info/wp-content/uploads/2023/05/monster04.png" >';
	let monster_5 = ' style="position: absolute;" name="monster_5" src="https://likehuman.info/wp-content/uploads/2023/05/monster05.png" >';
	let monster_6 = ' style="position: absolute;" name="monster_6" src="https://likehuman.info/wp-content/uploads/2023/05/monster06.png" >';
	let monster_7 = ' style="position: absolute;" name="monster_7" src="https://likehuman.info/wp-content/uploads/2023/05/monster07.png" >';
	let monster_8 = ' style="position: absolute;" name="monster_8" src="https://likehuman.info/wp-content/uploads/2023/05/monster08.png" >';
	let monster_9 = ' style="position: absolute;" name="monster_9" src="https://likehuman.info/wp-content/uploads/2023/05/monster09.png" >';
	let monster_10 = ' style="position: absolute;" name="monster_10" src="https://likehuman.info/wp-content/uploads/2023/06/monster10.png" >';
	let monster_11 = ' style="position: absolute;" name="monster_11" src="https://likehuman.info/wp-content/uploads/2023/06/monster11.png" >';		
	let lassboss = ' style="position: absolute;" name="lassboss" src="https://likehuman.info/wp-content/uploads/2023/05/lastboss.png" >';		
	
	/****************** 	
	フィールド背景に関する配列
	******************/	
	//戦闘背景・・・0grass,1ougi,2rasboss,3suna,4doukutu,5douku2_2,6yougan,7water,8water2,9yuki,10yuki2,11rakuen,12makai
	//フィールド背景・・・0ホワイト、1草原、2砂漠、3洞窟、4洞窟2、5溶岩、6水、7水2、8雪、9氷、10楽園、11宇宙、12宇宙
	let id_current_field = 1;
	let number_of_laps = 1;
	let field_background_src = [];
	field_background_src[0] = "https://likehuman.info/wp-content/uploads/2023/05/background_white.png";
	field_background_src[1] = "https://likehuman.info/wp-content/uploads/2022/11/grass.png";	
	field_background_src[2] = "https://likehuman.info/wp-content/uploads/2023/05/background_suna.png";
	field_background_src[3] = "https://likehuman.info/wp-content/uploads/2023/05/background_doukutu.png";
	field_background_src[4] = "https://likehuman.info/wp-content/uploads/2023/06/background_doukutu_4.png";
	field_background_src[5] = "https://likehuman.info/wp-content/uploads/2023/05/background_yougan.png";
	field_background_src[6] = "https://likehuman.info/wp-content/uploads/2023/05/background_water_2.png";
	field_background_src[7] = "https://likehuman.info/wp-content/uploads/2023/05/background_water.png";
	field_background_src[8] = "https://likehuman.info/wp-content/uploads/2023/05/background_yuki.png";
	field_background_src[9] = "https://likehuman.info/wp-content/uploads/2023/05/background_yuki2.png";
	field_background_src[10] = "https://likehuman.info/wp-content/uploads/2023/05/background_hana.png";	
	field_background_src[11] = "https://likehuman.info/wp-content/uploads/2023/05/background_utyue.jpg";	
	field_background_src[12] = "https://likehuman.info/wp-content/uploads/2023/05/background_utyue.jpg";
	field_background_src[13] = "https://likehuman.info/wp-content/uploads/2023/06/encount_red.png";	
	field_background_src[14] = "https://likehuman.info/wp-content/uploads/2023/05/background_white.png";//無関係
	field_background_src[15] = "https://likehuman.info/wp-content/uploads/2023/06/jQueryでRPGゲームをつくってみた.jpg";//タイトル
	
	
	
	
	
	
/****************************************** 	
//音楽・効果音に関する処理
//効果音提供 オトロジック(https://otologic.jp) 
*******************************************/
	function bgmInitialization(){
		
		$('.bgm_and_se').remove();
		
		$('.control_container').after('<div class="bgm_and_se"><audio src="https://likehuman.info/wp-content/uploads/2022/11/Cyber14-1.mp3" class="bgm_battle_select"></audio><audio src="https://likehuman.info/wp-content/uploads/2022/11/village.mp3" class="bgm_village"></audio><audio src="https://likehuman.info/wp-content/uploads/2022/12/Cyber14-2.mp3" class="bgm_talk"></audio>		<audio src="https://likehuman.info/wp-content/uploads/2022/12/attack_sword_heavy.mp3" class="bgm_attack_sword_heavy"></audio><audio src="https://likehuman.info/wp-content/uploads/2022/12/attack_sword_short.mp3" class="bgm_attack_sword_short"></audio><audio src="https://likehuman.info/wp-content/uploads/2022/12/stick-attack_L.mp3" class="bgm_stick-attack_L"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/01/normal_battle.mp3" class="bgm_normal_battle"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/01/bossbattle.mp3" class="bgm_bossbattle"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/01/dageki_1.mp3" class="bgm_dageki_1"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/01/zenmetsu.mp3" class="bgm_zenmetsu"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/01/fanfare.mp3" class="bgm_fanfare"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/01/turn.mp3" class="bgm_turn"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/01/escape_run.mp3" class="bgm_escape"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/01/kaifuku_1.mp3" class="bgm_kaifuku_1"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/01/eisho_kaifuku_1.mp3" class="bgm_eisho_kaifuku_1"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/02/eisho_black_magic.mp3" class="bgm_eisho_black_magic_1"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/02/se_Thunder_1.mp3" class="bgm_magic_thunder_1"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/02/bad_buzzer.mp3" class="bgm_badbuzzer"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/02/bgm_revival.mp3" class="bgm_revival"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/03/bgm_three_hammers.mp3" class="bgm_three_hammers"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/03/shredded.mp3" class="bgm_shredded"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/03/bgm_shield.mp3" class="bgm_shield"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/03/bgm_earth_fire.mp3" class="bgm_earth_fire"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/03/bgm_kaengiri.mp3" class="bgm_kaengiri"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/03/bgm_ittouryoudan.mp3" class="bgm_ittouryoudan"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/03/bgm_mistgiri.mp3" class="bgm_mistgiri"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/03/bgm_jigengiri.mp3" class="bgm_jigengiri"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/03/bgm_forcefang.mp3" class="bgm_forcefang"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/03/bgm_heavenlyblow.mp3" class="bgm_heavenlyblow"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/03/bgm_hellbird.mp3" class="bgm_hellbird"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/04/bgm_broadsaucer_attack.mp3" class="bgm_broadsaucer"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/04/bgm_darksoldier.mp3" class="bgm_darksoldier"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/04/bgm_jquery_attack1.mp3" class="bgm_jquery_at_1"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/04/bgm_noddydragon_attack.mp3" class="bgm_noddydragon"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/04/bgm_Cerberus.mp3" class="bgm_cerberus"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/05/lasboss.mp3" class="bgm_lassboss"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/05/bgm_knockdown.mp3" class="bgm_knockdown"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/05/bgm_lastboss2.mp3" class="bgm_lassboss2_at"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/05/lassboss2battle_music.mp3" class="bgm_lassboss2"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/bgm_enncount.mp3" class="bgm_enncount"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/bgm_warp.mp3" class="bgm_warp"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/bgm_opening.mp3" class="bgm_opening"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/bgm_clear.mp3" class="bgm_clear"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/bgm_dan.mp3" class="bgm_dan"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/bgm_dan2.mp3" class="bgm_dan2"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/bgm_dan3.mp3" class="bgm_dan3"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/bgm_hime.mp3" class="bgm_hime"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/bgm_lasdan.mp3" class="bgm_lasdan"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/bgm_town.mp3" class="bgm_town"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/normal_battle2.mp3" class="normal_battle2"></audio><audio src="https://likehuman.info/wp-content/uploads/2023/06/bgm_end.mp3" class="bgm_end"></audio></div>');	
	}//<audio src="" class=""></audio>
	////<audio src="" class=""></audio>
	
	
	let battle_bgm = [".bgm_attack_sword_heavy",".bgm_attack_sword_short",".bgm_stick-attack_L",".bgm_three_hammers",".bgm_shredded",".bgm_earth_fire",".bgm_kaengiri",".bgm_mistgiri",".bgm_jigengiri",".bgm_ittouryoudan",".bgm_heavenlyblow",".bgm_hellbird"];
	let battle_bgm2 = [".bgm_battle_select",".bgm_turn",".bgm_badbuzzer"];
	let battle_bgm3 = [".bgm_dageki_1"];
	let battle_bgm4 = [".bgm_fanfare",".bgm_zenmetsu",".bgm_escape",".bgm_knockdown",".bgm_enncount",".bgm_warp"];
	let battle_bgm5 = [".bgm_eisho_kaifuku_1",".bgm_kaifuku_1",".bgm_eisho_black_magic_1",".bgm_magic_thunder_1",".bgm_revival",".bgm_shield",".bgm_forcefang"];
	let battle_bgm6 = [".bgm_jquery_at_1",".bgm_broadsaucer",".bgm_darksoldier",".bgm_cerberus",".bgm_noddydragon",".bgm_lassboss2_at"];
	let battle_bgm7 = [".bgm_normal_battle",".bgm_lassboss",".bgm_village",".bgm_lassboss2",".bgm_opening"];
	let battle_bgm8 = [".bgm_clear",".bgm_dan",".bgm_dan2",".bgm_dan3",".bgm_hime",".bgm_lasdan",".bgm_town"];
	let battle_bgm9 = [".normal_battle2",".bgm_end"];
	let bgm_save_item = battle_bgm7[2];
	let bgm_load_item = battle_bgm7[0];
	let se_item = battle_bgm[0]; 	
/************
* BGMの再生
* bgm1・・・とめる曲。bgm2・・・流す曲
************/
	function bgmPlayback(bgm1,bgm2){
		if(bgm1 !== -1)bgm_save_item = bgm1;
		if(bgm2 !== -1)bgm_load_item = bgm2;
		if(!bgm_village_flag){
			
		}
		else{
			//止める曲もしくはキープしておく曲
			if(bgm1 !== -1)$(bgm1).get(0).pause();
			 // 再生位置を先頭に戻す
			if(bgm1 !== -1)$(bgm1).currentTime = 0;
			//流す曲
			if(bgm2 !== -1)$(bgm2).currentTime = 0;
			if(bgm2 !== -1)$(bgm2).get(0).play();
			if(bgm2 !== -1)$(bgm2).get(0).loop = true;				
		}		
	}	
	//BGM初期化
	bgmInitialization();

/********	
//音楽のオンオフ
*********/
	$(".bgm_btn").on('click',function(){	
		if(!bgm_village_flag){
			bgm_village_flag = true
		}else{
			bgm_village_flag = false;
		}

		if(bgm_village_flag){
			$(bgm_load_item).get(0).play();
			$(bgm_load_item).get(0).loop = true;		
		}else{
			$(bgm_load_item).get(0).pause();
		}

	});	
/*********************	
//フィールドの音楽自動選択
*********************/
	function bgmFieldBgm(){
		if(id_current_field == 1)return battle_bgm8[6];
		if(id_current_field == 2)return battle_bgm7[2];
		if(id_current_field == 3)return battle_bgm7[2];
		if(id_current_field == 4)return battle_bgm8[1];
		if(id_current_field == 5)return battle_bgm8[1];
		if(id_current_field == 6)return battle_bgm8[2];
		if(id_current_field == 7)return battle_bgm8[2];
		if(id_current_field == 8)return battle_bgm8[3];
		if(id_current_field == 9)return battle_bgm8[3];
		if(id_current_field == 10 && number_of_laps < 2)return battle_bgm7[2];//戦闘背景rakuen
		if(id_current_field == 10 && number_of_laps >= 2)return battle_bgm8[4];//戦闘背景makai
		if(id_current_field == 11)return battle_bgm8[5];
		if(id_current_field == 12)return battle_bgm8[5];
	}	
	
/****************** 	
オブジェクトに関する変数

******************/
	let warp_statue_flag = false
	let obj_hit_flag = [false,false,false];
	let obj_hit_range = [[false,false,false,false],[false,false,false,false],[false,false,false,false]]; 
	let objecte_left = [(view_w / 2)];
	let objecte_top = [50];
	let objecte_position = [];
	let objecte_list = [];
	objecte_list[0] = ' style="position: absolute;" name="ワープ像" src="https://likehuman.info/wp-content/uploads/2023/05/zou2.png" >';

	//ワープ像の出現
	function warpSymbol(){
		    //まずはエフェクトを出現させる。このループは必要ないが、面倒だったのでそのまま流用した
			$.each(objecte_list, function(i, value) {
			$('.game_container').append('<div class="objecte_'+ i +'" style="position: absolute;"><img class="warp_ef_img" style="position: absolute;" name="warp_ef" src="' + partner_effect_list[1] + '"></div>');
			$('.warp_ef_img').css({
				'background-color':'transparent',
				'z-index' : 94,	
				'left' : objecte_left[i] - 35 +'px',
				'top' : objecte_top[i]  - 20 + 'px',
			});	
			//暫定でエフェクトのポジションを取得しておく。そうしないとヒット判定でポジション未設定のワープ像とのヒット判定でエラーとなる
			objecte_position[i] = $(".warp_ef_img").position();
			if(bgm_village_flag){
				$(battle_bgm5[0]).get(0).currentTime = 0;
				$(battle_bgm5[0]).get(0).play();
			}
			//エフェクトの後にワープ像をしゅつげんさせる
			setTimeout(function(){
				$('[class^="objecte_"]').remove();
				$('.game_container').append('<div class="objecte_'+ i +'" style="position: absolute;"><img class="object_image_' + i +'"' + objecte_list[i] + '</div>');	
				$('.object_image_'+i).css({
					'background-color':'transparent',
					'z-index' : 94,
					// 'width' : 100 + 'px',
					// 'height': 120  + 'px',			
					'left' : objecte_left[i] +'px',
					'top' : objecte_top[i] + 'px',
				});
				//ワープ像のポジションを取得。ワープ像とキャラのヒット判定をするため
				objecte_position[i] = $(".object_image_" + i).position();
				warp_statue_flag = true;
			},2000);
		})	
	}
		
	//ワープ像の削除
	function warpSymbolDel(){
		$('[class^="objecte_"]').remove();
		warp_statue_flag = false;
		obj_hit_flag = [false,false,false];
		obj_hit_range = [[false,false,false,false],[false,false,false,false],[false,false,false,false]]; 
		objecte_position = [];	
	}	
	
/************************************************************************    	
タイトルを表示
************************************************************************/
	titleSetting();
	function titleSetting(){
		$('.game_container').append('<div id="game_title" class="style21 fontStyle01 title_position">RPG game with jQuery<span>RPG game with jQuery</span><span>RPG game with jQuery</span></div>');
			
		$('#game_title').after('<div id="game_title2" class="title_position2"><div class="style16 fontStyle01 ">Start with A button<span>Start with A button</span><span>Start with A button</span></div></div>');	


		title_ef_timer = setInterval(function(){
			$("#game_title2").fadeOut(500).fadeIn(500);
		},1000);		
		
		$(".title_position").css({
			'left' : 10 +'px',
			'top' : 10 + 'px'
		});
		
		$(".title_position2").css({
			// 'left' : (view_w / 15) +'px',
			// 'top' : (view_h / 2) + 'px'			
			// 'left' : 30 +'%',
			'position': 'absolute',
			'top' : 50 + '%',
			'left' : 25 + '%',
			// 'margin-left': 'auto',
			// 'margin-right': 'auto'
		});
		
		
		//bgm1・・・とめる曲。bgm2・・・流す曲 指定がない場合はー1
		bgmPlayback(-1,battle_bgm7[4]);	
		
		
		//フィールドの画像設定
		fieldBackgroundChange(15);
	}	
	
	
/************************************************************************    	
フィールドの設定とメインキャラのムーブ処理
************************************************************************/		
	function mainCharacterSetting(){
		$('.game_container').append('<div class="main_character_move" style="position: absolute;"><img class="main_character" src="https://likehuman.info/wp-content/uploads/2022/11/ぴぽや_女001_勇者.png" alt="女性勇者">');

		//ワープ像の出現
		warpSymbol();
		
		//フィールドの画像設定(1は草原)
		fieldBackgroundChange(1);
		
		//メインキャラの初期位置を設定
		$(".main_character_move").css({
			'left' : mainchara_position_left +'px',
			'top' : mainchara_position_top + 'px'
		});
		//メインキャラの位置情報を取得
		get_position_maincharacter = $(".main_character_move").position();
		//メインキャラのムーブを開始
		mainCharaMove();	
		//サブキャラのシャッフル
		let character_set_data = (array) => {
			let character_list = [...array];
			for (let i = character_list.length - 1; i >= 0; i--) {
			  let random_num = Math.floor(Math.random() * (i + 1));
			  let tmp_data = character_list[i];
			  character_list[i] = character_list[random_num];
			  character_list[random_num] = tmp_data;
			}
			return character_list;
		}
		new_character_list = character_set_data([chara_1,chara_2,chara_3]);
	}
	
/************************** 
サブキャラの設定およびムーブ開始
***************************/
	function SubCharacterSetting(){
		//サブキャラの向きと初期位置の設定
		$.each(new_character_list, function(i, value) {	
			$('.main_character_move').after('<div class="character_move_'+ i +'" style="position: absolute;"><img class="character_' + i +'"' + new_character_list[i] + '</div>');		
			$('.character_'+i).css({
				'left' : character_position_left_1[i] +'px',
				'top' : character_position_top_1[i] + 'px',
				'clip':'rect('+
					character_rect_1[i][0] + 'px,' +
					character_rect_1[i][1] + 'px,' +
					character_rect_1[i][3] + 'px,' +
					character_rect_1[i][2] + 'px' +
				')'
			});
		})
		//サブキャラの位置情報を取得
		$.each(new_character_list, function(i, value) {
			get_position_character_1[i] = $(".character_move_"+i).position();
			//console.log(get_position_character_1[i]);
		})
		//サブキャラのムーブを開始
		$.each(new_character_list, function(i, value) {
			charaDirectionDecide_1(i);
		})
	}

	/* 
	サブキャラの向きを設定
	・サブキャラの向きを2秒間隔でランダムに変更
	*/
	function charaDirectionDecide_1(i){
		let rand_num = Math.floor(Math.random()*4);
		characterInstruct_1(i,rand_num);
		stop_chara_id_1[i] = setTimeout(charaDirectionDecide_1, 2000,i);	
	}
	
	/* 
	サブキャラの向きに応じた処理の実行
	*/
	function characterInstruct_1(i,ran){
		switch (ran){
			case 0 ://下向き
				clearTimeout(stop_move_id_1[i]);
				clearTimeout(stop_walk_id_1[i]);
				character_rect_1[i][0] = 0;
				character_rect_1[i][3] = 32;
				characterMove_1(i);
				characterWalkDown_1(i);
				break;
			case 1 ://左向き
				clearTimeout(stop_move_id_1[i]);				
				clearTimeout(stop_walk_id_1[i]);
				character_rect_1[i][0] = 32;
				character_rect_1[i][3] = 64;
				characterMove_1(i);				
				characterWalkLeft_1(i);			
				break;
			case 2 ://右向き
				clearTimeout(stop_move_id_1[i]);				
				clearTimeout(stop_walk_id_1[i]);
				character_rect_1[i][0] = 64;
				character_rect_1[i][3] = 96;
				characterMove_1(i);				
				characterWalkRight_1(i);				
				break;
			case 3 ://上向き
				clearTimeout(stop_move_id_1[i]);				
				clearTimeout(stop_walk_id_1[i]);
				character_rect_1[i][0] = 96;
				character_rect_1[i][3] = 128;
				characterMove_1(i);				
				characterWalkUp_1(i);		
				break;	
			default:
				break;				
		}
	}
	/* 
	サブキャラの向きに応じてキャラクターチップからスプライトを生成する
	*/
	function characterMove_1(i){
		stop_move_id_1[i] = setTimeout(characterMove_1, 200,i);
		//character_rect_1 = [32,32,0,64];//上、右、左、下
		$(".character_"+i).css({
			'top' : - character_rect_1[i][0] + 'px',
			'left': - character_rect_1[i][2] + 'px',
			'clip':'rect('+
				character_rect_1[i][0] + 'px,' +
				character_rect_1[i][1] + 'px,' +
				character_rect_1[i][3] + 'px,' +
				character_rect_1[i][2] + 'px' +
			')'
		});
		character_rect_1[i][1] += cut_percentage;//右
		character_rect_1[i][2] += cut_percentage;//左
		if(character_rect_1[i][1] == 128){
			character_rect_1[i][1] = 32;
			character_rect_1[i][2] = 0; 
		}
	}
	
	
	/*
	サブキャラを歩かせる
	・setTimeout関数で歩く速度を調整
	・歩く毎に位置を取得し、メインキャラとの当たり判定をチェックする
	・当たり判定があり、かつメインキャラが進行方向に存在した場合は歩くのを止める
	・当たり判定はあるが、進行方向にメインキャラが存在しなければ歩くのを継続する
	・以上をsetTimeoutで50ミリ秒間隔で繰り返す
	*/
	
	//サブキャラを下方向に歩かせる
	function characterWalkDown_1(i){
		stop_walk_id_1[i] = setTimeout(characterWalkDown_1, 50,i);
		get_position_character_1[i] = $(".character_move_"+i).position();			
		hitJudgment(i);		
		let hit = [false,false,false,false,false];
		if(hit_flag[i]){
			hit[0] = true;//当たっているか
			hit[1] = hit_range[i][0];//x座標→メインキャラの方が数値大
			hit[2] = hit_range[i][1];//x座標→メインキャラの方が数値小
			hit[3] = hit_range[i][2];//y座標→メインキャラの方が数値大
			hit[4] = hit_range[i][3];//y座標→メインキャラの方が数値小			
		}
		if(character_position_top_1[i] <= view_h && !hit[3]){
			character_position_top_1[i] += 1;
		}
		$(".character_move_"+i).css({
			'left' : character_position_left_1[i] + 'px',
			'top' : character_position_top_1[i] + 'px'
		});
	}
	
	//サブキャラを左方向に歩かせる
	function characterWalkLeft_1(i){
		stop_walk_id_1[i] = setTimeout(characterWalkLeft_1, 50,i);
		get_position_character_1[i] = $(".character_move_"+i).position();	
		hitJudgment(i);			
		let hit = [false,false,false,false,false];
		if(hit_flag[i]){
			hit[0] = true;//当たっているか
			hit[1] = hit_range[i][0];//x座標→メインキャラの方が数値大
			hit[2] = hit_range[i][1];//x座標→メインキャラの方が数値小
			hit[3] = hit_range[i][2];//y座標→メインキャラの方が数値大
			hit[4] = hit_range[i][3];//y座標→メインキャラの方が数値小			
		}
		if(character_position_left_1[i] >= 0 && !hit[2]){
			character_position_left_1[i] -= 1;		
		}
		$(".character_move_"+i).css({
			'left' : character_position_left_1[i] + 'px',
			'top' : character_position_top_1[i] + 'px'
		});	
	
	}
	//サブキャラを右方向に歩かせる
	function characterWalkRight_1(i){
		stop_walk_id_1[i] = setTimeout(characterWalkRight_1, 50,i);	
		get_position_character_1[i] = $(".character_move_"+i).position();			
		hitJudgment(i);	
		let hit = [false,false,false,false,false];
		if(hit_flag[i]){
			hit[0] = true;//当たっているか
			hit[1] = hit_range[i][0];//x座標→メインキャラの方が数値大
			hit[2] = hit_range[i][1];//x座標→メインキャラの方が数値小
			hit[3] = hit_range[i][2];//y座標→メインキャラの方が数値大
			hit[4] = hit_range[i][3];//y座標→メインキャラの方が数値小			
		}
		if(character_position_left_1[i] <= view_w && !hit[1]){
			character_position_left_1[i] += 1;	
		}	
		$(".character_move_"+i).css({
			'left' : character_position_left_1[i] + 'px',
			'top' : character_position_top_1[i] + 'px'
		});		
	}
	//サブキャラを上方向に歩かせる
	function characterWalkUp_1(i){
		stop_walk_id_1[i] = setTimeout(characterWalkUp_1, 50,i);
		get_position_character_1[i] = $(".character_move_"+i).position();		
		hitJudgment(i);	
		let hit = [false,false,false,false,false];
		if(hit_flag[i]){
			hit[0] = true;//当たっているか
			hit[1] = hit_range[i][0];//x座標→メインキャラの方が数値大
			hit[2] = hit_range[i][1];//x座標→メインキャラの方が数値小
			hit[3] = hit_range[i][2];//y座標→メインキャラの方が数値大
			hit[4] = hit_range[i][3];//y座標→メインキャラの方が数値小			
		}
		if(character_position_top_1[i] >= 10 && !hit[4]){
			character_position_top_1[i] -= 1;
		}
		$(".character_move_"+i).css({
			'left' : character_position_left_1[i] + 'px',
			'top' : character_position_top_1[i] + 'px'
		});			
	}
	

	/****************************************************
	メインキャラの向きと身体の動き
	・キャラクターチップを切り抜き、スプライトを生成する
	・setTimeout関数でスプライトに動きをつける
	*****************************************************/
	function mainCharaMove(){
		stop_move_mainchar_id = setTimeout(mainCharaMove, 200);	
		$(".main_character").css({
			'top' : - mainchara_rect_top + 'px',
			'left': - mainchara_rect_left + 'px',
			'clip':'rect('+
				mainchara_rect_top + 'px,' +
				mainchara_rect_right + 'px,' +
				mainchara_rect_bottom + 'px,' +
				mainchara_rect_left + 'px' +
			')'
		});
		mainchara_rect_right += cut_percentage;
		mainchara_rect_left += cut_percentage;	
		if(mainchara_rect_right == 128){
			mainchara_rect_right = 32;
			mainchara_rect_left = 0; 
		}
	}
	
	
	//十字キーの下ボタンを押下したとき
	$(".down_btn").on('mousedown touchstart',function(event){
		event.preventDefault();
		if(title_flag){
			title_flag = false;
			//タイトルを削除
			clearInterval(title_ef_timer);
			$('[id^="game_title"]').remove();	
			//bgm1・・・とめる曲。bgm2・・・流す曲 指定がない場合はー1
			bgmPlayback(battle_bgm7[4],battle_bgm8[6]);		
			mainCharacterSetting();		
			SubCharacterSetting();
		}			
		if(battle_flag){
			if(battle_stage_1){
				b_index += 2;
				if(tactics.length - 1 < b_index)b_index = tactics.length - 1
				$('[id^="tactics_"]').css('background-color', 'black');
				$('#tactics_'+ b_index).css('background-color', 'dimgrey');
			}
			if(battle_stage_2){
				skill_index += 1;
				if(4 <= skill_index)skill_index = 3;
				skillDescription();
				$('[id^="command_"]').css('background-color', 'black');
				$('#command_'+ skill_index).css('background-color', 'dimgrey');
			}
			if(battle_stage_3){
				if(battle_stage_3_1){
					recovery_index += 1;
					if(recovery_index >= 4)recovery_index = 3;
					recoveryArrowSettings(recovery_index);
				}else{	
					monster_index += 1;
					if(monster_list.length - 1 < monster_index)monster_index = monster_list.length - 1;				
					monsterSelect(monster_index);
					$('[class^="m_name_"]').css('background-color', 'black');
					$('.m_name_'+ monster_index).css('background-color', 'dimgrey');
				}
			}
			//イベント名のチェック
			//console.log(event.type);	
		}else{
			clearTimeout(stop_move_mainchar_id);
			//会話を止める
			if(conversationv_flag)endOfConversation();
			//下を向いたキャラクター画像をキャラクターチップから切り抜くための座標設定
			mainchara_rect_top = 0;
			mainchara_rect_bottom = 32;
			//切り抜いた画像に動きをつける
			mainCharaMove();
			//下に歩かせる
			mainCharaWalkDown();
		}
	});
	//十字キーの左ボタンを押下したとき	
	$(".left_btn").on('mousedown touchstart', function(event){
		event.preventDefault();
		if(title_flag){
			title_flag = false;
			//タイトルを削除
			clearInterval(title_ef_timer);
			$('[id^="game_title"]').remove();	
			//bgm1・・・とめる曲。bgm2・・・流す曲 指定がない場合はー1
			bgmPlayback(battle_bgm7[4],battle_bgm8[6]);	
			mainCharacterSetting();		
			SubCharacterSetting();
		}			
		if(battle_flag){
			if(battle_stage_1){
				b_index -= 1;
				if(b_index < 0)b_index = 0;
				$('[id^="tactics_"]').css('background-color', 'black');
				$('#tactics_'+ b_index).css('background-color', 'dimgrey');
			}
			if(battle_stage_2){
				skill_index -= 1;
				if(skill_index < 0)skill_index = 0;	
				skillDescription();				
				$('[id^="command_"]').css('background-color', 'black');
				$('#command_'+ skill_index).css('background-color', 'dimgrey');
			}
			if(battle_stage_3 && !battle_stage_3_1){
				monster_index -= 1;
				if(monster_index < 0)monster_index = 0;
				monsterSelect(monster_index);
				$('[class^="m_name_"]').css('background-color', 'black');
				$('.m_name_'+ monster_index).css('background-color', 'dimgrey');	
			}

		}else{
			clearTimeout(stop_move_mainchar_id);
			if(conversationv_flag)endOfConversation();		
			mainchara_rect_top = 32;
			mainchara_rect_bottom = 64;
			mainCharaMove();		
			mainCharaWalkLeft();		
		}
	});
	//十字キーの右ボタンを押下したとき		
	$(".right_btn").on('mousedown touchstart', function(event){
		event.preventDefault();
		if(title_flag){
			title_flag = false;
			//タイトルを削除
			clearInterval(title_ef_timer);
			$('[id^="game_title"]').remove();	
			//bgm1・・・とめる曲。bgm2・・・流す曲 指定がない場合はー1
			bgmPlayback(battle_bgm7[4],battle_bgm8[6]);	
			mainCharacterSetting();		
			SubCharacterSetting();
		}	
		if(battle_flag){
			if(battle_stage_1){
				b_index += 1;
				if(tactics.length - 1 < b_index)b_index = tactics.length-1
				$('[id^="tactics_"]').css('background-color', 'black');
				$('#tactics_'+ b_index).css('background-color', 'dimgrey');
			}
			if(battle_stage_2){
				skill_index += 1;
				if(4 <= skill_index)skill_index = 3;
				skillDescription();				
				$('[id^="command_"]').css('background-color', 'black');
				$('#command_'+ skill_index).css('background-color', 'dimgrey');
			}			
			if(battle_stage_3 && !battle_stage_3_1){
				monster_index += 1;
				if(monster_list.length - 1 < monster_index)monster_index = monster_list.length - 1;				
				monsterSelect(monster_index);
				$('[class^="m_name_"]').css('background-color', 'black');
				$('.m_name_'+ monster_index).css('background-color', 'dimgrey');
			}			
		}else{
			clearTimeout(stop_move_mainchar_id);
			if(conversationv_flag)endOfConversation();		
			mainchara_rect_top = 64;
			mainchara_rect_bottom = 96;
			mainCharaMove();		
			mainCharaWalkRight();		
		}
	});
	//十字キーの上ボタンを押下したとき		
	$(".up_btn").on('mousedown touchstart', function(event){
		event.preventDefault();
		if(title_flag){
			title_flag = false;
			//タイトルを削除
			clearInterval(title_ef_timer);
			$('[id^="game_title"]').remove();	
			//bgm1・・・とめる曲。bgm2・・・流す曲 指定がない場合はー1
			bgmPlayback(battle_bgm7[4],battle_bgm8[6]);	
			mainCharacterSetting();		
			SubCharacterSetting();
		}	
		if(battle_flag){
			if(battle_stage_1){
				b_index -= 2;
				if(b_index < 0)b_index = 0;
				$('[id^="tactics_"]').css('background-color', 'black');
				$('#tactics_'+ b_index).css('background-color', 'dimgrey');
			}
			if(battle_stage_2){
				skill_index -= 1;
				if(skill_index < 0)skill_index = 0;
				skillDescription();				
				$('[id^="command_"]').css('background-color', 'black');
				$('#command_'+ skill_index).css('background-color', 'dimgrey');
			}			
			if(battle_stage_3){
				if(battle_stage_3_1){
					recovery_index -= 1;
					if(recovery_index <= 0)recovery_index = 0;
					recoveryArrowSettings(recovery_index);
				}else{	
					monster_index -= 1;
					if(monster_index < 0)monster_index = 0;
					monsterSelect(monster_index);
					$('[class^="m_name_"]').css('background-color', 'black');
					$('.m_name_'+ monster_index).css('background-color', 'dimgrey');
				}				
			}			
		}else{
			clearTimeout(stop_move_mainchar_id);
			if(conversationv_flag)endOfConversation();		
			mainchara_rect_top = 96;
			mainchara_rect_bottom = 128;
			mainCharaMove();		
			mainCharaWalkUp();
		}		
	});	
	//十字キーを離すと同時にsettimeout関数を止め、歩くのを止めさせる
	$(".down_btn").on('mouseup mouseleave touchend', function(){
		if(!battle_flag)clearTimeout(stop_down_mainchar_id);
	});
	$(".left_btn").on('mouseup mouseleave touchend', function(){
		if(!battle_flag)clearTimeout(stop_left_mainchar_id);
	});
	$(".right_btn").on('mouseup mouseleave touchend', function(){
		if(!battle_flag)clearTimeout(stop_right_mainchar_id);
	});	
	$(".up_btn").on('mouseup mouseleave touchend', function(){
		if(!battle_flag)clearTimeout(stop_up_mainchar_id);
	});
	
	/****************************************************
	メインキャラを歩かせる
	・setTimeout関数で歩く速度を調整
	・歩く毎に位置を取得し、サブキャラとの当たり判定をチェックする
	・当たり判定があり、かつサブキャラが進行方向に存在した場合は歩くのを止める
	・当たり判定はあるが、進行方向にサブキャラが存在しなければ歩くのを継続する
	*****************************************************/
		
/********************** 
メインキャラを下方向に歩かせる
**********************/
	function mainCharaWalkDown(){
		//フィールでヒットした(ぶつかった)対象IDを格納する変数の初期化
		target_field_chara = 0;		
		let hit = [false,false,false,false,false];
		get_position_maincharacter = $(".main_character_move").position();		
		$.each(new_character_list, function(i, value) {
			hitJudgment(i);
			if(hit_flag[i]){
				hit[0] = true;//当たっているか
				hit[1] = hit_range[i][0];//x座標→メインキャラの方が数値大
				hit[2] = hit_range[i][1];//x座標→メインキャラの方が数値小
				hit[3] = hit_range[i][2];//y座標→メインキャラの方が数値大
				hit[4] = hit_range[i][3];//y座標→メインキャラの方が数値小
				target_field_chara = new_character_list.indexOf(new_character_list[i]);			
			}
		});

		//オブジェクトのヒット判定
		let ob_hit = [false,false,false,false,false];
		if(warp_statue_flag)$.each(objecte_list, function(i, value) {
			objectHitJudgment(i);
			if(obj_hit_flag[i]){
				ob_hit[0] = true;//当たっているか
				ob_hit[1] = obj_hit_range[i][0];//x座標→メインキャラの方が数値大
				ob_hit[2] = obj_hit_range[i][1];//x座標→メインキャラの方が数値小
				ob_hit[3] = obj_hit_range[i][2];//y座標→メインキャラの方が数値大
				ob_hit[4] = obj_hit_range[i][3];//y座標→メインキャラの方が数値小
			}
		});			
		if(mainchara_position_top <= view_h && !hit[4] && !ob_hit[4])mainchara_position_top += 1;
		stop_down_mainchar_id = setTimeout(() => {
			mainCharaWalkDown();
		},1);
		mainCharaPosition();
		if(hit[0] && id_current_field !== 1){
			if(id_current_field == 10 || id_current_field == 12){
				//楽園の時は何もしない
			}else{
				if(!battle_flag){//バトル開始のときは実行されない。スレッドによる影響で実行が重複されないようにする	
					clearTimeout(stop_down_mainchar_id);
					encounterEffect();//階層が2以上なら戦闘開始※1階層は除外
				}
			}
		}		
		//if(mainchara_position_top >= view_h)battleMode();
	}
	
/********************** 
メインキャラを左方向に歩かせる
**********************/
	function mainCharaWalkLeft(){
		//フィールでヒットした(ぶつかった)対象IDを格納する変数の初期化
		target_field_chara = 0;		
		let hit = [false,false,false,false,false];
		get_position_maincharacter = $(".main_character_move").position();		
		$.each(new_character_list, function(i, value) {
			hitJudgment(i);
			if(hit_flag[i]){
				hit[0] = true;//当たっているか
				hit[1] = hit_range[i][0];//x座標→メインキャラの方が数値大
				hit[2] = hit_range[i][1];//x座標→メインキャラの方が数値小
				hit[3] = hit_range[i][2];//y座標→メインキャラの方が数値大
				hit[4] = hit_range[i][3];//y座標→メインキャラの方が数値小	
				target_field_chara = new_character_list.indexOf(new_character_list[i]);			
			}
		});
		///if(hit[0] && id_current_field !== 1 && id_current_field !== 10)battleMode();//階層が2以上なら戦闘開始※1と9階層は除外
		//オブジェクトのヒット判定
		let ob_hit = [false,false,false,false,false];
		if(warp_statue_flag)$.each(objecte_list, function(i, value) {
			objectHitJudgment(i);
			if(obj_hit_flag[i]){
				ob_hit[0] = true;//当たっているか
				ob_hit[1] = obj_hit_range[i][0];//x座標→メインキャラの方が数値大
				ob_hit[2] = obj_hit_range[i][1];//x座標→メインキャラの方が数値小
				ob_hit[3] = obj_hit_range[i][2];//y座標→メインキャラの方が数値大
				ob_hit[4] = obj_hit_range[i][3];//y座標→メインキャラの方が数値小			
			}
		});		
		if(mainchara_position_left >= 0 && !hit[1] && !ob_hit[1])mainchara_position_left -= 1;
		stop_left_mainchar_id = setTimeout(() => {
			mainCharaWalkLeft();
		},1);
		mainCharaPosition();
		if(hit[0] && id_current_field !== 1){
			if(id_current_field == 10 || id_current_field == 12){
				//楽園の時は何もしない
			}else{
				if(!battle_flag){//バトル開始のときは実行されない。スレッドによる影響で実行が重複されないようにする	
					clearTimeout(stop_left_mainchar_id);
					encounterEffect();//階層が2以上なら戦闘開始※1階層は除外
				}
			}
		}		
	}
	
/********************** 
メインキャラを右方向に歩かせる
**********************/
	function mainCharaWalkRight(){
		//フィールでヒットした(ぶつかった)対象IDを格納する変数の初期化
		target_field_chara = 0;		
		let hit = [false,false,false,false,false];
		get_position_maincharacter = $(".main_character_move").position();		
		$.each(new_character_list, function(i, value) {
			hitJudgment(i);
			if(hit_flag[i]){
				hit[0] = true;//当たっているか
				hit[1] = hit_range[i][0];//x座標→メインキャラの方が数値大
				hit[2] = hit_range[i][1];//x座標→メインキャラの方が数値小
				hit[3] = hit_range[i][2];//y座標→メインキャラの方が数値大
				hit[4] = hit_range[i][3];//y座標→メインキャラの方が数値小
				target_field_chara = new_character_list.indexOf(new_character_list[i]);			
			}
		});
		//if(hit[0] && id_current_field !== 1 && id_current_field !== 10)battleMode();//階層が2以上なら戦闘開始※1と9階層は除外
		//オブジェクトのヒット判定
		let ob_hit = [false,false,false,false,false];
		if(warp_statue_flag)$.each(objecte_list, function(i, value) {
			objectHitJudgment(i);
			if(obj_hit_flag[i]){
				ob_hit[0] = true;//当たっているか
				ob_hit[1] = obj_hit_range[i][0];//x座標→メインキャラの方が数値大
				ob_hit[2] = obj_hit_range[i][1];//x座標→メインキャラの方が数値小
				ob_hit[3] = obj_hit_range[i][2];//y座標→メインキャラの方が数値大
				ob_hit[4] = obj_hit_range[i][3];//y座標→メインキャラの方が数値小			
			}
		});			
		if(mainchara_position_left <= view_w && !hit[2] && !ob_hit[2])mainchara_position_left += 1;
		
		stop_right_mainchar_id = setTimeout(() => {
			mainCharaWalkRight();
		},1);
		mainCharaPosition();
		if(hit[0] && id_current_field !== 1){
			if(id_current_field == 10 || id_current_field == 12){
				//楽園の時は何もしない
			}else{
				if(!battle_flag){//バトル開始のときは実行されない。スレッドによる影響で実行が重複されないようにする	
					clearTimeout(stop_right_mainchar_id);
					encounterEffect();//階層が2以上なら戦闘開始※1階層は除外
				}
			}
		}	
	}
	
/********************** 
メインキャラを上方向に歩かせる
**********************/
	function mainCharaWalkUp(){
		//フィールでヒットした(ぶつかった)対象IDを格納する変数の初期化
		target_field_chara = 0;
		let hit = [false,false,false,false,false];
		get_position_maincharacter = $(".main_character_move").position();		
		$.each(new_character_list, function(i, value) {
			hitJudgment(i);
			if(hit_flag[i]){
				hit[0] = true;//当たっているか
				hit[1] = hit_range[i][0];//x座標→メインキャラの方が数値大
				hit[2] = hit_range[i][1];//x座標→メインキャラの方が数値小
				hit[3] = hit_range[i][2];//y座標→メインキャラの方が数値大
				hit[4] = hit_range[i][3];//y座標→メインキャラの方が数値小	
				target_field_chara = new_character_list.indexOf(new_character_list[i]);			
			}
		});
		//if(hit[0] && id_current_field !== 1 && id_current_field !== 10)battleMode();//階層が2以上なら戦闘開始※1と9階層は除外
		//オブジェクトのヒット判定
		let ob_hit = [false,false,false,false,false];
		if(warp_statue_flag)$.each(objecte_list, function(i, value) {
			objectHitJudgment(i);
			if(obj_hit_flag[i]){
				ob_hit[0] = true;//当たっているか
				ob_hit[1] = obj_hit_range[i][0];//x座標→メインキャラの方が数値大
				ob_hit[2] = obj_hit_range[i][1];//x座標→メインキャラの方が数値小
				ob_hit[3] = obj_hit_range[i][2];//y座標→メインキャラの方が数値大
				ob_hit[4] = obj_hit_range[i][3];//y座標→メインキャラの方が数値小			
			}
			
		});	

		if(mainchara_position_top >= 10 && !hit[3] && !ob_hit[3])mainchara_position_top -= 1;
		stop_up_mainchar_id = setTimeout(() => {
			mainCharaWalkUp();
		},1);
		mainCharaPosition();
		if(hit[0] && id_current_field !== 1){
			if(id_current_field == 10 || id_current_field == 12){
				//楽園の時は何もしない
			}else{
				if(!battle_flag){//バトル開始のときは実行されない。スレッドによる影響で実行が重複されないようにする	
					clearTimeout(stop_up_mainchar_id);
					encounterEffect();//階層が2以上なら戦闘開始※1階層は除外
				}
			}
		}		
	}
	//メインキャラの描画(歩かせる)
	function mainCharaPosition(){
		$(".main_character_move").css({
			'left' : mainchara_position_left + 'px',
			'top' : mainchara_position_top + 'px'
		});
	}
	/****************************************************
	当たり判定
	・メインキャラの半径30px範囲内にサブキャラが存在しているかどうか
	・存在している(当たっている)場合は、その対象(サブキャラ)が存在している方角の確認
	*****************************************************/	
	function hitJudgment(i){
		let main_left = get_position_maincharacter.left;
		let main_top = get_position_maincharacter.top;
		let chara_1_left = get_position_character_1[i].left;
		let chara_1_top = get_position_character_1[i].top;
		let hit_more_once = false;
		
		//当たり判定
		if(main_left >= chara_1_left - 30 && main_left <= chara_1_left + 30 && main_top >= chara_1_top - 30 && main_top <= chara_1_top + 30 ){
			//当たっているかどうか
			hit_flag[i] = true;
			//サブキャラがメインキャラの左にいる
			if(main_left >= chara_1_left)hit_range[i][0] = true;
			//サブキャラがメインキャラの右にいる
			if(main_left <= chara_1_left)hit_range[i][1] = true;
			//サブキャラがメインキャラの上にいる
			if(main_top >= chara_1_top)hit_range[i][2] = true;
			//サブキャラがメインキャラの下にいる
			if(main_top <= chara_1_top)hit_range[i][3] = true;
		}else{//当たり判定がなければ初期化
			hit_flag[i] = false;
			hit_target = false;
			hit_range[i][0] = false;
			hit_range[i][1] = false;
			hit_range[i][2] = false;
			hit_range[i][3] = false;			
		}

		
		
		//会話範囲判定(会話できる距離にサブキャラがいるかどうか)
		if(main_left >= chara_1_left - 60 && main_left <= chara_1_left + 60 && main_top >= chara_1_top - 60 && main_top <= chara_1_top + 60){
			talk_range[i] = true;
		}else{
			talk_range[i] = false;		
		}		

	}
	
	/****************************************************
	オブジェクトに対する当たり判定
	・メインキャラの半径30px範囲内にオブジェクトが存在しているかどうか
	・存在している(当たっている)場合は、その対象(オブジェクト)が存在している方角の確認
	*****************************************************/		
	function objectHitJudgment(i){
		let main_left = get_position_maincharacter.left;
		let main_top = get_position_maincharacter.top;		
		let ob_left = objecte_position[i].left;
		let ob_top = objecte_position[i].top;		
		//当たり判定
		if( main_left >= ob_left - 30 && main_left <= ob_left + 30 && main_top >= ob_top - 30 && main_top <= ob_top + 30){	
		    //オブジェクトに当たっているかどうか
			obj_hit_flag[i] = true;
			//オブジェクトがメインキャラの左にある
			if(main_left >= ob_left)obj_hit_range[i][0] = true;
			//オブジェクトがメインキャラの右にある
			if(main_left <= ob_left)obj_hit_range[i][1] = true;
			//オブジェクトがメインキャラの上にある
			if(main_top >= ob_top)obj_hit_range[i][2] = true;
			//オブジェクトがメインキャラの下にある
			if(main_top <= ob_top)obj_hit_range[i][3] = true;
		}else{			
			obj_hit_flag[i] = false;
			obj_hit_range[i][0] = false;
			obj_hit_range[i][1] = false;
			obj_hit_range[i][2] = false;
			obj_hit_range[i][3] = false;
		}		
	}
	/****************************************************
	* (フィールド用)バックグラウンドを変更する
	*****************************************************/
	//1grann,2suna,3doukutu,4doukutu_2,5yougan,6water,7water_2,8yuki,9yuki_2,10hana,11utyuu	
	function fieldBackgroundChange(g_src){
		if(number_of_laps >= 2 && id_current_field == 9){
			//2周目の階層10専用
			field_background_src[g_src] = "https://likehuman.info/wp-content/uploads/2023/05/background_doukutu_2.png";
		}
			
		if(g_src !== 0)id_current_field = g_src;
		
		if(g_src !== 15){
			//オープニング画像以外は下記の通り
			$('.game_container').css({	
				'background-image': 'url(' + field_background_src[g_src] + ')',	
				'background-repeat': 'round',
				'z-index': '90',		
				//タイトルの時、使用したCSS設定を無効化	
				'background-size': 'auto',				
				'background-position': '0% 0%',				
				'box-shadow':'initial'
				// 'position': 'relative',
				// 'align-items': 'center',	
				// 'height': '300px',
				//'width': '100%',
				// 'margin-bottom': '0',
				//'background-size': 'cover',
			});	
		}else{
			//オープニング画像は少し手を加える
			$('.game_container').css({	
				'background-image': 'url(' + field_background_src[g_src] + ')',	
				'background-size': '40%',
				'background-repeat': 'no-repeat',
				'background-position': 'center',
				'box-shadow': 'inset 0 0 10px 15px #FFF',
				'z-index': '90'				
			});				
		}	
	}	
	/****************************************************
	画面の点滅処理とオブジェクトに関するイベント
	*****************************************************/	
	function subbackGroundChange(){
		//背景を白にする。後々コンテンツ自体を透明にするので、意味ないかも
		$('.game_container').css({	
			'background-image': 'url(' + field_background_src[0] + ')',	
			'background-repeat': 'round',
			'z-index': '90'				
		});
		$('.game_container').css({'opacity': '1'});
		//メインキャラ以外を透明にする
		$('[class^="character_move_"]').hide();
		//1から2へと変化する数値を利用しているだけなのでopacity:1以外でもOK
		$('.game_container').animate({opacity: 0 },{
			duration:2000,
			//stepで時間に比例して変化する内容を記述
			step:function(o){
			//1から2へと変化する数値を利用しているだけなのでopacity:1とかじゃなくてもOK。暫定でこのようにしているだけ
			$(this).css({
				//複数指定する場合⇒⇒transform :'scale(' + o * 10 + ',' + o * 10 + ') translate(' + view_w / 2 * o + 'px,'+ 100 * o + 'px)',
				//transform :'scale(' + o * 10 + ',' + o * 5 + ')'
				});
			},
			//完了処理。メインキャラ以外の透明度を元に戻す
			complete:function(){$('.game_container').css('opacity', '1');}
		});
		//BGM
		setTimeout(function(){
			if(bgm_village_flag){
				$(battle_bgm4[5]).get(0).currentTime = 0;
				$(battle_bgm4[5]).get(0).play();
			}
		},900);
	}	
	function objectEventRange(i){
		//像のオブジェクト(0)に触れた時はワープする
		if(i == 0  && continuous_click_prevention == 1){
			//会話中だったら削除
			$(".conversation").remove();
			$(".conversation_container").remove();
			conversationv_flag = false;
			//画面を白くさせる
			subbackGroundChange();
			setTimeout(function(){
				//clearTimeout(stop_groundchange);
				//下はフィールド画像と関連付けするための参考データ
				//フィールドカレントID・・・1grass,2suna,3doukutu,4doukutu_2,5yougan,6water,7water_2,8yuki,9yuki_2,10hana,11utyuu	,,12utyuu	
				if(id_current_field == 1){
					fieldCharacterSetting();
					fieldBackgroundChange(2);//ここでid_current_field「フィールドカレントID」が決まる
					warpSymbolDel();
					bgmPlayback(bgm_load_item,bgmFieldBgm());			
				}	
				else if(id_current_field == 2){
					fieldCharacterSetting();
					fieldBackgroundChange(3);//ここでid_current_field「フィールドカレントID」が決まる
					warpSymbolDel();
					bgmPlayback(bgm_load_item,bgmFieldBgm());				
				}
				else if(id_current_field == 3){
					fieldCharacterSetting();
					fieldBackgroundChange(4);//ここでid_current_field「フィールドカレントID」が決まる
					warpSymbolDel();
					bgmPlayback(bgm_load_item,bgmFieldBgm());						
				}
				else if(id_current_field == 4){
					fieldCharacterSetting();
					fieldBackgroundChange(5);//ここでid_current_field「フィールドカレントID」が決まる
					warpSymbolDel();
					bgmPlayback(bgm_load_item,bgmFieldBgm());				
				}
				else if(id_current_field == 5){
					fieldCharacterSetting();
					fieldBackgroundChange(6);//ここでid_current_field「フィールドカレントID」が決まる
					warpSymbolDel();
					bgmPlayback(bgm_load_item,bgmFieldBgm());				
				}
				else if(id_current_field == 6){
					fieldCharacterSetting();
					fieldBackgroundChange(7);//ここでid_current_field「フィールドカレントID」が決まる
					warpSymbolDel();
					bgmPlayback(bgm_load_item,bgmFieldBgm());					
				}
				else if(id_current_field == 7){
					fieldCharacterSetting();
					fieldBackgroundChange(8);//ここでid_current_field「フィールドカレントID」が決まる
					warpSymbolDel();
					bgmPlayback(bgm_load_item,bgmFieldBgm());					
				}
				else if(id_current_field == 8){
					fieldCharacterSetting();
					fieldBackgroundChange(9);//ここでid_current_field「フィールドカレントID」が決まる
					warpSymbolDel();
					bgmPlayback(bgm_load_item,bgmFieldBgm());				
				}
				else if(id_current_field == 9){
					fieldCharacterSetting();
					fieldBackgroundChange(10);//ここでid_current_field「フィールドカレントID」が決まる
					bgmPlayback(bgm_load_item,bgmFieldBgm());					
				}
				else if(id_current_field == 10){
					fieldCharacterSetting();
					fieldBackgroundChange(11);//ここでid_current_field「フィールドカレントID」が決まる
					warpSymbolDel();			
					bgmPlayback(bgm_load_item,bgmFieldBgm());				
				}
				else if(id_current_field == 11){
					fieldCharacterSetting();
					fieldBackgroundChange(12);//ここでid_current_field「フィールドカレントID」が決まる
					warpSymbolDel();
					bgmPlayback(bgm_load_item,bgmFieldBgm());								
				}
				else if(id_current_field == 12){
					//2周目のカウント
					number_of_laps += 1;						
					fieldCharacterSetting();
					fieldBackgroundChange(1);//ここでid_current_field「フィールドカレントID」が決まる
					bgmPlayback(bgm_load_item,bgmFieldBgm());											
				}else{
					fieldCharacterSetting();
					fieldBackgroundChange(1);//ここでid_current_field「フィールドカレントID」が決まる
					bgmPlayback(bgm_load_item,bgmFieldBgm());								
					
				}
				//オブジェクト連続クリック防止措置を解除
				continuous_click_prevention = 0;					
			},2100);
		}
	}
/*****************************************************
フィールドキャラクター設定
・現階層フィールド上のキャラクターおよびモンスターの初期化⇒削除
・次階層フィールド上のキャラクター配列の設定
・次階層フィールド上のキャラクター変数の初期化
・設定したキャラクターのムーブを開始
*****************************************************/	
	function fieldCharacterSetting(){
		//削除するけど一応、その前にキャラの動きを止める(スレッド処理を止める)
		$.each(new_character_list, function(i, value) {
			clearTimeout(stop_chara_id_1[i]);			
			clearTimeout(stop_walk_id_1[i]);
			clearTimeout(stop_move_id_1[i]);
		});
		clearTimeout(stop_down_mainchar_id);
		clearTimeout(stop_right_mainchar_id);
		clearTimeout(stop_left_mainchar_id);
		clearTimeout(stop_down_mainchar_id);		
		clearTimeout(stop_move_mainchar_id);
		//どうせ消すのだが、一応初期化して消す
		fieldDataInitialization(new_character_list.length);		
		new_character_list = [];
		$('[class^="character_move_"]').remove();
		$('[class^="character_"]').remove();
		if(id_current_field == 1)new_character_list = [monster_1,monster_2,monster_3];	
		if(id_current_field == 2)new_character_list = [monster_4,monster_5,monster_6];				
		if(id_current_field == 3)new_character_list = [monster_7,monster_8,monster_1];
		if(id_current_field == 4)new_character_list = [monster_2,monster_3,monster_4];
		if(id_current_field == 5)new_character_list = [monster_5,monster_6,monster_7];
		if(id_current_field == 6)new_character_list = [monster_8,monster_1,monster_2];
		if(id_current_field == 7)new_character_list = [monster_3,monster_4,monster_5];
		if(id_current_field == 8)new_character_list = [monster_6,monster_7,monster_8];
		if(id_current_field == 9)new_character_list = [chara_4];
		if(id_current_field == 10)new_character_list = [monster_9,monster_10,monster_11];	
		if(id_current_field == 11)new_character_list = [lassboss];	
		if(id_current_field == 12)new_character_list = [chara_1,chara_2,chara_3];			
		
		//キャラクターおよびモンスター数に相当する変数を設定
		if(new_character_list.length == 3){
			fieldDataInitialization(new_character_list.length);			
		}	
		else if(new_character_list.length == 2){
			fieldDataInitialization(new_character_list.length);		
		}	
		else if(new_character_list.length == 1){
			fieldDataInitialization(new_character_list.length);			
		}	
		else{
			
		}	
		//フィールドでぶつかったモンスターIDを格納する変数を初期化
		target_field_chara = 0;
		//フィールドを歩くモンスターならびにサブキャラの設定とムーブ
		SubCharacterSetting();		
	}	
/*****************************************************
バトル終了後、エンカウントしたターゲットの削除または現状維持
・勝利した場合は現階層フィールド上のターゲット(キャラクターおよびモンスター)の⇒削除⇒ムーブ開始
・逃走した場合はターゲットの配列はそのままにして変数だけを初期化
・モンスターではなくキャラクターの場合は配列要素を全て削除←←←バトル終了後の関数のため、これが実行されることはない
*****************************************************/		
	function deleteFieldCharacter(){
		//1階層と9階層以外はフィールド上のモンスターを削除する
		if(id_current_field !== 1 && id_current_field !== 10){
			//一旦キャラクターの動きを止める
			$.each(new_character_list, function(i, value) {
				clearTimeout(stop_chara_id_1[i]);			
				clearTimeout(stop_walk_id_1[i]);
				clearTimeout(stop_move_id_1[i]);
			});
			clearTimeout(stop_down_mainchar_id);
			clearTimeout(stop_right_mainchar_id);
			clearTimeout(stop_left_mainchar_id);
			clearTimeout(stop_down_mainchar_id);		
			clearTimeout(stop_move_mainchar_id);			
			if(victory_flag){
				let kill_m = new_character_list.indexOf(target_field_chara);
				//フィールドモンスター配列からターゲットを間引く
				new_character_list.splice( kill_m, 1 );
				$('[class^="character_move_"]').remove();
				$('[class^="character_"]').remove();
				//フィールドモンスター配列を一掃したときは・・・
				if(new_character_list.length == 0){
					//フィールド上のモンスターを全滅させていたら配列を初期化しておく
					new_character_list = [];
					//フィールドでぶつかったモンスターIDを格納する変数を初期化
					target_field_chara = 0;
					fieldDataInitialization(0);
					if(id_current_field !== 10 && id_current_field !== 1 )warpSymbol();
				}else{//一掃できていないときは・・・
					//フィールドでぶつかったモンスターIDを格納する変数を初期化
					target_field_chara = 0;
					//フィールドを歩くモンスターならびにサブキャラの設定とムーブ
					fieldDataInitialization(new_character_list.length);					
					SubCharacterSetting();
				}
			}else{//要は逃走した時などはそのまま前回のフィールド情報をそのままにする
				//フィールドでぶつかったモンスターIDを格納する変数を初期化
				target_field_chara = 0;
				//フィールドを歩くモンスターならびにサブキャラの設定とムーブ
				fieldDataInitialization(new_character_list.length);
				SubCharacterSetting();			
			}	
		}else{//1階層と9階層はフィールド上のキャラクターを全削除する
			//……が。ここが実行されることはない。なぜならこの関数自体がバトル終了後だけ実行されるから
			fieldDataInitialization(new_character_list.length);		
			new_character_list = [];
			$('[class^="character_move_"]').remove();
			$('[class^="character_"]').remove();
			//フィールドでぶつかったキャラクターIDを格納する変数を初期化・・・ここでは意味ないか			
			target_field_chara = 0;	
		}	
	}
/*****************************************************
フィールドデータの初期化
・階層フィールド上のキャラクター配列の設定
・階層フィールド上のキャラクター変数の初期化
*****************************************************/	
function fieldDataInitialization(chara_monster_num){	
	//会話フラグ
	 conversationv_flag = false;
	if(chara_monster_num == 3){
			// 'left' : (view_w / 15) +'px',
			// 'top' : (view_h / 2) + 'px'		
		 character_position_left_1 = [50 , (view_w / 2) , (view_w * 3 / 4)];
		 character_position_top_1 = [50,200,170];
		 stop_move_id_1 = [0,0,0];
		 stop_chara_id_1 = [0,0,0];
		 stop_walk_id_1 = [0,0,0];	
		 character_rect_1 = [[32,32,0,64],[32,32,0,64],[32,32,0,64]];//上、右、左、下
		 get_position_character_1 = [];
		 target_field_chara = 0;
		 hit_flag = [false,false,false];
		 talk_range = [false,false,false];
		 hit_range = [[false,false,false,false],[false,false,false,false],[false,false,false,false]];
		 obj_hit_flag = [false,false,false];
		 obj_hit_range = [[false,false,false,false],[false,false,false,false],[false,false,false,false]]; 		
	}else if(chara_monster_num == 2){
		 character_position_left_1 = [50 , (view_w / 2)];
		 character_position_top_1 = [50,200];
		 stop_move_id_1 = [0,0];
		 stop_chara_id_1 = [0,0];
		 stop_walk_id_1 = [0,0];	
		 character_rect_1 = [[32,32,0,64],[32,32,0,64]];//上、右、左、下
		 get_position_character_1 = [];
		 target_field_chara = 0;
		 hit_flag = [false,false];
		 talk_range = [false,false];
		 hit_range = [[false,false,false,false],[false,false,false,false]];
		 obj_hit_flag = [false];
		 obj_hit_range = [[false,false,false,false]]; 
	}else if(chara_monster_num == 1){
		 character_position_left_1 = [50];
		 character_position_top_1 = [50];
		 stop_move_id_1 = [0];
		 stop_chara_id_1 = [0];
		 stop_walk_id_1 = [0];	
		 character_rect_1 = [[32,32,0,64]];//上、右、左、下
		 get_position_character_1 = [];
		 target_field_chara = 0;
		 hit_flag = [false];
		 talk_range = [false];
		 hit_range = [[false,false,false,false]];
		 obj_hit_flag = [false];
		 obj_hit_range = [[false,false,false,false]];		
	}else{
		 character_position_left_1 = [50 , (view_w / 2) , (view_w * 3 / 4)];
		 character_position_top_1 = [50,200,170];
		 stop_move_id_1 = [0,0,0];
		 stop_chara_id_1 = [0,0,0];
		 stop_walk_id_1 = [0,0,0];	
		 character_rect_1 = [[32,32,0,64],[32,32,0,64],[32,32,0,64]];//上、右、左、下
		 get_position_character_1 = [];
		 target_field_chara = 0;
		 hit_flag = [false,false,false];
		 talk_range = [false,false,false];
		 hit_range = [[false,false,false,false],[false,false,false,false],[false,false,false,false]];
		 obj_hit_flag = [false,false,false];
		 obj_hit_range = [[false,false,false,false],[false,false,false,false],[false,false,false,false]]; 		
	}	
}	
/*****************************************************
会話処理
・会話範囲判定がある場合は、その対象(サブキャラ)の属性を取得
・属性に応じたセリフの設定
・会話中はサブキャラ全員の動き(スレッド)を止める
・会話タグおよびCSSを500ミリ秒かけて出力
*****************************************************/
	function conversation(chara_num){
		
		//会話対象キャラがどのへんにいるのか
		let con_top = get_position_character_1[chara_num].top;
		
		//会話フラグ(連続で会話するのを防ぐため)
		conversationv_flag = true;
		//会話対象キャラを初期化
		talk_target = 99;
		//キャラ属性を取得
		let chara_type = $('.character_' + chara_num).attr("name");
		let dialog = "";
		//メインキャラ以外の動きを止める(スレッド処理を止める)
		$.each(new_character_list, function(i, value) {
			clearTimeout(stop_chara_id_1[i]);			
			clearTimeout(stop_walk_id_1[i]);
			clearTimeout(stop_move_id_1[i]);
		});
		
		//キャラに対応したセリフの設定
		if(number_of_laps == 1 && chara_type === "banditman")dialog = "When you warp, the monsters are swarming! Be careful! Also, if you don't destroy all the monsters in the outside world, the warp stone statue won't appear.";
		if(number_of_laps == 1 && chara_type === "maidwoman")dialog = "This is a village for beginners. Please take it easy. Press the A button in front of the statue to warp.";
		if(number_of_laps == 1 && chara_type === "childgirl")dialog = "JavaScript (jQuery) is difficult but fun! There may be bugs in the future, but please take it easy!(^^)!";
		if(number_of_laps == 2 && chara_type === "banditman")dialog = "The state of the imprisoned princess is strange.";
		if(number_of_laps == 2 && chara_type === "maidwoman")dialog = "Hero! The princess is acting strange!";
		if(number_of_laps == 2 && chara_type === "childgirl")dialog = "sorry for messy code(*_*)";	
		if(number_of_laps == 3 && chara_type === "banditman")dialog = "I never thought that the princess was also an enemy";
		if(number_of_laps == 3 && chara_type === "maidwoman")dialog = "No... the princess's true identity was the Great Demon Lord WordPress...";
		if(number_of_laps == 3 && chara_type === "childgirl")dialog = "sorry for messy code(*_*)";	
		if(number_of_laps == 4 && chara_type === "banditman")dialog = "They weren't offended. That's why... can you forgive me already?";
		if(number_of_laps == 4 && chara_type === "maidwoman")dialog = "As expected, brave man!";
		if(number_of_laps == 4 && chara_type === "childgirl")dialog = "Please read other articlesヽ(^o^)丿";	
		if(number_of_laps >= 5 && chara_type === "banditman")dialog = "It's the second " + number_of_laps + "week! ? wonderful!";
		if(number_of_laps >= 5 && chara_type === "maidwoman")dialog = "wonderful! It's the first time in the " + number_of_laps + "th week. I haven't tried it from here so I don't know……";
		if(number_of_laps >= 5 && chara_type === "childgirl")dialog = "thank you!";	

		if(chara_type === "monster_1" || chara_type === "monster_2" || chara_type === "monster_3" || chara_type === "monster_4" || chara_type === "monster_5" || chara_type === "monster_6" || chara_type === "monster_7" || chara_type === "monster_8" || chara_type === "monster_9" ||  chara_type === "monster_10" || chara_type === "monster_11")dialog = "Gugaa! !";

		
		//王妃の場合
		if(number_of_laps == 1 && id_current_field == 10){
			if(chara_type === "Princess")dialog = "Hero, please help me. Demon King jQuery intends to destroy the world. I'm a prisoner and I can't do anything. Only the hero can be relied upon. …… please";
		}
		if(number_of_laps == 2 && id_current_field == 10){
			if(chara_type === "Princess")dialog = "Tch...jQuery.... Did I fail... enough is enough. I will do it myself.";
		}
		if(number_of_laps == 3 && id_current_field == 10){
			if(chara_type === "Princess")dialog = "jQuery! You lost not once, but twice! ? Useless!";
		}
		if(number_of_laps == 4 && id_current_field == 10){
			if(chara_type === "Princess")dialog = "Gaaaaaa! different! That's wrong! It's jQuery that's bad!! So please forgive me!!!!!!";
		}
		if(number_of_laps >= 5 && id_current_field == 10){
			if(chara_type === "Princess")dialog = "So stupid! " + number_of_laps + " lap!? I haven't verified any more!!!! In the first place, I haven't verified it after the first week! ";
		}
		
		
		
		
		
		//ジェイクエリーの場合
		if(number_of_laps == 1 && id_current_field == 12){
			if(chara_type === "lassboss")dialog = "Brave man. I've made it this far. But your life ends here!";
		}	
		if(number_of_laps == 2 && id_current_field == 12){
			if(chara_type === "lassboss")dialog = "WordPress has been defeated! ?   can not forgive! ! Hero ahhh!";
		}	
		if(number_of_laps == 3 && id_current_field == 12){
			if(chara_type === "lassboss")dialog = "Have you come again! ? How many times are you going to beat me!";
		}	
		if(number_of_laps == 4 && id_current_field == 12){
			if(chara_type === "lassboss")dialog = "hmm...now...forgive me";
		}
		if(number_of_laps >= 5 && id_current_field == 12){
			if(chara_type === "lassboss")dialog = "Hieeee! " + number_of_laps + "laps! No way, you... are free! ?";
		}

		let con_target_top = 200;
		if(con_top >= 150)con_target_top = 1;
		else con_target_top = 200;
		//after	z-index : 100;	
		$('.game_container').append('<div class ="conversation_container"><div class="conversation" value="">' + dialog + '</div></div>');
		$('.conversation').css({'z-index': '100'});
		$('.conversation').show().animate({
		//色などの複雑な設定はできないので、初期設定はCSS
			//top: '300px',
			left: 0,
			width: '100%',
			height: '100px',
			top: con_target_top + 'px'			
		}, 500);
        $(".bgm_talk").get(0).play();
	}
	
/*****************************************************
終話処理
会話タグおよびCSSを削除
サブキャラの動き(スレッド)を再開
******************************************************/
	function endOfConversation(){
		$(".conversation").remove();
		$(".conversation_container").remove();
		conversationv_flag = false;
		
		if(number_of_laps >= 2 && id_current_field == 10){
		//if(id_current_field == 1){//デバグ用					
			encounterEffect();
		}else if(id_current_field == 12){
		//}else if(id_current_field == 0){//デバグ用					
			encounterEffect();
		}else{		
			//メインキャラ以外の動きを再開する
			$.each(new_character_list, function(i, value) {
				charaDirectionDecide_1(i);
			})
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/*********************************************************************** 	
	パーティに関する変数
	基本的には「ぴぽや https://pipoya.net/」様からダウンロードしたキャラクターチップでスプライトを生成 
	するための座標を格納
	************************************************************************/
	let b_left = view_w - 60;
	let b_character_position_left_1 = [b_left,b_left,b_left,b_left];
	let b_character_position_top_1 = [70,120,170,220];
	let b_character_hp = [100,100,100,100];
	let b_character_max_hp = [100,100,100,100];
	let b_character_mp = [100,100,500,500];
	let b_character_max_mp = [100,100,500,500];
	let b_stop_move_id_1 = [0,0,0,0];
	let b_stop_chara_id_1 = [0,0,0,0];
	let b_stop_walk_id_1 = [0,0,0,0];	
	let b_character_rect_1 = [[32,32,0,64],[32,32,0,64],[32,32,0,64],[32,32,0,64]];//上、右、左、下
	//let b_character_level = [[99,0],[99,0],[99,0],[99,0]];//level,経験値
	//let b_character_level = [[90,0],[90,0],[90,0],[90,0]];//level,経験値
	//let b_character_level = [[50,0],[50,0],[50,0],[50,0]];//level,経験値
	let b_character_level = [[1,0],[1,0],[1,0],[1,0]];//level,経験値	
	//let b_character_level = [[20,0],[20,0],[20,0],[20,0]];//level,経験値
	let recovery_target = [0,0,0,0];
	let experience_point = 0;
	let victory_dance_time = 0;
	let b_character_status_orijn = [[300,100,1,1],[300,80,1,1],[300,120,1,1],[300,120,1,1]];//力、魔力、素早さ(%)、防御力(%)
	//とりあえず、配列をコピーして使うことにする。
	let b_character_status = $.extend(true, [], b_character_status_orijn);
	
	
	//武器
	let weapon_list = [];
	weapon_list[0] = "https://likehuman.info/wp-content/uploads/2022/11/long_sword-e1669855464762.png";
	weapon_list[1] = "https://likehuman.info/wp-content/uploads/2022/11/long_sword-e1669855464762.png";
	weapon_list[2] = "https://likehuman.info/wp-content/uploads/2022/12/stick_1-e1670896030533.png";
	weapon_list[3] = "https://likehuman.info/wp-content/uploads/2022/12/stick_1-e1670896030533.png";
	weapon_list[4] = "https://likehuman.info/wp-content/uploads/2022/12/stick_1-e1670896030533.png";
	weapon_list[5] = "https://likehuman.info/wp-content/uploads/2023/01/ef_eisho_kaifuku_gifanime01.gif";	
	
	
	//モンスター
	let kill_monster_list = [];
	const m_select_arrow = ["https://likehuman.info/wp-content/uploads/2022/11/chara_arrow.png"];
	let target_monster_list = [];
	let stop_monster_standby = 0;
	let stop_monster_run = [];
	let stop_monster_behavior_time = [];
	let stop_m_arrow_timer = 0;
	let monster_index = 0;
	let monster_position = [];
	let monster_position_left = [5,5,75,75,145,145,215,215];
	let monster_position_top = [100,200,100,200,100,200,100,200];
	let monster_name = [];
	let monster_list_original = [];
	monster_list_original[0] = 
	' alt="poisonousMushroom"  name="poisonousMushroom" src="https://likehuman.info/wp-content/uploads/2022/12/m_kinoko01.png" >';
	monster_list_original[1] = 
	' alt="ghost" name="ghost" src="https://likehuman.info/wp-content/uploads/2022/12/m_ghost01.png" >';
	monster_list_original[2] = 
	' alt="zombie" name="zombie" src="https://likehuman.info/wp-content/uploads/2022/12/m_zonbi01.png" >';
	monster_list_original[3] = 
	' alt="EvilScareClaw" name="EvilScareClaw" src="https://likehuman.info/wp-content/uploads/2023/03/m_ebvilsukeakuro01.png" >';
	monster_list_original[4] = 
	' alt="crazyPig" name="crazyPig" src="https://likehuman.info/wp-content/uploads/2023/03/m_crazypig01.png" >';
	monster_list_original[5] = 
	' alt="Kamatarou" name="Kamatarou" src="https://likehuman.info/wp-content/uploads/2023/03/m_kamademon.png" >';
	monster_list_original[6] = 
	' alt="gargoyle" name="gargoyle" src="https://likehuman.info/wp-content/uploads/2023/03/m_gargoyle01.png" >';
	monster_list_original[7] = 
	' alt="rottenPumpkin" name="rottenPumpkin" src="https://likehuman.info/wp-content/uploads/2023/03/m_kusarepanpukin01.png" >';
	monster_list_original[8] = 
	' alt="carsEgg" name="carsEgg" src="https://likehuman.info/wp-content/uploads/2023/03/m_kazuegg01.png" >';
	monster_list_original[9] = 
	' alt="stalkingSpider" name="stalkingSpider" src="https://likehuman.info/wp-content/uploads/2023/03/m_sutokingspider01.png" >';
	monster_list_original[10] = 
	' alt="BadGolem" name="BadGolem" src="https://likehuman.info/wp-content/uploads/2023/03/m_badgorem01.png" >';
	monster_list_original[11] = 
	' alt="deathBox" name="deathBox" src="https://likehuman.info/wp-content/uploads/2023/03/m_desubox01.png" >';
	monster_list_original[12] = 
	' alt="devilScorpion" name="devilScorpion" src="https://likehuman.info/wp-content/uploads/2023/03/m_debilscorpion01.png" >';
	monster_list_original[13] = 
	' alt="panicFlower" name="panicFlower" src="https://likehuman.info/wp-content/uploads/2023/03/m_panicfulawa01.png" >';	
	monster_list_original[14] = 
	' alt="blueDemon" name="blueDemon" src="https://likehuman.info/wp-content/uploads/2023/03/m_aooni01.png" >';
	monster_list_original[15] = 
	' alt="hornDemon" name="hornDemon" src="https://likehuman.info/wp-content/uploads/2023/03/m_horndemon01.png" >';
	monster_list_original[16] = 
	' alt="Cerberus" name="Cerberus" src="https://likehuman.info/wp-content/uploads/2023/03/m_keruberos01.png" >';
	monster_list_original[17] = 
	' alt="noddyDragon" name="noddyDragon" src="https://likehuman.info/wp-content/uploads/2023/03/m_nodidoragon01.png" >';
	monster_list_original[18] = 
	' alt="broadSaucer" name="broadSaucer" src="https://likehuman.info/wp-content/uploads/2023/03/m_bloodsorcer.png" >';
	monster_list_original[19] = 
	' alt="darkSoldier" name="darkSoldier" src="https://likehuman.info/wp-content/uploads/2023/03/m_darksoldar01.png" >';	
	monster_list_original[20] = 
	' alt="jQuery" name="jQuery" src="https://likehuman.info/wp-content/uploads/2023/03/m_b_jquery.png" >';	
	monster_list_original[21] = 
	' alt="wordPress" name="wordPress" src="https://likehuman.info/wp-content/uploads/2023/05/m_b_wordpress.png" >';		
	
	//味方の初期値[[100,100,1,1],[90,80,1,1],[60,120,1,1],[60,120,1,1]];//力、魔力、素早さ(%)、防御力(%)
	//インデックス、HP、最大HP、MP、最大MP、力、魔力、素早さ、防御力,経験値,レベル
	let monster_status_original = 
	[[0,200,200,200,200,70,20,20,20,1000,1],//0
	[1,200,200,200,200,70,20,20,20,1000,1],//1
	[2,200,200,200,200,70,20,20,20,1000,1],//2
	[3,200,200,200,200,70,20,20,20,1000,1],//3
	[4,200,200,200,200,70,20,20,20,1000,1],//4
	[5,200,200,200,200,70,20,20,20,1000,1],//5
	[6,200,200,200,200,70,20,20,20,1000,1],//6
	[7,200,200,200,200,70,20,20,20,1000,1],//7
	[8,200,200,200,200,70,20,20,20,1000,1],//8
	[9,200,200,200,200,70,20,20,20,1000,1],//9
	[10,200,200,200,200,70,20,20,20,1000,1],//10
	[11,200,200,200,200,70,20,20,20,1000,1],//11
	[12,200,200,200,200,70,20,20,20,1000,1],//12
	[13,200,200,200,200,70,20,20,20,1000,1],//13
	[14,200,200,200,200,70,20,20,20,1000,1],//14
	[15,200,200,200,200,70,20,20,20,1000,1],//15
	[16,200,200,200,200,70,20,20,20,1000,1],//16
	[17,200,200,200,200,70,20,20,20,1000,1],//17
	[18,200,200,200,200,70,20,20,20,1000,1],//18
	[19,200,200,200,200,70,20,20,20,1000,1],//19
	[20,200,200,200,200,70,20,20,20,1000,1],//20
	[21,200,200,200,200,70,20,20,20,1000,1],//21	
	];	
	
	
	//とりあえず、配列をコピーして使うことにする。
	//let monster_list = $.extend(true, [], monster_list_original);
	//let monster_status = $.extend(true, [], monster_status_original);	
	let monster_list = [];
	let monster_status = [];

	let mon_special_at = [];
	//Cerberus
	mon_special_at[0] ='https://likehuman.info/wp-content/uploads/2023/04/fang.gif';
	//noddyDragon
	mon_special_at[1] ='https://likehuman.info/wp-content/uploads/2023/03/earth_fire.gif';
	//broadSaucer
	mon_special_at[2] ='https://likehuman.info/wp-content/uploads/2023/02/magic_kaminari_1.gif';
	//darkSoldier
	mon_special_at[3] ='https://likehuman.info/wp-content/uploads/2023/04/darksword.gif';
	//jQuery
	mon_special_at[4] ='https://likehuman.info/wp-content/uploads/2023/04/bigbang.gif';
	//wordPress
	mon_special_at[5] ='https://likehuman.info/wp-content/uploads/2023/05/death_march.gif';
	
	let mon_sp_explanation = [];
	mon_sp_explanation[0] = 'Deathfang';
	mon_sp_explanation[1] = 'purgatory';
	mon_sp_explanation[2] = 'thunderOfDeath';
	mon_sp_explanation[3] = 'darkSword';
	mon_sp_explanation[4] = 'bigBang';
	mon_sp_explanation[5] = 'meditation';	
	mon_sp_explanation[6] = 'deathMarch';		
	
	//ヒットエフェクト
	let stop_hit_id = [0,0,0,0];
	//要素の数は適当※出現モンスター数によるので
	let survivor = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
	//ダメージリアクションのエフェクトを止める配列※出現モンスター数によるので要素数は適当
	let stop_leanBack =  [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]];
	let hit_position = [];
/* 	let hit_position_left = [100,200,100,200,100,100,100];
	let hit_position_top = [100,100,200,200,100,100,200];
	let hit_rect = [[0,135,0,120],[0,135,0,120],[0,135,0,120],[0,135,0,120]];//上、右、左、下 */
	let hit_rect_percentage = 135;
	let hit_list = [];
	hit_list[0] = ' style="position: absolute;" name="ロングソード" src="https://likehuman.info/wp-content/uploads/2022/12/sord_attack_ef05.gif" >';
	hit_list[1] = ' style="position: absolute;" name="ロングソード" src="https://likehuman.info/wp-content/uploads/2022/12/sord_attack_ef05.gif" >';
	hit_list[2] = ' style="position: absolute;" name="杖" src="https://likehuman.info/wp-content/uploads/2022/12/stick_attack_ef02.gif" >';
	hit_list[3] = ' style="position: absolute;" name="杖" src="https://likehuman.info/wp-content/uploads/2022/12/stick_attack_ef02.gif" >';
	hit_list[4] = ' style="position: absolute;" name="剣技_4" src="https://likehuman.info/wp-content/uploads/2023/01/kengi_1.gif" >';
	hit_list[5] = ' style="position: absolute;" name="剣技_5" src="https://likehuman.info/wp-content/uploads/2023/02/kengi_2.gif" >';
	hit_list[6] = ' style="position: absolute;" name="無効(白なので)" src="" >';
	hit_list[7] = ' style="position: absolute;" name="黒魔法" src="https://likehuman.info/wp-content/uploads/2023/02/magic_kaminari_1.gif" >';
	hit_list[8] = ' style="position: absolute;" name="剣技_8" src="https://likehuman.info/wp-content/uploads/2023/03/3_sord_attack.gif" >';
	hit_list[9] = ' style="position: absolute;" name="剣技_9" src="https://likehuman.info/wp-content/uploads/2023/03/shureded_sord.gif" >';	
	hit_list[10] = ' style="position: absolute;" name="無効(白なので)" src="" >';
	hit_list[11] = ' style="position: absolute;" name="黒魔法" src="https://likehuman.info/wp-content/uploads/2023/03/earth_fire.gif" >';
	hit_list[12] = ' style="position: absolute;" name="剣技_12"" src="https://likehuman.info/wp-content/uploads/2023/03/exploding_sword.gif" >';hit_list[13] = ' style="position: absolute;" name="剣技_13" src="https://likehuman.info/wp-content/uploads/2023/03/mist_slash.gif" >';
	hit_list[14] = ' style="position: absolute;" name="無効(白なので)" src="" >';
	hit_list[15] = ' style="position: absolute;" name="黒魔法" src="https://likehuman.info/wp-content/uploads/2023/03/heavenlyblow.gif" >';	
	hit_list[16] = ' style="position: absolute;" name="剣技_16" src="https://likehuman.info/wp-content/uploads/2023/03/dimension_attack3.gif" >';
	hit_list[17] = ' style="position: absolute;" name="剣技_17" src="https://likehuman.info/wp-content/uploads/2023/03/cutin_half.gif" >';
	hit_list[18] = ' style="position: absolute;" name="無効(白なので)" src="" >';
	hit_list[19] = ' style="position: absolute;" name="黒魔法" src="https://likehuman.info/wp-content/uploads/2023/03/hellbird.gif" >';
	
	let acquired_skills = [];
	
	//どのヒットエフェクト(hit_list)を使うのかはskill_command_**[**]のkeyで指定
	let skill_command_0 = {4:"???",8:"???",12:"???",16:"???"};
	let skill_command_1 = {5:"???",9:"???",13:"???",17:"???"};
	let skill_command_2 = {6:"???",10:"???",14:"???",18:"???"};
	let skill_command_3 = {7:"???",11:"???",15:"???",19:"???"};
	
	// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
	// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
	// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
	// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};	
	
	let skill_overview = ["","","","","ridingAttack","dancingSword","healing","ThunderCrash","ThreeHammers","shadedSword","revival","earthFire","flameSlasher","mistSlash","shield","heavenBlow","dimensionCut","Iai-giri","ForceFang","hellBerd"];
	
	let skill_explanation = [["Flowing sword technique (wide attack *However, extra damage to attack target)","Hammer with 3 swords (wide attack *However, extra damage to attack target)","Flame-covered sword technique (Attack to all targets *Extra damage to the attack target)","Sword technique that cuts through dimensions (wide attack * However, extra damage to the attack target)"],["Dance-like sword technique (wide attack *However, extra damage is done to the attack target)","Sword technique that cuts at high speed (wide attack * However, extra damage to attack target)","Magical sword with magical power (general attack * However, extra damage to attack target)","Ultimate Iai-giri"],["A certain amount of recovery (single)","Revive a fallen companion (single)","Increase defense (single). Valid up to 2 times","Attack power increases for warriors, and magic power increases for magicians (single). Valid up to 2 times"],["Magical lightning strike (wide attack *However, extra damage to attack target)","Locally erupt (wide attack * However, extra damage to the attack target)","Heavenly Judgment for the Evil (All-out attack *However, additional damage is done to the attack target)","Scorching Hell (All-out attack *However, extra damage is done to the attack target)"]];//上、右、左、下
	//スキル6個は面倒臭い
	// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut",20:"???",24:"???"};
	// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri",21:"???",25:"???"};
	// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"???",22:"???",26:"???"};
	// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"???",19:"???",23:"???",27:"???"};
	
	//回復および補助魔法のエフェクト
	let partner_effect_list = [];
	partner_effect_list[0] = "https://likehuman.info/wp-content/uploads/2023/01/ef_eisho_kaifuku_gifanime01.gif";
	partner_effect_list[1] = "https://likehuman.info/wp-content/uploads/2023/01/ef_kaifuku_gifanime01.gif";
	partner_effect_list[2] = "https://likehuman.info/wp-content/uploads/2023/02/blackeisho.gif";
	partner_effect_list[3] = "https://likehuman.info/wp-content/uploads/2023/02/revival.gif";
	partner_effect_list[4] = "https://likehuman.info/wp-content/uploads/2023/03/shield.gif";
	partner_effect_list[5] = "https://likehuman.info/wp-content/uploads/2023/03/forcefang.gif";	
	
	//シールドの回数は2回まで有効にするための配列
	let shield_count = [0,0,0,0];
	//フォースファングの回数は2回まで有効にするための配列
	let force_count = [0,0,0,0];

	/****************** 	
	戦闘背景に関する配列
	******************/
	//戦闘背景・・・0grass,1ougi,2rasboss,3suna,4doukutu,5douku2_2,6yougan,7water,8water2,9yuki,10yuki2,11rakuen,12makai
	//フィールド背景・・・0ホワイト、1草原、2砂漠、3洞窟、4洞窟2、5溶岩、6水、7水2、8雪、9氷、10楽園、11宇宙、12宇宙	
    let background_src = [];
	background_src[0] = "https://likehuman.info/wp-content/uploads/2022/11/battle001.jpg";//草原のバトル背景
	//background_src[1] = "https://likehuman.info/wp-content/uploads/2023/05/battle_background.jpg";//奥義のバトル背景
	background_src[1] = "https://likehuman.info/wp-content/uploads/2023/05/black_haikei.png";//奥義のバトル背景		
	background_src[2] = "https://likehuman.info/wp-content/uploads/2023/05/background_lassboss.jpg";//ラスボスのバトル背景	
    background_src[3] = "https://likehuman.info/wp-content/uploads/2023/05/background_suna.jpg";//砂漠
    background_src[4] = "https://likehuman.info/wp-content/uploads/2023/05/background_doukutu.jpg";//洞窟
    background_src[5] = "https://likehuman.info/wp-content/uploads/2023/05/background_doukutu4.jpg";//洞窟最深部
    background_src[6] = "https://likehuman.info/wp-content/uploads/2023/05/background_yougan.jpg";//溶岩
    background_src[7] = "https://likehuman.info/wp-content/uploads/2023/05/background_water.jpg";//水
    background_src[8] = "https://likehuman.info/wp-content/uploads/2023/05/background_water2.jpg";//水2
    background_src[9] = "https://likehuman.info/wp-content/uploads/2023/05/background_yuki.jpg";//雪
    background_src[10] = "https://likehuman.info/wp-content/uploads/2023/05/background_ice.jpg";//アイス
    background_src[11] = "https://likehuman.info/wp-content/uploads/2023/05/background_hana.jpg";//楽園
    background_src[12] = "https://likehuman.info/wp-content/uploads/2023/05/background_doukutu3.jpg";//魔界	
	
	/****************** 	
	戦闘時の共通変数および配列
	******************/	
	let fieldScreen_flag = false; //fieldScreenが重複して実行されないようにするため
	let victory_flag = false;
	let escape_flag = false;
	let stop_battle_run = [0,0,0,0,0];
	let pause_time = 0;
	let b_index = 0;
	let skill_index = 0;
	let recovery_index = 0;
	//ターンタイムはモンスター生成時に構築
	let turn_time = [];
	//let turn_time = [1,4000,8000,12000,16000,17000,18000,19000,20000,21000,22000,23000,24000,25000,26000,27000,28000];
	//let turn_time = [1,4000,8000,12000,16000,18000,20000,22000,24000,26000,28000,30000,32000,34000,36000,38000,40000];
	//let turn_time = [1,4000,8000,12000,16000,19000,21000,24000,27000,30000,33000,36000,39000,42000,45000,48000,51000];
	let tactics = ["fight","runaway","skill","defense"];

	let battle_flag = false;
	let battle_run_flag = false;
	let battle_stage_1 = false;
	let battle_stage_2 = false;
	let battle_stage_3 = false;
	let battle_stage_3_1 = false;
	let battle_boss_flag = false;
	let battle_boss_flag2 = false;
	
	//let battle_stage_4 = [false,false,false,false];
	let b_chara_standby = [[0,0],[1,1],[2,2],[3,3]];//防御は99、逃走は100
	let b_member_inex = 0;
	let battle_position_chara = [];
	let effect_timer_1 = 0;
	let effect_timer_2 = 0;
	let battle_step = 0;
	let battle_message = ["victory","annihilated...","ran away"];
	let battle_message_position_left = view_w / 4 * 2;
	let battle_message_position_top = 0;
	const effect_2 = ["https://likehuman.info/wp-content/uploads/2022/11/chara_arrow.png"];
	const b_chara_1 = ' style="position: absolute;" name="hero" src="https://likehuman.info/wp-content/uploads/2022/11/ぴぽや_女001_勇者.png" >';
	const b_chara_2 = ' style="position: absolute;" name="ninja" src="https://likehuman.info/wp-content/uploads/2022/11/ぴぽや_女005_忍者.png">';
	const b_chara_3 = ' style="position: absolute;" name="monk" src="https://likehuman.info/wp-content/uploads/2022/11/ぴぽや_女_004_僧侶.png">';
	const b_chara_4 = ' style="position: absolute;" name="witch" src="https://likehuman.info/wp-content/uploads/2022/11/ぴぽや_女_003_魔女.png">';
	const battle_member = [b_chara_1,b_chara_2,b_chara_3,b_chara_4];
	const member_name = ["hero","ninja","monk","witch"]
	

/****************** 	
エンカウントのエフェクト
******************/
	function encounterEffect(){
		
		//キャラの動きを止める(スレッド処理を止める)
		$.each(new_character_list, function(i, value) {
			clearTimeout(stop_chara_id_1[i]);			
			clearTimeout(stop_walk_id_1[i]);
			clearTimeout(stop_move_id_1[i]);
		});
		clearTimeout(stop_down_mainchar_id);
		clearTimeout(stop_right_mainchar_id);
		clearTimeout(stop_left_mainchar_id);
		clearTimeout(stop_up_mainchar_id);		
		clearTimeout(stop_move_mainchar_id);
		//フィールド画面にもどる関数を重複実行されないようにするフラグを初期化
		fieldScreen_flag = false;
		//戦闘に関するフラグをfalse
		victory_flag = false;
		escape_flag = false;
		//倒したモンスターのインデックスを保存する配列を初期化
		kill_monster_list = [];

		//バトルフラグをtrue
		battle_flag = true;
		battle_stage_1 = true;
		
		//ダメージリアクションのエフェクトを止める配列を初期化
		stop_leanBack =  [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]];
		
		//シールド2回まで有効にするための配列を初期化
		shield_count = [0,0,0,0];
		//フォースファングを2回まで有効にするための配列を初期化
		force_count = [0,0,0,0];
		
		if(bgm_village_flag){
			$(battle_bgm4[4]).get(0).currentTime = 0;
			//再生速度の変更
			//$(battle_bgm[0]).get(0).playbackRate = 2.5;
			$(battle_bgm4[4]).get(0).play();	
		}

		$('.game_container').append('<img class="encount_img"' + new_character_list[target_field_chara] + '</div>');	
		
		//目に悪いから却下
/* 		let vv = 0
		//赤と白を交互に表示して点滅を表現
		let stop_encount_change = setInterval(function(){
			fieldBackgroundChange(vv);
			if(vv == 0){
				vv = 13;//赤の画像
			}else{
				vv = 0;						
			}
		},100); */
		
		$('[class^="character_move_"]').hide();
		//背景を赤にする
		let id_current_field_back = id_current_field;
		fieldBackgroundChange(13);
		//エンカウント時、ズームアップするモンスター画像の切り抜き
		$('.encount_img').css({	
			'left' : -300 + 'px',
			'top'  : 0 + 'px',
			'z-index' : 100,
			'overflow' : 'hidden',
			'background-image':'red',
			'clip':'rect('+
				// character_rect_1[target_field_chara][0] + 'px,' +
				// character_rect_1[target_field_chara][1] + 'px,' +
				// character_rect_1[target_field_chara][3] + 'px,' +
				// character_rect_1[target_field_chara][2] + 'px' +
				//切り抜きの位置は固定にしないとエンカウント時のズームアップが不安定(表示されたり、されなかったり)になる
				64 + 'px,' +
				96 + 'px,' +
				96 + 'px,' +
				64 + 'px' +
			')'
		});	
		//切り抜いた画像をズームアップする
		//widthやheightの値を変更しても意味なかった
		$('.encount_img').css({'opacity': '1'});
		//1から2へと変化する数値を利用しているだけなのでopacity:1以外でもOK
		$('.encount_img').animate({opacity: 2 },{
			duration:900,
			//stepで時間に比例して変化する内容を記述
			step:function(o){
			//1から2へと変化する数値を利用しているだけなのでopacity:1とかじゃなくてもOK。暫定でこのようにしているだけ
			$(this).css({
				//複数指定する場合⇒⇒transform :'scale(' + o * 10 + ',' + o * 10 + ') translate(' + view_w / 2 * o + 'px,'+ 100 * o + 'px)',
				transform :'scale(' + o * 10 + ',' + o * 5 + ')'
				});
			},
			//完了処理
			//complete:function(){$('.effect_img_' + i).css('opacity', '1');}
		});
		
		setTimeout(function(){
			//clearTimeout(stop_encount_change);
			$('[class^="encount_img"]').remove();
			fieldBackgroundChange(id_current_field_back);
			//バトル開始
			battleMode();
		},1000);		
	}
/******************************************************************************** 
********************************************************************************* 
戦闘画面の初期設定
*********************************************************************************
*********************************************************************************/		
	function battleMode(){
		//フィールド画面を非表示にする
		$('.game_container').hide();	
		$('.game').prepend('<div class ="battle_container"></div><div class="battle_menu" value=""></div>');
		
		$('.battle_menu').show().animate({
		//色などの複雑な設定はできないので、初期設定はCSS
			//top: '300px',
			width: '100%',
			height: '150px',
			zIndex : 91
		}, 50);
		
		//モンスター配列を生成
		monsterShuffle(); 
		
		//モンスター名称タグを出力
		$('.battle_menu').append('<div class="battle_monster"></div>');
/* 		$.each(monster_name, function(i, value) {	
			$('.battle_monster').append('<div>' + monster_name[i] +'</div>');		
		})	 */	

		//戦術メニュータグを出力
		$('.battle_monster').after('<div class="battle_tactics"></div>');
		$.each(tactics, function(i, value) {	
			$('.battle_tactics').append('<button id="tactics_' + i + '" class="game_btn">'+tactics[i]+'</button>');		
		})
		
		//パーティーのステータスタグを出力
		battle_status_show();
		
		//初期位置のCSS
		$('#tactics_'+ b_index).css('background-color', 'dimgrey');
		$('.selected_chara_'+ b_index).css('background-color', 'dimgrey');
		
			
		//戦闘キャラの向きの設定
		$.each(battle_member, function(i, value) {	
			$('.battle_container').append('<div class="battle_move_'+ i +'" style="position: absolute;"><img class="battle_character_' + i +'"' + battle_member[i] + '</div>');		
			//戦闘キャラの初期位置
			battleStartPosition(i);
			//戦闘キャラのエフェクトの土台
			$('.battle_container').append('<div class="b_chara_effect_'+ i +'" style="position: absolute;"></div>');
		})
		//カーソルの初期設定(一番目のキャラクターにカーソルを設定させる)
		arrowSettings(0);
		
		//レベルアップ時に習得するスキルを格納する配列の初期化
		acquired_skills = ["","","","","","","","","","","","","","","","","","","","",""];
		acquired_skills[20];
		
		
		//モンスターの描画
		monster_position = [];
		monster_name = [];	
		$.each(monster_list, function(i, value) {	
			$('.battle_container').append('<div class="monster_move_'+ i +'" style="position: absolute;"><img class="monster_' + i +'"  style="position: absolute;" ' + monster_list[i] + '</div>');			
			
			//モンスターの位置(名前も取得している)

			monsterStartPosition(i);
			//モンスターエフェクトの土台
			$('.battle_container').append('<div class="monster_s_effect_'+ i +'" style="position: absolute;"></div>');			
		})
	}
	//↑↑↑↑↑ここまでが戦闘の初期設定↑↑↑↑↑↑↑↑↑↑↑
	////**************************************
	
	
	
	
	/**
	* バックグラウンドを変更する
	*/	
	function battleBackgroundChange(g_src){
		//戦闘背景・・・0grass,1ougi,2rasboss,3suna,4doukutu,5douku2_2,6yougan,7water,8water2,9yuki,10yuki2,11rakuen,12makai
		//フィールド背景・・・0ホワイト、1草原、2砂漠、3洞窟、4洞窟2、5溶岩、6水、7水2、8雪、9氷、10楽園、11宇宙、12宇宙	
		

		$('.battle_container').css({	
			'background-image': 'url(' + background_src[g_src] + ')',	
			'position': 'relative',
			'align-items': 'center',	
			'height': '300px',
			//'width': '100%',
			'margin-bottom': '0',
			'background-repeat': 'round',
			//'background-size': 'cover',
			'z-index': '90'	
		});		
	}	
	
	
	//味方の初期値[[100,100,1,1],[90,80,1,1],[60,120,1,1],[60,120,1,1]];//力、魔力、素早さ(%)、防御力(%)
	//インデックス、HP、最大HP、MP、最大MP、力、魔力、素早さ、防御力,経験値,レベル
	function monsterAbilityReset(){
		let keikenti = 1000;
		monster_status_original = 
		[[0,200,200,200,200,30,20,20,20,keikenti,1],//0
		[1,200,200,200,200,30,20,20,20,keikenti,1],//1
		[2,200,200,200,200,30,20,20,20,keikenti,1],//2
		[3,200,200,200,200,30,20,20,20,keikenti,1],//3
		[4,200,200,200,200,30,20,20,20,keikenti,1],//4
		[5,200,200,200,200,30,20,20,20,keikenti,1],//5
		[6,200,200,200,200,30,20,20,20,keikenti,1],//6
		[7,200,200,200,200,30,20,20,20,keikenti,1],//7
		[8,200,200,200,200,30,20,20,20,keikenti,1],//8
		[9,200,200,200,200,30,20,20,20,keikenti,1],//9
		[10,200,200,200,200,30,20,20,20,keikenti,1],//10
		[11,200,200,200,200,30,20,20,20,keikenti,1],//11
		[12,200,200,200,200,30,20,20,20,keikenti,1],//12
		[13,200,200,200,200,30,20,20,20,keikenti,1],//13
		[14,200,200,200,200,30,20,20,20,keikenti,1],//14
		[15,200,200,200,200,30,20,20,20,keikenti,1],//15
		[16,200,200,200,200,30,20,20,20,keikenti,1],//16
		[17,200,200,200,200,30,20,20,20,keikenti,1],//17
		[18,200,200,200,200,30,20,20,20,keikenti,1],//18
		[19,200,200,200,200,30,20,20,20,keikenti,1],//19
		[20,200,200,200,200,30,20,20,20,keikenti,1],//20
		[21,200,200,200,200,30,20,20,20,keikenti,1],//20			
		];	
	}	
	
	/**
	* モンスターの能力値を決定する
	* 下記はパーティの能力値の並び
	*/	
	function monsterAbilityScore(ran1){

		let hp_rate = 1;
		let power_rate = 1;
		
		let lv_range1 = 0;
		let lv_range2 = 5;
		
		if(ran1 <= 19){//←←推定パーティの平均レベル
			hp_rate += 0;
			power_rate += 0;
			//モンスターの範囲
			lv_range1 = 0;
			lv_range2 = 5;		
		}	
		if(ran1 >= 20 && ran1 <= 49){//←←推定パーティの平均レベル
			hp_rate += Math.floor(500);
			power_rate += Math.floor(500);
			//モンスターの範囲			
			lv_range1 = 6;
			lv_range2 = 10;	
		}
		if(ran1 >= 50 && ran1 <= 79){//←←推定パーティの平均レベル
			hp_rate += Math.floor(1500);
			power_rate += Math.floor(1500);			
			//モンスターの範囲			
			lv_range1 = 11;
			lv_range2 = 15;			
		}	
		if(ran1 >= 80){//←←推定パーティの平均レベル
			hp_rate += Math.floor(2000);
			power_rate += Math.floor(2000);
			//モンスターの範囲			
			lv_range1 = 16;
			lv_range2 = 19;				
		}	
		//ラスボスの手前、11階層のモブは+20000
		if(id_current_field == 11){
			hp_rate += 70000;
			power_rate += Math.floor(3000 );			
			//モンスター範囲は雑魚全て
			lv_range1 = 1;
			lv_range2 = 19;				
		}
		if(ran1 === 99){//←←推定パーティの平均レベル。またラスボスの時は強制的にこれ
			hp_rate += Math.floor(20000);
			power_rate += Math.floor(2000);				
			//雑魚モンスターも含めて一応強化			
			lv_range1 = 16;
			lv_range2 = 19;							
		}//
		for (lv_range1; lv_range1 <= lv_range2; lv_range1++) {
			monster_status_original[lv_range1][1] += hp_rate;//HP
			monster_status_original[lv_range1][2] += hp_rate;//MAXHP
			monster_status_original[lv_range1][5] += power_rate;//力
		}
		//味方のレベル99で防御力は約25%。防御の構えが30%。なのでレベル99かつ防御状態なら約55%。シールド状態(1回が20%,2回目で40%)だと+40%で合計で95%の防御力となる計算
		//ラスボスは直接設定
		//ラスボス1
		monster_status_original[20][1] += 100000;//HP
		monster_status_original[20][2] += 100000;//MAXHP
		monster_status_original[20][5] += 7000;//力
		//デバグ用
		// monster_status_original[20][1] += 10;//HP
		// monster_status_original[20][2] += 10;//MAXHP
		// monster_status_original[20][5] += 70;//力		
		//ラスボス2
		monster_status_original[21][1] += 200000;//HP
		monster_status_original[21][2] += 200000;//MAXHP
		monster_status_original[21][5] += 10000;//力	
		//デバグ用
		// monster_status_original[21][1] += 20;//HP
		// monster_status_original[21][2] += 20;//MAXHP
		// monster_status_original[21][5] += 10;//力			
		
		
		
	}
			
	/**
	* モンスターをランダムに出現させるための配列を作成
	* 出現数・モンスターレベル・ターンタイムなどなどを処理
	*/
	function monsterShuffle() {
		
		//戦闘背景の設定
		//下はフィールド画像と戦闘背景画像を関連付けするための参考データ
		//戦闘背景・・・0grass,1ougi,2rasboss,3suna,4doukutu,5douku2_2,6yougan,7water,8water2,9yuki,10yuki2,11rakuen,12makai
		//フィールド背景・・・0ホワイト、1草原、2砂漠、3洞窟、4洞窟2、5溶岩、6水、7水2、8雪、9氷、10楽園、11宇宙、12宇宙	
		//※ラスボスについては別記で実行

		if(id_current_field == 1)battleBackgroundChange(0);
		if(id_current_field == 2)battleBackgroundChange(3);
		if(id_current_field == 3)battleBackgroundChange(4);
		if(id_current_field == 4)battleBackgroundChange(5);
		if(id_current_field == 5)battleBackgroundChange(6);
		if(id_current_field == 6)battleBackgroundChange(7);
		if(id_current_field == 7)battleBackgroundChange(8);
		if(id_current_field == 8)battleBackgroundChange(9);
		if(id_current_field == 9)battleBackgroundChange(10);
		if(id_current_field == 10 && number_of_laps < 2)battleBackgroundChange(11);//戦闘背景rakuen
		if(id_current_field == 10 && number_of_laps >= 2)battleBackgroundChange(12);//戦闘背景makai
		if(id_current_field == 11)battleBackgroundChange(2);
		if(id_current_field == 12)battleBackgroundChange(2);
		
		
		//モンスターステータスの初期化
		monsterAbilityReset();
		// (Math.random() * ( (最大値 + 1) - 最小値 ) + 最小値;)
		// 最小値から最大値までの乱数
		monster_list = [];
		monster_status = [];
		let occurrences = 1;
		let	m_range1 = 1;
		let m_range2 = 10;
		let level_sum = 1;
		$.each(b_character_level, function(i, value) {
			level_sum += b_character_level[i][0];
		})
		let average_level = Math.floor(level_sum / b_character_level.length);
		if(average_level <= 19){
			//平均レベルが19未満ならモンスターを5体出現させる
			occurrences = Math.floor(Math.random() * ((6 + 1) - 2)) + 2;
			//平均レベルが19未満ならモンスターIDは0~5番目まで
			m_range1 = 0;
			m_range2 = 5;
			monsterAbilityScore(average_level);
			turn_time = [1,4000,8000,12000,16000,17000,18000,19000,20000,21000,22000,23000,24000,25000,26000,27000,28000]
			monster_position_top = [100,200,100,200,100,200,100,200];	
			monster_position_left = [5,5,75,75,145,145,215,215];			
		}	
		if(average_level >= 20 && average_level <= 49){
			occurrences = Math.floor(Math.random() * ((6 + 1) - 2)) + 2;
			//平均レベルが49未満ならモンスターIDは6~10番目まで			
			m_range1 = 6;
			m_range2 = 10;
			monsterAbilityScore(average_level);
			turn_time = [1,4000,8000,12000,16000,17000,18000,19000,20000,21000,22000,23000,24000,25000,26000,27000,28000]
			monster_position_top = [100,200,100,200,100,200,100,200];	
			monster_position_left = [5,5,75,75,145,145,215,215];				
		}	
		if(average_level >= 50 && average_level <= 79){
			occurrences = Math.floor(Math.random() * ((8 + 1) - 2)) + 2;
			//平均レベルが79未満ならモンスターIDは11~15番目まで			
			m_range1 = 11;
			m_range2 = 15;
			monsterAbilityScore(average_level);
			turn_time = [1,4000,8000,12000,16000,17000,18000,19000,20000,21000,22000,23000,24000,25000,26000,27000,28000]
			monster_position_top = [100,200,100,200,100,200,100,200];	
			monster_position_left = [5,5,75,75,145,145,215,215];				
		}
		if(average_level >= 80 && average_level <= 100){
			occurrences = Math.floor(Math.random() * ((8 + 1) - 2)) + 2;
			//平均レベルが100未満ならモンスターIDは16~19番目まで
			m_range1 = 16;
			m_range2 = 19;
			monsterAbilityScore(average_level);
			turn_time = [1,4000,8000,12000,16000,20000,24000,28000,31000,33000,37000,41000,44000,48000,49000,52000,56000];	
			monster_position_top = [100,200,100,200,100,200,100,200];	
			monster_position_left = [5,5,75,75,145,145,215,215];				
		}
		//ラスボスの設定
		//戦闘背景・・・0grass,1ougi,2rasboss,3suna,4doukutu,5douku2_2,6yougan,7water,8water2,9yuki,10yuki2,11rakuen,12makai
		//フィールド背景・・・0ホワイト、1草原、2砂漠、3洞窟、4洞窟2、5溶岩、6水、7水2、8雪、9氷、10楽園、11宇宙、12宇宙		
		if(id_current_field == 12){
		//if(id_current_field == 1){//デバグ用		
			average_level = 999;
			occurrences = 1;			
			m_range1 = 20;//ラスボスでは無関係の設定
			m_range2 = 20;//ラスボスでは無関係の設定
			monsterAbilityScore(99);
			turn_time = [1,4000,8000,12000,16000,20000,24000,28000,31000,33000,37000,41000,44000,48000,49000,52000,56000];	
			monster_position_top = [0,200,100,200,100,200,100,200];	
			monster_position_left = [5,5,75,75,145,145,215,215];				
		}
		//ラスボス2の設定	
		if(number_of_laps >= 2 && id_current_field == 10){		
		//if(id_current_field == 0){//デバグ用
			average_level = 999;
			occurrences = 1;			
			m_range1 = 21;//ラスボスでは無関係の設定
			m_range2 = 21;//ラスボスでは無関係の設定
			monsterAbilityScore(99);
			turn_time = [1,4000,8000,12000,16000,20000,24000,28000,31000,33000,37000,41000,44000,48000,49000,52000,56000];	
			monster_position_top = [0,200,100,200,100,200,100,200];	
			monster_position_left = [5,5,75,75,145,145,215,215];		
		}
		let c = 0;
		let match_name = [];
		//モンスターリストとモンスターステータスリストを一応コピーして使う
		let mon_list = $.extend(true, [], monster_list_original);
		let mon_status = $.extend(true, [], monster_status_original);
		//ループ中に一定の範囲内で乱数を生成する。※例:モンスターIDは6番目(m_range1)~10番目(m_range2)までだったら、そのクラスのモンスターを出現させる	
		//新しいモンスターリストを作成するだけなので、(モンスターリストの)オリジナルコピーをループさせる必要はないが・・・、何体出現させるかランダムだし、まぁとりあえず適当だったので
		$.each(mon_list, function(i, value) {
			let	rand_monster = Math.floor(Math.random() * ((m_range2 + 1) - m_range1)) + m_range1;
			//↑この乱数はラスボスでは適用しない
			if(average_level >= 999){//ラスボスの出現条件はすでに設定済みなので、ラスボスの出現条件を適当(average_levelを999)にしている。ループは一回で終了
				let lassboss_id = 20;
				//ラスボス1の出現
				if(id_current_field == 12){
				//if(id_current_field == 1){//デバグ用	1にしたら最初のフィールドで戦闘開始
					lassboss_id = 20;
					monster_list[c] = mon_list[20];
				}	
				//ラスボス2の出現
				if(number_of_laps >= 2 && id_current_field == 10){
				//if(id_current_field == 0){//デバグ用 1にしたら最初のフィールドで戦闘開始
					lassboss_id = 21;
					monster_list[c] = mon_list[21];	
				}
				//console.log(mon_status);	
				//2次元配列の初期化は厄介。
				monster_status[c] = []; 
				//↑2次元配列の初期化
				monster_status[c][0] = mon_status[lassboss_id][0];
				monster_status[c][1] = mon_status[lassboss_id][1];
				monster_status[c][2] = mon_status[lassboss_id][2];				
				monster_status[c][3] = mon_status[lassboss_id][3];
				monster_status[c][4] = mon_status[lassboss_id][4];
				monster_status[c][5] = mon_status[lassboss_id][5];
				monster_status[c][6] = mon_status[lassboss_id][6];
				monster_status[c][7] = mon_status[lassboss_id][7];
				monster_status[c][8] = mon_status[lassboss_id][8];
				monster_status[c][9] = mon_status[lassboss_id][9];
				monster_status[c][10] = mon_status[lassboss_id][10];		
			}else{
				//var regexp =/[ァ-ンー]/g;カタカナの正規表現
				//var regexp =/"(.*?)"/g;任意一文字以上の正規表現
				var result = mon_list[rand_monster].split('"');
				//ダブルクゥォーテーションで囲まれている2個めの要素を抜き取る
				//alt="poisonousMushroom"  name="poisonousMushroom" src="https://likehuman.info/wp-content/uploads/2022/12/m_kinoko01.png"
				//上記の場合「poisonousMushroom」がそれに該当する
				match_name[c] = result[1];
				monster_list[c]	= mon_list[rand_monster].replace(result[1],result[1] + c);
				//「毒キノコ1」「毒キノコ2」、こうすることで同種のモンスターを判別している				
				//つまるところ、連番を追記することで、以下のような後々の同種モンスターをターゲット可能にしている
				//let m = monster_list.indexOf(target_monster_list[i]);
				
				
				//モンスター攻撃力に揺らぎをつくる
				// (Math.random() * ( (最大値 + 1) - 最小値 ) + 最小値;)
				let variable_range = Math.floor(Math.random() * ((8 + 1) - 2)) + 2;
									 
				let m_power = Math.floor(mon_status[rand_monster][5] * (variable_range / 100));
				//console.log(m_power);	
				

				//モンスターステータスの並び
				//[1,20,200,200,200,50,20,20,20,1000,1]
				//2次元配列の初期化は厄介。
				monster_status[c] = []; 
				//↑2次元配列の初期化
				monster_status[c][0] = mon_status[rand_monster][0];
				monster_status[c][1] = mon_status[rand_monster][1];
				monster_status[c][2] = mon_status[rand_monster][2];				
				monster_status[c][3] = mon_status[rand_monster][3];
				monster_status[c][4] = mon_status[rand_monster][4];
				monster_status[c][5] = mon_status[rand_monster][5] + m_power;
				monster_status[c][6] = mon_status[rand_monster][6];
				monster_status[c][7] = mon_status[rand_monster][7];
				monster_status[c][8] = mon_status[rand_monster][8];
				monster_status[c][9] = mon_status[rand_monster][9];
				monster_status[c][10] = mon_status[rand_monster][10];			
			}
			c += 1;
			//出現モンスター数を満たしたらループを抜ける
			if(occurrences === c){
				return false;
			}
		})
	};

	
	/* 
	モンスターの位置
	*/		
	function monsterStartPosition(i){
	
		//ボスの場合は表示位置、表示サイズ共に巨大化させる
		let m_boss_class = [];
		m_boss_class = monster_list[i].split('"')
		//' alt="jQuery" name="jQuery" src="https://likehuman.info/wp-content/uploads/2023/03/m_b_jquery.png" >';
		//m_boss_class[3]はname属性のジェイクエリー,ワードプレスが該当する
		if(m_boss_class[3] === "jQuery" || m_boss_class[3] === "wordPress"){
			$(".monster_move_"+i).css({
				'left' : monster_position_left[i] + 'px',
				'top'  : (monster_position_top[i] + 0) + 'px'
			});			
			//後からフェードインさせるので一旦非表示
			$(".monster_"+i).css({
				'display': 'none',
				'width' : 300 + 'px',
				'height': 250  + 'px'
			});			
		}else{
			//通常モンスターの場合
			$(".monster_move_"+i).css({
				'left' : monster_position_left[i] + 'px',
				'top' : monster_position_top[i]  + 'px'
			});			
			//後からフェードインさせるので一旦非表示
			$(".monster_"+i).css({
				'display': 'none',
				'width' : 70 + 'px',
				'height': 70  + 'px'
			});			
		}	
		//徐々に表示
		$(".monster_"+i).fadeIn(500);

		//モンスターの初期位置を格納
		monster_position[i] = $(".monster_"+i).position();
		//モンスター名を格納
		monster_name[i] = $(".monster_"+i).attr("name");
		//モンスター名を表示
		$('.battle_monster').append('<div class="m_name_' + i + '">' + monster_name[i] +'</div>');
		
		
		let m_monster_class = [];
		m_monster_class = monster_list[0].split('"')				
		//' alt="jQuery" name="jQuery" src="https://likehuman.info/wp-content/uploads/2023/03/m_b_jquery.png" >';
		//m_boss_class[3]はname属性のジェイクエリーが該当する
		//const battle_bgm7 = [".bgm_normal_battle",".bgm_lassboss",".bgm_village","bgm_lassboss2"];
		if(m_monster_class[3] === "jQuery"){
			battle_boss_flag = true;
			battle_boss_flag2 = true;
			bgmPlayback(bgm_load_item,battle_bgm7[1]);
		}else if(m_monster_class[3] === "wordPress"){
			battle_boss_flag = true;
			bgmPlayback(bgm_load_item,battle_bgm7[3]);
		}else if(id_current_field == 11){
			bgmPlayback(bgm_load_item,battle_bgm9[0]);			
		}else{
			bgmPlayback(bgm_load_item,battle_bgm7[0]);			
		}	
	}
	
	/* 
	戦闘キャラの初期位置
	*/		
	function battleStartPosition(i){
		b_character_rect_1[i][0] = 32;
		b_character_rect_1[i][1] = 32;
		b_character_rect_1[i][2] = 0;		
		b_character_rect_1[i][3] = 64;
		$('.battle_character_'+i).css({
			'top' : - b_character_rect_1[i][0] + 'px',
			'left': - b_character_rect_1[i][2] + 'px',
			'z-index' : '92',
			'clip':'rect('+
				b_character_rect_1[i][0] + 'px,' +
				b_character_rect_1[i][1] + 'px,' +
				b_character_rect_1[i][3] + 'px,' +
				b_character_rect_1[i][2] + 'px' +
			')'
		});
		//キャラクターの初期位置
		$(".battle_move_"+i).css({
			'left' : b_character_position_left_1[i] + 'px',
			'top' : b_character_position_top_1[i]  + 'px'
		});
		//戦闘キャラの初期位置を格納
		battle_position_chara[i] = $(".battle_move_"+i).position();
	}
	//パーティのステータスを表示する
	function battle_status_show(){
		$('.battle_tactics').after('<div class="battle_status"></div>');
		$.each(battle_member, function(i, value) {	
/* 			$('.battle_status').append('<div class="selected_chara_'+ i +'">' + member_name[i] + '</div><div class="selected_chara_'+ i +'">Lv ' + b_character_level[i][0] +'</div><div class="selected_chara_'+ i +'">HP</div><div class="selected_chara_'+ i +'">' + b_character_hp[i] +'</div><div class="selected_chara_'+ i +'">/</div>'+'<div class="selected_chara_'+ i +'">' + b_character_max_hp[i] +'</div>'+'<div class="selected_chara_'+ i +'"></div><div class="selected_chara_'+ i +'">MP</div><div class="selected_chara_'+ i +'">' + b_character_mp[i] +'</div><div class="selected_chara_'+ i +'">/</div><div class="selected_chara_'+ i +'">' + b_character_max_mp[i] +'</div>'); */	

			$('.battle_status').append('<div class="selected_chara_'+ i +'">' + member_name[i] + '</div><div class="selected_chara_'+ i +'">Lv ' + b_character_level[i][0] +'</div><div class="selected_chara_'+ i +'">HP</div><div class="selected_chara_'+ i +'">' + b_character_hp[i] +'</div><div class="selected_chara_'+ i +'"> MP</div><div class="selected_chara_'+ i +'">' + b_character_mp[i] +'</div>');	
		})	
	}	
	
/* 	function battleEnd(){
		//メインキャラの位置を再設定
		$(".main_character_move").css({
			'left' : main_left +'px',
			'top' : main_top+ 'px'
		});
		//メインキャラの身体の動きを再開
		mainCharaMove();
	} */
	
	//モンスターの選択エフェクト(モンスター頭上のカーソル)
	function monsterSelect(i){
		$('[class^="m_select_arrow_img_"]').remove();
		clearTimeout(stop_m_arrow_timer);
		$('.monster_s_effect_' + i).append('<img class="m_select_arrow_img_' + i +'" style="position: absolute;" name="モンスター矢印" src="' + m_select_arrow[0] + '">');
		
		//ボスの場合の表示位置準備
		let m_boss_class = [];
		let boss_position = 0;
		m_boss_class = monster_list[i].split('"')
		//' alt="jQuery" name="jQuery" src="https://likehuman.info/wp-content/uploads/2023/03/m_b_jquery.png" >';
		//m_boss_class[3]はname属性のジェイクエリーが該当する
		if(m_boss_class[3] === "jQuery" || m_boss_class[3] === "wordPress"){
			boss_position = 125;
		}else{
			boss_position = 25;
		}	
		
		
		$('.monster_s_effect_' + i).css({
			'left' :(monster_position_left[i]  + boss_position) +'px',
			'top' : (monster_position_top[i]  - 10) + 'px',
			'z-index' : '94'

		});
		//処理をループさせる
		stop_m_arrow_timer = setInterval(function(){
			$('.m_select_arrow_img_' + i).css({'opacity': '1'});
			//1から2へと変化する数値を利用しているだけなのでopacity:1以外でもOK
			$('.m_select_arrow_img_' + i).animate({opacity: 2 },{
				duration:1700,
				//stepで時間に比例して変化する内容を記述
				step:function(o){
				//1から2へと変化する数値を利用しているだけなのでopacity:1とかじゃなくてもOK。暫定でこのようにしているだけ
				$(this).css({transform:'rotateY(' + (o * 1080) + 'deg)'});
				},
				//完了処理
				//complete:function(){$('.effect_img_' + i).css('opacity', '1');}
			},2000);
		})
	}

	//カーソルのエフェクト(キャラクター頭上のカーソル)
	function arrowSettings(i){
		battle_position_chara[i] = $(".battle_move_"+i).position();
		clearTimeout(effect_timer_1);
		$('[class^="effect_img_"]').remove();
		$('.b_chara_effect_' + i).append('<img class="effect_img_' + i +'" style="position: absolute;" name="矢印" src="' + effect_2[0] + '">');	
		$('.b_chara_effect_' + i).css({
			'left' : battle_position_chara[i].left +'px',
			'top' : battle_position_chara[i].top  - 22 + 'px',
			'z-index' : '94'
		});
		//処理をループさせる
		effect_timer_1 = setInterval(function(){
			$('.effect_img_' + i).css({'opacity': '1'});
			//1から2へと変化する数値を利用しているだけなのでopacity:1以外でもOK
			$('.effect_img_' + i).animate({opacity: 2 },{
				duration:1700,
				//stepで時間に比例して変化する内容を記述
				step:function(o){
				//1から2へと変化する数値を利用しているだけなのでopacity:1とかじゃなくてもOK。暫定でこのようにしているだけ
				$(this).css({transform:'rotateY(' + (o * 1080) + 'deg)'});
				},
				//完了処理
				//complete:function(){$('.effect_img_' + i).css('opacity', '1');}
			},2000);
		})
	}
	
/******************************** 	
	回復系スキルを使用した時の味方選択 
*******************************/
	function recoveryArrowSettings(i){
		battle_position_chara[i] = $(".battle_move_"+i).position();
		clearTimeout(effect_timer_2);
		$('[class^="recovery_arrow_"]').remove();
		$('.b_chara_effect_' + i).append('<img class="recovery_arrow_' + i +'" style="position: absolute;" name="矢印" src="' + effect_2[0] + '">');	
		//細かな配置はb_chara_effect_ではできない。そもそもb_chara_effect_は他でも使用しているので設定すべきではない
		//ということで画像クラスで修正
		$('.recovery_arrow_' + i).css({
			'left' : 30 +'px',
			'top' : 20 + 'px',
			'z-index' : '94'
		});
		//b_chara_effect_を下記のように設定しないと、4人目が未設定なので矢印の位置が画面左上(初期位置)になってしまう
		$('.b_chara_effect_' + i).css({
			'left' : battle_position_chara[i].left +'px',
			'top' : battle_position_chara[i].top  - 22 + 'px',
			'z-index' : '94'
		});
		//処理をループさせる
		effect_timer_2 = setInterval(function(){
			$('.recovery_arrow_' + i).css({
				'opacity': '1',
				'rotate': '93deg',
				'filter': 'hue-rotate(140deg)'
				
			});
			//1から2へと変化する数値を利用しているだけなのでopacity:1以外でもOK
			$('.recovery_arrow_' + i).animate({opacity: 2 },{
				duration:1700,
				//stepで時間に比例して変化する内容を記述
				step:function(o){
				//1から2へと変化する数値を利用しているだけなのでopacity:1とかじゃなくてもOK。暫定でこのようにしているだけ
				$(this).css({transform:'rotateY(' + (o * 1080) + 'deg)'});
				},
				//完了処理
				//complete:function(){$('.effect_img_' + i).css('opacity', '1');}
			},2000);
		})
	}
	
			
/******************************** 	
	味方への補助魔法演出
*******************************/
	function recoveryEffect(i,ii){
		//詠唱キャラの回復エフェクト
		battle_position_chara[i] = $(".battle_move_"+i).position();
		$('[class^="take_recovery_ef_img"]').remove();
		$('.b_chara_effect_' + i).append('<img class="take_recovery_ef_img' + i +'" style="position: absolute;" name="回復詠唱" src="' + partner_effect_list[0] + '">');
		$('.b_chara_effect_' + i).css({
			'left' : battle_position_chara[i].left +'px',
			'top' : battle_position_chara[i].top  - 22 + 'px',
			'z-index' : '94'
		});
		//$('.b_chara_effect_' + ii)を起点としてleftやtopを決める。ちなみにb_chara_effect_はあくまでも基準点なので、
		//$('.b_chara_effect_' + ii)で具体的な画像エフェクトの配置を設定することはできない
		//画像配置の細かな設定をする時は下記のように画像クラスで設定する必要がある
		$('.take_recovery_ef_img' + i).css({	
			'background-color':'transparent',
			'left' : -40 + 'px',
			'top'  : -50 + 'px',
			'width' : 100 + 'px',
			'height': 120  + 'px',
			'z-index' : 94
		});
		//BGM
		if(bgm_village_flag){
			$(battle_bgm5[0]).get(0).currentTime = 0;
			$(battle_bgm5[0]).get(0).play();
		}	
		//時間差で下記処理(回復対象キャラに対する補助魔法エフェクト)を実行
		setTimeout(function(){
			//詠唱者の回復エフェクトを削除
			$('[class^="take_recovery_ef_img"]').remove();
			//対象キャラにエフェクトを設定する前の下準備
			battle_position_chara[ii] = $(".battle_move_"+ii).position();
			$('[class^="recovery_ef_img"]').remove();
			$('.b_chara_effect_' + ii).css({
				'left' : battle_position_chara[ii].left +'px',
				'top' : battle_position_chara[ii].top  - 22 + 'px',
				'z-index' : '94'
			});
			
			//バトル画面に表示されるスキルの概要
			skillOverview(skill_overview[b_chara_standby[i][0]]);			
			
			//補助魔法スキル毎のエフェクト
			if(b_chara_standby[i][0] == 6){
				if(skill_command_2[6] === "megahealing"){
					$.each(b_character_hp, function(t, t_value) {
						healAnAlly(i,t,1);
					});
				}else{
					healAnAlly(i,ii,1);
				}
			}
			if(b_chara_standby[i][0] == 10){
				if(skill_command_2[10] === "megaRevival"){
					$.each(b_character_hp, function(t, t_value) {
						healAnAlly(i,t,3);
					});
				}else{
					healAnAlly(i,ii,3);
				}
			}
			if(b_chara_standby[i][0] == 14){
				if(skill_command_2[14] === "megaShield"){
					$.each(b_character_hp, function(t, t_value) {
						healAnAlly(i,t,4);	
					});
				}else{
					healAnAlly(i,ii,4);		
				}
			}
			
			if(b_chara_standby[i][0] == 18){
				if(skill_command_2[18] === "megaForceFang"){
					$.each(b_character_hp, function(t, t_value) {
						healAnAlly(i,t,5);	
					});
				}else{
					healAnAlly(i,ii,5);		
				}
			}
			// if(b_chara_standby[i][0] == 18){
				// healAnAlly(i,ii,5);
			// }									
			//MPの消費
			let mp = Number(b_chara_standby[i][0]);
			//ラスボスが倒せないので僧侶はスキル番号*10を消費MPとしておく
			b_character_mp[i] -= (mp * 10);
			if(b_character_mp[i] <= 0){
				b_character_mp[i] = 0;
			}
			
			//回復したことをステータスに反映させる
			$(".battle_status").remove();
			battle_status_show();
		},500);
		
	}
/******************************** 	
	回復魔法エフェクト
*******************************/
	function healAnAlly(my,partner,ef_id){
		$('.b_chara_effect_' + partner).append('<img class="recovery_ef_img' + partner +'" style="position: absolute;" name="kaifuku" src="' + partner_effect_list[ef_id] + '">');
		//画像配置の細かな設定をする時は下記のように画像クラスで設定する必要がある
		$('.recovery_ef_img' + partner).css({	
			'background-color':'transparent',
			'left' : -30 + 'px',
			'top'  : -30 + 'px',
			'width' : 100 + 'px',
			'height': 120  + 'px',
			'z-index' : 94
		});	
		//詠唱者の魔力相当の数値を回復量として、味方HPに反映させる
		//MaxHPをオーバーした場合はMaxHPと同じにしておく
		//ただし、HP0(倒れた)キャラは回復できない
		if(b_chara_standby[my][0] == 6){
			if(b_character_hp[partner] !== 0){
				recoveryEffect2(my,partner);
			}else{
				b_character_hp[partner] = 0;
				//時間差で下記処理(回復エフェクトに関するCSSを削除)を実行
				//詠唱エフェクトの削除
				setTimeout(function(){
					$('[class^="recovery_ef_img"]').remove();
					$('[class^="recovery_ef_"]').remove();
				},1000);
			}
		}
		//倒れた仲間を復活させる
		//復活したときのHPは詠唱者の魔力相当分
		//生存者にかけても無効
		if(b_chara_standby[my][0] == 10){
			if(b_character_hp[partner] !== 0){
				//時間差で下記処理(回復エフェクトに関するCSSを削除)を実行
				//詠唱エフェクトの削除
				setTimeout(function(){
					$('[class^="recovery_ef_img"]').remove();
					$('[class^="recovery_ef_"]').remove();
				},1000);					
			}else{
				recoveryEffect2(my,partner);
				//倒れた仲間を立ち上がらせる
				$('.battle_character_' + partner).css({'opacity': '0'});
				$('.battle_character_' + partner).animate({opacity: 1 },{
					duration:2000,
					easing:'swing',
					step:function(o){
						$(this).css({transform:'rotate(+' + (o * 0) + 'deg)'});
				},})
			}
		}
		//防御力をあげる
		if(b_chara_standby[my][0] == 14){
			shield_count[partner] += 1;
			//シールドの有効回数は2回まで。ただしエフェクトは実行される
			if(shield_count[partner] < 3)b_character_status[partner][3] += 20
			setTimeout(function(){
					$('[class^="recovery_ef_img"]').remove();
					$('[class^="recovery_ef_"]').remove();
			},1000);
			$(battle_bgm5[5]).get(0).currentTime = 0;
			$(battle_bgm5[5]).get(0).play();
						
		}
		//攻撃力をあげる
		if(b_chara_standby[my][0] == 18){
			force_count[partner] += 1;
			if(force_count[partner] < 3){
				if(partner == 0 || partner == 1 ){
					//戦士系の場合は攻撃力
					b_character_status[partner][0] += Math.round(b_character_status[partner][0] * 0.5);
				}else{
					//マジシャン系の場合は魔力
					b_character_status[partner][1] += Math.round(b_character_status[partner][1] * 0.5);					
				}	
			}	
			setTimeout(function(){
					$('[class^="recovery_ef_img"]').remove();
					$('[class^="recovery_ef_"]').remove();
			},1000);
			$(battle_bgm5[6]).get(0).currentTime = 0;
			$(battle_bgm5[6]).get(0).play();
						
		}	
	}			
/******************************** 	
	味方への補助魔法演出__その2
*******************************/
	function recoveryEffect2(i,ii){
		b_character_hp[ii] += b_character_status[i][1];
		if(b_character_max_hp[ii] <= b_character_hp[ii])b_character_hp[ii] = b_character_max_hp[ii];
		//回復数値を頭上に表示
		$('.b_chara_effect_' + ii).append('<div class="recovery_ef_'+ ii +'" style="position: absolute;">' +  b_character_status[i][1] + '</div>');
		$('.b_chara_effect_' + ii).css({
			'left' : (battle_position_chara[ii].left - 15) +'px',
			'top' : battle_position_chara[ii].top  - 22 + 'px',
			'z-index' : '94'
		});
		$('.recovery_ef_' + ii).css({
			'font-weight':'bold',
			'color':'blue',
			'font-size':'0.9em',
			'z-index': 96
		});
		
		//$('.recovery_ef_' + ii).animate({opacity:"0"}, '20', 'swing').animate({opacity:"1"}, '20', 'swing');

		//メンバーに表示される回復数値を軽くバウンドさせる
		$('.recovery_ef_' + ii).animate({top:"-10px"}, 200).animate({top:"-4px"}, 200)
		//時間差で下記処理(回復エフェクトに関するCSSを削除)を実行
		setTimeout(function(){
			$('[class^="recovery_ef_img"]').remove();
			$('[class^="recovery_ef_"]').remove();
		},1000);
		//BGM
		if(bgm_village_flag){
			//回復魔法
			if(b_chara_standby[i][0] == 6){
				$(battle_bgm5[1]).get(0).currentTime = 0;
				$(battle_bgm5[1]).get(0).play();
			}
			//復活魔法
			if(b_chara_standby[i][0] == 10){
				$(battle_bgm5[4]).get(0).currentTime = 0;
				$(battle_bgm5[4]).get(0).play();
			}
		}
	}

/******************************** 	
	スキル説明
*******************************/
	function skillOverview(skill_overview_disp){
		$('[class^="battle_message"]').remove();
		//バトル中のメッセージ
		$('.battle_container').prepend('<div class ="battle_message">' + skill_overview_disp + '</div>');
		$(".battle_message").css({
			top:  battle_message_position_left + 'px',
			left: battle_message_position_left + 'px',
			zIndex : 91
		});
		setTimeout(function(){
			$('[class^="battle_message"]').remove();
		},1500);
	}	
	
/******************************** 	
武器攻撃および攻撃魔法演出
*******************************/
// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};
	function weaponEffect(i){
		battle_position_chara[i] = $(".battle_move_"+i).position();
		$('[class^="weapon_effect_img_"]').remove();
		//奥義については背景を変える※ただしラスボスの時は変更しない
		let m_boss_class = [];
		m_boss_class = monster_list[0].split('"')
		if(m_boss_class[3] !== "jQuery" && m_boss_class[3] !== "wordPress"){
			if( b_chara_standby[i][0] == 16 || b_chara_standby[i][0] == 17 || b_chara_standby[i][0] == 19){
				battleBackgroundChange(1);		
			}
		}
		//攻撃魔法を使用する場合
		if(b_chara_standby[i][0] == 7 || b_chara_standby[i][0] == 11 || b_chara_standby[i][0] == 15 || b_chara_standby[i][0] == 19){
			//詠唱キャラの攻撃魔法エフェクト
			$('.b_chara_effect_' + i).append('<img class="take_blackmagic_ef_img' + i +'" style="position: absolute;" name="黒魔法詠唱" src="' + weapon_list[5] + '">');
			$('.b_chara_effect_' + i).css({
				'left' : battle_position_chara[i].left +'px',
				'top' : battle_position_chara[i].top  - 22 + 'px',
				'z-index' : '94'
			});
			$('.take_blackmagic_ef_img' + i).css({	
					'background-color':'transparent',
					'left' : -40 + 'px',
					'top'  : -50 + 'px',
					'width' : 100 + 'px',
					'height': 120  + 'px',
					'z-index' : 94
			});
	
			//BGM
			if(bgm_village_flag){
				$(battle_bgm5[2]).get(0).currentTime = 0;
				$(battle_bgm5[2]).get(0).play();
			}

			//時間差で下記処理(攻撃魔法エフェクトに関するCSSを削除)を実行
			setTimeout(function(){
				$('[class^="take_blackmagic_ef_img"]').remove();

			},1000);
		}else{//武器によるスキルを使用する場合
			$('[class^="weapon_effect_img_"]').remove();
			$('.b_chara_effect_' + i).append('<img class="weapon_effect_img_' + i +'" style="position: absolute;" name="武器" src="' + weapon_list[i] + '">');	
			$('.b_chara_effect_' + i).css({
				'left' : battle_position_chara[i].left - 50 +'px',
				'top' : battle_position_chara[i].top  - 10 + 'px',
				'z-index' : '94'
			});
			//$('.weapon_effect_img_' + i).delay(3000);
			$('.weapon_effect_img_' + i).css({'opacity': '0'});
			//1から2へと変化する数値を利用しているだけなのでopacity:1以外でもOK
			$('.weapon_effect_img_' + i).animate({opacity: 1 },{
				duration:700,
				easing:'swing',
				//stepで時間に比例して変化する内容を記述
				step:function(o){
				//1から2へと変化する数値を利用しているだけなのでopacity:1とかじゃなくてもOK。暫定でこのようにしているだけ
				$(this).css({transform:'rotate(-' + (o * 200) + 'deg)',scale:'2'});
				},
				//完了処理
				complete:function(){$('.weapon_effect_img_' + i).css('opacity','0');}
			})
		}	
			//スキル番号一覧
			// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
			// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
			// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
			// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};
			
		//武器によってSEを変える
		if(bgm_village_flag){
			let t = b_chara_standby[i][0];
			switch (Number(t)) {
				case 0:	
					$(battle_bgm[0]).get(0).currentTime = 0;
					$(battle_bgm[0]).get(0).play();
					break;					
				case 1:				
					$(battle_bgm[1]).get(0).currentTime = 0;
					$(battle_bgm[1]).get(0).play();
					break;
				case 2:
				case 3:					
					$(battle_bgm[2]).get(0).currentTime = 0;
					$(battle_bgm[2]).get(0).play();
					break;
				case 4:
					//一定の間、ループさせることで連続斬撃音を再現
					let gg = setInterval(function(){
						$(battle_bgm[0]).get(0).currentTime = 0;
						//再生速度の変更
						$(battle_bgm[0]).get(0).playbackRate = 2.5;
						$(battle_bgm[0]).get(0).play();							
					},300);
					setTimeout(function(){
						clearTimeout(gg);
					},1000);
					break;					
				case 5:	
					//一定の間、ループさせることで連続斬撃音を再現
					let gg2 = setInterval(function(){
						$(battle_bgm[0]).get(0).currentTime = 0;
						//再生速度の変更
						$(battle_bgm[0]).get(0).playbackRate = 2.5;
						$(battle_bgm[0]).get(0).play();							
					},300);
					setTimeout(function(){
						clearTimeout(gg2);
					},1000);
					break;
				case 7:	
					$(battle_bgm5[3]).get(0).currentTime = 0;
					$(battle_bgm5[3]).get(0).play();
					break;						
				case 8:	
					$(battle_bgm[3]).get(0).currentTime = 0;
					$(battle_bgm[3]).get(0).play();
					break;	
				case 9:	
					//一定の間、ループさせることで連続斬撃音を再現
					let gg3 = setInterval(function(){
						$(battle_bgm[4]).get(0).currentTime = 0;

						$(battle_bgm[4]).get(0).play();							
					},200);
					setTimeout(function(){
						clearTimeout(gg3);
					},500);
					break;
				case 11:	
					$(battle_bgm[5]).get(0).currentTime = 0;
					$(battle_bgm[5]).get(0).play();
					break;
				case 12:	
					$(battle_bgm[6]).get(0).currentTime = 0;
					$(battle_bgm[6]).get(0).play();
					break;	
				case 13:	
					$(battle_bgm[7]).get(0).currentTime = 0;
					$(battle_bgm[7]).get(0).play();
					break;
				case 15:	
					$(battle_bgm[10]).get(0).currentTime = 0;
					$(battle_bgm[10]).get(0).play();
					break;						
				case 16:	
					$(battle_bgm[8]).get(0).currentTime = 0;
					$(battle_bgm[8]).get(0).play();
					break;	
				case 17:	
					$(battle_bgm[9]).get(0).currentTime = 0;
					$(battle_bgm[9]).get(0).play();
					break;
				case 19:	
					$(battle_bgm[11]).get(0).currentTime = 0;
					$(battle_bgm[11]).get(0).play();
					break;						
				default:
					$(battle_bgm[0]).get(0).currentTime = 0;
					$(battle_bgm[0]).get(0).play();
					break;
			}
		}	
	}
	
	
/********************************** 	
ヒットエフェクト
iはメンバー
iiは使用するヒットエフェクト 
***********************************/
	//スキル番号一覧
	// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
	// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
	// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
	// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};	
	function hitEffect(i,ii){
		let m = monster_list.indexOf(target_monster_list[i]);
		//攻撃対象モンスターが倒されていたら、0番目のモンスターに設定
		if(m === -1)m = 0;
		
		//バトル画面に表示されるスキルの概要
		//skillOverview(skill_overview[b_chara_standby[i][0]]);
		skillOverview(skill_overview[b_chara_standby[i][0]]);
			
/* 		//テストで次元切りの時だけ攻撃力増加 
		if(hit_list[ii] === hit_list[16])b_character_status[i][0] += (b_character_status[i][0] * 5);
		//このメソッドでスキルに合わせてダメージも増加させる予定 */
		
		
		
		$('[class^="hit_attack_"]').remove();
		$('.monster_s_effect_' + m).append('<div class="hit_attack_'+ m +'" style="position: absolute;"><img class="hit_effect_img_' + i +'"' + hit_list[ii] + '</div>');
		//
		//大技の時はかっこよく演出したいので、少し設定を変更する
		//
	// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
	// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
	// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
	// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};			
		let skill_position = [0,0,2.5];
		if(hit_list[ii] === hit_list[4] || hit_list[ii] === hit_list[5] || hit_list[ii] === hit_list[7] || hit_list[ii] === hit_list[8] || hit_list[ii] === hit_list[9] || hit_list[ii] === hit_list[11] || hit_list[ii] === hit_list[12] || hit_list[ii] === hit_list[13] || hit_list[ii] === hit_list[15] || hit_list[ii] === hit_list[16] || hit_list[ii] === hit_list[17] || hit_list[ii] === hit_list[19]){
			//ridingAttack
			if(hit_list[ii] === hit_list[4]){
				skill_position[0] = 0;
				skill_position[1] = 50;				
			}//dancingSword	
			if(hit_list[ii] === hit_list[5]){
				skill_position[0] = 0;
				skill_position[1] = 50;	
			}//ThunderCrash
			if(hit_list[ii] === hit_list[7]){
				skill_position[0] = -50;
				skill_position[1] = -60;	
				skill_position[2] = 4;				
			}//ThreeHammers
			if(hit_list[ii] === hit_list[8]){
				skill_position[0] = -50;
				skill_position[1] = 50;
				skill_position[2] = 3.5;
			}//shadedSword	
			if(hit_list[ii] === hit_list[9]){
				skill_position[0] = -60;
				skill_position[1] = -40;
				skill_position[2] = 3.5;				
			}//earthFire
			if(hit_list[ii] === hit_list[11]){
				skill_position[0] = -90;
				skill_position[1] = 60;
				skill_position[2] = 4.5;				
			}//flameSlasher
			if(hit_list[ii] === hit_list[12]){
				skill_position[0] = 0;
				skill_position[1] = 0;		
			}//mistSlash
			if(hit_list[ii] === hit_list[13]){
				skill_position[0] = -70;
				skill_position[1] = -30;
				skill_position[2] = 4.5;				
			}//heavenBlow
			if(hit_list[ii] === hit_list[15]){
				skill_position[0] = 0;
				skill_position[1] = 0;
			}//dimensionCut
			if(hit_list[ii] === hit_list[16]){
				skill_position[0] = 0;
				skill_position[1] = 0;
			}	
			//Iai-giri
			if(hit_list[ii] === hit_list[17]){
				skill_position[0] = -100;
				skill_position[1] = -100;				
			}//hellBerd
			if(hit_list[ii] === hit_list[19]){
				skill_position[0] = -50;
				skill_position[1] = -50;	
			}		
			$('.monster_s_effect_' + m).css({
				'left' : skill_position[0]  +'px',
				'top' : skill_position[1] + 'px',			
				'background-color':'transparent',
				'width' : 100 + 'px',
				'height': 120  + 'px',
				'z-index' : 94
			});
			//filter: brightness(200%);明度の変更ができる
			//filter: saturate(200%);色彩の変更ができる
			//filter: sepia(200%);セピアにできる※セピアの場合は数値を低くすることで反映する。0%で完全なセピア
			//$('.battle_container').css({'filter': 'brightness(70%)'});
			$('.hit_effect_img_' + i).css({'filter': 'brightness(500%)'});
			$('.hit_effect_img_' + i).css({'filter': 'saturate(500%)'});				

			$('.hit_effect_img_' + i).css({'opacity': '1'});
			//1から2へと変化する数値を利用しているだけなのでopacity:1以外でもOK
			$('.hit_effect_img_' + i).animate({opacity: 0 },{
				duration:2000,
				easing:'swing',
				//stepで時間に比例して変化する内容を記述
				step:function(o){
				//1から2へと変化する数値を利用しているだけなのでopacity:1とかじゃなくてもOK。暫定でこのようにしているだけ
					$(this).css({
						//ransform:'rotate(-' + (o * 200) + 'deg)',
						'zoom' : skill_position[2]
					});
				},
				//完了処理 透明度、明度、色彩を元に戻す。※透明度だけは0にする。
				complete:function(){
					$('.hit_effect_img_' + i).css('opacity','0');
					//$('.battle_container').css({'filter': 'brightness(100%)'});
					$('.hit_effect_img_' + i).css({'filter': 'brightness(100%)'});
					$('.hit_effect_img_' + i).css({'filter': 'saturate(100%)'});						
					}
			})
			setTimeout(function(){
				$('[class^="hit_attack_"]').remove();
			},1950);			
		}else{
			//通常攻撃
			let m_boss_class = [];
			let boss_position = 0;
			m_boss_class = monster_list[m].split('"')
			//' alt="jQuery" name="jQuery" src="https://likehuman.info/wp-content/uploads/2023/03/m_b_jquery.png" >';
			//m_boss_class[3]はname属性のジェイクエリーが該当する
			//ボスの場合の表示位置準備
			if(m_boss_class[3] === "jQuery" || m_boss_class[3] === "wordPress"){
				boss_position = 100;
			}
			$('.monster_s_effect_' + m).css({
				'left' : (monster_position_left[m] + boss_position)  +'px',
				'top' : (monster_position_top[m] + boss_position)  + 'px',
				'background-color':'transparent',
				// 'width' : 100 + 'px',
				// 'height': 120  + 'px',
				'z-index' : 94
			});
			$('.hit_effect_img_' + i).css({	
					'background-color':'transparent',
					'left' : -40 + 'px',
					'top'  : -50 + 'px',
					'width' : 200 + 'px',
					'height': 200  + 'px',
					'z-index' : 94
			});	
			$('.hit_effect_img_' + i).css({'opacity': '1'});			
			$('.hit_effect_img_' + i).animate({opacity: 0 },{
				duration:1000,
				easing:'swing',
				//stepで時間に比例して変化する内容を記述
				step:function(o){
				//1から2へと変化する数値を利用しているだけなのでopacity:1とかじゃなくてもOK。暫定でこのようにしているだけ
					$(this).css({
						//ransform:'rotate(-' + (o * 200) + 'deg)',
						//'zoom' : 2.5
					});
				},
				//完了処理 透明度、明度、色彩を元に戻す。※透明度だけは0にする。
				complete:function(){
					$('.hit_effect_img_' + i).css('opacity','0');
					//$('.battle_container').css({'filter': 'brightness(100%)'});
					$('.hit_effect_img_' + i).css({'filter': 'brightness(100%)'});
					$('.hit_effect_img_' + i).css({'filter': 'saturate(100%)'});						
					}
			})			
			setTimeout(function(){
				$('[class^="hit_attack_"]').remove();
			},1000);
		}
	}	
	
/***************************** 	

モンスターへのダメージ数表示
	
 ******************************/
	function damageSetting(i){
		let m = monster_list.indexOf(target_monster_list[i]);
		//攻撃対象モンスターが倒されていたら、0番目のモンスターに設定
		if(m === -1)m = 0;
		//力、魔力、素早さ、防御力
		//b_character_status[60,120,60,60]]
		setTimeout(function(){

			//$('[class^="monster_s_effect_"]').remove();
			$('[class^="hit_attack_"]').remove();
			$('[class^="hit_effect_img_"]').remove();
			
			//ボスの場合のダメージ数表示位置準備
			let m_boss_class = [];
			let boss_position = 0;
			m_boss_class = monster_list[m].split('"')
			//' alt="jQuery" name="jQuery" src="https://likehuman.info/wp-content/uploads/2023/03/m_b_jquery.png" >';
			//m_boss_class[3]はname属性のジェイクエリーが該当する
			if(m_boss_class[3] === "jQuery" || m_boss_class[3] === "wordPress"){
				boss_position = 100;
			}
			
			/****** ダメージ表示位置の設定*********/
			// 大技の際はループ処理で、ダメージ数を表示する位置を設定する
			if(b_chara_standby[i][0] == 4 || b_chara_standby[i][0] == 5 || b_chara_standby[i][0] == 7 || b_chara_standby[i][0] == 8 || b_chara_standby[i][0] == 9 || b_chara_standby[i][0] == 11 || b_chara_standby[i][0] == 12 || b_chara_standby[i][0] == 13 || b_chara_standby[i][0] == 15 || b_chara_standby[i][0] == 16 || b_chara_standby[i][0] == 17 || b_chara_standby[i][0] == 19){
				$.each(monster_list, function(mm, m_value) {
					//モンスターエフェクトの土台	
					$('.monster_s_effect_' + mm).append('<div class="hit_attack_'+ mm +'" style="position: absolute;"></div>');	
					// 当初はremoveするだけで、CSS設定も同時に削除できていると思っていた。
					// しかし、どうも以前のCSS設定を引き継いでいるようなので、このようにCSSを再設定している			
					$('.monster_s_effect_' + mm).css({
						'left' : (monster_position_left[mm] + boss_position)  +'px',
						'top' : monster_position_top[mm] + 'px',
						'zoom' : 1,
						'opacity' : 1,
						'font-size':'0.9em',
						'background-color':'transparent',
						'width' : 100 + 'px',
						'height': 120  + 'px',
						'z-index' : 96
					});					
				});
			}else{
				//通常攻撃時のダメージ表示
				//$('.battle_container').append('<div class="monster_s_effect_'+ mm +'" style="position: absolute;"></div>');				
				$('.monster_s_effect_' + m).append('<div class="hit_attack_'+ m +'" style="position: absolute;"></div>');
				// 当初はremoveするだけで、CSS設定も同時に削除できていると思っていた。
				// しかし、どうも以前のCSS設定を引き継いでいるようなので、このようにCSSを再設定している			
				$('.monster_s_effect_' + m).css({
					'left' : (monster_position_left[m] + boss_position)  +'px',
					'top' : monster_position_top[m]  + 'px',
					'zoom' : 1,
					'opacity' : 1,
					'font-size':'0.9em',
					'background-color':'transparent',
					'width' : 100 + 'px',
					'height': 120  + 'px',
					'z-index' : 96
				});				
			}

	
			/****** ダメージ数を表示する*********/
			//モンスターの生存確認をしてから実行
			if(monster_status[m][1] > 0){
			// 大技の際はループ処理で、ダメージ数を表示する
				if(b_chara_standby[i][0] == 4 || b_chara_standby[i][0] == 5 || b_chara_standby[i][0] == 7 || b_chara_standby[i][0] == 8 || b_chara_standby[i][0] == 9 || b_chara_standby[i][0] == 11 || b_chara_standby[i][0] == 12 || b_chara_standby[i][0] == 13 || b_chara_standby[i][0] == 15 || b_chara_standby[i][0] == 16 || b_chara_standby[i][0] == 17 || b_chara_standby[i][0] == 19){
					//大技のとき
					generalAttack(i);	
				}else{
					//物理スキルを使用したとき
					$('.hit_attack_' + m).append('<div class="hit_damage_'+ m +'" style="position: absolute;">' + b_character_status[i][0] + '</div>');	
					$('.hit_damage_' + m).css({
						'font-weight':'bold',
						'color':'lightsalmon',
						'font-size':'0.9em',
						'z-index': 96
					});
					//ダメージを軽くバウンドさせる
					$('.hit_damage_' + m).animate({top:"-20px"}, 200).animate({top:"0px"}, 200)
					setTimeout(function(){
						//$('[class^="hit_damage_"]').remove();
						$('[class^="hit_attack_"]').remove();
					},1200);					
				}
			}
		},2000);		
	}
	//スキル番号一覧
	// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
	// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
	// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
	// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};	
	function generalAttack(i){	
		//let m = target_monster_list[i];
		let targe_m = 0;
		$.each(monster_list, function(m, m_value) {
			//魔法スキルを使用したとき
			if(b_chara_standby[i][0] == 7 || b_chara_standby[i][0] == 11 || b_chara_standby[i][0] == 15 || b_chara_standby[i][0] == 19 ){
				targe_m = 0;
				targe_m = monster_list.indexOf(target_monster_list[i]);
				if(m == targe_m){
					$('.hit_attack_' + m).append('<div class="hit_damage_'+ m +'" style="position: absolute;">' + parseInt("" + (skillAttackPower(i) * 1.3),10) + '</div>');	
				}else{
					$('.hit_attack_' + m).append('<div class="hit_damage_'+ m +'" style="position: absolute;">' + skillAttackPower(i) + '</div>');
				}
			}else{
			//物理スキルを使用したとき
				targe_m = 0;
				targe_m = monster_list.indexOf(target_monster_list[i]);
				if(m == targe_m){
					$('.hit_attack_' + m).append('<div class="hit_damage_'+ m +'" style="position: absolute;">' + parseInt("" + (skillAttackPower(i) * 1.3),10) + '</div>');
				}else{
					$('.hit_attack_' + m).append('<div class="hit_damage_'+ m +'" style="position: absolute;">' + skillAttackPower(i) + '</div>');						
				}
				//$('.hit_attack_' + m).append('<div class="hit_damage_'+ m +'" style="position: absolute;">' + b_character_status[i][0] + '</div>');
			}
			$('.hit_damage_' + m).css({
				'font-weight':'bold',
				'color':'lightsalmon',
				'font-size':'0.9em',
				'z-index': 96
			});
			//ダメージを軽くバウンドさせる
			$('.hit_damage_' + m).animate({top:"-20px"}, 200).animate({top:"0px"}, 200)
		});
		setTimeout(function(){
				$('[class^="hit_attack_"]').remove();
		},1200);
	}

/***************** 	
スキル攻撃力の設定 必殺技
*****************/
function skillAttackPower(i){
	//スキル番号一覧
	// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
	// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
	// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
	// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};		
	if(b_chara_standby[i][0]  == 16 || b_chara_standby[i][0]  == 17){
		//return (Math.round(b_character_status[i][0]) * 2); 
		return parseInt("" + (b_character_status[i][0] * 2),10); 		
	}
	else if(b_chara_standby[i][0]  == 19){
		//return (Math.round(b_character_status[i][1]) * 4); 
		return parseInt("" + (b_character_status[i][1] * 4),10); 	
	}
	
	
	
	//小数点がついてしまうので全部修正した
	//else if(b_chara_standby[i][0]  == 4)return (Math.round(b_character_status[i][0]) * 1.2);
	else if(b_chara_standby[i][0]  == 4)return parseInt("" + (b_character_status[i][0] * 1.2),10); 	 	
	//else if(b_chara_standby[i][0]  == 5)return (Math.round(b_character_status[i][0]) * 1.2);
	else if(b_chara_standby[i][0]  == 5)return parseInt("" + (b_character_status[i][0] * 1.2),10); 	 	
	//else if(b_chara_standby[i][0]  == 8)return (Math.round(b_character_status[i][0]) * 1.5); 
	else if(b_chara_standby[i][0]  == 8)return parseInt("" + (b_character_status[i][0] * 1.5),10); 	 	
	//else if(b_chara_standby[i][0]  == 9)return (Math.round(b_character_status[i][0]) * 1.5);
	else if(b_chara_standby[i][0]  == 9)return parseInt("" + (b_character_status[i][0] * 1.5),10); 	 
	//else if(b_chara_standby[i][0]  == 12)return (Math.round(b_character_status[i][0]) * 1.7); 
	else if(b_chara_standby[i][0]  == 12)return parseInt("" + (b_character_status[i][0] * 1.7),10); 
	//else if(b_chara_standby[i][0]  == 13)return (Math.round(b_character_status[i][0]) * 1.7);
	else if(b_chara_standby[i][0]  == 13)return parseInt("" + (b_character_status[i][0] * 1.7),10); 	 	 		  
	//else if(b_chara_standby[i][0]  == 7)return (Math.round(b_character_status[i][1]) * 1.7);
	else if(b_chara_standby[i][0]  == 7)return parseInt("" + (b_character_status[i][1] * 1.7),10); 	 	
	//else if(b_chara_standby[i][0]  == 11)return (Math.round(b_character_status[i][1]) * 2);
	else if(b_chara_standby[i][0]  == 11)return parseInt("" + (b_character_status[i][1] * 2),10);	 	 	
	//else if(b_chara_standby[i][0]  == 15)return (Math.round(b_character_status[i][1]) * 3);
	else if(b_chara_standby[i][0]  == 15)return parseInt("" + (b_character_status[i][1] * 3),10); 	 	
	//else return Math.round(b_character_status[i][1]);
	else return parseInt("" + b_character_status[i][1],10); 	 
}		
/***************** 	
モンスターにダメージを与え、HPからマイナスする。0になったら該当するモンスター情報を削除して、再描画
モンスターを倒す
*****************/
	function inflictDamage(i){
		//キャラクターステータスの並び『力、魔力、素早さ、防御力』
		//b_character_status[60,120,60,60]
		//モンスターステータスの並び『インデックス、HP、最大HP、MP、最大MP、力、魔力、素早さ、防御力、経験値、レベル』
		//monster_status[0,200,200,200,200,30,20,20,20,1000,1];
		setTimeout(function(){	
			let m = monster_list.indexOf(target_monster_list[i]);
			//攻撃対象モンスターが倒されていたら、0番目のモンスターに設定
			if(m === -1)m = 0;
			//HPが0になったモンスターを保存する配列の準備
			kill_monster_list = [];
			kill_monster_list[monster_list.length];	
			$.each(monster_list, function(u, m_value) {
				kill_monster_list[u] = 0;
			});	
			//全体攻撃の場合
			if(b_chara_standby[i][0] == 4 || b_chara_standby[i][0] == 5 || b_chara_standby[i][0] == 7 || b_chara_standby[i][0] == 8 || b_chara_standby[i][0] == 9 || b_chara_standby[i][0] == 11 || b_chara_standby[i][0] == 12 || b_chara_standby[i][0] == 13 || b_chara_standby[i][0] == 15 || b_chara_standby[i][0] == 16 || b_chara_standby[i][0] == 17 || b_chara_standby[i][0] == 19){

				$.each(monster_list, function(mm, m_value) {
					if(b_chara_standby[i][0] == 7 || b_chara_standby[i][0] == 11 || b_chara_standby[i][0] == 15 || b_chara_standby[i][0] == 19 ){
						//魔法攻撃の場合は魔力
						if(mm == m){
							//ターゲットモンスターはダメージ3割増
							monster_status[mm][1] -= parseInt("" + (skillAttackPower(i) * 1.3),10);							
						}else{
							monster_status[mm][1] -= skillAttackPower(i);						
						}							
					}else{
						//物理攻撃の場合は力
						if(mm == m){
							//ターゲットモンスターはダメージ3割増							
							monster_status[mm][1] -= parseInt("" + (skillAttackPower(i) * 1.3),10);							
						}else{
							monster_status[mm][1] -= skillAttackPower(i);						
						}
					}	
					monsterKillCheck(mm);
				});	
				$.each(kill_monster_list, function(mm, m_value) {
					if(m_value !== 0){
						MonsterSwarmReconstruction(m_value);
					}
				});
				//モンスターが全滅していたらフィールド画面に戻る
				if(monsterAnnihilation() == 0){
					setTimeout(function(){
						victory_flag = true;
						if(!fieldScreen_flag)fieldScreen();
						return;
					},2500);
				}
			}else{
				//単体攻撃の場合
				monster_status[m][1] -= parseInt("" + b_character_status[i][0],10);
				monsterKillCheck(m);
				$.each(kill_monster_list, function(mm, m_value) {
					if(m_value !== 0){
						MonsterSwarmReconstruction(m_value);
					}
				});
				//モンスターが全滅していたらフィールド画面に戻る
				if(monsterAnnihilation() == 0){
					setTimeout(function(){
						victory_flag = true;
						if(!fieldScreen_flag)fieldScreen();
						return;
					},2500);
				}				
			}
			//スキルを使用する際はMPを消費
			// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
			// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
			// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
			// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};		
			if(b_chara_standby[i][0] >= 4){
				let mp = Number(b_chara_standby[i][0]);
				//とりあえずスキル番号*150を消費MPとしておく(笑)
				b_character_mp[i] -= (mp * 150);
				if(b_character_mp[i] <= 0){
					b_character_mp[i] = 0;
				}
				//消費MPを反映させる
				$(".battle_status").remove();
				battle_status_show();
			}
			
			//奥義で変更された背景を元に戻す※ただしラスボスの時は変更していないので何もしない
			let m_boss_class = [];
			if(monster_list.length >= 1){
				m_boss_class = monster_list[0].split('"')
				if(m_boss_class[3] !== "jQuery" && m_boss_class[3] !== "wordPress"){
					if( b_chara_standby[i][0] == 16 || b_chara_standby[i][0] == 17 || b_chara_standby[i][0] == 19){
						fieldreset();	
					}
				}
			}
			
		},3600);
	}
/**************** 	
HPが0になったモンスターをkill_monster_listに保存する
*****************/
	function monsterKillCheck(mm){
		if(monster_status[mm][1] <= 0){
			if(bgm_village_flag){
				$(battle_bgm4[3]).get(0).currentTime = 0;
				$(battle_bgm4[3]).get(0).play();
			}
			$(".monster_move_" + mm).fadeOut();
			$(".monster_s_effect_" + mm).fadeOut();
			$(".m_name_" + mm).fadeOut();
			experience_point += monster_status[mm][9];
			kill_monster_list[mm] = monster_list[mm];
		}else{
			kill_monster_list[mm] = 0;
		}
	}
/**************** 	
HPが0になったモンスターを配列から削除して、モンスター群を再構築する
*****************/
	function MonsterSwarmReconstruction(m_data){
		let kill_m = monster_list.indexOf(m_data);
		//ターゲットモンスターのデータをダミー配列から削除
		//splice( 開始位置, 要素数 );
		monster_list.splice( kill_m, 1 );
		monster_status.splice( kill_m, 1 );
		//一旦、すべてのモンスタータグを削除
		$('[class^="monster_move_"]').remove();
		$('[class^="monster_s_effect_"]').remove();
		$('[class^="m_name_"]').remove();
		monster_position = [];
		monster_name = [];
		$.each(monster_list, function(mmm, value) {	
			$('.battle_container').append('<div class="monster_move_'+ mmm +'" style="position: absolute;"><img class="monster_' + mmm +'"  style="position: absolute;" ' + monster_list[mmm] + '</div>');
			//モンスターの位置(名前も取得している)
			monsterStartPosition(mmm);
			//モンスターエフェクトの土台
			$('.battle_container').append('<div class="monster_s_effect_'+ mmm +'" style="position: absolute;"></div>');			
		})	
		//console.log(monster_position);
	}	
	

/***************** 	
戦闘キャラの前進または後退
*****************/
	function battleCharaDirection(i){
		if(battle_step == 0){
			b_character_rect_1[i][0] = 32;
			b_character_rect_1[i][3] = 64;		
			battleCharaMove(i);
			battleCharaLeftStep(i);
		}else{
			b_character_rect_1[i][0] = 64;
			b_character_rect_1[i][3] = 96;		
			battleCharaMove(i);		
			battleCharaRightStep(i);
		}
	}
/***************************** 
戦闘キャラの向きに関するスプライトを生成
******************************/
	function battleCharaMove(i){
		b_stop_move_id_1[i] = setTimeout(battleCharaMove, 200,i);
		//[32,32,0,64];//上、右、左、下
		$(".battle_character_"+i).css({
			'top' : - b_character_rect_1[i][0] + 'px',
			'left': - b_character_rect_1[i][2] + 'px',
			'z-index' : '92',
			'clip':'rect('+
				b_character_rect_1[i][0] + 'px,' +
				b_character_rect_1[i][1] + 'px,' +
				b_character_rect_1[i][3] + 'px,' +
				b_character_rect_1[i][2] + 'px' +
			')'
		});
		b_character_rect_1[i][1] += cut_percentage;//右
		b_character_rect_1[i][2] += cut_percentage;//左
		if(b_character_rect_1[i][1] == 128){
			b_character_rect_1[i][1] = 32;
			b_character_rect_1[i][2] = 0; 
		}
	}
/**************************** 
攻撃後のキャラを時間差で後退させる
*****************************/	
	function attackMotionTime(i){
		pause_time_id = setTimeout(attackMotionTime, 50,i);
		pause_time += 1;
		if(pause_time >= 30){		
			clearTimeout(pause_time_id);
			battleCharaDirection(i);
		}	
	}
/*************************************************** 
戦闘キャラを左にステップさせ、攻撃前に一時停止して攻撃モーションに入る
****************************************************/	
	function battleCharaLeftStep(i){
		b_stop_walk_id_1[i] = setTimeout(battleCharaLeftStep, 5,i);
		battle_step += 1;
		if(battle_step <= 10)b_character_position_left_1[i]  -= battle_step;
		if(battle_step >= 10){
			clearTimeout(b_stop_move_id_1[i]);			
		}	
		if(battle_step >= 30){
			clearTimeout(b_stop_walk_id_1[i]);
			//回復の場合
			if(b_chara_standby[i][0] == 6 || b_chara_standby[i][0] == 10 || b_chara_standby[i][0] == 14 || b_chara_standby[i][0] == 18){
				recoveryEffect(i,recovery_target[i]);
			}else{
				//モンスターが全滅していたらフィールド画面に戻る
				if(monsterAnnihilation() == 0){
					victory_flag = true;
					if(!fieldScreen_flag)fieldScreen();
					return;
				}else{
					//攻撃対象モンスターの生存確認
					let target_m = monster_list.indexOf(target_monster_list[i]);
					//攻撃対象モンスターが倒されていたら、0番目のモンスターに設定
					if(target_m === -1)target_m = 0;
					weaponEffect(i);
					hitEffect(i,b_chara_standby[i][0]);
					//モンスターに与えるダメージを表示する
					damageSetting(i);
					//モンスターにダメージを与え、HPからマイナスする。0になったら該当するモンスター情報を削除して、再描画
					inflictDamage(i);
				}
			}
			pause_time = 0;
			attackMotionTime(i);
		}
		if(battle_step <= 10){
			$(".battle_move_"+i).css({
				'left' : b_character_position_left_1[i] + 'px',
				'top' : b_character_position_top_1[i] + 'px'
			});
		}
	}

/************* 
戦闘用のキャラを右にステップさせる
*************/	
	function battleCharaRightStep(i){
		b_stop_walk_id_1[i] = setTimeout(battleCharaRightStep, 1,i);
		b_character_position_left_1[i]  += 1;
		if(b_left <= b_character_position_left_1[i]){		
			clearTimeout(b_stop_walk_id_1[i]);
			clearTimeout(b_stop_move_id_1[i]);
			b_character_position_left_1[i] = b_left;
			battleStartPosition(i);
		}	
		$(".battle_move_"+i).css({
			'left' : b_character_position_left_1[i] + 'px',
			'top' : b_character_position_top_1[i] + 'px'
		});
	}
	
	
	
/********************* 
戦闘キャラのスキルコマンド一覧の出力
***********************/	
	function battleCommand(k){
		let y = 0;
		$(".battle_status").remove();
		$('.battle_tactics').after('<div class="battle_skill_command"></div>');
		if(k === 0){
			$.each(skill_command_0, function(i, value) {
				//ここでのiはkeyを取得している
				$('.battle_skill_command').append('<button id="command_' + y + '" class="game_btn" value="' + i + '">'+skill_command_0[i]+'</button>');
				y += 1;
			})
		}else if(k === 1){
			$.each(skill_command_1, function(i, value) {
				//ここでのiはkeyを取得している			
				$('.battle_skill_command').append('<button id="command_' + y + '" class="game_btn" value="' + i + '">'+skill_command_1[i]+'</button>');
				y += 1;				
			})			
		}else if(k === 2){
			$.each(skill_command_2, function(i, value) {
				//ここでのiはkeyを取得している			
				$('.battle_skill_command').append('<button id="command_' + y + '" class="game_btn" value="' + i + '">'+skill_command_2[i]+'</button>');
				y += 1;				
			})		
		}else if(k === 3){
			$.each(skill_command_3, function(i, value) {
				//ここでのiはkeyを取得している			
				$('.battle_skill_command').append('<button id="command_' + y + '" class="game_btn" value="' + i + '">'+skill_command_3[i]+'</button>');
				y += 1;				
			})
		}else{}	
	}
/************ 
スキル説明
************/
	function skillDescription(){
		$('[class^="battle_message"]').remove();
		//バトル中のメッセージ
		$('.battle_container').prepend('<div class ="battle_message">' +  $('#command_'+ skill_index).text()+ '・・・' + skill_explanation[b_member_inex][skill_index] + '</div>');
		$(".battle_message").css({
			top:  battle_message_position_left + 'px',
			left: battle_message_position_left + 'px',
			zIndex : 91
		});
	}	
	

/*************** 
モンスターの全滅確認
****************/
	function monsterAnnihilation(){
		let monster_count = 0;
		$.each(monster_list, function(m, m_value) {
			if(m in monster_list){
				monster_count += 1;
			}
		});
		return monster_count;
	}
/**************** 
キャラクターの生存チェック 
*****************/
	function survivalCheck(i){
		for (i; i < 4; i++) {
			if(i in b_character_hp){
				if(b_character_hp[i] != 0){
					return i;
				}else{
					//暫定でキャラクターが死亡しているときは、100にしておく
					b_chara_standby[i][0] = 100;
					continue;
				}	
			}else{
				return 4;
			}	
		}
		return 4;
	}
/******************** 
runaway 
*********************/
	function runAway(){
		let stop_escape_time = setTimeout(runAway, 1);
		if(escape_flag){
			//戦闘キャラの向きの設定
			$.each(battle_member, function(i, value) {	
				$('.battle_character_' + i ).fadeOut();
				b_character_position_left_1[i] = b_left;
			})
			if(!fieldScreen_flag)fieldScreen();
			clearTimeout(stop_escape_time);
		}else{
			$.each(battle_member, function(i, value){
				b_character_position_left_1[i] += 1;
				$(".battle_move_"+i).css({
					'left' : b_character_position_left_1[i]  + 'px'
				});
				if(b_character_position_left_1[i]  >= (b_left + 40))escape_flag = true;
			})
		}
	}
/**************** 
レベルアップ
******************/
	function levelUp(i,l){
		//b_character_status_orijn = [[300,100,1,1],[300,80,1,1],[300,120,1,1],[300,120,1,1]];//力、魔力、素早さ(%)、防御力(%)
		let rate_of_up_strength = 100;
		let rate_of_up_magic = 100;
		//戦士系の場合とマジシャン系の場合で上昇率をわける
		//とはいえ、LV99の際はHP・MP・力・魔力9999 防御力・素早さは99にする
		if(i == 0 || i == 1){
			rate_of_up_strength = 100;
			rate_of_up_magic = 50;				
		}else{
			rate_of_up_strength = 50;
			rate_of_up_magic = 100;		
		}
		b_character_max_hp[i] += (100 * l);
		b_character_hp[i] = b_character_max_hp[i] 
		b_character_max_mp[i] += (100 * l);
		b_character_mp[i] = b_character_max_mp[i];		
		b_character_status_orijn[i][0] += (rate_of_up_strength * l);
		b_character_status_orijn[i][1] += (rate_of_up_magic * l);
		//素早さ と 防御力はパーセントで計算するので数値は低め
		b_character_status_orijn[i][2] += l;
		if(i == 2){
			//僧侶だけは防御力を高めに設定する※ラスボスで難易度が高くなりすぎるため
			b_character_status_orijn[i][3] += (l * 0.4);			
		}else{
			b_character_status_orijn[i][3] += (l * 0.25);
		}

		b_character_level[i][1] += (1000 * l);
		b_character_level[i][0] += l;
		if(b_character_level[i][0] >= 99)b_character_level[i][0] = 99;
		if(b_character_level[i][0] == 99){
			b_character_max_hp[i] = 9999;
			b_character_hp[i] = 9999 
			b_character_max_mp[i] = 9999;
			b_character_mp[i] = 9999;		
			b_character_status_orijn[i][0] = 9999;
			b_character_status_orijn[i][1] = 9999;
			//素早さ と 防御力はパーセントで計算するので数値は低め
			b_character_status_orijn[i][2] = 99;
			//僧侶の防御力は限界突破
			if(i !== 2)b_character_status_orijn[i][3] = 25;	
		}	
		//ステータスを最大値に置き換える
		b_character_status = $.extend(true, [], b_character_status_orijn);
		// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
		// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
		// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
		// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};
/* 		$.each(skill_command_0, function(i, value) {
			//ここでのiはkeyを取得している
			$('.battle_skill_command').append('<button id="command_' + y + '" class="game_btn" value="' + i + '">'+skill_command_0[i]+'</button>');
			y += 1;
		}) */
		
		//習得スキル

		if(i == 0 && b_character_level[i][0] >= 1 && b_character_level[i][0] < 10 && skill_command_0[4] == "???"){
			skill_command_0[4] = "ridingAttack";
			acquired_skills[0] = "ridingAttack";
		}
		if(i == 0 && b_character_level[i][0] >= 10 && b_character_level[i][0] < 15){
			if(skill_command_0[4] == "???"){
				skill_command_0[4] = "ridingAttack";
				acquired_skills[0] = "ridingAttack";				
			}
			if(skill_command_0[8] == "???"){
				skill_command_0[8] = "ThreeHammers";
				acquired_skills[1] = "ThreeHammers";				
			}			
		}
		if(i == 0 && b_character_level[i][0] >= 15 && b_character_level[i][0] < 20){
			
			if(skill_command_0[4] == "???"){
				skill_command_0[4] = "ridingAttack";
				acquired_skills[0] = "ridingAttack";				
			}
			if(skill_command_0[8] == "???"){
				skill_command_0[8] = "ThreeHammers";
				acquired_skills[1] = "ThreeHammers";				
			}
			if(skill_command_0[12] == "???"){
				skill_command_0[12] = "flameSlasher";
				acquired_skills[2] = "flameSlasher";				
			}				
		}
		if(i == 0 && b_character_level[i][0] >= 20){
			
			if(skill_command_0[4] == "???"){
				skill_command_0[4] = "ridingAttack";
				acquired_skills[0] = "ridingAttack";				
			}
			if(skill_command_0[8] == "???"){
				skill_command_0[8] = "ThreeHammers";
				acquired_skills[1] = "ThreeHammers";				
			}
			if(skill_command_0[12] == "???"){
				skill_command_0[12] = "flameSlasher";
				acquired_skills[2] = "flameSlasher";				
			}
			if(skill_command_0[16] == "???"){
				skill_command_0[16] = "dimensionCut";
				acquired_skills[3] = "dimensionCut";				
			}				
		}		
		// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
		// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
		// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
		// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};		
		if(i == 1 && b_character_level[i][0] >= 1 && b_character_level[i][0] < 10 && skill_command_1[5] == "???"){
			skill_command_1[5] = "dancingSword";
			acquired_skills[4] = "dancingSword";
		}
		if(i == 1 && b_character_level[i][0] >= 10 && b_character_level[i][0] < 15){
			if(skill_command_1[5] == "???"){
				skill_command_1[5] = "dancingSword"
				acquired_skills[4] = "dancingSword";				
			}
			if(skill_command_1[9] == "???"){
				skill_command_1[9] = "shadedSword"
				acquired_skills[5] = "shadedSword";				
			}
		}
		if(i == 1 && b_character_level[i][0] >= 15 && b_character_level[i][0] < 20){
			if(skill_command_1[5] == "???"){
				skill_command_1[5] = "dancingSword"
				acquired_skills[4] = "dancingSword";				
			}
			if(skill_command_1[9] == "???"){
				skill_command_1[9] = "shadedSword"
				acquired_skills[5] = "shadedSword";				
			}
			if(skill_command_1[13] == "???"){
				skill_command_1[13] = "mistSlash"
				acquired_skills[6] = "mistSlash";				
			}
		}
		if(i == 1 && b_character_level[i][0] >= 20){
			
			if(skill_command_1[5] == "???"){
				skill_command_1[5] = "dancingSword"
				acquired_skills[4] = "dancingSword";				
			}
			if(skill_command_1[9] == "???"){
				skill_command_1[9] = "shadedSword"
				acquired_skills[5] = "shadedSword";				
			}
			if(skill_command_1[13] == "???"){
				skill_command_1[13] = "mistSlash"
				acquired_skills[6] = "mistSlash";				
			}			
			if(skill_command_1[17] == "???"){
				skill_command_1[17] = "Iai-giri"
				acquired_skills[7] = "Iai-giri";				
			}				
		}		
		// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
		// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
		// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
		// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};		
		if(i == 2 && b_character_level[i][0] >= 1 && b_character_level[i][0] < 10 && skill_command_2[6] == "???"){
			skill_command_2[6] = "healing";
			acquired_skills[8] = "healing";
		}
		if(i == 2 && b_character_level[i][0] >= 10 && b_character_level[i][0] < 15){
			if(skill_command_2[6] == "???"){
				skill_command_2[6] = "healing";
				acquired_skills[8] = "healing";		
			}
			if(skill_command_2[10] == "???"){
				skill_command_2[10] = "revival";
				acquired_skills[9] = "revival";		
			}
		}
		if(i == 2 && b_character_level[i][0] >= 15 && b_character_level[i][0] < 20){
			if(skill_command_2[6] == "???"){
				skill_command_2[6] = "healing";
				acquired_skills[8] = "healing";		
			}
			if(skill_command_2[10] == "???"){
				skill_command_2[10] = "revival";
				acquired_skills[9] = "revival";		
			}			
			if(skill_command_2[14] == "???"){
				skill_command_2[14] = "shield";
				acquired_skills[10] = "shield";		
			}
		}
		if(i == 2 && b_character_level[i][0] >= 20 && b_character_level[i][0] < 25){
			if(skill_command_2[6] == "???"){
				skill_command_2[6] = "healing";
				acquired_skills[8] = "healing";		
			}
			if(skill_command_2[10] == "???"){
				skill_command_2[10] = "revival";
				acquired_skills[9] = "revival";		
			}
			if(skill_command_2[14] == "???"){
				skill_command_2[14] = "shield";
				acquired_skills[10] = "shield";		
			}			
			if(skill_command_2[18] == "???"){
				skill_command_2[18] = "ForceFang";
				acquired_skills[11] = "ForceFang";		
			}			
		}
		if(i == 2 && b_character_level[i][0] >= 25){
			if(skill_command_2[6] == "???"){
				skill_command_2[6] = "healing";
				acquired_skills[8] = "healing";		
			}
			if(skill_command_2[10] == "???"){
				skill_command_2[10] = "revival";
				acquired_skills[9] = "revival";		
			}
			if(skill_command_2[14] == "???"){
				skill_command_2[14] = "shield";
				acquired_skills[10] = "shield";		
			}			
			if(skill_command_2[18] == "???"){
				skill_command_2[18] = "ForceFang";
				acquired_skills[11] = "ForceFang";		
			}	
			if(skill_command_2[6] == "healing"){
				skill_command_2[6] = "megahealing";
				acquired_skills[16] = "megahealing";	
				skill_overview[6] = "megahealing";				
				skill_explanation[i][0] = "A certain amount of recovery (all parties)";					
			}
		}
		if(i == 2 && b_character_level[i][0] >= 25){
			
			if(skill_command_2[6] == "???"){
				skill_command_2[6] = "healing";
				acquired_skills[8] = "healing";		
			}
			if(skill_command_2[10] == "???"){
				skill_command_2[10] = "revival";
				acquired_skills[9] = "revival";		
			}			
			if(skill_command_2[18] == "???"){
				skill_command_2[18] = "ForceFang";
				acquired_skills[11] = "ForceFang";		
			}	
			if(skill_command_2[14] == "???"){
				skill_command_2[14] = "shield";
				acquired_skills[10] = "shield";		
			}			
			if(skill_command_2[6] == "healing"){
				skill_command_2[6] = "megahealing";
				acquired_skills[16] = "megahealing";	
				skill_overview[6] = "megahealing";				
				skill_explanation[i][0] = "A certain amount of recovery (all parties)";					
			}			
			if(skill_command_2[10] == "revival"){
				skill_command_2[10] = "megaRevival";
				acquired_skills[17] = "megaRevival";	
				skill_overview[10] = "megaRevival";				
				skill_explanation[i][1] = "Revive a fallen ally (every party)";				
			}					
		}
		if(i == 2 && b_character_level[i][0] >= 98){
			
			if(skill_command_2[6] == "???"){
				skill_command_2[6] = "healing";
				acquired_skills[8] = "healing";		
			}
			if(skill_command_2[10] == "???"){
				skill_command_2[10] = "revival";
				acquired_skills[9] = "revival";		
			}			
			if(skill_command_2[18] == "???"){
				skill_command_2[18] = "ForceFang";
				acquired_skills[11] = "ForceFang";		
			}	
			if(skill_command_2[14] == "???"){
				skill_command_2[14] = "shield";
				acquired_skills[10] = "shield";		
			}			
			if(skill_command_2[6] == "healing"){
				skill_command_2[6] = "megahealing";
				acquired_skills[16] = "megahealing";	
				skill_overview[6] = "megahealing";				
				skill_explanation[i][0] = "A certain amount of recovery (all parties)";					
			}			
			if(skill_command_2[10] == "revival"){
				skill_command_2[10] = "megaRevival";
				acquired_skills[17] = "megaRevival";	
				skill_overview[10] = "megaRevival";				
				skill_explanation[i][1] = "Revive a fallen ally (every party)";				
			}
			if(skill_command_2[14] == "shield"){
				skill_command_2[14] = "megaShield";
				acquired_skills[18] = "megaShield";	
				skill_overview[14] = "megaShield";				
				skill_explanation[i][2] = "Increase defense (whole party). Valid up to 2 times";				
			}
			if(skill_command_2[18] == "ForceFang"){
				skill_command_2[18] = "megaForceFang";
				acquired_skills[11] = "megaForceFang";
				skill_overview[14] = "megaForceFang";		
				skill_explanation[i][2] = "Warrior class increases attack power, magician class increases magical power (all parties). Valid up to 2 times";						
			}	
		}
		// let skill_command_0 = {4:"ridingAttack",8:"ThreeHammers",12:"flameSlasher",16:"dimensionCut"};
		// let skill_command_1 = {5:"dancingSword",9:"shadedSword",13:"mistSlash",17:"Iai-giri"};
		// let skill_command_2 = {6:"healing",10:"revival",14:"shield",18:"ForceFang"};
		// let skill_command_3 = {7:"ThunderCrash",11:"earthFire",15:"heavenBlow",19:"hellBerd"};		
		if(i == 3 && b_character_level[i][0] >= 1 && b_character_level[i][0] < 10 && skill_command_3[7] == "???"){
			skill_command_3[7] = "ThunderCrash";
			acquired_skills[12] = "ThunderCrash";
		}
		if(i == 3 && b_character_level[i][0] >= 10 && b_character_level[i][0] < 15){
			if(skill_command_3[7] == "???"){
				skill_command_3[7] = "ThunderCrash";	
				acquired_skills[12] = "ThunderCrash";				
			}
			if(skill_command_3[11] == "???"){
				skill_command_3[11] = "earthFire";	
				acquired_skills[13] = "earthFire";				
			}
		}
		if(i == 3 && b_character_level[i][0] >= 15 && b_character_level[i][0] < 20){
			if(skill_command_3[7] == "???"){
				skill_command_3[7] = "ThunderCrash";	
				acquired_skills[12] = "ThunderCrash";				
			}
			if(skill_command_3[11] == "???"){
				skill_command_3[11] = "earthFire";	
				acquired_skills[13] = "earthFire";				
			}
			if(skill_command_3[15] == "???"){
				skill_command_3[15] = "heavenBlow";	
				acquired_skills[14] = "heavenBlow";				
			}			
		}
		if(i == 3 && b_character_level[i][0] >= 20){
			if(skill_command_3[7] == "???"){
				skill_command_3[7] = "ThunderCrash";	
				acquired_skills[12] = "ThunderCrash";				
			}
			if(skill_command_3[11] == "???"){
				skill_command_3[11] = "earthFire";	
				acquired_skills[13] = "earthFire";				
			}
			if(skill_command_3[15] == "???"){
				skill_command_3[15] = "heavenBlow";	
				acquired_skills[14] = "heavenBlow";				
			}			
			if(skill_command_3[19] == "???"){
				skill_command_3[19] = "hellBerd";	
				acquired_skills[15] = "hellBerd";				
			}			
		}		
		
	}	
	
	
	
/*************** 
パーティ全滅チェック 
*****************/
	function Annihilation(){
		let hp0_num = 0;
		$.each(b_character_hp, function(i, value) {
			if(b_character_hp[i] <= 0){
				hp0_num += 1;
				if(hp0_num === 4){
					if(!fieldScreen_flag)fieldScreen();
				}
			}
		})
	}
/*************** 
パーティ全滅チェック サブバージョン
*****************/
	function AnnihilationSub(){
		let hp0_chara = 0;
		$.each(b_character_hp, function(i, value) {
			if(b_character_hp[i] <= 0){
				hp0_chara += 1;
				if(hp0_chara === 4){
					return true;
				}
			}
		})
		if(hp0_chara !== 4)return false;
	}	
/********************************** 
バトル画面に表示するモンスターの特殊攻撃概要 
***********************************/
	function monsterSkillExplanation(type){
		$('[class^="battle_message"]').remove();
		//バトル中のメッセージ
		$('.battle_container').prepend('<div class ="battle_message">' + mon_sp_explanation[type] + '</div>');
		$(".battle_message").css({
			top:  battle_message_position_left + 'px',
			left: battle_message_position_left + 'px',
			zIndex : 91
		});		
	}
/****************** 
	
	
ジェイクエリーおよびワードプレスによる特殊攻撃


*******************/
	function jqueryAttacks(){
		
		//ボスの場合のダメージ数表示位置準備
		let m_boss_class = [];
		let boss_sp_at = 4;
		let boss_sp_ex = 4;	
		let zoom_rate = 4.5;
		let left_rate = -70;
		let top_rate = -70;		
		m_boss_class = monster_list[0].split('"')
		//jQuery
		// mon_special_at[4] ='https://likehuman.info/wp-content/uploads/2023/04/bigbang.gif';
		//wordPress
		// mon_special_at[5] ='https://likehuman.info/wp-content/uploads/2023/05/death_march.gif';
		// mon_sp_explanation[4] = 'bigBang';
		// mon_sp_explanation[5] = 'meditation';	
		// mon_sp_explanation[6] = 'deathMarch';	
		if(m_boss_class[3] === "jQuery"){
			boss_sp_at = 4;
			boss_sp_ex = 4;
			zoom_rate = 7;
			left_rate = -70;
			top_rate = -22;				
		}
		if(m_boss_class[3] === "wordPress"){
			boss_sp_at = 5;
			boss_sp_ex = 6;
			zoom_rate = 6;
			left_rate = -100;	
			top_rate = -50;					
		}
		
		//対象キャラにエフェクトを設定する前の下準備
		battle_position_chara[2] = $(".battle_move_"+2).position();
		//$('[class^="monster_special_at_img_"]').remove();
		$('.b_chara_effect_' + 2).css({
			// 'left' : battle_position_chara[2].left +'px',
						'left' : battle_position_chara[2].left + left_rate +'px',
			'top' : battle_position_chara[2].top + top_rate + 'px',
			'z-index' : '94'
		});

		$('.b_chara_effect_' + 2).append('<img class="monster_special_at_img_' + 2 +'" style="position: absolute;" name="特殊攻撃" src="' + mon_special_at[boss_sp_at] + '">');
		//バトル画面に表示される特殊スキルの概要
		monsterSkillExplanation(boss_sp_ex);
		
		//画像配置の細かな設定をする時は下記のように画像クラスで設定する必要がある
		$('.monster_special_at_img_' + 2).css({	
			'background-color':'transparent',
			'left' : -30 + 'px',
			'top'  : -30 + 'px',
			'width' : 100 + 'px',
			'height': 120  + 'px',
			'z-index' : 94
		});
		//filter: brightness(200%);明度の変更ができる
		//filter: saturate(200%);色彩の変更ができる
		//filter: sepia(200%);セピアにできる※セピアの場合は数値を低くすることで反映する。0%で完全なセピア
		//$('.battle_container').css({'filter': 'brightness(70%)'});
		$('.monster_special_at_img_' + 2).css({'filter': 'brightness(500%)'});
		$('.monster_special_at_img_' + 2).css({'filter': 'saturate(500%)'});				

		$('.monster_special_at_img_' + 2).css({'opacity': '1'});
		//1から2へと変化する数値を利用しているだけなのでopacity:1以外でもOK
		$('.monster_special_at_img_' + 2).animate({opacity: 0 },{
			duration:1400,
			easing:'swing',
			//stepで時間に比例して変化する内容を記述
			step:function(o){
			//1から2へと変化する数値を利用しているだけなのでopacity:1とかじゃなくてもOK。暫定でこのようにしているだけ
				$(this).css({
					//ransform:'rotate(-' + (o * 200) + 'deg)',
					//'zoom' : zoom_rate * o
					//transform :'scale(' + o * 10 + ',' + o * 10 + ') translate(' + view_w / 2 * o + 'px,'+ 100 * o + 'px)',
					//transform :'scale(' + o * 7 + ',' + o * 3 + ')'	
					transform :'scale(' + 7 + ',' + 3 + ')'	
				});
			},
			//完了処理 透明度、明度、色彩を元に戻す。※透明度だけは0にする。
			complete:function(){
				$('.monster_special_at_img_' + 2).css('opacity','0');
				$('.monster_special_at_img_' + 2).css({'filter': 'brightness(100%)'});
				$('.monster_special_at_img_' + 2).css({'filter': 'saturate(100%)'});						
				}
		})

		//時間差で下記処理(エフェクトに関するCSSを削除)を実行
		setTimeout(function(){
			$('[class="monster_special_at_img_' + 2 +'"]').remove();
			$('[class^="battle_message"]').remove();
		},1500);		
	}
/****************** 	
//モンスターの回復
//主にボスクラス
*******************/
function monsterRecoverAction(m){
	//画面に表示されるモンスタースキル名
	monsterSkillExplanation(5);
	//モンスターの回復エフェクトタグの挿入
	$('.monster_s_effect_' + m).append('<img class="recovery_monster_img' + m +'" style="position: absolute;" name="kaifuku" src="' + partner_effect_list[1] + '">');
	$('.monster_s_effect_' + m).css({
		'left' : monster_position_left[m]  +'px',
		'top' : monster_position_top[m]  + 'px',
		'zoom' : 1,
		'opacity' : 1,
		'font-size':'0.9em',
		'background-color':'transparent',
		'width' : 100 + 'px',
		'height': 120  + 'px',
		'z-index' : 96
	});	
	$('.recovery_monster_img' + m).css({
		'zoom' : 3,
		'z-index': 94
	});
	//時間差で下記処理(回復エフェクトに関するCSSを削除)を実行
	setTimeout(function(){
		//モンスター回復エフェクトの削除
		$('[class^="recovery_monster_img"]').remove();
		//メッセージ削除
		$('[class^="battle_message"]').remove();		
		if(monster_status[m][1] !== 0){
			//現在HPの30パーセントを回復量とする
			monster_status[m][1] += Math.ceil(monster_status[m][1] * 0.3);
			//回復数値を頭上に表示
			$('.monster_s_effect_' + m).append('<div class="recovery_monster_num_'+ m +'" style="position: absolute;">' + Math.ceil(monster_status[m][1] * 0.3) + '</div>');
			$('.monster_s_effect_' + m).css({
				'left' : (monster_position_left[m] + 100)  +'px',
				'top' : monster_position_top[m]   + 'px'
			});				
			$('.recovery_monster_num_' + m).css({
				'font-weight':'bold',
				'color':'blue',
				'font-size':'0.9em',
				'z-index': 96
			});
			//回復数値を軽くバウンドさせる
			$('.recovery_monster_num_' + m).animate({top:"-10px"}, 200).animate({top:"-4px"}, 200)
			//時間差で下記処理(回復エフェクトに関するCSSを削除)を実行
			setTimeout(function(){
				$('[class^="recovery_monster_num_"]').remove();
			},1000);
			//BGM
			if(bgm_village_flag){
				$(battle_bgm5[1]).get(0).currentTime = 0;
				$(battle_bgm5[1]).get(0).play();
			}
		}else{
			monster_status[m][1] = 0;
			//時間差で下記処理(回復エフェクトに関するCSSを削除)を実行
			//詠唱エフェクトの削除
			setTimeout(function(){
				$('[class^="recovery_monster_num_"]').remove();
			},1000);
		}	
	},1000);
}	
/****************** 	
//モンスターによる特殊攻撃
//主にボスクラス
*******************/
	function specialAttacksByMonsters(chara,monster,mon_type){
/* 		
		//Cerberus
		mon_special_at[0] ='https://likehuman.info/wp-content/uploads/2023/04/fang.gif';
		//noddyDragon
		mon_special_at[1] ='https://likehuman.info/wp-content/uploads/2023/03/earth_fire.gif';
		//broadSaucer
		mon_special_at[2] ='https://likehuman.info/wp-content/uploads/2023/02/magic_kaminari_1.gif';
		//darkSoldier
		mon_special_at[3] ='https://likehuman.info/wp-content/uploads/2023/04/darksword.gif';
		//jQuery
		mon_special_at[4] ='https://likehuman.info/wp-content/uploads/2023/04/bigbang.gif';		 */
		
		//対象キャラにエフェクトを設定する前の下準備
		battle_position_chara[chara] = $(".battle_move_"+chara).position();
		//$('[class^="monster_special_at_img_"]').remove();
		$('.b_chara_effect_' + chara).css({
			'left' : battle_position_chara[chara].left +'px',
			'top' : battle_position_chara[chara].top  - 22 + 'px',
			'z-index' : '94'
		});
		//ボスタイプ別エフェクト
		let monster_sp_skill = "";
		let monster_sp_slill_index = 0;
		if(mon_type == "Cerberus"){
			monster_sp_skill = mon_special_at[0];
			monster_sp_slill_index = 0;
		}	
		if(mon_type == "noddyDragon"){
			monster_sp_skill = mon_special_at[1]
			monster_sp_slill_index = 1;			
		}	
		if(mon_type == "broadSaucer"){
			monster_sp_skill = mon_special_at[2]
			monster_sp_slill_index = 2;				
		}	
		if(mon_type == "darkSoldier"){
			monster_sp_skill = mon_special_at[3]
			monster_sp_slill_index = 3;				
		}
		
		$('.b_chara_effect_' + chara).append('<img class="monster_special_at_img_' + chara +'" style="position: absolute;" name="特殊攻撃" src="' + monster_sp_skill + '">');
		//バトル画面に表示される特殊スキルの概要
		monsterSkillExplanation(monster_sp_slill_index);

		//画像配置の細かな設定をする時は下記のように画像クラスで設定する必要がある
		$('.monster_special_at_img_' + chara).css({	
			'background-color':'transparent',
			'left' : -30 + 'px',
			'top'  : -30 + 'px',
			'width' : 100 + 'px',
			'height': 120  + 'px',
			'z-index' : 94
		});
		//時間差で下記処理(エフェクトに関するCSSを削除)を実行
		setTimeout(function(){
			$('[class="monster_special_at_img_' + chara +'"]').remove();
			$('[class^="battle_message"]').remove();
		},1500);
	}
	
	
	
/**************************** 	
//攻撃してくるモンスターの上下運動
*****************************/
	function attackInitialAction(monster){
		//攻撃してくるモンスターを上下させる
		monster_behavior = monster_position_top[monster]; 
			stop_monster_behavior_time[monster] = setInterval(function(){
			$(".monster_move_"+monster).css({
				'top' : monster_behavior  + 'px'
			});
			if(monster_behavior === monster_position_top[monster]){
				monster_behavior += 10;
			}else{
				monster_behavior = monster_position_top[monster];
			}
		},50);
		//時間差で下記処理を実行
		setTimeout(function(){
			//モンスターの上下運動をとめる
			clearInterval(stop_monster_behavior_time[monster]);
			$(".monster_move_"+monster).css({
				'top' : monster_position_top[monster] + 'px'
			});
		},700);		
	}	
	
	
/**************** 	
//味方へのダメージ表示 
*****************/
	function receiveDamage(i,m,bgm_type){
		//味方へのダメージ演出
		let leanBack_level = b_character_position_left_1[i];
		stop_leanBack[i][m] = setInterval(function(){
			leanBack_level += 1;
			if(leanBack_level >= (b_character_position_left_1[i] + 10)){
				leanBack_level -= 1;
			}	
			$(".battle_move_"+i).css({
				'left' : leanBack_level + 'px'
			});
			if(leanBack_level <= b_character_position_left_1[i]){
				$(".battle_move_"+i).css({
					'left' : b_character_position_left_1[i] + 'px'
				});
			}	
		},30);
		
		//ダメージの算出
		//味方の初期値[[300,100,1,1],[300,80,1,1],[300,120,1,1],[300,120,1,1]];//力、魔力、素早さ(%)、防御力(%)
		//モンスターの初期値[[0,200,200,200,200,30,20,20,20,keikenti,1]
		//仲間HP - (モンスターの力 - (モンスターの力 * 防御力 + 防御状態 / 100))
		//レベル99で防御力は約25%。防御の構えが30%。なのでレベル99かつ防御状態なら約55%。シールド状態(1回が20%,2回目で40%)だと+40%で合計で95%の防御力となる計算
		//防御力を加味して算出
		let defense_mode = 0;
		let total_defense_power = 0;
		let defense_ratio = 0;
		//防御状態の割合
		if(b_chara_standby[i][0] == 99){
			defense_mode = (30 / 100);
		}
		//防御力の割合
		defense_ratio = ( b_character_status[i][3] / 100);
		//トータルの防御力
		total_defense_power = defense_ratio + defense_mode;
		//防御力によって差し引かれるダメージ
		let damage_deducted = Math.floor(monster_status[m][5] * total_defense_power);
		//実際のダメージ parseIntで確実に整数へ置き換える
		let actual_damage = parseInt(""+(monster_status[m][5] - damage_deducted),10);
		//防御力でダメージが相殺される場合は0にする
		if(actual_damage <= 0)actual_damage = 0;
		//ダメージを算出
		b_character_hp[i] -= actual_damage;
		//キャラクターが倒れるエフェクト
		if(b_character_hp[i] <= 0){
			//b_character_status_orijn = [[300,100,1,1],[300,80,1,1],[300,120,1,1],[300,120,1,1]];//力、魔力、素早さ(%)、防御力(%)
			//ステータス効果を打ち消す
			b_character_status[i][0] = b_character_status_orijn[i][0];
			b_character_status[i][1] = b_character_status_orijn[i][1];
			b_character_status[i][2] = b_character_status_orijn[i][2];
			b_character_status[i][3] = b_character_status_orijn[i][3];

			//シールドの有効回数を初期化
			shield_count[i] = 0;
			//フォースファングの有効回数を初期化
			force_count[i] = 0;
			
			//HPを0にする
			b_character_hp[i] = 0;
			$('.battle_character_' + i).css({'opacity': '0'});
			//1から2へと変化する数値を利用しているだけなのでopacity:1以外でもOK
			$('.battle_character_' + i).animate({opacity: 1 },{
				duration:700,
				easing:'swing',
				//stepで時間に比例して変化する内容を記述
				step:function(o){
				//1から2へと変化する数値を利用しているだけなのでopacity:1とかじゃなくてもOK。暫定でこのようにしているだけ
					$(this).css({transform:'rotate(+' + (o * 100) + 'deg)'});
			},
			//完了処理
			//complete:function(){$('.battle_character_' + i).css('opacity','0');}
			})
		}
		
		$('.b_chara_effect_' + i).append('<div class="receive_damage'+ i +'" style="position: absolute;">' +  actual_damage + '</div>');	
		$('.b_chara_effect_' + i).css({
			'left' : (battle_position_chara[i].left - 15) +'px',
			'top' : (battle_position_chara[i].top  - 30) + 'px',
			'z-index' : '94'
		});
		
		$('.receive_damage' + i).css({
			'font-weight':'bold',
			'color':'lightsalmon',
			'font-size':'0.9em',
			'z-index': 96
		});
		
		//メンバーに表示されるダメージを軽くバウンドさせる
		$('.receive_damage' + i).animate({top:"-10px"}, 200).animate({top:"-4px"}, 200)
		//時間差で下記処理を実行
		setTimeout(function(){
			//ダメージの削除
			$('[class^="receive_damage"]').remove();
			//味方へのダメージ演出をとめる
			clearTimeout(stop_leanBack[i][m]);		
			$(".battle_move_"+i).css({
				'left' : b_character_position_left_1[i] + 'px'
			});
			
			//全滅チェック
			Annihilation();
			
		},1300);
		
		//BGM
		//ボスクラスBGM const battle_bgm6 = [".bgm_jquery_at_1",".bgm_broadsaucer",".bgm_darksoldier",".bgm_cerberus",".bgm_noddydragon",".bgm_lassboss2_at"];
		if(bgm_village_flag){
			switch (bgm_type) {
				case "jQuery":	
					$(battle_bgm6[0]).get(0).currentTime = 0;
					$(battle_bgm6[0]).get(0).play();
					break;
				case "broadSaucer":	
					$(battle_bgm6[1]).get(0).currentTime = 0;
					$(battle_bgm6[1]).get(0).play();
					break;	
				case "darkSoldier":
					$(battle_bgm6[2]).get(0).currentTime = 0;
					$(battle_bgm6[2]).get(0).play();
					break;	
				case "Cerberus":	
					$(battle_bgm6[3]).get(0).currentTime = 0;
					$(battle_bgm6[3]).get(0).play();
					break;	
				case "noddyDragon":	
					$(battle_bgm6[4]).get(0).currentTime = 0;
					$(battle_bgm6[4]).get(0).play();
					break;	
				case "wordPress":	
					$(battle_bgm6[5]).get(0).currentTime = 0;
					$(battle_bgm6[5]).get(0).play();
					break;						
				default:
					$(battle_bgm3[0]).get(0).currentTime = 0;
					$(battle_bgm3[0]).get(0).play();
					break;
			}
		}
		$(".battle_status").remove();
		battle_status_show();
	}
/******************
 
モンスターからの通常ランダム攻撃

******************/
	//アホみたいな配列をつくった理由は、通常の変数だと他のモンスタースレッドと、被ってしまう(共有してしまう)から
	//要素数は適当です※今後出現モンスター数を変更するかもしれないから、とりあえず変更しても問題ない数にした
	let conf_survival = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
	let survival_zero = [false,false,false,false,false,false,false,false,false,false];
	let ally_under_attack = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
	function normalRandomAttack(monster){
		conf_survival[monster] = 0;
		survival_zero[monster] = false;
		ally_under_attack[monster] = 0
		//生存しているモンスターによる攻撃の前に、パーティーメンバーの死亡確認
		while(conf_survival[monster] <= 1 || survival_zero[monster]){
			ally_under_attack[monster]  = Math.floor(Math.random() * (b_character_hp.length));
			if(b_character_hp[ally_under_attack[monster]] <= 0){
				//攻撃される味方のHPが0だったら、一応全滅もチェックする
				//全滅していたらループを抜ける
				survival_zero[monster] = AnnihilationSub();
				if(!survival_zero[monster] ){
					continue;
				}else{
					return 10;
				}
			}else{
				//生存していたらループを抜ける
				conf_survival[monster] += 1;
			}	
		}
		return ally_under_attack[monster];
	}
	
/******************
 
背景を初期化する

******************/	
	function fieldreset(){
		//下はフィールド画像と戦闘背景画像を関連付けするための参考データ
		//戦闘背景・・・0grass,1ougi,2rasboss,3suna,4doukutu,5douku2_2,6yougan,7water,8water2,9yuki,10yuki2,11rakuen,12makai
		//フィールド背景・・・0ホワイト、1草原、2砂漠、3洞窟、4洞窟2、5溶岩、6水、7水2、8雪、9氷、10楽園、11宇宙、12宇宙
		if(id_current_field == 1)battleBackgroundChange(0);
		if(id_current_field == 2)battleBackgroundChange(3);
		if(id_current_field == 3)battleBackgroundChange(4);
		if(id_current_field == 4)battleBackgroundChange(5);
		if(id_current_field == 5)battleBackgroundChange(6);
		if(id_current_field == 6)battleBackgroundChange(7);
		if(id_current_field == 7)battleBackgroundChange(8);
		if(id_current_field == 8)battleBackgroundChange(9);
		if(id_current_field == 9)battleBackgroundChange(10);
		if(id_current_field == 10 && number_of_laps < 2)battleBackgroundChange(11);//戦闘背景rakuen
		if(id_current_field == 10 && number_of_laps >= 2)battleBackgroundChange(12);//戦闘背景makai
		if(id_current_field == 11)battleBackgroundChange(2);
		if(id_current_field == 12)battleBackgroundChange(2);			
	}	
/******************
 
フィールド画面に切り替える

******************/
	function fieldScreen(){
		//この関数が重複して実行されないようにするため
		fieldScreen_flag = true;
		//キャラクターがレベルアップしたかどうか
		levelup_chara_list = [false,false,false,false];
		//ターゲットリストを初期化
		target_monster_list = [];
		//背景が変更されている時は、ノーマル戦闘画面に戻す
		fieldreset();
	
		//補助魔法の効果を打ち消す(ステータスを元に戻す)
		b_character_status = $.extend(true, [], b_character_status_orijn);
		//バトル変数等の初期化処理(不要な初期化処理もおそらく含んでいる)		
		battle_step = 0;
		b_member_inex = 0;
		b_index = 0;			
		battle_run_flag = false;
		battle_stage_1 = false;
		battle_stage_2 = false;
		battle_stage_3 = false;
		battle_stage_3_1 = false;

		//頭上のカーソルを削除
		$('[class^="effect_img_"]').remove();
		//バトル関連のスレッドを停止
		clearInterval(effect_timer_1);
		clearInterval(stop_m_arrow_timer);		
		
		//clearInterval(stop_monster_behavior_time);
		$.each(stop_monster_behavior_time, function(o, oo) {
			clearTimeout(stop_monster_behavior_time[o]);
		})		
		$.each(stop_battle_run, function(a, ally) {
			clearTimeout(stop_battle_run[a]);
		})
		$.each(stop_monster_run, function(m, monster) {
			clearTimeout(stop_monster_run[m]);
		})
		clearInterval(stop_monster_standby);
		
		
		//タイマーに関する変数
		let Screen_switching_timer = 2000;
		let level_riser_timer = 0;
		let skill_learner_timer = 0;
		
		//BGM初期化
		bgmInitialization();

		/****************** 		
		勝利した場合 
		******************/
		if(!escape_flag){
			if(victory_flag){
				//勝利した場合//
				//生存キャラに経験値を付与、ならびに全回復
				$.each(b_character_hp, function(i, value) {	
					//生存キャラは全回復
					b_character_hp[i] = b_character_max_hp[i]; 
					b_character_mp[i] = b_character_max_mp[i];					
					if(b_character_hp[i] !== 0){
						if(b_character_level[i][0] == 99){
							//キャラクタがレベルアップしたかどうか
							levelup_chara_list[i] = false;
						}else{
							levelup_chara_list[i] = true;
							levelUp(i,(experience_point / 1000));
							//レベルをステータスに反映させる
							$(".battle_status").remove();
							battle_status_show();
						}
					}
				});
				//タイマーの設定
				$.each(b_character_hp, function(i, value) {
					if(b_character_hp[i] !== 0){
						Screen_switching_timer += 1000;
					}
				});		
				$.each(acquired_skills, function(i, value) {
					if(acquired_skills[i] !== ""){
						Screen_switching_timer += 1000;
					}
				});	
				$(".battle_message").remove();
				$('.battle_container').prepend('<div class ="battle_message">' + battle_message[0] + '</div>');	
				$('.battle_message').css({
					top:  battle_message_position_left + 'px',
					left: battle_message_position_left + 'px',
					zIndex : 91
				});

				//各キャラクターの勝利ダンス
				let winner_jump_height = [b_character_position_top_1[0] ,b_character_position_top_1[1],b_character_position_top_1[2],b_character_position_top_1[3]]
				victory_dance_time = setInterval(function(){	
					$.each(b_character_hp, function(i, value) {
						if(b_character_hp[i] !== 0){
							if(b_character_position_top_1[i] === winner_jump_height[i]){
								winner_jump_height[i] += 10;
							}else{
								winner_jump_height[i] -= 10;
							}	
							$(".battle_move_" + i).css({
								'top' : winner_jump_height[i]  + 'px'
							});
						}
					});
				},200);

				//キャラクタ毎のレベルアップを表示
				$.each(b_character_hp, function(i, value) {
					if(b_character_hp[i] !== 0 && levelup_chara_list[i] == true){
						level_riser_timer += 1000;
						setTimeout(function(){
							$('[class^="battle_message2"]').remove();
							//バトル中のメッセージ
							$('.battle_message').after('<div class ="battle_message2">' + member_name[i] + '  level up to level ' + b_character_level[i][0] + '!!' + '</div>');
							$(".battle_message2").css({
								top:  battle_message_position_left + 'px',
								left: battle_message_position_left + 'px',
								zIndex : 91
							});
						//メッセージの表示時間をキャラクター×時間で設定
						},level_riser_timer);
					}
				});
				
				//習得スキルメッセージ
				$.each(acquired_skills, function(i, value) {
					if(acquired_skills[i] !== ""){
						skill_learner_timer += 1000;
						setTimeout(function(){
							$('[class^="battle_message2"]').remove();
							//バトル中のメッセージ
							$('.battle_message').after('<div class ="battle_message2"> I learned to' +acquired_skills[i] + '!!' + '</div>');
							$(".battle_message2").css({
								top:  battle_message_position_left + 'px',
								left: battle_message_position_left + 'px',
								zIndex : 91
							});
						//メッセージの表示時間をキャラクター×時間で設定
						},(level_riser_timer + skill_learner_timer));
					}
				});				
				//ボス討伐後はファンファーレを変える
				if(battle_boss_flag){
						skill_learner_timer += 5000;
						Screen_switching_timer += (skill_learner_timer + 2000);
						let boss_serif = "";
						if(battle_boss_flag2)boss_serif = "oh! Dear WordPress~~!!"//ジェイクエリーの場合
						else boss_serif = "Oh my god~~ But I won't perish, I'll come back to life again and again!"//ワードプレスの場合
						$('[class^="battle_message2"]').remove();
						//メッセージの表示
						$('.battle_message').after('<div class ="battle_message2">'+ boss_serif + '</div>');
						$(".battle_message2").css({
							top:  battle_message_position_left + 'px',
							left: battle_message_position_left + 'px',
							zIndex : 91
						});						
						setTimeout(function(){
							let boss_serif = "";
							$('[class^="battle_message2"]').remove();
							//BGMを再生
							//bgm1・・・とめる曲。bgm2・・・流す曲 指定がない場合はー1
							bgmPlayback(bgm_load_item,battle_bgm9[1]);							
						},(level_riser_timer + skill_learner_timer));
				}else{//通常の雑魚キャラの場合は普通のファンファーレ
					//BGMを再生
					//bgm1・・・とめる曲。bgm2・・・流す曲 指定がない場合はー1				
					bgmPlayback(bgm_load_item,battle_bgm4[0]);					
				}					
			}else{
				/****************** 		
				全滅した場合 
				******************/
				//パーティメンバーのHPを1に設定する
				$.each(b_character_hp, function(hp_i, hp_value) {
					b_character_hp[hp_i] = 1;
				});
				setTimeout(function(){
					$('[class^="hit_damage_"]').remove();
					//バトル中のメッセージ
					$('.battle_container').prepend('<div class ="battle_message">' + battle_message[1] + '</div>');
					$('.battle_message').show().animate({
					//色などの複雑な設定はできないので、初期設定はCSS
						top:  battle_message_position_left + 'px',
						left: battle_message_position_left + 'px',
						zIndex : 91
					}, 50);			
				},200);
				//BGMを再生
				bgmPlayback(bgm_load_item,battle_bgm4[1]);
			}
		}else{
			/****************** 		
			逃走した場合 
			******************/
			setTimeout(function(){
				$('[class^="hit_damage_"]').remove();
				//バトル中のメッセージ
				$('.battle_container').prepend('<div class ="battle_message">' + battle_message[2] + '</div>');
				$('.battle_message').show().animate({
				//色などの複雑な設定はできないので、初期設定はCSS
					top:  battle_message_position_left + 'px',
					left: battle_message_position_left + 'px',
					zIndex : 91
				}, 50);			
			},200);
			//BGMを再生
			bgmPlayback(bgm_load_item,battle_bgm4[2]);
		}
		/****************** 		
		戦闘後の共通処理 
		******************/
		setTimeout(function(){
			//時間差でフィールド画面に切り替える
			//モンスター配列(monster_list)を再度構築する
			monsterShuffle();			
			
			//死んだ仲間のHPを1にしておく。スレッド外で実行すると勝利ダンスで死体が生存判定され跳ねてしまうため、このように時間差で実行
			$.each(b_character_hp, function(i, value) {
				if(b_character_hp[i] === 0){
					b_character_hp[i] = 1; 	
				}
			});
			//勝利ダンス(ジャンプ)の終了
			clearTimeout(victory_dance_time);
			//フィールド画面を非表示にする
			$('[class^="battle_message"]').remove();
			$('.battle_container').remove();
			$('.battle_menu').remove();
			$('.game_container').show();
			//バトルフラグをfalse
			battle_flag = false;
			battle_stage_1 = false;
			experience_point = 0;
			//BGMを再生。ただしボス討伐後の場合は流さない
			if(battle_boss_flag && victory_flag){
				//ボス討伐後はファンファーレを継続させる
			}else{
				bgmPlayback(bgm_load_item,bgmFieldBgm());
			}	
			//ボスのフラグ。ここで初期化する
			battle_boss_flag2 = false;
			battle_boss_flag = false;			
			//フィールドのムーブを開始
			deleteFieldCharacter();

		},Screen_switching_timer);
		
	}
	
	
	
	
	
/********************* 	

Aボタンで会話範囲判定内であれば会話する

*********************/	
	$(".a_btn").on('click',function(){
		if(title_flag){
			title_flag = false;
			//タイトルを削除
			clearInterval(title_ef_timer);
			$('[id^="game_title"]').remove();	
			//bgm1・・・とめる曲。bgm2・・・流す曲 指定がない場合はー1
			bgmPlayback(battle_bgm7[4],battle_bgm8[6]);		
			mainCharacterSetting();		
			SubCharacterSetting();
		}	
		if(battle_flag){
			//バトル中はAボタンを無効にする	
			if(!battle_run_flag){
				//fight、skill、runaway、防御を選択するとき
				if(battle_stage_1){
					//BGMが有効ならSE(決定した時の音)を再生
					if(bgm_village_flag){
						//currentTimeを0にすることですぐに再生できる
						$(battle_bgm2[0]).get(0).currentTime = 0;
						$(battle_bgm2[0]).get(0).play();
					}
					//通常攻撃を選択した場合
					if(0 === b_index){
						//キャラクターに応じたヒットエフェクト(hit_list)を指定するためのインデックスを保存
						b_chara_standby[b_member_inex][0] = b_member_inex;					
						battle_stage_3 = true;
						battle_stage_3_1 = false;							
						battle_stage_2 = false;
						battle_stage_1 = false;
						//モンスター名にマスク
						$('.m_name_'+ 0).css('background-color', 'dimgrey');
						//モンスター選択値を初期化
						monster_index = 0;
						//モンスターの頭上にカーソル
						monsterSelect(0);
						return;
						//monsterSelect(b_member_inex);
					}else if(1 === b_index){
						
						runAway();
					
					}else if(2 === b_index){				
						battle_stage_3 = false;
						battle_stage_3_1 = false;							
						battle_stage_2 = true;
						battle_stage_1 = false;
						//スキルを選択する際のインデックス
						skill_index = 0;
						//スキル一覧を表示
						battleCommand(b_member_inex);
						skillDescription();
						$('[id^="command_"]').css('background-color', 'black');
						$('#command_'+ skill_index).css('background-color', 'dimgrey');
						return;
					//防御を選択した時	
					}else if(3 === b_index){
						//暫定で防御のときはb_chara_standbyを99にしておく
						b_chara_standby[b_member_inex][0] = 99;
						b_member_inex += 1;
						b_member_inex = survivalCheck(b_member_inex);
						battle_stage_3 = false;
						battle_stage_3_1 = false;							
						battle_stage_2 = false;
						battle_stage_1 = true;
						//攻撃(テスト用)※4人目のモンスター選択が終わると同時に攻撃開始
						if(b_member_inex == 4){//4になっているがindex上では5人目
							battle_run_flag = true;
							clearInterval(effect_timer_1);
							$('[class^="selected_chara_"]').css('background-color', 'black');
							$('[id^="tactics_"]').css('background-color', 'black');
							$('[class^="effect_img_"]').remove();
							//バトル実行
							battleRun();
						}else{
							//頭上カーソルの停止と開始
							clearInterval(effect_timer_1);
							arrowSettings(b_member_inex);
							$('#tactics_'+ b_index).css('opacity', '.4').animate({'opacity': '1'}, 'fast');					
							$('[class^="selected_chara_"]').css('background-color', 'black');
							$('.selected_chara_'+ b_member_inex).css('background-color', 'dimgrey');
						}
					}else{}
				}//使用するスキルを決定した時の処理
				if(battle_stage_2){
					//画面上のスキル説明を削除
					$('[class^="battle_message"]').remove();
					//未使用のスキルは使用できない
					let slill_mp = (Number($('#command_'+ skill_index).val()) * 10);
					if(b_character_mp[b_member_inex] < slill_mp || $('#command_'+ skill_index).text() === "???"){
						if(bgm_village_flag){
							//currentTimeを0にすることですぐに再生できる
							$(battle_bgm2[2]).get(0).currentTime = 0;
							$(battle_bgm2[2]).get(0).play();
						}						
						return;
					}	
					//BGMが有効ならSE(決定した時の音)を再生
					if(bgm_village_flag){
						//currentTimeを0にすることですぐに再生できる
						$(battle_bgm2[0]).get(0).currentTime = 0;
						$(battle_bgm2[0]).get(0).play();
					}
					//どのヒットエフェクト(hit_list)を使うのかはskill_command_**[**]のkeyで指定
					b_chara_standby[b_member_inex][0] = $('#command_'+ skill_index).val();
					//回復系のスキルを選択した時は別フラグを立てる
					if(b_chara_standby[b_member_inex][0] == 6 || b_chara_standby[b_member_inex][0] == 10 || b_chara_standby[b_member_inex][0] == 14|| b_chara_standby[b_member_inex][0] == 18){
						battle_stage_3_1 = true;
					}	
					//console.log(b_chara_standby[b_member_inex][0]);
					//battle_stage_3(モンスター選択)へ移行
					battle_stage_3 = true;						
					battle_stage_2 = false;
					battle_stage_1 = false;
					//console.log(b_chara_standby[b_member_inex][1]);
					//スキルコマンド画面を削除
					$(".battle_skill_command").remove();
					//パーティーのステータスタグを出力
					battle_status_show();
					if(battle_stage_3_1){
						//回復スキルを選択した時
						//回復する味方の生死確認※死んでいたら生存しているキャラにカーソル設定
						recovery_index = 0;
						//全体魔法(kaifuku)は仲間を選択する必要がないので、次のキャラに移行
						if(b_chara_standby[b_member_inex][0] == 6 && skill_command_2[6] === "megahealing"){
							battle_stage_1 = true;
							battle_stage_2 = false;					
							battle_stage_3 = false;
							//死亡確認後、次のメンバーの戦闘準備
							b_member_inex += 1;
							b_member_inex = survivalCheck(b_member_inex);
							//攻撃(テスト用)※死亡、生存含め4人目の設定が終わると同時に攻撃開始
							CombatStart(b_member_inex);							
						//全体魔法(kaifuku)は仲間を選択する必要がないので、次のキャラに移行
						}else if(b_chara_standby[b_member_inex][0] == 10 && skill_command_2[10] === "megaRevival"){
							battle_stage_1 = true;
							battle_stage_2 = false;					
							battle_stage_3 = false;
							//死亡確認後、次のメンバーの戦闘準備
							b_member_inex += 1;
							b_member_inex = survivalCheck(b_member_inex);
							//攻撃(テスト用)※死亡、生存含め4人目の設定が終わると同時に攻撃開始
							CombatStart(b_member_inex);								
						}else if(b_chara_standby[b_member_inex][0] == 14 && skill_command_2[14] === "megaShield"){
							battle_stage_1 = true;
							battle_stage_2 = false;					
							battle_stage_3 = false;
							//死亡確認後、次のメンバーの戦闘準備
							b_member_inex += 1;
							b_member_inex = survivalCheck(b_member_inex);
							//攻撃(テスト用)※死亡、生存含め4人目の設定が終わると同時に攻撃開始
							CombatStart(b_member_inex);								
						}else if(b_chara_standby[b_member_inex][0] == 18 && skill_command_2[18] === "megaForceFang"){
							battle_stage_1 = true;
							battle_stage_2 = false;					
							battle_stage_3 = false;
							//死亡確認後、次のメンバーの戦闘準備
							b_member_inex += 1;
							b_member_inex = survivalCheck(b_member_inex);
							//攻撃(テスト用)※死亡、生存含め4人目の設定が終わると同時に攻撃開始
							CombatStart(b_member_inex);								
						}else{
							recoveryArrowSettings(recovery_index);
						}
					}else{	
						//モンスター名にマスク
						$('.m_name_'+ 0).css('background-color', 'dimgrey');
						//モンスター選択値を初期化
						monster_index = 0;
						//モンスターの頭上にカーソル
						monsterSelect(0);
					}
					return;
				}	
				if(battle_stage_3){
					//BGMが有効ならSE(決定した時の音)を再生
					if(bgm_village_flag){
						//currentTimeを0にすることですぐに再生できる
						$(battle_bgm2[0]).get(0).currentTime = 0;
						$(battle_bgm2[0]).get(0).play();
					}
					battle_stage_1 = true;
					battle_stage_2 = false;					
					battle_stage_3 = false;
					if(battle_stage_3_1){//回復スキルを使用するとき
						//回復する相手(インデックス)を格納
						battle_stage_3_1 = false;
						recovery_target[b_member_inex] = recovery_index;
						$('[class^="recovery_arrow_"]').remove();
						clearInterval(effect_timer_2);
					}else{//攻撃をするとき
						//ターゲットにするモンスターインデックスを格納
						//target_monster_list[b_member_inex] = monster_index;
						target_monster_list[b_member_inex] = monster_list[monster_index];
						//モンスター選択関連のエフェクトを削除
						$('[class^="m_name_"]').css('background-color', 'black');
						$('[class^="m_select_arrow_img_"]').remove();
					}
					//死亡確認後、次のメンバーの戦闘準備
					b_member_inex += 1;
					b_member_inex = survivalCheck(b_member_inex);
					//攻撃(テスト用)※死亡、生存含め4人目の設定が終わると同時に攻撃開始
					CombatStart(b_member_inex);	
				}	
			}
		}else{
			let talk_target = 99;
			//会話範囲判定の検索
			$.each(new_character_list, function(i, value) {
				if(talk_range[i])talk_target = i;	
			});	
			//会話範囲判定内であれば会話する
			if(talk_target !== 99){
				if(conversationv_flag){
					endOfConversation();
				}else{
					conversation(talk_target);
				}
			}
			//オブジェクトのイベント
			$.each(obj_hit_flag, function(i, value) {
				if(i == 0 && continuous_click_prevention == 0){
					if(obj_hit_flag[i] == true){
						//連続クリック防止
						continuous_click_prevention += 1;
						//ワープイベント
						objectEventRange(0);
					}
				}
			});	
		}
	});
	
/********************* 	

(後始末をしてから)バトル開始

*********************/
	function CombatStart(b_menber_id){
		if(b_menber_id == 4){//4になっているがindex上では5人目
			battle_run_flag = true;
			clearInterval(effect_timer_1);
			$('[class^="selected_chara_"]').css('background-color', 'black');
			$('[id^="tactics_"]').css('background-color', 'black');
			$('[class^="effect_img_"]').remove();
			//バトル実行
			battleRun();
		}else{
			//頭上カーソルの停止と開始
			clearInterval(effect_timer_1);
			arrowSettings(b_menber_id);
			$('#tactics_'+ b_index).css('opacity', '.4').animate({'opacity': '1'}, 'fast');					
			$('[class^="selected_chara_"]').css('background-color', 'black');
			$('.selected_chara_'+ b_menber_id).css('background-color', 'dimgrey');
		}		
	}	
/********************* 
	
Bボタンで会話をキャンセル

*********************/	
	$(".b_btn").on('click',function(){
		if(title_flag){
			title_flag = false;
			//タイトルを削除
			clearInterval(title_ef_timer);
			$('[id^="game_title"]').remove();	
			//bgm1・・・とめる曲。bgm2・・・流す曲 指定がない場合はー1
			bgmPlayback(battle_bgm7[4],battle_bgm8[6]);	
			mainCharacterSetting();		
			SubCharacterSetting();
		}
		if(battle_flag){
			if(battle_stage_1){
				$('#tactics_'+ b_index).css('opacity', '.4').animate({'opacity': '1'}, 'fast');
				b_member_inex -= 1;
				if(b_member_inex <= 0)b_member_inex = 0;
				//頭上カーソルの停止と開始
				clearInterval(effect_timer_1);
				arrowSettings(b_member_inex);
				$('[class^="selected_chara_"]').css('background-color', 'black');
				$('.selected_chara_'+ b_member_inex).css('background-color', 'dimgrey');
			}
			if(battle_stage_2){
				battle_stage_1 = true;				
				battle_stage_2 = false;
				battle_stage_3 = false;
				battle_stage_3_1 = false;
				//画面上のスキル説明を削除
				$('[class^="battle_message"]').remove();				
				//パーティーのスキルコマンド欄を削除
				$(".battle_skill_command").remove();
				//パーティーのステータスタグを出力
				battle_status_show();			
			}
			if(battle_stage_3){
				battle_stage_1 = true;				
				battle_stage_2 = false;
				battle_stage_3 = false;
				battle_stage_3_1 = false;
				//回復スキル矢印削除
				//$('[class^="recovery_effect_img_"]').remove();
				$('[class^="recovery_arrow_"]').remove();				
				clearInterval(effect_timer_2);	
				
				//モンスター選択関連のエフェクトを削除
				$('[class^="m_name_"]').css('background-color', 'black');
				$('[class^="m_select_arrow_img_"]').remove();	
			}			
		}else if(conversationv_flag){
			endOfConversation();
		}else{}	
	});
	
	
	
/******************* 	
	バトルの実行
********************/
	function battleRun(){
		let turn_index = 0;
		//1人目
		if(b_chara_standby[0][0] == 99 || b_chara_standby[0][0] == 100){		
			//モンスターが全滅していたらフィールド画面に戻る
			// if(monsterAnnihilation() == 0){
				// victory_flag = true;
				// fieldScreen();
				// return;
			// }		
		}else{			
				//攻撃力に揺らぎをつくる
				// (Math.random() * ( (最大値 + 1) - 最小値 ) + 最小値;)
				let variable_range_0 = Math.floor(Math.random() * ((8 + 1) - 2)) + 2;					 
				b_character_status[0][0] = b_character_status[0][0] + Math.floor(b_character_status[0][0] * (variable_range_0 / 100));			
				//console.log();
				
			stop_battle_run[0] = setTimeout(function(){
				battle_step = 0;
				//モンスターが全滅していたらフィールド画面に戻る
				if(monsterAnnihilation() == 0){
					// victory_flag = true;
					// fieldScreen();
				}else{
					battleCharaDirection(0);
				}
			},turn_time[turn_index]);			
		}

		//2人目
		if(b_chara_standby[1][0] == 99 || b_chara_standby[1][0] == 100){
			//モンスターが全滅していたらフィールド画面に戻る
			// if(monsterAnnihilation() == 0){
				// victory_flag = true;
				// fieldScreen();
				// return;
			// }
		}else{
			//攻撃力に揺らぎをつくる
			// (Math.random() * ( (最大値 + 1) - 最小値 ) + 最小値;)
			let variable_range_1 = Math.floor(Math.random() * ((8 + 1) - 2)) + 2;					 
			b_character_status[1][0] = b_character_status[1][0] + Math.floor(b_character_status[1][0] * (variable_range_1 / 100));			
			//console.log();			
			turn_index += 1;
			stop_battle_run[1] = setTimeout(function(){
				battle_step = 0;
				//モンスターが全滅していたらフィールド画面に戻る
				if(monsterAnnihilation() == 0){
					// victory_flag = true;
					// fieldScreen();
					// return;					
				}else{
					battleCharaDirection(1);	
				}				
			},turn_time[turn_index]);			
		}	
		//3人目
		if(b_chara_standby[2][0] == 99 || b_chara_standby[2][0] == 100){		
			//モンスターが全滅していたらフィールド画面に戻る
			// if(monsterAnnihilation() == 0){
				// victory_flag = true;
				// fieldScreen();
				// return;
			// }
		}else{
			//魔力に揺らぎをつくる
			// (Math.random() * ( (最大値 + 1) - 最小値 ) + 最小値;)
			let variable_range_2 = Math.floor(Math.random() * ((8 + 1) - 2)) + 2;					 
			b_character_status[2][1] = b_character_status[2][1] + Math.floor(b_character_status[2][1] * (variable_range_2 / 100));			
			//console.log();			
			turn_index += 1;			
			stop_battle_run[2] = setTimeout(function(){
				battle_step = 0;
				//モンスターが全滅していたらフィールド画面に戻る
				if(monsterAnnihilation() == 0){
					// victory_flag = true;
					// fieldScreen();
				}else{
					battleCharaDirection(2);
				}				
			},turn_time[turn_index]);		
		}	
		//4人目
		if(b_chara_standby[3][0] == 99 || b_chara_standby[3][0] == 100){
			//モンスターが全滅していたらフィールド画面に戻る
			// if(monsterAnnihilation() == 0){
				// victory_flag = true;
				// fieldScreen();
				// return;
			// }
		}else{
			//魔力に揺らぎをつくる
			// (Math.random() * ( (最大値 + 1) - 最小値 ) + 最小値;)
			let variable_range_3 = Math.floor(Math.random() * ((8 + 1) - 2)) + 2;					 
			b_character_status[3][1] = b_character_status[3][1] + Math.floor(b_character_status[2][1] * (variable_range_3 / 100));					
			turn_index += 1;			
			stop_battle_run[3] = setTimeout(function(){
				battle_step = 0;
				//モンスターが全滅していたらフィールド画面に戻る
				if(monsterAnnihilation() == 0){
					// victory_flag = true;
					// fieldScreen();
				}else{
					battleCharaDirection(3);	
				}				
			},turn_time[turn_index]);			
		}	
		//モンスター全滅確認
		//ただしバトル中に別のスレッドで、全て倒した場合、ここでモンスター全滅を確認しても意味はない
		//なのでスレッドの中でも確認している
		if(monster_list.length != 0){
			turn_index += 1;
			stop_monster_run = [];
			stop_monster_standby = setTimeout(function(){
				//モンスターを全滅させ、 fieldScreen()が実行されているとbattle_flagがfalseになる
				//つまりすでにバトルが終了しているかどうかのチェックをしている
				if(battle_flag){
					stop_monster_run = [monster_list.length];	
					//モンスターが全滅しているのに、時間差でfieldScreen()が実行されていない場合があるので
					//ここで、再度チェック
					$.each(monster_list, function(m, m_value) {
						stop_monster_run[m] = setTimeout(function(){
							//if(m in monster_list){
							//パーティが全滅しているかどうかをまずチェック
							if(!AnnihilationSub()){	
								//ボスクラスによる攻撃の場合
								let m_boss_class = [];
								m_boss_class = monster_list[m].split('"')//ケルベロスmon_special_at[0]ノーディドラゴンmon_special_at[1]ブロードソーサーmon_special_at[2]ダークソルジャーmon_special_at[3]ジェイクエリーmon_special_at[4]							
								//' alt="jQuery" name="jQuery" src="https://likehuman.info/wp-content/uploads/2023/03/m_b_jquery.png" >';
								//m_boss_class[3]はname属性のジェイクエリーが該当する
								let boss_jquery = 0;//ジェイクエリー特有の攻撃
								if(m_boss_class[3] === "Cerberus" || m_boss_class[3] === "noddyDragon" || m_boss_class[3] === "broadSaucer" || m_boss_class[3] === "darkSoldier" || m_boss_class[3] === "jQuery" || m_boss_class[3] === "wordPress"){
									//ボスクラスモンスターでも、常に全体攻撃はしない
									//2分の1の乱数で、発動するようにしている。※1か2(1がでたら全体攻撃)
									//Math.random()関数が0以上1未満なので、Math.random()*2+1にした。
									//Math.floor()は切捨て関数。ゆえに2以上の数値はでない。1か2しかでない。
									if((Math.floor(Math.random()*2 + 1)) == 1){
									//生存しているパーティに対する全体攻撃
										$.each(b_character_hp, function(t, t_value) {
											if(b_character_hp[t] === 0){
												
											}else{
												if(m_boss_class[3] === "jQuery" || m_boss_class[3] === "wordPress")boss_jquery += 100;
													//100という数値に深い意味はない。ジェイクエリー特有の関数がループ中に1回だけ実行されれば良いだけ
												if(boss_jquery === 100){
													//ジェイクエリーのエフェクトと初期動作※1回実行したいだけなので他はelse内で実行
													jqueryAttacks();
													attackInitialAction(m);
												}else{
													//ボスクラスによる攻撃エフェクト※ジェイクエリー以外
													if(m_boss_class[3] !== "jQuery" && m_boss_class[3] !== "wordPress"){
														specialAttacksByMonsters(t,m,m_boss_class[3]);
													}	
												}
												//ボスクラスによる攻撃
												setTimeout(function(){
													receiveDamage(t,m,m_boss_class[3]);
												},1000);
											}	
										});
									}else{
										if( m_boss_class[3] === "jQuery" || m_boss_class[3] === "wordPress"){
											if((Math.floor(Math.random()*2 + 1)) == 1){
												//2分の一の確率で自身を回復
												monsterRecoverAction(m);
												if(survivor[m] != 10)receiveDamage(survivor[m],m,"通常");
											}else{
												//通常の攻撃
												//ランダムに選択された味方ターゲットが生存しているかどうか
												survivor[m] = 0;
												//survivor[m]・・・配列にした理由は、通常の変数だと他のスレッドと被ってしまうから
												//被ってしまうと、死体を攻撃してしまうことになる
												survivor[m] = normalRandomAttack(m)
												//全滅してなければ10以外の数値が返ってくる
												//console.log(survivor[m]);
												if(survivor[m] != 10)receiveDamage(survivor[m],m,"通常");									
											}
										}else{	
											survivor[m] = 0;
											survivor[m] = normalRandomAttack(m)
											if(survivor[m] != 10)receiveDamage(survivor[m],m,"通常");
										}
									}	
								}else{
									//通常モンスターによる攻撃
									survivor[m] = 0;
									survivor[m] = normalRandomAttack(m)
									if(survivor[m] != 10)receiveDamage(survivor[m],m,"通常");
								}
								//攻撃初期動作
								//・ラスボス以外※すでに実行済みなので
								//・初期動作は一回だけで良いので、ループの外に書いている
								if(m_boss_class[3] !== "jQuery" && m_boss_class[3] !== "wordPress")attackInitialAction(m);
							}else{
								//○○番目のモンスターがいなければ、そのスレッドを停止
								clearInterval(stop_monster_run[m]);
							}
							/********************** 							
							次のターンへ	
							**********************/					
							if(monster_list.length - 1 ===  m ){
								stop_battle_run[4] = setTimeout(function(){
									//ターンの割り込み等でキャラクターの位置がずれる時があるので、元に戻す
/* 									$.each(b_character_hp, function(hp_i, hp_value) {
										$(".battle_move_" + hp_i).css({
											'left' :  (view_w / 4 * 3) + 'px',
										});
									}); */
									
									battle_step = 0;
									b_member_inex = 0;
									b_index = 0;		
									battle_run_flag = false;
									//生存確認
									b_member_inex = survivalCheck(0);
									//カーソルの初期設定(一番目のキャラクターにカーソルを設定させる)			
									arrowSettings(b_member_inex);
									//初期位置のCSS
									$('#tactics_'+ b_index).css('background-color', 'dimgrey');
									$('.selected_chara_'+ b_member_inex).css('background-color', 'dimgrey');
							
									//モンスターが全滅していたらフィールド画面に戻る
									if(monsterAnnihilation() == 0){
										// victory_flag = true;
										// fieldScreen();
									}else{
										//BGMが有効ならSE(ターンの音)を再生
										if(bgm_village_flag){
											//currentTimeを0にすることですぐに再生できる
											$(battle_bgm2[0]).get(0).currentTime = 0;
											$(battle_bgm2[0]).get(0).play();
										}		
									}
								//時間調整
								},3000);
								//},turn_time[monster_list.length]);
							}
						},turn_time[m]);
					});
				}else{
					//バトルが終了していたらモンスターのスレッドを停止
					clearInterval(stop_monster_standby);
				}	
			},turn_time[turn_index]);	
		}
	}
});







</script>