Beispiel #1
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            if (function == 0)
            {
                int srcMapId = packet.ReadInt();
                if (srcMapId != session.FieldManager.MapId)
                {
                    return;
                }

                int       portalId  = packet.ReadInt();
                MapPortal srcPortal = MapEntityStorage.GetPortals(srcMapId)
                                      .FirstOrDefault(portal => portal.Id == portalId);
                if (srcPortal == default)
                {
                    logger.Warning($"Unable to find portal:{portalId} in map:{srcMapId}");
                    return;
                }

                MapPortal dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                                      .FirstOrDefault(portal => portal.Target == srcMapId);
                if (dstPortal == default)
                {
                    logger.Warning($"Unable to find return portal to map:{srcMapId} in map:{srcPortal.Target}");
                    return;
                }

                // TODO: There needs to be a more centralized way to set coordinates...
                session.Player.MapId = srcPortal.Target;
                session.Player.Coord = dstPortal.Coord.ToFloat();
                session.Send(FieldPacket.RequestEnter(session.FieldPlayer));
            }
        }
Beispiel #2
0
        public FieldManager(int mapId)
        {
            this.MapId = mapId;

            // Load default npcs for map from config
            foreach (MapNpc npc in MapEntityStorage.GetNpcs(mapId))
            {
                IFieldObject <Npc> fieldNpc = RequestFieldObject(new Npc(npc.Id)
                {
                    Rotation = (short)(npc.Rotation.Z * 10)
                });
                fieldNpc.Coord = npc.Coord.ToFloat();
                AddTestNpc(fieldNpc);
            }

            // 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);
            }
        }
Beispiel #3
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            if (function == 0)
            {
                int srcMapId = packet.ReadInt();
                if (srcMapId != session.FieldManager.MapId)
                {
                    return;
                }

                int       portalId  = packet.ReadInt();
                MapPortal srcPortal = MapEntityStorage.GetPortals(srcMapId)
                                      .FirstOrDefault(portal => portal.Id == portalId);
                if (srcPortal == default)
                {
                    Logger.Warning($"Unable to find portal:{portalId} in map:{srcMapId}");
                    return;
                }

                MapPortal dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                                      .FirstOrDefault(portal => portal.Target == srcMapId);
                if (dstPortal == default)
                {
                    Logger.Warning($"Unable to find return portal to map:{srcMapId} in map:{srcPortal.Target}");
                    return;
                }

                // TODO: There needs to be a more centralized way to set coordinates...
                session.Player.MapId    = srcPortal.Target;
                session.Player.Rotation = dstPortal.Rotation.ToFloat();
                session.Player.Coord    = dstPortal.Coord.ToFloat();

                if (dstPortal.Name == "Portal_cube") // spawn on the next block if portal is a cube
                {
                    if (dstPortal.Rotation.Z == 0)   // Facing SE
                    {
                        session.Player.Coord.Y -= Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == 90) // Facing NE
                    {
                        session.Player.Coord.X += Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == 180) // Facing NW
                    {
                        session.Player.Coord.Y += Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == 270) // Facing SW
                    {
                        session.Player.Coord.X -= Block.BLOCK_SIZE;
                    }
                }

                session.Player.SafeBlock = session.Player.Coord;
                session.Send(FieldPacket.RequestEnter(session.FieldPlayer));
            }
        }
Beispiel #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)
                });
                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 HandleBeauty(GameSession session)
    {
        MapPortal portal = MapEntityStorage.GetPortals(session.Player.MapId).FirstOrDefault(portal => portal.Id == 99); // unsure how the portalId is determined

        if (portal is null)
        {
            return;
        }

        session.Send(NpcTalkPacket.Action(ActionType.Portal, "", "", portal.Id));
        NpcMetadata npcTarget = NpcMetadataStorage.GetNpcMetadata(session.Player.NpcTalk.Npc.Id);

        session.Player.ShopId = npcTarget.ShopId;

        switch (npcTarget.ShopId)
        {
        case 500:                                                                                  // Dr Dixon
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "face")); // unsure how these strings are determined
            break;

        case 501:     // Dr Zenko
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "skin"));
            break;

        case 504:     // Rosetta
        case 509:     //Lolly
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,style"));
            break;

        case 505:     // Ren
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "makeup"));
            break;

        case 506:     // Douglas
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "itemcolor"));
            break;

        case 507:     // Mirror
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "mirror"));
            break;

        case 508:     // Paulie
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,random"));
            break;

        case 510:     // Mino
            session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,styleSave"));
            break;
        }

        session.Send(UserMoveByPortalPacket.Move(session.Player.FieldPlayer, portal.Coord.ToFloat(), portal.Rotation.ToFloat()));
    }
