31 lines
991 B
C#
31 lines
991 B
C#
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;
|
|
}
|
|
}
|