/// <summary> /// 根据攻击者和被攻击的攻击优先级列表生成对应的伤害请求list /// </summary> /// <param name="DamageRequestList">被填充的伤害请求list</param> /// <param name="Attacker">攻击者</param> /// <param name="AttackedUnit">被攻击者</param> public static List <DamageRequest> CaculateDamageRequestList(GameUnit.GameUnit Attacker, GameUnit.GameUnit AttackedUnit) { List <DamageRequest> damageRequestList = new List <DamageRequest>(); for (int i = 0; i < Attacker.priority.Count; i++) { damageRequestList.Add(new DamageRequest(Attacker, AttackedUnit, Attacker.priority[i])); } for (int i = 0; i < AttackedUnit.priority.Count; i++) { damageRequestList.Add(new DamageRequest(AttackedUnit, Attacker, AttackedUnit.priority[i])); } damageRequestList.Sort((a, b) => { if (a.priority < b.priority) { return(1); } else if (a.priority == b.priority) { return(0); } else { return(-1); } }); return(damageRequestList); }
// Use this for initialization void Start() { unit = null; vector = GetSelfPosition(); hasUnit = false; hasRetard = false; }
//TODO: 添加判断是否处于遭遇战以使用遭遇战胜利条件判断 //TODO: 等待胜利条件指定单位及战区接口 #region 遭遇战胜利条件 // 胜利条件先这样写着吧,胜利条件看的有点迷迷糊糊 // 里面的指定单位和战区都是遭遇战里面的吧,先空着等待接口 /// <summary> /// 护送某单位到指定战区 /// 判断单位位置是否在指定战区范围内 /// 己方单位先到战区则胜利 /// 敌方单位先到战区则失败 /// 都没到但是己方单位死亡也失败 /// </summary> public void EscortUnitToArea() { //TODO: 获取进入遭遇战后指定单位接口 const int success = 0; const int failure = 1; const int notUnit = -1; GameUnit.GameUnit player = null; // 被护送单位 GameUnit.GameUnit enemy = null; // 敌方单位 int AreaID = 0; // 指定战区id BattleMap.BattleMap battleMap = BattleMap.BattleMap.Instance(); // if (_battleAreaDictionary[AreaID].Contains(currentPos)) // 到达指定战区 // { // Gameplay.Instance().roundProcessController.Win(); // } // else if(player.IsDead()) // 未到达指定战区且死亡则失败 // { // Gameplay.Instance().roundProcessController.Lose(); // } if (battleMap.ProjectUnit(AreaID, player, enemy) == success) { Gameplay.Instance().roundProcessController.Win(); } else if (battleMap.ProjectUnit(AreaID, player, enemy) == failure) { Gameplay.Instance().roundProcessController.Lose(); } if (battleMap.ProjectUnit(AreaID, player, enemy) == notUnit && player.IsDead()) { Gameplay.Instance().roundProcessController.Lose(); } }
public override void OnPointerDownEnemy(GameUnit.GameUnit unit, PointerEventData eventData) { base.OnPointerDownEnemy(unit, eventData); //获取攻击者和被攻击者 GameUnit.GameUnit Attacker = BattleMap.BattleMap.Instance().GetUnitsOnMapBlock(FSM.TargetList[FSM.TargetList.Count - 1]); GameUnit.GameUnit AttackedUnit = unit; //创建攻击指令 UnitAttackCommand unitAtk = new UnitAttackCommand(Attacker, AttackedUnit); //如果攻击指令符合条件则执行 if (unitAtk.Judge()) { GameUtility.UtilityHelper.Log("触发攻击", GameUtility.LogColor.RED); FSM.HandleAtkCancel(BattleMap.BattleMap.Instance().GetUnitCoordinate(Attacker)); ////攻击完工攻击范围隐藏 unitAtk.Excute(); Attacker.disarm = true; //单位横置不能攻击 FSM.TargetList.Clear(); //清空对象列表 FSM.PushState(new InputFSMIdleState(FSM)); //状态机压入静止状态 } else { //如果攻击指令不符合条件就什么都不做 } }
public override void OnPointerDownBlock(BattleMapBlock mapBlock, PointerEventData eventData) { base.OnPointerDownBlock(mapBlock, eventData); //获取第一个选择的对象 GameUnit.GameUnit unit = BattleMap.BattleMap.Instance().GetUnitsOnMapBlock(FSM.TargetList[0]); //创建移动指令 Vector2 startPos = FSM.TargetList[0]; Vector2 endPos = mapBlock.position; UnitMoveCommand unitMove = new UnitMoveCommand(unit, startPos, endPos, mapBlock.GetSelfPosition()); //如果移动指令合法 if (unitMove.Judge()) { //移动完毕关闭移动范围染色 Vector2 pos = BattleMap.BattleMap.Instance().GetUnitCoordinate(unit); FSM.HandleMovCancel(pos); GameUtility.UtilityHelper.Log("移动完成,进入攻击状态,点击敌人进行攻击,右键点击角色取消攻击", GameUtility.LogColor.RED); unitMove.Excute(); //清空对象列表 //FSM.TargetList.Clear(); FSM.TargetList.Add(endPos); //unit.restrain = true; FSM.PushState(new InputFSMAttackState(FSM));//状态机压入新的攻击状态 } else { //如果不符合移动条件,什么都不做 } }
private bool hasBurined; //保证单位进入灼烧块只受到一次伤害 private void Start() { vector = GetSelfPosition(); unit = null; hasUnit = false; hasBurined = false; }
/// <summary> /// 更新血条HP /// </summary> /// <param name="attackedUnit">受攻击单位</param> internal void UpdateHp(GameUnit.GameUnit attackedUnit) { float hpDivMaxHp = (float)attackedUnit.hp / attackedUnit.MaxHP * 100; var textHp = attackedUnit.transform.GetComponentInChildren <Text>(); textHp.text = string.Format("Hp: {0}%", Mathf.Ceil(hpDivMaxHp)); }
/// <summary> /// 单位回收 /// </summary> /// <param name="deadUnit"></param> internal void UnitBackPool(GameUnit.GameUnit deadUnit) { //回收单位 GameUnitPool.Instance().PushUnit(deadUnit.gameObject); //移除对应地图块儿下的死亡单位 BattleMap.BattleMap.Instance().RemoveUnitOnBlock(deadUnit); }
//处理滞泻 private void Retard(Unit unit) { if (hasUnit == true) { unit.mov = 0; hasRetard = true; } }
//处理灼烧 private void Burning(Unit unit) { if (hasUnit == true && hasBurined == false) { unit.hp -= 1; hasBurined = true; } }
/// <summary> /// AI移动 /// 一格一格移动处理函数 /// </summary> /// <returns></returns> public IEnumerator moveStepByStepAI(Unit unit, List <Vector2> paths, System.Action callback) { #region 测试一哈 先固定(0.0)为灼烧块,(0.1)为粘滞块 List <Vector2> vector2s = new List <Vector2>(); vector2s.Add(new Vector2(0, 0)); BattleMap.Instance().debuffBM.SetBattleMapBlockBurning(vector2s); List <Vector2> vector22s = new List <Vector2>(); vector22s.Add(new Vector2(1, 1)); BattleMap.Instance().debuffBM.SetBattleMapBlockRetrad(vector22s); #endregion Vector2 tempVector; BattleMapBlock battleMap; bool isRetire = false; for (int i = paths.Count - 2; i >= 0; i--) { //移除上一步的地图块儿下面的units_on_me tempVector = new Vector2((int)paths[i + 1].x, (int)paths[i + 1].y); battleMap = BattleMap.Instance().GetSpecificMapBlock(tempVector); battleMap.RemoveUnit(unit); //添加当前unit到地图块儿下面的units_on_me内 tempVector = new Vector2((int)paths[i].x, (int)paths[i].y); battleMap = BattleMap.Instance().GetSpecificMapBlock(tempVector); if (i != 0) { battleMap.AddUnit(unit); } else { battleMap.AddUnit(unit, false); } unit.transform.localPosition = Vector3.zero; if (battleMap.blockType == EMapBlockType.Burnning)//如果经过灼烧块 { BattleMap.Instance().debuffBM.UnitEnterBurning(tempVector); } else if (battleMap.blockType == EMapBlockType.Retire)//如果经过滞留块 { BattleMap.Instance().debuffBM.UnitEnterRetire(unit, battleMap); unit.nextPos = paths[i]; MsgDispatcher.SendMsg((int)MessageType.Aftermove); isRetire = true; break; } unit.nextPos = paths[i]; MsgDispatcher.SendMsg((int)MessageType.Move); yield return(new WaitForSeconds(0.4f)); } if (isRetire == false) { MsgDispatcher.SendMsg((int)MessageType.Aftermove); } if (callback != null) { callback(); } }
//技能可释放范围染色 public void HandleSkillConfim(Vector2 target, int range) { BattleMap.BattleMap map = BattleMap.BattleMap.Instance(); if (map.CheckIfHasUnits(target)) { GameUnit.GameUnit unit = BattleMap.BattleMap.Instance().GetUnitsOnMapBlock(target); unit.GetComponent <ShowRange>().MarkSkillRange(target, range); } }
public void HandleCancle() { if (TargetList.Count == 1) { GameUnit.GameUnit unit = BattleMapManager.BattleMapManager.getInstance().GetUnitsOnMapBlock(TargetList[0]); unit.GetComponent <ShowRange>().CancleAttackRangeMark(); unit.GetComponent <ShowRange>().CancleMoveRangeMark(); TargetList.Clear(); } }
/// <summary> /// 移除BattleBlock下的 unit /// </summary> public void RemoveUnitOnBlock(Unit deadUnit) { //获取死亡单位的Pos Vector2 unitPos = GetUnitCoordinate(deadUnit); //通过unitPos的坐标获取对应的地图块儿 BattleMapBlock battleMap = GetSpecificMapBlock(unitPos); //移除对应地图块儿下的deadUnit battleMap.units_on_me.Remove(deadUnit); }
/// <summary> /// 根据给定unit寻找其所处坐标,若找不到则会返回不合法坐标 /// </summary> /// <param name="unit"></param> /// <returns></returns> public Vector3 GetUnitCoordinate(Unit unit) { foreach (Unit gameUnit in _unitsList) { if (gameUnit == unit) { return(gameUnit.mapBlockBelow.GetCoordinate()); } } return(new Vector3(-1, -1, -1)); }
//取消可释放技能范围染色 public void HandleSkillCancel(Vector2 target, int range) { GameUnit.GameUnit unit = null; if (BattleMap.BattleMap.Instance().CheckIfHasUnits(target)) { unit = BattleMap.BattleMap.Instance().GetUnitsOnMapBlock(target); } else { //unit = BeforeMoveGameUnits[0]; } unit.GetComponent <ShowRange>().CancleSkillRangeMark(InputFSM.TargetList[0], range); }
/// <summary> /// 自动攻击 /// </summary> protected override void AutoUseAtk() { //TODO 异能引入后进行修改 //异能为引入前版本 //获取攻击者和被攻击者 GameUnit.GameUnit Attacker = battleUnit; GameUnit.GameUnit AttackedUnit = targetBattleUnit; //创建攻击指令 UnitAttackCommand unitAtk = new UnitAttackCommand(Attacker, AttackedUnit); unitAtk.Excute();//已经判断过距离,放心攻击 }
/// <summary> /// 击杀指定单位,指定单位死亡则胜利,否则失败 /// </summary> public void KillSpecifyUnit() { GameUnit.GameUnit BeKilledUnit = null; // 指定被击杀单位 //TODO:获取指定的单位的引用,等待接口 if (BeKilledUnit.IsDead()) { Gameplay.Instance().roundProcessController.Win(); } else { Gameplay.Instance().roundProcessController.Lose(); } }
/// <summary> /// 判断A星算法给出的路径是否超过单位行动力 /// </summary> /// <param name="unit">当前控制单位</param> /// <returns></returns> private bool IsExcessUnitMove() { Vector2 startPos = paths[paths.Count - 1].position; Unit gameUnit = BattleMap.Instance().GetUnitsOnMapBlock(startPos); Debug.Log(gameUnit.name + "行动力为 " + gameUnit.mov); if (paths.Count - 1 > gameUnit.mov) { Debug.Log("超过移动力,无法移动到指定目标"); return(true); } return(false); }
public void HandleConfirm(Vector2 target) { BattleMapManager.BattleMapManager mapManager = BattleMapManager.BattleMapManager.getInstance(); if (TargetList.Count == 0) { if (mapManager.CheckIfHasUnits(target)) { TargetList.Add(target); GameUnit.GameUnit unit = BattleMapManager.BattleMapManager.getInstance().GetUnitsOnMapBlock(TargetList[0]); unit.GetComponent <ShowRange>().MarkMoveRange(); unit.GetComponent <ShowRange>().MarkAttackRange(); } } else if (TargetList.Count == 1) { if (mapManager.CheckIfHasUnits(target)) { //TargetList.Add(target); GameUnit.GameUnit unit1 = mapManager.GetUnitsOnMapBlock(TargetList[0]); //GameUnit.GameUnit unit2 = mapManager.GetUnitsOnMapBlock(TargetList[1])[0]; GameUnit.GameUnit unit2 = mapManager.GetUnitsOnMapBlock(target); UnitAttackCommand attackCommand = new UnitAttackCommand(unit1, unit2); if (attackCommand.Judge()) { //关闭染色 unit1.GetComponent <ShowRange>().CancleAttackRangeMark(); unit1.GetComponent <ShowRange>().CancleMoveRangeMark(); attackCommand.Excute(); TargetList.Clear(); } } else { //TargetList.Add(target); GameUnit.GameUnit unit1 = mapManager.GetUnitsOnMapBlock(TargetList[0]); Vector2 unit2 = target; UnitMoveCommand moveCommand = new UnitMoveCommand(unit1, unit2); if (moveCommand.Judge()) { //关闭染色 unit1.GetComponent <ShowRange>().CancleAttackRangeMark(); unit1.GetComponent <ShowRange>().CancleMoveRangeMark(); moveCommand.Excute(); TargetList.Clear(); } } } }
public override void OnPointerDownFriendly(GameUnit.GameUnit unit, PointerEventData eventData) { base.OnPointerDownFriendly(unit, eventData); //鼠标右键取消攻击 if (eventData.button == PointerEventData.InputButton.Right) { GameUtility.UtilityHelper.Log("取消攻击", GameUtility.LogColor.RED); FSM.HandleAtkCancel(BattleMap.BattleMap.Instance().GetUnitCoordinate(unit)); unit.restrain = true; unit.disarm = true; FSM.TargetList.Clear(); FSM.PushState(new InputFSMIdleState(FSM)); } }
public override void OnPointerDownEnemy(GameUnit.GameUnit unit, PointerEventData eventData) { base.OnPointerDownEnemy(unit, eventData); if ((FSM.ability.AbilityTargetList[FSM.TargetList.Count].TargetType == Ability.TargetType.Enemy) || (FSM.ability.AbilityTargetList[FSM.TargetList.Count].TargetType == Ability.TargetType.All)) { FSM.TargetList.Add(BattleMap.BattleMap.Instance().GetUnitCoordinate(unit)); } //如果已经选够了目标就发动卡片 //这里应该让Card那边写个发动卡片的函数,写在Input里不科学 if (FSM.TargetList.Count == FSM.ability.AbilityTargetList.Count) { Gameplay.Info.CastingCard = FSM.ability.GetComponent <OrderCard>(); CardManager.Instance().OnTriggerCurrentCard(); } }
/// <summary> /// AI移动 /// </summary> /// <param name="unit">目标单位</param> /// <param name="targetPosition">最优路径</param> /// <param name="callback">攻击回调</param> /// <returns></returns> public bool AIMoveUnitToCoordinate(Unit unit, List <Vector2> targetPosition, System.Action callback) { foreach (Unit gameUnit in _unitsList) { if (gameUnit == unit) { unit.mapBlockBelow.RemoveUnit(unit); if (_mapBlocks[(int)targetPosition[0].x, (int)targetPosition[0].y] != null) { unit.mapBlockBelow = _mapBlocks[(int)targetPosition[0].x, (int)targetPosition[0].y]; } StartCoroutine(MapNavigator.moveStepByStepAI(unit, targetPosition, callback)); return(true); } } return(false); }
/// <summary> /// 传入unit和坐标,将Unit瞬间移动到该坐标(仅做坐标变更,不做其他处理) /// <param name="unit">移动的目标单位</param> /// <param name="gameobjectCoordinate">地图块儿自身的物体坐标</param> /// <returns></returns> /// </summary> public bool MoveUnitToCoordinate(Unit unit, Vector2 gameobjectCoordinate) { foreach (Unit gameUnit in _unitsList) { if (gameUnit == unit) { unit.mapBlockBelow.RemoveUnit(unit); if (_mapBlocks[(int)gameobjectCoordinate.x, (int)gameobjectCoordinate.y] != null) { unit.mapBlockBelow = _mapBlocks[(int)gameobjectCoordinate.x, (int)gameobjectCoordinate.y]; } StartCoroutine(MapNavigator.moveStepByStep(unit)); return(true); } } return(false); }
/// <summary> /// 传入unit和坐标,将Unit瞬间移动到该坐标(仅做坐标变更,不做其他处理) /// <param name="unit">移动的目标单位</param> /// <param name="gameobjectCoordinate">地图块儿自身的物体坐标</param> /// <returns></returns> /// </summary> public bool MoveUnitToCoordinate(Vector2 gameobjectCoordinate, Unit unit) { foreach (Unit gameUnit in _unitsList) { if (gameUnit == unit) { unit.mapBlockBelow.RemoveUnit(unit); if (_mapBlocks[(int)gameobjectCoordinate.x, (int)gameobjectCoordinate.y] == null) { return(false); } unit.mapBlockBelow = _mapBlocks[(int)gameobjectCoordinate.x, (int)gameobjectCoordinate.y]; _mapBlocks[(int)gameobjectCoordinate.x, (int)gameobjectCoordinate.y].AddUnit(unit); return(true); } } return(false); }
//一格一格移动 public IEnumerator moveStepByStep(Unit unit) { #region 测试一哈 先固定(0.0)为灼烧块,(0.1)为粘滞块 List <Vector2> vector2s = new List <Vector2>(); vector2s.Add(new Vector2(0, 0)); BattleMap.Instance().debuffBM.SetBattleMapBlockBurning(vector2s); List <Vector2> vector22s = new List <Vector2>(); vector22s.Add(new Vector2(1, 1)); BattleMap.Instance().debuffBM.SetBattleMapBlockRetrad(vector22s); #endregion Vector2 tempVector; BattleMapBlock battleMap; for (int i = paths.Count - 2; i >= 0; i--) { //移除上一步的地图块儿下面的units_on_me tempVector = new Vector2((int)paths[i + 1].position.x, (int)paths[i + 1].position.y); battleMap = BattleMap.Instance().GetSpecificMapBlock(tempVector); battleMap.RemoveUnit(unit); //添加当前unit到地图块儿下面的units_on_me内 tempVector = new Vector2((int)paths[i].position.x, (int)paths[i].position.y); battleMap = BattleMap.Instance().GetSpecificMapBlock(tempVector); battleMap.AddUnit(unit); unit.transform.localPosition = Vector3.zero; if (battleMap.blockType == EMapBlockType.Burnning)//如果经过灼烧块 { BattleMap.Instance().debuffBM.UnitEnterBurning(tempVector); } else if (battleMap.blockType == EMapBlockType.Retire)//如果经过滞留块 { BattleMap.Instance().debuffBM.UnitEnterRetire(unit, battleMap); unit.nextPos = paths[i].position; GamePlay.Gameplay.Instance().bmbColliderManager.Fresh(unit); break; } unit.nextPos = paths[i].position; GamePlay.Gameplay.Instance().bmbColliderManager.Fresh(unit); MsgDispatcher.SendMsg((int)MessageType.Move); yield return(new WaitForSeconds(0.2f)); } unit.restrain = true; MsgDispatcher.SendMsg((int)MessageType.Aftermove); }
public override void OnPointerDownFriendly(GameUnit.GameUnit unit, PointerEventData eventData) { base.OnPointerDownFriendly(unit, eventData); Vector2 pos = BattleMap.BattleMap.Instance().GetUnitCoordinate(unit); //如果两次都点在同一个角色身上,就从移动转为攻击 if (FSM.TargetList.Count > 0 && FSM.TargetList[0] == pos) { GameUtility.UtilityHelper.Log("取消移动,进入攻击,再次点击角色取消攻击", GameUtility.LogColor.RED); FSM.HandleMovCancel(pos); //关闭移动范围染色 FSM.HandleAtkConfirm(pos); //开启攻击范围染色 unit.restrain = true; //横置单位 FSM.PushState(new InputFSMAttackState(FSM)); //状态机压入新的攻击状态 } else { //点到其他单位什么都不做 } }
private void Update() { //检测地图块上是否存在单位 if (BattleMapManager.BattleMapManager.getInstance().CheckIfHasUnits(vector)) { hasUnit = true; //units = MapManager.MapManager.getInstance().GetUnitsOnMapBlock(vector); if (transform.GetComponentInChildren <Unit>() != null) { unit = transform.GetComponentInChildren <Unit>(); Debug.Log(unit.hp); Burning(unit); Debug.Log(unit.hp); } } else { hasUnit = false; hasBurined = false; } }
// Update is called once per frame void Update() { if (BattleMapManager.BattleMapManager.getInstance().CheckIfHasUnits(vector) && hasRetard == false) { hasUnit = true; //units = MapManager.MapManager.getInstance().GetUnitsOnMapBlock(vector); if (transform.GetComponentInChildren <Unit>() != null) { unit = transform.GetComponentInChildren <Unit>(); tempMov = unit.mov; Debug.Log(unit.mov); Retard(unit); Debug.Log(unit.mov); } } else { hasUnit = false; hasRetard = false; unit.mov = tempMov; } }
public override void OnPointerDownFriendly(GameUnit.GameUnit unit, PointerEventData eventData) { base.OnPointerDownFriendly(unit, eventData); //如果单位可以移动 if (unit.restrain == false) { //获得单位的位置 Vector2 pos = BattleMap.BattleMap.Instance().GetUnitCoordinate(unit); GameUtility.UtilityHelper.Log("准备移动,再次点击角色取消移动进入攻击.Unit position is " + pos, GameUtility.LogColor.RED); FSM.TargetList.Add(pos); FSM.HandleMovConfirm(pos); FSM.PushState(new InputFSMMoveState(this.FSM)); } //如果单位已经不能移动,但是可以攻击 else if (unit.restrain == true && unit.disarm == false) { Vector2 pos = BattleMap.BattleMap.Instance().GetUnitCoordinate(unit); GameUtility.UtilityHelper.Log("准备攻击,右键取消攻击.Unit position is " + pos, GameUtility.LogColor.RED); FSM.TargetList.Add(pos); FSM.HandleAtkConfirm(pos); FSM.PushState(new InputFSMAttackState(this.FSM)); } }