示例#1
0
        private static void HandleUse(GameSession session, PacketReader packet)
        {
            string           uuid  = packet.ReadMapleString();
            MapInteractActor actor = MapEntityStorage.GetInteractActors(session.Player.MapId).FirstOrDefault(x => x.Uuid == uuid);

            if (actor == null)
            {
                return;
            }
            if (actor.Type == InteractActorType.Binoculars)
            {
                List <QuestStatus> questList = session.Player.QuestList;
                foreach (QuestStatus item in questList.Where(x => x.Basic.QuestID >= 72000000 && x.Condition != null))
                {
                    QuestCondition condition = item.Condition.FirstOrDefault(x => x.Code != "" && int.Parse(x.Code) == actor.Id);
                    if (condition == null)
                    {
                        continue;
                    }

                    item.Completed         = true;
                    item.CompleteTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    session.Send(QuestPacket.CompleteExplorationGoal(item.Basic.QuestID));
                    session.Send(QuestPacket.CompleteQuest(item.Basic.QuestID));
                    break;
                }
            }

            session.Send(InteractActorPacket.UseObject(actor));
            session.Send(InteractActorPacket.Extra(actor));
        }
示例#2
0
        public FieldManager(int mapId)
        {
            MapId       = mapId;
            BoundingBox = MapEntityStorage.GetBoundingBox(mapId);
            // Load default npcs for map from config
            foreach (MapNpc npc in MapEntityStorage.GetNpcs(mapId))
            {
                IFieldObject <Npc> fieldNpc = RequestFieldObject(new Npc(npc.Id)
                {
                    ZRotation = (short)(npc.Rotation.Z * 10)
                });
                IFieldObject <Mob> fieldMob = RequestFieldObject(new Mob(npc.Id)
                {
                    ZRotation = (short)(npc.Rotation.Z * 10)
                });

                if (fieldNpc.Value.Friendly == 2)
                {
                    fieldNpc.Coord = npc.Coord.ToFloat();
                    AddNpc(fieldNpc);
                }
                else
                {
                    fieldMob.Coord = npc.Coord.ToFloat();
                    AddMob(fieldMob);
                }
            }

            // Load default portals for map from config
            foreach (MapPortal portal in MapEntityStorage.GetPortals(mapId))
            {
                IFieldObject <Portal> fieldPortal = RequestFieldObject(new Portal(portal.Id)
                {
                    IsVisible        = portal.Flags.HasFlag(MapPortalFlag.Visible),
                    IsEnabled        = portal.Flags.HasFlag(MapPortalFlag.Enabled),
                    IsMinimapVisible = portal.Flags.HasFlag(MapPortalFlag.MinimapVisible),
                    Rotation         = portal.Rotation.ToFloat(),
                    TargetMapId      = portal.Target,
                });
                fieldPortal.Coord = portal.Coord.ToFloat();
                AddPortal(fieldPortal);
            }

            // Load default InteractActors
            List <IFieldObject <InteractActor> > actors = new List <IFieldObject <InteractActor> > {
            };

            foreach (MapInteractActor actor in MapEntityStorage.GetInteractActors(mapId))
            {
                // TODO: Group these fieldActors by their correct packet type.
                actors.Add(RequestFieldObject(new InteractActor(actor.Uuid, actor.Name, actor.Type)
                {
                }));
            }
            AddInteractActor(actors);
        }
        private static void HandleStart(GameSession session, PacketReader packet)
        {
            string           uuid  = packet.ReadMapleString();
            MapInteractActor actor = MapEntityStorage.GetInteractActors(session.Player.MapId).FirstOrDefault(x => x.Uuid == uuid);

            if (actor.Type == InteractActorType.Gathering)
            {
                // things to do when player starts gathering
            }
        }
