forked from Platonymous/Stardew-Valley-Mods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwimSuitMod.cs
111 lines (87 loc) · 3.57 KB
/
SwimSuitMod.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
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using System;
using System.Collections.Generic;
using System.Linq;
using xTile.Dimensions;
namespace SwimSuit
{
public class SwimSuitMod : Mod
{
private SConfig config;
public override void Entry(IModHelper helper)
{
helper.Events.Input.ButtonPressed += OnButtonPressed;
config = Helper.ReadConfig<SConfig>();
}
private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
{
if(e.Button == config.swimKey)
{
List<Vector2> tiles = getSurroundingTiles();
Vector2 jumpLocation = Vector2.Zero;
bool nextToWater = false;
try
{
nextToWater = Game1.currentLocation.waterTiles[(int)tiles.Last().X, (int)tiles.Last().Y];
}
catch
{
}
bool nextToBarrier = Game1.currentLocation.isTilePassable(new Location((int)tiles.Last().X, (int)tiles.Last().Y), Game1.viewport); ;
foreach (Vector2 tile in tiles)
{
bool isWater = false;
bool isPassable = false;
try
{
isPassable = Game1.currentLocation.isTilePassable(new Location((int)tile.X, (int)tile.Y), Game1.viewport);
isWater = Game1.currentLocation.waterTiles[(int)tile.X, (int)tile.Y];
}
catch
{
}
if (Game1.player.swimming.Value && !isWater && isPassable && !nextToBarrier)
jumpLocation = tile;
if (!Game1.player.swimming.Value && isWater && isPassable && nextToWater)
jumpLocation = tile;
}
if(jumpLocation != Vector2.Zero)
{
if (Game1.player.swimming.Value)
{
Game1.player.changeOutOfSwimSuit();
Game1.player.swimming.Value = false;
Game1.player.Position = new Vector2(jumpLocation.X * Game1.tileSize, jumpLocation.Y * Game1.tileSize);
}
else
{
Game1.player.changeIntoSwimsuit();
Game1.player.swimming.Value = true;
Game1.player.Position = new Vector2(jumpLocation.X * Game1.tileSize, jumpLocation.Y * Game1.tileSize);
}
}
}
}
private List<Vector2> getSurroundingTiles()
{
List<Vector2> tiles = new List<Vector2>();
int dir = Game1.player.facingDirection;
if (dir == 1)
for (int i = 8; i > 0; i--)
tiles.Add(Game1.player.getTileLocation() + new Vector2(i, 0));
if (dir == 2)
for (int i = 8; i > 0; i--)
tiles.Add(Game1.player.getTileLocation() + new Vector2(0, i));
if (dir == 3)
for (int i = 8; i > 0; i--)
tiles.Add(Game1.player.getTileLocation() - new Vector2(i, 0));
if (dir == 0)
for (int i = 8; i > 0; i--)
tiles.Add(Game1.player.getTileLocation() - new Vector2(0, i));
return tiles;
}
}
}