Skip to content

Commit

Permalink
added menu to stacking script
Browse files Browse the repository at this point in the history
  • Loading branch information
Rulfy committed Nov 17, 2015
1 parent 17a4189 commit 285b3b0
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 89 deletions.
2 changes: 1 addition & 1 deletion JungleStack/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
</configuration>
36 changes: 36 additions & 0 deletions JungleStack/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("JungleStack")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JungleStack")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6c3a5fc9-57b3-4402-b672-7e76e534e7e2")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
6 changes: 5 additions & 1 deletion JungleStack/JungleStack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>JungleStack</RootNamespace>
<AssemblyName>JungleStack</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<PreBuildEvent />
Expand Down Expand Up @@ -42,6 +42,9 @@
<Reference Include="Ensage">
<HintPath>C:\EnsageSharp\System\Ensage.dll</HintPath>
</Reference>
<Reference Include="Ensage.Common">
<HintPath>C:\EnsageSharp\System\Ensage.Common.dll</HintPath>
</Reference>
<Reference Include="SharpDX, Version=2.6.3.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\EnsageSharp\System\SharpDX.dll</HintPath>
Expand All @@ -57,6 +60,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Program.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
193 changes: 110 additions & 83 deletions JungleStack/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System;
using System.Linq;
using System.Windows.Forms;
using Ensage;
using Ensage.Common.Menu;
using SharpDX;
using SharpDX.Direct3D9;

