/// <summary> /// 触发火陷阱 /// </summary> /// <returns>The trap triggered.</returns> /// <param name="battlePlayer">Battle player.</param> private IEnumerator FireTrapTriggered(BattlePlayerController battlePlayer) { int count = 0; battlePlayer.SetEffectAnim(CommonData.burnedEffectName, null, 0, 3f); while (count < 3) { yield return(new WaitForSeconds(1f)); yield return(new WaitUntil(() => !battlePlayer.isInEvent)); MyTowards towards = battlePlayer.GetReversedTowards(); battlePlayer.AddHurtAndShow(50, HurtType.Physical, towards); ExploreManager.Instance.expUICtr.UpdatePlayerStatusBar(); if (battlePlayer.agent.health <= 0) { //ExploreManager.Instance.DisableAllInteractivity(); battlePlayer.AgentDie(); yield break; } count++; } }
/// <summary> /// 随机朝向 /// </summary> private void RandomTowards() { int towardsIndex = Random.Range(0, 4); boneTowards = MyTowards.Right; switch (towardsIndex) { case 0: baCtr.TowardsRight(); boneTowards = MyTowards.Right; break; case 1: baCtr.TowardsLeft(); boneTowards = MyTowards.Left; break; case 2: baCtr.TowardsUp(); // 朝上时要查一下骨骼实际的朝向 boneTowards = (baCtr as BattleMonsterController).GetMonsterBoneTowards(); break; case 3: baCtr.TowardsDown(); // 朝下时要查一下骨骼实际的朝向 boneTowards = (baCtr as BattleMonsterController).GetMonsterBoneTowards(); break; } }
/// <summary> /// 获取角色朝向的反方向 /// </summary> /// <returns>The reversed towards.</returns> public MyTowards GetReversedTowards() { MyTowards reversedTowards = MyTowards.Left; switch (towards) { case MyTowards.Left: reversedTowards = MyTowards.Right; break; case MyTowards.Right: reversedTowards = MyTowards.Left; break; case MyTowards.Up: reversedTowards = MyTowards.Right; break; case MyTowards.Down: reversedTowards = MyTowards.Right; break; } return(reversedTowards); }
/// <summary> /// 获取怪物的龙骨朝向[怪物探测方向分上下左右,但是怪物实际朝向只有左右] /// </summary> /// <returns>The monster bone towards.</returns> public MyTowards GetMonsterBoneTowards() { MyTowards myTowards = MyTowards.Right; if (armatureCom.armature.flipX) { myTowards = MyTowards.Left; } return(myTowards); }
/// <summary> /// 触发尖刺陷阱 /// </summary> /// <param name="battlePlayer">Battle player.</param> private void ThornTrapTriggered(BattlePlayerController battlePlayer) { mapItemRenderer.sprite = thornTrapOnSprite; MyTowards towards = battlePlayer.GetReversedTowards(); battlePlayer.AddHurtAndShow(50, HurtType.Physical, towards); if (battlePlayer.agent.health <= 0) { //ExploreManager.Instance.DisableAllInteractivity(); battlePlayer.AgentDie(); } ExploreManager.Instance.expUICtr.UpdatePlayerStatusBar(); }
/// <summary> /// 添加伤害文字动画到队列 /// </summary> /// <param name="text">Text.</param> public void AddHurtTextToQueue(string text, MyTowards towards) { // 角色的世界位置转化为在画布中的位置 Vector3 basePosition = MyTool.ToPointInCanvas(transform.position); // 根据分辨率不同调整屏幕位置 basePosition = new Vector3(basePosition.x * CommonData.scalerToPresetHW, basePosition.y, 0); // 生成探索文本 ExploreText ft = new ExploreText(text, towards, basePosition); // 将探索文本加入伤害文本队列 agentUICtr.exploreTextManager.AddHurtText(ft); }
/// <summary> /// 显示警示区域 /// </summary> public void ShowAlertAreaTint() { MyTowards towards = baCtr.towards; for (int i = 0; i < alertAreas.Length; i++) { if (i == (int)towards) { alertAreas [i].ShowAlerAreaTint(); } else { alertAreas [i].HideAlertAreaTint(); } } }
private IEnumerator BulletMoveWithMoveVectorAndRange(MyTowards towards, Vector2 range) { float distanceX = 0; float distanceY = 0; Vector3 moveVector = Vector3.zero; while (distanceX < range.x && distanceY < range.y) { switch (towards) { case MyTowards.Left: moveVector = new Vector3(-speed * Time.deltaTime, 0, 0); break; case MyTowards.Right: moveVector = new Vector3(speed * Time.deltaTime, 0, 0); break; case MyTowards.Up: moveVector = new Vector3(0, speed * Time.deltaTime, 0); break; case MyTowards.Down: moveVector = new Vector3(0, -speed * Time.deltaTime, 0); break; } this.transform.position += moveVector; distanceX += moveVector.x; distanceY += moveVector.y; // Debug.Log (this.transform.position); yield return(null); } // Debug.LogFormat("before : {0}",bulletAnimator.GetCurrentAnimatorClipInfo(0). // bulletAnimator.SetBool ("Play",false); bc2d.enabled = false; bulletPool.AddInstanceToPool(this.gameObject); }
/// <summary> /// 受到伤害并播放伤害文字动画 /// </summary> /// <param name="hurt">Hurt.</param> /// <param name="type">Type.</param> /// <param name="specialAttack">Special attack.</param> public void AddHurtAndShow(int hurt, HurtType type, MyTowards textTowards) { // 至少有1点伤害值 if (hurt == 0) { hurt = 1; } string hurtString = string.Empty; agent.health -= hurt; string colorText = string.Empty; // 根据伤害类型添加颜色富文本 switch (type) { case HurtType.Physical: if (this is BattlePlayerController) { colorText = "red"; } else { colorText = "white"; } hurtString = string.Format("<color={0}>{1}</color>", colorText, hurt); break; case HurtType.Magical: if (this is BattlePlayerController) { colorText = "cyan"; } else { colorText = "lightblue"; } hurtString = string.Format("<color={0}>{1}</color>", colorText, hurt); break; } // 加入到伤害文本队列 AddHurtTextToQueue(hurtString, textTowards); }
// 构造函数 public ExploreText(string text, MyTowards towards, Vector3 basePosition) { this.text = text; this.towards = towards; this.basePosition = basePosition; }
/// <summary> /// 走到指定位置上 /// </summary> /// <param name="position">Position.</param> /// <param name="cb">Cb.</param> /// <param name="showAlertArea">If set to <c>true</c> show alert area.</param> public override void WalkToPosition(Vector3 position, CallBack cb, bool showAlertArea = true) { baCtr.PlayRoleAnim(CommonData.roleWalkAnimName, 0, null); int oriPosX = Mathf.RoundToInt(transform.position.x); int oriPosY = Mathf.RoundToInt(transform.position.y); int targetPosX = Mathf.RoundToInt(position.x); int targetPosY = Mathf.RoundToInt(position.y); moveOrigin = new Vector3(oriPosX, oriPosY, 0); moveDestination = new Vector3(targetPosX, targetPosY, 0); RefreshWalkableInfoWhenStartMove(); if (targetPosY == oriPosY) { if (targetPosX >= oriPosX) { baCtr.TowardsRight(); boneTowards = MyTowards.Right; alertTint.transform.localPosition = new Vector3(alertIconOffsetX, alertIconOffsetY, 0); if (monsterSayContainer != null) { monsterSayContainer.transform.localPosition = new Vector3(monsterSayContainerOffsetX - 1000, monsterSayContainerOffsetY, 0); } } else { baCtr.TowardsLeft(); boneTowards = MyTowards.Left; alertTint.transform.localPosition = new Vector3(-alertIconOffsetX, alertIconOffsetY, 0); if (monsterSayContainer != null) { monsterSayContainer.transform.localPosition = new Vector3(-monsterSayContainerOffsetX - 1000, monsterSayContainerOffsetY, 0); } } } else if (targetPosX == oriPosX) { if (targetPosY >= oriPosY) { baCtr.TowardsUp(); } else { baCtr.TowardsDown(); } } if (moveCoroutine != null) { StopCoroutine(moveCoroutine); } float timeScale = 3f; if (showAlertArea) { ShowAlertAreaTint(); } moveCoroutine = MoveTo(position, timeScale, delegate { baCtr.PlayRoleAnim(CommonData.roleIdleAnimName, 0, null); bool saySomething = Random.Range(0, 10) <= 1 && !(baCtr.agent as Monster).isBoss; if (saySomething) { string say = GetMonsterSay(); tmPro.alignment = TMPro.TextAlignmentOptions.Center; ShowMonsterSay(say); } if (cb != null) { cb(); } SetSortingOrder(-Mathf.RoundToInt(position.y)); }); StartCoroutine(moveCoroutine); }
/// <summary> /// 调整位置后开始战斗 /// </summary> /// <returns>The position and start fight.</returns> /// <param name="battlePlayerCtr">Battle player ctr.</param> private IEnumerator ResetPositionAndStartFight(BattlePlayerController battlePlayerCtr) { // 等待准备好 yield return(new WaitUntil(() => isReadyToFight)); // 头山闪红色叹号 AlertTintSpark(); // 播放idle动画 baCtr.PlayRoleAnim(CommonData.roleIdleAnimName, 0, null); // 判断玩家角色是否需要重新开始攻击动作 bool playerNeedResetAttack = battlePlayerCtr.NeedResetAttack(); yield return(new WaitForSeconds(0.4f)); HideAllAlertAreas(); DisableAllDetect(); Vector3 playerOriPos = battlePlayerCtr.transform.position; Vector3 monsterOriPos = transform.position; int playerPosX = Mathf.RoundToInt(playerOriPos.x); int playerPosY = Mathf.RoundToInt(playerOriPos.y); int monsterPosX = Mathf.RoundToInt(monsterOriPos.x); int monsterPosY = Mathf.RoundToInt(monsterOriPos.y); int monsterLayerOrder = -monsterPosY; int posOffsetX = playerPosX - monsterPosX; int posOffsetY = playerPosY - monsterPosY; Vector3 monsterRunPos = Vector3.zero; Vector3 monsterFightPos = Vector3.zero; Vector3 playerFightPos = new Vector3(playerPosX, playerPosY, 0); int minX = 0; int maxX = ExploreManager.Instance.newMapGenerator.columns - 1; HLHRoleAnimInfo playerCurrentAnimInfo = battlePlayerCtr.GetCurrentRoleAnimInfo(); // 根据玩家角色和怪物的位置,战斗点附近的可行走情况决定人物和怪物的战斗位置 //人物在怪物右边 if (posOffsetX > 0) { // 人物角色先朝左 battlePlayerCtr.TowardsLeft(!battlePlayerCtr.isInFight); // 如果怪物在人物水平向左一格的附近位置,并且该位置没有超出地图左侧界限 if (playerPosX - 1 >= minX && playerPosX - 1 == monsterPosX && playerPosY == monsterPosY) { // 怪物跑向的位置【人物左边一格】 monsterRunPos = new Vector3(playerPosX - 1f, playerPosY, 0); // 怪物战斗位置【人物左边一格】 monsterFightPos = new Vector3(playerPosX - 1, playerPosY, 0); // 怪物层级调整到人物层级 monsterLayerOrder = -playerPosY; } // 人物左侧没有超过地图左侧界限,且地图上人物左侧位置上没有东西【可行走信息为1】 else if (playerPosX - 1 >= minX && ExploreManager.Instance.newMapGenerator.mapWalkableInfoArray[playerPosX - 1, playerPosY] == 1) { monsterRunPos = new Vector3(playerPosX - 0.5f, playerPosY, 0); monsterFightPos = new Vector3(playerPosX - 1, playerPosY, 0); monsterLayerOrder = -playerPosY; } // 人物左侧没有超过地图左侧界限,地图上人物左侧位置没有东西,但是可行走信息不为1,但是是当前怪物的单步行走目标位置【每个怪物在行走之前都会把目标位置可行走信息设为5,防止其他怪物也走上去】 else if (playerPosX - 1 >= minX && playerPosX - 1 == Mathf.RoundToInt(moveDestination.x) && playerPosY == Mathf.RoundToInt(moveDestination.y)) { monsterRunPos = new Vector3(playerPosX - 1f, playerPosY, 0); monsterFightPos = new Vector3(playerPosX - 1, playerPosY, 0); monsterLayerOrder = -playerPosY; } // 其他情况都要让怪物和人物的战斗位置尽量放进同一个格子里了 else { // 如果人物靠上 if (posOffsetY > 0) { //怪物跑到的位置 monsterRunPos = new Vector3(playerPosX - 0.25f, playerPosY - 0.15f, 0); // 怪物战斗位置 monsterFightPos = new Vector3(playerPosX - 0.25f, playerPosY - 0.15f, 0); // 怪物的层级比人物高1级 monsterLayerOrder = -playerPosY + 1; // 人物的战斗位置 playerFightPos = new Vector3(playerPosX + 0.25f, playerPosY + 0.15f, 0); baCtr.SetSortingOrder(monsterLayerOrder); } else // 如果人物靠下 { monsterRunPos = new Vector3(playerPosX - 0.25f, playerPosY + 0.15f, 0); monsterFightPos = new Vector3(playerPosX - 0.25f, playerPosY + 0.15f, 0); monsterLayerOrder = -playerPosY - 1; playerFightPos = new Vector3(playerPosX + 0.25f, playerPosY - 0.15f, 0); baCtr.SetSortingOrder(-playerPosY - 1); } } } else if (posOffsetX == 0) { if (playerPosX + 1 <= maxX && ExploreManager.Instance.newMapGenerator.mapWalkableInfoArray [playerPosX + 1, playerPosY] == 1) { battlePlayerCtr.TowardsRight(!battlePlayerCtr.isInFight); monsterRunPos = new Vector3(playerPosX + 0.5f, playerPosY, 0); monsterFightPos = new Vector3(playerPosX + 1, playerPosY, 0); monsterLayerOrder = -playerPosY; } else if (playerPosX + 1 <= maxX && playerPosX + 1 == Mathf.RoundToInt(moveDestination.x) && playerPosY == Mathf.RoundToInt(moveDestination.y)) { battlePlayerCtr.TowardsRight(!battlePlayerCtr.isInFight); monsterRunPos = new Vector3(playerPosX + 0.5f, playerPosY, 0); monsterFightPos = new Vector3(playerPosX + 1, playerPosY, 0); monsterLayerOrder = -playerPosY; } else if (playerPosX - 1 >= minX && ExploreManager.Instance.newMapGenerator.mapWalkableInfoArray [playerPosX - 1, playerPosY] == 1) { battlePlayerCtr.TowardsLeft(!battlePlayerCtr.isInFight); monsterRunPos = new Vector3(playerPosX - 0.5f, playerPosY, 0); monsterFightPos = new Vector3(playerPosX - 1, playerPosY, 0); monsterLayerOrder = -playerPosY; } else if (playerPosX - 1 >= minX && playerPosX - 1 == Mathf.RoundToInt(moveDestination.x) && playerPosY == Mathf.RoundToInt(moveDestination.y)) { battlePlayerCtr.TowardsLeft(!battlePlayerCtr.isInFight); monsterRunPos = new Vector3(playerPosX - 0.5f, playerPosY, 0); monsterFightPos = new Vector3(playerPosX - 1, playerPosY, 0); monsterLayerOrder = -playerPosY; } else { if (posOffsetY > 0) { monsterRunPos = new Vector3(playerPosX + 0.25f, playerPosY - 0.15f, 0); monsterFightPos = new Vector3(playerPosX + 0.25f, playerPosY - 0.15f, 0); monsterLayerOrder = -playerPosY + 1; playerFightPos = new Vector3(playerPosX - 0.25f, playerPosY + 0.15f, 0); baCtr.SetSortingOrder(-playerPosY + 1); battlePlayerCtr.TowardsRight(!battlePlayerCtr.isInFight); } else { monsterRunPos = new Vector3(playerPosX + 0.25f, playerPosY + 0.15f, 0); monsterFightPos = new Vector3(playerPosX + 0.25f, playerPosY + 0.15f, 0); monsterLayerOrder = -playerPosY - 1; playerFightPos = new Vector3(playerPosX - 0.25f, playerPosY - 0.15f, 0); baCtr.SetSortingOrder(-playerPosY - 1); battlePlayerCtr.TowardsRight(!battlePlayerCtr.isInFight); } } } else if (posOffsetX < 0) { battlePlayerCtr.TowardsRight(!battlePlayerCtr.isInFight); if (playerPosX + 1 <= maxX && playerPosX + 1 == monsterPosX && playerPosY == monsterPosY) { monsterRunPos = new Vector3(playerPosX + 1f, playerPosY, 0); monsterFightPos = new Vector3(playerPosX + 1, playerPosY, 0); monsterLayerOrder = -playerPosY; } else if (playerPosX + 1 <= maxX && ExploreManager.Instance.newMapGenerator.mapWalkableInfoArray[playerPosX + 1, playerPosY] == 1) { monsterRunPos = new Vector3(playerPosX + 0.5f, playerPosY, 0); monsterFightPos = new Vector3(playerPosX + 1, playerPosY, 0); monsterLayerOrder = -playerPosY; } else if (playerPosX + 1 <= maxX && playerPosX + 1 == Mathf.RoundToInt(moveDestination.x) && playerPosY == Mathf.RoundToInt(moveDestination.y)) { monsterRunPos = new Vector3(playerPosX + 1f, playerPosY, 0); monsterFightPos = new Vector3(playerPosX + 1, playerPosY, 0); monsterLayerOrder = -playerPosY; } else { if (posOffsetY > 0) { monsterRunPos = new Vector3(playerPosX + 0.25f, playerPosY - 0.15f, 0); monsterFightPos = new Vector3(playerPosX + 0.25f, playerPosY - 0.15f, 0); monsterLayerOrder = -playerPosY + 1; playerFightPos = new Vector3(playerPosX - 0.25f, playerPosY + 0.15f, 0); baCtr.SetSortingOrder(-playerPosY + 1); } else { monsterRunPos = new Vector3(playerPosX + 0.25f, playerPosY + 0.15f, 0); monsterFightPos = new Vector3(playerPosX + 0.25f, playerPosY + 0.15f, 0); monsterLayerOrder = -playerPosY - 1; playerFightPos = new Vector3(playerPosX - 0.25f, playerPosY - 0.15f, 0); baCtr.SetSortingOrder(-playerPosY - 1); } } } // 如果玩家需要重置战斗动作 if (playerNeedResetAttack) { battlePlayerCtr.ResetAttack(playerCurrentAnimInfo); ExploreManager.Instance.expUICtr.UpdateActiveSkillButtons(); } // 玩家位置修正 battlePlayerCtr.FixPosTo(playerFightPos, null); // 怪物跑到位置 RunToPosition(monsterRunPos, delegate { // 如果跑到的时候已经死了,直接返回 if (baCtr.isDead) { return; } // 调整怪物位置到战斗位置 baCtr.FixPosTo(monsterFightPos, null); // 如果玩家没有逃离战斗 if (!battlePlayerCtr.escapeFromFight) { // 根据双方位置关系重新调整朝向 if (transform.position.x <= ExploreManager.Instance.battlePlayerCtr.transform.position.x) { baCtr.TowardsRight(); boneTowards = MyTowards.Right; } else { baCtr.TowardsLeft(); boneTowards = MyTowards.Left; } // 如果玩家没有逃离战斗,并且玩家还没有进入战斗,则玩家和怪物都进入战斗 if (!battlePlayerCtr.isInEscaping && !battlePlayerCtr.isInFight) { ExploreManager.Instance.PlayerAndMonsterStartFight(); } else { // 其他情况下只有怪物进入战斗 ExploreManager.Instance.MonsterStartFight(); } } // 玩家在怪物跑的过程中脱离了战斗【这个现在从动画播放时长和跑动的时长上看是不会实现的,但是逻辑先做着】 else { bool monsterDie = baCtr.agent.health <= 0; RefreshWalkableInfoWhenQuit(monsterDie); QuitFightAndDelayMove(5); battlePlayerCtr.escapeFromFight = false; } }, monsterLayerOrder); }
public void SetUpFightTextManager(Vector3 selfPos, Vector3 enemyPos) { direction = selfPos.x < enemyPos.x ? MyTowards.Left : MyTowards.Right; basePosition = ToPointInCanvas(selfPos); }
public void SetTowards(MyTowards towards) { this.towards = towards; }