-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathASPlayer.cs
122 lines (105 loc) · 4.31 KB
/
ASPlayer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.GameInput;
using Terraria.ModLoader;
using AmmoSwitcher.UI;
namespace AmmoSwitcher
{
class ASPlayer : ModPlayer
{
public int useAmmoSlot = 54; //ammo slots are 54 - 57 inventory slots (top to bottom)
// switching slot and displaying message
public override void ProcessTriggers(TriggersSet triggersSet)
{
if (AmmoSwitcher.useAmmo1.JustPressed)
{
useAmmoSlot = 54;
if (ASUI.visible) Main.PlaySound(SoundID.MenuTick);
}
if (AmmoSwitcher.useAmmo2.JustPressed)
{
useAmmoSlot = 55;
if (ASUI.visible) Main.PlaySound(SoundID.MenuTick);
}
if (AmmoSwitcher.useAmmo3.JustPressed)
{
useAmmoSlot = 56;
if (ASUI.visible) Main.PlaySound(SoundID.MenuTick);
}
if (AmmoSwitcher.useAmmo4.JustPressed)
{
useAmmoSlot = 57;
if (ASUI.visible) Main.PlaySound(SoundID.MenuTick);
}
ASUI.activeSlot = useAmmoSlot;
if (player.HeldItem.useAmmo > 0 && !Main.playerInventory) ASUI.visible = true;
else ASUI.visible = false;
}
// consuming right item, priority to topleft corner of inventory
public override bool ConsumeAmmo(Item weapon, Item ammo)
{
// target ammo to consume
Item usedAmmo = player.inventory[useAmmoSlot];
// if selected ammo can't be used with current weapon
if (usedAmmo.ammo != weapon.useAmmo)
for (int i = 54; ; i++) // even if consuming priority is topleft, search of projectile started at ammo slots, like in vanilla
{
if (i == player.inventory.Length) i = 0;
if (player.inventory[i].ammo == weapon.useAmmo)
{
usedAmmo = player.inventory[i];
break;
}
if (i == 53) break;
}
// endles munition
if (usedAmmo.type == ItemID.EndlessMusketPouch) return false;
if (usedAmmo.type == ItemID.EndlessQuiver) return false;
// checking buffs
if (player.ammoCost80)
{
if (Main.rand.Next(100) < 20) return false;
}
else if (player.ammoCost75)
{
if (Main.rand.Next(100) < 25) return false;
}
else if (player.ammoBox)
{
if (Main.rand.Next(100) < 20) return false;
}
else if (player.ammoPotion)
{
if (Main.rand.Next(100) < 20) return false;
}
else if (player.magicQuiver && usedAmmo.ammo == AmmoID.Arrow)
{
if (Main.rand.Next(100) < 20) return false;
}
// checking weapon // dunno, maybe there is better way
if (weapon.type == ItemID.BoneGlove)
if (Main.rand.Next(100) < 33) return false;
if (weapon.type == ItemID.Minishark)
if (Main.rand.Next(100) < 33) return false;
if (weapon.type == ItemID.Megashark)
if (Main.rand.Next(100) < 50) return false;
if (weapon.type == ItemID.Gatligator)
if (Main.rand.Next(100) < 50) return false;
if (weapon.type == ItemID.ChainGun)
if (Main.rand.Next(100) < 50) return false;
if (weapon.type == ItemID.SDMG)
if (Main.rand.Next(100) < 50) return false;
if (weapon.type == ItemID.CandyCornRifle)
if (Main.rand.Next(100) < 33) return false;
// flamethrowers work a bit different, but this is an easier way and gives almost same result
if (weapon.type == ItemID.Flamethrower)
if (Main.rand.Next(100) < 80) return false;
if (weapon.type == ItemID.EldMelter)
if (Main.rand.Next(100) < 80) return false;
// consume... finally
player.ConsumeItem(usedAmmo.type);
return false;
}
}
}