public CircleShap(FixedNumber r, int num) { FixedNumber t360 = new FixedNumber(360); FixedNumber tmp = t360 / num; Fixed2[] v2s = new Fixed2[num]; int i = 0; for (FixedNumber tr = new FixedNumber(0); tr < t360 && i < num; tr += tmp, i++) { v2s[i] = Fixed2.Parse(tr) * r; } Points = v2s; }
public AINodeStatus AiAction(AINode node) { // UnityEngine.Debug.LogError("AI_"+(ActionType)node.intType); vInput.Key.Reset(); var type = (ActionType)node.intType; switch (type) { case ActionType.hasEnemy: { if (enemy != null && enemy.active) { return(AINodeStatus.Success); } else { // vInput.Key.SetKey(false,KeyNum.MoveKey); return(AINodeStatus.Failure); } } case ActionType.findEnemy: { var others = player.client.physics.OverlapShap(new CircleShap(5.ToFixed(), 6), player.transform.Position); foreach (var other in others) { if (other is PlayerData) { var te = other as PlayerData; if (teamManager.IsEnemy(te, player)) { enemy = te; return(AINodeStatus.Success); } // vInput.Key.SetKey(false,KeyNum.MoveKey); } } if (hasDirection) { vInput.SetJoyStickDirection(KeyNum.MoveKey, moveDir); } else { moveDir = Fixed2.Parse(player.client.random.Range(0, 360).ToFixed()); hasDirection = true; player.client.coroutine.WaitCall(player.client.random.RangeFixed(2.ToFixed(), 5.ToFixed()), () => { hasDirection = false; }); } return(AINodeStatus.Failure); } case ActionType.enemyInRange: { if (Fixed2.DistanceLess(ComputNextPos(enemy), player.transform.Position, 1.5f.ToFixed())) { vInput.Key.SetKey(false, KeyNum.MoveKey); return(AINodeStatus.Success); } else { return(AINodeStatus.Failure); } } case ActionType.skill1: { vInput.SetJoyStickDirection(KeyNum.Skill1, ComputNextPos(enemy) - (player.transform.Position)); player.client.coroutine.WaitCall(0.5f.ToFixed(), () => { vInput.Key.SetKey(false, KeyNum.Skill1); }); return(AINodeStatus.Success); } case ActionType.findPath: { moveDir = enemy.transform.Position - player.transform.Position; return(AINodeStatus.Success); } case ActionType.moveToEnemy: { if (DontHasPath(moveDir)) { var rot = moveDir.ToRotation(); rot += 90; moveDir = Fixed2.Parse(rot); if (DontHasPath(moveDir)) { rot -= 180; moveDir = Fixed2.Parse(rot); } } vInput.SetJoyStickDirection(KeyNum.MoveKey, moveDir); return(AINodeStatus.Success); } default: break; } return(AINodeStatus.Failure); }