This commit is contained in:
2025-05-13 05:19:58 +03:00
parent 853edaf0b4
commit 472b2aee18
1034 changed files with 41844 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
using UnityEngine;
using System.Collections;
public class AiAim : AiBehavior {
private GameObject obj;
private HumanController selfController;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (obj == null) {
obj = blackboard.Obj;
selfController = obj.GetComponent<HumanController>();
}
return selfController.PrepareItem() ? BehaviorStatus.Success : BehaviorStatus.Fail;
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 703aed8d891f45d4a891c457267df9cb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+72
View File
@@ -0,0 +1,72 @@
using System.Linq;
using UnityEngine;
using System.Collections;
public class AiCanHitEnemy : AiBehavior {
private GameObject obj;
private Inventory inventory;
private HumanController selfController;
public LayerMask skipRaycast;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (obj == null) {
blackboard.GetValue<GameObject>("gameobject", out obj);
inventory = obj.GetComponent<Inventory>();
selfController = obj.GetComponent<HumanController>();
}
PlayerController enemy;
blackboard.GetValue("enemy", out enemy);
if (enemy == null) {
return BehaviorStatus.Fail;
}
Vector3 right = obj.transform.localToWorldMatrix.MultiplyVector(Vector3.right).normalized;
var raycastDir = Mathf.Abs(enemy.transform.position.x - obj.transform.position.x) * right;
var p0 = obj.transform.position + Vector3.up * selfController.ArmsStandOffset;
var p1 = obj.transform.position + Vector3.up * selfController.ArmsCrouchOffset;
string crouchingName = "crouchToShoot";
if ( RaycastEnemy(p0, raycastDir, enemy)) {
blackboard.SetValue(crouchingName, false);
Debug.Log("WTF1");
return BehaviorStatus.Success;
} else if (RaycastEnemy(p1, raycastDir, enemy)) {
Debug.Log("WTF2");
blackboard.SetValue(crouchingName, true);
return BehaviorStatus.Success;
}
return BehaviorStatus.Fail;
}
private bool RaycastEnemy(Vector3 from, Vector3 d, PlayerController enemy) {
var hits = Physics2D.RaycastAll(from, d, 100, Physics2D.DefaultRaycastLayers & ~skipRaycast.value);
Debug.Log("Hits: " + hits.Length);
//find first collision which is not inside player head
int firstOutsideId = -1;
for (int i = 0; i < hits.Length; ++i) {
if (hits[i].fraction > 0.0f) {
firstOutsideId = i;
break;
}
}
Debug.Log("Hits name: " + hits[firstOutsideId].transform.name);
if (firstOutsideId >= 0) {
var hit = hits[firstOutsideId];
var g = hit.collider.GetComponent<PlayerController>();
if (g != null && g == enemy) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e63b0fdce85d3e24dafa3251136a3f0c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+24
View File
@@ -0,0 +1,24 @@
using UnityEngine;
using System.Collections;
public class AiCancelAim : AiBehavior {
private GameObject obj;
private HumanController selfController;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (obj == null) {
obj = blackboard.Obj;
selfController = obj.GetComponent<HumanController>();
}
if (!selfController.GunArmed) {
return BehaviorStatus.Fail;
}
selfController.UnprepareItem();
selfController.Crouch = false;
return BehaviorStatus.Success;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b9f8f06b1ce7868419b3244bd9bd7b07
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+67
View File
@@ -0,0 +1,67 @@
using UnityEngine;
using System.Collections;
public class AiChase : AiBehavior {
public float chaseTimeout = 5;
private GameObject _obj;
private HumanController _selfController;
private bool _chasing;
public RandomSoundPlayer endChasingSound;
protected override void OnBegin(AiBlackboard blackboard) {
base.OnBegin(blackboard);
if (_obj == null) {
_obj = blackboard.Obj;
_selfController = _obj.GetComponent<HumanController>();
}
}
private void OnEndChasing() {
Debug.Log("Begin chasing");
if (endChasingSound != null) {
endChasingSound.Play();
}
}
private void OnBeginChasing() {
Debug.Log("End chasing");
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
float time;
if (!blackboard.GetValue(BlackboardVariables.LastSuspiciousTime, out time)) {
return BehaviorStatus.Fail;
}
//check if chasing too long
if (Time.time - time >= chaseTimeout) {
if (_chasing) {
_chasing = false;
OnEndChasing();
}
return BehaviorStatus.Fail;
}
//do chase!
if (!_chasing) {
_chasing = true;
OnBeginChasing();
}
Vector3 chaseTarget;
if (blackboard.GetValue(BlackboardVariables.LastEnemyPosition, out chaseTarget)) {
if (_selfController != null) {
float dir = Mathf.Sign(chaseTarget.x - _obj.transform.position.x);
if (Mathf.Abs(chaseTarget.x - _obj.transform.position.x) > 0.3f) {
_selfController.UpdateMovement(dir * _selfController.maxWalkSpeed);
}
}
}
return BehaviorStatus.Success;
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f00beff876f03384e8d2938e1e37b74f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
+16
View File
@@ -0,0 +1,16 @@
using UnityEngine;
using System.Collections;
public class AiDelay : AiBehavior {
public float delay = 1;
private float _startTime;
protected override void OnBegin(AiBlackboard blackboard) {
_startTime = Time.time;
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
return (_startTime + delay) > Time.time ? BehaviorStatus.Running : BehaviorStatus.Success;
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f55a86bc81f2e5447b675e80b521b328
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 75cff1be3576d61429363834ca95e010, type: 3}
userData:
assetBundleName:
+30
View File
@@ -0,0 +1,30 @@
using UnityEngine;
using System.Collections;
public class AiEquipGun : AiBehavior {
private GameObject obj;
private Inventory inventory;
private HumanController selfController;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (obj == null) {
blackboard.GetValue<GameObject>("gameobject", out obj);
inventory = obj.GetComponent<Inventory>();
selfController = obj.GetComponent<HumanController>();
}
if (selfController.GetSocket(ItemSocketType.Hands).AttachedItem == null) {
var weapon = inventory.QueryItem(null, "Gun", null);
if (weapon != null) {
//Debug.LogFormat("Character {0} equipped weapon {1}", obj.name, weapon.description.Name);
inventory.EquipItem(weapon);
}
else {
return BehaviorStatus.Fail;
}
}
return BehaviorStatus.Success;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6ad8bdf70f1755c44b33fb4286544f22
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+75
View File
@@ -0,0 +1,75 @@
using System.Linq;
using UnityEngine;
using System.Collections;
public class AiFindEnemy : AiBehavior {
private GameObject obj;
private PlayerSensor sensor;
private HumanController selfController;
public LayerMask skipMask;
protected override void OnBegin(AiBlackboard blackboard) {
base.OnBegin(blackboard);
if (obj == null) {
obj = blackboard.Obj;
sensor = obj.GetComponent<HumanoidAI>().viewSensor;
selfController = obj.GetComponent<HumanController>();
}
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
bool playerInCone = sensor.Player != null;
if (playerInCone) {
var enemyEyes = sensor.Player.eyes.transform.position;
var selfEyes = selfController.eyes.transform.position;
var from = new Vector3[] { selfEyes, selfEyes };
var to = new Vector3[] { enemyEyes, sensor.Player.transform.position };
for (int i = 0; i < 2; ++i) {
Debug.DrawLine(from[i], to[i], Color.gray);
}
for (int i = 0; i < 2; ++i) {
if (RaycastEnemy(from[i], to[i])) {
blackboard.SetValue(BlackboardVariables.Enemy, sensor.Player);
blackboard.SetValue(BlackboardVariables.LastEnemyPosition, sensor.Player.transform.position);
//Debug.Log("Raycast OK");
return BehaviorStatus.Success;
}
}
// Debug.Log("Raycast FAIL");
}
blackboard.SetValue(BlackboardVariables.Enemy, null);
return BehaviorStatus.Fail;
}
private bool RaycastEnemy(Vector3 from, Vector3 to) {
var hits = Physics2D.RaycastAll(from, (to - from).normalized, 100, (Physics2D.DefaultRaycastLayers & (~skipMask.value)));
//find first collision which is not inside player head
int firstOutsideId = -1;
for (int i = 0; i < hits.Length; ++i) {
if (hits[i].fraction > 0.0f) {
firstOutsideId = i;
break;
}
}
if (firstOutsideId >= 0) {
var hit = hits[firstOutsideId];
var g = hit.collider.GetComponent<PlayerController>();
if (g != null) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0a8a0b982bd08a5488a7c4999040b3e2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+15
View File
@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
public class AiHitDetector : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4ff1b2e8d41c5ab46bfc53c0c3cb1252
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+29
View File
@@ -0,0 +1,29 @@
using UnityEngine;
using System.Collections;
public class AiListenSounds : AiBehavior {
private AiSoundListener _listener;
private GameObject _obj;
protected override void OnBegin(AiBlackboard blackboard) {
base.OnBegin(blackboard);
if (_obj == null) {
_obj = blackboard.Obj;
_listener = _obj.GetComponent<AiSoundListener>();
}
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
var sound = _listener.LatestSound;
blackboard.SetValue(BlackboardVariables.LastSound, sound);
if (sound != null) {
blackboard.SetValue(BlackboardVariables.LastEnemyPosition, sound.transform.position);
blackboard.SetValue(BlackboardVariables.LastSuspiciousTime, Time.time);
}
return sound == null ? BehaviorStatus.Fail : BehaviorStatus.Success;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7e1f1556b659a8f458973a7c12bdc793
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
+37
View File
@@ -0,0 +1,37 @@
using UnityEngine;
using System.Collections;
public class AiPatrol : AiBehavior {
public AiWaypoint[] patrolPoints;
private int _targetPoint;
private GameObject targetObject;
private HumanController controller;
protected override void OnBegin(AiBlackboard blackboard) {
base.OnBegin(blackboard);
//_targetPoint = 0;
blackboard.GetValue("gameobject", out targetObject);
controller = targetObject.GetComponent<HumanController>();
}
private void NextPoint() {
_targetPoint = (_targetPoint + 1)%patrolPoints.Length;
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
var point = patrolPoints[_targetPoint];
var dir = (Vector2) point.transform.position - (Vector2) controller.transform.position;
if (controller.GetComponent<Health>().Dead) {
return BehaviorStatus.Success;
}
if (Mathf.Abs(dir.x) < 0.1f) {
NextPoint();
} else {
controller.UpdateMovement(Mathf.Sign(dir.x) * controller.maxWalkSpeed);
}
return BehaviorStatus.Running;
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0689ea7abd9f480449a528cc05fb0c0c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName:
@@ -0,0 +1,24 @@
using UnityEngine;
using System.Collections;
public class AiSaySomethingOnSound : AiBehavior {
public RandomSoundPlayer player;
private AiSound _lastSound;
private float _lastSloundTime;
public float minDelay = 3;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
AiSound sound;
blackboard.GetValue(BlackboardVariables.LastSound, out sound);
if (sound == null) {
return BehaviorStatus.Fail;
}
if (Time.time - _lastSloundTime >= minDelay) {
player.Play();
_lastSloundTime = Time.time;
Debug.Log("Saying!");
}
return BehaviorStatus.Success;
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 05fb3d4c5b2994e48a8d5836b3d82b3f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
+29
View File
@@ -0,0 +1,29 @@
using UnityEngine;
using System.Collections;
public class AiUseItem : AiBehavior {
private GameObject obj;
private HumanController selfController;
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (obj == null) {
obj = blackboard.Obj;
selfController = obj.GetComponent<HumanController>();
}
var item = selfController.GetSocket(ItemSocketType.Hands).AttachedItem;
if (item == null) {
return BehaviorStatus.Fail;
}
bool shouldCrouch = false;
blackboard.GetValue<bool>("crouchToShoot", out shouldCrouch);
selfController.Crouch = shouldCrouch;
item.OnBeginUse();
item.OnEndUse();
return BehaviorStatus.Success;
}
}
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4e969b77faa0f304abbd0a3faa55a3f2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d08017e60048a74ca44adc931b5cea0, type: 3}
userData:
assetBundleName: