示例#1
0
        private void AttemptGift()
        {
            Player localPlayer = Main.LocalPlayer;

            if (localPlayer.talkNPC == npc.whoAmI && localPlayer.HeldItem.type > ItemID.None && LWMWorld.villageGiftCooldown[(int)villagerType] == 0)
            {
                Item helditem = localPlayer.HeldItem;
                if (helditem.favorited)
                {
                    return;
                }
                if (likedGifts.Contains(helditem.type))
                {
                    LWMWorld.ModifyReputation(villagerType, 5, npc.getRect(), true);
                }
                else if (dislikedGifts.Contains(helditem.type))
                {
                    LWMWorld.ModifyReputation(villagerType, -5, npc.getRect(), true);
                }
                else
                {
                    LWMWorld.ModifyReputation(villagerType, 0, npc.getRect(), true);
                }
            }
        }
        /// <summary>
        /// Removes reputation from the Harpy Reputation value if a normal Harpy or Wyvern is killed
        /// </summary>
        public override bool SpecialNPCLoot(NPC npc)
        {
            switch (npc.type)
            {
            case NPCID.Harpy:
                LWMWorld.ModifyReputation(VillagerType.Harpy, -1, new Rectangle((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height));
                break;

            case NPCID.WyvernHead:
                LWMWorld.ModifyReputation(VillagerType.Harpy, -5, new Rectangle((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height));
                break;
            }
            return(base.SpecialNPCLoot(npc));
        }
示例#3
0
        private void UpdateReputationBools()
        {
            float reputation = LWMWorld.GetReputation(villagerType);

            if (reputation <= 0f)
            {
                isHatedRep    = true;
                isNegativeRep = false;
                isNeutralRep  = false;
                isPositiveRep = false;
                isMaxRep      = false;
            }
            else if (reputation <= 50f && reputation > 0f)
            {
                isHatedRep    = false;
                isNegativeRep = true;
                isNeutralRep  = false;
                isPositiveRep = false;
                isMaxRep      = false;
            }
            else if (reputation >= 100f && reputation <= 150f)
            {
                isHatedRep    = false;
                isNegativeRep = false;
                isNeutralRep  = true;
                isPositiveRep = false;
                isMaxRep      = false;
            }
            else if (reputation > 150f && reputation < 200f)
            {
                isHatedRep    = false;
                isNegativeRep = false;
                isNeutralRep  = false;
                isPositiveRep = true;
                isMaxRep      = false;
            }
            else if (reputation >= 200f)
            {
                isHatedRep    = false;
                isNegativeRep = false;
                isNeutralRep  = false;
                isPositiveRep = false;
                isMaxRep      = true;
            }
        }
示例#4
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            VillagerType shrineType = ShrineUIPanel.shrineType;
            //int reputation = LWMWorld.GetReputation(shrineType);
            float quotient;

            if (giftMode)
            {
                int giftProgress = LWMWorld.GetGiftProgress(shrineType);

                text.SetText($"{giftProgress} / {maxProgress}");
                quotient = giftProgress / (float)maxProgress;
            }
            else //stageMode
            {
                int shrineStage = LWMWorld.GetShrineStage(shrineType);

                text.SetText($"{shrineStage} / {maxProgress}");
                quotient = shrineStage / (float)maxProgress;
            }

            quotient = Terraria.Utils.Clamp(quotient, 0f, 1f);
            Rectangle hitbox = barFrame.GetInnerDimensions().ToRectangle();

            //Magic numbers to keep everything aligned
            hitbox.X     += 2;
            hitbox.Width -= 4;

            int left  = hitbox.Left;
            int right = hitbox.Right;
            int steps = (int)((right - left) * quotient);

            for (int i = 0; i < steps; i += 1)
            {
                //float percent = (float)i / steps; // Alternate Gradient Approach
                float percent = (float)i / (right - left);
                Color color   = Color.Lerp(colorA, colorB, percent);
                spriteBatch.Draw(Main.magicPixel, new Rectangle(left + i, hitbox.Y, 1, hitbox.Height), color);
            }
        }
示例#5
0
        public override void AnimateTile(ref int frame, ref int frameCounter)
        {
            int giftProgress = LWMWorld.GetGiftProgress(shrineType);

            frame = frameCounter = (int)(giftProgress / 6.66f);
        }
示例#6
0
        public ShrineUIPanel(float scale = 1f, float opacity = 1f) : base(scale, opacity)
        {
            Instance = this;

            Width.Set(width, 0);
            Height.Set(height, 0);
            Left.Set(Main.screenWidth / 2 - width, 0);
            Top.Set(Main.screenHeight / 2 - height, 0);
            SetPadding(0);
            BorderColor     = Microsoft.Xna.Framework.Color.Transparent;
            BackgroundColor = Microsoft.Xna.Framework.Color.Transparent;

            #region UI Initialization

            //Background
            CustomUIImage background =
                new CustomUIImage(GetTexture("LivingWorldMod/Textures/UIElements/ShrineMenu/Background"), 1f);
            background.Width.Set(0, 0);
            background.Height.Set(0f, 0);
            background.Left.Set(-12f, 0);
            background.Top.Set(-12f, 0);
            Append(background);

            //Cross to Close Menu
            CustomUIImage closeMenuCross =
                new CustomUIImage(GetTexture("LivingWorldMod/Textures/UIElements/ShrineMenu/CloseCross"), 1f);
            closeMenuCross.Width.Set(19f, 0);
            closeMenuCross.Height.Set(19f, 0);
            closeMenuCross.Left.Set(width - 35f, 0);
            closeMenuCross.Top.Set(-7f, 0);
            closeMenuCross.OnClick += (__, _) => Hide();
            Append(closeMenuCross);

            #region Item in itemSlot info

            //Gift Item Image
            CustomUIImage giftItem = new CustomUIImage(Main.itemTexture[0], 1f);
            giftItem.SetScaleToFit(true);
            giftItem.Left.Set(165f, 0);
            giftItem.Top.Set(35f, 0);
            Append(giftItem);
            giftItem.Hide();

            //Undiscovered Gift
            CustomUIText undiscoveredGift = new CustomUIText("?", 1f);
            undiscoveredGift.TextColor = Microsoft.Xna.Framework.Color.LightGray;
            undiscoveredGift.Left.Set(195f, 0);
            undiscoveredGift.Top.Set(40f, 0);
            Append(undiscoveredGift);
            undiscoveredGift.Hide();


            //Amount gifted
            CustomUIText giftAmount = new CustomUIText("", 0.9f);
            giftAmount.Left.Set(110f, 0);
            giftAmount.Top.Set(30f, 0);
            Append(giftAmount);
            giftAmount.Hide();


            //Liking Neutral
            CustomUIText giftLiking = new CustomUIText("", 0.9f);
            giftLiking.Left.Set(110f, 0);
            giftLiking.Top.Set(50f, 0);
            Append(giftLiking);
            giftLiking.Hide();

            #endregion

            //ItemSlot
            itemSlot = new CustomItemSlot();
            itemSlot.Width.Set(54f, 0);
            itemSlot.Height.Set(54f, 0);
            itemSlot.Left.Set(5f, 0);
            itemSlot.Top.Set(25f, 0);
            itemSlot.OnItemEquipped += _ => ShowItemSlotInfo();
            itemSlot.OnItemRemoved  += _ => HideItemSlotInfo();
            itemSlot.SetBackgroundTexture(GetTexture("LivingWorldMod/Textures/UIElements/ShrineMenu/ItemSlot"));
            Append(itemSlot);

            //Gift
            Texture2D     giftTexture  = GetTexture("LivingWorldMod/Textures/UIElements/ShrineMenu/Gift");
            Texture2D     giftTexture2 = GetTexture("LivingWorldMod/Textures/UIElements/ShrineMenu/Gift2");
            UIImageButton gift         = new UIImageButton(giftTexture);
            gift.Width.Set(26f, 0);
            gift.Height.Set(26f, 0);
            gift.Left.Set(66f, 0);
            gift.Top.Set(38f, 0);
            gift.SetVisibility(1f, 1f);
            gift.OnMouseOver += (__, _) => { gift.SetImage(giftTexture2); };
            gift.OnMouseOut  += (__, _) => { gift.SetImage(giftTexture); };
            gift.OnMouseDown += (__, _) =>
            {
                gift.Top.Set(gift.Top.Pixels + 1f, 0);
                GiftItem();
                HideItemSlotInfo();
            };
            gift.OnMouseUp += (__, _) => { gift.Top.Set(gift.Top.Pixels - 1f, 0); };
            Append(gift);

            //Gifts Text
            CustomUIText repText = new CustomUIText("Gifts: ", 0.8f);
            repText.Left.Set(8f, 0);
            repText.Top.Set(95f, 0);
            Append(repText);

            //Gifts ProgressBar
            Color             Color    = new Color(63, 113, 169);
            ShrineProgressBar repFrame = new ShrineProgressBar(true, 100, Color);
            repFrame.Width.Set(170f, 0);
            repFrame.Height.Set(16f, 0);
            repFrame.Left.Set(48f, 0);
            repFrame.Top.Set(95f, 0);
            repFrame.Activate();
            Append(repFrame);

            //Stage Text
            CustomUIText stageText = new CustomUIText("Stage: ", 0.8f);
            stageText.Left.Set(5f, 0);
            stageText.Top.Set(120f, 0);
            Append(stageText);

            //Stage ProgressBar
            ShrineProgressBar stageFrame = new ShrineProgressBar(false, 5, Color);
            stageFrame.Width.Set(170f, 0);
            stageFrame.Height.Set(16f, 0);
            stageFrame.Left.Set(48f, 0);
            stageFrame.Top.Set(120f, 0);
            stageFrame.Activate();
            Append(stageFrame);

            #region Methods

            void GiftItem()
            {
                int itemType = itemSlot.Item.type;

                LWMWorld.AddGiftToProgress(shrineType, itemType);
                itemSlot.Item.TurnToAir();
            }

            void ShowItemSlotInfo()
            {
                giftItem.SetImage(Main.itemTexture[itemSlot.Item.type]);
                giftItem.SetSize(24f, 24f);

                Color color;

                if (LWMWorld.GetGiftAmount(shrineType, itemSlot.Item.type) == 0)
                {
                    color = new Color(66, 66, 66);
                    giftItem.Show();
                    undiscoveredGift.Show();
                }
                else
                {
                    color = Microsoft.Xna.Framework.Color.White;
                }

                giftItem.SetOverlayColor(color);

                //Update Amount Gifted
                int    amount     = LWMWorld.GetGiftAmount(shrineType, itemSlot.Item.type);
                string amountText = "Gifted: " + (amount == 0 ? "" : amount.ToString());

                giftAmount.SetText(amountText);

                //Update Gift Liking
                int liking = LivingWorldMod.GetGiftValue(shrineType, itemSlot.Item.type);

                string likingText = "Liking: ";

                if (amount != 0 && Math.Abs(liking) == 3)
                {
                    likingText += liking > 0 ? "Good" : "Bad";
                }
                else if (amount != 0 && Math.Abs(liking) == 5)
                {
                    likingText += liking > 0 ? "Great" : "Awful";
                }
                else if (amount != 0 && liking == 0)
                {
                    likingText += "Neutral";
                }
                giftLiking.SetText(likingText);

                giftAmount.Show();
                giftLiking.Show();
            }

            void HideItemSlotInfo()
            {
                giftItem.Hide();
                giftAmount.Hide();
                giftLiking.Hide();
                undiscoveredGift.Hide();
            }

            #endregion

            #endregion
        }