Terraria.Player.dropItemCheck C# (CSharp) Method

dropItemCheck() public method

public dropItemCheck ( ) : void
return void
        public void dropItemCheck()
        {
            if (!Main.playerInventory)
                this.noThrow = 0;
            if (this.noThrow > 0)
                --this.noThrow;
            if (!Main.craftGuide && Main.guideItem.itemId > 0)
            {
                Main.guideItem.position = this.Center;
                Item obj = this.GetItem(this.whoAmI, Main.guideItem, false, true);
                if (obj.stack > 0)
                {
                    int number = Item.NewItem((int)this.position.X, (int)this.position.Y, this.width, this.height, obj.itemId, obj.stack, false, (int)Main.guideItem.prefix, true);
                    Main.item[number].newAndShiny = false;
                    if (Main.netMode == 1)
                        NetMessage.SendData(21, -1, -1, "", number, 1f, 0.0f, 0.0f, 0, 0, 0);
                }
                Main.guideItem = new Item();
            }
            if (!Main.reforge && Main.reforgeItem.itemId > 0)
            {
                Main.reforgeItem.position = this.Center;
                Item obj = this.GetItem(this.whoAmI, Main.reforgeItem, false, true);
                if (obj.stack > 0)
                {
                    int number = Item.NewItem((int)this.position.X, (int)this.position.Y, this.width, this.height, obj.itemId, obj.stack, false, (int)Main.reforgeItem.prefix, true);
                    Main.item[number].newAndShiny = false;
                    if (Main.netMode == 1)
                        NetMessage.SendData(21, -1, -1, "", number, 1f, 0.0f, 0.0f, 0, 0, 0);
                }
                Main.reforgeItem = new Item();
            }
            if (Main.myPlayer == this.whoAmI)
                this.inventory[58] = Main.mouseItem.Clone();
            bool flag1 = true;
            if (Main.mouseItem.itemId > 0 && Main.mouseItem.stack > 0 && !Main.gamePaused)
            {
                Player.tileTargetX = (int)(((double)Main.mouseX + (double)Main.screenPosition.X) / 16.0);
                Player.tileTargetY = (int)(((double)Main.mouseY + (double)Main.screenPosition.Y) / 16.0);
                if ((double)this.gravDir == -1.0)
                    Player.tileTargetY = (int)(((double)Main.screenPosition.Y + (double)Main.screenHeight - (double)Main.mouseY) / 16.0);
                if (this.selectedItem != 58)
                    this.oldSelectItem = this.selectedItem;
                this.selectedItem = 58;
                flag1 = false;
            }
            if (flag1 && this.selectedItem == 58)
                this.selectedItem = this.oldSelectItem;
            if (WorldGen.InWorld(Player.tileTargetX, Player.tileTargetY, 0) && Main.tile[Player.tileTargetX, Player.tileTargetY] != null && ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].type == 334 && this.ItemFitsWeaponRack(this.inventory[this.selectedItem])))
                this.noThrow = 2;
            if (WorldGen.InWorld(Player.tileTargetX, Player.tileTargetY, 0) && Main.tile[Player.tileTargetX, Player.tileTargetY] != null && ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].type == 395 && this.ItemFitsItemFrame(this.inventory[this.selectedItem])))
                this.noThrow = 2;
            if (Main.mouseItem.itemId > 0 && !Main.playerInventory)
            {
                Main.mouseItem.position = this.Center;
                Item obj = this.GetItem(this.whoAmI, Main.mouseItem, false, true);
                if (obj.stack > 0)
                {
                    int number = Item.NewItem((int)this.position.X, (int)this.position.Y, this.width, this.height, obj.itemId, obj.stack, false, 0, true);
                    Main.item[number].newAndShiny = false;
                    if (Main.netMode == 1)
                        NetMessage.SendData(21, -1, -1, "", number, 1f, 0.0f, 0.0f, 0, 0, 0);
                }
                Main.mouseItem = new Item();
                Recipe.FindRecipes();
            }
            if ((!this.controlThrow || !this.releaseThrow || (this.inventory[this.selectedItem].favorited || this.inventory[this.selectedItem].itemId <= 0) || Main.chatMode) && ((!Main.mouseRight || this.mouseInterface || !Main.mouseRightRelease) && Main.playerInventory || (Main.mouseItem.itemId <= 0 || Main.mouseItem.stack <= 0)) || this.noThrow > 0)
                return;
            if (this.inventory[this.selectedItem].favorited)
            {
                this.inventory[this.selectedItem] = this.GetItem(this.whoAmI, this.inventory[this.selectedItem], false, true);
                if (this.selectedItem == 58)
                    Main.mouseItem = this.inventory[this.selectedItem];
                Recipe.FindRecipes();
                if (this.inventory[this.selectedItem].itemId == 0)
                    return;
            }
            Item obj1 = new Item();
            bool flag2 = false;
            if ((Main.mouseRight && !this.mouseInterface && Main.mouseRightRelease || !Main.playerInventory) && (Main.mouseItem.itemId > 0 && Main.mouseItem.stack > 0))
            {
                obj1 = this.inventory[this.selectedItem];
                this.inventory[this.selectedItem] = Main.mouseItem;
                this.delayUseItem = true;
                this.controlUseItem = false;
                flag2 = true;
            }
            int number1 = Item.NewItem((int)this.position.X, (int)this.position.Y, this.width, this.height, this.inventory[this.selectedItem].itemId, 1, false, 0, false);
            if (!flag2 && this.inventory[this.selectedItem].itemId == 8 && this.inventory[this.selectedItem].stack > 1)
            {
                --this.inventory[this.selectedItem].stack;
            }
            else
            {
                this.inventory[this.selectedItem].position = Main.item[number1].position;
                Main.item[number1] = this.inventory[this.selectedItem];
                this.inventory[this.selectedItem] = new Item();
            }
            if (Main.netMode == 0)
                Main.item[number1].noGrabDelay = 100;
            Main.item[number1].velocity.Y = -2f;
            Main.item[number1].velocity.X = (float)(4 * this.direction) + this.velocity.X;
            Main.item[number1].favorited = false;
            Main.item[number1].newAndShiny = false;
            if ((Main.mouseRight && !this.mouseInterface || !Main.playerInventory) && Main.mouseItem.itemId > 0)
            {
                this.inventory[this.selectedItem] = obj1;
                Main.mouseItem = new Item();
            }
            else
            {
                this.itemAnimation = 10;
                this.itemAnimationMax = 10;
            }
            Recipe.FindRecipes();
            if (Main.netMode != 1)
                return;
            NetMessage.SendData(21, -1, -1, "", number1, 0.0f, 0.0f, 0.0f, 0, 0, 0);
        }

