Skip to content

Commit

Permalink
GadgetCore v2.0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperKael committed Jul 11, 2021
1 parent d4dc79b commit 03c667f
Show file tree
Hide file tree
Showing 24 changed files with 547 additions and 121 deletions.
4 changes: 3 additions & 1 deletion API/CraftMenuInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -818,19 +818,21 @@ public static Tuple<SlotValidator, CraftValidator, CraftPerformer> CreateAdvance
}
for (int i = 0; i < recipe.Slots.Length; i++)
{
int oldQuantity = items[i]?.q ?? 0;
switch (recipe.Slots[i].Type)
{
case AdvancedRecipeComponentType.CORE_OUTPUT:
items[i] = coreItem.CloneItem();
items[i].id = recipe.Slots[i].Item.id;
items[i].q = recipe.Slots[i].Item.q;
items[i].q = recipe.Slots[i].Item.q + oldQuantity;
items[i].exp += recipe.Slots[i].Item.exp;
items[i].tier += recipe.Slots[i].Item.tier;
if (recipe.Slots[i].QuantityVariation > 0) items[i].q += UnityEngine.Random.Range(0, recipe.Slots[i].QuantityVariation + 1);
if (recipe.Slots[i].QuantityVariation < 0) items[i].q -= UnityEngine.Random.Range(0, -recipe.Slots[i].QuantityVariation + 1);
break;
case AdvancedRecipeComponentType.OUTPUT:
items[i] = recipe.Slots[i].Item.CloneItem();
items[i].q += oldQuantity;
if (items[i].tier < 0) items[i].tier = GadgetCoreAPI.GetRandomCraftTier();
if (recipe.Slots[i].QuantityVariation > 0) items[i].q += UnityEngine.Random.Range(0, recipe.Slots[i].QuantityVariation + 1);
if (recipe.Slots[i].QuantityVariation < 0) items[i].q -= UnityEngine.Random.Range(0, -recipe.Slots[i].QuantityVariation + 1);
Expand Down
6 changes: 3 additions & 3 deletions API/GadgetConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public static int SendConsoleMessage(string message, string sender, bool printCo
string[] args = ParseArgs(message.Substring(1));
if (commandAliases.ContainsKey(args[0]))
{
if (force || SceneManager.GetActiveScene().buildIndex == 0 || Network.isServer || !isOperatorOnly[commandAliases[args[0]]] || operators.Contains(Menuu.curName))
if (force || SceneManager.GetActiveScene().buildIndex == 0 || Network.isServer || !isOperatorOnly[commandAliases[args[0]]] || operators.Contains(GadgetCoreAPI.GetPlayerName()))
{
GadgetConsoleMessage feedback;
try
Expand All @@ -431,7 +431,7 @@ public static int SendConsoleMessage(string message, string sender, bool printCo
}
catch (Exception e)
{
feedback = new GadgetConsoleMessage("Error executing command: " + e);
feedback = new GadgetConsoleMessage("Error executing command: " + e, null, MessageSeverity.ERROR);
}
finally
{
Expand Down Expand Up @@ -523,7 +523,7 @@ private GadgetConsole()
InputField.text = "";
InputField.ActivateInputField();
InputField.Select();
SendConsoleMessage(text, SceneManager.GetActiveScene().buildIndex == 0 ? "User" : Menuu.curName);
SendConsoleMessage(text, SceneManager.GetActiveScene().buildIndex == 0 ? "User" : GadgetCoreAPI.GetPlayerName());
messageHistory.Add(text);
historyIndex = messageHistory.Count;
}
Expand Down
92 changes: 85 additions & 7 deletions API/GadgetCoreAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public static class GadgetCoreAPI
/// <summary>
/// The version numbers for this version of Gadget Core. You generally shouldn't access this directly, instead use <see cref="GetRawVersion()"/>
/// </summary>
public const string RAW_VERSION = "2.0.4.0";
public const string RAW_VERSION = "2.0.4.1";
/// <summary>
/// A slightly more informative version. You generally shouldn't access this directly, instead use <see cref="GetFullVersion()"/>
/// </summary>
public const string FULL_VERSION = "2.0.4.0 - Power Commands Edition";
public const string FULL_VERSION = "2.0.4.1 - Power Commands Edition";
/// <summary>
/// Indicates whether this version of GadgetCore is a beta version. You generally shouldn't access this directly, instead use <see cref="GetIsBeta()"/>
/// </summary>
Expand Down Expand Up @@ -77,6 +77,7 @@ public static class GadgetCoreAPI
internal static int spriteSheetSize = -1;
internal static Texture2D spriteSheet;
internal static int[][] equippedGearStats = new int[9][];
internal static string playerName;

static GadgetCoreAPI()
{
Expand All @@ -85,8 +86,10 @@ static GadgetCoreAPI()

internal static void SceneReset()
{
playersByName.Clear();
inventory = null;
portalUses = null;
playerName = Menuu.curName;
}

/// <summary>
Expand All @@ -111,12 +114,20 @@ public static bool GetIsBeta()
return IS_BETA;
}

/// <summary>
/// Gets the name of the current player, potentially including the numeric afix in the case of multiple players with the same name in a multiplayer game.
/// </summary>
public static string GetPlayerName()
{
return playerName;
}

/// <summary>
/// Returns the <see cref="PlayerScript"/> for the player with the given name. Returns null if no player with that name exists.
/// </summary>
public static PlayerScript GetPlayerByName(string name)
{
return playersByName.ContainsKey(name) ? playersByName[name] : name == Menuu.curName ? InstanceTracker.PlayerScript : null;
return playersByName.ContainsKey(name) ? playersByName[name] : name == Menuu.curName || name == GetPlayerName() ? InstanceTracker.PlayerScript : null;
}

/// <summary>
Expand Down Expand Up @@ -163,10 +174,37 @@ public static bool IsInputFrozen()
/// </summary>
public static void Quit()
{
if (ModBrowser.UpdateOnRestart)
{
QuitAndUpdate();
return;
}
GadgetCore.Quitting = true;
Application.Quit();
}

/// <summary>
/// Quits the game, and launches an update using an already-downloaded "Gadget Core Installer.exe" file in the Tools directory.
/// </summary>
public static void QuitAndUpdate()
{
GadgetCore.Quitting = true;
try
{
using (StreamWriter stream = File.CreateText(Path.Combine(GadgetPaths.GadgetCorePath, "Update.tmp")))
{
stream.Write(GetFullVersion());
}
}
catch (Exception) { }
try
{
Process.Start(Path.Combine(GadgetPaths.ToolsPath, "Gadget Core Installer.exe"), $"--update \"{GadgetPaths.GamePath}\"");
}
catch (Exception) { }
Application.Quit();
}

/// <summary>
/// Returns an interface that can be used for interfacing with UMF. Will return null if UMF is not installed.
/// </summary>
Expand Down Expand Up @@ -290,6 +328,7 @@ public static void DisplayYesNoDialog(string text, Action onYes, Action onNo = n
SceneInjector.ConfirmationText.text = text;
SceneInjector.ConfirmationYesAction = onYes;
SceneInjector.ConfirmationNoAction = onNo;
SceneInjector.ConfirmationDialogBackingPanel.SetActive(true);
SceneInjector.ConfirmationDialog.SetActive(true);
}

Expand All @@ -303,6 +342,7 @@ public static void DisplayOKCancelDialog(string text, Action onOK, Action onCanc
SceneInjector.ConfirmationNoAction = onCancel;
SceneInjector.ConfirmationYesText.text = "OK";
SceneInjector.ConfirmationNoText.text = "Cancel";
SceneInjector.ConfirmationDialogBackingPanel.SetActive(true);
SceneInjector.ConfirmationDialog.SetActive(true);
}

Expand All @@ -314,6 +354,7 @@ public static void DisplayInfoDialog(string text)
SceneInjector.ConfirmationText.text = text;
SceneInjector.ConfirmationYesText.transform.parent.gameObject.SetActive(false);
SceneInjector.ConfirmationNoText.text = "OK";
SceneInjector.ConfirmationDialogBackingPanel.SetActive(true);
SceneInjector.ConfirmationDialog.SetActive(true);
}

Expand All @@ -323,6 +364,7 @@ public static void DisplayInfoDialog(string text)
public static void CloseDialog()
{
SceneInjector.ConfirmationDialog.SetActive(false);
SceneInjector.ConfirmationDialogBackingPanel.SetActive(false);
SceneInjector.ConfirmationText.text = "";
SceneInjector.ConfirmationYesText.text = "Yes";
SceneInjector.ConfirmationNoText.text = "No";
Expand Down Expand Up @@ -446,7 +488,7 @@ public static void SpawnItem(Vector3 pos, Item item, bool isChip = false)
{
if (!isChip)
{
int[] st = ConstructIntArrayFromItem(item);
int[] st = ConstructIntArrayFromItem(item, true, false);
if (Network.isServer)
{
ItemScript itemScript = ((GameObject)Network.Instantiate(Resources.Load("i"), pos, Quaternion.identity, 0)).GetComponent<ItemScript>();
Expand All @@ -464,7 +506,7 @@ public static void SpawnItem(Vector3 pos, Item item, bool isChip = false)
else
{
ItemScript itemScript = ((GameObject)Network.Instantiate(Resources.Load("i"), pos, Quaternion.identity, 0)).GetComponent<ItemScript>();
itemScript.gameObject.GetComponent<NetworkView>().RPC("Chip", RPCMode.AllBuffered, item.id);
itemScript.gameObject.GetComponent<NetworkView>().RPC("Chip", RPCMode.AllBuffered, ChipRegistry.Singleton.ConvertIDToHost(item.id));
}
}

Expand Down Expand Up @@ -689,7 +731,7 @@ public static ItemScript DropItem(Vector3 pos, Item item, bool isChip = false)
{
if (!isChip)
{
int[] st = ConstructIntArrayFromItem(item);
int[] st = ConstructIntArrayFromItem(item, true, false);
ItemScript itemScript = ((GameObject)Network.Instantiate(Resources.Load("i2"), pos, Quaternion.identity, 0)).GetComponent<ItemScript>();
itemScript.gameObject.GetComponent<NetworkView>().RPC("Init", RPCMode.AllBuffered, st);
if ((ItemRegistry.GetItem(item.id)?.Type & ItemType.LEVELING) == ItemType.LEVELING) itemScript.back.SetActive(true);
Expand All @@ -698,7 +740,7 @@ public static ItemScript DropItem(Vector3 pos, Item item, bool isChip = false)
else
{
ItemScript itemScript = ((GameObject)Network.Instantiate(Resources.Load("i2"), pos, Quaternion.identity, 0)).GetComponent<ItemScript>();
itemScript.gameObject.GetComponent<NetworkView>().RPC("Chip", RPCMode.AllBuffered, item.id);
itemScript.gameObject.GetComponent<NetworkView>().RPC("Chip", RPCMode.AllBuffered, ChipRegistry.Singleton.ConvertIDToHost(item.id));
return itemScript;
}
}
Expand Down Expand Up @@ -1206,6 +1248,42 @@ internal static void UnregisterStatModifiers(int modID)
/// <param name="item">The item who's stats are being modified.</param>
public delegate EquipStatsDouble StatModifier(Item item);

/// <summary>
/// Generates a plane-shaped mesh, with a specified width and height.
/// </summary>
public static Mesh GeneratePlaneMesh(float width, float height)
{
return new Mesh
{
name = "Plane",
vertices = new Vector3[]
{
new Vector3(width / -2, height / -2, 0),
new Vector3(width / -2, height / 2, 0),
new Vector3(width / 2, height / 2, 0),
new Vector3(width / 2, height / -2, 0)
},
uv = new Vector2[]
{
new Vector2(0, 0),
new Vector2(0, 1),
new Vector2(1, 1),
new Vector2(1, 0)
},
normals = new Vector3[]
{
new Vector3(0, 0, -1),
new Vector3(0, 0, -1),
new Vector3(0, 0, -1),
new Vector3(0, 0, -1)
},
triangles = new int[]
{
0, 1, 2, 2, 3, 0
}
};
}

/// <summary>
/// Use to check if there is a resource registered at the specified path. This includes resources registered by the base game.
/// </summary>
Expand Down
Loading

0 comments on commit 03c667f

Please sign in to comment.