Skip to content

Commit

Permalink
Incorporated commits from other Razor repo
Browse files Browse the repository at this point in the history
  • Loading branch information
markdwags committed Jan 18, 2020
1 parent 71bf761 commit 9b9ee6a
Show file tree
Hide file tree
Showing 19 changed files with 1,204 additions and 142 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
@@ -1,6 +0,0 @@
[submodule "Razor/Macros/Scripts/ScriptEngine"]
path = Razor/Macros/Scripts/ScriptEngine
url = https://github.com/jaedan/steam-engine
[submodule "steam-engine"]
path = steam-engine
url = https://github.com/jaedan/steam-engine
5 changes: 5 additions & 0 deletions Razor/Core/Agents.cs
Expand Up @@ -1525,6 +1525,11 @@ public ScavengerAgent()
Agent.OnItemCreated += new ItemCreatedEventHandler(CheckBagOPL);
}

public void ToggleEnabled()
{
OnEnableDisable();
}

private void OnEnableDisable()
{
m_Enabled = !m_Enabled;
Expand Down
113 changes: 113 additions & 0 deletions Razor/Core/Dress.cs
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assistant.Core
{
public static class Dress
{
private static Item m_Right, m_Left;

public static void ToggleRight()
{
if (World.Player == null)
return;

Item item = World.Player.GetItemOnLayer(Layer.RightHand);
if (item == null)
{
if (m_Right != null)
m_Right = World.FindItem(m_Right.Serial);

if (m_Right != null && m_Right.IsChildOf(World.Player.Backpack))
{
// try to also undress conflicting hand(s)
Item conflict = World.Player.GetItemOnLayer(Layer.LeftHand);
if (conflict != null && (conflict.IsTwoHanded || m_Right.IsTwoHanded))
{
Unequip(DressList.GetLayerFor(conflict));
}

Equip(m_Right, DressList.GetLayerFor(m_Right));
}
else
{
World.Player.SendMessage(MsgLevel.Force, LocString.MustDisarm);
}
}
else
{
Unequip(DressList.GetLayerFor(item));
m_Right = item;
}
}

public static void ToggleLeft()
{
if (World.Player == null || World.Player.Backpack == null)
return;

Item item = World.Player.GetItemOnLayer(Layer.LeftHand);
if (item == null)
{
if (m_Left != null)
m_Left = World.FindItem(m_Left.Serial);

if (m_Left != null && m_Left.IsChildOf(World.Player.Backpack))
{
Item conflict = World.Player.GetItemOnLayer(Layer.RightHand);
if (conflict != null && (conflict.IsTwoHanded || m_Left.IsTwoHanded))
{
Unequip(DressList.GetLayerFor(conflict));
}

Equip(m_Left, DressList.GetLayerFor(m_Left));
}
else
{
World.Player.SendMessage(MsgLevel.Force, LocString.MustDisarm);
}
}
else
{
Unequip(DressList.GetLayerFor(item));
m_Left = item;
}
}

public static bool Equip(Item item, Layer layer)
{
if (layer == Layer.Invalid || layer > Layer.LastUserValid || item == null || item.Layer == Layer.Invalid ||
item.Layer > Layer.LastUserValid)
return false;

if (item != null && World.Player != null && item.IsChildOf(World.Player.Backpack))
{
DragDropManager.DragDrop(item, World.Player, layer);
return true;
}

return false;
}

public static bool Unequip(Layer layer)
{
if (layer == Layer.Invalid || layer > Layer.LastUserValid)
return false;

Item item = World.Player.GetItemOnLayer(layer);
if (item != null)
{
Item pack = DressList.FindUndressBag(item);
if (pack != null)
{
DragDropManager.DragDrop(item, pack);
return true;
}
}

return false;
}
}
}
7 changes: 7 additions & 0 deletions Razor/Core/Main.cs
Expand Up @@ -4,6 +4,7 @@
using System.Collections;
using System.Windows.Forms;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -229,8 +230,14 @@ public static DateTime MistedDateTime
get { return DateTime.UtcNow.AddHours(Differential); }
}

