Ejemplo n.º 1
0
    private void SpawnPickUp()
    {
        int index = _nextPickup;

        _nextPickup = (_nextPickup + 1) % _pickups.Length;
        PickupObject obj  = Instantiate(_pickUpObject, GameManager.GetRandomSpawnPoint(), Quaternion.identity);
        Sprite       icon = _pickups[index].Icon;

        if (icon != null)
        {
            obj.GetComponentInChildren <SpriteRenderer>().sprite = icon;
        }

        obj.OnPickup += id => OnPickUp(id, _pickups[index]);
    }
        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();
            }
        }
        private IEnumerator HandleSoldItem(PickupObject targetItem)
        {
            if (!targetItem)
            {
                m_currentlySellingAnItem = false; yield break;
            }
            while (m_currentlySellingAnItem)
            {
                yield return(null);
            }
            m_currentlySellingAnItem = true;
            targetItem.IsBeingSold   = true;
            float magnitude = (targetItem.sprite.WorldCenter - specRigidbody.UnitCenter).magnitude;

            if (!targetItem.sprite || magnitude > 1.8f)
            {
                targetItem.IsBeingSold   = false;
                m_currentlySellingAnItem = false;
                yield break;
            }
            IPlayerInteractable ixable = null;

            if (targetItem is PassiveItem)
            {
                PassiveItem passiveItem = targetItem as PassiveItem;
                passiveItem.GetRidOfMinimapIcon();
                ixable = (targetItem as PassiveItem);
            }
            else if (targetItem is Gun)
            {
                Gun gun = targetItem as Gun;
                gun.GetRidOfMinimapIcon();
                ixable = (targetItem as Gun);
            }
            else if (targetItem is PlayerItem)
            {
                PlayerItem playerItem = targetItem as PlayerItem;
                playerItem.GetRidOfMinimapIcon();
                ixable = (targetItem as PlayerItem);
            }
            if (ixable != null)
            {
                RoomHandler.unassignedInteractableObjects.Remove(ixable);
                GameManager.Instance.PrimaryPlayer.RemoveBrokenInteractable(ixable);
            }
            float          elapsed      = 0f;
            float          duration     = 0.5f;
            Vector3        startPos     = targetItem.transform.position;
            Vector3        finalOffset  = Vector3.zero;
            tk2dBaseSprite targetSprite = targetItem.GetComponentInChildren <tk2dBaseSprite>();

            if (targetSprite)
            {
                finalOffset = targetSprite.GetBounds().extents;
            }
            while (elapsed < duration)
            {
                elapsed += BraveTime.DeltaTime;
                if (!targetItem || !targetItem.transform)
                {
                    m_currentlySellingAnItem = false; yield break;
                }
                targetItem.transform.localScale = Vector3.Lerp(Vector3.one, new Vector3(0.01f, 0.01f, 1f), elapsed / duration);
                targetItem.transform.position   = Vector3.Lerp(startPos, startPos + new Vector3(finalOffset.x, 0f, 0f), elapsed / duration);
                yield return(null);
            }
            if (!targetItem || !targetItem.transform)
            {
                m_currentlySellingAnItem = false; yield break;
            }
            SellPitDweller.SendPlaymakerEvent("playerSoldSomething");
            int sellPrice = Mathf.Clamp(Mathf.CeilToInt(targetItem.PurchasePrice * SellValueModifier), 0, 200);

            if (targetItem.quality == PickupObject.ItemQuality.SPECIAL || targetItem.quality == PickupObject.ItemQuality.EXCLUDED)
            {
                sellPrice = 3;
            }
            LootEngine.SpawnCurrency(targetItem.sprite.WorldCenter, sellPrice, false);
            m_thingsSold++;
            if (targetItem.PickupObjectId == GlobalItemIds.MasteryToken_Castle || targetItem.PickupObjectId == GlobalItemIds.MasteryToken_Catacombs || targetItem.PickupObjectId == GlobalItemIds.MasteryToken_Gungeon || targetItem.PickupObjectId == GlobalItemIds.MasteryToken_Forge || targetItem.PickupObjectId == GlobalItemIds.MasteryToken_Mines)
            {
                m_masteryRoundsSold++;
            }
            if (targetItem is Gun && targetItem.GetComponentInParent <DebrisObject>())
            {
                Destroy(targetItem.transform.parent.gameObject);
            }
            else
            {
                Destroy(targetItem.gameObject);
            }
            if (m_thingsSold >= 3 && m_masteryRoundsSold > 0)
            {
                StartCoroutine(HandleSellPitOpening());
            }
            m_currentlySellingAnItem = false;
            yield break;
        }