public override void DoAction(PlayerCharacter character, Selectable select)
        {
            PlayerData   pdata        = PlayerData.Get();
            Construction construction = select.GetComponent <Construction>();

            if (construction != null)
            {
                ItemData      take_item = construction.data.take_item_data;
                InventoryData inv_data  = character.Inventory.GetValidInventory(take_item, 1);
                if (take_item != null && inv_data != null)
                {
                    BuiltConstructionData bdata = pdata.GetConstructed(construction.GetUID());
                    float durability            = bdata != null ? bdata.durability : take_item.durability;

                    inv_data.AddItem(take_item.id, 1, durability, select.GetUID());
                    select.Destroy();
                }
            }

            Character acharacter = select.GetComponent <Character>();

            if (acharacter != null)
            {
                ItemData      take_item = acharacter.data.take_item_data;
                InventoryData inv_data  = character.Inventory.GetValidInventory(take_item, 1);
                if (take_item != null && inv_data != null)
                {
                    TrainedCharacterData cdata = pdata.GetCharacter(acharacter.GetUID());
                    inv_data.AddItem(take_item.id, 1, take_item.durability, select.GetUID());
                    select.Destroy();
                }
            }
        }
Esempio n. 2
0
        public override void DoAction(PlayerCharacter character, Selectable select)
        {
            InventoryItemData item  = character.EquipData.GetFirstItemInGroup(required_item);
            ItemData          idata = ItemData.Get(item?.item_id);
            Plant             plant = select.GetComponent <Plant>();

            if (idata != null && plant != null)
            {
                //Remove water
                if (idata.durability_type == DurabilityType.UsageCount)
                {
                    item.durability -= 1f;
                }
                else
                {
                    character.Inventory.RemoveEquipItem(idata.equip_slot);
                }

                //Add to plant
                plant.AddWater(character);

                string animation = character.Animation ? character.Animation.water_anim : "";
                character.TriggerAnim(animation, plant.transform.position, 1f);
                character.TriggerProgressAction(1f);
            }
        }
Esempio n. 3
0
        public override bool CanDoAction(PlayerCharacter character, ItemSlot slot, Selectable select)
        {
            Furnace           furnace   = select.GetComponent <Furnace>();
            InventoryData     inventory = slot.GetInventory();
            InventoryItemData iidata    = inventory?.GetItem(slot.index);

            return(furnace != null && iidata != null && furnace.CountItemSpace() > 0 && melt_item_quantity > 0);
        }
Esempio n. 4
0
        public override void DoAction(PlayerCharacter character, Selectable select)
        {
            Storage storage = select.GetComponent <Storage>();

            if (storage != null)
            {
                storage.OpenStorage(character);
            }
        }
        public override void DoAction(PlayerCharacter character, Selectable select)
        {
            AnimalRide ride = select.GetComponent <AnimalRide>();

            if (ride != null)
            {
                character.RideAnimal(ride);
            }
        }
        public override void DoAction(PlayerCharacter character, Selectable select)
        {
            Trap trap = select.GetComponent <Trap>();

            if (trap != null)
            {
                trap.Activate();
            }
        }
        public override void DoAction(PlayerCharacter character, Selectable select)
        {
            Construction construct = select.GetComponent <Construction>();

            if (construct != null)
            {
                character.Sleep(this);
            }
        }
        public override bool CanDoAction(PlayerCharacter character, Selectable select)
        {
            Plant plant = select.GetComponent <Plant>();

            if (plant != null)
            {
                return(plant.HasFruit());
            }
            return(false);
        }
        public override bool CanDoAction(PlayerCharacter character, Selectable select)
        {
            Trap trap = select.GetComponent <Trap>();

            if (trap != null)
            {
                return(!trap.IsActive());
            }
            return(false);
        }
        //Merge action
        public override void DoAction(PlayerCharacter character, ItemSlot slot, Selectable select)
        {
            Firepit       fire      = select.GetComponent <Firepit>();
            InventoryData inventory = slot.GetInventory();

            if (fire != null && slot.GetItem() && inventory.HasItem(slot.GetItem().id))
            {
                fire.AddFuel(fire.wood_add_fuel);
                inventory.RemoveItemAt(slot.index, 1);
            }
        }