public static CultureInfo Culture;

public static void Load()
{
Culture = new CultureInfo("en-EN", false);
Culture.NumberFormat.NumberDecimalSeparator = ".";
Culture.NumberFormat.NumberGroupSeparator = ",";

/* Load localization files */
string defLang = Config.GetAppSetting<string>("DefaultLanguage");
if (defLang == null)
Expand Down
14 changes: 14 additions & 0 deletions Razor/Core/Spells.cs
Expand Up @@ -187,13 +187,15 @@ protected override void OnTick()

private static Dictionary<string, Spell> m_SpellsByPower;
private static Dictionary<int, Spell> m_SpellsByID;
private static Dictionary<string, Spell> m_SpellsByName;
private static HotKeyCallbackState HotKeyCallback;

static Spell()
{
string filename = Path.Combine(Config.GetInstallDirectory(), "spells.def");
m_SpellsByPower = new Dictionary<string, Spell>(64 + 10 + 16);
m_SpellsByID = new Dictionary<int, Spell>(64 + 10 + 16);
m_SpellsByName = new Dictionary<string, Spell>(64 + 10 + 16);

if (!File.Exists(filename))
{
Expand Down Expand Up @@ -224,6 +226,12 @@ static Spell()

m_SpellsByID[s.GetID()] = s;

line = Language.GetString(s.Name);
if (string.IsNullOrEmpty(line))
line = split[3].Trim();
if (!string.IsNullOrEmpty(line))
m_SpellsByName[line.ToLower()] = s;

if (s.WordsOfPower != null && s.WordsOfPower.Trim().Length > 0)
m_SpellsByPower[s.WordsOfPower] = s;
}
Expand Down Expand Up @@ -467,6 +475,12 @@ public static Spell Get(int num)
return s;
}

public static Spell GetByName(string name)
{
m_SpellsByName.TryGetValue(name.ToLower(), out Spell s);
return s;
}

public static Spell Get(int circle, int num)
{
return Get(Spell.ToID(circle, num));
Expand Down
5 changes: 5 additions & 0 deletions Razor/Core/Targeting.cs
Expand Up @@ -70,6 +70,11 @@ public static bool HasTarget
get { return m_HasTarget; }
}

public static TargetInfo LastTargetInfo
{
get { return m_LastTarget; }
}

public static bool FromGrabHotKey
{
get { return m_FromGrabHotKey; }
Expand Down
45 changes: 30 additions & 15 deletions Razor/Core/Utility.cs
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Text;
using System.Collections;
using System.Globalization;

namespace Assistant
{
Expand Down Expand Up @@ -335,32 +336,46 @@ public static int ToInt32(string str, int def)
if (str == null)
return def;

try
{
if (str.Length > 2 && str.Substring(0, 2).ToLower() == "0x")
return Convert.ToInt32(str.Substring(2), 16);
else
return Convert.ToInt32(str);
}
catch
{
if (str == null)
return def;

int val;
if (str.StartsWith("0x"))
{
if (int.TryParse(str.Substring(2), NumberStyles.HexNumber, Engine.Culture, out val))
return val;
}
else if (int.TryParse(str, out val))
return val;

return def;
}

public static double ToDouble(string str, double def)
public static uint ToUInt32(string str, uint def)
{
if (str == null)
return def;

try
uint val;
if (str.StartsWith("0x"))
{
return Convert.ToDouble(str);
if (uint.TryParse(str.Substring(2), NumberStyles.HexNumber, Engine.Culture, out val))
return val;
}
catch
{
else if (uint.TryParse(str, out val))
return val;

return def;
}

public static double ToDouble(string str, double def)
{
if (str == null)
return def;
}

if (double.TryParse(str, out double d))
return d;
return def;
}
}
}

0 comments on commit 9b9ee6a

Please sign in to comment.