示例#4
0
        public FieldManager(int mapId)
        {
            MapId       = mapId;
            BoundingBox = MapEntityStorage.GetBoundingBox(mapId);
            // Load default npcs for map from config
            foreach (MapNpc npc in MapEntityStorage.GetNpcs(mapId))
            {
                IFieldObject <Npc> fieldNpc = RequestFieldObject(new Npc(npc.Id)
                {
                    ZRotation = (short)(npc.Rotation.Z * 10)
                });

                if (fieldNpc.Value.Friendly == 2)
                {
                    fieldNpc.Coord = npc.Coord.ToFloat();
                    AddNpc(fieldNpc);
                }
                else
                {
                    // NPC is an enemy
                    IFieldObject <Mob> fieldMob = RequestFieldObject(new Mob(npc.Id)
                    {
                        ZRotation = (short)(npc.Rotation.Z * 10)
                    });

                    fieldMob.Coord = npc.Coord.ToFloat();
                    AddMob(fieldMob);
                }
            }

            // Spawn map's mobs at the mob spawners
            foreach (MapMobSpawn mobSpawn in MapEntityStorage.GetMobSpawns(mapId))
            {
                if (mobSpawn.SpawnData == null)
                {
                    Debug.WriteLine($"Missing mob spawn data: {mobSpawn}");
                    continue;
                }
                IFieldObject <MobSpawn> fieldMobSpawn = RequestFieldObject(new MobSpawn(mobSpawn));
                fieldMobSpawn.Coord = mobSpawn.Coord.ToFloat();
                State.AddMobSpawn(fieldMobSpawn);
                SpawnMobs(fieldMobSpawn);
            }

            // Load default portals for map from config
            foreach (MapPortal portal in MapEntityStorage.GetPortals(mapId))
            {
                IFieldObject <Portal> fieldPortal = RequestFieldObject(new Portal(portal.Id)
                {
                    IsVisible        = portal.Flags.HasFlag(MapPortalFlag.Visible),
                    IsEnabled        = portal.Flags.HasFlag(MapPortalFlag.Enabled),
                    IsMinimapVisible = portal.Flags.HasFlag(MapPortalFlag.MinimapVisible),
                    Rotation         = portal.Rotation.ToFloat(),
                    TargetMapId      = portal.Target,
                });
                fieldPortal.Coord = portal.Coord.ToFloat();
                AddPortal(fieldPortal);
            }

            // Load default InteractActors
            List <IFieldObject <InteractActor> > actors = new List <IFieldObject <InteractActor> > {
            };

            foreach (MapInteractActor actor in MapEntityStorage.GetInteractActors(mapId))
            {
                // TODO: Group these fieldActors by their correct packet type.
                actors.Add(RequestFieldObject(new InteractActor(actor.Uuid, actor.Name, actor.Type)
                {
                }));
            }
            AddInteractActor(actors);

            string mapName = MapMetadataStorage.GetMetadata(mapId).Name;

            Triggers = TriggerLoader.GetTriggers(mapName).Select(initializer =>
            {
                TriggerContext context  = new TriggerContext(this, Logger);
                TriggerState startState = initializer.Invoke(context);
                return(new TriggerScript(context, startState));
            }).ToArray();
        }
        private static void HandleUse(GameSession session, PacketReader packet)
        {
            string           uuid  = packet.ReadMapleString();
            MapInteractActor actor = MapEntityStorage.GetInteractActors(session.Player.MapId).FirstOrDefault(x => x.Uuid == uuid);
            int numDrop            = 0;

            if (actor == null)
            {
                return;
            }
            if (actor.Type == InteractActorType.Binoculars)
            {
                CheckForExplorationQuest(session, actor);
            }
            else if (actor.Type == InteractActorType.Gathering)
            {
                RecipeMetadata    recipe         = RecipeMetadataStorage.GetRecipe(actor.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(actor.RecipeId, 0);
                int numCount = session.Player.GatheringCount[actor.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(actor.RecipeId, numDrop);
                    session.Player.Levels.GainMasteryExp(type, recipe.RewardMastery);
                }
            }
            session.Send(InteractActorPacket.UseObject(actor, (short)(numDrop > 0 ? 0 : 1), numDrop));
            session.Send(InteractActorPacket.Extra(actor));
        }
        private static void HandleUse(GameSession session, PacketReader packet)
        {
            string           uuid  = packet.ReadMapleString();
            MapInteractActor actor = MapEntityStorage.GetInteractActors(session.Player.MapId).FirstOrDefault(x => x.Uuid == uuid);
            int numDrop            = 0;

            if (actor == null)
            {
                return;
            }
            if (actor.Type == InteractActorType.Binoculars)
            {
                List <QuestStatus> questList = session.Player.QuestList;
                foreach (QuestStatus item in questList.Where(x => x.Basic.QuestID >= 72000000 && x.Condition != null))
                {
                    QuestCondition condition = item.Condition.FirstOrDefault(x => x.Code != "" && int.Parse(x.Code) == actor.InteractId);
                    if (condition == null)
                    {
                        continue;
                    }

                    item.Completed         = true;
                    item.CompleteTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    session.Send(QuestPacket.CompleteExplorationGoal(item.Basic.QuestID));
                    session.Send(QuestPacket.CompleteQuest(item.Basic.QuestID));
                    break;
                }
            }
            else if (actor.Type == InteractActorType.Gathering)
            {
                RecipeMetadata    recipe         = RecipeMetadataStorage.GetRecipe(actor.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(actor.RecipeId, 0);
                int numCount = session.Player.GatheringCount[actor.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(actor.RecipeId, numDrop);
                    session.Player.Levels.GainMasteryExp(type, recipe.RewardMastery);
                }
            }
            session.Send(InteractActorPacket.UseObject(actor, numDrop > 0 ? 0 : 1, numDrop));
            session.Send(InteractActorPacket.Extra(actor));
        }