Пример #1
0
    private void OnUpdateBounds(Bounds bounds)
    {
        KBoxCollider2D component = GetComponent <KBoxCollider2D>();

        component.offset = bounds.center;
        component.size   = bounds.extents;
    }
    protected override void OnSpawn()
    {
        base.OnSpawn();
        KBatchedAnimController component = GetComponent <KBatchedAnimController>();
        Rotatable component2             = GetComponent <Rotatable>();

        if ((Object)component != (Object)null && (Object)component2 == (Object)null)
        {
            component.Offset = Def.GetVisualizerOffset() + Def.placementPivot;
        }
        KBoxCollider2D component3 = GetComponent <KBoxCollider2D>();

        if ((Object)component3 != (Object)null)
        {
            Vector3 visualizerOffset = Def.GetVisualizerOffset();
            component3.offset += new Vector2(visualizerOffset.x, visualizerOffset.y);
        }
        if (Def.IsTilePiece)
        {
            int cell = Grid.PosToCell(base.transform.GetPosition());
            Def.RunOnArea(cell, base.Orientation, delegate(int c)
            {
                TileVisualizer.RefreshCell(c, Def.TileLayer, Def.ReplacementLayer);
            });
        }
        RegisterBlockTileRenderer();
    }
Пример #3
0
    private static GameObject ConfigPlacedEntity(GameObject template, string id, string name, string desc, float mass, KAnimFile anim, string initialAnim, Grid.SceneLayer sceneLayer, int width, int height, EffectorValues decor, EffectorValues noise = default(EffectorValues), SimHashes element = SimHashes.Creature, List <Tag> additionalTags = null, float defaultTemperature = 293f)
    {
        if ((Object)anim == (Object)null)
        {
            Debug.LogErrorFormat("Cant create [{0}] entity without an anim", name);
        }
        ConfigBasicEntity(template, id, name, desc, mass, true, anim, initialAnim, sceneLayer, element, additionalTags, defaultTemperature);
        KBoxCollider2D kBoxCollider2D = template.AddOrGet <KBoxCollider2D>();

        kBoxCollider2D.size = new Vector2f(width, height);
        float num = 0.5f * (float)((width + 1) % 2);

        kBoxCollider2D.offset = new Vector2f(num, (float)height / 2f);
        KBatchedAnimController component = template.GetComponent <KBatchedAnimController>();

        component.Offset = new Vector3(num, 0f, 0f);
        OccupyArea occupyArea = template.AddOrGet <OccupyArea>();

        occupyArea.OccupiedCellsOffsets = GenerateOffsets(width, height);
        DecorProvider decorProvider = template.AddOrGet <DecorProvider>();

        decorProvider.SetValues(decor);
        decorProvider.overrideName = name;
        return(template);
    }
        public Instance(IStateMachineTarget master, Def def)
            : base(master, def)
        {
            KBoxCollider2D component = master.GetComponent <KBoxCollider2D>();

            originalColliderSize   = component.size;
            originalColliderOffset = component.offset;
        }
Пример #5
0
    private static bool Add2DComponents(BuildingDef def, GameObject go, string initialAnimState = null, bool no_collider = false, int layer = -1)
    {
        bool flag = def.AnimFiles != null && def.AnimFiles.Length > 0;

        if (layer == -1)
        {
            layer = LayerMask.NameToLayer("Default");
        }
        go.layer = layer;
        KBatchedAnimController[] components = go.GetComponents <KBatchedAnimController>();
        if (components.Length > 1)
        {
            for (int i = 2; i < components.Length; i++)
            {
                Object.DestroyImmediate(components[i]);
            }
        }
        if ((Object)def.BlockTileAtlas == (Object)null)
        {
            KBatchedAnimController kBatchedAnimController = UpdateComponentRequirement <KBatchedAnimController>(go, flag);
            if ((Object)kBatchedAnimController != (Object)null)
            {
                kBatchedAnimController.AnimFiles = def.AnimFiles;
                if (def.isKAnimTile)
                {
                    kBatchedAnimController.initialAnim = null;
                }
                else
                {
                    if (def.isUtility && initialAnimState == null)
                    {
                        initialAnimState = "idle";
                    }
                    else if ((Object)go.GetComponent <Door>() != (Object)null)
                    {
                        initialAnimState = "closed";
                    }
                    kBatchedAnimController.initialAnim = ((initialAnimState == null) ? def.DefaultAnimState : initialAnimState);
                }
                kBatchedAnimController.SetFGLayer(def.ForegroundLayer);
                kBatchedAnimController.materialType = KAnimBatchGroup.MaterialType.Default;
            }
        }
        KBoxCollider2D kBoxCollider2D = UpdateComponentRequirement <KBoxCollider2D>(go, flag && !no_collider);

        if ((Object)kBoxCollider2D != (Object)null)
        {
            kBoxCollider2D.offset = new Vector3(0f, 0.5f * (float)def.HeightInCells, 0f);
            kBoxCollider2D.size   = new Vector3((float)def.WidthInCells, (float)def.HeightInCells, 0f);
        }
        if (def.AnimFiles == null)
        {
            Debug.LogError(def.Name + " Def missing anim files");
        }
        return(flag);
    }
    public void LateUpdate()
    {
        Vector3        pivotSymbolPosition = controller.GetPivotSymbolPosition();
        KBoxCollider2D kBoxCollider2D      = animCollider;
        float          num       = baseOffset.x + pivotSymbolPosition.x;
        Vector3        position  = base.transform.GetPosition();
        float          x         = num - position.x;
        float          num2      = baseOffset.y + pivotSymbolPosition.y;
        Vector3        position2 = base.transform.GetPosition();

        kBoxCollider2D.offset = new Vector2(x, num2 - position2.y);
    }
Пример #7
0
 protected override void OnSpawn()
 {
     base.OnSpawn();
     mCollider      = GetComponent <KBoxCollider2D>();
     mCollider.size = new Vector2(1.1f, 1.1f);
     mSelectable    = GetComponent <KSelectable>();
     SelectedDisplaySprite.transform.localScale = Vector3.one * 0.390625f;
     SelectedDisplaySprite.GetComponent <SpriteRenderer>().sprite = Sprite_Hover;
     Subscribe(Game.Instance.gameObject, 493375141, ForceRefreshUserMenu);
     overlayFilterMap.Add(OverlayModes.Oxygen.ID, () => Grid.Element[mouseCell].IsGas);
     overlayFilterMap.Add(OverlayModes.GasConduits.ID, () => Grid.Element[mouseCell].IsGas);
     overlayFilterMap.Add(OverlayModes.LiquidConduits.ID, () => Grid.Element[mouseCell].IsLiquid);
 }
    public GameObject CreatePrefab(string id, string name, Material default_material)
    {
        GameObject gameObject = EntityTemplates.CreateEntity(id, name, true);

        gameObject.layer = LayerMask.NameToLayer("PlaceWithDepth");
        gameObject.AddOrGet <SaveLoadRoot>();
        gameObject.AddOrGet <StateMachineController>();
        Prioritizable prioritizable = gameObject.AddOrGet <Prioritizable>();

        prioritizable.iconOffset = new Vector2(0.3f, 0.32f);
        KBoxCollider2D kBoxCollider2D = gameObject.AddOrGet <KBoxCollider2D>();

        kBoxCollider2D.offset = new Vector2(0f, 0.5f);
        kBoxCollider2D.size   = new Vector2(1f, 1f);
        GameObject gameObject2 = new GameObject("Mask");

        gameObject2.layer            = LayerMask.NameToLayer("PlaceWithDepth");
        gameObject2.transform.parent = gameObject.transform;
        gameObject2.transform.SetLocalPosition(new Vector3(0f, 0.5f, -3.537f));
        gameObject2.transform.eulerAngles = new Vector3(0f, 180f, 0f);
        MeshFilter meshFilter = gameObject2.AddComponent <MeshFilter>();

        meshFilter.sharedMesh = Assets.instance.commonPlacerAssets.mesh;
        MeshRenderer meshRenderer = gameObject2.AddComponent <MeshRenderer>();

        meshRenderer.lightProbeUsage      = LightProbeUsage.Off;
        meshRenderer.reflectionProbeUsage = ReflectionProbeUsage.Off;
        meshRenderer.shadowCastingMode    = ShadowCastingMode.Off;
        meshRenderer.receiveShadows       = false;
        meshRenderer.sharedMaterial       = default_material;
        EasingAnimations easingAnimations = gameObject2.AddComponent <EasingAnimations>();

        EasingAnimations.AnimationScales animationScales = default(EasingAnimations.AnimationScales);
        animationScales.name             = "ScaleUp";
        animationScales.startScale       = 0f;
        animationScales.endScale         = 1f;
        animationScales.type             = EasingAnimations.AnimationScales.AnimationType.EaseInOutBack;
        animationScales.easingMultiplier = 5f;
        EasingAnimations.AnimationScales animationScales2 = default(EasingAnimations.AnimationScales);
        animationScales2.name             = "ScaleDown";
        animationScales2.startScale       = 1f;
        animationScales2.endScale         = 0f;
        animationScales2.type             = EasingAnimations.AnimationScales.AnimationType.EaseOutBack;
        animationScales2.easingMultiplier = 1f;
        easingAnimations.scales           = new EasingAnimations.AnimationScales[2]
        {
            animationScales,
            animationScales2
        };
        return(gameObject);
    }
        public void SetCollider(bool original_size)
        {
            KBoxCollider2D component = base.master.GetComponent <KBoxCollider2D>();

            if (original_size)
            {
                component.size   = originalColliderSize;
                component.offset = originalColliderOffset;
            }
            else
            {
                component.size   = base.def.moundColliderSize;
                component.offset = base.def.moundColliderOffset;
            }
        }
 protected override void OnSpawn()
 {
     base.OnSpawn();
     KBatchedAnimTracker[] componentsInChildren = GetComponentsInChildren <KBatchedAnimTracker>(true);
     KBatchedAnimTracker[] array = componentsInChildren;
     foreach (KBatchedAnimTracker kBatchedAnimTracker in array)
     {
         if (kBatchedAnimTracker.useTargetPoint)
         {
             onWorkTargetSet += kBatchedAnimTracker.SetTarget;
         }
     }
     controller   = GetComponent <KBatchedAnimController>();
     animCollider = GetComponent <KBoxCollider2D>();
     baseOffset   = animCollider.offset;
 }
    public Vector3 GetWorldPivot()
    {
        Vector3        position  = base.transform.GetPosition();
        KBoxCollider2D component = GetComponent <KBoxCollider2D>();

        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
        {
            float   x      = position.x;
            Vector2 vector = component.offset;
            position.x = x + vector.x;
            float   y       = position.y;
            Vector2 vector2 = component.offset;
            float   y2      = vector2.y;
            Vector2 size    = component.size;
            position.y = y + (y2 - size.y / 2f);
        }
        return(position);
    }
