public static void AddPrefab(KPrefabID prefab)
 {
     if (!((UnityEngine.Object)prefab == (UnityEngine.Object)null))
     {
         prefab.UpdateSaveLoadTag();
         if (PrefabsByTag.ContainsKey(prefab.PrefabTag))
         {
             Debug.LogWarning("Tried loading prefab with duplicate tag, ignoring: " + prefab.PrefabTag);
         }
         PrefabsByTag[prefab.PrefabTag] = prefab;
         foreach (Tag tag in prefab.Tags)
         {
             if (!PrefabsByAdditionalTags.ContainsKey(tag))
             {
                 PrefabsByAdditionalTags[tag] = new List <KPrefabID>();
             }
             PrefabsByAdditionalTags[tag].Add(prefab);
         }
         Prefabs.Add(prefab);
         TryAddCountableTag(prefab);
         if (OnAddPrefab != null)
         {
             OnAddPrefab(prefab);
         }
     }
 }
 private void CheckTarget()
 {
     if (target == null)
     {
         KPrefabID instance = KPrefabIDTracker.Get().GetInstance(target_instance_id);
         if ((Object)instance != (Object)null)
         {
             target = instance.GetComponent <IAssignableIdentity>();
             if (target != null)
             {
                 MinionIdentity minionIdentity = target as MinionIdentity;
                 if ((bool)minionIdentity)
                 {
                     minionIdentity.ValidateProxy();
                 }
                 else
                 {
                     StoredMinionIdentity storedMinionIdentity = target as StoredMinionIdentity;
                     if ((bool)storedMinionIdentity)
                     {
                         storedMinionIdentity.ValidateProxy();
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        public void RefreshModifiers(float dt)
        {
            IStateMachineTarget master = GetMaster();

            if (!master.isNull)
            {
                int cell = Grid.PosToCell(base.gameObject);
                if (Grid.IsValidCell(cell))
                {
                    KSelectable component  = GetComponent <KSelectable>();
                    KPrefabID   component2 = GetComponent <KPrefabID>();
                    if (component2.HasAnyTags(PRESERVED_TAGS))
                    {
                        UnrefrigeratedModifier.SetValue(0f);
                        ContaminatedAtmosphere.SetValue(0f);
                    }
                    else
                    {
                        UnrefrigeratedModifier.SetValue(rotTemperatureModifier());
                        ContaminatedAtmosphere.SetValue(rotAtmosphereModifier());
                    }
                    SetStatusItems(atmoshpere: (ContaminatedAtmosphere.Value != 0f) ? ((ContaminatedAtmosphere.Value > 0f) ? RotAtmosphereQuality.Sterilizing : RotAtmosphereQuality.Contaminating) : RotAtmosphereQuality.Normal, selectable: component, refrigerated: UnrefrigeratedModifier.Value == 0f);
                    RotAmountInstance.deltaAttribute.ClearModifiers();
                    if (UnrefrigeratedModifier.Value != 0f && ContaminatedAtmosphere.Value != 0.5f)
                    {
                        RotAmountInstance.deltaAttribute.Add(UnrefrigeratedModifier);
                    }
                    if (ContaminatedAtmosphere.Value != 0f && ContaminatedAtmosphere.Value != 0.5f)
                    {
                        RotAmountInstance.deltaAttribute.Add(ContaminatedAtmosphere);
                    }
                }
            }
        }
            public void ScanSky()
            {
                float     detectTime = this.GetDetectTime();
                KPrefabID component  = this.GetComponent <KPrefabID>();

                if ((UnityEngine.Object) this.targetCraft.Get() == (UnityEngine.Object)null)
                {
                    if ((double)SaveGame.Instance.GetComponent <SeasonManager>().TimeUntilNextBombardment() <= (double)detectTime)
                    {
                        component.AddTag(GameTags.Detecting);
                    }
                    else
                    {
                        component.RemoveTag(GameTags.Detecting);
                    }
                }
                else
                {
                    Spacecraft conditionManager = SpacecraftManager.instance.GetSpacecraftFromLaunchConditionManager(this.targetCraft.Get());
                    if (conditionManager.state == Spacecraft.MissionState.Destroyed)
                    {
                        this.targetCraft.Set((LaunchConditionManager)null);
                        component.RemoveTag(GameTags.Detecting);
                    }
                    else if (conditionManager.state == Spacecraft.MissionState.Launching || conditionManager.state == Spacecraft.MissionState.WaitingToLand || conditionManager.state == Spacecraft.MissionState.Landing || conditionManager.state == Spacecraft.MissionState.Underway && (double)conditionManager.GetTimeLeft() <= (double)detectTime)
                    {
                        component.AddTag(GameTags.Detecting);
                    }
                    else
                    {
                        component.RemoveTag(GameTags.Detecting);
                    }
                }
            }
    private void OnPickupablesChanged(object data)
    {
        float num  = 0f;
        int   cell = Grid.CellAbove(this.NaturalBuildingCell());

        ListPool <ScenePartitionerEntry, LogicMassSensor> .PooledList pooledList = ListPool <ScenePartitionerEntry, LogicMassSensor> .Allocate();

        GameScenePartitioner instance = GameScenePartitioner.Instance;
        Vector2I             vector2I = Grid.CellToXY(cell);
        int      x         = vector2I.x;
        Vector2I vector2I2 = Grid.CellToXY(cell);

        instance.GatherEntries(x, vector2I2.y, 1, 1, GameScenePartitioner.Instance.pickupablesLayer, pooledList);
        for (int i = 0; i < pooledList.Count; i++)
        {
            Pickupable pickupable = pooledList[i].obj as Pickupable;
            if (!((Object)pickupable == (Object)null) && !pickupable.wasAbsorbed)
            {
                KPrefabID component = pickupable.GetComponent <KPrefabID>();
                if (!component.HasTag(GameTags.Creature) || component.HasTag(GameTags.Creatures.Walker) || component.HasTag(GameTags.Creatures.Hoverer) || pickupable.HasTag(GameTags.Creatures.Flopping))
                {
                    num += pickupable.PrimaryElement.Mass;
                }
            }
        }
        pooledList.Recycle();
        massPickupables = num;
    }
Exemplo n.º 6
0
    private void OnSelectObject(object data)
    {
        GameObject gameObject = (GameObject)data;

        if ((Object)gameObject != (Object)null)
        {
            KPrefabID component = gameObject.GetComponent <KPrefabID>();
            if ((Object)component != (Object)null && !component.IsInitialized())
            {
                return;
            }
        }
        if ((Object)gameObject != (Object)selectedGO)
        {
            selectedGO = gameObject;
            CloseSubMenus();
            if ((Object)selectedGO != (Object)null && ((Object)selectedGO.GetComponent <KPrefabID>() != (Object)null || (bool)selectedGO.GetComponent <CellSelectionObject>()))
            {
                AddSubMenu(detailsScreen);
                detailsScreen.Refresh(selectedGO);
                AddSubMenu(userMenu);
                userMenu.SetSelected(selectedGO);
                userMenu.Refresh(selectedGO);
            }
            else
            {
                userMenu.SetSelected(null);
            }
        }
    }
Exemplo n.º 7
0
 public void CopyTags(KPrefabID other)
 {
     foreach (Tag tag in other.tags)
     {
         tags.Add(tag);
     }
 }
Exemplo n.º 8
0
        public static GameObject BaseRollerSnake(string id, string name, string desc, string anim_file, string traitId, bool is_baby, string symbolOverridePrefix = null)
        {
            GameObject placedEntity = EntityTemplates.CreatePlacedEntity(id, name, desc, Mass, Assets.GetAnim(anim_file), "idle_loop", Grid.SceneLayer.Creatures,
                                                                         width: 1,
                                                                         height: 1,
                                                                         TUNING.DECOR.BONUS.TIER1, new EffectorValues(), SimHashes.Creature, null, DefaultTemperature);
            string NavGridName = NavGridId;

            if (is_baby)
            {
                NavGridName = NavGridBabyId;
            }
            EntityTemplates.ExtendEntityToBasicCreature(placedEntity, FactionManager.FactionID.Pest, traitId, NavGridName, NavType.Floor, 32,
                                                        moveSpeed: MoveSpeed,
                                                        onDeathDropID: OnDeathDropId,
                                                        onDeathDropCount: OnDeathDropCount,
                                                        false, false,
                                                        lethalLowTemperature: TemperatureLethalLow,
                                                        warningLowTemperature: TemperatureWarningLow,
                                                        warningHighTemperature: TemperatureWarningHigh,
                                                        lethalHighTemperature: TemperatureLethalHigh);
            if (symbolOverridePrefix != null)
            {
                placedEntity.AddOrGet <SymbolOverrideController>().ApplySymbolOverridesByAffix(Assets.GetAnim(anim_file), symbolOverridePrefix, null, 0);
            }
            placedEntity.AddOrGet <Trappable>();
            placedEntity.AddOrGetDef <CreatureFallMonitor.Def>();
            placedEntity.AddOrGetDef <ThreatMonitor.Def>().fleethresholdState = Health.HealthState.Dead;
            placedEntity.AddWeapon(1f, 1f, AttackProperties.DamageType.Standard, AttackProperties.TargetType.Single, 1, 0.0f);
            EntityTemplates.CreateAndRegisterBaggedCreature(placedEntity, true, true, false);
            KPrefabID component = placedEntity.GetComponent <KPrefabID>();

            component.AddTag(GameTags.Creatures.Walker, false);
            component.prefabInitFn += (inst => inst.GetAttributes().Add(Db.Get().Attributes.MaxUnderwaterTravelCost));
            bool condition = !is_baby;

            ChoreTable.Builder chore_table = new ChoreTable.Builder()
                                             .Add(new DeathStates.Def(), true)
                                             .Add(new AnimInterruptStates.Def(), true)
                                             .Add(new GrowUpStates.Def(), true)
                                             .Add(new TrappedStates.Def(), true)
                                             .Add(new IncubatingStates.Def(), true)
                                             .Add(new BaggedStates.Def(), true)
                                             .Add(new FallStates.Def(), true)
                                             .Add(new StunnedStates.Def(), true)
                                             .Add(new DebugGoToStates.Def(), true)
                                             .Add(new FleeStates.Def(), true)
                                             .Add(new AttackStates.Def(), condition).PushInterruptGroup()
                                             .Add(new CreatureSleepStates.Def(), true)
                                             .Add(new FixedCaptureStates.Def(), true)
                                             .Add(new RanchedStates.Def(), true)
                                             .Add(new LayEggStates.Def(), true)
                                             .Add(new EatStates.Def(), true)
                                             .Add(new PlayAnimsStates.Def(GameTags.Creatures.Poop, false, "poop", STRINGS.CREATURES.STATUSITEMS.EXPELLING_SOLID.NAME, STRINGS.CREATURES.STATUSITEMS.EXPELLING_SOLID.TOOLTIP), true)
                                             .Add(new CallAdultStates.Def(), true).PopInterruptGroup()
                                             .Add(new IdleStates.Def(), true);
            EntityTemplates.AddCreatureBrain(placedEntity, chore_table, SpeciesId, symbolOverridePrefix);
            placedEntity.AddTag(GameTags.Amphibious);
            return(placedEntity);
        }
Exemplo n.º 9
0
 private void ClearTarget()
 {
     _target          = null;
     _targetCell      = int.MinValue;
     _targetDirection = Vector3.negativeInfinity;
     _operational.SetActive(false);
 }
    private static int CountNearbyPlants(int cell, int radius)
    {
        int x = 0;
        int y = 0;

        Grid.PosToXY(Grid.CellToPos(cell), out x, out y);
        int num = radius * 2;

        x -= radius;
        y -= radius;
        ListPool <ScenePartitionerEntry, GameScenePartitioner> .PooledList pooledList = ListPool <ScenePartitionerEntry, GameScenePartitioner> .Allocate();

        GameScenePartitioner.Instance.GatherEntries(x, y, num, num, GameScenePartitioner.Instance.plants, pooledList);
        int num2 = 0;

        foreach (ScenePartitionerEntry item in pooledList)
        {
            KPrefabID kPrefabID = (KPrefabID)item.obj;
            if (!(bool)kPrefabID.GetComponent <TreeBud>())
            {
                num2++;
            }
        }
        pooledList.Recycle();
        return(num2);
    }
Exemplo n.º 11
0
    private void CleanupLimboMinions()
    {
        KPrefabID component = GetComponent <KPrefabID>();

        if (component.InstanceID == -1)
        {
            DebugUtil.LogWarningArgs("Minion with an invalid kpid! Attempting to recover...", name);
            if ((UnityEngine.Object)KPrefabIDTracker.Get().GetInstance(component.InstanceID) != (UnityEngine.Object)null)
            {
                KPrefabIDTracker.Get().Unregister(component);
            }
            component.InstanceID = KPrefabID.GetUniqueID();
            KPrefabIDTracker.Get().Register(component);
            DebugUtil.LogWarningArgs("Restored as:", component.InstanceID);
        }
        if (component.conflicted)
        {
            DebugUtil.LogWarningArgs("Minion with a conflicted kpid! Attempting to recover... ", component.InstanceID, name);
            if ((UnityEngine.Object)KPrefabIDTracker.Get().GetInstance(component.InstanceID) != (UnityEngine.Object)null)
            {
                KPrefabIDTracker.Get().Unregister(component);
            }
            component.InstanceID = KPrefabID.GetUniqueID();
            KPrefabIDTracker.Get().Register(component);
            DebugUtil.LogWarningArgs("Restored as:", component.InstanceID);
        }
        assignableProxy.Get().SetTarget(this, base.gameObject);
    }
 protected override void OnSpawn()
 {
     base.OnSpawn();
     UpdateTint();
     UpdateStatusString();
     base.OnAssign += OnNewAssignment;
     if (assignee == null)
     {
         MinionStorage component = GetComponent <MinionStorage>();
         if ((bool)component)
         {
             List <MinionStorage.Info> storedMinionInfo = component.GetStoredMinionInfo();
             if (storedMinionInfo.Count > 0)
             {
                 MinionStorage.Info info             = storedMinionInfo[0];
                 Ref <KPrefabID>    serializedMinion = info.serializedMinion;
                 if (serializedMinion != null && serializedMinion.GetId() != -1)
                 {
                     KPrefabID            kPrefabID  = serializedMinion.Get();
                     StoredMinionIdentity component2 = kPrefabID.GetComponent <StoredMinionIdentity>();
                     component2.ValidateProxy();
                     Assign(component2);
                 }
             }
         }
     }
 }
Exemplo n.º 13
0
        public static void Postfix(GameObject __result)
        {
            GasAndLiquidConsumerMonitor.Def def = __result.AddOrGetDef <GasAndLiquidConsumerMonitor.Def>();
            List <string> vanillasSlickstersIds = new List <string>
            {
                "Oilfloater",
                "OilfloaterBaby",
                "OilfloaterDecor",
                "OilfloaterDecorBaby",
                "OilfloaterHighTemp",
                "OilfloaterHighTempBaby"
            };

            KPrefabID kId = __result.AddOrGet <KPrefabID>();

            // If the slickster is a vanilla slickster, I check the options
            if (vanillasSlickstersIds.Contains(kId.PrefabTag.Name))
            {
                if (Patches.Settings.IncreasesVanillaSlickstersConsumption)
                {
                    def.consumptionRate = 5f;
                }
            }
            else
            {
                if (def.consumptionRate <= 0.5f)
                {
                    def.consumptionRate = 5f * Patches.Settings.ConsumptionMultiplier;
                }
            }
        }
    public static GameObject TryGetPrefab(Tag tag)
    {
        KPrefabID value = null;

        PrefabsByTag.TryGetValue(tag, out value);
        return((!((UnityEngine.Object)value != (UnityEngine.Object)null)) ? null : value.gameObject);
    }
Exemplo n.º 15
0
    protected override void OnSpawn()
    {
        base.OnSpawn();
        RegisterInGrid(true);
        SetGridRestrictions(null, DefaultPermission);
        foreach (KeyValuePair <Ref <KPrefabID>, Permission> savedPermission in savedPermissions)
        {
            SetGridRestrictions(savedPermission.Key.Get(), savedPermission.Value);
        }
        ListPool <Tuple <MinionAssignablesProxy, Permission>, AccessControl> .PooledList pooledList = ListPool <Tuple <MinionAssignablesProxy, Permission>, AccessControl> .Allocate();

        for (int num = savedPermissions.Count - 1; num >= 0; num--)
        {
            KPrefabID kPrefabID = savedPermissions[num].Key.Get();
            if ((Object)kPrefabID != (Object)null)
            {
                MinionIdentity component = kPrefabID.GetComponent <MinionIdentity>();
                if ((Object)component != (Object)null)
                {
                    pooledList.Add(new Tuple <MinionAssignablesProxy, Permission>(component.assignableProxy.Get(), savedPermissions[num].Value));
                    savedPermissions.RemoveAt(num);
                    ClearGridRestrictions(kPrefabID);
                }
            }
        }
        foreach (Tuple <MinionAssignablesProxy, Permission> item in pooledList)
        {
            SetPermission(item.first, item.second);
        }
        pooledList.Recycle();
        SetStatusItem();
    }
Exemplo n.º 16
0
    public Dictionary <Tag, float> GetRemainingMinimum()
    {
        Dictionary <Tag, float> dictionary = new Dictionary <Tag, float>();

        foreach (FetchOrder2 fetchOrder in FetchOrders)
        {
            Tag[] tags = fetchOrder.Tags;
            foreach (Tag key in tags)
            {
                dictionary[key] = MinimumAmount[key];
            }
        }
        foreach (GameObject item in Destination.items)
        {
            if ((UnityEngine.Object)item != (UnityEngine.Object)null)
            {
                Pickupable component = item.GetComponent <Pickupable>();
                if ((UnityEngine.Object)component != (UnityEngine.Object)null)
                {
                    KPrefabID component2 = component.GetComponent <KPrefabID>();
                    foreach (Tag tag in component2.Tags)
                    {
                        if (dictionary.ContainsKey(tag))
                        {
                            dictionary[tag] = Math.Max(dictionary[tag] - component.TotalAmount, 0f);
                        }
                    }
                }
            }
        }
        return(dictionary);
    }
    public void DoPostConfigure(GameObject go)
    {
        SetupVest(go);
        KPrefabID component = go.GetComponent <KPrefabID>();

        component.AddTag(GameTags.PedestalDisplayable,false);
    }
Exemplo n.º 18
0
        /// <summary>
        /// <para>计算剩余价值:繁殖条件相同时,剩余年龄(单位:周期)还能繁殖多少次</para>
        /// <para>无年龄、无繁殖度的对象剩余价值无限大</para>
        /// <para>剩余存活周期 = 总生命周期 - 已存活周期</para>
        /// <para>当前繁殖已消耗周期 = 每次繁殖所需周期 * 当前繁殖度</para>
        /// <para>剩余繁殖次数 = (剩余存活周期 + 当前繁殖次已消耗周期) / 每次繁殖所需周期</para>
        /// </summary>
        private static float CalcProfit(KPrefabID creature)
        {
            var ageAmount       = Db.Get().Amounts.Age.Lookup(creature);
            var fertilityAmount = Db.Get().Amounts.Fertility.Lookup(creature);

            if (ageAmount == null || fertilityAmount == null)
            {
                return(float.MaxValue);
            }
            var maxAge     = ageAmount.GetMax();
            var currentAge = ageAmount.value;
            // 剩余年龄
            var leftAge = maxAge - currentAge;
            // 每次繁殖所需周期
            var cyclesPerFertility = creature.gameObject.GetDef <FertilityMonitor.Def>()?.baseFertileCycles ?? 0;
            // 当前繁殖度
            var currentFertilityRate = fertilityAmount.value;
            // 当前繁殖已消耗周期
            var currentFertilityCycles = cyclesPerFertility * currentFertilityRate;
            // 剩余繁殖次数
            var fertilityTimes = (leftAge + currentFertilityCycles) / cyclesPerFertility;

            // VUtils.Log($"baseFertileCycles: {cyclesPerFertility}");
            // VUtils.Log($"{ageAmount.name} {ageAmount.modifier.Id} {ageAmount.modifier.Name} {ageAmount.value} ({ageAmount.GetDelta()}/{ageAmount.GetMin()}/{ageAmount.GetMax()})");
            // VUtils.Log($"{fertilityAmount.name} {fertilityAmount.modifier.Id} {fertilityAmount.modifier.Name} {fertilityAmount.value} ({fertilityAmount.GetDelta()}/{fertilityAmount.GetMin()}/{fertilityAmount.GetMax()})");

            return(fertilityTimes);
        }
Exemplo n.º 19
0
    public static GameObject CreateArtifact(string id, string name, string desc, string initial_anim, string ui_anim, ArtifactTier artifact_tier, PostInitFn postInitFn = null, SimHashes element = SimHashes.Creature)
    {
        GameObject gameObject = EntityTemplates.CreateLooseEntity("artifact_" + id.ToLower(), name, desc, 25f, true, Assets.GetAnim("artifacts_kanim"), initial_anim, Grid.SceneLayer.Ore, EntityTemplates.CollisionShape.RECTANGLE, 1f, 1f, true, SORTORDER.BUILDINGELEMENTS, element, new List <Tag>
        {
            GameTags.MiscPickupable
        });
        OccupyArea occupyArea = gameObject.AddOrGet <OccupyArea>();

        occupyArea.OccupiedCellsOffsets = EntityTemplates.GenerateOffsets(1, 1);
        DecorProvider decorProvider = gameObject.AddOrGet <DecorProvider>();

        decorProvider.SetValues(artifact_tier.decorValues);
        decorProvider.overrideName = gameObject.name;
        SpaceArtifact spaceArtifact = gameObject.AddOrGet <SpaceArtifact>();

        spaceArtifact.SetUIAnim(ui_anim);
        spaceArtifact.SetArtifactTier(artifact_tier);
        gameObject.AddOrGet <KSelectable>();
        gameObject.GetComponent <KBatchedAnimController>().initialMode = KAnim.PlayMode.Loop;
        postInitFn?.Invoke(gameObject);
        KPrefabID component = gameObject.GetComponent <KPrefabID>();

        component.AddTag(GameTags.PedestalDisplayable, false);
        component.AddTag(GameTags.Artifact, false);
        return(gameObject);
    }
Exemplo n.º 20
0
    public override void DoPostConfigureComplete(GameObject go)
    {
        GeneratedBuildings.RegisterLogicPorts(go, DoorConfig.INPUT_PORTS_N1_0);
        Door door = go.AddOrGet <Door>();

        door.unpoweredAnimSpeed        = 0.01f;
        door.poweredAnimSpeed          = 0.1f;
        door.hasComplexUserControls    = true;
        door.allowAutoControl          = false;
        door.doorOpeningSoundEventName = "BunkerDoor_opening";
        door.doorClosingSoundEventName = "BunkerDoor_closing";
        door.verticalOrientation       = Orientation.R90;
        Workable workable = go.AddOrGet <Workable>();

        workable.workTime = 3f;
        KBatchedAnimController component = go.GetComponent <KBatchedAnimController>();

        component.initialAnim    = "closed";
        component.visibilityType = KAnimControllerBase.VisibilityType.OffscreenUpdate;
        go.AddOrGet <ZoneTile>();
        go.AddOrGet <KBoxCollider2D>();
        Prioritizable.AddRef(go);
        Object.DestroyImmediate(go.GetComponent <BuildingEnabledButton>());
        KPrefabID component2 = go.GetComponent <KPrefabID>();

        component2.AddTag(GameTags.Bunker, false);
    }
 /// <summary>
 /// Applied before AndTagBits runs.
 /// </summary>
 internal static bool Prefix(KPrefabID __instance, ref TagBits ___tagBits,
                             ref TagBits rhs)
 {
     __instance.UpdateTagBits();
     TagBitOps.And(ref rhs, ref ___tagBits);
     return(false);
 }
Exemplo n.º 22
0
    public static SubstanceChunk CreateChunk(Element element, float mass, float temperature, byte diseaseIdx, int diseaseCount, Vector3 position)
    {
        if (temperature <= 0f)
        {
            DebugUtil.LogWarningArgs("GeneratedOre.CreateChunk tried to create a chunk with a temperature <= 0");
        }
        GameObject prefab = Assets.GetPrefab(element.tag);

        if ((UnityEngine.Object)prefab == (UnityEngine.Object)null)
        {
            Debug.LogError("Could not find prefab for element " + element.id.ToString());
        }
        SubstanceChunk component = GameUtil.KInstantiate(prefab, Grid.SceneLayer.Ore, null, 0).GetComponent <SubstanceChunk>();

        component.transform.SetPosition(position);
        component.gameObject.SetActive(true);
        PrimaryElement component2 = component.GetComponent <PrimaryElement>();

        component2.Mass        = mass;
        component2.Temperature = temperature;
        component2.AddDisease(diseaseIdx, diseaseCount, "GeneratedOre.CreateChunk");
        KPrefabID component3 = component.GetComponent <KPrefabID>();

        component3.InitializeTags();
        return(component);
    }
 public SafeCellSensor(Sensors sensors)
     : base(sensors)
 {
     navigator = GetComponent <Navigator>();
     brain     = GetComponent <MinionBrain>();
     prefabid  = GetComponent <KPrefabID>();
 }
    public GameObject CreatePrefab()
    {
        GameObject gameObject = EntityTemplates.CreateLooseEntity("AdvancedCure", ITEMS.PILLS.ADVANCEDCURE.NAME, ITEMS.PILLS.ADVANCEDCURE.DESC, 1f, true, Assets.GetAnim("vial_spore_kanim"), "object", Grid.SceneLayer.Front, EntityTemplates.CollisionShape.RECTANGLE, 0.8f, 0.4f, true, 0, SimHashes.Creature, null);
        KPrefabID  component  = gameObject.GetComponent <KPrefabID>();

        component.AddTag(GameTags.MedicalSupplies, false);
        ComplexRecipe.RecipeElement[] array = new ComplexRecipe.RecipeElement[2]
        {
            new ComplexRecipe.RecipeElement(SimHashes.Steel.CreateTag(), 1f),
            new ComplexRecipe.RecipeElement("LightBugOrangeEgg", 1f)
        };
        ComplexRecipe.RecipeElement[] array2 = new ComplexRecipe.RecipeElement[1]
        {
            new ComplexRecipe.RecipeElement("AdvancedCure", 1f)
        };
        string        id            = ComplexRecipeManager.MakeRecipeID("Apothecary", array, array2);
        ComplexRecipe complexRecipe = new ComplexRecipe(id, array, array2);

        complexRecipe.time        = 200f;
        complexRecipe.description = ITEMS.PILLS.ADVANCEDCURE.RECIPEDESC;
        complexRecipe.nameDisplay = ComplexRecipe.RecipeNameDisplay.Result;
        complexRecipe.fabricators = new List <Tag>
        {
            "Apothecary"
        };
        complexRecipe.sortOrder    = 20;
        complexRecipe.requiredTech = "MedicineIV";
        recipe = complexRecipe;
        return(gameObject);
    }
 public void RestoreTargetFromInstanceID()
 {
     if (target_instance_id != -1 && target == null)
     {
         KPrefabID instance = KPrefabIDTracker.Get().GetInstance(target_instance_id);
         if ((bool)instance)
         {
             IAssignableIdentity component = instance.GetComponent <IAssignableIdentity>();
             if (component != null)
             {
                 SetTarget(component, instance.gameObject);
             }
             else
             {
                 Debug.LogWarningFormat("RestoreTargetFromInstanceID target ID {0} was found but it wasn't an IAssignableIdentity, destroying proxy object.", target_instance_id);
                 Util.KDestroyGameObject(base.gameObject);
             }
         }
         else
         {
             Debug.LogWarningFormat("RestoreTargetFromInstanceID target ID {0} was not found, destroying proxy object.", target_instance_id);
             Util.KDestroyGameObject(base.gameObject);
         }
     }
 }
Exemplo n.º 26
0
    public void SetPermission(MinionAssignablesProxy key, Permission permission)
    {
        KPrefabID component = key.GetComponent <KPrefabID>();

        if (!((Object)component == (Object)null))
        {
            bool flag = false;
            for (int i = 0; i < savedPermissions.Count; i++)
            {
                if (savedPermissions[i].Key.GetId() == component.InstanceID)
                {
                    flag = true;
                    KeyValuePair <Ref <KPrefabID>, Permission> keyValuePair = savedPermissions[i];
                    savedPermissions[i] = new KeyValuePair <Ref <KPrefabID>, Permission>(keyValuePair.Key, permission);
                    break;
                }
            }
            if (!flag)
            {
                savedPermissions.Add(new KeyValuePair <Ref <KPrefabID>, Permission>(new Ref <KPrefabID>(component), permission));
            }
            SetStatusItem();
            SetGridRestrictions(component, permission);
        }
    }
Exemplo n.º 27
0
 /// <summary>
 /// Adds a critter in the current world to the inventory.
 /// </summary>
 /// <param name="creature">The creature to add.</param>
 private void AddCritter(KPrefabID id)
 {
     if (counts.TryGetValue(id.GetCritterType(), out CritterInventoryPerType byType))
     {
         var  species = id.PrefabTag;
         bool targeted = false, targetable = false;
         // Create critter totals if not present
         if (!byType.TryGetValue(species, out CritterTotals totals))
         {
             byType.Add(species, totals = new CritterTotals());
             discovered = true;
         }
         totals.Total++;
         if (id.TryGetComponent(out FactionAlignment alignment))
         {
             targeted   = FACTION_TARGETED.Get(alignment);
             targetable = FACTION_TARGETABLE.Get(alignment);
         }
         // Reserve wrangled, marked for attack, and trussed/bagged creatures
         if ((id.TryGetComponent(out Capturable capturable) && capturable.
              IsMarkedForCapture) || (targeted && targetable) || id.HasTag(
                 GameTags.Creatures.Bagged))
         {
             totals.Reserved++;
         }
     }
 }
Exemplo n.º 28
0
    private void SetGridRestrictions(KPrefabID kpid, Permission permission)
    {
        Building component = GetComponent <Building>();

        if (!((Object)component == (Object)null))
        {
            int minion = (!((Object)kpid != (Object)null)) ? (-1) : kpid.InstanceID;
            Grid.Restriction.Directions directions = (Grid.Restriction.Directions) 0;
            switch (permission)
            {
            case Permission.Both:
                directions = (Grid.Restriction.Directions) 0;
                break;

            case Permission.GoLeft:
                directions = Grid.Restriction.Directions.Right;
                break;

            case Permission.GoRight:
                directions = Grid.Restriction.Directions.Left;
                break;

            case Permission.Neither:
                directions = (Grid.Restriction.Directions.Left | Grid.Restriction.Directions.Right);
                break;
            }
            int[] placementCells = component.PlacementCells;
            foreach (int cell in placementCells)
            {
                Grid.SetRestriction(cell, minion, directions);
            }
        }
    }
Exemplo n.º 29
0
    static bool isPlantWild(KPrefabID plant)
    {
        if (plant.GetComponent <BasicForagePlantPlanted>() != null)
        {
            return(true);
        }

        ReceptacleMonitor receptacleMonitor = plant.GetComponent <ReceptacleMonitor>();

        if (receptacleMonitor != null)
        {
            if (!receptacleMonitor.Replanted)
            {
                return(true);
            }

            var plantablePlot = receptacleMonitor.GetReceptacle();
            if (plantablePlot != null)
            {
                if (plantablePlot.GetComponent <WildPlanterBox>() || plantablePlot.GetComponent <WildFarmTile>())
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Exemplo n.º 30
0
    public GameObject CreatePrefab()
    {
        GameObject gameObject = EntityTemplates.CreateLooseEntity("IntermediateCure", ITEMS.PILLS.INTERMEDIATECURE.NAME, ITEMS.PILLS.INTERMEDIATECURE.DESC, 1f, true, Assets.GetAnim("iv_slimelung_kanim"), "object", Grid.SceneLayer.Front, EntityTemplates.CollisionShape.RECTANGLE, 0.8f, 0.4f, true, 0, SimHashes.Creature, null);
        KPrefabID  component  = gameObject.GetComponent <KPrefabID>();

        component.AddTag(GameTags.MedicalSupplies, false);
        ComplexRecipe.RecipeElement[] array = new ComplexRecipe.RecipeElement[2]
        {
            new ComplexRecipe.RecipeElement(SwampLilyFlowerConfig.ID, 1f),
            new ComplexRecipe.RecipeElement(SimHashes.Phosphorite.CreateTag(), 1f)
        };
        ComplexRecipe.RecipeElement[] array2 = new ComplexRecipe.RecipeElement[1]
        {
            new ComplexRecipe.RecipeElement("IntermediateCure", 1f)
        };
        string        id            = ComplexRecipeManager.MakeRecipeID("Apothecary", array, array2);
        ComplexRecipe complexRecipe = new ComplexRecipe(id, array, array2);

        complexRecipe.time        = 100f;
        complexRecipe.description = ITEMS.PILLS.INTERMEDIATECURE.RECIPEDESC;
        complexRecipe.nameDisplay = ComplexRecipe.RecipeNameDisplay.Result;
        complexRecipe.fabricators = new List <Tag>
        {
            "Apothecary"
        };
        complexRecipe.sortOrder    = 10;
        complexRecipe.requiredTech = "MedicineII";
        recipe = complexRecipe;
        return(gameObject);
    }