public static void AddMastery(GameSession session, FishMetadata fish, bool newFish) { if (newFish) { int exp = fish.Rarity * 2; session.Player.Levels.GainMasteryExp(MasteryType.Fishing, exp); session.Send(FishingPacket.IncreaseMastery(MasteryType.Fishing, fish.Id, exp)); return; } int expChance; Random rnd = Random.Shared; MasteryExp masteryExp = session.Player.Levels.MasteryExp.FirstOrDefault(x => x.Type == MasteryType.Fishing); FishingSpotMetadata fishingSpot = FishingSpotMetadataStorage.GetMetadata(session.Player.MapId); if (masteryExp.CurrentExp > fishingSpot.MaxMastery) { expChance = rnd.Next(0, 200); // decrease chance of gaining mastery by half } else { expChance = rnd.Next(0, 100); } if (expChance <= 10) { int exp = rnd.Next(1, 3); session.Player.Levels.GainMasteryExp(MasteryType.Fishing, exp); session.Send(FishingPacket.IncreaseMastery(MasteryType.Fishing, fish.Id, exp)); } }
private static void HandlePrepareFishing(GameSession session, PacketReader packet) { long fishingRodUid = packet.ReadLong(); MasteryExp masteryExp = session.Player.Levels.MasteryExp.FirstOrDefault(x => x.Type == MasteryType.Fishing); if (masteryExp == null) // add mastery to list { masteryExp = new MasteryExp(MasteryType.Fishing); session.Player.Levels.MasteryExp.Add(masteryExp); } if (!FishingSpotMetadataStorage.CanFish(session.Player.MapId, masteryExp.CurrentExp)) { session.Send(FishingPacket.Notice((short)FishingNotice.MasteryTooLowForMap)); return; } if (!session.Player.Inventory.Items.ContainsKey(fishingRodUid)) { session.Send(FishingPacket.Notice((short)FishingNotice.InvalidFishingRod)); return; } Item fishingRod = session.Player.Inventory.Items[fishingRodUid]; FishingRodMetadata rodMetadata = FishingRodMetadataStorage.GetMetadata(fishingRod.Function.Id); if (rodMetadata.MasteryLimit < masteryExp.CurrentExp) { session.Send(FishingPacket.Notice((short)FishingNotice.MasteryTooLowForRod)); } int direction = Direction.GetClosestDirection(session.FieldPlayer.Rotation); CoordF startCoord = Block.ClosestBlock(session.FieldPlayer.Coord); List <MapBlock> fishingBlocks = CollectFishingBlocks(startCoord, direction, session.Player.MapId); if (fishingBlocks.Count == 0) { session.Send(FishingPacket.Notice((short)FishingNotice.CanOnlyFishNearWater)); return; } session.Player.FishingRod = fishingRod; // Adding GuideObject CoordF guideBlock = GetObjectBlock(fishingBlocks, session.FieldPlayer.Coord); guideBlock.Z += Block.BLOCK_SIZE; // sits on top of the block GuideObject guide = new GuideObject(1, session.Player.CharacterId); IFieldObject <GuideObject> fieldGuide = session.FieldManager.RequestFieldObject(guide); fieldGuide.Coord = guideBlock; session.Player.Guide = fieldGuide; session.FieldManager.AddGuide(fieldGuide); session.Send(FishingPacket.LoadFishTiles(fishingBlocks, rodMetadata.ReduceTime)); session.FieldManager.BroadcastPacket(GuideObjectPacket.Add(fieldGuide)); session.Send(FishingPacket.PrepareFishing(fishingRodUid)); }
public void GainMasteryExp(MasteryType type, long amount) { MasteryExp masteryExp = MasteryExp.FirstOrDefault(x => x.Type == type); if (masteryExp == null || amount <= 0) { return; } // user already has some exp in mastery, so simply update it Session.Send(MasteryPacket.SetExp(type, masteryExp.CurrentExp += amount)); int currLevel = MasteryMetadataStorage.GetGradeFromXP(type, masteryExp.CurrentExp); if (currLevel <= masteryExp.Level) { return; } masteryExp.Level = currLevel; TrophyManager.OnGainMasteryLevel(Player, masteryExp.Type); }