private void BlipMove(ref MonsterCharacter.InputFrame frame) { frame.up = dir.y; frame.right = dir.x; frame.WantDirection = Quaternion.Euler(0, 0, AxMath.SafeAtan2(dir.y, dir.x) * Mathf.Rad2Deg); if (blipTimer > 0) { blipTimer -= Time.deltaTime; return; } blipTimer = BlipTime; dir = Vec2I.zero; if (Random.value < BlipWaitChance) { return; } if (Leashed) { if ((homePosition - transform.position).sqrMagnitude >= LeashRange * LeashRange) { Vector2 distance = transform.position - Camera.main.transform.position; if (Mathf.Max(distance.x) > Options.AlertDistance.x || Mathf.Max(distance.y) > Options.AlertDistance.y) { Destroy(gameObject); } } } if (Random.value < BlipRandomChance) { dir = Vec2I.directions[Random.Range(1, Vec2I.directions.Length)]; return; } if (HuntPlayer) { if (LastKnownPlayerRoom != -1) { targetRoom = LastKnownPlayerRoom; } } if (targetRoom >= 0 && targetRoom < Room.Rooms.Length) { //simplistic behavior //dir = Room.Rooms[targetRoom].parent[thing.gridPos.x, thing.gridPos.y] - thing.gridPos; //return; //to avoid monsters piling up on single point if (Vec2I.Manhattan(Room.Rooms[targetRoom].gridPos, thing.gridPos) < NearSteps) { return; } if (!AI.RoomPath(thing.gridPos, Room.Rooms[targetRoom], MaxSteps, out Vec2I[] path))
private void StandAround(ref MonsterCharacter.InputFrame frame) { if (target != null) { character.OnInputRequest = Hesitate; return; } Vec2I dif = playerGridPos - thing.gridPos; frame.WantDirection = Quaternion.Euler(0, 0, AxMath.SafeAtan2(dif.y, dif.x) * Mathf.Rad2Deg); if (decisionTimer > 0f) { decisionTimer -= Time.deltaTime; return; } decisionTimer = Random.Range(DecisionInterval.x, DecisionInterval.y); if (activated) { if (Vec2I.Manhattan(playerGridPos, thing.gridPos) <= PlayerDistance.x) { character.OnInputRequest = MoveOut; return; } if (targetRoom >= 0 || targetRoom < Room.Rooms.Length) { Room room = Room.Rooms[targetRoom]; if (TheGrid.Valid(playerGridPos) && TheGrid.Valid(thing.gridPos)) { if (room.steps[playerGridPos.x, playerGridPos.y] < room.steps[thing.gridPos.x, thing.gridPos.y]) { character.OnInputRequest = MoveOut; return; } } } } }
public static int Heuristic(Vec2I from, Vec2I to) { return(Vec2I.Manhattan(from, to) * 40); }