示例#1
0
        private void SpawnFoldingTable()
        {
            Vector2              nearbyPoint          = Owner.CenterPosition + (Owner.unadjustedAimPoint.XY() - Owner.CenterPosition).normalized;
            IntVector2?          nearestAvailableCell = Owner.CurrentRoom.GetNearestAvailableCell(nearbyPoint, new IntVector2?(IntVector2.One), new CellTypes?(CellTypes.FLOOR), false, null);
            FoldingTableItem     component6           = PickupObjectDatabase.GetById(644).GetComponent <FoldingTableItem>();
            GameObject           gameObject5          = component6.TableToSpawn.gameObject;
            GameObject           gameObject6          = UnityEngine.Object.Instantiate <GameObject>(gameObject5.gameObject, nearestAvailableCell.Value.ToVector2(), Quaternion.identity);
            SpeculativeRigidbody componentInChildren  = gameObject6.GetComponentInChildren <SpeculativeRigidbody>();
            FlippableCover       component7           = gameObject6.GetComponent <FlippableCover>();

            component7.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(component7);
            component7.ConfigureOnPlacement(component7.transform.position.XY().GetAbsoluteRoom());
            componentInChildren.Initialize();
            PhysicsEngine.Instance.RegisterOverlappingGhostCollisionExceptions(componentInChildren, null, false);
        }
示例#2
0
        private void HandleHit(Projectile arg1, SpeculativeRigidbody arg2, bool arg3)
        {
            if (arg2.aiActor != null && arg2.aiActor.behaviorSpeculator && !arg2.aiActor.IsHarmlessEnemy)
            {
                PlayerController player = gun.CurrentOwner as PlayerController;
                if ((player.HasPickupID(131) || player.HasPickupID(239) || player.HasPickupID(815)) || (gun.DuctTapeMergedGunIDs != null))
                {
                    float value2 = UnityEngine.Random.Range(0.0f, 1.0f);
                    if (value2 <= 0.05 && armorCount < 10)
                    {
                        GameManager.Instance.StartCoroutine(this.Clang());
                        LootEngine.SpawnItem(PickupObjectDatabase.GetById(120).gameObject, arg2.sprite.WorldBottomCenter, Vector2.up, 1f, true, false, true);
                        armorCount += 1;
                    }
                }

                float value = UnityEngine.Random.Range(0.0f, 1.0f);
                if (value <= 0.05)
                {
                    GameManager.Instance.StartCoroutine(this.Clang());

                    // TURRET
                    SpawnObjectPlayerItem portableturret = PickupObjectDatabase.GetById(201).GetComponent <SpawnObjectPlayerItem>();
                    String     turretGuid    = portableturret.enemyGuidToSpawn;
                    GameObject objectToSpawn = EnemyDatabase.GetOrLoadByGuid(turretGuid).gameObject;

                    GameObject     gameObject2 = UnityEngine.Object.Instantiate <GameObject>(objectToSpawn, arg2.sprite.WorldBottomCenter, Quaternion.identity);
                    tk2dBaseSprite component4  = gameObject2.GetComponent <tk2dBaseSprite>();
                    if (component4)
                    {
                        component4.sprite.IsPerpendicular = true;
                        component4.PlaceAtPositionByAnchor(arg2.sprite.WorldBottomCenter.ToVector3ZUp(component4.transform.position.z), tk2dBaseSprite.Anchor.MiddleCenter);
                    }
                    this.spawnedPlayerObject = gameObject2;
                    PortableTurretController component5 = this.spawnedPlayerObject.GetComponent <PortableTurretController>();
                    if (component5)
                    {
                        component5.sourcePlayer = player;
                    }
                }

                else
                {
                    if (value <= 0.1)
                    {
                        GameManager.Instance.StartCoroutine(this.Clang());

                        //MINE
                        SpawnObjectPlayerItem proximitymine = PickupObjectDatabase.GetById(66).GetComponent <SpawnObjectPlayerItem>();
                        GameObject            mineObject    = proximitymine.objectToSpawn.gameObject;

                        GameObject     mineObject2 = UnityEngine.Object.Instantiate <GameObject>(mineObject, arg2.sprite.WorldBottomCenter, Quaternion.identity);
                        tk2dBaseSprite mineSprite  = mineObject2.GetComponent <tk2dBaseSprite>();
                        if (mineSprite)
                        {
                            mineSprite.IsPerpendicular = true;
                            mineSprite.PlaceAtPositionByAnchor(arg2.sprite.WorldBottomCenter, tk2dBaseSprite.Anchor.MiddleCenter);
                        }
                    }

                    else
                    {
                        if (value <= 0.15)
                        {
                            GameManager.Instance.StartCoroutine(this.Clang());

                            //TABLE
                            FoldingTableItem     foldingtable        = PickupObjectDatabase.GetById(644).GetComponent <FoldingTableItem>();
                            GameObject           tableObject         = foldingtable.TableToSpawn.gameObject;
                            GameObject           gameObject          = UnityEngine.Object.Instantiate <GameObject>(tableObject.gameObject, arg2.sprite.WorldBottomCenter, Quaternion.identity);
                            SpeculativeRigidbody componentInChildren = gameObject.GetComponentInChildren <SpeculativeRigidbody>();
                            FlippableCover       component           = gameObject.GetComponent <FlippableCover>();
                            component.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(component);
                            component.ConfigureOnPlacement(component.transform.position.XY().GetAbsoluteRoom());
                            componentInChildren.Initialize();
                            PhysicsEngine.Instance.RegisterOverlappingGhostCollisionExceptions(componentInChildren, null, false);
                        }
                    }
                }
            }
        }
