private static void HandleStart(GameSession session, PacketReader packet) { string uuid = packet.ReadMapleString(); MapInteractObject interactObject = MapEntityStorage.GetInteractObject(session.Player.MapId).FirstOrDefault(x => x.Uuid == uuid); if (interactObject.Type == InteractObjectType.Gathering) { // things to do when player starts gathering } }
// for binoculars this shows "You get a good look at the area" // for extractor it does nothing public static Packet Extra(MapInteractObject interactObject) { PacketWriter pWriter = PacketWriter.Of(SendOp.INTERACT_OBJECT); pWriter.WriteEnum(InteractObjectMode.Extra); pWriter.WriteByte(); pWriter.WriteShort((short)interactObject.Uuid.Length); pWriter.WriteString(interactObject.Uuid); pWriter.WriteEnum(interactObject.Type); return(pWriter); }
public static Packet UseObject(MapInteractObject interactObject, short result = 0, int numDrops = 0) { PacketWriter pWriter = PacketWriter.Of(SendOp.INTERACT_OBJECT); pWriter.WriteEnum(InteractObjectMode.Use); pWriter.WriteShort((short)interactObject.Uuid.Length); pWriter.WriteString(interactObject.Uuid); pWriter.WriteEnum(interactObject.Type); if (interactObject.Type == InteractObjectType.Gathering) { pWriter.WriteShort(result); pWriter.WriteInt(numDrops); } return(pWriter); }
private static void HandleUse(GameSession session, PacketReader packet) { string uuid = packet.ReadMapleString(); IFieldObject <InteractObject> interactObject = session.FieldManager.State.InteractObjects[uuid]; if (interactObject == null) { return; } MapInteractObject mapObject = MapEntityStorage.GetInteractObject(session.Player.MapId).FirstOrDefault(x => x.Uuid == uuid); int numDrop = 0; switch (interactObject.Value.Type) { case InteractObjectType.Binoculars: QuestHelper.UpdateExplorationQuest(session, mapObject.InteractId.ToString(), "interact_object_rep"); break; case InteractObjectType.Gathering: RecipeMetadata recipe = RecipeMetadataStorage.GetRecipe(mapObject.RecipeId); session.Player.Levels.GainMasteryExp((MasteryType)recipe.MasteryType, 0); long currentMastery = session.Player.Levels.MasteryExp.FirstOrDefault(x => x.Type == (MasteryType)recipe.MasteryType).CurrentExp; if (currentMastery < recipe.RequireMastery) { return; } session.Player.IncrementGatheringCount(mapObject.RecipeId, 0); int numCount = session.Player.GatheringCount[mapObject.RecipeId].Current; List <RecipeItem> items = RecipeMetadataStorage.GetResult(recipe); int masteryDiffFactor = numCount switch { int n when n < recipe.HighPropLimitCount => MasteryFactorMetadataStorage.GetFactor(0), int n when n < recipe.NormalPropLimitCount => MasteryFactorMetadataStorage.GetFactor(1), int n when n < (int)(recipe.NormalPropLimitCount * 1.3) => MasteryFactorMetadataStorage.GetFactor(2), _ => MasteryFactorMetadataStorage.GetFactor(3), }; foreach (RecipeItem item in items) { int prob = RarityChance[item.Rarity] * masteryDiffFactor / 10000; if (RandomProvider.Get().Next(100) >= prob) { continue; } for (int i = 0; i < item.Amount; i++) { session.FieldManager.AddItem(session, new Item(item.Id)); } numDrop += item.Amount; } if (numDrop > 0) { session.Player.IncrementGatheringCount(mapObject.RecipeId, numDrop); session.Player.Levels.GainMasteryExp((MasteryType)recipe.MasteryType, recipe.RewardMastery); } break; case InteractObjectType.AdBalloon: session.Send(PlayerHostPacket.AdBalloonWindow(interactObject)); return; default: break; } session.Send(InteractObjectPacket.UseObject(mapObject, (short)(numDrop > 0 ? 0 : 1), numDrop)); session.Send(InteractObjectPacket.Extra(mapObject)); }
private static void HandleUse(GameSession session, PacketReader packet) { string uuid = packet.ReadMapleString(); MapInteractObject interactObject = MapEntityStorage.GetInteractObject(session.Player.MapId).FirstOrDefault(x => x.Uuid == uuid); int numDrop = 0; if (interactObject == null) { return; } if (interactObject.Type == InteractObjectType.Binoculars) { QuestHelper.UpdateExplorationQuest(session, interactObject.InteractId.ToString(), "interact_object_rep"); } else if (interactObject.Type == InteractObjectType.Gathering) { RecipeMetadata recipe = RecipeMetadataStorage.GetRecipe(interactObject.RecipeId); long requireMastery = int.Parse(recipe.RequireMastery); Enums.MasteryType type = (Enums.MasteryType) int.Parse(recipe.MasteryType); session.Player.Levels.GainMasteryExp(type, 0); long currentMastery = session.Player.Levels.MasteryExp.FirstOrDefault(x => x.Type == type).CurrentExp; if (currentMastery < requireMastery) { return; } session.Player.IncrementGatheringCount(interactObject.RecipeId, 0); int numCount = session.Player.GatheringCount[interactObject.RecipeId].Current; List <RecipeItem> items = RecipeMetadataStorage.GetResult(recipe); Random rand = new Random(); int masteryDiffFactor = numCount switch { int n when n < recipe.HighPropLimitCount => MasteryFactorMetadataStorage.GetFactor(0), int n when n < recipe.NormalPropLimitCount => MasteryFactorMetadataStorage.GetFactor(1), int n when n < (int)(recipe.NormalPropLimitCount * 1.3) => MasteryFactorMetadataStorage.GetFactor(2), _ => MasteryFactorMetadataStorage.GetFactor(3), }; foreach (RecipeItem item in items) { int prob = (int)(RarityChance[item.Rarity] * masteryDiffFactor) / 10000; if (rand.Next(100) >= prob) { continue; } for (int i = 0; i < item.Amount; i++) { session.FieldManager.AddItem(session, new Item(item.Id)); } numDrop += item.Amount; } if (numDrop > 0) { session.Player.IncrementGatheringCount(interactObject.RecipeId, numDrop); session.Player.Levels.GainMasteryExp(type, recipe.RewardMastery); } } session.Send(InteractObjectPacket.UseObject(interactObject, (short)(numDrop > 0 ? 0 : 1), numDrop)); session.Send(InteractObjectPacket.Extra(interactObject)); }