public bool DoStep(NetworkClient networkClient, GameClient client)
        {
            if (IsReadyForAction)
            {
                _gameItemsGroups = Instance.GameItemsGroups;

                //Current location must be quction, check it
                string locationIdent = Helper.GetCurrentLocationIdent(client);
                if (Locations.Auctions.Contains(locationIdent))
                {
                    //Sell items from auc
                    DoSellingItemsFromAuc(networkClient, client);

                    //Sell items from inventory
                    DoSellingItemsFromInv(networkClient, client);
                }

                //Clear auction items cache
                _auctionItems.Clear();

                _prewSellingTime = Environment.TickCount;
                return true;
            }

            return false;
        }
Esempio n. 2
0
        public static ShopItem ParseShopItem(XmlNode item, GameItemsGroupList gameItemsGroups)
        {
            //If it`s valid node
            if (item.Attributes != null)
            {
                XmlAttribute name = item.Attributes["name"];
                XmlAttribute txt = item.Attributes["txt"];
                XmlAttribute type = item.Attributes["type"];
                XmlAttribute lvl = item.Attributes["lvl"];
                XmlAttribute owner = item.Attributes["owner"];
                if (name != null && txt != null && owner != null)
                {
                    //Get item data
                    string sTxt = txt.InnerText;
                    string subGroupId = name.InnerText;
                    string subGroupType = type.InnerText.Replace(".", "");
                    string sLvl = lvl != null ? lvl.InnerText : "";
                    string groupId = gameItemsGroups.SubGroupToGroupId(subGroupId, subGroupType);
                    string sOwner = owner.InnerText;

                    //Get parent item
                    GameItem gameItem = gameItemsGroups.GetItem(groupId, subGroupId,
                        subGroupType, sTxt, sLvl);

                    //Process game item
                    if (gameItem != null)
                    {
                        XmlAttribute id = item.Attributes["id"];
                        XmlAttribute count = item.Attributes["count"];
                        XmlAttribute quality = item.Attributes["quality"];
                        XmlAttribute maxQuality = item.Attributes["maxquality"];
                        XmlAttribute cost = item.Attributes["cost"];

                        //Create shop item
                        if (id != null && cost != null)
                        {
                            string sId = id.InnerText;
                            float fCost = float.Parse(cost.InnerText);
                            bool isSingle = count == null;
                            int iCount = !isSingle
                                ? int.Parse(count.InnerText)
                                : 1;
                            float fQuality = quality != null
                                ? float.Parse(quality.InnerText)
                                : 0f;
                            float fMaxQuality = maxQuality != null
                                ? float.Parse(maxQuality.InnerText)
                                : 0f;

                            return new ShopItem(gameItem, sId, iCount, fQuality, fMaxQuality,
                                                isSingle, fCost, sOwner);
                        }
                    }
                }
            }
            return null;
        }