namespace JungleStack
{
class Program
{
const int WM_KEYUP = 0x0101;
const int WM_KEYDOWN = 0x0105;
private static readonly Menu Menu = new Menu("JungleStack", "jungleStack", true);

private static readonly Vector3[] StackRouteRadiant =
{
Expand All @@ -33,20 +32,35 @@ class Program
private const int AttackTimeDire = 52;


private static Unit _pullCreep;
private static Font _text;
private static int _orderState = -1;
private static int _attackTime;
private static int _startTime;
private static Vector3[] _route;
private static bool _noCreep;
private static readonly Timer Timer = new Timer();
private static Unit pullCreep;
private static Font text;
private static int orderState = -1;
private static int attackTime;
private static int startTime;
private static Vector3[] route;
private static bool noCreep;
private static readonly System.Windows.Forms.Timer Timer = new System.Windows.Forms.Timer();


static void Main(string[] args)
{
var hotkey = new MenuItem("hotkey", "Toggle hotkey").SetValue(
new KeyBind('O', KeyBindType.Toggle));
hotkey.ValueChanged += Hotkey_ValueChanged;
Menu.AddItem(hotkey);

Menu.AddItem(new MenuItem("positionX", "X-Position").SetValue(
new Slider(5, 0, Drawing.Width)));

Menu.AddItem(new MenuItem("positionY", "Y-Position").SetValue(
new Slider(50, 0, Drawing.Height)));

Menu.AddToMainMenu();

ChangeToggleValue(false);

Timer.Tick += Timer_Tick;
_text = new Font(
text = new Font(
Drawing.Direct3DDevice9,
new FontDescription
{
Expand All @@ -59,19 +73,64 @@ static void Main(string[] args)
Drawing.OnPreReset += Drawing_OnPreReset;
Drawing.OnPostReset += Drawing_OnPostReset;
Drawing.OnEndScene += Drawing_OnEndScene;
Game.OnWndProc += Game_OnGameWndProc;
Game.OnUpdate += Game_OnGameUpdate;
AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
}
// ReSharper disable once InconsistentNaming
private static void Hotkey_ValueChanged(object sender, OnValueChangeEventArgs e)
{
var newVal = e.GetNewValue<KeyBind>().Active;
if (newVal != e.GetOldValue<KeyBind>().Active)
{
// Deactivate script
if (!newVal)
{
pullCreep = null;
}
else
{
// Activate script
var player = ObjectMgr.LocalPlayer;
if (player == null || player.Team == Team.Observer)
return;
switch (player.Team)
{
case Team.Radiant:
startTime = StartTimeRadiant;
attackTime = AttackTimeRadiant;
route = StackRouteRadiant;
break;
case Team.Dire:
startTime = StartTimeDire;
attackTime = AttackTimeDire;
route = StackRouteDire;
break;
default:
e.Process = false;
return;
}
var units = player.Selection.ToList();
pullCreep = (Unit)units.FirstOrDefault(unit => unit is Unit && ((Unit)unit).IsControllable && ((Unit)unit).IsRanged);
if (pullCreep != null)
{
pullCreep.Move(route.Last());
orderState = -1;
}
else e.Process = false;
}
}
}

// ReSharper disable once InconsistentNaming
static void Timer_Tick(object sender, EventArgs e)
{
Timer.Enabled = false;
}

// ReSharper disable once InconsistentNaming
static void CurrentDomain_DomainUnload(object sender, EventArgs e)
{
_text.Dispose();
text.Dispose();
}

static void Drawing_OnEndScene(EventArgs args)
Expand All @@ -83,134 +142,102 @@ static void Drawing_OnEndScene(EventArgs args)
if( player == null || player.Team == Team.Observer)
return;

if (_pullCreep == null)
int x = Menu.Item("positionX").GetValue<Slider>().Value, y = Menu.Item("positionY").GetValue<Slider>().Value;
if (pullCreep == null)
{
_text.DrawText(null, "StackScript: Select a ranged creep and press \"O\".", 5, 50, Color.White);
var key = (char)Menu.Item("hotkey").GetValue<KeyBind>().Key;
text.DrawText(null, "StackScript: Select a ranged creep and press \""+key+"\".", x, y, Color.White);
}
else
{
switch (_orderState)
switch (orderState)
{
case -1:
_text.DrawText(null, "StackScript: moving to wait location", 5, 50, Color.White);
text.DrawText(null, "StackScript: moving to wait location", x, y, Color.White);
break;
case 0:
_text.DrawText(null,
_noCreep
text.DrawText(null,
noCreep
? "StackScript: found no creep for pulling."
: "StackScript: waiting for next pull.", 5, 50, Color.White);
: "StackScript: waiting for next pull.", x, y, Color.White);
break;
case 1:
_text.DrawText(null, "StackScript: waiting for attack order.", 5, 50, Color.White);
text.DrawText(null, "StackScript: waiting for attack order.", x, y, Color.White);
break;
case 2:
_text.DrawText(null, "StackScript: pulling.", 5, 50, Color.White);
text.DrawText(null, "StackScript: pulling.", x, y, Color.White);
break;
}
}
}

static void Drawing_OnPostReset(EventArgs args)
{
_text.OnResetDevice();
text.OnResetDevice();
}

static void Drawing_OnPreReset(EventArgs args)
{
_text.OnLostDevice();
text.OnLostDevice();
}

static void Game_OnGameWndProc(WndEventArgs args)
static void ChangeToggleValue(bool newValue)
{
if (args.Msg != WM_KEYUP || args.WParam != 'O' || Game.IsChatOpen)
return;

// Deactivate script
if (_pullCreep != null)
{
Console.WriteLine("Deactivated");
_pullCreep = null;
return;
}

// Activate script
var player = ObjectMgr.LocalPlayer;
if (player == null || player.Team == Team.Observer)
return;
switch (player.Team)
{
case Team.Radiant:
_startTime = StartTimeRadiant;
_attackTime = AttackTimeRadiant;
_route = StackRouteRadiant;
break;
case Team.Dire:
_startTime = StartTimeDire;
_attackTime = AttackTimeDire;
_route = StackRouteDire;
break;
default:
return;
}
var units = player.Selection.ToList();
_pullCreep = (Unit)units.FirstOrDefault(unit => unit is Unit && ((Unit)unit).IsControllable && ((Unit)unit).IsRanged);
if (_pullCreep != null)
{
_pullCreep.Move(_route.Last());
_orderState = -1;
}
var oldVal = Menu.Item("hotkey").GetValue<KeyBind>();
Menu.Item("hotkey").SetValue(new KeyBind(oldVal.Key, KeyBindType.Toggle, newValue));
}

static void Game_OnGameUpdate(EventArgs args)
{
if (Timer.Enabled || !Game.IsInGame || Game.IsPaused || _pullCreep == null)
if (Timer.Enabled || !Game.IsInGame || Game.IsPaused || pullCreep == null)
return;

if (!_pullCreep.IsValid || !_pullCreep.IsAlive)
if (!pullCreep.IsValid || !pullCreep.IsAlive)
{
_pullCreep = null;
ChangeToggleValue(false);
pullCreep = null;
return;
}

var seconds = ((int) Game.GameTime) % 60;
switch (_orderState)
switch (orderState)
{
case -1:
if (GetDistance2D(_pullCreep.Position, _route.Last()) < 3)
_orderState = 0;
if (GetDistance2D(pullCreep.Position, route.Last()) < 3)
orderState = 0;
break;
case 0:
if (seconds >= _startTime)
if (seconds >= startTime)
{
Console.WriteLine("Move to route 0");
_pullCreep.Move(_route[0]);
_orderState = 1;
pullCreep.Move(route[0]);
orderState = 1;
}
break;
case 1:
if (seconds >= _attackTime)
if (seconds >= attackTime)
{
var attackme = GetNearestCreepToPull();
_noCreep = attackme == null;
if (_noCreep)
noCreep = attackme == null;
if (noCreep)
{
_pullCreep.Move(_route.Last());
_orderState = 0;
pullCreep.Move(route.Last());
orderState = 0;

Timer.Interval = 10*1000; // wait until next minute starts
Timer.Start();
return;
}
_pullCreep.Attack(attackme);
_orderState = 2;
pullCreep.Attack(attackme);
orderState = 2;
Timer.Interval = 1650; // Wait until attack starts
Timer.Start();
}
break;
case 2:
_pullCreep.Move(_route[1]);
_pullCreep.Move(_route[2],true);
_orderState = 0;
pullCreep.Move(route[1]);
pullCreep.Move(route[2],true);
orderState = 0;

Timer.Interval = 10*1000; // wait until next minute starts
Timer.Start();
Expand All @@ -228,7 +255,7 @@ private static Unit GetNearestCreepToPull()
var bestDistance = float.MaxValue;
foreach (var creep in creeps)
{
var distance = GetDistance2DFast(_pullCreep, creep);
var distance = GetDistance2DFast(pullCreep, creep);
if (bestCreep == null || distance < bestDistance)
{
bestDistance = distance;
Expand Down
5 changes: 1 addition & 4 deletions Snatcher/Snatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@
<HintPath>C:\EnsageSharp\System\Ensage.Common.dll</HintPath>
</Reference>
<Reference Include="SharpDX">
<HintPath>C:\EnsageSharp\System\SharpDX.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Direct3D9">
<HintPath>C:\EnsageSharp\System\SharpDX.Direct3D9.dll</HintPath>
<HintPath>..\..\..\..\..\..\EnsageSharp\System\SharpDX.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down

0 comments on commit 285b3b0

Please sign in to comment.