示例#3
0
        private void SpawnObjects(GameObject[] selectedObjects)
        {
            ObjectPrefabSpawnCount = selectedObjects.Length;
            if (ObjectPrefabSpawnCount < 0 | selectedObjects == null)
            {
                if (ExpandSettings.debugMode)
                {
                    ETGModConsole.Log("[DEBUG] ERROR: Object array is empty or null! Nothing to spawn!");
                }
                return;
            }
            IntVector2 pos = specRigidbody.UnitCenter.ToIntVector2(VectorConversions.Floor);

            if (aiActor.IsFalling && !allowSpawnOverPit)
            {
                return;
            }
            if (GameManager.Instance.Dungeon.CellIsPit(specRigidbody.UnitCenter.ToVector3ZUp(0f)) && !allowSpawnOverPit)
            {
                return;
            }
            RoomHandler roomFromPosition     = GameManager.Instance.Dungeon.GetRoomFromPosition(pos);
            List <SpeculativeRigidbody> list = new List <SpeculativeRigidbody>();

            list.Add(specRigidbody);
            Vector2 unitBottomLeft = specRigidbody.UnitBottomLeft;

            for (int i = 0; i < ObjectPrefabSpawnCount; i++)
            {
                if (objectsToSpawn == null)
                {
                    return;
                }
                GameObject SelectedObject = selectedObjects[i];
                if (spawnRatCorpse)
                {
                    SelectedObject = ExpandPrefabs.RatCorpseNPC;
                }
                GameObject SpawnedObject = null;
                if (!usesExternalObjectArray)
                {
                    if (spawnRatCorpse)
                    {
                        SpawnedObject = Instantiate(SelectedObject, (specRigidbody.GetUnitCenter(ColliderType.HitBox) - new Vector2(0.6f, 0.6f)).ToVector3ZUp(), Quaternion.identity);
                    }
                    else if (SelectedObject.GetComponent <Chest>() != null)
                    {
                        if (GameManager.Instance.Dungeon.GetRoomFromPosition(aiActor.transform.PositionVector2().ToIntVector2()) != null)
                        {
                            // RoomHandler currentRoom = aiActor.GetAbsoluteParentRoom();
                            RoomHandler        currentRoom  = GameManager.Instance.Dungeon.GetRoomFromPosition(aiActor.transform.PositionVector2().ToIntVector2());
                            Chest              TruthChest   = SelectedObject.GetComponent <Chest>();
                            WeightedGameObject wChestObject = new WeightedGameObject();
                            wChestObject.rawGameObject = SelectedObject;
                            WeightedGameObjectCollection wChestObjectCollection = new WeightedGameObjectCollection();
                            wChestObjectCollection.Add(wChestObject);
                            Chest PlacedTruthChest = currentRoom.SpawnRoomRewardChest(wChestObjectCollection, aiActor.transform.PositionVector2().ToIntVector2());
                            SpawnedObject = PlacedTruthChest.gameObject;
                        }
                    }
                    else
                    {
                        SpawnedObject = Instantiate(SelectedObject, specRigidbody.UnitCenter.ToIntVector2(VectorConversions.Floor).ToVector3(), Quaternion.identity);
                    }
                    if (SpawnedObject == null)
                    {
                        return;
                    }
                }

                if (SpawnedObject == null)
                {
                    return;
                }

                if (ExpandSettings.debugMode)
                {
                    ETGModConsole.Log("About to Spawn an object after death.");
                    ETGModConsole.Log("Object: " + SpawnedObject.name);
                    ETGModConsole.Log("AIActor:" + aiActor.GetActorName());
                }

                float RandomIntervalFloat       = UnityEngine.Random.Range(0.02f, 0.06f);
                float RandomDispFloat           = UnityEngine.Random.Range(0.1f, 0.16f);
                float RandomDispIntensityFloat  = UnityEngine.Random.Range(0.1f, 0.4f);
                float RandomColorProbFloat      = UnityEngine.Random.Range(0.05f, 0.2f);
                float RandomColorIntensityFloat = UnityEngine.Random.Range(0.1f, 0.25f);

                if (!spawnRatCorpse)
                {
                    if (SpawnedObject.GetComponent <tk2dBaseSprite>() != null)
                    {
                        ExpandShaders.Instance.ApplyGlitchShader(SpawnedObject.GetComponent <tk2dBaseSprite>(), true, RandomIntervalFloat, RandomDispFloat, RandomDispIntensityFloat, RandomColorProbFloat, RandomColorProbFloat);
                    }
                    else if (SpawnedObject.GetComponentInChildren <tk2dBaseSprite>() != null && SpawnedObject.GetComponent <Chest>() == null)
                    {
                        ExpandShaders.Instance.ApplyGlitchShader(SpawnedObject.GetComponentInChildren <tk2dBaseSprite>(), true, RandomIntervalFloat, RandomDispFloat, RandomDispIntensityFloat, RandomColorProbFloat, RandomColorProbFloat);
                    }
                }
                if (SpawnedObject != null)
                {
                    if (!usesExternalObjectArray && SpawnedObject.GetComponent <MysteryMimicManController>() != null)
                    {
                        Destroy(SpawnedObject.GetComponent <MysteryMimicManController>());
                    }

                    if (!usesExternalObjectArray && SpawnedObject.GetComponent <TalkDoerLite>() != null)
                    {
                        TalkDoerLite talkdoerComponent = SpawnedObject.GetComponent <TalkDoerLite>();
                        talkdoerComponent.SpeaksGleepGlorpenese = true;
                        talkdoerComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(talkdoerComponent);
                        if (SpawnedObject.name == ExpandPrefabs.RatCorpseNPC.name && !usesExternalObjectArray)
                        {
                            talkdoerComponent.transform.position.XY().GetAbsoluteRoom().TransferInteractableOwnershipToDungeon(talkdoerComponent);
                        }
                        else if (spawnRatCorpse)
                        {
                            talkdoerComponent.transform.position.XY().GetAbsoluteRoom().TransferInteractableOwnershipToDungeon(talkdoerComponent);
                        }
                        if (SpawnedObject.name.StartsWith(ExpandPrefabs.RatCorpseNPC.name))
                        {
                            talkdoerComponent.playmakerFsm.SetState("Set Mode");
                            // ExpandUtility.AddHealthHaver(talkdoerComponent.gameObject, 60, flashesOnDamage: false, exploderSpawnsItem: ratCorpseSpawnsItemOnExplosion);
                            ExpandUtility.GenerateHealthHaver(talkdoerComponent.gameObject, 60, flashesOnDamage: false, exploderSpawnsItem: ratCorpseSpawnsItemOnExplosion, isCorruptedObject: false, isRatNPC: true);
                            if (ratCorpseSpawnsKey)
                            {
                                HealthHaver ratCorpseHealthHaver = talkdoerComponent.gameObject.GetComponent <HealthHaver>();
                                ratCorpseHealthHaver.gameObject.AddComponent <ExpandSpawnGlitchObjectOnDeath>();
                                ExpandSpawnGlitchObjectOnDeath ratCorpseObjectSpawnOnDeath = ratCorpseHealthHaver.gameObject.GetComponent <ExpandSpawnGlitchObjectOnDeath>();
                                ratCorpseObjectSpawnOnDeath.spawnRatKey = true;
                            }
                        }
                    }

                    if (!usesExternalObjectArray && SpawnedObject.GetComponentInChildren <KickableObject>() != null && SpawnedObject.GetComponent <TalkDoerLite>() == null)
                    {
                        KickableObject kickableObjectComponent = SpawnedObject.GetComponentInChildren <KickableObject>();
                        kickableObjectComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(kickableObjectComponent);
                        kickableObjectComponent.ConfigureOnPlacement(kickableObjectComponent.transform.position.XY().GetAbsoluteRoom());
                    }

                    if (!usesExternalObjectArray && SpawnedObject.GetComponent <FlippableCover>() != null)
                    {
                        FlippableCover tableComponent = SpawnedObject.GetComponent <FlippableCover>();
                        tableComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(tableComponent);
                        tableComponent.ConfigureOnPlacement(tableComponent.transform.position.XY().GetAbsoluteRoom());
                        SpawnedObject.AddComponent <ExpandKickableObject>();
                        ExpandKickableObject chaosKickableComponent = SpawnedObject.GetComponent <ExpandKickableObject>();
                        chaosKickableComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(chaosKickableComponent);
                    }

                    if (!usesExternalObjectArray && SpawnedObject.GetComponent <NoteDoer>() != null)
                    {
                        NoteDoer noteComponent = SpawnedObject.GetComponent <NoteDoer>();
                        noteComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(noteComponent);
                        noteComponent.alreadyLocalized     = true;
                        noteComponent.useAdditionalStrings = false;
                        noteComponent.stringKey            = ("Here lies " + aiActor.GetActorName() + "\nHe was annoying anyways....");
                    }

                    /*if (!usesExternalObjectArray && SpawnedObject.GetComponent<HeartDispenser>() != null) {
                     *  HeartDispenser heartDispenserComponent = SpawnedObject.GetComponent<HeartDispenser>();
                     *  heartDispenserComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(heartDispenserComponent);
                     * }*/

                    if (SpawnedObject.GetComponentInChildren <SpeculativeRigidbody>() != null &&
                        SpawnedObject.GetComponentInChildren <KickableObject>() == null &&
                        SpawnedObject.GetComponent <TrapController>() == null &&
                        SpawnedObject.GetComponent <FlippableCover>() == null &&
                        SpawnedObject.GetComponent <Chest>() == null &&
                        SelectedObject.name != "NPC_ResourcefulRat_Beaten" &&
                        !usesExternalObjectArray)
                    {
                        SpeculativeRigidbody SpawnedObjectRigidBody = SpawnedObject.GetComponentInChildren <SpeculativeRigidbody>();
                        SpawnedObjectRigidBody.PrimaryPixelCollider.Enabled = false;
                        SpawnedObjectRigidBody.HitboxPixelCollider.Enabled  = false;
                        SpawnedObjectRigidBody.CollideWithOthers            = false;
                    }
                }

                if (SpawnedObject.GetComponentInChildren <SpeculativeRigidbody>() != null && SpawnedObject.name.ToLower().StartsWith("Table"))
                {
                    try {
                        SpeculativeRigidbody objectSpecRigidBody = SpawnedObject.GetComponentInChildren <SpeculativeRigidbody>();
                        objectSpecRigidBody.Initialize();
                        Vector2 a      = unitBottomLeft - (objectSpecRigidBody.UnitBottomLeft - SpawnedObject.transform.position.XY());
                        Vector2 vector = a + new Vector2(Mathf.Max(0f, specRigidbody.UnitDimensions.x - objectSpecRigidBody.UnitDimensions.x), 0f);
                        SpawnedObject.transform.position = Vector2.Lerp(a, vector, (ObjectPrefabSpawnCount != 1) ? i / (ObjectPrefabSpawnCount - 1f) : 0f);
                        objectSpecRigidBody.Reinitialize();
                        a      -= new Vector2(PhysicsEngine.PixelToUnit(extraPixelWidth), 0f);
                        vector += new Vector2(PhysicsEngine.PixelToUnit(extraPixelWidth), 0f);
                        Vector2       a2            = Vector2.Lerp(a, vector, (ObjectPrefabSpawnCount != 1) ? i / (ObjectPrefabSpawnCount - 1f) : 0.5f);
                        IntVector2    intVector     = PhysicsEngine.UnitToPixel(a2 - SpawnedObject.transform.position.XY());
                        CollisionData collisionData = null;
                        if (PhysicsEngine.Instance.RigidbodyCastWithIgnores(objectSpecRigidBody, intVector, out collisionData, true, true, null, false, list.ToArray()))
                        {
                            intVector = collisionData.NewPixelsToMove;
                        }
                        CollisionData.Pool.Free(ref collisionData);
                        SpawnedObject.transform.position += PhysicsEngine.PixelToUnit(intVector).ToVector3ZUp(1f);
                        objectSpecRigidBody.Reinitialize();
                        list.Add(objectSpecRigidBody);
                    } catch (Exception ex) {
                        if (ExpandSettings.debugMode)
                        {
                            ETGModConsole.Log("[DEBUG]: Warning: Exception caught while setting up rigid body settings in ChaosSpawnGlitchedObjectONDeath!");
                            Debug.Log("Warning: Exception caught while setting up rigid body settings in ChaosSpawnGlitchedObjectONDeath!");
                            Debug.LogException(ex);
                        }
                    }
                }
            }
            if (list.Count > 0)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    for (int k = 0; k < list.Count; k++)
                    {
                        if (j != k)
                        {
                            list[j].RegisterGhostCollisionException(list[k]);
                        }
                    }
                }
            }
        }
        public void InitializeInternal(PickupObject i)
        {
            this.item = i;
            if (this.item && this.item.encounterTrackable)
            {
                GameStatsManager.Instance.SingleIncrementDifferentiator(this.item.encounterTrackable);
            }

            this.CurrentPrice = this.item.PurchasePrice;
            if (this.m_baseParentShop != null && this.CurrencyType == ShopCurrencyType.KEYS)
            {
                this.CurrentPrice = 1;
                if (this.item.quality == PickupObject.ItemQuality.A)
                {
                    this.CurrentPrice = 2;
                }
                if (this.item.quality == PickupObject.ItemQuality.S)
                {
                    this.CurrentPrice = 3;
                }
            }
            if (this.m_baseParentShop != null && this.CurrencyType == ShopCurrencyType.BLANKS)
            {
                this.CurrentPrice = 1;
                if (this.item.quality == PickupObject.ItemQuality.A || this.item.quality == PickupObject.ItemQuality.S)
                {
                    this.CurrentPrice = 2;
                }
            }
            if (this.m_baseParentShop != null && this.CurrencyType == ShopCurrencyType.CUSTOM)
            {
                this.CurrentPrice = 1;
                if (customPrice != null)
                {
                    this.CurrentPrice = customPrice(this.m_baseParentShop, this, this.item);
                }
                else
                {
                    ETGModConsole.Log("CustomPrice is sadly null please look into this!");
                }
            }

            base.gameObject.AddComponent <tk2dSprite>();
            tk2dSprite tk2dSprite = i.GetComponent <tk2dSprite>();

            if (tk2dSprite == null)
            {
                tk2dSprite = i.GetComponentInChildren <tk2dSprite>();
            }
            base.sprite.SetSprite(tk2dSprite.Collection, tk2dSprite.spriteId);
            base.sprite.IsPerpendicular = true;
            if (this.UseOmnidirectionalItemFacing)
            {
                base.sprite.IsPerpendicular = false;
            }
            base.sprite.HeightOffGround       = 1f;
            this.UseOmnidirectionalItemFacing = true;
            base.sprite.PlaceAtPositionByAnchor(base.transform.parent.position, tk2dBaseSprite.Anchor.MiddleCenter);
            base.sprite.transform.position = base.sprite.transform.position.Quantize(0.0625f);
            DepthLookupManager.ProcessRenderer(base.sprite.renderer);
            tk2dSprite componentInParent = base.transform.parent.gameObject.GetComponentInParent <tk2dSprite>();

            if (componentInParent != null)
            {
                componentInParent.AttachRenderer(base.sprite);
            }
            SpriteOutlineManager.AddOutlineToSprite(base.sprite, Color.black, 0.1f, 0.05f, SpriteOutlineManager.OutlineType.NORMAL);
            GameObject gameObject = null;

            if (this.m_parentShop != null && this.m_parentShop.shopItemShadowPrefab != null)
            {
                gameObject = this.m_parentShop.shopItemShadowPrefab;
            }
            if (this.m_baseParentShop != null && this.m_baseParentShop.shopItemShadowPrefab != null)
            {
                gameObject = this.m_baseParentShop.shopItemShadowPrefab;
            }
            if (gameObject != null)
            {
                if (!this.m_shadowObject)
                {
                    this.m_shadowObject = UnityEngine.Object.Instantiate <GameObject>(gameObject);
                }
                tk2dBaseSprite component = this.m_shadowObject.GetComponent <tk2dBaseSprite>();
                component.PlaceAtPositionByAnchor(base.sprite.WorldBottomCenter, tk2dBaseSprite.Anchor.MiddleCenter);
                component.transform.position = component.transform.position.Quantize(0.0625f);
                base.sprite.AttachRenderer(component);
                component.transform.parent = base.sprite.transform;
                component.HeightOffGround  = -0.5f;
            }
            base.sprite.UpdateZDepth();
            SpeculativeRigidbody orAddComponent = base.gameObject.GetOrAddComponent <SpeculativeRigidbody>();

            orAddComponent.PixelColliders = new List <PixelCollider>();
            PixelCollider pixelCollider = new PixelCollider
            {
                ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Circle,
                CollisionLayer         = CollisionLayer.HighObstacle,
                ManualDiameter         = 14
            };
            Vector2 vector = base.sprite.WorldCenter - base.transform.position.XY();

            pixelCollider.ManualOffsetX = PhysicsEngine.UnitToPixel(vector.x) - 7;
            pixelCollider.ManualOffsetY = PhysicsEngine.UnitToPixel(vector.y) - 7;
            orAddComponent.PixelColliders.Add(pixelCollider);
            orAddComponent.Initialize();
            orAddComponent.OnPreRigidbodyCollision = null;
            SpeculativeRigidbody speculativeRigidbody = orAddComponent;

            speculativeRigidbody.OnPreRigidbodyCollision = (SpeculativeRigidbody.OnPreRigidbodyCollisionDelegate)Delegate.Combine(speculativeRigidbody.OnPreRigidbodyCollision, new SpeculativeRigidbody.OnPreRigidbodyCollisionDelegate(this.ItemOnPreRigidbodyCollision));
            base.RegenerateCache();
            if (!GameManager.Instance.IsFoyer && this.item is Gun && GameManager.Instance.PrimaryPlayer.CharacterUsesRandomGuns)
            {
                this.ForceOutOfStock();
            }
        }