Esempio n. 3
0
        private void InitializeEnvironment()
        {
            //Init application settings
            AppSettings.FileName = "TimeZero.Auction.Bot.cfg";

            //Get the game folder path
            string mainSwfFile = Path.Combine(AppSettings.Instance["GameFolder"] ?? "", "tz.swf");

            //Is it first start of the application?
            if (!File.Exists(mainSwfFile))
            {
                //Hide the loading form
                HideLoadingForm();

                MessageBox.Show(@"Game folder is not configured.
            Possible this is the first launch of the application, so you should define the game folder first.
            Some of the game resources will be used to make authorization on a game server.
            Privacy all of your personal data is guaranteed!",
                                "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                //Show application settings window
                if (!ChangeSettings(true))
                {
                    //If the user presses cancel button, terminate the application
                    MessageBox.Show(@"To continue you should define the game folder.
            Application terminated.",
                                    "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Process.GetCurrentProcess().Kill();
                    return;
                }

                //Get the game folder path
                mainSwfFile = Path.Combine(AppSettings.Instance["GameFolder"] ?? "", "tz.swf");

                //Show the loading form
                ShowLoadingForm();
            }

            //Prepare flash player
            flashPlayer.Base = mainSwfFile;
            flashPlayer.Movie = mainSwfFile;
            flashPlayer.OnReadyStateChange += player_OnReadyStateChange;

            //Init game client
            string password = AppSettings.Instance["Password"];
            _gameClient.Init(AppSettings.Instance["Login"],
                             Helper.DecryptStringByHardwareID(password),
                             AppSettings.Instance["ClientVersion"],
                             AppSettings.Instance["ClientVersion2"],
                             flashPlayer);

            //Init network client
            _networkClient.Init(AppSettings.Instance["Server"],
                                AppSettings.Instance.GetInt("Port"),
                                AppSettings.Instance.GetInt("Port"));
            _networkClient.OnDataReceived += DataReceived;
            _networkClient.OnDataSended += DataSended;
            _networkClient.OnGeneralLogMessage += GeneralLogMessage;
            _networkClient.OnInstantMessage += InstantMessage;
            _networkClient.OnChatMessage += ChatMessage;
            _networkClient.OnActionLogMessage += ActionLogMessage;
            _networkClient.OnNetworkActivityOut += NetworkActivityOut;
            _networkClient.OnNetworkActivityIn += NetworkActivityIn;
            _networkClient.OnConnected += Connected;
            _networkClient.OnDisconnected += Disconnected;
            _networkClient.OnActionStepStarted += OnActionStepStarted;
            _networkClient.OnActionStepCompleted += OnActionStepCompleted;

            _networkClient.OutInstantMessages = AppSettings.Instance.GetBool("OutInstantMessages");
            _networkClient.OutChatMessages = AppSettings.Instance.GetBool("OutChatMessages");
            _networkClient.OutGeneralLogs = AppSettings.Instance.GetBool("OutGeneralLogs");
            _networkClient.OutDetailedLogs = AppSettings.Instance.GetBool("OutDetailedLogs");
            _networkClient.OutActionsLogs = AppSettings.Instance.GetBool("OutActionsLogs");

            //Init game items groups
            try
            {
                if (File.Exists("gameItemsGroups.dat"))
                {
                    byte[] data = File.ReadAllBytes("gameItemsGroups.dat");
                    Instance.GameItemsGroups = new Serializer<GameItemsGroupList>().Deserialize(data);
                    _gameItemsGroups = Instance.GameItemsGroups;
                }
            }
            catch { }

            if (_gameItemsGroups.Empty)
            {
                _gameItemsGroups.InitializeDefaults();
            }
            RefreshGameItemsTreeView();
        }
        public bool DoStep(NetworkClient networkClient, GameClient client)
        {
            if (IsReadyForAction)
            {
                _gameItemsGroups = Instance.GameItemsGroups;
                DateTime startShoppingTime = DateTime.Now;

                //Refresh list of items owners
                _listOfItemsOwners.Refresh();

                //Refresh list of purchased items with their owners
                _listOfPurchasedItemsWithOwners.Refresh();

                //Check full update requirement
                bool fullUpdate = _prewFullUpdateTime == 0 ||
                     Environment.TickCount - _prewFullUpdateTime >= SHOPPING_FULL_UPDATE_MIN * 60000;

                //Get location ident
                string locationIdent = Helper.GetCurrentLocationIdent(client);

                //Check on shop
                bool isShop = Locations.Shops.Contains(locationIdent);

                //Check on auction
                bool isAuction = Locations.Auctions.Contains(locationIdent);

                //Out action message
                string message = string.Format(@"started, {0}
            • in a shop: {1}
            • is it an auction: {2}
            • full update: {3}
            ", DateTime.Now,
               isShop ? "YES" : "NO",
               isAuction ? "YES" : "NO",
               fullUpdate ? "YES" : "NO").TrimEnd();
                networkClient.OutActionLogMessage(this, message);

                //Current location must be a shop, check it
                if (isShop)
                {
                    //Make a little shopping :)
                    DoShopping(networkClient, client, locationIdent, isAuction, fullUpdate);
                }
                else
                {
                    //Out action message
                    message = "You are not inside a shop. Shopping unavailable.";
                    networkClient.OutActionLogMessage(this, message);
                }

                //Store last time of full update
                _prewShoppingnTime = Environment.TickCount;
                if (fullUpdate)
                {
                    _prewFullUpdateTime = _prewShoppingnTime;
                }

                //Out action message
                string shoppingTime = DateTime.Now.Subtract(startShoppingTime).ToString();
                message = string.Format("completed. Duration: {0}", Helper.RemoveMilliseconds(shoppingTime));
                networkClient.OutActionLogMessage(this, message);

                return true;
            }

            return false;
        }