Beispiel #6
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);
                }
                if (fieldMob.Value.Friendly != 2)
                {
                    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);
            }
        }
Beispiel #7
0
        public static void HandleInstanceMove(GameSession session, int mapId)
        {
            // TODO: Revise to include instancing

            if (MapEntityStorage.HasSafePortal(session.Player.MapId))
            {
                session.Player.ReturnCoord = session.FieldPlayer.Coord;
                session.Player.ReturnMapId = session.Player.MapId;
            }

            MapPortal dstPortal = MapEntityStorage.GetPortals(mapId).First(x => x.Id == 1);

            if (dstPortal == null)
            {
                return;
            }

            session.Player.MapId    = mapId;
            session.Player.Rotation = dstPortal.Rotation.ToFloat();
            session.Player.Coord    = dstPortal.Coord.ToFloat();
            session.Send(FieldPacket.RequestEnter(session.FieldPlayer));
        }
Beispiel #8
0
        private static void HandleMove(GameSession session, PacketReader packet)
        {
            int srcMapId = packet.ReadInt();

            if (srcMapId != session.FieldManager.MapId)
            {
                return;
            }

            int portalId = packet.ReadInt();
            IFieldObject <Portal> fieldPortal = session.FieldManager.State.Portals.Values.FirstOrDefault(x => x.Value.Id == portalId);

            if (fieldPortal == default)
            {
                Logger.Warn($"Unable to find portal:{portalId} in map:{srcMapId}");
                return;
            }

            Portal srcPortal = fieldPortal.Value;

            switch (srcPortal.PortalType)
            {
            case PortalTypes.Field:
                break;

            case PortalTypes.DungeonReturnToLobby:
                DungeonSession dungeonSession = GameServer.DungeonManager.GetDungeonSessionByInstanceId(session.Player.InstanceId);
                if (dungeonSession == null)
                {
                    return;
                }
                session.Player.Warp(dungeonSession.DungeonLobbyId, instanceId: dungeonSession.DungeonInstanceId);
                return;

            case PortalTypes.LeaveDungeon:
                HandleLeaveInstance(session);
                return;

            case PortalTypes.Home:
                HandleHomePortal(session, fieldPortal);
                return;

            default:
                Logger.Warn($"unknown portal type id: {srcPortal.PortalType}");
                break;
            }

            if (!MapEntityStorage.HasSafePortal(srcMapId) || srcPortal.TargetMapId == 0) // map is instance only
            {
                HandleLeaveInstance(session);
                return;
            }

            MapPortal dstPortal = MapEntityStorage.GetPortals(srcPortal.TargetMapId)
                                  .FirstOrDefault(portal => portal.Id == srcPortal.TargetPortalId); // target map's portal id == source portal's targetPortalId

            if (dstPortal == default)
            {
                session.Player.Warp(srcPortal.TargetMapId);
                return;
            }

            CoordF coord = dstPortal.Coord.ToFloat();

            if (dstPortal.Name == "Portal_cube") // spawn on the next block if portal is a cube
            {
                if (dstPortal.Rotation.Z == Direction.SOUTH_EAST)
                {
                    coord.Y -= Block.BLOCK_SIZE;
                }
                else if (dstPortal.Rotation.Z == Direction.NORTH_EAST)
                {
                    coord.X += Block.BLOCK_SIZE;
                }
                else if (dstPortal.Rotation.Z == Direction.NORTH_WEST)
                {
                    coord.Y += Block.BLOCK_SIZE;
                }
                else if (dstPortal.Rotation.Z == Direction.SOUTH_WEST)
                {
                    coord.X -= Block.BLOCK_SIZE;
                }
            }

            session.Player.Warp(srcPortal.TargetMapId, coord, dstPortal.Rotation.ToFloat());
        }
Beispiel #9
0
        public FieldManager(Player player)
        {
            MapId       = player.MapId;
            InstanceId  = player.InstanceId;
            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.IsVisible,
                    IsEnabled        = portal.Enable,
                    IsMinimapVisible = portal.MinimapVisible,
                    Rotation         = portal.Rotation.ToFloat(),
                    TargetMapId      = portal.Target,
                    TargetPortalId   = portal.TargetPortalId,
                    PortalType       = portal.PortalType
                });
                fieldPortal.Coord = portal.Coord.ToFloat();
                AddPortal(fieldPortal);
            }

            MapMetadata mapMetadata = MapMetadataStorage.GetMetadata(MapId);

            if (mapMetadata != null)
            {
                string xBlockName = mapMetadata.XBlockName;
                Triggers = TriggerLoader.GetTriggers(xBlockName).Select(initializer =>
                {
                    TriggerContext context  = new TriggerContext(this, Logger);
                    TriggerState startState = initializer.Invoke(context);
                    return(new TriggerScript(context, startState));
                }).ToArray();
            }

            foreach (MapTriggerMesh mapTriggerMesh in MapEntityStorage.GetTriggerMeshes(MapId))
            {
                if (mapTriggerMesh != null)
                {
                    TriggerMesh triggerMesh = new TriggerMesh(mapTriggerMesh.Id, mapTriggerMesh.IsVisible);
                    State.AddTriggerObject(triggerMesh);
                }
            }

            foreach (MapTriggerEffect mapTriggerEffect in MapEntityStorage.GetTriggerEffects(MapId))
            {
                if (mapTriggerEffect != null)
                {
                    TriggerEffect triggerEffect = new TriggerEffect(mapTriggerEffect.Id, mapTriggerEffect.IsVisible);
                    State.AddTriggerObject(triggerEffect);
                }
            }

            foreach (MapTriggerActor mapTriggerActor in MapEntityStorage.GetTriggerActors(MapId))
            {
                if (mapTriggerActor != null)
                {
                    TriggerActor triggerActor = new TriggerActor(mapTriggerActor.Id, mapTriggerActor.IsVisible, mapTriggerActor.InitialSequence);
                    State.AddTriggerObject(triggerActor);
                }
            }

            foreach (MapTriggerCamera mapTriggerCamera in MapEntityStorage.GetTriggerCameras(MapId))
            {
                if (mapTriggerCamera != null)
                {
                    TriggerCamera triggerCamera = new TriggerCamera(mapTriggerCamera.Id, mapTriggerCamera.IsEnabled);
                    State.AddTriggerObject(triggerCamera);
                }
            }

            foreach (MapTriggerCube mapTriggerCube in MapEntityStorage.GetTriggerCubes(MapId))
            {
                if (mapTriggerCube != null)
                {
                    TriggerCube triggerCube = new TriggerCube(mapTriggerCube.Id, mapTriggerCube.IsVisible);
                    State.AddTriggerObject(triggerCube);
                }
            }

            foreach (MapTriggerLadder mapTriggerLadder in MapEntityStorage.GetTriggerLadders(MapId))
            {
                if (mapTriggerLadder != null)
                {
                    TriggerLadder triggerLadder = new TriggerLadder(mapTriggerLadder.Id, mapTriggerLadder.IsVisible);
                    State.AddTriggerObject(triggerLadder);
                }
            }

            foreach (MapTriggerRope mapTriggerRope in MapEntityStorage.GetTriggerRopes(MapId))
            {
                if (mapTriggerRope != null)
                {
                    TriggerRope triggerRope = new TriggerRope(mapTriggerRope.Id, mapTriggerRope.IsVisible);
                    State.AddTriggerObject(triggerRope);
                }
            }

            foreach (MapTriggerSound mapTriggerSound in MapEntityStorage.GetTriggerSounds(MapId))
            {
                if (mapTriggerSound != null)
                {
                    TriggerSound triggerSound = new TriggerSound(mapTriggerSound.Id, mapTriggerSound.IsEnabled);
                    State.AddTriggerObject(triggerSound);
                }
            }

            foreach (MapTriggerSkill mapTriggerSkill in MapEntityStorage.GetTriggerSkills(MapId))
            {
                if (mapTriggerSkill != null)
                {
                    TriggerSkill triggerSkill = new TriggerSkill(mapTriggerSkill.Id, mapTriggerSkill.SkillId, mapTriggerSkill.SkillLevel, mapTriggerSkill.Count, mapTriggerSkill.Position);
                    IFieldObject <TriggerSkill> fieldTriggerSkill = RequestFieldObject(triggerSkill);
                    fieldTriggerSkill.Coord = fieldTriggerSkill.Value.Position;

                    State.AddTriggerSkills(fieldTriggerSkill);
                }
            }

            // Load breakables
            foreach (MapBreakableActorObject mapActor in MapEntityStorage.GetBreakableActors(MapId))
            {
                if (mapActor != null)
                {
                    BreakableActorObject actor = new BreakableActorObject(mapActor.EntityId, mapActor.IsEnabled, mapActor.HideDuration, mapActor.ResetDuration);
                    State.AddBreakable(actor);
                }
            }

            foreach (MapBreakableNifObject mapNif in MapEntityStorage.GetBreakableNifs(MapId))
            {
                if (mapNif != null)
                {
                    BreakableNifObject nif = new BreakableNifObject(mapNif.EntityId, mapNif.IsEnabled, mapNif.TriggerId, mapNif.HideDuration, mapNif.ResetDuration);
                    State.AddBreakable(nif);
                }
            }

            // Load interact objects
            foreach (MapInteractObject mapInteract in MapEntityStorage.GetInteractObjects(MapId))
            {
                if (mapInteract != null)
                {
                    InteractObject interactObject = new InteractObject(mapInteract.EntityId, mapInteract.InteractId, mapInteract.Type, InteractObjectState.Default);
                    State.AddInteractObject(interactObject);
                }
            }

            // Load cubes
            if (MapId == (int)Map.PrivateResidence)
            {
                Home home = GameServer.HomeManager.GetHomeById(player.VisitingHomeId);
                if (home != null)
                {
                    // Add cubes to state
                    Dictionary <long, Cube> cubes = home.FurnishingInventory;
                    foreach (Cube cube in cubes.Values.Where(x => x.PlotNumber == 1))
                    {
                        IFieldObject <Cube> ugcCube = RequestFieldObject(cube);
                        ugcCube.Coord    = cube.CoordF;
                        ugcCube.Rotation = cube.Rotation;
                        State.AddCube(ugcCube);
                    }

                    // Add portals to state
                    IEnumerable <Cube> cubePortals = cubes.Values.Where(x => x.Item.Id == 50400158);
                    foreach (Cube cubePortal in cubePortals)
                    {
                        Portal portal = new Portal(GuidGenerator.Int())
                        {
                            IsVisible        = true,
                            IsEnabled        = true,
                            IsMinimapVisible = false,
                            Rotation         = cubePortal.Rotation,
                            PortalType       = PortalTypes.Home
                        };

                        IFieldObject <Portal> fieldPortal = RequestFieldObject(portal);
                        fieldPortal.Coord = cubePortal.CoordF;
                        fieldPortal.Value.UGCPortalMethod = cubePortal.PortalSettings.Method;
                        if (!string.IsNullOrEmpty(cubePortal.PortalSettings.DestinationTarget))
                        {
                            switch (cubePortal.PortalSettings.Destination)
                            {
                            case UGCPortalDestination.PortalInHome:
                                fieldPortal.Value.TargetMapId = (int)Map.PrivateResidence;
                                break;

                            case UGCPortalDestination.SelectedMap:
                                fieldPortal.Value.TargetMapId = int.Parse(cubePortal.PortalSettings.DestinationTarget);
                                break;

                            case UGCPortalDestination.FriendHome:
                                fieldPortal.Value.TargetHomeAccountId = long.Parse(cubePortal.PortalSettings.DestinationTarget);
                                break;
                            }
                        }
                        cubePortal.PortalSettings.PortalObjectId = fieldPortal.ObjectId;
                        AddPortal(fieldPortal);
                    }
                }
            }
            else
            {
                List <Home> homes = GameServer.HomeManager.GetPlots(MapId);
                foreach (Home home in homes)
                {
                    Dictionary <long, Cube> cubes = home.FurnishingInventory;
                    foreach (Cube cube in cubes.Values.Where(x => x.PlotNumber != 1))
                    {
                        IFieldObject <Cube> ugcCube = RequestFieldObject(cube);
                        ugcCube.Coord    = cube.CoordF;
                        ugcCube.Rotation = cube.Rotation;
                        State.AddCube(ugcCube);
                    }
                }
            }

            if (MapEntityStorage.HasHealingSpot(MapId))
            {
                List <CoordS> healingSpots = MapEntityStorage.GetHealingSpot(MapId);
                if (State.HealingSpots.IsEmpty)
                {
                    foreach (CoordS coord in healingSpots)
                    {
                        int objectId = GuidGenerator.Int();
                        State.AddHealingSpot(RequestFieldObject(new HealingSpot(objectId, coord)));
                    }
                }
            }
        }
        public FieldManager(int mapId, long instanceId)
        {
            MapId       = mapId;
            InstanceId  = instanceId;
            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.IsVisible,
                    IsEnabled        = portal.Enable,
                    IsMinimapVisible = portal.MinimapVisible,
                    Rotation         = portal.Rotation.ToFloat(),
                    TargetMapId      = portal.Target,
                    PortalType       = portal.PortalType
                });
                fieldPortal.Coord = portal.Coord.ToFloat();
                AddPortal(fieldPortal);
            }

            // Load default InteractObjects
            List <IFieldObject <InteractObject> > actors = new List <IFieldObject <InteractObject> > {
            };

            foreach (MapInteractObject interactObject in MapEntityStorage.GetInteractObject(mapId))
            {
                // TODO: Group these fieldActors by their correct packet type.
                actors.Add(RequestFieldObject(new InteractObject(interactObject.Uuid, interactObject.Name, interactObject.Type)
                {
                }));
            }
            AddInteractObject(actors);

            MapMetadata mapMetadata = MapMetadataStorage.GetMetadata(mapId);

            if (mapMetadata != null)
            {
                string xBlockName = mapMetadata.XBlockName;
                Triggers = TriggerLoader.GetTriggers(xBlockName).Select(initializer =>
                {
                    TriggerContext context  = new TriggerContext(this, Logger);
                    TriggerState startState = initializer.Invoke(context);
                    return(new TriggerScript(context, startState));
                }).ToArray();
            }

            foreach (MapTriggerMesh mapTriggerMesh in MapEntityStorage.GetTriggerMeshes(mapId))
            {
                if (mapTriggerMesh != null)
                {
                    TriggerMesh triggerMesh = new TriggerMesh(mapTriggerMesh.Id, mapTriggerMesh.IsVisible);
                    State.AddTriggerObject(triggerMesh);
                }
            }

            foreach (MapTriggerEffect mapTriggerEffect in MapEntityStorage.GetTriggerEffects(mapId))
            {
                if (mapTriggerEffect != null)
                {
                    TriggerEffect triggerEffect = new TriggerEffect(mapTriggerEffect.Id, mapTriggerEffect.IsVisible);
                    State.AddTriggerObject(triggerEffect);
                }
            }

            foreach (MapTriggerActor mapTriggerActor in MapEntityStorage.GetTriggerActors(mapId))
            {
                if (mapTriggerActor != null)
                {
                    TriggerActor triggerActor = new TriggerActor(mapTriggerActor.Id, mapTriggerActor.IsVisible, mapTriggerActor.InitialSequence);
                    State.AddTriggerObject(triggerActor);
                }
            }

            foreach (MapTriggerCamera mapTriggerCamera in MapEntityStorage.GetTriggerCameras(mapId))
            {
                if (mapTriggerCamera != null)
                {
                    TriggerCamera triggerCamera = new TriggerCamera(mapTriggerCamera.Id, mapTriggerCamera.IsEnabled);
                    State.AddTriggerObject(triggerCamera);
                }
            }

            foreach (MapTriggerCube mapTriggerCube in MapEntityStorage.GetTriggerCubes(mapId))
            {
                if (mapTriggerCube != null)
                {
                    TriggerCube triggerCube = new TriggerCube(mapTriggerCube.Id, mapTriggerCube.IsVisible);
                    State.AddTriggerObject(triggerCube);
                }
            }

            foreach (MapTriggerLadder mapTriggerLadder in MapEntityStorage.GetTriggerLadders(mapId))
            {
                if (mapTriggerLadder != null)
                {
                    TriggerLadder triggerLadder = new TriggerLadder(mapTriggerLadder.Id, mapTriggerLadder.IsVisible);
                    State.AddTriggerObject(triggerLadder);
                }
            }

            foreach (MapTriggerRope mapTriggerRope in MapEntityStorage.GetTriggerRopes(mapId))
            {
                if (mapTriggerRope != null)
                {
                    TriggerRope triggerRope = new TriggerRope(mapTriggerRope.Id, mapTriggerRope.IsVisible);
                    State.AddTriggerObject(triggerRope);
                }
            }

            foreach (MapTriggerSound mapTriggerSound in MapEntityStorage.GetTriggerSounds(mapId))
            {
                if (mapTriggerSound != null)
                {
                    TriggerSound triggerSound = new TriggerSound(mapTriggerSound.Id, mapTriggerSound.IsEnabled);
                    State.AddTriggerObject(triggerSound);
                }
            }

            // Load breakables
            foreach (MapBreakableActorObject mapActor in MapEntityStorage.GetBreakableActors(mapId))
            {
                if (mapActor != null)
                {
                    BreakableActorObject actor = new BreakableActorObject(mapActor.EntityId, mapActor.IsEnabled, mapActor.HideDuration, mapActor.ResetDuration);
                    State.AddBreakable(actor);
                }
            }

            foreach (MapBreakableNifObject mapNif in MapEntityStorage.GetBreakableNifs(mapId))
            {
                if (mapNif != null)
                {
                    BreakableNifObject nif = new BreakableNifObject(mapNif.EntityId, mapNif.IsEnabled, mapNif.TriggerId, mapNif.HideDuration, mapNif.ResetDuration);
                    State.AddBreakable(nif);
                }
            }

            if (MapEntityStorage.HasHealingSpot(MapId))
            {
                List <CoordS> healingSpots = MapEntityStorage.GetHealingSpot(MapId);
                if (State.HealingSpots.IsEmpty)
                {
                    foreach (CoordS coord in healingSpots)
                    {
                        int objectId = GuidGenerator.Int();
                        State.AddHealingSpot(RequestFieldObject(new HealingSpot(objectId, coord)));
                    }
                }
            }
        }
