What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Beta Chicken Plugin

Nexic

Member
Joined
Aug 30, 2013
Messages
67
Reaction score
1
Updated chicken logic to work on beta- I do not run ES characters; therefore, I will not update for es chicken.

Chicken.cs

Code:
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Markup;
using log4net;
using System;
using Loki.Bot;
using Loki.Game;
using Loki.Game.GameData;
using Loki.Game.Objects;
using Loki.Game.Objects.Items;
using Loki.Utilities;

namespace Chicken
{
    internal class Chicken : IPlugin
    {
        private static readonly ILog Log = Logger.GetLoggerInstanceForType();

        #region Implementation of IPlugin

        /// <summary> The name of the plugin. </summary>
        public string Name
        {
            get { return "Chicken"; }
        }

        /// <summary> The description of the plugin. </summary>
        public string Description
        {
            get { return "A plugin that provides Chicken use."; }
        }

        /// <summary>The author of the plugin.</summary>
        public string Author
        {
            get { return "Bossland GmbH"; }
        }

        /// <summary>The version of the plugin.</summary>
        public Version Version
        {
            get { return new Version(0, 0, 1, 2); }
        }

        /// <summary>Initializes this plugin.</summary>
        public void Initialize()
        {
            Log.DebugFormat("[Chicken] Initialize");
        }

        /// <summary> The plugin start callback. Do any initialization here. </summary>
        public void Start()
        {
            Log.DebugFormat("[Chicken] Start");
        }

        

        /// <summary> The plugin tick callback. Do any update logic here. </summary>
        public void Tick()
        {
            if (!LokiPoe.IsInGame || LokiPoe.Me.IsInTown || LokiPoe.Me.IsDead)
                return;

            // Life
            if (LokiPoe.Me.HealthPercent < ChickenSettings.Instance.HpChickenPercentTrigger)
            {
                var res = LokiPoe.EscapeState.LogoutToTitleScreen();
                Log.DebugFormat("LogoutToTitleScreen returned {0}.", res);

            }

           
        }

        /// <summary> The plugin stop callback. Do any pre-dispose cleanup here. </summary>
        public void Stop()
        {
            Log.DebugFormat("[Chicken] Stop");
        }

        public JsonSettings Settings
        {
            get { return ChickenSettings.Instance; }
        }

        /// <summary> The routine's settings control. This will be added to the Exilebuddy Settings tab.</summary>
        public UserControl Control
        {
            get
            {
                using (var fs = new FileStream(@"Plugins\Chicken\SettingsGui.xaml", FileMode.Open))
                {
                    var root = (UserControl)XamlReader.Load(fs);

                    // Your settings binding here.

                    if (
                        !Wpf.SetupTextBoxBinding(root, "HpChickenPercentTriggerTextBox", "HpChickenPercentTrigger",
                            BindingMode.TwoWay, ChickenSettings.Instance))
                    {
                        Log.DebugFormat(
                            "[SettingsControl] SetupTextBoxBinding failed for 'HpChickenPercentTriggerTextBox'.");
                        throw new Exception("The SettingsControl could not be created.");
                    }

                    return root;
                }
            }
        }

        /// <summary> The plugin is being enabled.</summary>
        public void OnEnable()
        {
            Log.DebugFormat("[Chicken] OnEnable");
        }

        /// <summary> The plugin is being disabled.</summary>
        public void OnDisable()
        {
            Log.DebugFormat("[Chicken] OnDisable");
        }

        #endregion

        #region Implementation of IDisposable

        /// <summary> </summary>
        public void Dispose()
        {
        }

        #endregion

        #region Override of Object

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return Name + ": " + Description;
        }

        #endregion

    }
}

ChickenSettings.cs
Code:
using System.ComponentModel;
using Loki.Bot.Settings;
using Loki.Utilities;

namespace Chicken
{
    /// <summary>Settings for the AutoFlask. </summary>
    public class ChickenSettings : JsonSettings
    {
        private static ChickenSettings _instance;

        /// <summary>The current instance for this class. </summary>
        public static ChickenSettings Instance
        {
            get { return _instance ?? (_instance = new ChickenSettings()); }
        }

