public static GameObject Create(CraftData data, Vector3 pos, PlayerCharacter owner)
        {
            if (data is ItemData)
            {
                ItemData item = (ItemData)data;
                Item     obj  = Item.Create(item, pos, 1);
                return(obj.gameObject);
            }

            if (data is PlantData)
            {
                PlantData item = (PlantData)data;
                Plant     obj  = Plant.Create(item, pos, -1);
                return(obj.gameObject);
            }

            if (data is ConstructionData)
            {
                ConstructionData item = (ConstructionData)data;
                Construction     obj  = Construction.Create(item, pos);
                return(obj.gameObject);
            }

            if (data is CharacterData)
            {
                CharacterData item = (CharacterData)data;
                Character     obj  = Character.Create(item, pos);
                return(obj.gameObject);
            }

            return(null);
        }
Exemplo n.º 2
0
        //Create a totally new one that will be added to save file, already constructed
        public static Construction Create(ConstructionData data, Vector3 pos)
        {
            Construction construct = CreateBuildMode(data, pos);

            construct.buildable.FinishBuild();
            return(construct);
        }
Exemplo n.º 3
0
        public static Construction Create(ConstructionData data, Vector3 pos, Quaternion rot)
        {
            Construction construct = CreateBuildMode(data, pos);

            construct.transform.rotation = rot;
            construct.buildable.FinishBuild();
            return(construct);
        }
Exemplo n.º 4
0
        //Create a totally new one that will be added to save file, but only after constructed by the player
        public static Construction CreateBuildMode(ConstructionData data, Vector3 pos)
        {
            GameObject   build     = Instantiate(data.construction_prefab, pos, data.construction_prefab.transform.rotation);
            Construction construct = build.GetComponent <Construction>();

            construct.data        = data;
            construct.was_spawned = true;
            return(construct);
        }
Exemplo n.º 5
0
        public static List <Construction> GetAllOf(ConstructionData data)
        {
            List <Construction> valid_list = new List <Construction>();

            foreach (Construction construct in construct_list)
            {
                if (construct.data == data)
                {
                    valid_list.Add(construct);
                }
            }
            return(valid_list);
        }
        public void CraftConstructionBuildMode(ConstructionData item, bool pay_craft_cost = true, UnityAction <Buildable> callback = null)
        {
            if (!pay_craft_cost || CanCraft(item))
            {
                CancelCrafting();

                Construction construction = Construction.CreateBuildMode(item, transform.position + transform.forward * 1f);
                current_buildable = construction.GetBuildable();
                current_buildable.StartBuild(character);
                current_build_data = item;
                clicked_build      = false;
                build_pay_cost     = pay_craft_cost;
                build_callback     = callback;
                build_timer        = 0f;
            }
        }
Exemplo n.º 7
0
        public static int CountInRange(ConstructionData data, Vector3 pos, float range)
        {
            int count = 0;

            foreach (Construction construct in GetAll())
            {
                if (construct.data == data && construct.IsBuilt())
                {
                    float dist = (construct.transform.position - pos).magnitude;
                    if (dist < range)
                    {
                        count++;
                    }
                }
            }
            return(count);
        }
Exemplo n.º 8
0
        public void SpawnLoot(CraftData item, int quantity = 1)
        {
            Vector3 pos = GetLootRandomPos();

            if (item is ItemData)
            {
                ItemData aitem = (ItemData)item;
                Item.Create(aitem, pos, quantity);
            }
            if (item is ConstructionData)
            {
                ConstructionData construct_data = (ConstructionData)item;
                Construction.Create(construct_data, pos);
            }
            if (item is PlantData)
            {
                PlantData plant_data = (PlantData)item;
                Plant.Create(plant_data, pos, 0);
            }
        }
Exemplo n.º 9
0
        //Spawn an existing one in the save file (such as after loading)
        public static Construction Spawn(string uid, Transform parent = null)
        {
            BuiltConstructionData bdata = PlayerData.Get().GetConstructed(uid);

            if (bdata != null && bdata.scene == SceneNav.GetCurrentScene())
            {
                ConstructionData cdata = ConstructionData.Get(bdata.construction_id);
                if (cdata != null)
                {
                    GameObject build = Instantiate(cdata.construction_prefab, bdata.pos, bdata.rot);
                    build.transform.parent = parent;

                    Construction construct = build.GetComponent <Construction>();
                    construct.data                = cdata;
                    construct.was_spawned         = true;
                    construct.unique_id.unique_id = uid;
                    return(construct);
                }
            }
            return(null);
        }
        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 Construction CraftConstruction(ConstructionData construct, bool pay_craft_cost = true)
        {
            if (!pay_craft_cost || CanCraft(construct))
            {
                if (pay_craft_cost)
                {
                    PayCraftingCost(construct);
                }

                Vector3      pos        = transform.position + transform.forward * 1f;
                Construction aconstruct = Construction.Create(construct, pos);

                character.Data.AddCraftCount(construct.id);

                if (onCraft != null)
                {
                    onCraft.Invoke(construct);
                }

                return(aconstruct);
            }
            return(null);
        }
        //----- 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);
            }
        }
        //----- Crafting Completion -----

        //Craft immediately
        public void CraftCraftable(CraftData data)
        {
            ItemData         item      = data.GetItem();
            ConstructionData construct = data.GetConstruction();
            PlantData        plant     = data.GetPlant();
            CharacterData    character = data.GetCharacter();

            if (item != null)
            {
                CraftItem(item);
            }
            else if (construct != null)
            {
                CraftConstruction(construct);
            }
            else if (plant != null)
            {
                CraftPlant(plant, 0);
            }
            else if (character != null)
            {
                CraftCharacter(character);
            }
        }
Exemplo n.º 14
0
        void Awake()
        {
            _instance = this;

            CraftData.Load();
            ItemData.Load();
            ConstructionData.Load();
            PlantData.Load();
            CharacterData.Load();

            //Load managers
            if (!FindObjectOfType <TheUI>())
            {
                Instantiate(TheGame.IsMobile() ? assets.ui_canvas_mobile : assets.ui_canvas);
            }
            if (!FindObjectOfType <TheAudio>())
            {
                Instantiate(assets.audio_manager);
            }
            if (!FindObjectOfType <ActionSelector>())
            {
                Instantiate(assets.action_selector);
            }
        }