Beispiel #11
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 HandleEnter(GameSession session, PacketReader packet)
        {
            int globalEventId  = packet.ReadInt();
            int selectionIndex = packet.ReadInt();

            GlobalEvent globalEvent = GameServer.GlobalEventManager.GetEventById(globalEventId);

            if (globalEvent == null)
            {
                return;
            }

            Map map = Map.Tria;

            switch (globalEvent.Events[selectionIndex])
            {
            case GlobalEventType.oxquiz:
                map = Map.MapleOXQuiz;
                break;

            case GlobalEventType.trap_master:
                map = Map.TrapMaster;
                break;

            case GlobalEventType.spring_beach:
                map = Map.SpringBeach;
                break;

            case GlobalEventType.crazy_runner:
                map = Map.CrazyRunners;
                break;

            case GlobalEventType.final_surviver:
                map = Map.SoleSurvivor;
                break;

            case GlobalEventType.great_escape:
                map = Map.LudibriumEscape;
                break;

            case GlobalEventType.dancedance_stop:
                map = Map.DanceDanceStop;
                break;

            case GlobalEventType.crazy_runner_shanghai:
                map = Map.ShanghaiCrazyRunners;
                break;

            case GlobalEventType.hideandseek:
                map = Map.HideAndSeek;
                break;

            case GlobalEventType.red_arena:
                map = Map.RedArena;
                break;

            case GlobalEventType.blood_mine:
                map = Map.CrimsonTearMine;
                break;

            case GlobalEventType.treasure_island:
                map = Map.TreasureIsland;
                break;

            case GlobalEventType.christmas_dancedance_stop:
                map = Map.HolidayDanceDanceStop;
                break;

            default:
                Logger.Warn($"Unknown Global Event: {globalEvent.Events[selectionIndex]}");
                return;
            }

            session.Player.Mount = null;
            MapPortal portal = MapEntityStorage.GetPortals((int)map).FirstOrDefault(portal => portal.Id == 1);

            session.Player.Warp((int)map, portal.Coord.ToFloat(), portal.Rotation.ToFloat());
        }
