public virtual IEnumerator Attack(Responsible responsible)
        {
            Coroutine coroutine = null;
            Weapon    weapon    = responsible.Equipment.Weapon;

            weapon.SetTarget(gameObject);

            while (health > 0)
            {
                if (weapon == null)
                {
                    break;
                }
                if (weapon.CheckTargetInRange())
                {
                    if (coroutine != null)
                    {
                        StopCoroutine(coroutine);
                        coroutine = null;
                    }

                    responsible.StopWalking();
                    yield return(StartCoroutine(responsible.Turn()));

                    if (Jobs.Count != 0 && !Jobs[0].Target.Equals(responsible) && Behaviour.autoWill)
                    {
                        JobManager.AddJob(new Job(new JobInfo(this, responsible, responsible.GetType().GetMethod("Attack"), new object [] { this })));
                        FinishJob(true);
                    }

                    yield return(weapon.Use());
                }

                if (coroutine == null)
                {
                    coroutine = StartCoroutine(responsible.Walk(weapon.GetInRangePosition(), true));
                }

                yield return(null);
            }

            responsible.GetComponent <Responsible>().FinishJob();
        }
Esempio n. 2
0
        public MethodInfo FindAllowedAction(Responsible responsible, ActivityType activityType)
        {
            MethodInfo methodInfo = null;

            if (Methods == null || Methods.Count == 0)
            {
                return(null);
            }

            foreach (var method in Methods)
            {
                if (IsActivityAllowed(method, activityType) && CanInteractWith(method, responsible))
                {
                    methodInfo = method;
                }
            }

            return(methodInfo);
        }
Esempio n. 3
0
        private bool CanInteractWith(MethodInfo method, Responsible responsible)
        {
            InteractableAttribute[] interactableAttributes =
                System.Attribute.GetCustomAttributes(method, typeof(InteractableAttribute)) as InteractableAttribute [];

            if (interactableAttributes != null && interactableAttributes.Length <= 0)
            {
                return(false);
            }

            foreach (var attribute in interactableAttributes)
            {
                if (attribute.InteractableType == responsible.GetType() || attribute.InteractableType == responsible.GetType().BaseType)
                {
                    return(true);
                }
            }

            return(false);
        }