예제 #1
0
        /// <summary>
        /// Execute the AI plan.
        /// </summary>
        public void ExecutePlan()
        {
            if (flag != 1)
            {
                return;
            }
            m_Account.SetStatus(Status.Fighting);
            Dictionary <BSpell, BFighter> plan = m_AI.GetPlan();

            foreach (KeyValuePair <BSpell, BFighter> pair in plan)
            {
                if (pair.Value == null)
                {
                    return;
                }
                int c = m_Data.CanUseSpell(pair.Key, pair.Value); /* Get if we can use the spell with/without move, or if we can't launch the spell */
                switch (c)
                {
                case -1:                  /* We can't use the spell, continue to the next spell */
                    continue;

                case  0:
                    LaunchSpell(pair.Key.SpellId, pair.Value.CellId);      /* We can use the spell without move */
                    return;

                default:
                    MoveToCell(c);                                        /* We can use the spell with move */
                    LaunchSpell(pair.Key.SpellId, pair.Value.CellId);
                    return;
                }
            }
            PerformMove(); /* No spell are launchable, move if we can and end the turn */
        }
예제 #2
0
        private void client_StateChanged(object sender, NetSockStateChangedEventArgs e)
        {
            switch (e.NewState)
            {
            case SocketState.Closed:
                account.SetStatus(Enums.Status.Disconnected);
                break;

            case SocketState.Connected:
                account.SetStatus(Enums.Status.None);
                break;
            }
            State = e.NewState;
        }
예제 #3
0
        public static void GameFightPlacementPossiblePositionsMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            GameFightPlacementPossiblePositionsMessage msg = (GameFightPlacementPossiblePositionsMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            account.SetStatus(Status.Fighting);
            account.FightData.UpdateTurn(0);
            if (account.Fight != null)
            {
                account.Fight.PlaceCharacter(msg.positionsForChallengers.ToList());
            }
            if (account.WithItemSetBox.Checked == true)
            {
                sbyte id = (sbyte)account.PresetStartUpD.Value;
                InventoryPresetUseMessage msg2 = new InventoryPresetUseMessage((sbyte)(id - 1));
                account.SocketManager.Send(msg2);
                account.Log(new ActionTextInformation("Equipement rapide numero " + Convert.ToString(id)), 5);
            }
            GameFightReadyMessage nmsg = new GameFightReadyMessage(true);

            account.SocketManager.Send(nmsg);
            account.Log(new BotTextInformation("Send Ready !"), 5);
        }
예제 #4
0
        public static void ObtainedItemMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            ObtainedItemMessage msg = (ObtainedItemMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            if (account.Gather.resourceName == "Unknown")
            {
                return;
            }
            account.SetStatus(Status.None);
            account.Log(new ActionTextInformation("Ressource récoltée : " + account.Gather.resourceName + " +" + msg.baseQuantity), 3);
            if (account.Gather.Stats.ContainsKey(account.Gather.resourceName))
            {
                account.Gather.Stats[account.Gather.resourceName] += msg.baseQuantity;
            }
            else
            {
                account.Gather.Stats.Add(account.Gather.resourceName, msg.baseQuantity);
            }
            account.Gather.Current_Job.ActualizeStats(account.Gather.Stats);
            if (account.PerformGather() == false && account.Path != null)
            {
                account.Path.PerformActionsStack();
            }
        }
예제 #5
0
        public static void LifePointsRegenBeginMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            LifePointsRegenBeginMessage msg = (LifePointsRegenBeginMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            if (account.Fight != null && account.state == Enums.Status.Fighting)
            {
                account.Fight.watch.Stop();
                account.Fight.WaitForReady   = false;
                account.Fight.IsFighterTurn  = false;
                account.Fight.IsFightStarted = false;
                account.Log(new ActionTextInformation("Combat fini ! (" + account.Fight.watch.Elapsed.Minutes + " min, " + account.Fight.watch.Elapsed.Seconds + " sec)"), 0);
                account.Fight.watch.Reset();
                account.Fight.PerformAutoTimeoutFight(2000);
                if (account.WithItemSetBox.Checked == true)
                {
                    sbyte id = (sbyte)account.PresetEndUpD.Value;
                    InventoryPresetUseMessage msg2 = new InventoryPresetUseMessage((sbyte)(id - 1));
                    account.SocketManager.Send(msg2);
                    account.Log(new ActionTextInformation("Equipement rapide numero " + Convert.ToString(id)), 5);
                }
                account.Fight.PulseRegen();
            }
            account.SetStatus(Status.None);

            //account.Path.Stop = false;
        }