Beispiel #13
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            if (function == 0)
            {
                int srcMapId = packet.ReadInt();
                if (srcMapId != session.FieldManager.MapId)
                {
                    return;
                }

                int       portalId  = packet.ReadInt();
                MapPortal srcPortal = MapEntityStorage.GetPortals(srcMapId)
                                      .FirstOrDefault(portal => portal.Id == portalId);
                if (srcPortal == default)
                {
                    Logger.Warning($"Unable to find portal:{portalId} in map:{srcMapId}");
                    return;
                }

                if (!MapEntityStorage.HasSafePortal(srcMapId)) // map is instance only
                {
                    session.Player.MapId          = session.Player.ReturnMapId;
                    session.Player.Rotation       = session.FieldPlayer.Rotation;
                    session.Player.Coord          = session.Player.ReturnCoord;
                    session.Player.ReturnCoord.Z += Block.BLOCK_SIZE;
                    session.Send(FieldPacket.RequestEnter(session.FieldPlayer));
                    return;
                }

                MapPortal dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                                      .FirstOrDefault(portal => portal.Target == srcMapId);
                if (dstPortal == default)
                {
                    session.Player.ReturnCoord = session.FieldPlayer.Coord;
                    session.Player.ReturnMapId = session.Player.MapId;
                }

                dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                            .FirstOrDefault(portal => portal.Id == srcPortal.TargetPortalId);
                if (dstPortal == default)
                {
                    Logger.Warning($"Unable to find portal id:{srcPortal.TargetPortalId} in map:{srcPortal.Target}");
                    return;
                }

                // TODO: There needs to be a more centralized way to set coordinates...
                session.Player.MapId    = srcPortal.Target;
                session.Player.Rotation = dstPortal.Rotation.ToFloat();
                session.Player.Coord    = dstPortal.Coord.ToFloat();

                if (dstPortal.Name == "Portal_cube") // spawn on the next block if portal is a cube
                {
                    if (dstPortal.Rotation.Z == Direction.SOUTH_EAST)
                    {
                        session.Player.Coord.Y -= Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == Direction.NORTH_EAST)
                    {
                        session.Player.Coord.X += Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == Direction.NORTH_WEST)
                    {
                        session.Player.Coord.Y += Block.BLOCK_SIZE;
                    }
                    else if (dstPortal.Rotation.Z == Direction.SOUTH_WEST)
                    {
                        session.Player.Coord.X -= Block.BLOCK_SIZE;
                    }
                }

                session.Player.SafeBlock = session.Player.Coord;
                DatabaseManager.UpdateCharacter(session.Player);
                session.Send(FieldPacket.RequestEnter(session.FieldPlayer));
            }
        }
