public static void Set_Movablelist() { //移動可能範囲の初期化 movablelist = new List <int[]>(); //移動可能範囲を取得 movablelist = Mapclass.Dfs(BattleVal.mapdata, BattleVal.selectX, BattleVal.selectY, BattleVal.selectedUnit.status.step, BattleVal.selectedUnit.status.jump); }
//出撃可能エリアにユニットを描画 public void DrawUnit() { CharaData loaddata = ScriptableObject.Instantiate(Resources.Load(string.Format("BattleChara/{0}", unit.savescobj)) as CharaData); unit.gobj = MonoBehaviour.Instantiate(loaddata.gobj, new Vector3(), Quaternion.identity); foreach (int[] pos in CharaSetup.unitsetposlist) { //キャラが居なければ生成 if (!BattleVal.id2index.ContainsKey(string.Format("{0},{1}", pos[0], pos[1]))) { //描画 Mapclass.DrawCharacter(unit.gobj, pos[0], pos[1]); unit.gobj.layer = 8; unit.x = pos[0]; unit.y = pos[1]; //unitlistへの登録 BattleVal.unitlist.Add(unit); //id2indexへの登録 BattleVal.id2index.Add(string.Format("{0},{1}", pos[0], pos[1]), unit); ////mapdataにユニット情報を登録 BattleVal.mapdata[(int)MapdataList.MAPUNIT][unit.y][unit.x] = 99; //ユニット番号はcsvから読み取るときしか使わないため、1から99なら何でもよい //足元にチーム識別タイルを GameObject unittile; unittile = Instantiate(prefabPlayerTile, unit.gobj.transform); unittile.transform.localScale = new Vector3(unittile.transform.localScale.x / unittile.transform.lossyScale.x, 0.01f, unittile.transform.localScale.z / unittile.transform.lossyScale.z); Mapclass.DrawCharacter(unittile, unit.x, unit.y); break; } } }
//attackablelistを表示するだけ public static void Show_Attackablelist() { //表示処理 foreach (int[] mappos in attackablelist) { GameObject tmptile = Instantiate(attackabletile); tilelist.Add(tmptile); Mapclass.DrawCharacter(tilelist[tilelist.Count - 1], mappos[0], mappos[1]); } }
public Range ForbiddenRange; //禁止範囲 //RangeからAttackDfsに渡す部分マップを作成する public List <int[]> Attackablelist(List <List <List <int> > > maps, int startx, int starty) { List <int[]> ans = new List <int[]>(); //ベース範囲の計算 ans = Mapclass.DfsA(maps, startx, starty, BaseRange); //禁止範囲の計算 List <int[]> forbidden = new List <int[]>(); forbidden = Mapclass.DfsA(maps, startx, starty, ForbiddenRange); if (!ForbiddenRange.is_selfforbidden) { int[] temp = new int[] { startx, starty }; //dummy bool flag = false; foreach (int[] t in forbidden) { if (t[0] == startx && t[1] == starty) { temp = t; flag = true; break; } } if (flag) { forbidden.Remove(temp); } } //Exceptを使うために文字列に変換 List <string> ansstring = new List <string>(); foreach (int[] tile in ans) { ansstring.Add(TileToString(tile)); } List <string> forbiddenstring = new List <string>(); foreach (int[] tile in forbidden) { forbiddenstring.Add(TileToString(tile)); } //禁止範囲の除外 ansstring = ansstring.Except <string>(forbiddenstring).ToList <string>(); //戻す ans = new List <int[]>(); foreach (string str in ansstring) { ans.Add(StringToTile(str)); } return(ans); }
public static void Show_Movablelist() { //表示処理 foreach (int[] mappos in movablelist) { if (!BattleVal.zocmap[mappos[0], mappos[1]]) { tilelist.Add(Instantiate(movabletile)); } if (BattleVal.zocmap[mappos[0], mappos[1]]) { tilelist.Add(Instantiate(zoctile)); } Mapclass.DrawCharacter(tilelist[tilelist.Count - 1], mappos[0], mappos[1]); } }
//与えたマップ内座標が、選択したユニットの移動可能範囲(movablelist)かを判定し、移動可能なら移動準備を行う public static bool Is_movable(int map_x, int map_y) { //判定 foreach (int[] mappos in movablelist) { if (map_x == mappos[0] && map_y == mappos[1]) { //移動経路を登録 movepath = Mapclass.GetPath(BattleVal.mapdata, BattleVal.selectedUnit.status.step, BattleVal.selectX, BattleVal.selectY, map_x, map_y, BattleVal.selectedUnit.status.jump); Initialize_Moving_Param(); Destroy_Movabletile(); return(true); } } return(false); }
//attackablelistを表示するだけ public static void Show_Attackablelist() { //表示処理 foreach (int[] mappos in attackablelist) { GameObject tmptile; //回復かどうか if (selectedskill.s_atk < 0) { tmptile = Instantiate(healabletile); } else { tmptile = Instantiate(attackabletile); } tilelist.Add(tmptile); Mapclass.DrawCharacter(tilelist[tilelist.Count - 1], mappos[0], mappos[1]); } }
//攻撃エリアの描画 public static void Show_Attackarea() { //消去処理 Destroy_Areatile(); //表示処理 foreach (int[] mappos in attackkingarea) { GameObject tmptile; //回復かどうか if (selectedskill.s_atk < 0) { tmptile = Instantiate(healareatile); } else { tmptile = Instantiate(attackareatile); } areatilelist.Add(tmptile); Mapclass.DrawCharacter(areatilelist[areatilelist.Count - 1], mappos[0], mappos[1]); } }
//ユニット設置可能なマスにタイルを描く void DrawTile() { unitsetposlist.Clear(); for (int i = 0; i < Mapclass.mapxnum; i++) { for (int j = 0; j < Mapclass.mapynum; j++) { if (BattleVal.mapdata[(int)MapdataList.MAPUNITSET][j][i] == 1) { unitsetlist.Add(Instantiate(UnitSetTile)); Mapclass.DrawCharacter(unitsetlist[unitsetlist.Count - 1], i, j); //1つ目の座標に視点移動 if (unitsetposlist.Count == 0) { Vector3 temp = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref temp, i, j); CameraAngle.CameraPoint(temp); } unitsetposlist.Add(new int[] { i, j }); } } } }
//キャラクターの座標を入れ替える関数(配置変更用) public static void Swap_Unit_Position(Unitdata unit1, Unitdata unit2) { int tmpx, tmpy; tmpx = unit1.x; tmpy = unit1.y; //unit1のGameObjectの位置を変更 Vector3 r1 = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r1, unit2.x, unit2.y); unit1.gobj.transform.position = r1; unit1.gobj.transform.LookAt(new Vector3(r1.x, unit1.gobj.transform.position.y, r1.z)); unit1.x = unit2.x; unit1.y = unit2.y; //unit2のGameObjectの位置を変更 Mapclass.TranslateMapCoordToPosition(ref r1, tmpx, tmpy); unit2.gobj.transform.position = r1; unit2.gobj.transform.LookAt(new Vector3(r1.x, unit2.gobj.transform.position.y, r1.z)); unit2.x = tmpx; unit2.y = tmpy; //map上のキャラクターIDの更新 int tmpmap1 = BattleVal.mapdata[(int)MapdataList.MAPUNIT][unit1.y][unit1.x]; BattleVal.mapdata[(int)MapdataList.MAPUNIT][unit1.y][unit1.x] = BattleVal.mapdata[(int)MapdataList.MAPUNIT][unit2.y][unit2.x]; BattleVal.mapdata[(int)MapdataList.MAPUNIT][unit2.y][unit2.x] = tmpmap1; //ディクショナリのアップデート BattleVal.id2index.Remove(string.Format("{0},{1}", unit2.x, unit2.y)); //swap後なのでこれはunit1の消去であることに注意 BattleVal.id2index.Remove(string.Format("{0},{1}", unit1.x, unit1.y)); //swap後なのでこれはunit2の消去であることに注意 BattleVal.id2index.Add(string.Format("{0},{1}", unit1.x, unit1.y), unit1); BattleVal.id2index.Add(string.Format("{0},{1}", unit2.x, unit2.y), unit2); }
//キャラクターの座標を変更する関数(1手戻し、配置変更用) public static void Change_Unit_Position(Unitdata unit, int[] old_pos, int[] new_pos) { //unitのGameObjectの位置を変更 Vector3 r1 = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r1, new_pos[0], new_pos[1]); unit.gobj.transform.position = r1; unit.gobj.transform.LookAt(new Vector3(r1.x, unit.gobj.transform.position.y, r1.z)); unit.x = new_pos[0]; unit.y = new_pos[1]; //map上のキャラクターIDの更新 BattleVal.mapdata[(int)MapdataList.MAPUNIT][new_pos[1]][new_pos[0]] = BattleVal.mapdata[(int)MapdataList.MAPUNIT][old_pos[1]][old_pos[0]]; BattleVal.mapdata[(int)MapdataList.MAPUNIT][old_pos[1]][old_pos[0]] = 0; //ディクショナリのアップデート BattleVal.id2index.Remove(string.Format("{0},{1}", old_pos[0], old_pos[1])); BattleVal.id2index.Add(string.Format("{0},{1}", new_pos[0], new_pos[1]), unit); //unitの行動フラグを戻す unit.movable = true; }
//敵がターゲットを見つける関数 public static int[] SearchTraget(Unitdata enemy) { //戻り値 int[] target = new int[2]; target[0] = -1; target[1] = -1; //考える範囲 int range = enemy.routin.sightrange; if (range == 0) { range = enemy.status.step * 2; //defaultならばstepの2倍 } //rangeでDfsを呼び出す List <int[]> searchlist = Mapclass.Dfs(BattleVal.mapdata, enemy.x, enemy.y, range, enemy.status.jump); //Dfsは自身を含まないため、加える searchlist.Add(new int[] { enemy.x, enemy.y }); //発見したtargetのリスト HashSet <int[]> targetlist = new HashSet <int[]>(); //searchlistをまわす foreach (int[] coord in searchlist) { //攻撃可能マスを取得 //List<int[]> attacklist = Mapclass.AttackDfs(BattleVal.mapdata, coord[0], coord[1], // CharaAttack.attackrange[enemy.jobid], CharaAttack.AttackMaxRange(enemy.jobid)); List <int[]> attacklist = enemy.attackrange.Attackablelist(BattleVal.mapdata, coord[0], coord[1]); //攻撃範囲を探索 foreach (int[] attackcoord in attacklist) { //そこに誰かいれば if (BattleVal.id2index.ContainsKey( string.Format("{0},{1}", attackcoord[0], attackcoord[1]))) { //それが敵ではないならターゲットに追加 if (BattleVal.id2index[string.Format("{0},{1}", attackcoord[0], attackcoord[1])].team != enemy.team) { targetlist.Add(attackcoord); } } } } //ターゲットがいない場合 if (targetlist.Count == 0) { return(new int[] { enemy.x, enemy.y }); //自身の座標を返却 } //AIタイプに基づいてtargetlistからターゲットを決める //ターゲットループ double maxeval = 0.0; foreach (int[] targetcoord in targetlist) { Unitdata unit = BattleVal.id2index[string.Format("{0},{1}", targetcoord[0], targetcoord[1])]; double evaluation = enemy.routin.EvaluationTarget(enemy, unit); //評価値が最大なら、ターゲットに。 if ((target[0] == -1 && target[1] == -1) || evaluation > maxeval) { maxeval = evaluation; target = targetcoord; } } return(target); }
//攻撃対象に向けて移動する先を決める public static int[] DecideDestination(Unitdata enemy, int[] target) { int[] destination = new int[2]; //命を大事にする傾向で、HPが1/8を切っていたら逃げる if (enemy.hp <= enemy.status.maxhp / 8 && enemy.routin.Cherish_life) { //自身とターゲットにの間の変位ベクトルの反転を求める int[] v = new int[] { enemy.x - target[0], enemy.y - target[1] }; //vのx,yの整数比を求め、疑規格化 for (int i = 2; i <= (int)Mathf.Min(v[0], v[1]);) { if (v[0] % i == 0 && v[1] % i == 0) { v[0] /= i; v[1] /= i; } else { i++; } } target = new int[] { enemy.x + v[0] * enemy.status.step, enemy.y + v[1] * enemy.status.step }; if (target[0] >= Mapclass.mapxnum) { target[0] = Mapclass.mapxnum - 1; } if (target[0] < 0) { target[0] = 0; } if (target[1] >= Mapclass.mapynum) { target[1] = Mapclass.mapynum - 1; } if (target[1] < 0) { target[1] = 0; } } //歩数が十分大きいとして、行動可能範囲を探索 List <int[]> movablelist = Mapclass.Dfs(BattleVal.mapdata, enemy.x, enemy.y, enemy.status.step, enemy.status.jump); //Dfsは自身の位置を含めないため、追加 movablelist.Add(new int[] { enemy.x, enemy.y }); int mindist = -1; //移動可能範囲の中で、ターゲットに攻撃できる位置に向かう //もしくはターゲットに最も近いマンハッタン距離の位置に向かう foreach (int[] a in movablelist) { //攻撃可能マスを取得 //List<int[]> attacklist = Mapclass.AttackDfs(BattleVal.mapdata, coord[0], coord[1], // CharaAttack.attackrange[enemy.jobid], CharaAttack.AttackMaxRange(enemy.jobid)); List <int[]> attacklist = enemy.attackrange.Attackablelist(BattleVal.mapdata, a[0], a[1]); bool brakeflag = false; //攻撃範囲を探索 foreach (int[] attackcoord in attacklist) { //そこにターゲットがいる if (attackcoord[0] == target[0] && attackcoord[1] == target[1]) { destination = a; brakeflag = true; break; } } if (brakeflag) { break; } int tempdist = Mapclass.Calc_Dist(target, a); if (mindist == -1 || tempdist < mindist) { mindist = tempdist; destination = a; } } return(destination); }
public GameObject defeatEffect; //撃墜時のエフェクト private void Update() { //戦闘中 if (BattleVal.status == STATUS.BATTLE) { bool critflag = false; bool dodgeflag = false; int damage = 0; switch (bstate) { case BATTLE_STATUS.SETVECT: //キャラの向きの調整 Vector3 r0 = new Vector3(); //攻撃元 Vector3 r1 = new Vector3(); //攻撃先 Mapclass.TranslateMapCoordToPosition(ref r0, BattleVal.selectX, BattleVal.selectY); Mapclass.TranslateMapCoordToPosition(ref r1, attackedpos[0], attackedpos[1]); //攻撃対象の登録 Unitdata temp = BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])]; damage = Calc_Damage(BattleVal.selectedUnit, temp); float dex = Calc_Dexterity(BattleVal.selectedUnit, temp); float rate = Calc_CriticalRate(BattleVal.selectedUnit, temp); //当たった場合 if (Is_Hit(dex)) { //クリティカル発生かどうか if (Is_Hit(rate)) { damage = (int)(damage * 1.5f); critflag = true; } temp.hp -= damage; //ダメージ処理 string damagetext = string.Format("{0}", damage); int count = 1; //ダメージテキストの中心座標 Vector3 damage_center = Camera.main.WorldToScreenPoint(r1); //テキストの登録 foreach (char a in damagetext) { int num = (int)char.GetNumericValue(a); //数を取得 damagenum.Add(Instantiate(damagetextprefab, r1, Quaternion.identity)); damagenum[count - 1].text = a.ToString(); //サイズ取得 damagenum[count - 1].rectTransform.sizeDelta = new Vector2(damagenum[count - 1].preferredWidth, damagenum[count - 1].preferredHeight); damagenum[count - 1].rectTransform.sizeDelta = new Vector2(damagenum[count - 1].preferredWidth, damagenum[count - 1].preferredHeight); damagenum[count - 1].transform.SetParent(canvas.transform, false); damagenum[count - 1].transform.localPosition = damage_center - new Vector3(canvas.GetComponent <RectTransform>().sizeDelta.x / 2, canvas.GetComponent <RectTransform>().sizeDelta.y / 2, 0); //1桁当たりの文字ブロック Vector3 numsize = damagenum[count - 1].GetComponent <RectTransform>().sizeDelta *damagenum[count - 1].GetComponent <RectTransform>().localScale; numsize.y = 0; numsize.z = 0; damagenum[count - 1].transform.localPosition += (count - 1) * numsize; damagenum[count - 1].transform.localPosition += new Vector3(0, 30, 0); damagenum[count - 1].gameObject.SetActive(false); damagenum[count - 1].color = new Vector4(1, 0, 0, 1); count++; } //クリティカルの場合、そのテキストを表示 if (critflag) { damagenum.Add(Instantiate(damagetextprefab, r1, Quaternion.identity)); damagenum[count - 1].text = "Critical!"; //サイズ取得 damagenum[count - 1].rectTransform.sizeDelta = new Vector2(damagenum[count - 1].preferredWidth, damagenum[count - 1].preferredHeight); damagenum[count - 1].rectTransform.sizeDelta = new Vector2(damagenum[count - 1].preferredWidth, damagenum[count - 1].preferredHeight); damagenum[count - 1].transform.SetParent(canvas.transform, false); damagenum[count - 1].transform.localPosition = damage_center - new Vector3(canvas.GetComponent <RectTransform>().sizeDelta.x / 2, canvas.GetComponent <RectTransform>().sizeDelta.y / 2, 0); damagenum[count - 1].transform.localPosition += new Vector3(0, 100, 0); damagenum[count - 1].gameObject.SetActive(false); damagenum[count - 1].color = new Color(1.0f, 1.0f, 0); count++; } } else { dodgeflag = true; //ダメージテキストの中心座標 Vector3 damage_center = Camera.main.WorldToScreenPoint(r1); //テキストの登録 damagenum.Add(Instantiate(damagetextprefab, r1, Quaternion.identity)); damagenum[0].text = "DODGE!"; //サイズ取得 damagenum[0].rectTransform.sizeDelta = new Vector2(damagenum[0].preferredWidth, damagenum[0].preferredHeight); damagenum[0].rectTransform.sizeDelta = new Vector2(damagenum[0].preferredWidth, damagenum[0].preferredHeight); damagenum[0].transform.SetParent(canvas.transform, false); damagenum[0].transform.localPosition = damage_center - new Vector3(canvas.GetComponent <RectTransform>().sizeDelta.x / 2, canvas.GetComponent <RectTransform>().sizeDelta.y / 2, 0); damagenum[0].transform.localPosition += new Vector3(0, 30, 0); damagenum[0].gameObject.SetActive(false); damagenum[0].color = new Vector4(1, 1, 1, 1); } //initialize nowtime = -1; //キャラ向きの調整(お互いに向き合う) float tempy = r1.y; r1.y = r0.y; BattleVal.selectedUnit.gobj.transform.LookAt(r1); r0.y = tempy; temp.gobj.transform.LookAt(r0); //行動スタックのクリア(1手戻し不可能に) BattleVal.actions.Clear(); //state undate if (critflag) { bstate = BATTLE_STATUS.EFFECT; //クリティカル攻撃・構えモーション BattleVal.selectedUnit.gobj.GetComponent <Animator>().Play("CriticalPre"); } else { bstate = BATTLE_STATUS.BATTLE; //攻撃モーション開始 BattleVal.selectedUnit.gobj.GetComponent <Animator>().Play("Attack"); } attackedAnimator = temp.gobj.GetComponent <Animator>(); attackedanimstate = "Damage"; if (dodgeflag) { attackedanimstate = "Dodge"; } break; //クリティカル攻撃の演出 case BATTLE_STATUS.EFFECT: //クリティカル攻撃・構えモーションが終了し、音声はなり終わったか? if (BattleVal.selectedUnit.gobj.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime >= 1 && !BattleVal.selectedUnit.gobj.GetComponent <CharaAnimation>().voiceSource.isPlaying && !BattleVal.selectedUnit.gobj.GetComponent <CharaAnimation>().seSource.isPlaying) { //クリティカル攻撃モーションへ BattleVal.selectedUnit.gobj.GetComponent <Animator>().Play("CriticalAttack"); bstate = BATTLE_STATUS.BATTLE; } break; case BATTLE_STATUS.BATTLE: //バトルのアニメーション //ヒット判定で効果音+被ダメージアニメーション if (BattleVal.selectedUnit.gobj.GetComponent <CharaAnimation>().isHit) { attackedAnimator.Play(attackedanimstate); if (attackedanimstate == "Dodge") { Operation.setSE(seDodge); } else { Operation.setSE(seHitN); Vector3 effectpos = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref effectpos, attackedpos[0], attackedpos[1]); hitEffect = Instantiate(BattleVal.selectedUnit.attackeffect, effectpos, BattleVal.selectedUnit.attackeffect.transform.rotation); } //テキスト表示 foreach (Text a in damagenum) { a.gameObject.SetActive(true); } } //攻撃者の攻撃モーションが終わったか? if (!BattleVal.selectedUnit.gobj.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsTag("Attack")) { //ダメージテキストの表示 if (nowtime == -1) { nowtime = 0; } else if (nowtime >= battle_time - Time.deltaTime) { bstate = BATTLE_STATUS.AFTERBATTLE; //ダメージ数値のテキストを消す処理 foreach (Text a in damagenum) { Destroy(a.gameObject); } damagenum.Clear(); //攻撃可能フラグをオフに BattleVal.selectedUnit.atackable = false; } else { //ダメージ数値のテキストを消す処理 //damagetext.color -= new Color(0,0,0,Time.deltaTime); foreach (Text a in damagenum) { a.color -= new Color(0, 0, 0, Time.deltaTime); a.transform.position += new Vector3(0, 1, 0); } nowtime += Time.deltaTime; } } break; //戦闘後処理 case BATTLE_STATUS.AFTERBATTLE: //ヒットエフェクトの消去 Destroy(hitEffect); //獲得経験値 int getexp = 10; //基本値 //撃墜処理 if (BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])].hp <= 0) { Vector3 effectpos = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref effectpos, attackedpos[0], attackedpos[1]); Unitdata unit = BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])]; //撃墜エフェクト StartCoroutine(UnitDefeat.DefeatHandle(unit, defeatEffect, effectpos)); //撃墜ボーナス getexp += BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])].status.needexp; //ユニットデータを消去 ////BattleVal.unitlistから消去 for (int i = 0; i < BattleVal.unitlist.Count; i++) { if (BattleVal.unitlist[i].x == unit.x && BattleVal.unitlist[i].y == unit.y) { BattleVal.unitlist.RemoveAt(i); break; } } ////BattleVal.id2indexから消去 BattleVal.id2index.Remove(string.Format("{0},{1}", unit.x, unit.y)); ////mapdataからユニット情報の削除 BattleVal.mapdata[(int)MapdataList.MAPUNIT][unit.y][unit.x] = 0; } //ユニットセレクトに戻る bstate = BATTLE_STATUS.SETVECT; if (BattleVal.selectedUnit.team == 0) { //経験値を獲得するキャラの場合 if (BattleVal.selectedUnit.status.needexp != 0 && BattleVal.selectedUnit.status.level < 99 && BattleVal.selectedUnit.status.level >= 1) { Operation.AddGetExp(BattleVal.selectedUnit, getexp); BattleVal.status = STATUS.GETEXP; } else { BattleVal.status = STATUS.PLAYER_UNIT_SELECT; } } else { BattleVal.status = STATUS.ENEMY_UNIT_SELECT; } break; } } }
//Update private void Update() { //移動中の場合 if (BattleVal.status == STATUS.MOVING) { switch (mstate) { case MOVING_STATUS.SETVECT: //移動終了の判定 if (nowstep == movepath.Count - 1) { //行動スタックを積む(1手戻し用) if (BattleVal.status == STATUS.MOVING) { Action thisact = new Action(BattleVal.selectedUnit, BattleVal.selectedUnit.x, BattleVal.selectedUnit.y, movepath[nowstep][0], movepath[nowstep][1]); BattleVal.actions.Push(thisact); } //map上のキャラクターIDの更新 //座標情報のアップデート BattleVal.mapdata[(int)MapdataList.MAPUNIT][movepath[nowstep][1]][movepath[nowstep][0]] = BattleVal.mapdata[(int)MapdataList.MAPUNIT][movepath[0][1]][movepath[0][0]]; //移動した場合 if (nowstep != 0) { BattleVal.mapdata[(int)MapdataList.MAPUNIT][movepath[0][1]][movepath[0][0]] = 0; } //BattleVal.selectedUnit.gobj.GetComponent<QuerySDMecanimController>().ChangeAnimation(QuerySDMecanimController.QueryChanSDAnimationType.NORMAL_STAND); BattleVal.selectedUnit.gobj.GetComponent <Animator>().SetBool("Walk", false); BattleVal.selectedUnit.gobj.GetComponent <Animator>().SetBool("Jump", false); BattleVal.selectedUnit.gobj.GetComponent <Animator>().Play("Idle"); BattleVal.selectedUnit.gobj.GetComponent <Animator>().Update(0); BattleVal.selectedUnit.x = movepath[nowstep][0]; BattleVal.selectedUnit.y = movepath[nowstep][1]; //ディクショナリのアップデート BattleVal.id2index.Remove(string.Format("{0},{1}", BattleVal.selectX, BattleVal.selectY)); BattleVal.id2index.Add(string.Format("{0},{1}", movepath[nowstep][0], movepath[nowstep][1]), BattleVal.selectedUnit); //Battleval.statusのアップデート Debug.Log(BattleVal.turnplayer); if (BattleVal.turnplayer == 0) { BattleVal.status = STATUS.PLAYER_UNIT_SELECT; BattleVal.selectX = -1; BattleVal.selectY = -1; } else { BattleVal.status = STATUS.ENEMY_UNIT_SELECT; } //移動可能フラグをオフに BattleVal.selectedUnit.movable = false; break; } //速度ベクトル(実空間)の計算 Vector3 r0 = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r0, movepath[nowstep][0], movepath[nowstep][1]); Vector3 r1 = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r1, movepath[nowstep + 1][0], movepath[nowstep + 1][1]); velocity = (1.0f / steptime) * (r1 - r0); //1マスの移動に0.5sec nowtime = 0; stoptime = 0; if (Mathf.Abs(BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep + 1][1]][movepath[nowstep + 1][0]] - BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep][1]][movepath[nowstep][0]]) > 0) { //ジャンプモーション BattleVal.selectedUnit.gobj.GetComponent <Animator>().Play("Jump"); BattleVal.selectedUnit.gobj.GetComponent <Animator>().SetBool("Walk", false); stoptime = 0.3f; } else { BattleVal.selectedUnit.gobj.GetComponent <Animator>().SetBool("Walk", true); } /* * //もしもジャンプする場合 * if (BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep + 1][1]][movepath[nowstep + 1][0]] - BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep][1]][movepath[nowstep][0]] > 0) * { * //ジャンプモーション * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Walk", false); * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Jump",true); * //BattleVal.selectedUnit.gobj.GetComponent<QuerySDMecanimController>().ChangeAnimation(QuerySDMecanimController.QueryChanSDAnimationType.NORMAL_FLY_UP); * stoptime = 0.3f; * } * else if (BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep + 1][1]][movepath[nowstep + 1][0]] - BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep][1]][movepath[nowstep][0]] < 0) * { * //ジャンプモーション * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Walk", false); * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Jump", true); * * //BattleVal.selectedUnit.gobj.GetComponent<QuerySDMecanimController>().ChangeAnimation(QuerySDMecanimController.QueryChanSDAnimationType.NORMAL_FLY_DOWN); * stoptime = 0.3f; * } * else * { * //歩行モーション * //BattleVal.selectedUnit.gobj.GetComponent<QuerySDMecanimController>().ChangeAnimation(QuerySDMecanimController.QueryChanSDAnimationType.NORMAL_WALK); * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Jump", false); * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Walk", true); * * } */ //キャラの向きの調整 Mapclass.TranslateMapCoordToPosition(ref r1, movepath[nowstep + 1][0], movepath[nowstep + 1][1]); BattleVal.selectedUnit.gobj.transform.LookAt(r1); //mstateのアップデート mstate = MOVING_STATUS.MOVING; break; case MOVING_STATUS.MOVING: //ステップ終了の判定 if (nowtime >= steptime - Time.deltaTime) { if (now_stop_time == 0) { //BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Jump", false); } //終点に表示 if (now_stop_time > stoptime) { r1 = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r1, movepath[nowstep + 1][0], movepath[nowstep + 1][1]); BattleVal.selectedUnit.gobj.transform.position = r1; BattleVal.selectedUnit.gobj.transform.LookAt(new Vector3(r1.x, BattleVal.selectedUnit.gobj.transform.position.y, r1.z)); CameraAngle.CameraPoint(BattleVal.selectedUnit.gobj.transform.position); nowstep++; now_stop_time = 0; mstate = MOVING_STATUS.SETVECT; break; } now_stop_time += Time.deltaTime; nowtime += Time.deltaTime; /* * //終点に表示 * * r1 = new Vector3(); * Mapclass.TranslateMapCoordToPosition(ref r1, movepath[nowstep + 1][0], movepath[nowstep + 1][1]); * BattleVal.selectedUnit.gobj.transform.position = r1; * BattleVal.selectedUnit.gobj.transform.LookAt(new Vector3(r1.x, BattleVal.selectedUnit.gobj.transform.position.y, r1.z)); * CameraAngle.CameraPoint(BattleVal.selectedUnit.gobj.transform.position); * nowstep++; * now_stop_time = 0; * mstate = MOVING_STATUS.SETVECT; * break; */ } else { r1 = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r1, movepath[nowstep + 1][0], movepath[nowstep + 1][1]); BattleVal.selectedUnit.gobj.transform.LookAt(new Vector3(r1.x, BattleVal.selectedUnit.gobj.transform.position.y, r1.z)); //nowtime 加算処理 nowtime += Time.deltaTime; //移動 BattleVal.selectedUnit.gobj.transform.position += new Vector3(velocity.x, 0, velocity.z) * Time.deltaTime; //カメラの移動 CameraAngle.CameraPoint(BattleVal.selectedUnit.gobj.transform.position); if (nowtime < steptime / 2 && velocity.y > 0) { BattleVal.selectedUnit.gobj.transform.position += new Vector3(0, (float)velocity.y * steptime * 60 * nowtime, 0) * Time.deltaTime; } else if (nowtime >= steptime / 2 && velocity.y > 0) { float tempvelocity = (r1.y - BattleVal.selectedUnit.gobj.transform.position.y) / (steptime - nowtime); BattleVal.selectedUnit.gobj.transform.position += new Vector3(0, tempvelocity, 0) * Time.deltaTime; } else if (velocity.y < 0) { BattleVal.selectedUnit.gobj.transform.position += new Vector3(0, velocity.y, 0) * Time.deltaTime; } /* * //モーションチェンジ * * if (nowtime < steptime / 2 && velocity.y > 0) * { * BattleVal.selectedUnit.gobj.transform.position += new Vector3(0, (float)velocity.y * steptime * 60 * nowtime, 0) * Time.deltaTime; * } * else if (nowtime >= steptime / 2 && velocity.y > 0) * { * BattleVal.selectedUnit.gobj.transform.position -= new Vector3(0, (float)(velocity.y * steptime * 16 + Physics.gravity.y) * (nowtime - steptime / 2)) * Time.deltaTime; * } * else if (velocity.y < 0) * { * BattleVal.selectedUnit.gobj.transform.position -= new Vector3(0, (float)(velocity.y * steptime * 8 - Physics.gravity.y) * nowtime - steptime) * Time.deltaTime; * } */ } break; } } }
//位置変更するパーティユニットのタイル色を変更 void SetChangeTile() { UnitChangeTile = Instantiate(UnitChangeTilePrefab, new Vector3(), Quaternion.identity); Mapclass.DrawCharacter(UnitChangeTile, BattleVal.selectX, BattleVal.selectY); }
//Update private void Update() { //戦闘中 if (BattleVal.status == STATUS.USESKILL) { int damage = 0; switch (bstate) { case BATTLE_STATUS.SETVECT: //キャラの向き調整;攻撃元が発動場所を向く Vector3 r0 = new Vector3(); //攻撃元 Vector3 rSkill = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r0, BattleVal.selectX, BattleVal.selectY); Mapclass.TranslateMapCoordToPosition(ref rSkill, skillpos[0], skillpos[1]); rSkill.y = r0.y; BattleVal.selectedUnit.gobj.transform.LookAt(rSkill); /* * //攻撃対象 * foreach (int[] attackedpos in attackedposlist) * { * Vector3 r1 = new Vector3(); //攻撃先 * Mapclass.TranslateMapCoordToPosition(ref r1, attackedpos[0], attackedpos[1]); * Unitdata temp = BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])]; * damage = Calc_Damage(BattleVal.selectedUnit, temp); * * temp.hp -= damage; //ダメージ処理 * * string damagetext = string.Format("{0}", (int)Mathf.Abs(damage)); * int count = 1; * //ダメージテキストの中心座標 * Vector3 damage_center = Camera.main.WorldToScreenPoint(r1); * * //テキストの登録 * List<Text> damagenumtmp = new List<Text>(); * foreach (char a in damagetext) * { * int num = (int)char.GetNumericValue(a); //数を取得 * * damagenumtmp.Add(Instantiate(damagetextprefab, r1, Quaternion.identity)); * damagenumtmp[count - 1].text = a.ToString(); * //サイズ取得 * damagenumtmp[count - 1].rectTransform.sizeDelta = * new Vector2(damagenumtmp[count - 1].preferredWidth, damagenumtmp[count - 1].preferredHeight); * damagenumtmp[count - 1].rectTransform.sizeDelta = * new Vector2(damagenumtmp[count - 1].preferredWidth, damagenumtmp[count - 1].preferredHeight); * damagenumtmp[count - 1].transform.SetParent(canvas.transform, false); * damagenumtmp[count - 1].transform.localPosition = damage_center - new Vector3(canvas.GetComponent<RectTransform>().sizeDelta.x / 2, canvas.GetComponent<RectTransform>().sizeDelta.y / 2, 0); * * //1桁当たりの文字ブロック * Vector3 numsize = damagenumtmp[count - 1].GetComponent<RectTransform>().sizeDelta * damagenumtmp[count - 1].GetComponent<RectTransform>().localScale; * numsize.y = 0; * numsize.z = 0; * * damagenumtmp[count - 1].transform.localPosition += (count - 1) * numsize; * damagenumtmp[count - 1].transform.localPosition += new Vector3(0, 30, 0); * damagenumtmp[count - 1].color = new Vector4(1, 0, 0, 1); * if (damage < 0) damagenumtmp[count - 1].color = new Vector4(0.7f,1,0.7f,1); * damagenumtmp[count - 1].gameObject.SetActive(false); * count++; * * } * damagenum.Add(damagenumtmp); * * //アニメーション設定 * attackedAnimator.Add(temp.gobj.GetComponent<Animator>()); * if(damage > 0) * attackedanimstate.Add(hitAnimName); //共通モーションだと思うが、一部キャラで回復・ダメージが混ざる将来性も加味する * else * attackedanimstate.Add(healAnimName); //暫定 Healモーションも作る * attackedCharaAnimation.Add(temp.gobj.GetComponent<CharaAnimation>()); * } */ nowtime = -1; //initialize //スキルの消費 selectedskill.Consume(1); //行動スタックのクリア(1手戻し不可能に) BattleVal.actions.Clear(); //カットイン演出の場合 if (selectedskill.is_cutscene) { gobjCutin = Instantiate(selectedskill.prefab_cutin); bstate = BATTLE_STATUS.CUTIN; } else { //通常スキルの場合 //スキル使用モーション再生 BattleVal.selectedUnit.gobj.GetComponent <Animator>().Play(selectedskill.animname); //state update bstate = BATTLE_STATUS.EFFECT; skilltext.text = selectedskill.skillname; skillnamePanel.SetActive(true); } break; case BATTLE_STATUS.CUTIN: if (gobjCutin.GetComponent <CutinChecker>().cutinFinish) { Destroy(gobjCutin); //スキル使用モーション再生 BattleVal.selectedUnit.gobj.GetComponent <Animator>().Play(selectedskill.animname); //state update bstate = BATTLE_STATUS.EFFECT; skilltext.text = selectedskill.skillname; skillnamePanel.SetActive(true); } break; case BATTLE_STATUS.EFFECT: //スキル使用モーションが終了し、音声はなり終わったか? /* * if (BattleVal.selectedUnit.gobj.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime >= 1 * && !BattleVal.selectedUnit.gobj.GetComponent<CharaAnimation>().voiceSource.isPlaying * && !BattleVal.selectedUnit.gobj.GetComponent<CharaAnimation>().seSource.isPlaying) */ if (!BattleVal.selectedUnit.gobj.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).shortNameHash.Equals(Animator.StringToHash(selectedskill.animname)) && !BattleVal.selectedUnit.gobj.GetComponent <CharaAnimation>().voiceSource.isPlaying && !BattleVal.selectedUnit.gobj.GetComponent <CharaAnimation>().seSource.isPlaying) { Vector3 effectcampoint = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref effectcampoint, skillpos[0], skillpos[1]); CameraAngle.CameraPoint(effectcampoint); //エフェクト再生へ Vector3 reffect = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref reffect, skillpos[0], skillpos[1]); hitEffect = Instantiate(selectedskill.skillefect, reffect, selectedskill.skillefect.transform.rotation); bstate = BATTLE_STATUS.BATTLE; } break; case BATTLE_STATUS.BATTLE: //バトルのアニメーション //エフェクトの再生が終了したか? if (hitEffect == null) { //被弾モーション再生 if (nowtime == -1) { //攻撃対象 foreach (int[] attackedpos in attackedposlist) { Vector3 r1 = new Vector3(); //攻撃先 Mapclass.TranslateMapCoordToPosition(ref r1, attackedpos[0], attackedpos[1]); Unitdata temp = BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])]; damage = Calc_Damage(BattleVal.selectedUnit, temp); temp.hp -= damage; //ダメージ処理 string damagetext = string.Format("{0}", (int)Mathf.Abs(damage)); int count = 1; //ダメージテキストの中心座標 Vector3 damage_center = Camera.main.WorldToScreenPoint(r1); //テキストの登録 List <Text> damagenumtmp = new List <Text>(); foreach (char a in damagetext) { int num = (int)char.GetNumericValue(a); //数を取得 damagenumtmp.Add(Instantiate(damagetextprefab, r1, Quaternion.identity)); damagenumtmp[count - 1].text = a.ToString(); //サイズ取得 damagenumtmp[count - 1].rectTransform.sizeDelta = new Vector2(damagenumtmp[count - 1].preferredWidth, damagenumtmp[count - 1].preferredHeight); damagenumtmp[count - 1].rectTransform.sizeDelta = new Vector2(damagenumtmp[count - 1].preferredWidth, damagenumtmp[count - 1].preferredHeight); damagenumtmp[count - 1].transform.SetParent(canvas.transform, false); damagenumtmp[count - 1].transform.localPosition = damage_center - new Vector3(canvas.GetComponent <RectTransform>().sizeDelta.x / 2, canvas.GetComponent <RectTransform>().sizeDelta.y / 2, 0); //1桁当たりの文字ブロック Vector3 numsize = damagenumtmp[count - 1].GetComponent <RectTransform>().sizeDelta *damagenumtmp[count - 1].GetComponent <RectTransform>().localScale; numsize.y = 0; numsize.z = 0; damagenumtmp[count - 1].transform.localPosition += (count - 1) * numsize; damagenumtmp[count - 1].transform.localPosition += new Vector3(0, 30, 0); damagenumtmp[count - 1].color = new Vector4(1, 0, 0, 1); if (damage < 0) { damagenumtmp[count - 1].color = new Vector4(0.7f, 1, 0.7f, 1); } damagenumtmp[count - 1].gameObject.SetActive(false); count++; } damagenum.Add(damagenumtmp); //アニメーション設定 attackedAnimator.Add(temp.gobj.GetComponent <Animator>()); if (damage > 0) { attackedanimstate.Add(hitAnimName); //共通モーションだと思うが、一部キャラで回復・ダメージが混ざる将来性も加味する } else { attackedanimstate.Add(healAnimName); //暫定 Healモーションも作る } attackedCharaAnimation.Add(temp.gobj.GetComponent <CharaAnimation>()); } for (int i = 0; i < attackedAnimator.Count; i++) { //Count不一致するかも? attackedAnimator[i].Play(attackedanimstate[i]); if (attackedanimstate[i] == hitAnimName) { attackedCharaAnimation[i].seSource.clip = seDamage; } else { attackedCharaAnimation[i].seSource.clip = seHeal; } attackedCharaAnimation[i].seSource.Play(); } //テキスト表示 foreach (List <Text> damagenumtmp in damagenum) { foreach (Text a in damagenumtmp) { a.gameObject.SetActive(true); } //CameraAngle.CameraPoint(BattleVal.selectedUnit.gobj.transform.position); } nowtime = 0; } else if (nowtime >= battle_time - Time.deltaTime) { //戦闘後処理 bstate = BATTLE_STATUS.AFTERBATTLE; //ダメージ数値のテキストを消す処理 foreach (List <Text> damagenumtmp in damagenum) { foreach (Text a in damagenumtmp) { Destroy(a.gameObject); } } //戦闘用のダメージ表示などの判定が終了した後に、カメラの位置の移動 CameraAngle.CameraPoint(BattleVal.selectedUnit.gobj.transform.position); //アニメーション関連の初期化 attackedAnimator.Clear(); attackedanimstate.Clear(); attackedCharaAnimation.Clear(); damagenum.Clear(); skillnamePanel.SetActive(false); //攻撃可能フラグをオフに BattleVal.selectedUnit.atackable = false; } else { //ダメージ数値のテキストを消す処理 //damagetext.color -= new Color(0,0,0,Time.deltaTime); foreach (List <Text> damagenumtmp in damagenum) { foreach (Text a in damagenumtmp) { a.color -= new Color(0, 0, 0, Time.deltaTime); a.transform.position += new Vector3(0, 1, 0); } } nowtime += Time.deltaTime; } } break; //戦闘後処理 case BATTLE_STATUS.AFTERBATTLE: //獲得経験値 int getexp = 10; //基本値 //撃墜処理 foreach (int[] attackedpos in attackedposlist) { Unitdata temp = BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])]; //撃墜処理 if (temp.hp <= 0) { Vector3 defeatpos = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref defeatpos, attackedpos[0], attackedpos[1]); StartCoroutine(UnitDefeat.DefeatHandle(temp, defeatEffect, defeatpos)); //撃墜ボーナス getexp += BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])].status.needexp; //ユニットデータを消去 ////BattleVal.unitlistから消去 for (int i = 0; i < BattleVal.unitlist.Count; i++) { if (BattleVal.unitlist[i].x == temp.x && BattleVal.unitlist[i].y == temp.y) { BattleVal.unitlist.RemoveAt(i); break; } } ////BattleVal.id2indexから消去 BattleVal.id2index.Remove(string.Format("{0},{1}", temp.x, temp.y)); ////mapdataからユニット情報の削除 BattleVal.mapdata[(int)MapdataList.MAPUNIT][temp.y][temp.x] = 0; } if (temp.hp > temp.status.maxhp) { temp.hp = temp.status.maxhp; } } //必殺技の場合、獲得経験値が1.5倍ボーナス if (selectedskill.is_cutscene) { getexp = (int)((float)getexp * 1.5f); } //ユニットセレクトに戻る bstate = BATTLE_STATUS.SETVECT; if (BattleVal.selectedUnit.team == 0) { //経験値を獲得するキャラの場合 if (BattleVal.selectedUnit.status.needexp != 0 && BattleVal.selectedUnit.status.level < 99 && BattleVal.selectedUnit.status.level >= 1) { Operation.AddGetExp(BattleVal.selectedUnit, getexp); BattleVal.status = STATUS.GETEXP; } else { BattleVal.status = STATUS.PLAYER_UNIT_SELECT; } } else { BattleVal.status = STATUS.ENEMY_UNIT_SELECT; } break; } } else { } }