Ejemplo n.º 1
0
        public static void ProcessExchangeRequest(WorldClient Client, string Packet)
        {
            if (!Packet.Contains('|'))
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            var Data = Packet.Substring(2).Split('|');

            if (Data.Length != 2)
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            var  ExchangeType = 0;
            long ActorId      = 0;

            if (!int.TryParse(Data[0], out ExchangeType))
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            if (!Enum.IsDefined(typeof(ExchangeTypeEnum), ExchangeType))
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            if (!long.TryParse(Data[1], out ActorId) && (ExchangeTypeEnum)ExchangeType != ExchangeTypeEnum.EXCHANGE_MOUNT && (ExchangeTypeEnum)ExchangeType != ExchangeTypeEnum.EXCHANGE_BIGSTORE_BUY && (ExchangeTypeEnum)ExchangeType != ExchangeTypeEnum.EXCHANGE_BIGSTORE_SELL)
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            var Actor = Client.Character.myMap.GetActor(ActorId);

            // inexistant ?
            if (Actor == null && (ExchangeTypeEnum)ExchangeType != ExchangeTypeEnum.EXCHANGE_MOUNT && (ExchangeTypeEnum)ExchangeType != ExchangeTypeEnum.EXCHANGE_BIGSTORE_BUY && (ExchangeTypeEnum)ExchangeType != ExchangeTypeEnum.EXCHANGE_BIGSTORE_SELL)
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            // Il peu echanger ?
            if (!Client.CanGameAction(GameActionTypeEnum.EXCHANGE) && !(Client.GetExchange() != null && Client.GetExchange() is MarketSellExchange && ExchangeType == 11))
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            switch ((ExchangeTypeEnum)ExchangeType)
            {
            case ExchangeTypeEnum.EXCHANGE_BIGSTORE_BUY:
                if (Client.Character.Deshonor >= 5)
                {
                    Client.Send(new TextInformationMessage(TextInformationTypeEnum.ERREUR, 83));
                    Client.Send(new ExchangeLeaveMessage());
                    return;
                }
                if (Client.GetExchange() != null)
                {
                    ProcessExchangeLeaveMessage(Client);
                }
                if (!BidHouseTable.Cache.ContainsKey(Client.Character.Map))
                {
                    //TODO IM Message HDV Not Exist
                    Client.Send(new ExchangeLeaveMessage());
                    return;
                }
                var Market = BidHouseTable.Cache[Client.Character.Map];

                var MbExchange = new MarketBuyExchange(Client, Market);

                Client.AddGameAction(new GameExchange(Client.Character, MbExchange));
                Client.SetExchange(MbExchange);

                Client.Send(new ExchangeCreateMessage(ExchangeTypeEnum.EXCHANGE_BIGSTORE_BUY, "1,10,100;" + Market.CategoriesString + ";" + Market.TaxRate() + ";" + Market.levelMax + ";" + Market.countItem + ";-1;" + Market.sellTime));

                break;

            case ExchangeTypeEnum.EXCHANGE_SHOP:

                // lol ?
                if (Actor.ActorType != GameActorTypeEnum.TYPE_NPC)
                {
                    Client.Send(new BasicNoOperationMessage());
                    return;
                }

                var Npc      = Actor as Npc;
                var Exchange = new NpcExchange(Client, Npc);


                Client.AddGameAction(new GameExchange(Client.Character, Exchange));
                Client.SetExchange(Exchange);

                Client.Send(new ExchangeCreateMessage((ExchangeTypeEnum)ExchangeType, Npc.ActorId.ToString()));
                Client.Send(new ExchangeItemListMessage(Npc));
                break;

            case ExchangeTypeEnum.EXCHANGE_BIGSTORE_SELL:
                if (Client.Character.Deshonor >= 5)
                {
                    Client.Send(new TextInformationMessage(TextInformationTypeEnum.ERREUR, 83));
                    Client.Send(new ExchangeLeaveMessage());
                    return;
                }
                if (!BidHouseTable.Cache.ContainsKey(Client.Character.Map))
                {
                    //TODO IM Message HDV Not Exist
                    Client.Send(new ExchangeLeaveMessage());
                    return;
                }
                Market = BidHouseTable.Cache[Client.Character.Map];

                var MaExchange = new MarketSellExchange(Client, Market);

                Client.AddGameAction(new GameExchange(Client.Character, MaExchange));
                Client.SetExchange(MaExchange);

                Client.Send(new ExchangeCreateMessage(ExchangeTypeEnum.EXCHANGE_BIGSTORE_SELL, "1,10,100;" + Market.CategoriesString + ";" + Market.TaxRate() + ";" + Market.levelMax + ";" + Market.countItem + ";-1;" + Market.sellTime));
                Client.Send(new ExchangeItemListMessagePerAccount(Client.Account.Data, Market.HdvID));

                break;

            case ExchangeTypeEnum.EXCHANGE_MOUNT:

                var Mount = Client.Character.Mount;

                if (Mount == null)
                {
                    return;
                }

                var MExchange = new MountExchange(Client, Mount);


                Client.AddGameAction(new GameExchange(Client.Character, MExchange));
                Client.SetExchange(MExchange);

                Client.Send(new ExchangeCreateMessage((ExchangeTypeEnum)ExchangeType, Mount.ID.ToString()));
                Client.Send(new ExchangeMountItemListMessage(Mount));
                Client.Send(new MountActualPodMessage(Mount));
                break;

            case ExchangeTypeEnum.EXCHANGE_PLAYER:

                // lol?
                if (Actor.ActorType != GameActorTypeEnum.TYPE_CHARACTER)
                {
                    Client.Send(new BasicNoOperationMessage());
                    return;
                }

                // cast
                var Target = (Actor as Player).Client;

                if (!Target.CanGameAction(GameActionTypeEnum.BASIC_REQUEST) ||
                    Target.Character.HasRestriction(RestrictionEnum.RESTRICTION_CANT_EXCHANGE) ||
                    Client.Character.HasRestriction(RestrictionEnum.RESTRICTION_CANT_EXCHANGE))
                {
                    Client.Send(new BasicNoOperationMessage());
                    return;
                }

                var Request       = new ExchangeRequest(Client, Target);
                var RequestAction = new GameRequest(Client.Character, Request);

                Client.AddGameAction(RequestAction);
                Target.AddGameAction(RequestAction);

                Client.SetBaseRequest(Request);
                Target.SetBaseRequest(Request);

                var Message = new ExchangeRequestMessage(Client.Character.ID, Target.Character.ID);

                Client.Send(Message);
                Target.Send(Message);
                break;

            case ExchangeTypeEnum.EXCHANGE_TAXCOLLECTOR:
                if (Packet.Length < 4 || !Client.Character.HasGuild())
                {
                    Client.Send(new BasicNoOperationMessage());
                    return;
                }
                long         PercepteurID = long.Parse(Packet.Substring(4));
                TaxCollector perco        = TaxCollectorTable.GetPerco(PercepteurID);

                if (perco == null || perco.inFight > 0 || perco.inExchange)
                {
                    Client.Send(new BasicNoOperationMessage());
                    return;
                }

                perco.inExchange = true;

                if (Actor.ActorType != GameActorTypeEnum.TYPE_TAX_COLLECTOR)
                {
                    Client.Send(new BasicNoOperationMessage());
                    return;
                }

                var TC        = Actor as TaxCollector;
                var TExchange = new TaxCollectorExchange(Client, TC);


                Client.AddGameAction(new GameExchange(Client.Character, TExchange));
                Client.SetExchange(TExchange);

                Client.Send(new ExchangeCreateMessage((ExchangeTypeEnum)ExchangeType, TC.ActorId.ToString()));
                Client.Send(new ExchangeTaxItemListMessage(TC.SerializeAsItemList()));

                break;
            }
        }
