public override void DoAction(PlayerCharacter character, Selectable select)
 {
     if (select.GetDestructible())
     {
         character.Attack(select.GetDestructible());
     }
 }
        private void OnClickObject(Selectable selectable, Vector3 pos)
        {
            if (!controls_enabled)
            {
                return;
            }

            if (selectable == null)
            {
                return;
            }

            if (character_craft.IsBuildMode())
            {
                OnClickFloor(pos);
                return;
            }

            if (is_action && can_cancel_action)
            {
                CancelAction();
            }

            selectable.Select();

            //Attack target ?
            Destructible target = selectable.GetDestructible();

            if (target != null && character_combat.CanAutoAttack(target))
            {
                Attack(target);
            }
            else
            {
                InteractWith(selectable, pos);
            }
        }
 public override bool CanDoAction(PlayerCharacter character, Selectable select)
 {
     return(select.GetDestructible() && !select.GetDestructible().IsDead());
 }
 public override void DoAction(PlayerCharacter character, Selectable select)
 {
     select.GetDestructible().KillIn(0.5f);
     character.TriggerAnim(animation, select.transform.position);
     character.TriggerAction(0.5f);
 }
        //Detect if the player is in vision
        private void DetectThreat(float range)
        {
            Vector3 pos = transform.position;

            //React to player
            float min_dist = range;

            foreach (PlayerCharacter player in PlayerCharacter.GetAll())
            {
                Vector3 char_dir = (player.transform.position - pos);
                float   dist     = char_dir.magnitude;
                if (dist < min_dist)
                {
                    float dangle = detect_angle / 2f; // /2 for each side
                    float angle  = Vector3.Angle(transform.forward, char_dir.normalized);
                    if (angle < dangle || char_dir.magnitude < detect_360_range)
                    {
                        player_target = player;
                        attack_target = null;
                        min_dist      = dist;
                    }
                }
            }

            //React to other characters/destructibles
            foreach (Selectable selectable in Selectable.GetAllActive())
            {
                if (selectable.gameObject != gameObject)
                {
                    Vector3 dir = (selectable.transform.position - pos);
                    if (dir.magnitude < min_dist)
                    {
                        float dangle = detect_angle / 2f; // /2 for each side
                        float angle  = Vector3.Angle(transform.forward, dir.normalized);
                        if (angle < dangle || dir.magnitude < detect_360_range)
                        {
                            //Find destructible to attack
                            if (HasAttackBehavior())
                            {
                                Destructible destruct = selectable.GetDestructible();
                                if (destruct && (destruct.attack_group == AttackGroup.Ally || destruct.attack_group == AttackGroup.Enemy)) //Attack by default (not neutral)
                                {
                                    if (destruct.attack_group == AttackGroup.Ally || destruct.team_group != this.destruct.team_group)      //Is not in same team
                                    {
                                        attack_target = destruct;
                                        player_target = null;
                                        min_dist      = dir.magnitude;
                                    }
                                }
                            }

                            //Find character to escape from
                            if (HasEscapeBehavior())
                            {
                                Character character = selectable.GetComponent <Character>();
                                if (character && character.attack_enabled)                                  //Only afraid if the character can attack
                                {
                                    if (character.GetDestructible().team_group != this.destruct.team_group) //Not afraid if in same team
                                    {
                                        attack_target = destruct;
                                        player_target = null;
                                        min_dist      = dir.magnitude;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }