Exemple #1
0
        public int PutItem(ItemData item, ItemData create, float duration, int quantity)
        {
            if (current_item == null || create == current_item)
            {
                if (current_quantity < quantity_max && quantity > 0)
                {
                    int max   = quantity_max - current_quantity;             //Maximum space remaining
                    int quant = Mathf.Min(max, quantity + current_quantity); //Cant put more than maximum

                    prev_item         = item;
                    current_item      = create;
                    current_quantity += quant;
                    timer             = 0f;
                    this.duration     = duration;

                    if (progress_prefab != null && duration > 0.1f)
                    {
                        GameObject obj = Instantiate(progress_prefab, transform);
                        progress        = obj.GetComponent <ActionProgress>();
                        progress.manual = true;
                    }

                    if (select.IsNearCamera(10f))
                    {
                        TheAudio.Get().PlaySFX("furnace", put_audio);
                    }

                    return(quant);  //Return actual quantity that was used
                }
            }
            return(0);
        }
Exemple #2
0
    public void TakeItem()
    {
        PlayerData pdata = PlayerData.Get();

        if (CanTakeItem())
        {
            int slot = pdata.AddItem(data.id, quantity); //Add to inventory

            if (was_dropped)
            {
                pdata.RemoveDroppedItem(unique_id.unique_id); //Removed from dropped items
            }
            else
            {
                pdata.RemoveObject(GetUID()); //Taken from map
            }
            Destroy(gameObject);

            //Take fx
            ItemTakeFX.DoTakeFX(transform.position, data, slot);

            TheAudio.Get().PlaySFX("item", take_audio);
            if (take_fx != null)
            {
                Instantiate(take_fx, transform.position, Quaternion.identity);
            }
        }
    }
        public override void DoAction(PlayerCharacter character, ItemSlot slot)
        {
            ItemData      item      = slot.GetItem();
            InventoryData inventory = slot.GetInventory();

            if (item != null && item.construction_data != null)
            {
                character.Crafting.CraftConstructionBuildMode(item.construction_data, false, (Buildable build) =>
                {
                    InventoryItemData invdata = inventory.GetItem(slot.index);
                    inventory.RemoveItemAt(slot.index, 1);

                    BuiltConstructionData constru = PlayerData.Get().GetConstructed(build.GetUID());
                    if (invdata != null && constru != null && item.HasDurability())
                    {
                        constru.durability = invdata.durability; //Save durability
                    }
                });

                TheAudio.Get().PlaySFX("craft", item.craft_sound);
            }

            if (item != null && item.character_data != null)
            {
                character.Crafting.CraftCharacterBuildMode(item.character_data, false, (Buildable build) =>
                {
                    InventoryItemData invdata = inventory.GetItem(slot.index);
                    inventory.RemoveItemAt(slot.index, 1);
                });

                TheAudio.Get().PlaySFX("craft", item.craft_sound);
            }
        }
Exemple #4
0
    //Deal damages to the destructible, if it reaches 0 HP it will be killed
    public void TakeDamage(int damage)
    {
        if (!dead)
        {
            int adamage = Mathf.Max(damage - armor, 1);
            hp -= adamage;

            if (onDamaged != null)
            {
                onDamaged.Invoke();
            }

            if (shake_on_hit)
            {
                ShakeFX();
            }

            if (hp <= 0)
            {
                Kill();
            }

            TheAudio.Get().PlaySFX("destruct", hit_sound);
        }
    }
Exemple #5
0
    public void FinishContruction()
    {
        building_mode      = false;
        is_overlap         = false;
        selectable.enabled = true;
        foreach (Collider collide in colliders)
        {
            collide.isTrigger = false;
        }

        destruct = GetComponent <Destructible>();
        if (destruct)
        {
            destruct.enabled   = true;
            destruct.was_built = true;
        }

        SetModelColor(Color.white);

        BuiltConstructionData cdata = PlayerData.Get().AddConstruction(data.id, SceneNav.GetCurrentScene(), transform.position);

        unique_id.unique_id = cdata.uid;

        if (build_fx != null)
        {
            Instantiate(build_fx, transform.position, Quaternion.identity);
        }
        TheAudio.Get().PlaySFX("construction", build_audio);

        if (onBuild != null)
        {
            onBuild.Invoke();
        }
    }
Exemple #6
0
    private IEnumerator GatherRun(PlayerCharacter character)
    {
        is_taking = true;

        GameObject source = fruit_model != null ? fruit_model.gameObject : gameObject;

        character.GainItem(source, fruit, 1);

        yield return(new WaitForSeconds(0.4f));

        has_fruit = false;
        PlayerData.Get().SetUniqueID(GetFruitUID(), 0);

        if (death_on_harvest && destruct != null)
        {
            destruct.Kill();
        }

        TheAudio.Get().PlaySFX("plant", gather_audio);

        if (gather_fx != null)
        {
            Instantiate(gather_fx, transform.position, Quaternion.identity);
        }

        is_taking = false;
    }
Exemple #7
0
        public void FinishItem()
        {
            if (current_item != null)
            {
                Item.Create(current_item, spawn_point.transform.position, current_quantity);

                prev_item        = null;
                current_item     = null;
                current_quantity = 0;
                timer            = 0f;

                if (active_fx != null)
                {
                    active_fx.SetActive(false);
                }

                if (progress != null)
                {
                    Destroy(progress.gameObject);
                }

                if (select.IsNearCamera(10f))
                {
                    TheAudio.Get().PlaySFX("furnace", finish_audio);
                }
            }
        }
Exemple #8
0
        //Deal damages to the destructible, if it reaches 0 HP it will be killed
        private void ApplyDamage(int damage)
        {
            if (!dead)
            {
                int adamage = Mathf.Max(damage - armor, 1);
                hp -= adamage;

                PlayerData.Get().SetCustomValue(GetHpUID(), hp);

                if (shake_on_hit)
                {
                    ShakeFX();
                }

                if (select.IsActive() && select.IsNearCamera(20f))
                {
                    if (hit_fx != null)
                    {
                        Instantiate(hit_fx, transform.position, Quaternion.identity);
                    }

                    TheAudio.Get().PlaySFX("destruct", hit_sound);
                }

                onDamaged?.Invoke();
            }
        }
    public void SelectCraftConstruction(ConstructionData item)
    {
        current_construction = Construction.CreateBuildMode(item, transform.position);
        current_construction.StartConstruction();
        clicked_build = false;

        TheAudio.Get().PlaySFX("craft", item.craft_sound);
    }
Exemple #10
0
        private void KillFX()
        {
            //FX
            if (select.IsActive() && select.IsNearCamera(20f))
            {
                if (death_fx != null)
                {
                    Instantiate(death_fx, transform.position, Quaternion.identity);
                }

                TheAudio.Get().PlaySFX("destruct", death_sound);
            }
        }
Exemple #11
0
    public void OnClickPause()
    {
        if (TheGame.Get().IsPaused())
        {
            TheGame.Get().Unpause();
        }
        else
        {
            TheGame.Get().Pause();
        }

        TheAudio.Get().PlaySFX("UI", ui_sound);
    }
Exemple #12
0
    //Kill the destructible
    public void Kill()
    {
        if (!dead)
        {
            dead = true;

            foreach (Collider collide in colliders)
            {
                collide.enabled = false;
            }

            //Loot
            foreach (CraftData item in loots)
            {
                float   radius = Random.Range(0.5f, 1f);
                float   angle  = Random.Range(0f, 360f) * Mathf.Rad2Deg;
                Vector3 pos    = transform.position + new Vector3(Mathf.Cos(angle), 0f, Mathf.Sin(angle)) * radius;
                if (item is ItemData)
                {
                    Item.Create((ItemData)item, pos, 1);
                }
                if (item is ConstructionData)
                {
                    Construction construct = Construction.Create((ConstructionData)item, pos);
                    construct.FinishContruction();
                }
            }

            if (!was_built)
            {
                PlayerData.Get().RemoveObject(GetUID());
            }

            if (onDeath != null)
            {
                onDeath.Invoke();
            }

            //FX
            if (death_fx != null)
            {
                Instantiate(death_fx, transform.position, Quaternion.identity);
            }

            TheAudio.Get().PlaySFX("destruct", death_sound);

            select.Destroy(destroy_delay);
        }
    }
Exemple #13
0
    private IEnumerator TakeItemRun()
    {
        is_taking = true;
        yield return(new WaitForSeconds(0.4f));

        if (nb_item > 0)
        {
            nb_item--;
        }

        PlayerData.Get().SetUniqueID(GetAmountUID(), nb_item);
        is_taking = false;

        TheAudio.Get().PlaySFX("item", take_sound);
    }
        public void TakeItem()
        {
            if (onTake != null)
            {
                onTake.Invoke();
            }

            DestroyItem();

            TheAudio.Get().PlaySFX("item", take_audio);
            if (take_fx != null)
            {
                Instantiate(take_fx, transform.position, Quaternion.identity);
            }
        }
Exemple #15
0
        public override void DoAction(PlayerCharacter character, ItemSlot slot)
        {
            ItemData      item      = slot.GetItem();
            InventoryData inventory = slot.GetInventory();

            if (item != null && item.plant_data != null)
            {
                character.Crafting.CraftPlantBuildMode(item.plant_data, 0, false, (Buildable build) =>
                {
                    inventory.RemoveItemAt(slot.index, 1);
                });

                TheAudio.Get().PlaySFX("craft", item.craft_sound);
            }
        }
        public void CompleteBuilding(Vector3 pos)
        {
            CraftData item = current_crafting;

            if (item != null && current_buildable != null && (!build_pay_cost || CanCraft(item, true)))
            {
                current_buildable.SetBuildPositionTemporary(pos); //Set to position to test the condition, before applying it

                if (current_buildable.CheckIfCanBuild())
                {
                    current_buildable.SetBuildPosition(pos);

                    character.FaceTorward(pos);

                    if (build_pay_cost)
                    {
                        PayCraftingCost(item);
                    }

                    Buildable buildable = current_buildable;
                    buildable.FinishBuild();

                    character.Data.AddCraftCount(item.id);

                    UnityAction <Buildable> bcallback = build_callback;
                    current_buildable  = null;
                    current_build_data = null;
                    build_callback     = null;
                    clicked_build      = false;
                    character.StopAutoMove();

                    PlayerUI.Get(character.player_id)?.CancelSelection();
                    TheAudio.Get().PlaySFX("craft", buildable.build_audio);

                    if (onBuild != null)
                    {
                        onBuild.Invoke(buildable);
                    }

                    if (bcallback != null)
                    {
                        bcallback.Invoke(buildable);
                    }

                    character.TriggerAction(1f);
                }
            }
        }
        public override void DoAction(PlayerCharacter character, ItemSlot slot)
        {
            foreach (CraftData data in learn_list)
            {
                character.Crafting.LearnCraft(data.id);
            }

            TheAudio.Get().PlaySFX("learn", learn_audio);

            InventoryData inventory = slot.GetInventory();

            if (destroy_on_learn)
            {
                inventory.RemoveItemAt(slot.index, 1);
            }

            CraftSubPanel.Get(character.player_id)?.RefreshCraftPanel();
        }
 private void StartSwim()
 {
     if (!is_swimming)
     {
         is_swimming     = true;
         swim_mesh_tpos += Vector3.up * swim_offset_y;
         if (swim_start_fx != null)
         {
             Instantiate(swim_start_fx, transform.position, swim_start_fx.transform.rotation);
         }
         if (swimming_fx != null)
         {
             swimming_fx.SetActive(true);
         }
         character.TriggerAction(0.25f);
         TheAudio.Get().PlaySFX("character", swim_start_audio);
     }
 }
        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 void CraftPlant(PlantData plant)
    {
        if (CanCraft(plant))
        {
            CraftCostData cost = plant.GetCraftCost();
            foreach (KeyValuePair <ItemData, int> pair in cost.craft_items)
            {
                PlayerData.Get().RemoveItem(pair.Key.id, pair.Value);
                if (pair.Key.container_data)
                {
                    PlayerData.Get().AddItem(pair.Key.container_data.id, pair.Value);
                }
            }
            Vector3 pos = transform.position + transform.forward * 0.4f;
            Plant.Create(plant, pos, 0);

            TheAudio.Get().PlaySFX("craft", plant.craft_sound);
        }
    }
Exemple #21
0
    void Update()
    {
        if (TheGame.Get().IsPaused())
        {
            return;
        }

        //Check if dead
        PlayerCharacter character = PlayerCharacter.Get();

        if (character.IsDead())
        {
            death_timer += Time.deltaTime;
            if (death_timer > 2f)
            {
                enabled = false; //Stop running this loop
                TheUI.Get().ShowGameOver();
            }
        }

        //Game time
        PlayerData pdata       = PlayerData.Get();
        GameData   gdata       = GameData.Get();
        float      game_speed  = GameData.Get().game_time_mult;
        float      hour_to_sec = game_speed / 3600f;

        pdata.day_time += hour_to_sec * Time.deltaTime;
        if (pdata.day_time >= 24f)
        {
            pdata.day_time = 0f;
            pdata.day++; //New day
        }

        //Set music
        AudioClip[] music_playlist = GameData.Get().music_playlist;
        if (music_playlist.Length > 0 && !TheAudio.Get().IsMusicPlaying("music"))
        {
            AudioClip clip = music_playlist[Random.Range(0, music_playlist.Length)];
            TheAudio.Get().PlayMusic("music", clip, 0.4f, false);
        }
    }
    public void TakeDamage(int damage)
    {
        if (is_dead)
        {
            return;
        }

        int dam = damage - GetArmor();

        dam = Mathf.Max(dam, 1);

        PlayerData.Get().AddAttributeValue(AttributeType.Health, -dam, GetAttributeMax(AttributeType.Health));

        TheCamera.Get().Shake();
        TheAudio.Get().PlaySFX("character", hit_sound);

        if (onDamaged != null)
        {
            onDamaged.Invoke();
        }
    }
        public void BuildItem(InventoryData inventory, int slot)
        {
            InventoryItemData invdata = inventory?.GetItem(slot);
            ItemData          idata   = ItemData.Get(invdata?.item_id);

            if (invdata != null && idata != null)
            {
                ConstructionData construct  = idata.construction_data;
                PlantData        aplant     = idata.plant_data;
                CharacterData    acharacter = idata.character_data;

                if (construct != null)
                {
                    inventory.RemoveItemAt(slot, 1);
                    Construction          construction = character.Crafting.CraftConstruction(construct, false);
                    BuiltConstructionData constru      = PlayerData.Get().GetConstructed(construction.GetUID());
                    if (idata.HasDurability())
                    {
                        constru.durability = invdata.durability; //Save durability
                    }
                    TheAudio.Get().PlaySFX("craft", construction.GetBuildable().build_audio);
                }

                else if (aplant != null)
                {
                    inventory.RemoveItemAt(slot, 1);
                    Plant plant = character.Crafting.CraftPlant(aplant, 0, false);
                    TheAudio.Get().PlaySFX("craft", plant.GetBuildable().build_audio);
                }

                else if (acharacter != null)
                {
                    inventory.RemoveItemAt(slot, 1);
                    Character charact = character.Crafting.CraftCharacter(acharacter, false);
                    TheAudio.Get().PlaySFX("craft", charact.GetBuildable().build_audio);
                }

                PlayerUI.Get(character.player_id)?.CancelSelection();
            }
        }
        public void TakeDamage(int damage)
        {
            if (is_dead)
            {
                return;
            }

            if (character.Attributes.GetBonusEffectTotal(BonusType.Invulnerable) > 0.5f)
            {
                return;
            }

            int dam = damage - GetArmor();

            dam = Mathf.Max(dam, 1);

            int invuln = Mathf.RoundToInt(dam * character.Attributes.GetBonusEffectTotal(BonusType.Invulnerable));

            dam = dam - invuln;

            if (dam <= 0)
            {
                return;
            }

            character_attr.AddAttribute(AttributeType.Health, -dam);

            //Durability
            character.Inventory.UpdateAllEquippedItemsDurability(false, -1f);

            character.StopSleep();

            TheCamera.Get().Shake();
            TheAudio.Get().PlaySFX("player", hit_sound);

            if (onDamaged != null)
            {
                onDamaged.Invoke();
            }
        }
        public void Harvest(PlayerCharacter character)
        {
            if (fruit != null && has_fruit && character.Inventory.CanTakeItem(fruit, 1))
            {
                GameObject source = fruit_model != null ? fruit_model.gameObject : gameObject;
                character.Inventory.GainItem(fruit, 1, source.transform.position);

                RemoveFruit();

                if (death_on_harvest && destruct != null)
                {
                    destruct.Kill();
                }

                TheAudio.Get().PlaySFX("plant", gather_audio);

                if (gather_fx != null)
                {
                    Instantiate(gather_fx, transform.position, Quaternion.identity);
                }
            }
        }
    public void CraftItem(ItemData item)
    {
        if (CanCraft(item) && PlayerData.Get().CanTakeItem(item.id, 1))
        {
            CraftCostData cost = item.GetCraftCost();
            foreach (KeyValuePair <ItemData, int> pair in cost.craft_items)
            {
                PlayerData.Get().RemoveItem(pair.Key.id, pair.Value);
            }
            PlayerData.Get().AddItem(item.id, 1);

            //Gain container back after gaining the craft item
            foreach (KeyValuePair <ItemData, int> pair in cost.craft_items)
            {
                if (pair.Key.container_data)
                {
                    PlayerData.Get().AddItem(pair.Key.container_data.id, pair.Value);
                }
            }

            TheAudio.Get().PlaySFX("craft", item.craft_sound);
        }
    }
        //----- Craftin process -----

        public void StartCraftingOrBuilding(CraftData data)
        {
            if (CanCraft(data))
            {
                ConstructionData construct = data.GetConstruction();
                PlantData        plant     = data.GetPlant();

                if (construct != null)
                {
                    CraftConstructionBuildMode(construct);
                }
                else if (plant != null)
                {
                    CraftPlantBuildMode(plant, 0);
                }
                else
                {
                    StartCrafting(data);
                }

                TheAudio.Get().PlaySFX("craft", data.craft_sound);
            }
        }
Exemple #28
0
 private void OnPlayMusic(string channel, AudioClip clip, float vol = 0.4f)
 {
     TheAudio.Get().PlayMusic(channel, clip, vol);
 }
Exemple #29
0
 private void OnStopMusic(string channel)
 {
     TheAudio.Get().StopMusic(channel);
 }
Exemple #30
0
 private void OnPlaySFX(string channel, AudioClip clip, float vol = 0.8f)
 {
     TheAudio.Get().PlaySFX(channel, clip, vol);
 }