예제 #6
0
        public static void GameFightPlacementPossiblePositionsMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            GameFightPlacementPossiblePositionsMessage msg = (GameFightPlacementPossiblePositionsMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            account.SetStatus(Status.Fighting);
            if (account.Fight != null)
            {
                account.Fight.PlacementCells = msg.positionsForChallengers.ToList();
                account.Fight.TurnId         = 0;
                if (account.Fight.m_Conf.Tactic != BlueSheep.Core.Fight.TacticEnum.Immobile)
                {
                    account.Fight.PlaceCharacter();
                }
            }
            //account.Fight.PerformAutoTimeoutFight(3000);
            //if (account.IsMITM)
            // account.Fight.PerformAutoTimeoutFight(3000);
            if (account.WithItemSetBox.Checked == true)
            {
                sbyte id = (sbyte)account.PresetStartUpD.Value;
                InventoryPresetUseMessage msg2 = new InventoryPresetUseMessage((sbyte)(id - 1));
                account.SocketManager.Send(msg2);
                account.Log(new ActionTextInformation("Equipement rapide numero " + Convert.ToString(id)), 5);
                account.Fight.PerformAutoTimeoutFight(500);
            }
            //LaunchWatch()
            GameFightReadyMessage nmsg = new GameFightReadyMessage(true);

            account.SocketManager.Send(nmsg);
            account.Log(new BotTextInformation("Send Ready !"), 5);
        }
예제 #7
0
 public void PulseRegen()
 {
     if (((m_Account.CharacterStats.lifePoints / m_Account.CharacterStats.maxLifePoints) * 100) < m_Account.RegenChoice.Value)
     {
         m_Account.SetStatus(Status.Regenerating);
         List <Item> items = GetRegenItems();
         if (items.Count > 0)
         {
             if (UseItems(items))
             {
                 m_Account.Wait(500, 1000);
                 PulseRegen();
                 return;
             }
         }
         int maxLife = Convert.ToInt32(m_Account.CharacterStats.maxLifePoints);
         int life    = Convert.ToInt32(m_Account.CharacterStats.lifePoints);
         int time    = Convert.ToInt32(Math.Round(Convert.ToDecimal(maxLife - life) / 2));
         BlueSheep.Common.Protocol.Messages.EmotePlayRequestMessage msg = new BlueSheep.Common.Protocol.Messages.EmotePlayRequestMessage(1);
         m_Account.SocketManager.Send(msg);
         m_Account.Log(new GeneralTextInformation(String.Format("Régénération pendant {0} secondes.", time)), 2);
         m_Account.Wait(time * 1000, (time + 1) * 1000);
         if (m_Account.Path != null && m_Account.Path.Launched)
         {
             m_Account.Path.ParsePath();
         }
     }
 }
예제 #8
0
 public void Connect(ConnectionInformations connectionInformations)
 {
     //if (MainForm.ActualMainForm.IpAdressChoice.SelectedIndex > -1)
     //{
     // IPEndPoint e = new IPEndPoint(new IPAddress(GetBytes(MainForm.ActualMainForm.IpAdressChoice.SelectedText)), 0);
     // m_Socket.Bind(e);
     //}
     if (m_RawSocket != null && !m_RawSocket.Connected)
     {
         RawConnect();
     }
     if (m_IsChangingServer)
     {
         m_Socket.Disconnect(false);
         m_Socket.Dispose();
         m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         account.SetStatus(Status.Disconnected);
     }
     try
     {
         m_Socket.Connect(connectionInformations.Address, connectionInformations.Port);
         if (m_Socket.Connected)
         {
             account.SetStatus(Status.None);
             account.LatencyFrame = new LatencyFrame(account);
             account.Log(new ConnectionTextInformation("Connexion établie au serveur " + connectionInformations.ServerName + "."), 0);
             if ((!m_IsChangingServer))
             {
                 m_ReceptionThread = new Thread(SocketReception);
                 m_ReceptionThread.Start();
             }
             m_IsChangingServer = false;
         }
         else
         {
             account.Log(new ConnectionTextInformation("Connexion échouée."), 0);
         }
     }
     catch (SocketException sockEx)
     {
         account.Log(new ErrorTextInformation("[Socket Exception] " + sockEx.Message), 0);
         account.TryReconnect(1);
     }
 }
예제 #9
0
        public static void GameContextRemoveElementMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            ExchangeStartOkNpcShopMessage msg = (ExchangeStartOkNpcShopMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            account.SetStatus(Status.Exchanging);
        }
예제 #10
0
        public static void NpcDialogCreationMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            LeaveDialogMessage msg = (LeaveDialogMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            account.SetStatus(Status.None);
        }
예제 #11
0
        public static void GameFightEndMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            GameFightEndMessage msg = (GameFightEndMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            account.FightData.FightStop();
            account.SetStatus(Status.None);
            //account.Fight.infinite = true; // Swap it with checkbox
        }
예제 #12
0
        public static void LeaveDialogMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            NpcDialogCreationMessage msg = (NpcDialogCreationMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            account.Npc.Id     = msg.npcId;
            account.Npc.Entity = account.MapData.Npcs.FirstOrDefault((npc) => npc.contextualId == msg.npcId);
            account.SetStatus(Status.Speaking);
        }
