-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathTeleportationResolver.cs
63 lines (56 loc) · 2.4 KB
/
TeleportationResolver.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
using System;
using System.Collections.Generic;
using System.Linq;
using Entoarox.AdvancedLocationLoader.Configs;
using StardewValley;
namespace Entoarox.AdvancedLocationLoader
{
internal class TeleportationResolver
{
/*********
** Fields
*********/
private static readonly Dictionary<string, TeleportationResolver> Cache = new Dictionary<string, TeleportationResolver>();
private readonly Dictionary<string, Response> Destinations;
private readonly TeleporterList List;
/*********
** Public methods
*********/
public static TeleportationResolver Request(string list)
{
if (!TeleportationResolver.Cache.ContainsKey(list))
TeleportationResolver.Cache.Add(list, new TeleportationResolver(list));
return TeleportationResolver.Cache[list];
}
public void Init()
{
List<Response> destinations = new List<Response>();
foreach (KeyValuePair<string, Response> entry in this.Destinations)
if (entry.Key != Game1.currentLocation.Name)
destinations.Add(entry.Value);
Game1.currentLocation.lastQuestionKey = "SelectTeleportDestination";
Game1.currentLocation.createQuestionDialogue(ModEntry.Strings.Get("teleporter"), destinations.ToArray(), this.Resolver, null);
}
public void Resolver(Farmer who, string answer)
{
if (answer == "cancel")
return;
int i = Convert.ToInt32(answer);
TeleporterDestination destination = this.List.Destinations[i];
Game1.warpFarmer(destination.MapName, destination.TileX, destination.TileY, false);
}
/*********
** Private methods
*********/
private TeleportationResolver(string list)
{
this.List = ModEntry.PatchData.Teleporters.FirstOrDefault(e => e.ListName == list);
this.Destinations = new Dictionary<string, Response> { { "", new Response("cancel", ModEntry.Strings.Get("cancel")) } };
for (int c = 0; c < this.List.Destinations.Count; c++)
{
if (this.List.Destinations[c].MapName != Game1.currentLocation.Name)
this.Destinations.Add(this.List.Destinations[c].MapName, new Response(c.ToString(), this.List.Destinations[c].ItemText));
}
}
}
}