コード例 #1
0
    private static void HandleStart(GameSession session, PacketReader packet)
    {
        if (session.Player.Guide != null)
        {
            return;
        }

        byte unk = packet.ReadByte();
        int  furnishingItemId  = packet.ReadInt();
        long furnishingItemUid = packet.ReadLong();

        // Add Guide Object
        CoordF startCoord = Block.ClosestBlock(session.Player.FieldPlayer.Coord);

        startCoord.Z += Block.BLOCK_SIZE;
        GuideObject guide = new(0, session.Player.CharacterId);
        IFieldObject <GuideObject> fieldGuide = session.FieldManager.RequestFieldObject(guide);

        fieldGuide.Coord     = startCoord;
        session.Player.Guide = fieldGuide;
        session.FieldManager.AddGuide(fieldGuide);

        session.FieldManager.BroadcastPacket(GuideObjectPacket.Add(fieldGuide));
        session.FieldManager.BroadcastPacket(BuildModePacket.Use(session.Player.FieldPlayer, BuildModeType.House, furnishingItemId, furnishingItemUid));
    }
コード例 #2
0
        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));
        }
コード例 #3
0
        public void AddPlayer(GameSession sender, IFieldObject <Player> player)
        {
            Debug.Assert(player.ObjectId > 0, "Player was added to field without initialized objectId.");
            player.Coord       = player.Value.Coord;
            player.Value.MapId = MapId;
            // TODO: Determine new coordinates for player as well
            lock (Sessions)
            {
                Sessions.Add(sender);
            }

            // TODO: Send the initialization state of the field
            foreach (IFieldObject <Player> existingPlayer in State.Players.Values)
            {
                sender.Send(FieldPacket.AddPlayer(existingPlayer));
                sender.Send(FieldObjectPacket.LoadPlayer(existingPlayer));
            }

            State.AddPlayer(player);
            // Broadcast new player to all players in map
            Broadcast(session =>
            {
                session.Send(FieldPacket.AddPlayer(player));
                session.Send(FieldObjectPacket.LoadPlayer(player));
            });

            foreach (IFieldObject <Item> existingItem in State.Items.Values)
            {
                sender.Send(FieldPacket.AddItem(existingItem, 123456));
            }
            foreach (IFieldObject <Npc> existingNpc in State.Npcs.Values)
            {
                sender.Send(FieldPacket.AddNpc(existingNpc));
                sender.Send(FieldObjectPacket.LoadNpc(existingNpc));
            }
            foreach (IFieldObject <Portal> existingPortal in State.Portals.Values)
            {
                sender.Send(FieldPacket.AddPortal(existingPortal));
            }
            foreach (IFieldObject <Mob> existingMob in State.Mobs.Values)
            {
                sender.Send(FieldPacket.AddMob(existingMob));
                sender.Send(FieldObjectPacket.LoadMob(existingMob));
            }

            if (player.Value.MapId == (int)Map.PrivateResidence && !player.Value.IsInDecorPlanner)
            {
                // Send function cubes
                List <Cube> functionCubes = State.Cubes.Values.Where(x => x.Value.PlotNumber == 1 &&
                                                                     (x.Value.Item.HousingCategory is ItemHousingCategory.Farming or ItemHousingCategory.Ranching))
                                            .Select(x => x.Value).ToList();

                if (functionCubes.Count > 0)
                {
                    sender.Send(FunctionCubePacket.SendCubes(functionCubes));
                }
            }

            foreach (IFieldObject <GuideObject> guide in State.Guide.Values)
            {
                sender.Send(GuideObjectPacket.Add(guide));
            }

            foreach (IFieldObject <HealingSpot> healingSpot in State.HealingSpots.Values)
            {
                sender.Send(RegionSkillPacket.Send(healingSpot.ObjectId, healingSpot.Value.Coord, new SkillCast(70000018, 1, 0, 1)));
            }

            foreach (IFieldObject <Instrument> instrument in State.Instruments.Values)
            {
                if (instrument.Value.Improvise)
                {
                    sender.Send(InstrumentPacket.StartImprovise(instrument));
                }
                else
                {
                    sender.Send(InstrumentPacket.PlayScore(instrument));
                }
            }

            List <BreakableObject> breakables = new List <BreakableObject>();

            breakables.AddRange(State.BreakableActors.Values.ToList());
            breakables.AddRange(State.BreakableNifs.Values.ToList());
            sender.Send(BreakablePacket.LoadBreakables(breakables));

            List <InteractObject> interactObjects = new List <InteractObject>();

            interactObjects.AddRange(State.InteractObjects.Values.Where(t => t is not AdBalloon).ToList());
            sender.Send(InteractObjectPacket.LoadInteractObject(interactObjects));

            List <AdBalloon> adBalloons = new List <AdBalloon>();

            adBalloons.AddRange(State.InteractObjects.Values.OfType <AdBalloon>().ToList());
            foreach (AdBalloon balloon in adBalloons)
            {
                sender.Send(InteractObjectPacket.LoadAdBallon(balloon));
            }

            List <TriggerObject> triggerObjects = new List <TriggerObject>();

            triggerObjects.AddRange(State.TriggerMeshes.Values.ToList());
            triggerObjects.AddRange(State.TriggerEffects.Values.ToList());
            triggerObjects.AddRange(State.TriggerCameras.Values.ToList());
            triggerObjects.AddRange(State.TriggerActors.Values.ToList());
            triggerObjects.AddRange(State.TriggerCubes.Values.ToList());
            triggerObjects.AddRange(State.TriggerLadders.Values.ToList());
            triggerObjects.AddRange(State.TriggerRopes.Values.ToList());
            triggerObjects.AddRange(State.TriggerSounds.Values.ToList());
            sender.Send(TriggerPacket.LoadTriggers(triggerObjects));

            if (MapLoopTask == null)
            {
                MapLoopTask = StartMapLoop(); //TODO: find a better place to initialise MapLoopTask
            }
        }
コード例 #4
0
        public void AddPlayer(GameSession sender, IFieldObject <Player> player)
        {
            Debug.Assert(player.ObjectId > 0, "Player was added to field without initialized objectId.");
            player.Coord       = player.Value.Coord;
            player.Value.MapId = MapId;
            // TODO: Determine new coordinates for player as well
            lock (Sessions)
            {
                Sessions.Add(sender);
            }

            // TODO: Send the initialization state of the field
            foreach (IFieldObject <Player> existingPlayer in State.Players.Values)
            {
                sender.Send(FieldPacket.AddPlayer(existingPlayer));
                sender.Send(FieldObjectPacket.LoadPlayer(existingPlayer));
            }
            foreach (IFieldObject <Item> existingItem in State.Items.Values)
            {
                sender.Send(FieldPacket.AddItem(existingItem, 123456));
            }
            foreach (IFieldObject <Npc> existingNpc in State.Npcs.Values)
            {
                sender.Send(FieldPacket.AddNpc(existingNpc));
                sender.Send(FieldObjectPacket.LoadNpc(existingNpc));
            }
            foreach (IFieldObject <Portal> existingPortal in State.Portals.Values)
            {
                sender.Send(FieldPacket.AddPortal(existingPortal));
            }
            foreach (IFieldObject <Mob> existingMob in State.Mobs.Values)
            {
                sender.Send(FieldPacket.AddMob(existingMob));
                sender.Send(FieldObjectPacket.LoadMob(existingMob));
            }
            if (State.InteractObjects.Values.Count > 0)
            {
                ICollection <IFieldObject <InteractObject> > balloons = State.InteractObjects.Values.Where(x => x.Value.Type == InteractObjectType.AdBalloon).ToList();
                if (balloons.Count > 0)
                {
                    foreach (IFieldObject <InteractObject> balloon in balloons)
                    {
                        sender.Send(InteractObjectPacket.AddAdBallons(balloon));
                    }
                }
                ICollection <IFieldObject <InteractObject> > objects = State.InteractObjects.Values.Where(x => x.Value.Type != InteractObjectType.AdBalloon).ToList();
                if (objects.Count > 0)
                {
                    sender.Send(InteractObjectPacket.AddInteractObjects(objects));
                }
            }

            if (State.Cubes.IsEmpty && !player.Value.IsInDecorPlanner)
            {
                if (MapId == (int)Map.PrivateResidence)
                {
                    Home home = GameServer.HomeManager.GetHome(player.Value.VisitingHomeId);
                    if (home != null)
                    {
                        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);
                        }
                    }
                }
                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);
                        }
                    }
                }
            }

            foreach (IFieldObject <GuideObject> guide in State.Guide.Values)
            {
                sender.Send(GuideObjectPacket.Add(guide));
            }

            foreach (IFieldObject <HealingSpot> healingSpot in State.HealingSpots.Values)
            {
                sender.Send(RegionSkillPacket.Send(healingSpot.ObjectId, healingSpot.Value.Coord, new SkillCast(70000018, 1, 0, 1)));
            }

            foreach (IFieldObject <Instrument> instrument in State.Instruments.Values)
            {
                if (instrument.Value.Improvise)
                {
                    sender.Send(InstrumentPacket.StartImprovise(instrument));
                }
                else
                {
                    sender.Send(InstrumentPacket.PlayScore(instrument));
                }
            }

            List <BreakableObject> breakables = new List <BreakableObject>();

            breakables.AddRange(State.BreakableActors.Values.ToList());
            breakables.AddRange(State.BreakableNifs.Values.ToList());
            sender.Send(BreakablePacket.LoadBreakables(breakables));

            List <TriggerObject> triggerObjects = new List <TriggerObject>();

            triggerObjects.AddRange(State.TriggerMeshes.Values.ToList());
            triggerObjects.AddRange(State.TriggerEffects.Values.ToList());
            triggerObjects.AddRange(State.TriggerCameras.Values.ToList());
            triggerObjects.AddRange(State.TriggerActors.Values.ToList());
            triggerObjects.AddRange(State.TriggerCubes.Values.ToList());
            triggerObjects.AddRange(State.TriggerLadders.Values.ToList());
            triggerObjects.AddRange(State.TriggerRopes.Values.ToList());
            triggerObjects.AddRange(State.TriggerSounds.Values.ToList());
            sender.Send(TriggerPacket.LoadTriggers(triggerObjects));
            State.AddPlayer(player);

            if (MapLoopTask == null)
            {
                MapLoopTask = StartMapLoop(); //TODO: find a better place to initialise MapLoopTask
            }

            // Broadcast new player to all players in map
            Broadcast(session =>
            {
                session.Send(FieldPacket.AddPlayer(player));
                session.Send(FieldObjectPacket.LoadPlayer(player));
            });
        }
