2017-07-04 10:07:20 -04:00
|
|
|
/*
|
|
|
|
* MIT License
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEVEL
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using ShiftOS.Engine.Properties;
|
|
|
|
using System.IO;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
|
|
|
using ShiftOS.Objects;
|
|
|
|
using ShiftOS.Engine.Scripting;
|
|
|
|
using ShiftOS.Objects.ShiftFS;
|
|
|
|
using ShiftOS.Engine;
|
|
|
|
|
|
|
|
namespace ShiftOS.Frontend
|
|
|
|
{
|
2017-08-02 20:15:46 -04:00
|
|
|
public static class Cowsay
|
|
|
|
{
|
|
|
|
[Command("cowsay")]
|
|
|
|
[RequiresArgument("id")]
|
|
|
|
public static void Say(Dictionary<string, object> args)
|
|
|
|
{
|
|
|
|
var builder = new List<string>();
|
|
|
|
int speechlen = (args.ContainsKey("width")) ? Convert.ToInt32(args["width"].ToString()) : 50;
|
2017-08-03 08:49:07 -04:00
|
|
|
string cowfile = (args.ContainsKey("file")) ? args["file"].ToString() : null;
|
2017-08-02 20:15:46 -04:00
|
|
|
string speech = args["id"].ToString();
|
|
|
|
AnimalMode _mode = AnimalMode.Normal;
|
|
|
|
if (args.ContainsKey("mode"))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_mode = (AnimalMode)Enum.Parse(typeof(AnimalMode), args["mode"].ToString());
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
Console.WriteLine("Invalid animal mode. Valid animal modes are:");
|
|
|
|
foreach(var name in Enum.GetNames(typeof(AnimalMode)))
|
|
|
|
{
|
|
|
|
Console.WriteLine(" - " + name);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
DrawSpeechBubble(ref builder, speechlen, speech);
|
2017-08-03 08:49:07 -04:00
|
|
|
DrawCow(ref builder, _mode, cowfile);
|
2017-08-02 20:15:46 -04:00
|
|
|
Console.WriteLine(string.Join(Environment.NewLine, builder.ToArray()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string[] SplitInParts(this string value, int width)
|
|
|
|
{
|
|
|
|
List<string> nvalue = new List<string>();
|
|
|
|
while(value.Length > 0)
|
|
|
|
{
|
|
|
|
string substr = value.Substring(0, Math.Min(value.Length, width));
|
|
|
|
value = value.Remove(0, substr.Length);
|
|
|
|
nvalue.Add(substr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nvalue.ToArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string RepeatChar(this char value, int amount)
|
|
|
|
{
|
|
|
|
string nvalue = "";
|
|
|
|
for(int i = 0; i < amount; i++)
|
|
|
|
{
|
|
|
|
nvalue += value;
|
|
|
|
}
|
|
|
|
return nvalue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void DrawSpeechBubble(ref List<string> Builder, int balloonWidth, string speech)
|
|
|
|
{
|
|
|
|
var lineLength = balloonWidth - 4;
|
|
|
|
var output = speech.SplitInParts((int)lineLength).ToArray();
|
|
|
|
var lines = output.Length;
|
|
|
|
var wrapperLineLength = (lines == 1 ? output.First().Length : (int)balloonWidth - 4) + 2;
|
|
|
|
|
|
|
|
Builder.Add($" {'_'.RepeatChar(wrapperLineLength)}");
|
|
|
|
if (lines == 1)
|
|
|
|
{
|
|
|
|
Builder.Add($"< {output.First()} >");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (var i = 0; i < lines; i++)
|
|
|
|
{
|
|
|
|
char lineStartChar = '|';
|
|
|
|
char lineEndChar = '|';
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
lineStartChar = '/';
|
|
|
|
lineEndChar = '\\';
|
|
|
|
}
|
|
|
|
else if (i == lines - 1)
|
|
|
|
{
|
|
|
|
lineStartChar = '\\';
|
|
|
|
lineEndChar = '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
var neededPadding = (int)balloonWidth - 4 - output[i].Length;
|
|
|
|
Builder.Add($"{lineStartChar} {output[i]}{' '.RepeatChar(neededPadding)} {lineEndChar}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Builder.Add($" {'-'.RepeatChar(wrapperLineLength)}");
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum AnimalMode
|
|
|
|
{
|
|
|
|
Normal,
|
|
|
|
Borg,
|
|
|
|
Dead,
|
|
|
|
Greedy,
|
|
|
|
Paranoid,
|
|
|
|
Stoned,
|
|
|
|
Tired,
|
|
|
|
Wired,
|
|
|
|
Youthful
|
|
|
|
}
|
|
|
|
|
2017-08-03 08:49:07 -04:00
|
|
|
private static void DrawCow(ref List<string> Builder, AnimalMode AnimalMode, string cowfile)
|
2017-08-02 20:15:46 -04:00
|
|
|
{
|
|
|
|
var startingLinePadding = Builder.First().Length / 4;
|
|
|
|
|
|
|
|
var eyeChar = 'o';
|
|
|
|
var tongueChar = ' ';
|
|
|
|
|
|
|
|
switch (AnimalMode)
|
|
|
|
{
|
|
|
|
case AnimalMode.Borg:
|
|
|
|
eyeChar = '=';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AnimalMode.Dead:
|
|
|
|
eyeChar = 'x';
|
|
|
|
tongueChar = 'U';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AnimalMode.Greedy:
|
|
|
|
eyeChar = '$';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AnimalMode.Paranoid:
|
|
|
|
eyeChar = '@';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AnimalMode.Stoned:
|
|
|
|
eyeChar = '*';
|
|
|
|
tongueChar = 'U';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AnimalMode.Tired:
|
|
|
|
eyeChar = '-';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AnimalMode.Wired:
|
|
|
|
eyeChar = 'O';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AnimalMode.Youthful:
|
|
|
|
eyeChar = '.';
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2017-08-03 08:49:07 -04:00
|
|
|
string cowpath = Paths.GetPath("data") + "/cows/" + cowfile + ".cow";
|
|
|
|
if (string.IsNullOrWhiteSpace(cowfile) || !Utils.FileExists(cowpath))
|
|
|
|
{
|
|
|
|
Builder.Add($"{' '.RepeatChar(startingLinePadding)}\\ ^__^");
|
|
|
|
Builder.Add($"{' '.RepeatChar(startingLinePadding)} \\ ({eyeChar.RepeatChar(2)})\\_______");
|
|
|
|
Builder.Add($"{' '.RepeatChar(startingLinePadding)} (__)\\ )\\/\\");
|
|
|
|
Builder.Add($"{' '.RepeatChar(startingLinePadding)} {tongueChar.RepeatChar(1)} ||----w |");
|
|
|
|
Builder.Add($"{' '.RepeatChar(startingLinePadding)} || ||");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string[] lines = Utils.ReadAllText(cowpath).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
foreach(var line in lines)
|
|
|
|
{
|
|
|
|
Builder.Add($"{' '.RepeatChar(startingLinePadding)}{line.Replace("#", eyeChar.ToString())}");
|
|
|
|
}
|
|
|
|
}
|
2017-08-02 20:15:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-01 12:22:15 -04:00
|
|
|
public static class MissionsCommands
|
|
|
|
{
|
|
|
|
[Command("startmission")]
|
|
|
|
[RequiresArgument("id")]
|
|
|
|
[RequiresUpgrade("tutorial1")]
|
|
|
|
public static void StartMission(Dictionary<string, object> args)
|
|
|
|
{
|
|
|
|
string id = args["id"].ToString();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!Shiftorium.UpgradeInstalled(id))
|
|
|
|
{
|
|
|
|
Story.Start(id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Console.WriteLine("That mission has already been complete. You can't replay it.");
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
Console.WriteLine("That mission could not be found. Try running missions for a list of available missions.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Command("missions")]
|
|
|
|
[RequiresUpgrade("tutorial1")]
|
|
|
|
public static void Missions()
|
|
|
|
{
|
|
|
|
Console.WriteLine("Available missions");
|
|
|
|
Console.WriteLine("===================");
|
|
|
|
Console.WriteLine();
|
|
|
|
bool found = false;
|
|
|
|
foreach (var type in ReflectMan.Types)
|
|
|
|
{
|
|
|
|
foreach(var mth in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
|
|
|
|
{
|
|
|
|
var missionattrib = mth.GetCustomAttributes(false).FirstOrDefault(x => x is MissionAttribute) as MissionAttribute;
|
|
|
|
if(missionattrib != null)
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
Console.WriteLine();
|
|
|
|
Console.WriteLine($@"{missionattrib.Name} (id {missionattrib.StoryID})
|
|
|
|
------------------------------------
|
|
|
|
|
|
|
|
assigner: {missionattrib.Assigner}
|
|
|
|
cp reward: {missionattrib.CodepointAward}
|
|
|
|
|
|
|
|
{missionattrib.Description}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(found == false)
|
|
|
|
{
|
|
|
|
Console.WriteLine();
|
|
|
|
Console.WriteLine(@"No missions found.
|
|
|
|
------------------------------------
|
|
|
|
|
|
|
|
assigner: undefined
|
|
|
|
cp reward: [object Object]
|
|
|
|
|
|
|
|
There are no missions available for you to complete. Please check back later for more!");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-04 10:07:20 -04:00
|
|
|
[TutorialLock]
|
|
|
|
public static class TerminalCommands
|
|
|
|
{
|
2017-08-02 08:14:22 -04:00
|
|
|
[Command("echo")]
|
|
|
|
[RequiresArgument("id")]
|
|
|
|
public static void Echo(Dictionary<string, object> args)
|
|
|
|
{
|
|
|
|
Console.WriteLine(args["id"].ToString());
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:49:37 -04:00
|
|
|
[MetaCommand]
|
2017-07-04 10:07:20 -04:00
|
|
|
[Command("clear", description = "{DESC_CLEAR}")]
|
|
|
|
public static bool Clear()
|
|
|
|
{
|
|
|
|
Engine.Desktop.InvokeOnWorkerThread(() =>
|
|
|
|
{
|
|
|
|
AppearanceManager.ConsoleOut.Clear();
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class ShiftOSCommands
|
|
|
|
{
|
2017-07-29 13:49:37 -04:00
|
|
|
#if DEBUG
|
|
|
|
[Command("debug")]
|
|
|
|
public static void EnterDebug()
|
|
|
|
{
|
|
|
|
TerminalBackend.SetShellOverride("shiftos_debug> ");
|
|
|
|
}
|
|
|
|
#endif
|
2017-07-04 10:07:20 -04:00
|
|
|
|
2017-07-29 13:49:37 -04:00
|
|
|
[Command("setsfxenabled", description = "{DESC_SETSFXENABLED}")]
|
2017-07-29 13:42:25 -04:00
|
|
|
[RequiresArgument("id")]
|
2017-07-04 10:07:20 -04:00
|
|
|
public static bool SetSfxEnabled(Dictionary<string, object> args)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-07-29 13:42:25 -04:00
|
|
|
bool value = Convert.ToBoolean(args["id"].ToString());
|
2017-07-04 10:07:20 -04:00
|
|
|
SaveSystem.CurrentSave.SoundEnabled = value;
|
|
|
|
SaveSystem.SaveGame();
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
Console.WriteLine("{ERR_BADBOOL}");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Command("setmusicenabled", description = "{DESC_SETMUSICENABLED}")]
|
2017-07-29 13:42:25 -04:00
|
|
|
[RequiresArgument("id")]
|
2017-07-04 10:07:20 -04:00
|
|
|
public static bool SetMusicEnabled(Dictionary<string, object> args)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-07-29 13:42:25 -04:00
|
|
|
bool value = Convert.ToBoolean(args["id"].ToString());
|
2017-07-04 10:07:20 -04:00
|
|
|
SaveSystem.CurrentSave.MusicEnabled = value;
|
|
|
|
SaveSystem.SaveGame();
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
Console.WriteLine("{ERR_BADBOOL}");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Command("setvolume", description ="{DESC_SETVOLUME}")]
|
2017-07-29 13:42:25 -04:00
|
|
|
[RequiresArgument("id")]
|
2017-07-04 10:07:20 -04:00
|
|
|
public static bool SetSfxVolume(Dictionary<string, object> args)
|
|
|
|
{
|
2017-07-29 13:42:25 -04:00
|
|
|
int value = int.Parse(args["id"].ToString());
|
2017-07-04 10:07:20 -04:00
|
|
|
if(value >= 0 && value <= 100)
|
|
|
|
{
|
|
|
|
SaveSystem.CurrentSave.MusicVolume = value;
|
|
|
|
SaveSystem.SaveGame();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Console.WriteLine("{ERR_BADPERCENT}");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[RemoteLock]
|
|
|
|
[Command("shutdown", description = "{DESC_SHUTDOWN}")]
|
|
|
|
public static bool Shutdown()
|
|
|
|
{
|
2017-07-27 12:03:55 -04:00
|
|
|
if(Objects.ShiftFS.Utils.Mounts.Count > 0)
|
|
|
|
SaveSystem.SaveGame();
|
2017-07-04 10:07:20 -04:00
|
|
|
AppearanceManager.Exit();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[Command("lang", description = "{DESC_LANG}")]
|
2017-07-29 13:42:25 -04:00
|
|
|
[RequiresArgument("id")]
|
2017-07-04 10:07:20 -04:00
|
|
|
public static bool SetLanguage(Dictionary<string, object> userArgs)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
string lang = "";
|
|
|
|
|
2017-07-29 13:42:25 -04:00
|
|
|
lang = (string)userArgs["id"];
|
2017-07-04 10:07:20 -04:00
|
|
|
|
|
|
|
if (Localization.GetAllLanguages().Contains(lang))
|
|
|
|
{
|
|
|
|
SaveSystem.CurrentSave.Language = lang;
|
|
|
|
SaveSystem.SaveGame();
|
|
|
|
Console.WriteLine("{RES_LANGUAGE_CHANGED}");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Exception("{ERR_NOLANG}");
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-29 11:01:32 -04:00
|
|
|
[MetaCommand]
|
|
|
|
[Command("help", "", "{DESC_COMMANDS}")]
|
2017-07-04 10:07:20 -04:00
|
|
|
public static bool Commands()
|
|
|
|
{
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
sb.AppendLine("{GEN_COMMANDS}");
|
|
|
|
sb.AppendLine("=================");
|
|
|
|
sb.AppendLine();
|
|
|
|
//print all unique namespaces.
|
2017-07-29 11:01:32 -04:00
|
|
|
foreach (var n in TerminalBackend.Commands.Where(x => !(x is TerminalBackend.WinOpenCommand) && Shiftorium.UpgradeInstalled(x.Dependencies) && x.CommandInfo.hide == false && x.MatchShell() == true).OrderBy(x => x.CommandInfo.name))
|
2017-07-04 10:07:20 -04:00
|
|
|
{
|
|
|
|
sb.Append(" - " + n.CommandInfo.name);
|
|
|
|
if (!string.IsNullOrWhiteSpace(n.CommandInfo.description))
|
|
|
|
if (Shiftorium.UpgradeInstalled("help_description"))
|
|
|
|
sb.Append(" - " + n.CommandInfo.description);
|
|
|
|
sb.AppendLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
Console.WriteLine(sb.ToString());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[MultiplayerOnly]
|
|
|
|
[Command("save", description = "{DESC_SAVE}")]
|
|
|
|
public static bool Save()
|
|
|
|
{
|
|
|
|
SaveSystem.SaveGame();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[MultiplayerOnly]
|
|
|
|
[Command("status", description = "{DESC_STATUS}")]
|
|
|
|
public static bool Status()
|
|
|
|
{
|
|
|
|
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
|
|
|
|
|
|
string cp = SaveSystem.CurrentSave.Codepoints.ToString();
|
|
|
|
string installed = SaveSystem.CurrentSave.CountUpgrades().ToString();
|
|
|
|
string available = Shiftorium.GetAvailable().Length.ToString();
|
|
|
|
|
|
|
|
Console.WriteLine(Localization.Parse("{COM_STATUS}", new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
["%cp"] = cp,
|
|
|
|
["%version"] = version,
|
|
|
|
["%installed"] = installed,
|
|
|
|
["%available"] = available
|
|
|
|
}));
|
|
|
|
Console.WriteLine("{GEN_OBJECTIVES}");
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (Story.CurrentObjectives.Count > 0)
|
|
|
|
{
|
|
|
|
foreach (var obj in Story.CurrentObjectives)
|
|
|
|
{
|
|
|
|
Console.WriteLine(obj.Name);
|
|
|
|
Console.WriteLine("-------------------------------");
|
|
|
|
Console.WriteLine();
|
|
|
|
Console.WriteLine(obj.Description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Console.WriteLine("{RES_NOOBJECTIVES}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
Console.WriteLine("{RES_NOOBJECTIVES}");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class ShiftoriumCommands
|
|
|
|
{
|
|
|
|
[Command("buy", description = "{DESC_BUY}")]
|
2017-07-29 13:42:25 -04:00
|
|
|
[RequiresArgument("id")]
|
2017-07-04 10:07:20 -04:00
|
|
|
public static bool BuyUpgrade(Dictionary<string, object> userArgs)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
string upgrade = "";
|
|
|
|
|
2017-07-29 13:42:25 -04:00
|
|
|
upgrade = (string)userArgs["id"];
|
2017-07-04 10:07:20 -04:00
|
|
|
|
|
|
|
var upg = Shiftorium.GetAvailable().FirstOrDefault(x => x.ID == upgrade);
|
|
|
|
if(upg != null)
|
|
|
|
{
|
|
|
|
if (!Shiftorium.Buy(upg.ID, upg.Cost) == true)
|
|
|
|
Console.WriteLine("{ERR_NOTENOUGHCODEPOINTS}");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Console.WriteLine("{ERR_NOUPGRADE}");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
Console.WriteLine("{ERR_GENERAL}");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[RequiresUpgrade("shiftorium_bulk_buy")]
|
|
|
|
[Command("bulkbuy", description = "{DESC_BULKBUY}")]
|
2017-07-29 13:42:25 -04:00
|
|
|
[RequiresArgument("id")]
|
2017-07-04 10:07:20 -04:00
|
|
|
public static bool BuyBulk(Dictionary<string, object> args)
|
|
|
|
{
|
2017-07-29 13:42:25 -04:00
|
|
|
if (args.ContainsKey("id"))
|
2017-07-04 10:07:20 -04:00
|
|
|
{
|
2017-07-29 13:42:25 -04:00
|
|
|
string[] upgrade_list = (args["id"] as string).Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
2017-07-04 10:07:20 -04:00
|
|
|
foreach (var upg in upgrade_list)
|
|
|
|
{
|
|
|
|
var dict = new Dictionary<string, object>();
|
|
|
|
dict.Add("upgrade", upg);
|
|
|
|
BuyUpgrade(dict);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Command("upgradeinfo", description ="{DESC_UPGRADEINFO}")]
|
2017-07-29 13:42:25 -04:00
|
|
|
[RequiresArgument("id")]
|
2017-07-04 10:07:20 -04:00
|
|
|
public static bool ViewInfo(Dictionary<string, object> userArgs)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
string upgrade = "";
|
|
|
|
|
2017-07-29 13:42:25 -04:00
|
|
|
upgrade = (string)userArgs["id"];
|
2017-07-04 10:07:20 -04:00
|
|
|
|
|
|
|
foreach (var upg in Shiftorium.GetDefaults())
|
|
|
|
{
|
|
|
|
if (upg.ID == upgrade)
|
|
|
|
{
|
|
|
|
Console.WriteLine(Localization.Parse("{COM_UPGRADEINFO}", new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
["%id"] = upg.ID,
|
|
|
|
["%category"] = upg.Category,
|
|
|
|
["%name"] = upg.Name,
|
|
|
|
["%cost"] = upg.Cost.ToString(),
|
|
|
|
["%description"] = upg.Description
|
|
|
|
}));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Exception("{ERR_NOUPGRADE}");
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Command("upgradecategories", description = "{DESC_UPGRADECATEGORIES}")]
|
|
|
|
public static bool ListCategories()
|
|
|
|
{
|
|
|
|
foreach(var cat in Shiftorium.GetCategories())
|
|
|
|
{
|
|
|
|
Console.WriteLine(Localization.Parse("{SHFM_CATEGORY}", new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
["%name"] = cat,
|
|
|
|
["%available"] = Shiftorium.GetAvailable().Where(x=>x.Category==cat).Count().ToString()
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[Command("upgrades", description ="{DESC_UPGRADES}")]
|
|
|
|
public static bool ListAll(Dictionary<string, object> args)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
bool showOnlyInCategory = false;
|
|
|
|
|
|
|
|
string cat = "Other";
|
|
|
|
|
|
|
|
if (args.ContainsKey("cat"))
|
|
|
|
{
|
|
|
|
showOnlyInCategory = true;
|
|
|
|
cat = args["cat"].ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary<string, ulong> upgrades = new Dictionary<string, ulong>();
|
|
|
|
int maxLength = 5;
|
|
|
|
|
|
|
|
IEnumerable<ShiftoriumUpgrade> upglist = Shiftorium.GetAvailable();
|
|
|
|
if (showOnlyInCategory)
|
|
|
|
{
|
|
|
|
if (Shiftorium.IsCategoryEmptied(cat))
|
|
|
|
{
|
|
|
|
ConsoleEx.Bold = true;
|
|
|
|
ConsoleEx.ForegroundColor = ConsoleColor.Red;
|
|
|
|
Console.WriteLine("{SHFM_QUERYERROR}");
|
|
|
|
Console.WriteLine();
|
|
|
|
ConsoleEx.Bold = false;
|
|
|
|
ConsoleEx.ForegroundColor = ConsoleColor.Gray;
|
|
|
|
Console.WriteLine("{ERR_EMPTYCATEGORY}");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
upglist = Shiftorium.GetAvailable().Where(x => x.Category == cat);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(upglist.Count() == 0)
|
|
|
|
{
|
|
|
|
ConsoleEx.Bold = true;
|
|
|
|
ConsoleEx.ForegroundColor = ConsoleColor.Red;
|
|
|
|
Console.WriteLine("{SHFM_NOUPGRADES}");
|
|
|
|
Console.WriteLine();
|
|
|
|
ConsoleEx.Bold = false;
|
|
|
|
ConsoleEx.ForegroundColor = ConsoleColor.Gray;
|
|
|
|
Console.WriteLine("{ERR_NOMOREUPGRADES}");
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
foreach (var upg in upglist)
|
|
|
|
{
|
|
|
|
if (upg.ID.Length > maxLength)
|
|
|
|
{
|
|
|
|
maxLength = upg.ID.Length;
|
|
|
|
}
|
|
|
|
|
|
|
|
upgrades.Add(upg.ID, upg.Cost);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var upg in upgrades)
|
|
|
|
{
|
|
|
|
Console.WriteLine(Localization.Parse("{SHFM_UPGRADE}", new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
["%id"] = upg.Key,
|
|
|
|
["%cost"] = upg.Value.ToString()
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
CrashHandler.Start(e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class WindowCommands
|
|
|
|
{
|
|
|
|
[RemoteLock]
|
|
|
|
[Command("processes", description = "{DESC_PROCESSES}")]
|
|
|
|
public static bool List()
|
|
|
|
{
|
|
|
|
Console.WriteLine("{GEN_CURRENTPROCESSES}");
|
|
|
|
foreach (var app in AppearanceManager.OpenForms)
|
|
|
|
{
|
|
|
|
//Windows are displayed the order in which they were opened.
|
|
|
|
Console.WriteLine($"{AppearanceManager.OpenForms.IndexOf(app)}\t{app.Text}");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[Command("programs", description = "{DESC_PROGRAMS}")]
|
|
|
|
public static bool Programs()
|
|
|
|
{
|
2017-07-28 14:29:08 -04:00
|
|
|
var sb = new StringBuilder();
|
|
|
|
sb.AppendLine("{GEN_PROGRAMS}");
|
|
|
|
sb.AppendLine("===============");
|
|
|
|
sb.AppendLine();
|
|
|
|
//print all unique namespaces.
|
|
|
|
foreach(var n in TerminalBackend.Commands.Where(x => x is TerminalBackend.WinOpenCommand && Shiftorium.UpgradeInstalled(x.Dependencies)).OrderBy(x => x.CommandInfo.name))
|
2017-07-04 10:07:20 -04:00
|
|
|
{
|
2017-07-28 14:29:08 -04:00
|
|
|
sb.Append(" - " + n.CommandInfo.name);
|
|
|
|
if (!string.IsNullOrWhiteSpace(n.CommandInfo.description))
|
2017-07-04 10:07:20 -04:00
|
|
|
if (Shiftorium.UpgradeInstalled("help_description"))
|
2017-07-28 14:29:08 -04:00
|
|
|
sb.Append(" - " + n.CommandInfo.description);
|
|
|
|
sb.AppendLine();
|
2017-07-04 10:07:20 -04:00
|
|
|
}
|
2017-07-28 14:29:08 -04:00
|
|
|
|
|
|
|
Console.WriteLine(sb.ToString());
|
|
|
|
|
2017-07-04 10:07:20 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[RemoteLock]
|
2017-07-29 13:42:25 -04:00
|
|
|
[Command("close", description ="{DESC_CLOSE}")]
|
|
|
|
[RequiresArgument("id")]
|
2017-07-04 10:07:20 -04:00
|
|
|
public static bool CloseWindow(Dictionary<string, object> args)
|
|
|
|
{
|
|
|
|
int winNum = -1;
|
2017-07-29 13:42:25 -04:00
|
|
|
if (args.ContainsKey("id"))
|
|
|
|
winNum = Convert.ToInt32(args["id"].ToString());
|
2017-07-04 10:07:20 -04:00
|
|
|
string err = null;
|
|
|
|
|
|
|
|
if (winNum < 0 || winNum >= AppearanceManager.OpenForms.Count)
|
|
|
|
err = Localization.Parse("{ERR_BADWINID}", new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
["%max"] = (AppearanceManager.OpenForms.Count - 1).ToString()
|
|
|
|
});
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(err))
|
|
|
|
{
|
|
|
|
Console.WriteLine("{RES_WINDOWCLOSED}");
|
|
|
|
AppearanceManager.Close(AppearanceManager.OpenForms[winNum].ParentWindow);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Console.WriteLine(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|