private static void Unbag(Instance smi)
    {
        Baggable component = smi.gameObject.GetComponent <Baggable>();

        if ((bool)component)
        {
            component.Free();
        }
    }
Exemplo n.º 2
0
    public void SpawnResources(object data)
    {
        SpaceDestination spacecraftDestination = SpacecraftManager.instance.GetSpacecraftDestination(SpacecraftManager.instance.GetSpacecraftID(GetComponent <RocketModule>().conditionManager.GetComponent <LaunchableRocket>()));
        int rootCell = Grid.PosToCell(base.gameObject);

        foreach (KeyValuePair <SimHashes, float> item in spacecraftDestination.GetMissionResourceResult(storage.RemainingCapacity(), storageType == CargoType.solids, storageType == CargoType.liquids, storageType == CargoType.gasses))
        {
            Element element = ElementLoader.FindElementByHash(item.Key);
            if (storageType == CargoType.solids && element.IsSolid)
            {
                GameObject gameObject = Scenario.SpawnPrefab(rootCell, 0, 0, element.tag.Name, Grid.SceneLayer.Ore);
                gameObject.GetComponent <PrimaryElement>().Mass        = item.Value;
                gameObject.GetComponent <PrimaryElement>().Temperature = ElementLoader.FindElementByHash(item.Key).defaultValues.temperature;
                gameObject.SetActive(true);
                storage.Store(gameObject, false, false, true, false);
            }
            else if (storageType == CargoType.liquids && element.IsLiquid)
            {
                storage.AddLiquid(item.Key, item.Value, ElementLoader.FindElementByHash(item.Key).defaultValues.temperature, byte.MaxValue, 0, false, true);
            }
            else if (storageType == CargoType.gasses && element.IsGas)
            {
                storage.AddGasChunk(item.Key, item.Value, ElementLoader.FindElementByHash(item.Key).defaultValues.temperature, byte.MaxValue, 0, false, true);
            }
        }
        if (storageType == CargoType.entities)
        {
            foreach (KeyValuePair <Tag, int> item2 in spacecraftDestination.GetMissionEntityResult())
            {
                GameObject prefab = Assets.GetPrefab(item2.Key);
                if ((UnityEngine.Object)prefab == (UnityEngine.Object)null)
                {
                    KCrashReporter.Assert(false, "Missing prefab: " + item2.Key.Name);
                }
                else
                {
                    for (int i = 0; i < item2.Value; i++)
                    {
                        GameObject gameObject2 = Util.KInstantiate(prefab, base.transform.position);
                        gameObject2.SetActive(true);
                        storage.Store(gameObject2, false, false, true, false);
                        Baggable component = gameObject2.GetComponent <Baggable>();
                        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
                        {
                            component.SetWrangled();
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 3
0
    public static GameObject CreateAndRegisterBaggedCreature(GameObject creature, bool must_stand_on_top_for_pickup, bool allow_mark_for_capture, bool use_gun_for_pickup = false)
    {
        KPrefabID creature_prefab_id = creature.GetComponent <KPrefabID>();

        creature_prefab_id.AddTag(GameTags.BagableCreature, false);
        Baggable baggable = creature.AddOrGet <Baggable>();

        baggable.mustStandOntopOfTrapForPickup = must_stand_on_top_for_pickup;
        baggable.useGunForPickup = use_gun_for_pickup;
        Capturable capturable = creature.AddOrGet <Capturable>();

        capturable.allowCapture           = allow_mark_for_capture;
        creature_prefab_id.prefabSpawnFn += delegate
        {
            WorldInventory.Instance.Discover(creature_prefab_id.PrefabTag, WorldInventory.GetCategoryForTags(creature_prefab_id.Tags));
        };
        return(creature);
    }