Пример #12
0
    public static GameObject MakeHangingOffsets(GameObject template, int width, int height)
    {
        KBoxCollider2D component = template.GetComponent <KBoxCollider2D>();

        if ((bool)component)
        {
            component.size = new Vector2f(width, height);
            float a = 0.5f * (float)((width + 1) % 2);
            component.offset = new Vector2f(a, (float)(-height) / 2f + 1f);
        }
        OccupyArea component2 = template.GetComponent <OccupyArea>();

        if ((bool)component2)
        {
            component2.OccupiedCellsOffsets = GenerateHangingOffsets(width, height);
        }
        return(template);
    }
Пример #13
0
    public static GameObject AddCollision(GameObject template, CollisionShape shape, float width, float height)
    {
        switch (shape)
        {
        case CollisionShape.RECTANGLE:
        {
            KBoxCollider2D kBoxCollider2D = template.AddOrGet <KBoxCollider2D>();
            kBoxCollider2D.size = new Vector2f(width, height);
            break;
        }

        case CollisionShape.POLYGONAL:
            template.AddOrGet <PolygonCollider2D>();
            break;

        default:
        {
            KCircleCollider2D kCircleCollider2D = template.AddOrGet <KCircleCollider2D>();
            kCircleCollider2D.radius = Mathf.Max(width, height);
            break;
        }
        }
        return(template);
    }
    /// Modifies critters as they are loaded
    /// missing parameters: is_baby, override_prefix, lifespan, diet_list
    /// babyId: only reveals material, actually object is defined in egg
    public static void PatchCritters(KPrefabID prefab, GameObject critter)
    {
        CritterContainer setting = CustomizeCritterState.StateManager.State.critter_settings.Find(s => s.id == critter.name);

        if (setting == null)
        {
            return;
        }

        Debug.Log("DEBUG HELLO 1");

        if (setting.name != null)
        {
            prefab.PrefabTag = TagManager.Create(setting.id, setting.name);
            critter.GetComponent <KSelectable>()?.SetName(setting.name);
            critter.AddOrGet <DecorProvider>().overrideName = setting.name;
        }

        Debug.Log("DEBUG HELLO 2");

        if (setting.desc != null)
        {
            critter.AddOrGet <InfoDescription>().description = setting.desc;
        }

        Debug.Log("DEBUG HELLO 3");

        if (setting.anim_file != null)
        {
            KBatchedAnimController kbatchedAnimController = critter.AddOrGet <KBatchedAnimController>();
            kbatchedAnimController.AnimFiles = new KAnimFile[] { Assets.GetAnim(setting.anim_file) };
            //kbatchedAnimController.sceneLayer = sceneLayer;
            //kbatchedAnimController.initialAnim = initialAnim;
        }

        Debug.Log("DEBUG HELLO 4");

        if (setting.is_baby != null)
        {
            Debug.Log(setting.id + ".is_baby: This cannot be changed on existing critters.");
        }

        Debug.Log("DEBUG HELLO 5");

        if (setting.traitId != null)
        {
            Modifiers modifiers = critter.AddOrGet <Modifiers>();
            if (setting.traitId != "")
            {
                modifiers.initialTraits = new string[] { setting.traitId }
            }
            ;
            else
            {
                modifiers.initialTraits = null;
            }
            //modifiers.initialAmounts.Add(Db.Get().Amounts.HitPoints.Id);
        }

        Debug.Log("DEBUG HELLO 6");

        if (setting.override_prefix != null)
        {
            Debug.Log(setting.id + ".override_prefix: This cannot be changed on existing critters.");
        }

        Debug.Log("DEBUG HELLO 7");

        if (setting.space_requirement != null)
        {
            critter.AddOrGetDef <OvercrowdingMonitor.Def>().spaceRequiredPerCreature = setting.space_requirement.Value;
        }

        Debug.Log("DEBUG HELLO 8");

        if (setting.lifespan != null)
        {
            Debug.Log(setting.id + ".lifespan: This value is not read from the game. It exists only as artifact. Use traits instead!");
            //trait.Add(new AttributeModifier(Db.Get().Amounts.Age.maxAttribute.Id, 150f, name, false, false, true));
        }

        Debug.Log("DEBUG HELLO 9");

        if (setting.mass != null)
        {
            critter.AddOrGet <PrimaryElement>().Mass = setting.mass.Value;
        }

        Debug.Log("DEBUG HELLO 10");

        if (setting.width != null || setting.height != null)
        {
            float          width          = setting.width ?? 1f;
            float          height         = setting.height ?? 1f;
            KBoxCollider2D kboxCollider2D = critter.AddOrGet <KBoxCollider2D>();
            kboxCollider2D.size = new Vector2f(width, height);
            float num = 0.5f * (float)((width + 1) % 2);
            kboxCollider2D.offset = new Vector2f(num, (float)height / 2f);
            critter.GetComponent <KBatchedAnimController>().Offset = new Vector3(num, 0f, 0f);
            critter.AddOrGet <OccupyArea>().OccupiedCellsOffsets   = EntityTemplates.GenerateOffsets((int)Math.Round(width, 0), (int)Math.Round(height, 0));
        }

        Debug.Log("DEBUG HELLO 11");

        if (setting.decor != null)
        {
            DecorProvider decorProvider = critter.AddOrGet <DecorProvider>();
            decorProvider.SetValues(setting.decor.Value);
        }

        Debug.Log("DEBUG HELLO 12");

        if (setting.navGridName != null)
        {
            critter.AddOrGet <Navigator>().NavGridName = setting.navGridName;
        }

        Debug.Log("DEBUG HELLO 13");

        if (setting.navi != null)
        {
            critter.AddOrGet <Navigator>().CurrentNavType = setting.navi.Value;
        }

        Debug.Log("DEBUG HELLO 14");

        if (setting.moveSpeed != null)
        {
            critter.AddOrGet <Navigator>().defaultSpeed = setting.moveSpeed.Value;
        }

        Debug.Log("DEBUG HELLO 15");

        if (setting.dropOnDeath != null)
        {
            critter.AddOrGet <Butcherable>().SetDrops(setting.dropOnDeath);
        }

        Debug.Log("DEBUG HELLO 16");

        if (setting.canDrown != null)
        {
            if (setting.canDrown.Value)
            {
                critter.AddOrGet <DrowningMonitor>();
            }
            else
            {
                critter.RemoveComponents <DrowningMonitor>();
            }
        }

        Debug.Log("DEBUG HELLO 17");

        if (setting.canCrushed != null)
        {
            if (setting.canCrushed.Value)
            {
                critter.AddOrGet <EntombVulnerable>();
            }
            else
            {
                critter.RemoveComponents <EntombVulnerable>();
            }
        }

        Debug.Log("DEBUG HELLO 18");

        if (setting.tempLowDeath != null)
        {
            critter.AddOrGet <TemperatureVulnerable>().internalTemperatureLethal_Low = setting.tempLowDeath.Value;
        }

        Debug.Log("DEBUG HELLO 19");

        if (setting.tempLowWarning != null)
        {
            critter.AddOrGet <TemperatureVulnerable>().internalTemperatureWarning_Low = setting.tempLowWarning.Value;
        }

        Debug.Log("DEBUG HELLO 20");

        if (setting.tempHighWarning != null)
        {
            critter.AddOrGet <TemperatureVulnerable>().internalTemperatureWarning_High = setting.tempHighWarning.Value;
        }

        Debug.Log("DEBUG HELLO 21");

        if (setting.tempHighDeath != null)
        {
            critter.AddOrGet <TemperatureVulnerable>().internalTemperatureLethal_High = setting.tempHighDeath.Value;
        }

        Debug.Log("DEBUG HELLO 22");

        if (setting.tempBorn != null)
        {
            critter.AddOrGet <PrimaryElement>().Temperature = setting.tempBorn.Value;
        }

        Debug.Log("DEBUG HELLO 23");

        if (setting.pickup_only_from_top != null)
        {
            critter.AddOrGet <Baggable>().mustStandOntopOfTrapForPickup = setting.pickup_only_from_top.Value;
        }

        Debug.Log("DEBUG HELLO 24");

        if (setting.pickup_allow_mark != null)
        {
            critter.AddOrGet <Capturable>().allowCapture = setting.pickup_allow_mark.Value;
        }

        Debug.Log("DEBUG HELLO 25");

        if (setting.pickup_use_gun != null)
        {
            critter.AddOrGet <Baggable>().useGunForPickup = setting.pickup_use_gun.Value;
        }

        Debug.Log("DEBUG HELLO 26");

        if (setting.tags != null)
        {
            prefab.ProcessTags(setting.tags);
        }

        Debug.Log("DEBUG HELLO 27");

        if (setting.species != null)
        {
            critter.AddOrGet <CreatureBrain>().species = setting.species;
        }

        Debug.Log("DEBUG HELLO 28");

        if (setting.attackValue != null)
        {
            if (setting.attackValue.Value > 0f)
            {
                critter.AddWeapon(setting.attackValue.Value, setting.attackValue.Value, AttackProperties.DamageType.Standard, AttackProperties.TargetType.Single, 1, 0f);
            }
            else
            {
                critter.RemoveComponents <Weapon>();
            }
        }

        Debug.Log("DEBUG HELLO 29");

        if (setting.chore_table != null)
        {
            ChoreConsumer chore_consumer = critter.AddOrGet <ChoreConsumer>();
            chore_consumer.choreTable = setting.chore_table.CreateTable();
            // prefab.instantiateFn += delegate(GameObject go) { go.GetComponent<ChoreConsumer>().choreTable = chore_consumer.choreTable; };
        }

        Debug.Log("DEBUG HELLO 30");

        if (setting.adultId != null)
        {
            critter.AddOrGetDef <BabyMonitor.Def>().adultPrefab = setting.adultId;
        }

        Debug.Log("DEBUG HELLO 31");

        if (setting.dropOnMature != null)
        {
            critter.AddOrGetDef <BabyMonitor.Def>().onGrowDropID = setting.dropOnMature;
        }

        Debug.Log("DEBUG HELLO 32");

        if (setting.fertility_cycles != null)
        {
            critter.AddOrGetDef <FertilityMonitor.Def>().baseFertileCycles = setting.fertility_cycles.Value;
        }

        Debug.Log("DEBUG HELLO 33");

        if (setting.egg_chances != null)
        {
            critter.AddOrGetDef <FertilityMonitor.Def>().initialBreedingWeights = setting.egg_chances;
        }

        Debug.Log("DEBUG HELLO 34");

        if (setting.is_ranchable != null)
        {
            if (setting.is_ranchable.Value)
            {
                critter.AddOrGetDef <RanchableMonitor.Def>();
            }
            else
            {
                critter.RemoveDef <RanchableMonitor.Def>();
            }
        }

        Debug.Log("DEBUG HELLO 35");

        if (setting.calories_per_KG != null)
        {
            critter.AddOrGetDef <CreatureCalorieMonitor.Def>();
        }

        Debug.Log("DEBUG HELLO 36");

        if (setting.min_poop_KG != null)
        {
            critter.AddOrGetDef <CreatureCalorieMonitor.Def>().minPoopSizeInCalories = setting.min_poop_KG.Value * setting.calories_per_KG ?? 1f;
        }

        Debug.Log("DEBUG HELLO 37");

        if (setting.diet_list != null)
        {
            //Diet diet = new Diet(setting.diet_list.ToArray());
            //critter.AddOrGetDef<CreatureCalorieMonitor.Def>().diet = diet;
            //critter.AddOrGetDef<SolidConsumerMonitor.Def>().diet = diet;
        }

        Debug.Log("DEBUG HELLO 38");

        if (setting.eggId != null)
        {
            critter.AddOrGetDef <FertilityMonitor.Def>().eggPrefab = setting.eggId;
            prefab.prefabSpawnFn += delegate(GameObject inst)
            {
                WorldInventory.Instance.Discover(setting.eggId.ToTag(), WorldInventory.GetCategoryForTags(egg_tags));
            };
        }

        Debug.Log("DEBUG HELLO 39");

        if (setting.babyId != null)
        {
            prefab.prefabSpawnFn += delegate(GameObject inst)
            {
                WorldInventory.Instance.Discover(setting.babyId.ToTag(), WorldInventory.GetCategoryForTags(prefab.Tags));
            };
        }

        Debug.Log("DEBUG HELLO 40");

        if (setting.light != null)
        {
            if (setting.light.color != Color.black)
            {
                Light2D light2D = critter.AddOrGet <Light2D>();
                if (setting.light.color != null)
                {
                    light2D.Color = setting.light.color.Value;
                }
                light2D.overlayColour = TUNING.LIGHT2D.LIGHTBUG_OVERLAYCOLOR;
                if (setting.light.range != null)
                {
                    light2D.Range = setting.light.range.Value;
                }
                light2D.Angle       = 0f;
                light2D.Direction   = TUNING.LIGHT2D.LIGHTBUG_DIRECTION;
                light2D.Offset      = TUNING.LIGHT2D.LIGHTBUG_OFFSET;
                light2D.shape       = LightShape.Circle;
                light2D.drawOverlay = true;
                if (setting.light.lux != null)
                {
                    light2D.Lux = setting.light.lux.Value;
                }
                critter.AddOrGet <LightSymbolTracker>().targetSymbol = "snapTo_light_locator";
                critter.AddOrGetDef <CreatureLightToggleController.Def>();
            }
            else
            {
                critter.RemoveComponents <Light2D>();
                critter.RemoveComponents <LightSymbolTracker>();
                critter.RemoveDef <CreatureLightToggleController.Def>();
            }
        }

        Debug.Log("DEBUG HELLO 41");

        if (setting.expulsion != null)  //works also with gasses/liquids/solids
        {
            ElementDropperMonitor.Def def_morb = critter.AddOrGetDef <ElementDropperMonitor.Def>();
            if (setting.expulsion.element != null)
            {
                def_morb.dirtyEmitElement = setting.expulsion.element.ToSimHash();
            }
            if (setting.expulsion.probability != null)
            {
                def_morb.dirtyProbabilityPercent = setting.expulsion.probability.Value;
            }
            if (setting.expulsion.cellTargetMass != null)
            {
                def_morb.dirtyCellToTargetMass = setting.expulsion.cellTargetMass.Value;
            }
            if (setting.expulsion.massPerDirt != null)
            {
                def_morb.dirtyMassPerDirty = setting.expulsion.massPerDirt.Value;
            }
            if (setting.expulsion.onDeath != null)
            {
                def_morb.dirtyMassReleaseOnDeath = setting.expulsion.onDeath.Value;
            }
            if (setting.expulsion.diseaseId != null)
            {
                def_morb.emitDiseaseIdx = Db.Get().Diseases.GetIndex(setting.expulsion.diseaseId);
            }
            if (setting.expulsion.diseaseAmount != null)
            {
                def_morb.emitDiseasePerKg = setting.expulsion.diseaseAmount.Value;
            }
        }

        Debug.Log("DEBUG HELLO 42");

        if (setting.scales != null)
        {
            ScaleGrowthMonitor.Def def_scale = critter.AddOrGetDef <ScaleGrowthMonitor.Def>();
            if (setting.scales.growthRate != null)
            {
                def_scale.defaultGrowthRate = setting.scales.growthRate.Value;
            }
            if (setting.scales.mass != null)
            {
                def_scale.dropMass = setting.scales.mass.Value;
            }
            if (setting.scales.drop != null)
            {
                def_scale.itemDroppedOnShear = setting.scales.drop;
            }
            if (setting.scales.levelCount != null)
            {
                def_scale.levelCount = setting.scales.levelCount.Value;
            }
            if (setting.scales.atmosphere != null)
            {
                def_scale.targetAtmosphere = setting.scales.atmosphere.ToSimHash();
            }
        }

        Debug.Log("DEBUG HELLO 43");
    }
