Exemplo n.º 1
0
        [PacketHandler(RealmServerOpCode.EndFishing)]//6171
        public static void EndFishingRequest(IRealmClient client, RealmPacketIn packet)
        {
            if (client.ActiveCharacter.CurrentFish == null)
            {
                SendFishingEndedResponse(client, Asda2EndFishingStatus.YouAlreadyFishing, 0);
                return;
            }
            var ft = client.ActiveCharacter.CurrentFish;

            client.ActiveCharacter.CurrentFish = null;
            if (client.ActiveCharacter.FishReadyTime > (uint)Environment.TickCount)
            {
                SendFishingEndedResponse(client, Asda2EndFishingStatus.YouAlreadyFishing, 0);
                return;
            }
            if (client.ActiveCharacter.Asda2Inventory.Equipment[9] == null || !client.ActiveCharacter.Asda2Inventory.Equipment[9].IsRod)
            {
                client.ActiveCharacter.YouAreFuckingCheater("Trying to fishing without rod.", 30);
                SendFishingStartedResponse(client, Asda2StartFishStatus.YouHaveNoFishRod);
                return;
            }
            if (client.ActiveCharacter.Asda2Inventory.Equipment[10] == null || !client.ActiveCharacter.Asda2Inventory.Equipment[10].Template.IsBait)
            {
                client.ActiveCharacter.YouAreFuckingCheater("Trying to fishing without bait.", 30);
                SendFishingStartedResponse(client, Asda2StartFishStatus.YouHaveNoBait);
                return;
            }
            var rod = client.ActiveCharacter.Asda2Inventory.Equipment[9];

            if (rod.Category != Asda2ItemCategory.PremiumFishRod && CharacterFormulas.DecraseRodDurability())
            {
                rod.DecreaseDurability(1);
            }
            var bait = client.ActiveCharacter.Asda2Inventory.Equipment[10];

            bait.ModAmount(-1);
            if (bait.Category != Asda2ItemCategory.BaitElite && !ft.BaitIds.Contains(bait.ItemId))
            {
                SendFishingEndedResponse(client, Asda2EndFishingStatus.Ok, 0, bait);
                return;
            }
            FishingSpot spot = null;

            foreach (var fishingSpot in Asda2FishingMgr.FishingSpotsByMaps[(int)client.ActiveCharacter.MapId])
            {
                if (client.ActiveCharacter.Asda2Position.GetDistance(fishingSpot.Position) > fishingSpot.Radius / 2)
                {
                    continue;
                }
                spot = fishingSpot;
                break;
            }
            if (spot == null)
            {
                client.ActiveCharacter.YouAreFuckingCheater("Trying to fishing in wrong place.", 30);
                SendFishingStartedResponse(client, Asda2StartFishStatus.YouCantFishHere);
                return;
            }
            if (client.ActiveCharacter.FishingLevel < spot.RequiredFishingLevel)
            {
                SendFishingStartedResponse(client, Asda2StartFishStatus.YourFishingLevelIsToLowToFishHereItMustBe, 0, (uint)spot.RequiredFishingLevel);
                return;
            }
            if (client.ActiveCharacter.Asda2Inventory.FreeRegularSlotsCount < 1)
            {
                SendFishingStartedResponse(client, Asda2StartFishStatus.NotEnoughtSpace);
                return;
            }
            var success = CharacterFormulas.CalcFishingSuccess(client.ActiveCharacter.FishingLevel, spot.RequiredFishingLevel, client.ActiveCharacter.Asda2Luck);

            if (!success)
            {
                SendFishingEndedResponse(client, Asda2EndFishingStatus.Ok, 0, bait, null);
                return;
            }
            var fishSize =
                (short)
                Util.Utility.Random(ft.MinLength,
                                    ft.MaxLength);

            fishSize = (short)(fishSize + fishSize * client.ActiveCharacter.GetIntMod(StatModifierInt.Asda2FishingGauge) / 100 * (client.ActiveCharacter.GodMode ? 10 : 1));
            if (CharacterFormulas.CalcFishingLevelRised(client.ActiveCharacter.FishingLevel) && client.ActiveCharacter.Record.FishingLevel < spot.RequiredFishingLevel + 80)
            {
                client.ActiveCharacter.Record.FishingLevel++;
            }

            client.ActiveCharacter.GuildPoints += CharacterFormulas.FishingGuildPoints;

            Asda2Item item   = null;
            var       err    = client.ActiveCharacter.Asda2Inventory.TryAdd((int)ft.ItemTemplate.ItemId, 1, true, ref item);
            var       resLog = Log.Create(Log.Types.ItemOperations, LogSourceType.Character, client.ActiveCharacter.EntryId)
                               .AddAttribute("source", 0, "fishing")
                               .AddItemAttributes(item)
                               .Write();

            client.ActiveCharacter.Map.AddMessage(() =>
            {
                if (err != Asda2InventoryError.Ok)
                {
                    SendFishingEndedResponse(client, Asda2EndFishingStatus.NoSpace, 0, bait, null);
                    return;
                }
                foreach (var registeredFishingBook in client.ActiveCharacter.RegisteredFishingBooks.Values)
                {
                    registeredFishingBook.OnCatchFish(item.ItemId, fishSize);
                }
                client.ActiveCharacter.GainXp(
                    CharacterFormulas.CalcExpForFishing(client.ActiveCharacter.Level,
                                                        client.ActiveCharacter.FishingLevel, item.Template.Quality,
                                                        spot.RequiredFishingLevel, fishSize),
                    "fishing");
                SendFishingEndedResponse(client, Asda2EndFishingStatus.Ok, fishSize, bait, item);
                SendSomeOneStartedFishingResponse(client.ActiveCharacter, (int)ft.ItemTemplate.Id, fishSize);
                Asda2TitleChecker.OnSuccessFishing(client.ActiveCharacter, (int)ft.ItemTemplate.Id, fishSize);
            });
        }