Ejemplo n.º 2
0
        private static void ProcessTaxCollectorJoinFigh(WorldClient Client, string Packet)
        {
            String PercoID = IntHelper.toString(int.Parse(Packet.Substring(1)), 36);
            long   TiD     = -1;

            if (!long.TryParse(PercoID, out TiD))
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }
            var TaxCollector = TaxCollectorTable.GetPerco(TiD);

            if (TaxCollector == null)
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            short MapID = -1;

            try
            {
                MapID = (short)TaxCollector.Mapid;
            }
            catch (Exception e)
            {};

            int CellID = -1;

            try
            {
                CellID = TaxCollector.CellId;
            }
            catch (Exception e)
            {};

            if (TiD == -1 || TaxCollector.CurrentFight == null || MapID == -1 || CellID == -1)
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            if (Client.GetFight() == null && !Client.GetCharacter().isAaway)
            {
                if (Client.GetCharacter().myMap.Id != MapID)
                {
                    Client.GetCharacter().isJoiningTaxFight = true;
                    Client.GetCharacter().OldPosition       = new Couple <Map, int>(Client.Character.myMap, Client.Character.CellId);
                    Client.GetCharacter().Teleport(TaxCollector.Map, CellID);
                    try
                    {
                        System.Threading.Thread.Sleep(700);
                    }
                    catch (Exception e)
                    {
                        Logger.Error(e);
                    }
                }

                if (Client.GetCharacter().HasRestriction(RestrictionEnum.RESTRICTION_IS_TOMBESTONE))
                {
                    Client.Send(new BasicNoOperationMessage());
                    return;
                }

                var Team = TaxCollector.CurrentFight.GetTeam2();

                if (TaxCollector.CurrentFight.CanJoin(Team, Client.GetCharacter()))
                {
                    var Fighter = new CharacterFighter(TaxCollector.CurrentFight, Client);

                    var FightAction = new GameFight(Fighter, TaxCollector.CurrentFight);

                    Client.AddGameAction(FightAction);

                    TaxCollector.CurrentFight.JoinFightTeam(Fighter, Team, false, -1, false);
                }
            }
        }