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 (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)); }); }
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 } }
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)); }); }
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)); }); }