Пример #15
0
    protected override void OnSpawn()
    {
        base.OnSpawn();
        KBatchedAnimController component = GetComponent <KBatchedAnimController>();
        Rotatable component2             = GetComponent <Rotatable>();

        if ((Object)component != (Object)null && (Object)component2 == (Object)null)
        {
            component.Offset = Def.GetVisualizerOffset() + Def.placementPivot;
        }
        KBoxCollider2D component3 = GetComponent <KBoxCollider2D>();

        if ((Object)component3 != (Object)null)
        {
            Vector3 visualizerOffset = Def.GetVisualizerOffset();
            component3.offset += new Vector2(visualizerOffset.x, visualizerOffset.y);
        }
        int cell = Grid.PosToCell(base.transform.GetPosition());

        if (Def.IsFoundation)
        {
            int[] placementCells = base.PlacementCells;
            foreach (int num in placementCells)
            {
                Grid.Foundation[num] = true;
                Game.Instance.roomProber.SolidChangedEvent(num, false);
            }
        }
        Vector3 position = Grid.CellToPosCBC(cell, Def.SceneLayer);

        base.transform.SetPosition(position);
        PrimaryElement component4 = GetComponent <PrimaryElement>();

        if ((Object)component4 != (Object)null && component4.Mass == 0f)
        {
            component4.Mass = Def.Mass[0];
        }
        Def.MarkArea(cell, base.Orientation, Def.ObjectLayer, base.gameObject);
        if (Def.IsTilePiece)
        {
            Def.MarkArea(cell, base.Orientation, Def.TileLayer, base.gameObject);
            Def.RunOnArea(cell, base.Orientation, delegate(int c)
            {
                TileVisualizer.RefreshCell(c, Def.TileLayer, Def.ReplacementLayer);
            });
        }
        RegisterBlockTileRenderer();
        if (Def.PreventIdleTraversalPastBuilding)
        {
            for (int j = 0; j < base.PlacementCells.Length; j++)
            {
                Grid.PreventIdleTraversal[base.PlacementCells[j]] = true;
            }
        }
        KSelectable component5 = GetComponent <KSelectable>();

        if ((Object)component5 != (Object)null)
        {
            component5.SetStatusIndicatorOffset(Def.placementPivot);
        }
        Components.BuildingCompletes.Add(this);
        BuildingConfigManager.Instance.AddBuildingCompleteKComponents(base.gameObject, Def.Tag);
        hasSpawnedKComponents = true;
        scenePartitionerEntry = GameScenePartitioner.Instance.Add(base.name, this, GetExtents(), GameScenePartitioner.Instance.completeBuildings, null);
        Attributes attributes = this.GetAttributes();

        if (attributes != null)
        {
            Deconstructable component6 = GetComponent <Deconstructable>();
            if ((Object)component6 != (Object)null)
            {
                for (int k = 1; k < component6.constructionElements.Length; k++)
                {
                    Tag     tag     = component6.constructionElements[k];
                    Element element = ElementLoader.GetElement(tag);
                    if (element != null)
                    {
                        foreach (AttributeModifier attributeModifier in element.attributeModifiers)
                        {
                            attributes.Add(attributeModifier);
                        }
                    }
                    else
                    {
                        GameObject gameObject = Assets.TryGetPrefab(tag);
                        if ((Object)gameObject != (Object)null)
                        {
                            PrefabAttributeModifiers component7 = gameObject.GetComponent <PrefabAttributeModifiers>();
                            if ((Object)component7 != (Object)null)
                            {
                                foreach (AttributeModifier descriptor in component7.descriptors)
                                {
                                    attributes.Add(descriptor);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Пример #16
0
    public GameObject CreatePrefab()
    {
        string     name       = DUPLICANTS.MODIFIERS.BASEDUPLICANT.NAME;
        GameObject gameObject = EntityTemplates.CreateEntity(ID, name, true);

        gameObject.AddOrGet <StateMachineController>();
        MinionModifiers modifiers = gameObject.AddOrGet <MinionModifiers>();

        AddMinionAmounts(modifiers);
        AddMinionTraits(name, modifiers);
        gameObject.AddOrGet <MinionBrain>();
        gameObject.AddOrGet <KPrefabID>().AddTag(GameTags.DupeBrain, false);
        gameObject.AddOrGet <Worker>();
        gameObject.AddOrGet <ChoreConsumer>();
        Storage storage = gameObject.AddOrGet <Storage>();

        storage.fxPrefix   = Storage.FXPrefix.PickedUp;
        storage.dropOnLoad = true;
        storage.SetDefaultStoredItemModifiers(new List <Storage.StoredItemModifier>
        {
            Storage.StoredItemModifier.Preserve,
            Storage.StoredItemModifier.Seal
        });
        gameObject.AddOrGet <Health>();
        OxygenBreather oxygenBreather = gameObject.AddOrGet <OxygenBreather>();

        oxygenBreather.O2toCO2conversion  = 0.02f;
        oxygenBreather.lowOxygenThreshold = 0.52f;
        oxygenBreather.noOxygenThreshold  = 0.05f;
        oxygenBreather.mouthOffset        = new Vector2f(0.25f, 0.7f);
        oxygenBreather.minCO2ToEmit       = 0.02f;
        oxygenBreather.breathableCells    = new CellOffset[6]
        {
            new CellOffset(0, 0),
            new CellOffset(0, 1),
            new CellOffset(1, 1),
            new CellOffset(-1, 1),
            new CellOffset(1, 0),
            new CellOffset(-1, 0)
        };
        gameObject.AddOrGet <WarmBlooded>();
        gameObject.AddOrGet <MinionIdentity>();
        GridVisibility gridVisibility = gameObject.AddOrGet <GridVisibility>();

        gridVisibility.radius      = 30f;
        gridVisibility.innerRadius = 20f;
        gameObject.AddOrGet <MiningSounds>();
        gameObject.AddOrGet <SaveLoadRoot>();
        gameObject.AddOrGet <AntiCluster>();
        Navigator navigator = gameObject.AddOrGet <Navigator>();

        navigator.NavGridName    = "MinionNavGrid";
        navigator.CurrentNavType = NavType.Floor;
        KBatchedAnimController kBatchedAnimController = gameObject.AddOrGet <KBatchedAnimController>();

        kBatchedAnimController.isMovable  = true;
        kBatchedAnimController.sceneLayer = Grid.SceneLayer.Move;
        kBatchedAnimController.AnimFiles  = new KAnimFile[8]
        {
            Assets.GetAnim("body_comp_default_kanim"),
            Assets.GetAnim("anim_construction_default_kanim"),
            Assets.GetAnim("anim_idles_default_kanim"),
            Assets.GetAnim("anim_loco_firepole_kanim"),
            Assets.GetAnim("anim_loco_new_kanim"),
            Assets.GetAnim("anim_loco_tube_kanim"),
            Assets.GetAnim("anim_construction_firepole_kanim"),
            Assets.GetAnim("anim_construction_jetsuit_kanim")
        };
        KBoxCollider2D kBoxCollider2D = gameObject.AddOrGet <KBoxCollider2D>();

        kBoxCollider2D.offset = new Vector2(0f, 0.8f);
        kBoxCollider2D.size   = new Vector2(1f, 1.5f);
        SnapOn snapOn = gameObject.AddOrGet <SnapOn>();

        snapOn.snapPoints = new List <SnapOn.SnapPoint>(new SnapOn.SnapPoint[17]
        {
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"dig",
                buildFile      = Assets.GetAnim("excavator_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"build",
                buildFile      = Assets.GetAnim("constructor_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"fetchliquid",
                buildFile      = Assets.GetAnim("water_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"paint",
                buildFile      = Assets.GetAnim("painting_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"harvest",
                buildFile      = Assets.GetAnim("plant_harvester_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"capture",
                buildFile      = Assets.GetAnim("net_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"attack",
                buildFile      = Assets.GetAnim("attack_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"pickup",
                buildFile      = Assets.GetAnim("pickupdrop_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"store",
                buildFile      = Assets.GetAnim("pickupdrop_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"disinfect",
                buildFile      = Assets.GetAnim("plant_spray_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"tend",
                buildFile      = Assets.GetAnim("plant_harvester_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "carry",
                automatic      = false,
                context        = (HashedString)string.Empty,
                buildFile      = null,
                overrideSymbol = (HashedString)"snapTo_chest"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "build",
                automatic      = false,
                context        = (HashedString)string.Empty,
                buildFile      = null,
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "remote",
                automatic      = false,
                context        = (HashedString)string.Empty,
                buildFile      = null,
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "snapTo_neck",
                automatic      = false,
                context        = (HashedString)string.Empty,
                buildFile      = Assets.GetAnim("helm_oxygen_kanim"),
                overrideSymbol = (HashedString)"snapTo_neck"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"powertinker",
                buildFile      = Assets.GetAnim("electrician_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"specialistdig",
                buildFile      = Assets.GetAnim("excavator_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            }
        });
        gameObject.AddOrGet <Effects>();
        gameObject.AddOrGet <Traits>();
        gameObject.AddOrGet <AttributeLevels>();
        gameObject.AddOrGet <AttributeConverters>();
        PrimaryElement primaryElement = gameObject.AddOrGet <PrimaryElement>();

        primaryElement.InternalTemperature = 310.15f;
        primaryElement.MassPerUnit         = 30f;
        primaryElement.ElementID           = SimHashes.Creature;
        gameObject.AddOrGet <ChoreProvider>();
        gameObject.AddOrGetDef <DebugGoToMonitor.Def>();
        gameObject.AddOrGetDef <SpeechMonitor.Def>();
        gameObject.AddOrGetDef <BlinkMonitor.Def>();
        gameObject.AddOrGetDef <ConversationMonitor.Def>();
        gameObject.AddOrGet <Sensors>();
        gameObject.AddOrGet <Chattable>();
        gameObject.AddOrGet <FaceGraph>();
        gameObject.AddOrGet <Accessorizer>();
        gameObject.AddOrGet <Schedulable>();
        LoopingSounds loopingSounds = gameObject.AddOrGet <LoopingSounds>();

        loopingSounds.updatePosition = true;
        gameObject.AddOrGet <AnimEventHandler>();
        FactionAlignment factionAlignment = gameObject.AddOrGet <FactionAlignment>();

        factionAlignment.Alignment = FactionManager.FactionID.Duplicant;
        gameObject.AddOrGet <Weapon>();
        gameObject.AddOrGet <RangedAttackable>();
        gameObject.AddOrGet <CharacterOverlay>();
        OccupyArea occupyArea = gameObject.AddOrGet <OccupyArea>();

        occupyArea.objectLayers         = new ObjectLayer[1];
        occupyArea.ApplyToCells         = false;
        occupyArea.OccupiedCellsOffsets = new CellOffset[2]
        {
            new CellOffset(0, 0),
            new CellOffset(0, 1)
        };
        gameObject.AddOrGet <Pickupable>();
        CreatureSimTemperatureTransfer creatureSimTemperatureTransfer = gameObject.AddOrGet <CreatureSimTemperatureTransfer>();

        creatureSimTemperatureTransfer.SurfaceArea = 10f;
        creatureSimTemperatureTransfer.Thickness   = 0.01f;
        gameObject.AddOrGet <SicknessTrigger>();
        gameObject.AddOrGet <ClothingWearer>();
        gameObject.AddOrGet <SuitEquipper>();
        DecorProvider decorProvider = gameObject.AddOrGet <DecorProvider>();

        decorProvider.baseRadius = 3f;
        decorProvider.isMovable  = true;
        gameObject.AddOrGet <ConsumableConsumer>();
        gameObject.AddOrGet <NoiseListener>();
        gameObject.AddOrGet <MinionResume>();
        DuplicantNoiseLevels.SetupNoiseLevels();
        SetupLaserEffects(gameObject);
        SymbolOverrideController symbolOverrideController = SymbolOverrideControllerUtil.AddToPrefab(gameObject);

        symbolOverrideController.applySymbolOverridesEveryFrame = true;
        ConfigureSymbols(gameObject);
        return(gameObject);
    }