Esempio n. 11
0
        public override void DoAction(PlayerCharacter character, ItemSlot slot, Selectable select)
        {
            if (select.HasGroup(merge_target))
            {
                ItemProvider  provider  = select.GetComponent <ItemProvider>();
                InventoryData inventory = slot.GetInventory();

                provider.RemoveItem();
                provider.PlayTakeSound();
                inventory.RemoveItemAt(slot.index, 1);
                character.Inventory.GainItem(inventory, filled_item, 1);
            }
        }
        public override void DoAction(PlayerCharacter character, Selectable select)
        {
            Plant plant = select.GetComponent <Plant>();

            if (plant != null)
            {
                string animation = character.Animation ? character.Animation.take_anim : "";
                character.TriggerAnim(animation, plant.transform.position);
                character.TriggerAction(0.5f, () =>
                {
                    plant.Harvest(character);
                });
            }
        }
Esempio n. 13
0
        public float duration         = 1f; //In game hours

        //Merge action
        public override void DoAction(PlayerCharacter character, ItemSlot slot, Selectable select)
        {
            InventoryData     inventory = slot.GetInventory();
            InventoryItemData iidata    = inventory.GetItem(slot.index);

            Furnace furnace = select.GetComponent <Furnace>();

            if (furnace != null && furnace.CountItemSpace() > 0)
            {
                int create_quantity = Mathf.FloorToInt(iidata.quantity / (float)melt_item_quantity);
                int quantity        = furnace.PutItem(slot.GetItem(), melt_item, duration, create_quantity);
                inventory.RemoveItemAt(slot.index, quantity * melt_item_quantity);
            }
        }
        public override void DoAction(PlayerCharacter character, Selectable select)
        {
            if (select != null)
            {
                character.FaceTorward(select.transform.position);

                ItemProvider pond = select.GetComponent <ItemProvider>();
                if (pond != null)
                {
                    if (pond.HasItem())
                    {
                        character.FishItem(pond, 1);
                    }
                }
            }
        }
        public override void DoAction(PlayerCharacter character, Selectable select)
        {
            Plant plant = select.GetComponent <Plant>();

            if (plant != null)
            {
                string animation = character.Animation ? character.Animation.take_anim : "";
                character.TriggerAnim(animation, plant.transform.position);
                character.TriggerAction(0.5f, () =>
                {
                    plant.GrowPlant(0);

                    Destructible destruct = plant.GetDestructible();
                    TheAudio.Get().PlaySFX("destruct", destruct.death_sound);

                    destruct.SpawnLoots();
                });
            }
        }
        public override void DoAction(PlayerCharacter character, Selectable select)
        {
            DigSpot spot = select.GetComponent <DigSpot>();

            if (spot != null)
            {
                string animation = character.Animation ? character.Animation.dig_anim : "";
                character.TriggerAnim(animation, spot.transform.position);
                character.TriggerProgressAction(1.5f, () =>
                {
                    spot.Dig();

                    InventoryItemData ivdata = character.EquipData.GetFirstItemInGroup(required_item);
                    if (ivdata != null)
                    {
                        ivdata.durability -= 1;
                    }
                });
            }
        }
Esempio n. 17
0
        public override bool CanDoAction(PlayerCharacter character, Selectable select)
        {
            Plant plant = select.GetComponent <Plant>();

            return(plant != null && character.EquipData.HasItemInGroup(required_item));
        }
Esempio n. 18
0
 public override bool CanDoAction(PlayerCharacter character, Selectable select)
 {
     return(select.GetComponent <Storage>() != null);
 }
        //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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 public override bool CanDoAction(PlayerCharacter character, Selectable select)
 {
     return(select.GetComponent <Plant>());
 }
        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());
        }
Esempio n. 22
0
        public override bool CanDoAction(PlayerCharacter character, ItemSlot slot, Selectable select)
        {
            ItemProvider provider = select != null?select.GetComponent <ItemProvider>() : null;

            return(provider != null && provider.HasItem());
        }
        public override bool CanDoAction(PlayerCharacter character, Selectable select)
        {
            AnimalRide ride = select.GetComponent <AnimalRide>();

            return(ride != null && !ride.IsDead());
        }