public void AddInteractObject(ICollection <IFieldObject <InteractObject> > objects) { foreach (IFieldObject <InteractObject> interactObject in objects) { State.AddInteractObject(interactObject); } if (objects.Count > 0) { Broadcast(session => { session.Send(InteractObjectPacket.AddInteractObjects(objects)); }); } }
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))); } } } }