// Start is called before the first frame update //在sense加载最开始调用 private void Awake() { //获取双方对战数据,生成battleData //该部分数据直接在这里生成要用于测试 //否则应该是从database中读取或者通过网络接收 List <int[]> myList = new List <int[]>(); List <int[]> opList = new List <int[]>(); myList.Add(new int[7] { 2, 0, 0, 0, 0, 0, 0 }); myList.Add(new int[7] { 2, 1, 0, 0, 0, 0, 0 }); myList.Add(new int[7] { 2, 2, 0, 0, 0, 0, 0 }); myList.Add(new int[7] { 1, 0, 1, 0, 0, 0, 0 }); myList.Add(new int[7] { 3, 2, 1, 0, 0, 0, 0 }); myList.Add(new int[7] { 3, 0, 2, 0, 0, 0, 0 }); myList.Add(new int[7] { 3, 1, 2, 0, 0, 0, 0 }); opList.Add(new int[7] { 2, 0, 0, 0, 0, 0, 0 }); opList.Add(new int[7] { 2, 1, 0, 0, 0, 0, 0 }); opList.Add(new int[7] { 1, 0, 1, 0, 0, 0, 0 }); opList.Add(new int[7] { 3, 1, 1, 0, 0, 0, 0 }); opList.Add(new int[7] { 3, 2, 1, 0, 0, 0, 0 }); opList.Add(new int[7] { 1, 0, 2, 0, 0, 0, 0 }); opList.Add(new int[7] { 1, 2, 2, 0, 0, 0, 0 }); battle_data bd = new battle_data(myList, opList); //家在数据到controller中 controller.Instance.Initial(bd); //开始战斗流程 controller.Instance.Start_Animation(); }
//行动,轮到角色行动时调用此方法 public List <int> Action(battle_data battleData) { Vector3Int location = Get_location(); this.battleData = battleData; _msg.Clear(); _msg.Add(location.x); _msg.Add(location.y); _msg.Add(location.z); if (_mp < 100) //怒气小于100普攻,否则skill { _msg.Add(0); Attack(Count_critic()); Modify_mp(25); //普攻怒气加25 } else { _msg.Add(1); Skill(Count_critic()); Modify_mp(0); } Check_buff_remain(); //skill后怒气归零 return(_msg); }
//被动:行动结束后给全体活着友方0.5倍攻击力的治疗量 public override List <int> Action(battle_data battleData) { List <int> msg = base.Action(battleData); List <Character> friends = Get_target(true); foreach (Character friend in friends) { friend.Get_heal(Heal(0.5 * Count_atk())); } return(msg); }
//获取攻击目标 //一般来说isskill没什么用,但如果技能和平A攻击范围不同时有用 //面对范围攻击的情况,此处返回值修改为list public List <Character> Get_target(bool skill) //TODO { List <Character> list = new List <Character>(); Vector3Int location = Get_location(); //设置battleData if (battleData == null) { battleData = controller.Instance.battleData; } Character[,,] enemies = battleData.GetCharacterList(); Character enemy; int enemyGroup = location[0] == 0? 1 : 0; for (int i = 0; i < 3; i++) { //检测当前位置有没有东西 if (!battleData.hasCharacterInGrid(enemyGroup, location.y, i)) { continue; } enemy = enemies[enemyGroup, location.y, i]; if (enemy._hp > 0) { list.Add(enemy); return(list); } } for (int i = 0; i < 3; i++) { if (i != location.y) { for (int j = 0; j < 3; j++) { //检测当前位置有没有东西 if (!battleData.hasCharacterInGrid(enemyGroup, i, j)) { continue; } enemy = enemies[enemyGroup, i, j]; if (enemy._hp > 0) { list.Add(enemy); return(list); } } } } return(null); }
// Start is called before the first frame update //在sense加载最开始调用 private void Awake() { //获取双方对战数据,生成battleData //该部分数据直接在这里生成要用于测试 //否则应该是从database中读取或者通过网络接收 List <int[]> myList = new List <int[]>(); List <int[]> opList = new List <int[]>(); battleResult.OnHide(); /*myList.Add(new int[7]{2,0,0,0,0,0,0}); * myList.Add(new int[7]{2,1,0,0,0,0,0}); * myList.Add(new int[7]{2,2,0,0,0,0,0}); * myList.Add(new int[7]{1,0,1,0,0,0,0}); * myList.Add(new int[7]{3,2,1,0,0,0,0}); * myList.Add(new int[7]{3,0,2,0,0,0,0}); * myList.Add(new int[7]{3,1,2,0,0,0,0});*/ SceneData sc = GameObject.Find("SceneData").GetComponent <SceneData>(); myList = sc.MyList; opList = sc.OpList; /*opList.Add(new int[7]{2,0,0,0,0,0,0}); * opList.Add(new int[7]{2,1,0,0,0,0,0}); * opList.Add(new int[7]{1,0,1,0,0,0,0}); * opList.Add(new int[7]{3,1,1,0,0,0,0}); * opList.Add(new int[7]{3,2,1,0,0,0,0}); * opList.Add(new int[7]{1,0,2,0,0,0,0}); * opList.Add(new int[7]{1,2,2,0,0,0,0});*/ //由scenedata决定生成battledata还是服务器下发 battle_data bd; if (sc.isClientCompute) { bd = new battle_data(myList, opList); } else { bd = new battle_data(myList, opList, sc.battleDataList); } //家在数据到controller中 controller.Instance.Initial(bd); //开始战斗流程 controller.Instance.Start_Animation(); }
//初始化controller public void Initial(battle_data battleData)//battle_data battleData) { //清空gridunits中所有格子里的单位 for (int i = 0; i < 2; i++) { for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { gridUnits[i * 9 + x * 3 + y].initial(new Vector3Int(i, x, y)); } } } this.battleData = battleData; //把单位放到格子里面 loadPrefab(); SetPrefabsActive(); }
/* * 以下为能够被重载的方法 */ //行动,轮到角色行动时调用此方法 public virtual List <int> Action(battle_data battleData) { Vector3Int location = Get_location(); this.battleData = battleData; _msg = new List <int>(); _msg.Clear(); _msg.Add(location.x); _msg.Add(location.y); _msg.Add(location.z); //检测沉默 bool silent = false; foreach (Buff buff in _buffs) { if (buff._buffKind == BuffKind.Silence) { silent = true; break; } } if (_mp < _skillMp || silent) //怒气小于100或沉默状态下普攻,否则skill { _msg.Add(0); Attack(Count_critic()); } else { _msg.Add(1); Skill(Count_critic()); } Check_buff_remain(); //减少buff持续时间1回合 return(_msg); }
//被动:行动结束后友方攻击力最高的攻击力加40%,持续1回合 public override List <int> Action(battle_data battleData) { List <int> msg = base.Action(battleData); if (battleData == null) { battleData = controller.Instance.battleData; } Character[,,] enemies = battleData.GetCharacterList(); Character friend; Character target = this; //检测攻击力最高的 int f = Get_location()[0]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (!battleData.hasCharacterInGrid(f, i, j)) { continue; } friend = enemies[f, i, j]; if (friend._hp > 0 && friend._atk > target._atk) { target = friend; } } } //给攻击力最高的上buff target.Get_buff(new Buff(BuffKind.Atk, 40, true, 1)); return(msg); }
//获取攻击目标 //一般来说isskill没什么用,但如果技能和平A攻击范围不同时有用 //面对范围攻击的情况,此处返回值修改为list public virtual List <Character> Get_target(bool skill) { List <Character> list = new List <Character>(); Vector3Int location = Get_location(); //设置battleData if (battleData == null) { battleData = controller.Instance.battleData; } Character[,,] enemies = battleData.GetCharacterList(); Character enemy; int enemyGroup = location[0] == 0 ? 1 : 0; //检测嘲讽 for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (!battleData.hasCharacterInGrid(enemyGroup, i, j)) { continue; } enemy = enemies[enemyGroup, i, j]; if (enemy._hp > 0) { //检测嘲讽 foreach (Buff buff in enemy._buffs) { if (buff._buffKind == BuffKind.Taunt) { list.Add(enemy); return(list); } } } } } //优先打本列的 for (int i = 0; i < 3; i++) { //检测当前位置有没有东西 if (!battleData.hasCharacterInGrid(enemyGroup, location.y, i)) { continue; } enemy = enemies[enemyGroup, location.y, i]; if (enemy._hp > 0) { list.Add(enemy); return(list); } } //没有本列的,优先打近的那一列 for (int i = (location.y == 2 ? 2 : 0), step = (location.y == 2 ? -1 : 1); i < 3 && i >= 0; i += step) { if (i != location.y) { for (int j = 0; j < 3; j++) { //检测当前位置有没有东西 if (!battleData.hasCharacterInGrid(enemyGroup, i, j)) { continue; } enemy = enemies[enemyGroup, i, j]; if (enemy._hp > 0) { list.Add(enemy); return(list); } } } } return(null); }