コード例 #5
0
        public void AddPlayer(GameSession sender, IFieldObject <Player> player)
        {
            Debug.Assert(player.ObjectId > 0, "Player was added to field without initialized objectId.");
            player.Coord       = player.Value.Coord;
            player.Value.MapId = MapId;
            // TODO: Determine new coordinates for player as well
            lock (Sessions)
            {
                Sessions.Add(sender);
            }

            // TODO: Send the initialization state of the field
            foreach (IFieldObject <Player> existingPlayer in State.Players.Values)
            {
                sender.Send(FieldPacket.AddPlayer(existingPlayer));
                sender.Send(FieldObjectPacket.LoadPlayer(existingPlayer));
            }
            foreach (IFieldObject <Item> existingItem in State.Items.Values)
            {
                sender.Send(FieldPacket.AddItem(existingItem, 123456));
            }
            foreach (IFieldObject <Npc> existingNpc in State.Npcs.Values)
            {
                sender.Send(FieldPacket.AddNpc(existingNpc));
                sender.Send(FieldObjectPacket.LoadNpc(existingNpc));
            }
            foreach (IFieldObject <Portal> existingPortal in State.Portals.Values)
            {
                sender.Send(FieldPacket.AddPortal(existingPortal));
            }
            foreach (IFieldObject <Mob> existingMob in State.Mobs.Values)
            {
                sender.Send(FieldPacket.AddMob(existingMob));
                sender.Send(FieldObjectPacket.LoadMob(existingMob));
            }
            if (State.InteractObjects.Values.Count > 0)
            {
                ICollection <IFieldObject <InteractObject> > balloons = State.InteractObjects.Values.Where(x => x.Value.Type == InteractObjectType.AdBalloon).ToList();
                if (balloons.Count > 0)
                {
                    foreach (IFieldObject <InteractObject> balloon in balloons)
                    {
                        sender.Send(InteractObjectPacket.AddAdBallons(balloon));
                    }
                }
                ICollection <IFieldObject <InteractObject> > objects = State.InteractObjects.Values.Where(x => x.Value.Type != InteractObjectType.AdBalloon).ToList();
                if (objects.Count > 0)
                {
                    sender.Send(InteractObjectPacket.AddInteractObjects(objects));
                }
            }
            if (State.Cubes.Values.Count > 0)
            {
                sender.Send(CubePacket.LoadCubes(State.Cubes.Values));
            }
            foreach (IFieldObject <GuideObject> guide in State.Guide.Values)
            {
                sender.Send(GuideObjectPacket.Add(guide));
            }

            foreach (IFieldObject <HealingSpot> healingSpot in State.HealingSpots.Values)
            {
                sender.Send(RegionSkillPacket.Send(healingSpot.ObjectId, healingSpot.Value.Coord, new SkillCast(70000018, 1, 0, 1)));
            }

            foreach (IFieldObject <Instrument> instrument in State.Instruments.Values)
            {
                if (instrument.Value.Improvise)
                {
                    sender.Send(InstrumentPacket.StartImprovise(instrument));
                }
                else
                {
                    sender.Send(InstrumentPacket.PlayScore(instrument));
                }
            }

            State.AddPlayer(player);

            if (!State.HealingSpots.IsEmpty)
            {
                if (HealingSpotThread == null)
                {
                    HealingSpotThread = StartHealingSpot();
                }
            }

            // Broadcast new player to all players in map
            Broadcast(session =>
            {
                session.Send(FieldPacket.AddPlayer(player));
                session.Send(FieldObjectPacket.LoadPlayer(player));
            });
        }
