public override void UseGrapple(Player player, ref int type)
        {
            var config   = LockedAbilitiesConfig.Instance;
            int chainAmt = config.Get <int>(nameof(LockedAbilitiesConfig.GrappleRequiresChainAmount));

            if (chainAmt > 0)
            {
                int idx = ItemFinderLibraries.FindIndexOfFirstOfItemInCollection(
                    player.inventory,
                    new HashSet <int> {
                    ItemID.Chain
                }
                    );

                if (idx == -1)
                {
                    Main.NewText("No chains available for grappling.", Color.Yellow);
                    return;
                }

                PlayerItemLibraries.RemoveInventoryItemQuantity(
                    player,
                    ItemID.Chain,
                    chainAmt
                    );
            }
        }
		////////////////

		private void UpdateDoubleJumps( bool isOnGround ) {
			if( !LockedAbilitiesConfig.Instance.Get<bool>( nameof(LockedAbilitiesConfig.DoubleJumpsRequireGels) ) ) {
				return;
			}

			if( !isOnGround ) {
				if( this.player.jump == 0 ) {
					if( !this.player.inventory.Any( i => i != null && !i.IsAir && i.type == ItemID.Gel ) ) {
						bool hadDoubleJump = this.player.jumpAgainBlizzard
							|| this.player.jumpAgainCloud
							|| this.player.jumpAgainFart
							|| this.player.jumpAgainSail
							|| this.player.jumpAgainSandstorm;

						if( hadDoubleJump ) {
							Main.NewText( "Need gels to double jump.", Color.Yellow );
						}

						this.player.jumpAgainBlizzard = false;
						this.player.jumpAgainCloud = false;
						this.player.jumpAgainFart = false;
						this.player.jumpAgainSail = false;
						this.player.jumpAgainSandstorm = false;
					}
				}

				if( this.player.doubleJumpBlizzard && !this.player.jumpAgainBlizzard && !this.HasBlizzardJumped ) {
					this.HasBlizzardJumped = true;
					PlayerItemLibraries.RemoveInventoryItemQuantity( this.player, ItemID.Gel, 1 );
				} else
				if( this.player.doubleJumpCloud && !this.player.jumpAgainCloud && !this.HasCloudJumped ) {
					this.HasCloudJumped = true;
					PlayerItemLibraries.RemoveInventoryItemQuantity( this.player, ItemID.Gel, 1 );
				} else
				if( this.player.doubleJumpFart && !this.player.jumpAgainFart && !this.HasFartJumped ) {
					this.HasFartJumped = true;
					PlayerItemLibraries.RemoveInventoryItemQuantity( this.player, ItemID.Gel, 1 );
				} else
				if( this.player.doubleJumpSail && !this.player.jumpAgainSail && !this.HasSailJumped ) {
					this.HasSailJumped = true;
					PlayerItemLibraries.RemoveInventoryItemQuantity( this.player, ItemID.Gel, 1 );
				}
				if( this.player.doubleJumpSandstorm && !this.player.jumpAgainSandstorm && !this.HasSandstormJumped ) {
					this.HasSandstormJumped = true;
					PlayerItemLibraries.RemoveInventoryItemQuantity( this.player, ItemID.Gel, 1 );
				}
			} else {
				this.HasBlizzardJumped = false;
				this.HasCloudJumped = false;
				this.HasFartJumped = false;
				this.HasSailJumped = false;
				this.HasSandstormJumped = false;
			}
		}
		private void ConsumePixieDust() {
			PlayerItemLibraries.RemoveInventoryItemQuantity( this.player, ItemID.PixieDust, 1 );

			for( int i=0; i<4; i++ ) {
				int dustIdx = Dust.NewDust(
					Position: this.player.position,
					Height: this.player.width,
					Width: this.player.height,
					Type: 55,
					SpeedX: 0f,
					SpeedY: 0f,
					Alpha: 200,
					newColor: Color.White,
					Scale: 1f
				);
				Main.dust[dustIdx].velocity *= 0.3f;
			}
		}
        ////////////////

        public bool PickupIntoJarIf(Player player, out bool isError)
        {
            if (player.HeldItem?.IsAir != false)
            {
                isError = false;
                return(false);
            }

            int emptyJarType = ModContent.ItemType <EmptyCanopicJarItem>();

            if (player.HeldItem?.type != emptyJarType)
            {
                isError = false;
                return(false);
            }

            if (PlayerItemLibraries.RemoveInventoryItemQuantity(player, emptyJarType, 1) == 0)
            {
                Main.NewText("Could not fill jar.", Color.Yellow);
                isError = true;
                return(false);
            }

            int itemWho = Item.NewItem(
                position: player.position,
                Type: ModContent.ItemType <FilledCanopicJarItem>(),
                Stack: 1,
                noBroadcast: false,
                prefixGiven: 0,
                noGrabDelay: true
                );

            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                NetMessage.SendData(MessageID.SyncItem, -1, -1, null, itemWho, 1f, 0f, 0f, 0, 0, 0);
            }

            Main.PlaySound(SoundID.Drip, this.item.Center, 2);

            isError = false;
            return(true);
        }