예제 #13
0
        public bool SearchFight()
        {
            m_Account.Path.Stop = true;
            int minNumber = (int)m_Account.nudMinMonstersNumber.Value;
            int maxNumber = (int)m_Account.nudMaxMonstersNumber.Value;
            int minLevel  = (int)m_Account.nudMinMonstersLevel.Value;
            int maxLevel  = (int)m_Account.nudMaxMonstersLevel.Value;

            lock (this.clock)
            {
                foreach (MonsterGroup monsters in m_Account.Map.List)
                {
                    if (monsters.monstersCount < minNumber || monsters.monstersCount > maxNumber)
                    {
                        continue;
                    }

                    if (monsters.monstersLevel < minLevel || monsters.monstersLevel > maxLevel)
                    {
                        continue;
                    }
                    if (m_Account.VerifGroup(monsters.NameList()) == false)
                    {
                        continue;
                    }

                    this.followinggroup = monsters;
                    if (m_Account.Map.MoveToCell(monsters.m_cellId))
                    {
                        m_Account.SetStatus(Status.Moving);
                        m_Account.Path.Stop = true;
                        m_Account.Log(new ActionTextInformation(string.Format("Lancement d'un combat contre {0} monstres de niveau {1} ({2})", monsters.monstersCount, monsters.monstersLevel, monsters.monstersName(true))), 1);
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #14
0
 /// <summary>
 /// Clear all the fields before parsing MapComplementaryInformationsDataMessage.
 /// </summary>
 public void Clear()
 {
     if (Data != null)
     {
         LastMapId = Id;
     }
     Players.Clear();
     Monsters.Clear();
     Npcs.Clear();
     Others.Clear();
     InteractiveElements.Clear();
     StatedElements.Clear();
     m_Account.SetStatus(Engine.Enums.Status.None);
 }
예제 #15
0
        public static void GameMapMovementConfirmMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            GameMapMovementConfirmMessage msg = (GameMapMovementConfirmMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            BlueSheep.Core.Fight.Entity Character = null;
            foreach (BlueSheep.Core.Fight.Entity e in account.Map.Entities)
            {
                if (e.Id == account.CharacterBaseInformations.id)
                {
                    Character = e;
                }
            }
            int mapChangeData = ((BlueSheep.Data.D2p.Map)account.Map.Data).Cells[Character.CellId].MapChangeData;

            if (mapChangeData != 0)
            {
                int neighbourId = 0;
                if (neighbourId == -2)
                {
                    if ((mapChangeData & 64) > 0)
                    {
                        neighbourId = ((BlueSheep.Data.D2p.Map)account.Map.Data).TopNeighbourId;
                    }
                    if ((mapChangeData & 16) > 0)
                    {
                        neighbourId = ((BlueSheep.Data.D2p.Map)account.Map.Data).LeftNeighbourId;
                    }
                    if ((mapChangeData & 4) > 0)
                    {
                        neighbourId = ((BlueSheep.Data.D2p.Map)account.Map.Data).BottomNeighbourId;
                    }
                    if ((mapChangeData & 1) > 0)
                    {
                        neighbourId = ((BlueSheep.Data.D2p.Map)account.Map.Data).RightNeighbourId;
                    }
                }
                if (neighbourId >= 0)
                {
                    account.Map.LaunchChangeMap(neighbourId);
                }
            }
            account.SetStatus(Status.None);
        }
예제 #16
0
        public static void GameEntitiesDispositionMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            GameEntitiesDispositionMessage msg = (GameEntitiesDispositionMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            if (account.Fight != null)
            {
                msg.dispositions.ToList().ForEach(d =>
                {
                    account.FightData.UpdateFighterCell(d.id, d.cellId);
                });
            }
            account.SetStatus(Status.Fighting);
        }
예제 #17
0
        public static void InteractiveUseEndedMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            InteractiveUseEndedMessage msg = (InteractiveUseEndedMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            if (account.Gather.Id == -1)
            {
                return;
            }
            account.SetStatus(Status.None);
            if (account.PerformGather() == false && account.Path != null)
            {
                account.Path.PerformActionsStack();
            }
        }
예제 #18
0
 public static void HelloConnectMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
 {
     account.SetStatus(Status.None);
     if (!account.IsMITM)
     {
         HelloConnectMessage helloConnectMessage = (HelloConnectMessage)message;
         using (BigEndianReader reader = new BigEndianReader(packetDatas))
         {
             helloConnectMessage.Deserialize(reader);
         }
         sbyte[] credentials = RSAKey.Encrypt(helloConnectMessage.key,
                                              account.AccountName,
                                              account.AccountPassword,
                                              helloConnectMessage.salt);
         IdentificationMessage msg = new IdentificationMessage(GameConstants.AutoConnect, GameConstants.UseCertificate, GameConstants.UseLoginToken, new Common.Protocol.Types.VersionExtended(GameConstants.Major, GameConstants.Minor, GameConstants.Release, GameConstants.Revision, GameConstants.Patch, GameConstants.BuildType, GameConstants.Install, GameConstants.Technology), GameConstants.Lang, credentials, GameConstants.ServerID, GameConstants.SessionOptionalSalt, new System.Collections.Generic.List <short>());
         account.SocketManager.Send(msg);
     }
     account.Log(new ConnectionTextInformation("Identification en cours."), 0);
 }
예제 #19
0
 /// <summary>
 /// Set the fight as stopped.
 /// </summary>
 public void FightStop()
 {
     watch.Stop();
     WaitForReady   = false;
     IsFighterTurn  = false;
     IsFightStarted = false;
     IsDead         = false;
     m_Account.Log(new ActionTextInformation("Combat fini ! (" + watch.Elapsed.Minutes + " min, " + watch.Elapsed.Seconds + " sec)"), 0);
     watch.Reset();
     m_Account.SetStatus(Status.Busy);
     Reset();
     PerformAutoTimeoutFight(2000);
     if (m_Account.WithItemSetBox.Checked == true)
     {
         sbyte id = (sbyte)m_Account.PresetEndUpD.Value;
         InventoryPresetUseMessage msg2 = new InventoryPresetUseMessage((byte)(id - 1));
         m_Account.SocketManager.Send(msg2);
         m_Account.Log(new ActionTextInformation("Equipement rapide numero " + Convert.ToString(id)), 5);
     }
     PulseRegen();
 }
예제 #20
0
        public static void GameEntitiesDispositionMessageTreatment(Message message, byte[] packetDatas, AccountUC account)
        {
            GameEntitiesDispositionMessage msg = (GameEntitiesDispositionMessage)message;

            using (BigEndianReader reader = new BigEndianReader(packetDatas))
            {
                msg.Deserialize(reader);
            }
            if (account.Fight != null)
            {
                msg.dispositions.ToList().ForEach(d =>
                {
                    var fighter = account.Fight.GetFighter(d.id);
                    if (fighter != null)
                    {
                        ((BFighter)fighter).CellId = d.cellId;
                    }
                });
            }
            account.SetStatus(Status.Fighting);
        }
예제 #21
0
        public bool MoveToCell(int cellId)
        {
            if (m_Account.state == Engine.Enums.Status.Fighting)
            {
                return(false);
            }
            m_Account.SetStatus(Status.Moving);
            MovementPath path = (new Pathfinder(m_Account.MapData)).FindPath(m_Account.MapData.Character.Disposition.CellId, cellId);

            if (path == null)
            {
                return(false);
            }
            List <UInt32> serverMovement = MapMovementAdapter.GetServerMovement(path);

            if (serverMovement[serverMovement.Count - 1] == m_Account.MapData.Character.Disposition.CellId)
            {
                Moving = false;
                ConfirmMove();
                return(true);
            }
            int timetowait;

            if (serverMovement.Count() < 3)
            {
                timetowait = serverMovement.Count() * 500;
            }
            else
            {
                timetowait = serverMovement.Count() * 300;
            }
            m_time = timetowait;
            using (BigEndianWriter writer = new BigEndianWriter())
            {
                GameMapMovementRequestMessage msg = new GameMapMovementRequestMessage(serverMovement.Select(ui => (short)ui).ToList(), m_Account.MapData.Id);
                msg.Serialize(writer);
                writer.Content = m_Account.HumanCheck.hash_function(writer.Content);
                MessagePackaging pack = new MessagePackaging(writer);
                pack.Pack((int)msg.MessageID);
                m_Account.SocketManager.Send(pack.Writer.Content);
                Moving = true;
                if (m_Account.DebugMode.Checked)
                {
                    m_Account.Log(new DebugTextInformation("[SND] 950 (GameMapMovementRequestMessage)"), 0);
                }
            }

            //m_Account.Wait(timetowait, timetowait + 100);
            //using (BigEndianWriter writer = new BigEndianWriter())
            //{
            //    GameMapMovementConfirmMessage newmsg = new GameMapMovementConfirmMessage();
            //    newmsg.Serialize(writer);
            //    MessagePackaging pack = new MessagePackaging(writer);
            //    pack.Pack((int)newmsg.ProtocolID);
            //    if (m_Account.Fight != null && m_Account.FightData.IsFollowingGroup && m_Account.FightData.followingGroup.m_cellId == cellId)
            //    {
            //        m_Account.SocketManager.Send(pack.Writer.Content);
            //        if (m_Account.DebugMode.Checked)
            //            m_Account.Log(new DebugTextInformation("[SND] 952 (GameMapMovementConfirmMessage)"), 0);
            //        m_Account.Fight.LaunchFight(m_Account.FightData.followingGroup.m_contextualId);
            //        Thread t = new Thread(new ThreadStart(CheckFight));
            //        t.Start();
            //    }
            //    else if (m_Account.Fight != null && m_Account.FightData.IsFollowingGroup)
            //    {
            //        m_Account.Fight.SearchFight();
            //    }
            //    else if (m_Account.Gather.Id != -1)
            //    {
            //        m_Account.SocketManager.Send(pack.Writer.Content);
            //        if (m_Account.DebugMode.Checked)
            //            m_Account.Log(new DebugTextInformation("[SND] 952 (GameMapMovementConfirmMessage)"), 0);
            //        //UseElement(m_Account.Gather.Id, m_Account.Gather.SkillInstanceUid);
            //        int distance = m_Account.Gather.GetRessourceDistance(m_Account.Gather.Id);
            //        m_Account.Log(new DebugTextInformation("[Gather] New distance from element " + m_Account.Gather.Id + " = " + distance), 0);
            //        if (distance <= m_Account.Inventory.WeaponRange)
            //        {
            //            UseElement(m_Account.Gather.Id, m_Account.Gather.SkillInstanceUid);
            //            m_Account.SetStatus(Status.Gathering);
            //        }
            //        else if (m_Account.Path != null)
            //            m_Account.Path.PerformFlag();
            //        else
            //            m_Account.PerformGather();
            //    }
            //    else
            //    {
            //        m_Account.SocketManager.Send(pack.Writer.Content);
            //        if (m_Account.DebugMode.Checked)
            //            m_Account.Log(new DebugTextInformation("[SND] 952 (GameMapMovementConfirmMessage)"), 0);
            //    }
            //    m_Account.SetStatus(Status.None);
            //}

            return(true);
        }
예제 #22
0
        public bool GoGather(List <int> ressources, JobUC job)
        {
            List <int>           ListeRessourcesID = ressources;
            List <int>           ListDistance      = new List <int>();
            List <UsableElement> ListUsableElement = new List <UsableElement>();

            Current_Job = job;
            try
            {
                if (ListeRessourcesID.Count > 0)
                {
                    foreach (var RessourceID in ListeRessourcesID)
                    {
                        foreach (var UsableElement in account.Map.UsableElements)
                        {
                            foreach (InteractiveElement InteractiveElement in account.Map.InteractiveElements.Values)
                            {
                                if (UsableElement.Value.Element.Id == InteractiveElement.Id && InteractiveElement.IsUsable)
                                {
                                    if (InteractiveElement.TypeId == RessourceID && account.Map.NoEntitiesOnCell(UsableElement.Value.CellId))
                                    {
                                        ListUsableElement.Add(UsableElement.Value);
                                        ListDistance.Add(GetRessourceDistance((int)UsableElement.Value.Element.Id));
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (var UsableElement in account.Map.UsableElements)
                    {
                        foreach (InteractiveElement InteractiveElement in account.Map.InteractiveElements.Values)
                        {
                            if (UsableElement.Value.Element.Id == InteractiveElement.Id && InteractiveElement.IsUsable)
                            {
                                if (account.Map.NoEntitiesOnCell(UsableElement.Value.CellId))
                                {
                                    ListUsableElement.Add(UsableElement.Value);
                                    ListDistance.Add(GetRessourceDistance((int)UsableElement.Value.Element.Id));
                                }
                            }
                        }
                    }
                }

                if (ListDistance.Count > 0)
                {
                    foreach (UsableElement UsableElement in TrierDistanceElement(ListDistance, ListUsableElement))
                    {
                        if (UsableElement.Element.IsUsable == false)
                        {
                            continue;
                        }
                        Id = (int)UsableElement.Element.Id;
                        SkillInstanceUid = UsableElement.Skills[0].skillInstanceUid;
                        Current_El       = UsableElement.Element;
                        //resourceName = UsableElement.Element.TypeId;
                        if (GetRessourceDistance((int)UsableElement.Element.Id) == 1 || IsFishing)
                        {
                            if (Moved)
                            {
                                account.Map.UseElement(Id, SkillInstanceUid);
                            }
                            else
                            {
                                account.Map.UseElement((int)UsableElement.Element.Id, UsableElement.Skills[0].skillInstanceUid);
                            }
                            Moved     = false;
                            IsFishing = false;
                            account.SetStatus(Status.Gathering);
                            return(true);
                        }
                        if ((account.Inventory.HasFishingRod == false && account.Map.MoveToElement((int)UsableElement.Element.Id, 1)) || (account.Inventory.HasFishingRod == true && account.Map.MoveToElement((int)UsableElement.Element.Id, account.Inventory.WeaponRange)))
                        {
                            account.SetStatus(Status.Gathering);
                            Id = (int)UsableElement.Element.Id;
                            SkillInstanceUid = UsableElement.Skills[0].skillInstanceUid;
                            if (account.Inventory.HasFishingRod)
                            {
                                IsFishing = true;
                            }
                            else
                            {
                                IsFishing = false;
                            }
                            return(true);
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                account.Log(new ErrorTextInformation(Ex.Message), 0);
            }
            Id = -1;
            SkillInstanceUid = -1;
            IsFishing        = false;
            Current_El       = null;
            return(false);
        }
예제 #23
0
        /// <summary>
        /// Perform the gathering of the specified ressources.
        /// </summary>
        /// <param name="ressources">
        /// List of the ressources'id.
        /// </param>
        /// /// <param name="job">
        /// The job used.
        /// </param>
        public bool GoGather(List <int> ressources, JobUC job)
        {
            List <int>           ListeRessourcesID = ressources;
            List <int>           ListDistance      = new List <int>();
            List <UsableElement> ListUsableElement = new List <UsableElement>();

            Current_Job = job;
            try
            {
                if (ListeRessourcesID.Count > 0)
                {
                    foreach (var RessourceID in ListeRessourcesID)
                    {
                        foreach (var UsableElement in account.MapData.UsableElements)
                        {
                            foreach (InteractiveElement InteractiveElement in account.MapData.InteractiveElements.Keys)
                            {
                                if (UsableElement.Value.Element.Id == InteractiveElement.Id && InteractiveElement.IsUsable)
                                {
                                    if (InteractiveElement.TypeId == RessourceID && account.MapData.NoEntitiesOnCell(UsableElement.Value.CellId))
                                    {
                                        ListUsableElement.Add(UsableElement.Value);
                                        ListDistance.Add(GetRessourceDistance((int)UsableElement.Value.Element.Id));
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (var UsableElement in account.MapData.UsableElements)
                    {
                        foreach (InteractiveElement InteractiveElement in account.MapData.InteractiveElements.Keys)
                        {
                            if (UsableElement.Value.Element.Id == InteractiveElement.Id && InteractiveElement.IsUsable)
                            {
                                if (account.MapData.NoEntitiesOnCell(UsableElement.Value.CellId))
                                {
                                    ListUsableElement.Add(UsableElement.Value);
                                    ListDistance.Add(GetRessourceDistance((int)UsableElement.Value.Element.Id));
                                }
                            }
                        }
                    }
                }

                if (ListDistance.Count > 0)
                {
                    foreach (UsableElement UsableElement in TrierDistanceElement(ListDistance, ListUsableElement))
                    {
                        if (UsableElement.Element.IsUsable == false || m_BannedId.Contains((int)UsableElement.Element.Id))
                        {
                            continue;
                        }
                        Id = (int)UsableElement.Element.Id;
                        SkillInstanceUid = UsableElement.Skills[0].skillInstanceUid;
                        Current_El       = UsableElement.Element;
                        int distance = GetRessourceDistance((int)UsableElement.Element.Id);
                        account.Log(new DebugTextInformation("[Gather] Distance from element " + UsableElement.Element.Id + " = " + distance), 0);
                        if (distance == -1)
                        {
                            continue;
                        }
                        if (account.MapData.CanGatherElement(Id, distance))
                        {
                            account.SetStatus(Status.Gathering);
                            account.Map.UseElement(Id, SkillInstanceUid);
                            return(true);
                        }
                        else if (account.Map.MoveToElement((int)UsableElement.Element.Id, account.Inventory.WeaponRange))
                        {
                            return(true);
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                account.Log(new ErrorTextInformation(Ex.Message), 0);
            }
            Id = -1;
            SkillInstanceUid = -1;
            Current_El       = null;
            return(false);
        }