Usage Example

Example #1
0
        public void PreUpdatePlayer(Player player)
        {
        	if (ModPlayer.stackSplit > 0)
				ModPlayer.stackSplit--;

            tPlayer = player;
			
			controlInv = false;
			//invSelectItem = false;
			invSelectItemRelease = false;
			//craftScroll = 0;

            if (!Main.gameMenu && (Main.netMode != 2))
            {
				if(invCool>0) invCool--;
				
                if (padState.IsConnected)
                {
                	int ScrollValue = HandleScroll(Microsoft.Xna.Framework.Input.Buttons.LeftTrigger, 
                		Microsoft.Xna.Framework.Input.Buttons.RightTrigger);

					//Open Inventory
					if (padState.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.Y))
					{
						controlInv = true;
					}

					if (padState.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.RightStick))
					{
						rightStick=true;
					}
					else if(rightStick)
					{
						rightStick=false;
						aimMode++;
						if(aimMode>1) aimMode=0; 
					}
					
					if (!Main.playerInventory)
					{
						//Use Tile
						if (padState.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.B))
						{
							useTile=true;
						}
						else if(useTile)
						{
							useTile=false;
							player.controlUseTile=true;
						}

						HandleMovement(player);

						//Aiming
						if(aimMode==0)
						{
							Point stickPoint = new Point(1, 0);
	                   
							Vector2 stick = padState.ThumbSticks.Right;
							if (stick.X != 0 || stick.Y != 0)
							{
								stickPoint = updateStick(stick, (float)Player.tileRangeX);
							}
							else
							{
								stickPoint = new Point(1, 0);
								stick = padState.ThumbSticks.Left;
								if (stick.Y == 0)
								{
									stick.X = ((float)1 * (float)tPlayer.direction);
								}
								stickPoint = updateStick(stick, 2F);
							}

							if (Math.Abs(stickPoint.X) + Math.Abs(stickPoint.Y) > 0)
							{
								if (stickPoint.X != lastStickPoint.X || stickPoint.Y != lastStickPoint.Y)
								{
									Microsoft.Xna.Framework.Input.Mouse.SetPosition(stickPoint.X, stickPoint.Y);
									lastStickPoint.X = (int) stickPoint.X;
									lastStickPoint.Y = (int) stickPoint.Y;
								}
							}
						}
						else if(aimMode==1) {
							Vector2 stick = padState.ThumbSticks.Right;
							Point stickPoint = new Point(0, 0);
							//Add to velocity of mouse
							velocity = padState.ThumbSticks.Right;

							mousePos.X += (velocity.X/2);
							mousePos.Y += (velocity.Y/2);

							if(mousePos.X > (float)Player.tileRangeX) mousePos.X = (float)Player.tileRangeX;
							if(mousePos.X < (float)Player.tileRangeX*-1) mousePos.X = (float)Player.tileRangeX*-1;
							if(mousePos.Y > (float)Player.tileRangeY) mousePos.Y = (float)Player.tileRangeY;
							if(mousePos.Y < (float)Player.tileRangeY*-1) mousePos.Y = (float)Player.tileRangeY*-1;

							//Main.NewText(velocity.X+","+velocity.Y);
							
							int X = (int)((float)(Main.screenWidth / 2) + mousePos.X  * 16f); //* (float)Player.tileRangeX
               				int Y = (int)((float)(Main.screenHeight / 2) - mousePos.Y * 16f); //* 2F
							Microsoft.Xna.Framework.Input.Mouse.SetPosition(X, Y);
						}

						//Throw an Item!
						if (padState.Buttons.X == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
						//padState.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.X)) //
						{
							player.controlThrow = true;
							//player.releaseThrow = true;
						}
						
						//Use an item!
						if (padState.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.RightShoulder))
						{
							player.controlUseItem = true;
						}
						if(ScrollValue!=0) {
							player.selectedItem+=ScrollValue;
							
							if (ScrollValue != 0) {
								Main.PlaySound(12, -1, -1, 1);
								scrollCooldown = scrollCooldownAmt;
							}

							if (player.changeItem >= 0)
							{
								if (player.selectedItem != tPlayer.changeItem)
									Main.PlaySound(12, -1, -1, 1);

								player.selectedItem = player.changeItem;
								player.changeItem = -1;
							}

							while (player.selectedItem > 9)
								player.selectedItem -= 10;

							while (player.selectedItem < 0)
								player.selectedItem += 10;
						}
					}
					else {
						if (padState.Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
						{
							Main.menuMode = 10;
							WorldGen.SaveAndQuit();
						}

			            if (padState.Buttons.Start == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
						{
							enableCraft=true;
						} else if(enableCraft)
						{
							showCraft=!showCraft;
							enableCraft=false;
						}

						if (padState.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.LeftShoulder))
						{
							craftBtn=true;
						} else {
							craftBtn=false;
							//ModPlayer.stackSplit=0;
						}

						if(ScrollValue!=0) {
							invMenu+=ScrollValue;
							scrollCooldown = scrollCooldownAmt;
							if(invMenu==CHEST && Main.player[Main.myPlayer].chest==-1) invMenu+=ScrollValue;

							if(invMenu>invMenuMax) invMenu=0;
							if(invMenu<0) invMenu=invMenuMax;

							UpdateInvMouse();
						}

						int craftScroll=0;
						//Handle craft selection
						if(craftCooldown<=0) {
				
							if(padState.ThumbSticks.Right.Y < 0)
								craftScroll++;
							else if (padState.ThumbSticks.Right.Y > 0)
								craftScroll--;

							craftCooldown=craftCooldownAmt;
						}
						else craftCooldown--;

						Main.focusRecipe+=craftScroll;
						if(Main.focusRecipe<0) Main.focusRecipe=0;
						if(Main.focusRecipe>Main.numAvailableRecipes) Main.focusRecipe=Main.numAvailableRecipes;

						//if(!padState.IsButtonDown(right)
						//	&& !padState.IsButtonDown(left)) scrollCooldown=0;

						
						if (padState.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.A))
						{
							invSelectItem = true;
						}
						else if(invSelectItem) {
							invSelectItem=false;
							invSelectItemRelease = true;
						}

						if (padState.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.RightShoulder))
						{
							invSelectMore = true;
						}
						else {
							invSelectMore=false;
							//ModPlayer.stackSplit=0;
						}

						if(invCool<=0) {							
							Point stickPoint = new Point(0, 0);
								
							Vector2 stick = padState.ThumbSticks.Left;
							if (stick.X != 0 || stick.Y != 0)
							{
								stickPoint.X = (int) stick.X;
								stickPoint.Y = (int) stick.Y;
							}
							if(Math.Abs(stickPoint.X) + Math.Abs(stickPoint.Y) > 0) {
								if(invMenu==INVENTORY) { //Main inventory of items

									//Inventory selection
							  
									int oldSelectionX = invSelectionX;
									int oldSelectionY = invSelectionY;
									if(stickPoint.X > 0) {
										invSelectionX++;
									}
									else if(stickPoint.X < 0) {
										invSelectionX--;
									}
									else if (stickPoint.Y > 0) {
										invSelectionY--;
									}
									else if (stickPoint.Y < 0) {
										invSelectionY++;
									}
									if(invSelectionX>11) invSelectionX = 11;
									if(invSelectionX<0) invSelectionX = 0;
									if(invSelectionY>3) {
										if(Main.player[Main.myPlayer].chest!=-1) {
											invMenu=CHEST;
											chestSelY=0;
											chestSelX=invSelectionX-1;
											if(chestSelX>4) chestSelX=4;

											invCool = invCoolAmt;
											UpdateInvMouse();
										}
										else invSelectionY = 3;
									}
									if(invSelectionY<0) invSelectionY = 0;
									if(oldSelectionX != invSelectionX || oldSelectionY != invSelectionY) {
										invCool = invCoolAmt;
										UpdateInvMouse();
									}
								}
								else if(invMenu==CHEST)
								{
									if(Main.player[Main.myPlayer].chest==-1) {
										invMenu=0;
										UpdateInvMouse();
									} else {
										int oldSelectionX = chestSelX;
										int oldSelectionY = chestSelY;
										if(stickPoint.X > 0) {
											chestSelX++;
										}
										else if(stickPoint.X < 0) {
											chestSelX--;
										}
										else if (stickPoint.Y > 0) {
											chestSelY--;
										}
										else if (stickPoint.Y < 0) {
											chestSelY++;
										}
										if(chestSelX>5) chestSelX = 5;
										if(chestSelX<0) chestSelX = 0;
										if(chestSelY>3) chestSelY = 3;
										if(chestSelY<0) {
											invMenu=ModPlayer.INVENTORY;
											chestSelY = 0;
											invSelectionY = 3;
											invSelectionX = chestSelX+1;
											invCool = invCoolAmt;
										}
										if(oldSelectionX != chestSelX || oldSelectionY != chestSelY) {
											invCool = invCoolAmt;
											UpdateInvMouse();
										}
									}
								}
								/*else if(invMenu==COINS)
								{
									int prev = coinSel;
									if (stickPoint.Y > 0) {
										coinSel--;
									}
									else if (stickPoint.Y < 0) {
										coinSel++;
									}
									if(coinSel!=prev) {
										invCool = invCoolAmt;
									}
								}*/
								else if(invMenu==ARMOR) {			
									//Inventory selection
							  
									int oldSelectionX = armorSel;
									//int oldSelectionY = invSelectionY;
									if(stickPoint.Y > 0) {
										armorSel--;
									}
									else if(stickPoint.Y < 0) {
										armorSel++;
									}
									else if (stickPoint.X > 0 && armorSel>=8) {
										armorSel-=8;
									}
									else if (stickPoint.X < 0 && armorSel<8) {
										armorSel+=8;
									}
									if(armorSel>10) armorSel = 10;
									if(armorSel<0) armorSel = 0;
									//if(invSelectionY>3) invSelectionY = 3;
									//if(invSelectionY<0) invSelectionY = 0;
									if(oldSelectionX != armorSel) { // || oldSelectionY != invSelectionY) {
										invCool = invCoolAmt;
										UpdateInvMouse();
									}
								}
							}
						}
					}
					
					if (controlInv)
					{
						if (releaseInventory) {
							player.toggleInv();
							if(Main.playerInventory) UpdateInvMouse();
						}

						releaseInventory = false;
					}
					else releaseInventory = true;

					if (player.delayUseItem)
					{
						if (!player.controlUseItem)
							player.delayUseItem = false;

						player.controlUseItem = false;
					}

					if (player.itemAnimation == 0 && player.itemTime == 0)
					{
						player.dropItemCheck();
					}
                }
            }

            //UpdateButtons();
        }
Player