public override bool CanDoAction(PlayerCharacter character, Selectable select)
 {
     return(select.GetComponent <Plant>());
 }
        //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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 //When using an action on a Selectable in the scene
 public virtual void DoAction(PlayerCharacter character, Selectable select)
 {
 }
 //Condition to check if the action is possible, override to add a condition
 public virtual bool CanDoAction(PlayerCharacter character, Selectable select)
 {
     return(true); //No condition
 }
 protected virtual void Awake()
 {
     craftable_list.Add(this);
     cselect = GetComponent <Selectable>();
 }
Exemple #6
0
 void Awake()
 {
     furnace_list.Add(this);
     select = GetComponent <Selectable>();
 }
Exemple #7
0
 public override void Hide(bool instant = false)
 {
     base.Hide(instant);
     target = null;
 }
Exemple #8
0
 public override bool CanDoAction(PlayerCharacter character, Selectable select)
 {
     return(select.GetComponent <Storage>() != null);
 }
        public override bool CanDoAction(PlayerCharacter character, Selectable select)
        {
            AnimalRide ride = select.GetComponent <AnimalRide>();

            return(ride != null && !ride.IsDead());
        }
Exemple #10
0
        void Start()
        {
            select = GetComponent <Selectable>();

            select.onUse += OnUse;
        }
 //Condition when mergin item-select, override if you need to add a new condition
 public virtual bool CanDoAction(PlayerCharacter character, ItemSlot slot, Selectable select)
 {
     return(select != null && select.HasGroup(merge_target));
 }
 public override bool CanDoAction(PlayerCharacter character, Selectable select)
 {
     return(character.EquipData.HasItemInGroup(required_item));
 }
        public override bool CanDoAction(PlayerCharacter character, Selectable select)
        {
            ItemProvider pond = select.GetComponent <ItemProvider>();

            return(pond != null && pond.HasItem() && character.EquipData.HasItemInGroup(fishing_rod) && !character.IsSwimming());
        }
Exemple #14
0
 //When using an action on a Selectable in the scene
 public override void DoAction(PlayerCharacter character, Selectable select)
 {
 }
Exemple #15
0
 void Awake()
 {
     lure_list.Add(this);
     selectable = GetComponent <Selectable>();
 }
Exemple #16
0
 //Condition to check if the action is possible, override to add a condition
 public override bool CanDoAction(PlayerCharacter character, Selectable select)
 {
     return(true);
 }
 void Start()
 {
     select    = GetComponent <Selectable>();
     start_rot = chest_lid.localRotation;
 }