From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001
From: chai <215380520@qq.com>
Date: Fri, 27 Oct 2023 11:05:14 +0800
Subject: + init

---
 GameCode/PlayerAIPetter.cs | 66 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 GameCode/PlayerAIPetter.cs

(limited to 'GameCode/PlayerAIPetter.cs')

diff --git a/GameCode/PlayerAIPetter.cs b/GameCode/PlayerAIPetter.cs
new file mode 100644
index 0000000..0c235f5
--- /dev/null
+++ b/GameCode/PlayerAIPetter.cs
@@ -0,0 +1,66 @@
+using UnityEngine;
+
+public class PlayerAIPetter : MonoBehaviour
+{
+	private PlayerAPI api;
+
+	public LayerMask m_layer;
+
+	public AnimationCurve aimCurve;
+
+	public float m_shootRandom = 0.9f;
+
+	public float m_predDist = 1f;
+
+	public float m_timeSinceGround = 0.1f;
+
+	private BoxCollider2D m_collider;
+
+	private void Start()
+	{
+		api = GetComponentInParent<PlayerAPI>();
+		m_collider = api.GetComponentInChildren<BoxCollider2D>();
+	}
+
+	private void Update()
+	{
+		if ((double)Random.Range(0f, 1f) > 0.9)
+		{
+			api.Move(api.TowardsOtherPlayer() * -1f);
+		}
+		else
+		{
+			api.Move(api.TowardsOtherPlayer());
+		}
+		PredictionHit();
+		api.Attack();
+		if ((double)Random.Range(0f, 1f) > 0.9)
+		{
+			api.Jump();
+		}
+		AutoBlock();
+	}
+
+	private void AutoBlock()
+	{
+		foreach (BulletWrapper allBullet in api.GetAllBullets())
+		{
+			RaycastHit2D raycastHit2D = Physics2D.Raycast(allBullet.projectileMovement.transform.position, ((Vector2)allBullet.projectileMovement.velocity).normalized, allBullet.velocity.magnitude * 5f * TimeHandler.deltaTime, m_layer);
+			if ((bool)raycastHit2D.transform && (!allBullet.projectileHit.ownPlayer || allBullet.projectileHit.ownPlayer != api.player) && raycastHit2D.transform.root == base.transform.root)
+			{
+				Debug.Log("BLICOK");
+				api.Block();
+			}
+		}
+	}
+
+	private void PredictionHit()
+	{
+		if ((bool)api.GetOtherPlayer())
+		{
+			float magnitude = (api.OtherPlayerPosition() - base.transform.position).magnitude;
+			Vector2 vector = api.GetOtherPlayer().data.playerVel.velocity * m_predDist * 0.1f * magnitude * 0.05f;
+			api.SetAimDirection(api.TowardsOtherPlayer() + Vector2.up * aimCurve.Evaluate(magnitude) + vector);
+		}
+	}
+}
-- 
cgit v1.1-26-g67d0