예제 #5
0
        private void CheckTrackKitResume(int heldTrackKitItemType)
        {
            if (!this.player.mount.Active || !this.player.mount.Cart)
            {
                return;
            }

            var trackKitSingleton = ModContent.GetInstance <TrackDeploymentKitItem>();

            (int x, int y, int dir)resume = trackKitSingleton.ResumeDeploymentAt;
            var resumeWldPos = new Vector2((resume.x << 4) + 8, (resume.y << 4) + 8);

            if (Vector2.DistanceSquared(this.player.Center, resumeWldPos) >= 4096)                // 4 tiles
            {
                return;
            }

            PlayerItemLibraries.RemoveInventoryItemQuantity(this.player, heldTrackKitItemType, 1);

            int leftovers = TrackDeploymentKitItem.Redeploy(this.player.whoAmI);

            if (leftovers == 0)
            {
                return;
            }

            int itemWho = Item.NewItem(resumeWldPos, ItemID.MinecartTrack, leftovers);

            if (Main.netMode != NetmodeID.MultiplayerClient)
            {
                NetMessage.SendData(MessageID.SyncItem, -1, -1, null, itemWho, 1f);
            }
            else
            {
                TrackKitDeployProtocol.SendToServer(resume.dir > 0, resume.x, resume.y, true);
            }
        }
		private void UpdateRocketBoots( bool isOnGround ) {
			if( !LockedAbilitiesConfig.Instance.Get<bool>( nameof(LockedAbilitiesConfig.RocketBootsRequireGels) ) ) {
				return;
			}

			if( this.player.rocketBoots == 0 ) {
				return;
			}

			if( !isOnGround ) {
				if( this.player.rocketTime > 1 ) {
					if( !this.player.inventory.Any( i => i != null && !i.IsAir && i.type == ItemID.Gel ) ) {
						this.player.rocketTime = 1;
					} else if( this.player.rocketTime > 0 && this.player.rocketTime < this.player.rocketTimeMax ) {
						if( !this.HasRocketChecked ) {
							this.HasRocketChecked = true;
							PlayerItemLibraries.RemoveInventoryItemQuantity( this.player, ItemID.Gel, 1 );
						}
					}
				}
			} else {
				this.HasRocketChecked = false;
			}
		}
        public static bool ApplyRepairIf(Player player, Item item)
        {
            if (item?.active != true || item.stack == 0)
            {
                return(false);
            }

            int  scrapItemType = ModContent.ItemType <MagitechScrapItem>();
            Item scrapItem     = PlayerItemFinderLibraries.FindFirstOfPossessedItemFor(
                player,
                new HashSet <int> {
                scrapItemType
            },
                false
                );

            var myScrapItem = scrapItem?.modItem as MagitechScrapItem;

            if (myScrapItem == null)
            {
                Main.NewText("No repair scrap items in player's possession.", Color.Yellow);
                return(false);
            }

            int ruinedPrefixType = ModContent.PrefixType <RuinedPrefix>();

            if (item.prefix != ruinedPrefixType)
            {
                return(false);
            }

            var  config   = RuinedItemsConfig.Instance;
            var  myitem   = item.GetGlobalItem <RuinedItemsItem>();
            bool onlyOnce = config.Get <bool>(nameof(config.MagitechScrapAttemptsRepairOnlyOncePerItem));

            if (onlyOnce && myitem.IsScrapUsedUpon)
            {
                Main.NewText("Cannot repair this with scrap more than once. Use reforging instead.", Color.Yellow);
                return(false);
            }

            if (PlayerItemLibraries.RemoveInventoryItemQuantity(Main.LocalPlayer, scrapItemType, 1) <= 0)
            {
                Main.NewText("Could not use player's scrap items for repairing.", Color.Yellow);
                return(false);
            }

            if (Main.rand.NextFloat() < config.Get <float>(nameof(config.MagitechScrapRepairChance)))
            {
                float rollChance = config.Get <float>(nameof(config.GeneralRuinRollChance));

                config.SetOverride(nameof(config.GeneralRuinRollChance), 0f);
                item.Prefix(-1);
                config.SetOverride(nameof(config.GeneralRuinRollChance), rollChance);

                CombatText.NewText(Main.LocalPlayer.getRect(), Color.Lime, "Repair success!", true);
                Main.NewText("Repair success!", Color.Lime);
            }
            else
            {
                CombatText.NewText(Main.LocalPlayer.getRect(), Color.DimGray, "Repair failed!", true);
                Main.NewText("Repair failed! Item can now only be repaired via. reforging.", Color.OrangeRed);
            }

            myitem.IsScrapUsedUpon = true;

            Main.PlaySound(SoundID.Item37, Main.LocalPlayer.Center);
            Main.PlaySound(SoundID.Grab, Main.LocalPlayer.Center);

            return(true);
        }