forked from hajsdfgj/modular-overhaul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMusk.cs
139 lines (122 loc) · 5.11 KB
/
Musk.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
namespace DaLion.Overhaul.Modules.Professions;
#region using directives
using DaLion.Overhaul.Modules.Professions.VirtualProperties;
using Microsoft.Xna.Framework;
using StardewValley.Monsters;
#endregion using directivesv
internal sealed class Musk
{
/// <summary>Initializes a new instance of the <see cref="Musk"/> class, attached to a fixed <paramref name="position"/> on the specified <paramref name="location"/>.</summary>
/// <param name="location">The <see cref="GameLocation"/>.</param>
/// <param name="position">The <see cref="Vector2"/> absolute position.</param>
/// <param name="duration">The duration, in seconds.</param>
internal Musk(GameLocation location, Vector2 position, int duration)
{
this.Location = location;
this.FakeFarmer = new FakeFarmer
{
UniqueMultiplayerID = Guid.NewGuid().GetHashCode(),
currentLocation = location,
Position = position,
};
this.Duration = duration;
for (var i = 0; i < 3; i++)
{
Reflector.GetStaticFieldGetter<Multiplayer>(typeof(Game1), "multiplayer").Invoke()
.broadcastSprites(
location,
new TemporaryAnimatedSprite(5, position + new Vector2(16f, -64f + (32f * i)), Color.Purple)
{
motion = new Vector2(Utility.RandomFloat(-1f, 1f), -0.5f),
scaleChange = 0.005f,
scale = 0.5f,
alpha = 1f,
alphaFade = 0.0075f,
shakeIntensity = 1f,
delayBeforeAnimationStart = 100 * i,
layerDepth = 0.9999f,
positionFollowsAttachedCharacter = false,
attachedCharacter = this.FakeFarmer,
});
}
location.playSound("steam");
}
/// <summary>Initializes a new instance of the <see cref="Musk"/> class.</summary>
/// <param name="attachedMonster">The <see cref="Monster"/> this instance is attached to.</param>
/// <param name="duration">The duration, in seconds.</param>
internal Musk(Monster attachedMonster, int duration)
{
this.AttachedMonster = attachedMonster;
this.Location = attachedMonster.currentLocation;
this.FakeFarmer = new FakeFarmer
{
UniqueMultiplayerID = Guid.NewGuid().GetHashCode(),
currentLocation = attachedMonster.currentLocation,
Position = attachedMonster.position.Value,
};
this.Duration = duration;
for (var i = 0; i < 3; i++)
{
Reflector.GetStaticFieldGetter<Multiplayer>(typeof(Game1), "multiplayer").Invoke()
.broadcastSprites(
attachedMonster.currentLocation,
new TemporaryAnimatedSprite(
5,
attachedMonster.Position + new Vector2(16f, -64f + (32f * i)),
Color.Purple)
{
motion = new Vector2(Utility.RandomFloat(-1f, 1f), -0.5f),
scaleChange = 0.005f,
scale = 0.5f,
alpha = 1f,
alphaFade = 0.0075f,
shakeIntensity = 1f,
delayBeforeAnimationStart = 100 * i,
layerDepth = 0.9999f,
positionFollowsAttachedCharacter = false,
attachedCharacter = this.FakeFarmer,
});
}
attachedMonster.currentLocation.playSound("steam");
}
internal GameLocation Location { get; }
internal FakeFarmer FakeFarmer { get; }
internal Monster? AttachedMonster { get; }
internal int Duration { get; private set; }
internal void Update()
{
if (this.AttachedMonster is not null)
{
this.FakeFarmer.Position = this.AttachedMonster.Position;
}
this.Duration--;
if (this.Duration <= 0)
{
this.Location.RemoveMusk(this);
if (this.AttachedMonster is not null)
{
Monster_Musked.Values.Remove(this.AttachedMonster);
}
return;
}
Reflector.GetStaticFieldGetter<Multiplayer>(typeof(Game1), "multiplayer").Invoke()
.broadcastSprites(
this.Location,
new TemporaryAnimatedSprite(
5,
this.FakeFarmer.Position + new Vector2(16f, -32f),
Color.Purple)
{
motion = new Vector2(Utility.RandomFloat(-1f, 1f), -0.5f),
scaleChange = 0.005f,
scale = 0.5f,
alpha = 1f,
alphaFade = 0.0075f,
shakeIntensity = 1f,
delayBeforeAnimationStart = 100,
layerDepth = 0.9999f,
positionFollowsAttachedCharacter = false,
attachedCharacter = this.FakeFarmer,
});
}
}