Beispiel #14
0
        public static void HandleMove(GameSession session, PacketReader packet)
        {
            int srcMapId = packet.ReadInt();

            if (srcMapId != session.FieldManager.MapId)
            {
                return;
            }

            int       portalId  = packet.ReadInt();
            MapPortal srcPortal = MapEntityStorage.GetPortals(srcMapId)
                                  .FirstOrDefault(portal => portal.Id == portalId);

            if (srcPortal == default)
            {
                System.Console.WriteLine($"Unable to find portal:{portalId} in map:{srcMapId}");
                return;
            }

            if (!MapEntityStorage.HasSafePortal(srcMapId)) // map is instance only
            {
                HandleLeaveInstance(session);
                return;
            }

            MapPortal dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                                  .FirstOrDefault(portal => portal.Target == srcMapId);

            if (dstPortal == default)
            {
                session.Player.ReturnCoord = session.FieldPlayer.Coord;
                session.Player.ReturnMapId = session.Player.MapId;
            }

            dstPortal = MapEntityStorage.GetPortals(srcPortal.Target)
                        .FirstOrDefault(portal => portal.Id == srcPortal.TargetPortalId);
            if (dstPortal == default)
            {
                System.Console.WriteLine($"Unable to find portal id:{srcPortal.TargetPortalId} in map:{srcPortal.Target}");
                return;
            }

            CoordF coord = dstPortal.Coord.ToFloat();

            if (dstPortal.Name == "Portal_cube") // spawn on the next block if portal is a cube
            {
                if (dstPortal.Rotation.Z == Direction.SOUTH_EAST)
                {
                    coord.Y -= Block.BLOCK_SIZE;
                }
                else if (dstPortal.Rotation.Z == Direction.NORTH_EAST)
                {
                    coord.X += Block.BLOCK_SIZE;
                }
                else if (dstPortal.Rotation.Z == Direction.NORTH_WEST)
                {
                    coord.Y += Block.BLOCK_SIZE;
                }
                else if (dstPortal.Rotation.Z == Direction.SOUTH_WEST)
                {
                    coord.X -= Block.BLOCK_SIZE;
                }
            }

            session.Player.Warp(coord, dstPortal.Rotation.ToFloat(), srcPortal.Target);
        }
        public void MoveUser(int mapId, int triggerId, int boxId)
        {
            List <IFieldObject <Player> > players = Field.State.Players.Values.ToList();

            if (boxId != 0)
            {
                MapTriggerBox box = MapEntityStorage.GetTriggerBox(Field.MapId, boxId);
                List <IFieldObject <Player> > boxedPlayers = new List <IFieldObject <Player> >();
                foreach (IFieldObject <Player> player in players)
                {
                    if (FieldManager.IsPlayerInBox(box, player))
                    {
                        boxedPlayers.Add(player);
                    }
                }
                players = boxedPlayers;
            }

            // move player back to return map
            if (mapId == 0 && triggerId == 0)
            {
                foreach (IFieldObject <Player> player in players)
                {
                    player.Value.Warp(player.Value.ReturnMapId, player.Value.ReturnCoord);
                }
                return;
            }

            if (mapId == Field.MapId)
            {
                IFieldObject <Portal> portal = Field.State.Portals.Values.First(p => p.Value.Id == triggerId);
                foreach (IFieldObject <Player> player in players)
                {
                    player.Coord    = portal.Coord;
                    player.Rotation = portal.Rotation;
                    player.Value.Session.Send(UserMoveByPortalPacket.Move(player, portal.Coord, portal.Rotation));
                }
                return;
            }

            CoordF    moveCoord;
            CoordF    moveRotation;
            MapPortal dstPortal = MapEntityStorage.GetPortals(mapId).FirstOrDefault(portal => portal.Id == triggerId);

            if (dstPortal == null)
            {
                MapPlayerSpawn spawn = MapEntityStorage.GetRandomPlayerSpawn(mapId);
                moveCoord    = spawn.Coord.ToFloat();
                moveRotation = spawn.Rotation.ToFloat();
            }
            else
            {
                moveCoord    = dstPortal.Coord.ToFloat();
                moveRotation = dstPortal.Rotation.ToFloat();
            }

            foreach (IFieldObject <Player> player in players)
            {
                player.Value.Warp(mapId, moveCoord, moveRotation);
            }
        }
