Пример #1
0
        /// <summary>
        /// attempt to start the requested pony, checking that it is one from
        /// the configuration system.
        /// </summary>
        public static void StartPony(string name)
        {
            PonyConfig pconfig;

            // the pony you seek, i may have heard of her long ago...
            pconfig = PonyConfig.List.Find(delegate(PonyConfig config){
                return(config.Name == name);
            });

            if (pconfig == null)
            {
                // ... but it was only in legend.
                Trace.WriteLine(String.Format(
                                    "== unable to start {0}",
                                    name
                                    ));

                return;
            }
            else
            {
                // ... yeah she lives next door.
                Pony pone = new Pony(pconfig);
                Main.PonyList.Add(pone);
            }
        }
Пример #2
0
        public PonyWindow(Pony Pony)
        {
            InitializeComponent();

            // set up the window.
            this.Left    = 0;
            this.Top     = 0;
            this.Width   = 1;
            this.Height  = 1;
            this.Title   = "Pony";
            this.Topmost = true;
            this.Hide();

            // reference to the pony.
            this.Pony = Pony;

            // tray icon.
            this.Tray = new PonyIcon(this.Pony);
            this.Tray.Show();

            // set a mouse cursor for petting lol.
            this.Cursor = System.Windows.Input.Cursors.Hand;

            // enable moving the window by dragging anywhere.
            // this.MouseLeftButtonDown += new MouseButtonEventHandler(OnWindowDragAction);
        }
Пример #3
0
        public PonyWindow(Pony Pony)
        {
            InitializeComponent();

            // set up the window.
            this.Left = 0;
            this.Top = 0;
            this.Width = 1;
            this.Height = 1;
            this.Title = "Pony";
            this.Topmost = true;
            this.Hide();

            // reference to the pony.
            this.Pony = Pony;

            // tray icon.
            this.Tray = new PonyIcon(this.Pony);
            this.Tray.Show();

            // set a mouse cursor for petting lol.
            this.Cursor = System.Windows.Input.Cursors.Hand;

            // enable moving the window by dragging anywhere.
            // this.MouseLeftButtonDown += new MouseButtonEventHandler(OnWindowDragAction);
        }
Пример #4
0
        public PonyIcon(Pony pone)
        {
            string path;

            this.Pony = pone;

            // check that the icon we want exists.
            path = PonyImage.SelectImagePath(pone.Name, "MarkSmall.png").LocalPath;
            if (!File.Exists(path))
            {
                return;
            }

            // create the tray icon.
            this.Icon = new NotifyIcon();

            // load the image and convert it to an icon resource.
            this.Icon.Icon = System.Drawing.Icon.FromHandle((new Bitmap(path)).GetHicon());

            // connect some signals.
            this.Icon.MouseClick += this.OnMouseClick;

            this.Show();
            return;
        }
Пример #5
0
        /// <summary>
        /// releases the resources and references this window has.
        /// </summary>
        public void Free()
        {
            // dispose of tray icon.
            this.Tray.Hide();
            this.Tray.Free();
            this.Tray = null;

            // release references.
            this.Pony = null;
        }
Пример #6
0
        public void Free()
        {
            if(this.Icon != null) {
                this.Hide();
                this.Icon.Dispose();
                this.Icon = null;
            }

            this.Pony = null;
        }
Пример #7
0
        public void Free()
        {
            if (this.Icon != null)
            {
                this.Hide();
                this.Icon.Dispose();
                this.Icon = null;
            }

            this.Pony = null;
        }
Пример #8
0
        /// <summary>
        /// stop a currently running pony.
        /// </summary>
        public static void StopPony(Pony pone)
        {
            Main.PonyList.Remove(pone);
            pone.Free();
            pone = null;


            if (Main.PonyList.Count == 0)
            {
                Application.Current.Shutdown();
            }
        }
Пример #9
0
        public PonyIcon(Pony pone)
        {
            string path;

            this.Pony = pone;

            // check that the icon we want exists.
            path = PonyImage.SelectImagePath(pone.Name,"MarkSmall.png").LocalPath;
            if(!File.Exists(path)) return;

            // create the tray icon.
            this.Icon = new NotifyIcon();

            // load the image and convert it to an icon resource.
            this.Icon.Icon = System.Drawing.Icon.FromHandle((new Bitmap(path)).GetHicon());

            // connect some signals.
            this.Icon.MouseClick += this.OnMouseClick;

            this.Show();
            return;
        }
Пример #10
0
        /// <summary>
        /// attempt to start the requested pony, checking that it is one from
        /// the configuration system.
        /// </summary>
        public static void StartPony(string name)
        {
            PonyConfig pconfig;

            // the pony you seek, i may have heard of her long ago...
            pconfig = PonyConfig.List.Find(delegate(PonyConfig config){
                return config.Name == name;
            });

            if(pconfig == null) {
                // ... but it was only in legend.
                Trace.WriteLine(String.Format(
                    "== unable to start {0}",
                    name
                ));

                return;
            } else {
                // ... yeah she lives next door.
                Pony pone = new Pony(pconfig);
                Main.PonyList.Add(pone);
            }
        }
