protected override int onExecute(TBTWorkingData wData) { BattleBehaviorWorkingData behaviorData = wData as BattleBehaviorWorkingData; float deltaTime = behaviorData.deltaTime; BattleUnit source = behaviorData.owner; AIBehaviorRequest request = behaviorData.request; Unit target = request.target; Vector2 sourcePos = source.Get2DPosition(); Vector2 targetPos = target.Get2DPosition(); Vector2 sourceForward = source.Get2DForward(); Vector2 targetForward = (targetPos - sourcePos).normalized; float turnSpeed = source.GetTurnSpeed(); float angle = Vector2.Angle(targetForward, sourceForward); float radianToTurn = turnSpeed * deltaTime; //BattleLog.Log("【NOD_TurnTo】angle:{0},{1}", angle, radianToTurn * Mathf.Rad2Deg); if (angle < radianToTurn * Mathf.Rad2Deg) { source.Set2DForward(targetForward); GameMsg.instance.SendMessage(GameMsgDef.Hero_TurnTo2D, new HeorTurnEventArgs() { id = source.id, forward = targetForward, }); return(TBTRunningStatus.FINISHED); } // 叉积算出方向 unity是左手坐标系,所以反过来了 Vector3 cross = Vector3.Cross(targetForward, sourceForward); if (cross.z > 0) { radianToTurn = -radianToTurn; } Vector2 newForward = BattleMath.Vector2RotateFromRadian(sourceForward.x, sourceForward.y, radianToTurn); //BattleLog.Log("【NOD_TurnTo】自己朝向:{0} 目标朝向:{1} 相隔角度:{2} 旋转弧度:{3} 叉乘:{4} 新的朝向:{5}", sourceForward.ToString(),targetForward.ToString(), angle.ToString(),(radianToTurn * Mathf.Rad2Deg).ToString(), cross.ToString(), newForward.ToString()); source.Set2DForward(newForward); GameMsg.instance.SendMessage(GameMsgDef.Hero_TurnTo2D, new HeorTurnEventArgs() { id = source.id, forward = newForward, }); return(TBTRunningStatus.EXECUTING); }
protected override void OnUpdate(float casterX, float casterZ, float targetX, float targetZ, float targetForwardX, float targetForwardZ) { base.OnUpdate(casterX, casterZ, targetX, targetZ, targetForwardX, targetForwardZ); m_length = BattleMath.SqartDistance2DMagnitude(casterX, casterZ, targetX, targetZ); var scale = m_indicatorTransform.localScale; m_scale.Set(scale.x, scale.y, m_length); m_indicatorTransform.localScale = m_scale; m_indicatorTransform.position = m_casterTransform.position; m_position.Set(targetForwardX, 0, targetForwardZ); if (m_position != Vector3.zero) { m_indicatorTransform.forward = m_position; } }
/// <summary> /// Launch the attached GameObject at a target. Ex: a hero towards an enemy or vice versa. /// </summary> /// <param name="startPosition"> Start position of the propelled object</param> /// <param name="targetObj"> Target GameObject</param> /// <param name="targetID"> Target's partyID or battleID</param> public virtual void Propel(int battleID, Vector2 startPosition, GameObject targetObj, int targetID, BattleMode mode) { // Convert partyID to battleID if necessary selfID = gameObject.CompareTag("Hero_Battle") ? BattleMath.ConvertHeroID(battleID) : battleID; this.targetBattleID = targetID; // Set start position this.startPosition = startPosition; // Set target, and collicder if it exists target = targetObj; bool isOnGameObject = targetObj.TryGetComponent <Collider2D>(out targetCollider); if (!isOnGameObject) { targetCollider = targetObj.GetComponentInChildren <Collider2D>(); } // Create a bullseye-like target at the location of the target (in case there is no collider) targetLastPosition = new Bounds(target.transform.position, new Vector2(BoundsMargin, BoundsMargin)); // Action being performed by the Propel this.mode = mode; // Modify speed if Kick or Drill (other effects use override methods to add here) switch (mode) { case BattleMode.Blitz_Kick: propelSpeedModifier = KickSpeedModifier; break; case BattleMode.Tools_Drill: propelSpeedModifier = DrillSpeedModifier; break; default: propelSpeedModifier = 1f; break; } // Allow the Update() method to move this GameObject isPropelled = true; }
// Uses the selected item public void Click_UseButton() { if (selection == null) { return; } AudioManager.PlaySound(AudioClipName.UsePotion); // reference to hero and item InvItem item = partyStash.Contents[(int)selection]; BattleHero hero = BattleLoader.Party.Hero[BattleMath.ConvertHeroID(TurnCounter.CurrentID)]; // check for full hp/mp, display message and do not use. int hp = hero.HP; int hpMax = hero.HPMax; if (hp == hpMax && item.Type == InvType.Potion && item.Subtype == InvSubtype.Health) { previousMessage = messageText.text; messageText.text = "You are already at full health."; messageTimer.Run(); return; } int mp = hero.MP; int mpMax = hero.MPMax; if (mp == mpMax && item.Type == InvType.Potion && item.Subtype == InvSubtype.Mana) { previousMessage = messageText.text; messageText.text = "You are already at full mana."; messageTimer.Run(); return; } // create negative damage for restorative item Damage damage = new Damage(); switch (item.Type) { case InvType.Potion: int healing; switch (item.Subtype) { case InvSubtype.Health: switch (item.Name) { case InvNames.Potion_Health_Tiny: healing = 25; break; case InvNames.Potion_Health_Small: healing = 75; break; case InvNames.Potion_Health_Medium: healing = 250; break; case InvNames.Potion_Health_Large: healing = 600; break; case InvNames.Potion_Health_Huge: healing = 2000; break; case InvNames.Potion_Health_Epic: healing = 100000; break; default: healing = 25; break; } if (hp + healing > hpMax) { healing = hpMax - hp; } // remove item from stash and queue healing in Damage partyStash.RemoveInvItem(item.Name, 1); damage.Add(-healing, false, true, false); // amount, not crit, isItem, not MP break; case InvSubtype.Mana: switch (item.Name) { case InvNames.Potion_Mana_Tiny: healing = 10; break; case InvNames.Potion_Mana_Small: healing = 20; break; case InvNames.Potion_Mana_Medium: healing = 50; break; case InvNames.Potion_Mana_Large: healing = 125; break; case InvNames.Potion_Mana_Huge: healing = 250; break; case InvNames.Potion_Mana_Epic: healing = 100000; break; default: healing = 10; break; } if (mp + healing > mpMax) { healing = mpMax - mp; } // remove item from stash and queue healing in Damage partyStash.RemoveInvItem(item.Name, 1); damage.Add(-healing, false, true, true); // amount, not crit, isItem, is MP break; } break; default: damage.Add(null); break; } // disable ui once a choice is made uiEnabler.EnableUI(false); // Invoke a Player End Turn event // Use this event instead of triggering off a fight collision with enemy // TurnOver applies the damage queued in Damage turnInvoker.TurnOver(damage, TurnCounter.CurrentID); // Exit menu Destroy(gameObject); }