        /// <summary>The default ctor. Will use the settings path "AutoFlask".</summary>
        public ChickenSettings()
            : base(GetSettingsFilePath(Configuration.Instance.Name, string.Format("{0}.json", "Chicken")))
        {
            // Setup defaults here if needed for properties that don't support DefaultValue.
        }

        private int _HpChickenPercentTrigger;




        /// <summary>The % to trigger hp flasks.</summary>
        [DefaultValue(50)]
        public int HpChickenPercentTrigger
        {
            get { return _HpChickenPercentTrigger; }
            set
            {
                if (value.Equals(_HpChickenPercentTrigger))
                {
                    return;
                }
                _HpChickenPercentTrigger = value;
                NotifyPropertyChanged(() => HpChickenPercentTrigger);
            }
        }

        
        
    }
}

SettingsGui
Code:
<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="440" d:DesignWidth="627">

    <Grid x:Name="Root">
        <Grid.Resources>
            <Style TargetType="Label" x:Key="TitleLabel">
                <Setter Property="Margin" Value="15,0,0,0"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="FontWeight" Value="Bold"/>
                <Setter Property="Foreground" Value="White"/>
            </Style>
            <Style TargetType="Label" x:Key="Label">
                <Setter Property="Margin" Value="15,0,0,0"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Foreground" Value="White"/>
            </Style>
            <Style TargetType="TextBox" x:Key="TextBox">
                <Setter Property="Margin" Value="3"/>
                <Setter Property="Foreground" Value="White"/>
                <Setter Property="Background" Value="#333333"/>
                <Setter Property="BorderBrush" Value="black"/>
            </Style>
        </Grid.Resources>

        <ScrollViewer VerticalScrollBarVisibility="Auto">
            <StackPanel>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" MinHeight="30"/>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" MinWidth="50" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" MinWidth="50" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" MinWidth="50" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>


                    <!-- life flask support -->
                    <Label Grid.Row="0" Grid.Column="0" Style="{StaticResource TitleLabel}" Content="Chicken"/>

                    <Label Grid.Row="1" Grid.Column="0" Style="{StaticResource Label}" Content="Trigger (%): " ToolTipService.ToolTip="The % life your character has to be at to trigger Chicken."/>
                    <TextBox Grid.Row="1" Grid.Column="1" x:Name="HpChickenPercentTriggerTextBox" Style="{StaticResource TextBox}"/>

                </Grid>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</UserControl>
 
Last edited:
public void Tick()
{
if (!LokiPoe.IsInGame || LokiPoe.Me.IsInTown || LokiPoe.Me.IsDead)
return;

// Life
if (LokiPoe.Me.HealthPercent < ChickenSettings.Instance.HpChickenPercentTrigger)
{
//need line of code that logs out- I assume the bot automatically detects that it has been logged out and will automatically log back in; however if not wait 5 seconds and restart bot and it should work
}


}
 
The API for logging out now is in EscapeState:

Code:
var res = LokiPoe.EscapeState.LogoutToTitleScreen();
Log.DebugFormat("LogoutToTitleScreen returned {0}.", res);

Code:
var res = LokiPoe.EscapeState.LogoutToCharacterSelection();
Log.DebugFormat("LogoutToCharacterSelection returned {0}.", res);

Code:
var res = LokiPoe.EscapeState.ExitGame();
Log.DebugFormat("ExitGame returned {0}.", res);

That's it. :)

Only other things to mention is, ProcessHookManager has to be enabled (responsibility of the bot implementation being used), and LokiPoe.IsInGame needs to be true, as you can't activate the escape menu when you're not in game. The API will return errors specifying why it didn't execute in both cases though. The logout method is though input emulation now, but it's still fast and reliable, as can be seen in the current bot when back to back exceptions are thrown and it logs out to character selection.

As for auto-login, that has to be configured in the Login tab of the bot. As long as the bot isn't stopped, it will auto-login according to settings. If the bot is stopped, you'd have to use a plugin that hooks the GUI to restart the bot (ExamplePlugin shows this).
 
Thanks works like a charm. Should I post the chicken plugin or will you guys be eventually installing a built in one?
 
Thanks works like a charm. Should I post the chicken plugin or will you guys be eventually installing a built in one?

Please feel free to share your work and let people use it and give feedback. :)

That's the driving force behind the idea of our project's approach right now! It's one less thing I'd have to spend time on making an example for, which right now, time is in very limited supply.
 
Back
Top