Stránka 1 z 1

Alchemy

Napsal: 23.08.2010 12:00:34
od Mole Two
Nekontroluje zda máte prázdný flašky či jestli zaměříte nekompatibilní flašky/regy/kegy

Kód: Vybrat vše

using System;
using System.Collections.Generic;
using System.Text;
using Phoenix;
using Phoenix.WorldData;

namespace Phoenix.Scripts {
    public class Alchemy {
        private const string SuccessMessage = "You pour the completed potion into a bottle";
        private const string FailureMessage = "You toss the failed mixture from the mortar";

        [Executable( "alchemy" )]
        public void Start() {
            ItemType reagent = ItemType.FromTarget( "reagent" );
            ItemType potion = ItemType.FromTarget( "potion" );

            UO.Print( "Select 'keg':" );
            UOItem keg = World.GetItem( UIManager.TargetObject() );
            if ( !keg.Exist )
                throw new ScriptErrorException( "Item 'keg' not found" );

            int success = 0, failure = 0;

            while ( reagent.Count > 10 ) {
                Journal.Clear();

                reagent.Use();
                Journal.WaitForText( true, 40000, SuccessMessage, FailureMessage );
                UO.Wait( 500 );

                if ( Journal.Contains( SuccessMessage ) )
                    success++;
                else if ( Journal.Contains( FailureMessage ) )
                    failure++;

                UO.PrintInformation( "Success: {0} Failure: {1} => {2}%", success, failure, success + failure > 0 ? ( success * 100 / ( success + failure ) ) : 0 );

                while ( potion.Count > potion.InitialCount - 1 ) {
                    potion.WaitTarget();
                    keg.Use();
                    Journal.WaitForText( true, 20000, "Prelil jsi lahvicku do kade" );
                    UO.Wait( 500 );
                }
            }

            UO.PrintInformation( "Script finished" );
        }

        #region Nested type: ItemType

        private class ItemType {
            public ItemType( string name, Graphic graphic, UOColor color ) {
                Graphic = graphic;
                Color = color;
                InitialCount = Count;
            }

            public void Use() {
                UOItem item = World.Player.Backpack.AllItems.FindType( Graphic, Color );
                if ( !item.Exist )
                    throw new ScriptErrorException( "Item '" + Name + "' not found" );

                item.Use();
            }

            public void WaitTarget() {
                UOItem item = World.Player.Backpack.AllItems.FindType( Graphic, Color );
                if ( !item.Exist )
                    throw new ScriptErrorException( "Item '" + Name + "' not found" );

                item.WaitTarget();
            }

            #region Public properties

            public string Name {
                get;
                private set;
            }

            public Graphic Graphic {
                get;
                private set;
            }

            public UOColor Color {
                get;
                private set;
            }

            public int InitialCount {
                get;
                private set;
            }

            public int Count {
                get {
                    return World.Player.Backpack.AllItems.Count( Graphic, Color );
                }
            }

            #endregion

            #region Static members

            public static ItemType FromTarget( string name ) {
                UO.Print( "Select '" + name + "':" );
                UOItem item = World.GetItem( UIManager.TargetObject() );
                if ( !item.Exist )
                    throw new ScriptErrorException( "Item '" + name + "' not found" );

                return new ItemType( name, item.Graphic, item.Color );
            }

            #endregion
        }

        #endregion
    }
}