예제 #1
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);
        }
예제 #2
0
        void Awake()
        {
            select = GetComponent <Selectable>();

            construct = GetComponent <Construction>();
            plant     = GetComponent <Plant>();
            item      = GetComponent <Item>();
            character = GetComponent <Character>();
        }
        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;
            }
        }
예제 #4
0
        public static new Construction GetNearest(Vector3 pos, float range = 999f)
        {
            Construction nearest  = null;
            float        min_dist = range;

            foreach (Construction construction in construct_list)
            {
                float dist = (construction.transform.position - pos).magnitude;
                if (dist < min_dist && construction.IsBuilt())
                {
                    min_dist = dist;
                    nearest  = construction;
                }
            }
            return(nearest);
        }
예제 #5
0
 void Awake()
 {
     firepit_list.Add(this);
     select       = GetComponent <Selectable>();
     construction = GetComponent <Construction>();
     buildable    = GetComponent <Buildable>();
     unique_id    = GetComponent <UniqueID>();
     heat_source  = GetComponent <HeatSource>();
     if (fire_fx)
     {
         fire_fx.SetActive(false);
     }
     if (fuel_model)
     {
         fuel_model.SetActive(false);
     }
 }
예제 #6
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);
            }
        }
        //Return all scenes objects with this data
        public static List <GameObject> GetAllObjectsOf(CraftData data)
        {
            List <GameObject> valid_list = new List <GameObject>();

            if (data is ItemData)
            {
                List <Item> items = Item.GetAllOf((ItemData)data);
                foreach (Item item in items)
                {
                    valid_list.Add(item.gameObject);
                }
            }

            if (data is PlantData)
            {
                List <Plant> items = Plant.GetAllOf((PlantData)data);
                foreach (Plant plant in items)
                {
                    valid_list.Add(plant.gameObject);
                }
            }

            if (data is ConstructionData)
            {
                List <Construction> items = Construction.GetAllOf((ConstructionData)data);
                foreach (Construction construct in items)
                {
                    valid_list.Add(construct.gameObject);
                }
            }

            if (data is CharacterData)
            {
                List <Character> items = Character.GetAllOf((CharacterData)data);
                foreach (Character character in items)
                {
                    valid_list.Add(character.gameObject);
                }
            }
            return(valid_list);
        }
예제 #8
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 static int CountSceneObjects(CraftData data, Vector3 pos, float range)
        {
            int count = 0;

            if (data is CharacterData)
            {
                count += Character.CountInRange((CharacterData)data, pos, range);
            }
            if (data is PlantData)
            {
                count += Plant.CountInRange((PlantData)data, pos, range);
            }
            if (data is ConstructionData)
            {
                count += Construction.CountInRange((ConstructionData)data, pos, range);
            }
            if (data is ItemData)
            {
                count += Item.CountInRange((ItemData)data, pos, range);
            }
            return(count);
        }
        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);
        }