Beispiel #16
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            switch (function)
            {
            case 0:     // Cancel
                return;

            case 1:
                int objectId = packet.ReadInt();
                if (!session.FieldManager.State.Npcs.TryGetValue(objectId, out IFieldObject <Npc> npc))
                {
                    return;     // Invalid NPC
                }
                session.Player.NpcTalk = npc;
                // If NPC is a shop, load and open the shop
                if (npc.Value.IsShop())
                {
                    ShopHandler.HandleOpen(session, npc);
                    return;
                }
                else if (npc.Value.IsBank())
                {
                    session.Send(HomeBank.OpenBank());
                    return;
                }
                else if (npc.Value.IsBeauty())
                {
                    session.Send(NpcTalkPacket.Respond(npc, NpcType.Default, DialogType.Beauty, 1));
                    return;
                }
                // Stellar Chest: 11004215
                session.Send(NpcTalkPacket.Respond(npc, NpcType.Unk2, DialogType.TalkOption, 0));
                break;

            case 2:                                                                                                                 // Continue chat?
                int index = packet.ReadInt();                                                                                       // selection index

                if (session.Player.NpcTalk.Value.IsBeauty())                                                                        // This may need a cleaner method
                {
                    MapPortal portal = MapEntityStorage.GetPortals(session.Player.MapId).FirstOrDefault(portal => portal.Id == 99); // unsure how the portalId is determined
                    session.Send(NpcTalkPacket.Action(ActionType.Portal, "", "", portal.Id));
                    NpcMetadata npcTarget = NpcMetadataStorage.GetNpc(session.Player.NpcTalk.Value.Id);

                    switch (npcTarget.ShopId)
                    {
                    case 500:                                                                                  // Dr Dixon
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "face")); // unsure how these strings are determined
                        break;

                    case 501:         // Dr Zenko
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "skin"));
                        break;

                    case 504:         // Rosetta
                    case 509:         //Lolly
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,style"));
                        break;

                    case 505:         // Ren
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "makeup"));
                        break;

                    case 506:         // Douglas
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "itemcolor"));
                        break;

                    case 507:         // Mirror
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "mirror"));
                        break;

                    case 508:         // Paulie
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,random"));
                        break;

                    case 510:         // Mino
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,styleSave"));
                        break;
                    }
                    session.Send(UserMoveByPortalPacket.Move(session, portal.Coord.ToFloat(), portal.Rotation.ToFloat()));
                }
                session.Send(NpcTalkPacket.Close());
                session.Player.NpcTalk = null;
                break;
            }
        }