void EscapeTheAcademy()
        {
            if (state_timeout_counter > 15)
            {
                state_timeout_counter = 0;
                action_completed      = true;
                current_state         = current_state > STEELBOT_STATE.HELLO ? current_state - 1 : STEELBOT_STATE.HELLO + 1;
            }
            if (action_completed)
            {
                updateWorldAcos();
                updateInventoryAcos();
                findSteelBotManagerAco();

                doStateAction(current_state);

                if (current_state == next_state)
                {
                    state_timeout_counter++;
                }
                else
                {
                    state_timeout_counter = 0;
                }

                current_state = next_state;
            }
        }
 void waitMsAndGoToState(int ms, STEELBOT_STATE state)
 {
     timer = new System.Threading.Timer((obj) =>
     {
         next_state       = state;
         action_completed = true;
         timer.Dispose();
     }, null, ms, System.Threading.Timeout.Infinite);
 }
 private void Current_ContainerOpened(object sender, ContainerOpenedEventArgs e)
 {
     if (e.ItemGuid != 0)
     {
         aco_chest_container = e.ItemGuid;
         action_completed    = true;
         current_state       = STEELBOT_STATE.DELAY1;
         CoreManager.Current.Actions.AddChatText("Container opened: " + aco_chest_container.ToString(), 5);
     }
 }
        private void WorldFilter_CreateObject(object sender, CreateObjectEventArgs e)
        {
            if (e.New.Name == "Pathwarden Supply Key")
            {
                current_state    = STEELBOT_STATE.UNLOCKING_CHEST;
                action_completed = true;
            }

            if (e.New.Name == "Academy Exit Token")
            {
                current_state    = STEELBOT_STATE.ESCAPING;
                action_completed = true;
            }
        }
        public void FilterCore_ClientDispatch(object sender, NetworkMessageEventArgs e)
        {
            if (e.Message.Type == 0xF7C8)
            { // Enter Game
                freshLogin    = true;
                current_state = STEELBOT_STATE.HELLO;
                steelRunnerTimer_initialized = false;
            }

            if (e.Message.Type == 0xF7B1 && Convert.ToInt32(e.Message["action"]) == 0xA1) // Character Materialize (Any time is done portalling in, login or portal)
            {
                if (freshLogin)
                {
                    freshLogin       = false;
                    current_state    = STEELBOT_STATE.HELLO;
                    action_completed = true;

                    string characterName = GameRepo.Game.Character;
                    if (string.IsNullOrEmpty(characterName))
                    {
                        // Do not know why GameRepo.Game.Character is not yet populated, but it isn't
                        var launchInfo = LaunchControl.GetLaunchInfo();
                        if (launchInfo.IsValid)
                        {
                            characterName = launchInfo.CharacterName;
                        }
                    }

                    var persister = new LoginCommandPersister(GameRepo.Game.Account, GameRepo.Game.Server, characterName);

                    log.WriteDebug("FilterCore_ClientDispatch: Character: '{0}'", GameRepo.Game.Character);

                    //_loginCmds = persister.ReadAndCombineQueues();

                    loginCompleteTime = DateTime.Now;

                    initHandlers();

                    CoreManager.Current.RenderFrame += new EventHandler <EventArgs>(Current_RenderFrame);
                }
                else
                {
                    // find the pathwarden
                    current_state    = STEELBOT_STATE.MOVING_TO_CHEST;
                    action_completed = true;
                }
            }
        }
        void GiveArmorToPathWarden(STEELBOT_STATE state)
        {
            foreach (var item in CoreManager.Current.WorldFilter.GetInventory())
            {
                if (pathwarden_armor_names.Contains(item.Name))
                {
                    CoreManager.Current.Actions.GiveItem(item.Id, aco_pathwarden);
                    timer = new System.Threading.Timer((obj) =>
                    {
                        action_completed = true;
                        timer.Dispose();
                    }, null, 500, System.Threading.Timeout.Infinite);

                    return;
                }
            }

            next_state       = STEELBOT_STATE.GIVING_STEEL;
            action_completed = true;
        }
 private void WorldFilter_ChangeObject(object sender, ChangeObjectEventArgs e)
 {
     try
     {
         if (e.Change == WorldChangeType.IdentReceived && e.Changed.Id == aco_door)
         {
             is_door_open     = e.Changed.Values(BoolValueKey.Open);
             action_completed = true;
         }
         if (e.Changed.Name == "Pathwarden Supply Key")
         {
             current_state    = STEELBOT_STATE.UNLOCKING_CHEST;
             action_completed = true;
         }
         if (e.Changed.Name == "Academy Exit Token")
         {
             current_state    = STEELBOT_STATE.ESCAPING;
             action_completed = true;
         }
     }
     catch (Exception ex) { }
 }
        void doStateAction(STEELBOT_STATE state)
        {
            CoreManager.Current.Actions.AddChatText("Doing action for state: " + state.ToString(), 5);
            log.WriteDebug("Doing action for state: " + state.ToString());
            action_completed = false;
            switch (state)
            {
            case STEELBOT_STATE.HELLO:
                if (aco_greeter == 0)
                {
                    next_state = STEELBOT_STATE.LOGGING_OUT;
                }
                else
                {
                    CoreManager.Current.Actions.UseItem(aco_greeter, 0);
                    next_state = STEELBOT_STATE.CHECKING_DOOR;
                }
                break;

            case STEELBOT_STATE.CHECKING_DOOR:
                CoreManager.Current.Actions.RequestId(aco_door);
                next_state = STEELBOT_STATE.OPENING_DOOR;
                break;

            case STEELBOT_STATE.OPENING_DOOR:
                if (is_door_open)
                {
                    next_state       = STEELBOT_STATE.APPROACHING_SAM;
                    action_completed = true;
                }
                else
                {
                    CoreManager.Current.Actions.UseItem(aco_door, 0);
                    next_state = STEELBOT_STATE.CHECKING_DOOR;
                }
                break;

            case STEELBOT_STATE.APPROACHING_SAM:
                CoreManager.Current.Actions.UseItem(aco_sign, 0);
                next_state = STEELBOT_STATE.TALKING_TO_JONATHAN;
                break;

            case STEELBOT_STATE.TALKING_TO_JONATHAN:
                CoreManager.Current.Actions.UseItem(aco_jonathan, 0);
                next_state = STEELBOT_STATE.ESCAPING;
                break;

            case STEELBOT_STATE.ESCAPING:
                Thread.Sleep(100);
                var exit_token = FindItemInInventoryByName(EXIT_TOKEN);
                if (exit_token != 0)
                {
                    CoreManager.Current.Actions.GiveItem(exit_token, aco_jonathan);
                    waitMsAndGoToState(1000, STEELBOT_STATE.ESCAPING);
                }
                break;

            case STEELBOT_STATE.PORTALING:
                break;

            case STEELBOT_STATE.MOVING_TO_CHEST:
                CoreManager.Current.Actions.UseItem(aco_pathwarden_chest, 0);
                next_state = STEELBOT_STATE.TURNING_IN_PATHWARDEN_TOKEN;
                break;

            case STEELBOT_STATE.TURNING_IN_PATHWARDEN_TOKEN:
                Thread.Sleep(100);
                var token = FindItemInInventoryByName(PATHWARDEN_TOKEN);
                if (token != 0)
                {
                    CoreManager.Current.Actions.GiveItem(token, aco_pathwarden);
                    waitMsAndGoToState(2000, STEELBOT_STATE.TURNING_IN_PATHWARDEN_TOKEN);
                }
                else
                {
                    next_state       = STEELBOT_STATE.WAITING_FOR_KEY;
                    action_completed = true;
                }
                break;

            case STEELBOT_STATE.WAITING_FOR_KEY:
                var key = FindItemInInventoryByName(PATHWARDEN_KEY);
                if (key != 0)
                {
                    next_state = STEELBOT_STATE.UNLOCKING_CHEST;
                }
                action_completed = true;
                break;

            case STEELBOT_STATE.UNLOCKING_CHEST:
                CoreManager.Current.Actions.ApplyItem(aco_pathwarden_key, aco_pathwarden_chest);
                next_state       = STEELBOT_STATE.OPENING_CHEST;
                action_completed = true;
                break;

            case STEELBOT_STATE.OPENING_CHEST:
                if (aco_chest_container == 0)
                {
                    var retry_key = FindItemInInventoryByName(PATHWARDEN_KEY);
                    if (retry_key != 0)
                    {
                        next_state       = STEELBOT_STATE.UNLOCKING_CHEST;
                        action_completed = true;
                    }
                    else
                    {
                        CoreManager.Current.Actions.UseItem(aco_pathwarden_chest, 0);
                        next_state = STEELBOT_STATE.OPENING_CHEST;
                    }
                }
                else
                {
                    CoreManager.Current.Actions.AddChatText("OPENING_CHEST_NONZERO_CONTAINER" + state.ToString(), 5);
                    next_state       = STEELBOT_STATE.LOOTING_CHEST;
                    action_completed = true;
                }
                break;

            case STEELBOT_STATE.DELAY1:
                next_state       = STEELBOT_STATE.LOOTING_CHEST;
                action_completed = true;
                break;

            case STEELBOT_STATE.LOOTING_CHEST:
                var chest = CoreManager.Current.WorldFilter.GetByContainer(aco_chest_container);
                if (aco_chest_container != 0)
                {
                    if (chest.Count > 0)
                    {
                        CoreManager.Current.Actions.MoveItem(chest.First.Id, CoreManager.Current.CharacterFilter.Id);
                        next_state       = STEELBOT_STATE.LOOTING_CHEST;
                        action_completed = true;
                    }
                    else
                    {
                        next_state       = STEELBOT_STATE.CLOSING_CHEST;
                        action_completed = true;
                    }
                }
                else
                {
                    CoreManager.Current.Actions.AddChatText("LOOTING_CHEST__0_CONTAINER" + state.ToString(), 5);
                }
                break;

            case STEELBOT_STATE.CLOSING_CHEST:
                CoreManager.Current.Actions.UseItem(aco_pathwarden_chest, 0);
                waitMsAndGoToState(1000, STEELBOT_STATE.TURNING_IN_PATHWARDEN_ARMOR);
                break;

            case STEELBOT_STATE.TURNING_IN_PATHWARDEN_ARMOR:
                GiveArmorToPathWarden(current_state);
                break;

            case STEELBOT_STATE.GIVING_STEEL:
                var steel = FindItemInInventoryByName(SALVAGED_STEEL);
                if (steel != 0)
                {
                    CoreManager.Current.Actions.GiveItem(steel, aco_steelbot_manager);
                    waitMsAndGoToState(300, STEELBOT_STATE.GIVING_STEEL);
                }
                else
                {
                    next_state = STEELBOT_STATE.LOGGING_OUT;
                }
                break;

            case STEELBOT_STATE.LOGGING_OUT:
                CoreManager.Current.Actions.AddChatText("DONE.", 5);
                break;
            }
        }