コード例 #6
0
        public void AddPlayer(GameSession sender, IFieldObject <Player> player)
        {
            Debug.Assert(player.ObjectId > 0, "Player was added to field without initialized objectId.");
            player.Coord       = player.Value.Coord;
            player.Value.MapId = MapId;
            // TODO: Determine new coordinates for player as well
            lock (Sessions)
            {
                Sessions.Add(sender);
            }

            // TODO: Send the initialization state of the field
            foreach (IFieldObject <Player> existingPlayer in State.Players.Values)
            {
                sender.Send(FieldPacket.AddPlayer(existingPlayer));
                sender.Send(FieldObjectPacket.LoadPlayer(existingPlayer));
            }
            foreach (IFieldObject <Item> existingItem in State.Items.Values)
            {
                sender.Send(FieldPacket.AddItem(existingItem, 123456));
            }
            foreach (IFieldObject <Npc> existingNpc in State.Npcs.Values)
            {
                sender.Send(FieldPacket.AddNpc(existingNpc));
                sender.Send(FieldObjectPacket.LoadNpc(existingNpc));
            }
            foreach (IFieldObject <Portal> existingPortal in State.Portals.Values)
            {
                sender.Send(FieldPacket.AddPortal(existingPortal));
            }
            foreach (IFieldObject <Mob> existingMob in State.Mobs.Values)
            {
                sender.Send(FieldPacket.AddMob(existingMob));
                sender.Send(FieldObjectPacket.LoadMob(existingMob));
            }
            if (State.InteractActors.Values.Count > 0)
            {
                sender.Send(InteractActorPacket.AddInteractActors(State.InteractActors.Values));
            }
            if (State.Cubes.Values.Count > 0)
            {
                sender.Send(CubePacket.LoadCubes(State.Cubes.Values));
            }
            foreach (IFieldObject <GuideObject> guide in State.Guide.Values)
            {
                sender.Send(GuideObjectPacket.Add(guide));
            }
            if (MapEntityStorage.HasHealingSpot(MapId))
            {
                if (HealingSpotThread == null || HealingSpotThread.IsCompleted)
                {
                    HealingSpotThread = StartHealingSpot(sender, player);
                }
                sender.Send(RegionSkillPacket.Send(player, MapEntityStorage.GetHealingSpot(MapId), new SkillCast(70000018, 1, 0, 1)));
            }

            State.AddPlayer(player);
            // Broadcast new player to all players in map
            Broadcast(session =>
            {
                session.Send(FieldPacket.AddPlayer(player));
                session.Send(FieldObjectPacket.LoadPlayer(player));
            });
        }