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);
            }
        }
        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();
                }
            }
        }
Пример #3
0
 private void OnBuild()
 {
     if (data != null)
     {
         BuiltConstructionData cdata = PlayerData.Get().AddConstruction(data.id, SceneNav.GetCurrentScene(), transform.position, transform.rotation, data.durability);
         unique_id.unique_id = cdata.uid;
     }
 }
        //---- Constructions and Plants and Characters

        public BuiltConstructionData AddConstruction(string construct_id, string scene, Vector3 pos, Quaternion rot, float durability)
        {
            BuiltConstructionData citem = new BuiltConstructionData();

            citem.uid                      = UniqueID.GenerateUniqueID();
            citem.construction_id          = construct_id;
            citem.scene                    = scene;
            citem.pos                      = pos;
            citem.rot                      = rot;
            citem.durability               = durability;
            built_constructions[citem.uid] = citem;
            return(citem);
        }
Пример #5
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();
            }
        }