Пример #11
0
        /// <summary>
        /// allow the pony's personality to choose her next action and
        /// direction from any of her available actions. she is a free pony
        /// and you should never tell her otherwise.
        ///
        /// eventually this will be tweakable via the this.pony file for each
        /// pony to make them all unique to their own respective personalities.
        /// </summary>
        private PonyState DecideByPonyality()
        {
            var  choice    = new PonyState();
            bool undecided = false;
            bool lazy      = false;

            // if the pony is too tired then she should go to sleep. if she can
            // sleep, that is.
            if (this.Energy <= 0)
            {
                if (this.CanDo(PonyAction.Sleep))
                {
                    choice.Direction = this.Direction;

                    // if she is doing something active, stop first instead of
                    // just falling asleep in mid sprint.
                    if (this.IsActive())
                    {
                        choice.Action = this.DecideFromPassiveActions().Action;
                    }
                    else
                    {
                        choice.Action = PonyAction.Sleep;
                        this.EnergyReset();
                    }

                    return(choice);
                }
                else
                {
                    // else just reset it.
                    this.EnergyReset();
                }
            }

            do
            {
                choice.Action    = this.ChooseAction();
                choice.Direction = this.ChooseDirection();
                undecided        = false;

                ///////////////////////////////////////////////////////////////
                // directional choices ////////////////////////////////////////

                // direction choices are up for grabs every time a pony thinks
                // she had decided what to do. if she elects to be indecisive
                // about her actions later then she will rethink her direction
                // as well.

                // does the pony want to change directions? pony does not like
                // to change direction too often while performing actions.
                if (choice.Direction != this.Direction && !this.RandomChance(this.Ponyality.Spazziness))
                {
                    // if pony is doing something active and will continue to
                    // do so then there is a higher chance she will not change
                    // directions.
                    if (this.IsActive() && Pony.IsActionActive(choice.Action))
                    {
                        choice.Direction = this.Direction;
                    }

                    // if pony is doing something active and she suddenly stops
                    // then this too will have a greater chance of not changing
                    // directions.
                    if (this.IsActive() && !Pony.IsActionActive(choice.Action))
                    {
                        choice.Direction = this.Direction;
                    }
                }

                ///////////////////////////////////////////////////////////////
                // action choices /////////////////////////////////////////////

                // apply personality quirks to the pony's decision making
                // system to allow for subdued but unique behaviour.

                // don't ever do these.
                if (choice.Action == PonyAction.Sleep || choice.Action == PonyAction.Teleport2)
                {
                    undecided = true;
                    continue;
                }

                // if she has decided she is being lazy...
                if (lazy)
                {
                    return(this.DecideFromPassiveActions());
                }

                // pony generally like be lazy. if she is doing somethng lazy
                // there is a greater chance she will not want to do something
                // active.
                if (!this.IsActive() && Pony.IsActionActive(choice.Action))
                {
                    if (this.RandomChance(this.Ponyality.Laziness))
                    {
                        undecided = lazy = true;
                        continue;
                    }
                }

                // pony do not like to flaunt their personality quirks, if we
                // selected one of the personality actions then there is a high
                // chance she should be undecided. this should make the quirky
                // actions more special when they do actually happen.
                switch (choice.Action)
                {
                case PonyAction.Action1:
                    undecided = !this.RandomChance(this.Ponyality.Quirkiness);
                    continue;

                case PonyAction.Action2:
                    undecided = !this.RandomChance(this.Ponyality.Quirkiness);
                    continue;

                case PonyAction.Passive1:
                    undecided = !this.RandomChance(this.Ponyality.Quirkiness);
                    continue;
                }

                // pony that can teleport generally do not teleport that often. i assume
                // the action takes mana or something, lol.
                if (choice.Action == PonyAction.Teleport)
                {
                    if (this.RandomChance(30))
                    {
                        undecided = true;
                        continue;
                    }
                }

                // pony may tire easy. if she is doing something active and has chosen to
                // continue to be active, there is a chance she is too tired and will be
                // lazy instead.
                if (this.IsActive() && Pony.IsActionActive(choice.Action))
                {
                    if (!this.RandomChance(this.Ponyality.Stamina))
                    {
                        undecided = lazy = true;
                        continue;
                    }
                }
            } while(undecided);

            return(choice);
        }
Пример #12
0
        /////////////////////////////////////////////////////////////////////////////
        // utility methods //////////////////////////////////////////////////////////

        /// <summary>
        /// is the action she is currently doing considered an active action?
        /// </summary>
        /// <returns></returns>
        public bool IsActive()
        {
            return(Pony.IsActionActive(this.Action));
        }
Пример #13
0
        /// <summary>
        /// stop a currently running pony.
        /// </summary>
        public static void StopPony(Pony pone)
        {
            Main.PonyList.Remove(pone);
            pone.Free();
            pone = null;

            if(Main.PonyList.Count == 0) {
                Application.Current.Shutdown();
            }
        }
Пример #14
0
        /// <summary>
        /// releases the resources and references this window has.
        /// </summary>
        public void Free()
        {
            // dispose of tray icon.
            this.Tray.Hide();
            this.Tray.Free();
            this.Tray = null;

            // release references.
            this.Pony = null;
        }