-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathActions.cs
158 lines (147 loc) · 6.83 KB
/
Actions.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Entoarox.AdvancedLocationLoader.Configs;
using Entoarox.Framework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Menus;
using StardewValley.Locations;
using xTile.Layers;
using xTile.ObjectModel;
using SObject = StardewValley.Object;
using Tile = xTile.Tiles.Tile;
namespace Entoarox.AdvancedLocationLoader
{
internal static class Actions
{
/*********
** Fields
*********/
internal static Random Random = new Random();
/*********
** Public methods
*********/
public static void Shift(Farmer who, string[] arguments, Vector2 tile)
{
Game1.warpFarmer(who.currentLocation.Name, Convert.ToInt32(arguments[0]), Convert.ToInt32(arguments[1]), who.facingDirection, who.currentLocation.isStructure.Value);
}
public static void Message(Farmer who, string[] arguments, Vector2 tile)
{
Game1.drawDialogueNoTyping(ModEntry.Strings.Get(arguments[0] + ":" + arguments[1]));
}
public static void RawMessage(Farmer who, string[] arguments, Vector2 tile)
{
Game1.drawDialogueNoTyping(string.Join(" ", arguments));
}
public static void RandomMessage(Farmer who, string[] arguments, Vector2 tile)
{
string[] opts = string.Join(" ", arguments).Split('|');
Game1.drawObjectDialogue(opts[Actions.Random.Next(opts.Length)]);
}
public static void React(Farmer who, string[] arguments, Vector2 tile)
{
int interval = Convert.ToInt32(arguments[0]);
int[] indexes = arguments[1].Split(',').Select(e => Convert.ToInt32(e)).ToArray();
Layer layer = who.currentLocation.Map.GetLayer("Buildings");
Tile source = layer.Tiles[(int)tile.X, (int)tile.Y];
PropertyValue property = who.currentLocation.GetTileProperty((int)tile.X, (int)tile.Y, "Buildings", "Action");
int delay = interval * indexes.Length;
who.currentLocation.SetTile((int)tile.X, (int)tile.Y, "Buildings", indexes, interval, source.TileSheet.Id);
Timer timer = null;
timer = new Timer(obj =>
{
who.currentLocation.SetTile((int)tile.X, (int)tile.Y, "Buildings", source.TileIndex, source.TileSheet.Id);
who.currentLocation.SetTileProperty((int)tile.X, (int)tile.Y, "Buildings", "Action", property);
timer.Dispose();
},
null, delay, Timeout.Infinite
);
}
public static void Teleporter(Farmer who, string[] arguments, Vector2 tile)
{
if (ModEntry.PatchData.Teleporters.Any(e => e.ListName.Equals(arguments[0].Trim())))
TeleportationResolver.Request(arguments[0]).Init();
else
{
ModEntry.Logger.Log("Teleporter does not exist: " + arguments[0], LogLevel.Error);
IList<string> lists = new List<string>();
foreach (TeleporterList list in ModEntry.PatchData.Teleporters)
lists.Add(list.ListName);
ModEntry.Logger.Log("Known lists: " + string.Join(",", lists), LogLevel.Trace);
Game1.drawObjectDialogue(ModEntry.Strings.Get("sparkle"));
}
}
public static void Conditional(Farmer who, string[] arguments, Vector2 tile)
{
if (!who.mailReceived.Contains("ALLCondition_" + arguments[0]) && ModEntry.PatchData.Conditionals.Any(e => e.Name == arguments[0]))
ConditionalResolver.Request(arguments[0]).Init();
else
{
if (who.mailReceived.Contains("ALLCondition_" + arguments[0]))
ModEntry.Logger.Log("Conditional has already been completed: " + arguments[0], LogLevel.Error);
else
ModEntry.Logger.Log("Conditional does not exist: " + arguments[0], LogLevel.Error);
Game1.drawObjectDialogue(ModEntry.Strings.Get("sparkle"));
}
}
public static void Shop(Farmer who, string[] arguments, Vector2 tile)
{
try
{
if (!ModEntry.PatchData.Shops.Any(p => p.Name == arguments[0]))
{
Game1.activeClickableMenu = new ShopMenu(new Dictionary<ISalable, int[]>());
ModEntry.Logger.Log("Unable to open shop, shop not found: " + arguments[0], LogLevel.Error);
}
else
{
ShopConfig shop = ModEntry.PatchData.Shops.First(p => p.Name == arguments[0]);
List<Item> stock = new List<Item>();
NPC portrait = new NPC
{
Portrait = shop.PortraitTexture,
Name = shop.Owner
};
foreach (ShopItem item in shop.Items)
{
if (!string.IsNullOrEmpty(item.Conditions) && !ModEntry.SHelper.Conditions().ValidateConditions(item.Conditions))
continue;
SObject result = item.Price != null
? new SObject(item.Id, item.Stock, false, (int)item.Price)
: new SObject(item.Id, item.Stock);
stock.Add(item.Stack > 1
? new StackableShopObject(result, item.Stack)
: result
);
}
if (stock.Count == 0)
ModEntry.Logger.Log("No stock: " + arguments[0] + ", if this is intended this message can be ignored.", LogLevel.Warn);
var menu = new ShopMenu(stock.ToDictionary(_ => _ as ISalable, _ => new int[] { _.Stack }));
menu.portraitPerson = portrait;
menu.potraitPersonDialogue = shop.Messages[Actions.Random.Next(shop.Messages.Count)];
Game1.activeClickableMenu = menu;
}
}
catch (Exception err)
{
ModEntry.Logger.Log("Unable to open shop due to unexpected error: ", LogLevel.Error, err);
}
}
public static void Trigger(Farmer who, string[] arguments, Vector2 tile)
{
switch(arguments[0])
{
case "Fridge":
((FarmHouse)Game1.getLocationFromName("FarmHouse")).fridge.Value.checkForAction(who, false);
break;
default:
ModEntry.Logger.Log("Unknown ALLTrigger argument: " + arguments[0], LogLevel.Error);
break;
}
}
}
}