Advertisement
yoraimer

Find , Lose Ammo , Shoot Item

Mar 22nd, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. public void UseItem(Player player, int playerID)
  2. {
  3. if (playerID == Main.myPlayer)
  4. {
  5. #region if it needs ammo
  6. Item MyCheckedItem = new Item();
  7. bool FoundUsableAmmo = false;
  8. bool FoundAmmoInAmmoSlot = false;
  9. for (int PassingIndex = 44; PassingIndex < 48; PassingIndex++)
  10. {
  11. if (player.inventory[PassingIndex].ammo == item.useAmmo && player.inventory[PassingIndex].stack > 0)
  12. {
  13. MyCheckedItem = player.inventory[PassingIndex];
  14. FoundUsableAmmo = true;
  15. FoundAmmoInAmmoSlot = true;
  16. break;
  17. }
  18. }
  19. if (!FoundAmmoInAmmoSlot)
  20. {
  21. for (int PasserIndex = 0; PasserIndex < 44; PasserIndex++)
  22. {
  23. if (player.inventory[PasserIndex].ammo == item.useAmmo && player.inventory[PasserIndex].stack > 0)
  24. {
  25. MyCheckedItem = player.inventory[PasserIndex];
  26. FoundUsableAmmo = true;
  27. break;
  28. }
  29. }
  30. }
  31. if (FoundUsableAmmo)
  32. {
  33. bool DoNotConsumeAmmo = false;
  34. if (player.ammoCost80 && Main.rand.Next(5) == 0)
  35. {
  36. DoNotConsumeAmmo = true;
  37. }
  38. if (player.ammoCost75 && Main.rand.Next(4) == 0)
  39. {
  40. DoNotConsumeAmmo = true;
  41. }
  42. if (!DoNotConsumeAmmo)
  43. {
  44. MyCheckedItem.stack--;
  45. if (MyCheckedItem.stack <= 0)
  46. {
  47. MyCheckedItem.active = false;
  48. MyCheckedItem.name = "";
  49. MyCheckedItem.type = 0;
  50. }
  51. }
  52. #endregion
  53. }
  54. if(FoundUsableAmmo)
  55. {
  56. #region regular
  57. int MyProjectileIndex = -1;
  58. int MyProjectileSpeed = 10;
  59. int MyProjectileRandomOffseter = 5;
  60. float x = (float) (player.itemLocation.X + (float)Main.itemTexture[item.type].Width * 0.5f)-7-MyProjectileRandomOffseter+Main.rand.Next(MyProjectileRandomOffseter);
  61. player.direction = -1;
  62. if ((player.itemLocation.X + (float)Main.itemTexture[item.type].Width * 0.5f) < (Main.mouseX + Main.screenPosition.X))
  63. {
  64. player.direction = 1;
  65. x = (float) (player.itemLocation.X + (float)Main.itemTexture[item.type].Width * 0.5f)-7+MyProjectileRandomOffseter+Main.rand.Next(MyProjectileRandomOffseter);
  66. }
  67.  
  68. float y = (float) (player.itemLocation.Y + (float)Main.itemTexture[item.type].Height * 0.5f)-Main.rand.Next(-MyProjectileRandomOffseter,MyProjectileRandomOffseter);
  69.  
  70. float rot = (float) Math.Atan2((Main.mouseY + Main.screenPosition.Y)-(y + 5),(Main.mouseX + Main.screenPosition.X) - (x + 5));
  71.  
  72. float VX = (float)((Math.Cos(rot) * MyProjectileSpeed));
  73. float VY = (float)((Math.Sin(rot) * MyProjectileSpeed));
  74.  
  75. VX = ((Main.mouseX + Main.screenPosition.X) - (player.position.X + player.width * 0.5f));
  76. VY = ((Main.mouseY + Main.screenPosition.Y) - (player.position.Y + player.height * 0.5f));
  77. float distance = (float) Math.Sqrt((double) ((VX * VX) + (VY * VY)));
  78. distance = MyProjectileSpeed / distance;
  79. VX *= distance;
  80. VY *= distance;
  81.  
  82. MyProjectileIndex = Projectile.NewProjectile(
  83. x,
  84. y,
  85. VX,
  86. VY,
  87. "Blade Shot", //Type
  88. (int) (item.damage*player.magicDamage), //Damage
  89. 2.0f,
  90. playerID
  91. );
  92. NetMessage.SendData(27, -1, -1, "", MyProjectileIndex, 0f, 0f, 0f, 0);
  93. }
  94. #endregion
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement