public static void Setup(IServerConfiguration serverConfiguration) { worldService = Api.Server.World; protoSpawnZone = Api.GetProtoEntity <ZoneSpecialPlayerSpawn>(); serverConfiguration.SetupPlayerCharacterSpawnCallbackMethod( character => SpawnPlayer(character, isRespawn: false)); }
protected override void PrepareProtoStatusEffect() { base.PrepareProtoStatusEffect(); if (Api.IsClient) { return; } // cache the server zone prototype this.serverZone = this.ServerZoneProto; // cache the tile offsets // but select only every third tile (will help to reduce the load without damaging accuracy too much) this.serverTileOffsetsCircle = ShapeTileOffsetsHelper .GenerateOffsetsCircle(EnvironmentalRadiationLookupAreaDiameter) .ToArray(); this.serverTileOffsetsCircle = ShapeTileOffsetsHelper.SelectOffsetsWithRate( this.serverTileOffsetsCircle, rate: 3); // setup timer (tick every frame) TriggerEveryFrame.ServerRegister( callback: this.ServerGlobalUpdate, name: "System." + this.ShortId); }
private void ServerRemote_InvokeZoneScripts(IProtoZone protoZone, bool isInitialSpawn) { var serverZoneInstance = protoZone.ServerZoneInstance; if (protoZone.AttachedScripts.Count == 0) { Api.Logger.Dev("No scripts attached to the zone: " + protoZone.ShortId); return; } var trigger = isInitialSpawn ? (ProtoTrigger)Api.GetProtoEntity <TriggerWorldInit>() : (ProtoTrigger)Api.GetProtoEntity <TriggerTimeInterval>(); using var tempList = Api.Shared.GetTempList <IZoneScriptConfig>(); // process attached scripts in the random order (same as real triggers in the game) tempList.AddRange(protoZone.AttachedScripts); // Disabled because it break some spawn scripts order! //tempList.Shuffle(); foreach (var script in tempList.AsList()) { script.ServerInvoke(trigger, serverZoneInstance); } }
private QuadTreeSnapshot ServerRemote_GetServerZoneData(IProtoZone protoZone) { var character = ServerRemoteContext.Character; var quadTreeSnapshot = protoZone.ServerZoneInstance.GetPositionsSnapshot(); Logger.Important($"Zone quadtree sent: {protoZone} to {character}"); return(quadTreeSnapshot); }
private void ServerRemote_ApplyZoneModififications(IProtoZone protoZone, QuadTreeDiff diff) { var character = ServerRemoteContext.Character; var zoneInstance = protoZone.ServerZoneInstance; zoneInstance.ApplyDiff(diff); Logger.Important($"Zone quadtree diff applied: {diff} for {protoZone} by {character}"); }
public void ServerRegisterZone(IProtoZone zone) { foreach (var triggerConfig in this.ZoneScript.Triggers) { triggerConfig.ServerRegister( callback: () => this.TriggerCallback(zone, triggerConfig), $"ZoneScript.{this.GetType().Name}.{this.ShortId}"); } }
public static ClientZoneProvider Get(IProtoZone protoZone) { if (Providers.TryGetValue(protoZone, out var provider)) { return(provider); } provider = new ClientZoneProvider(protoZone); Providers[protoZone] = provider; return(provider); }
public void ClientClearSelectedZone(IProtoZone zone) { Logger.Important("Cleaning zone completely: " + zone.ShortId); var zoneProvider = ClientZoneProvider.Get(zone); var root = zoneProvider.GetQuadTree(); if (root.IsEmpty) { // no need to clean return; } zoneProvider.ClearZone(); zoneProvider.ApplyClientChanges(forcePushChangesImmediately: true); }
public void ClientDeleteSelectedZoneObjects(IProtoZone zone) { var clientZoneProvider = ClientZoneProvider.Get(zone); var worldService = Api.Client.World; var zoneQuadTree = clientZoneProvider.GetQuadTree(); var zoneBounds = zoneQuadTree.Bounds; var worldBoundsToDeleteObjects = worldService.GetStaticObjectsAtBounds(zoneBounds) .Where(o => zoneQuadTree.IsPositionFilled(o.TilePosition)) .ToList(); EditorStaticObjectsRemovalHelper.ClientDelete(worldBoundsToDeleteObjects); this.CallServer(_ => _.ServerRemote_DeleteZoneMobs(zone)); }
private void TriggerCallback(IProtoZone zone, BaseTriggerConfig triggerConfig) { if (Api.IsEditor) { //Api.Logger.Write( // string.Format( // "Trigger suppressed {0}: should invoke {1} for {2}{3}(suppressed because you\'re running the Editor executable)", // triggerConfig.ShortId, // this.ShortId, // zone.ShortId, // Environment.NewLine)); return; } var serverZoneInstance = zone.ServerZoneInstance; //Api.Logger.Info($"Trigger invoke {triggerConfig.ShortId}: invoking {this.ShortId} for {zone.ShortId}"); this.ServerInvoke(triggerConfig.Trigger, serverZoneInstance); }
public void ClientDeleteSelectedZoneObjects(IProtoZone zone) { var clientZoneProvider = ClientZoneProvider.Get(zone); var worldService = Api.Client.World; var zoneQuadTree = clientZoneProvider.GetQuadTree(); var zoneBounds = zoneQuadTree.Bounds; // TODO: it would be great if we can make that it will delete the map objects // that were spawned only by spawn scripts and not by hand/during loading the map from the map file. // Unfortunately, it's not possible to determine. var worldBoundsToDeleteObjects = worldService.GetStaticObjectsAtBounds(zoneBounds) .Where(o => zoneQuadTree.IsPositionFilled(o.TilePosition)) .ToList(); EditorStaticObjectsRemovalHelper.ClientDelete(worldBoundsToDeleteObjects); this.CallServer(_ => _.ServerRemote_DeleteZoneMobs(zone)); }
private void ServerRemote_DeleteZoneMobs(IProtoZone zone) { Logger.Important("Destroying all spawned mobs at zone: " + zone.ShortId); var serverZone = zone.ServerZoneInstance; var worldService = Server.World; foreach (var zoneAttachedScript in zone.AttachedScripts.Where(s => s.ZoneScript is ProtoZoneSpawnScript)) { var tracker = SpawnedMobsTrackingManagersStore.Get( (ProtoZoneSpawnScript)zoneAttachedScript.ZoneScript, serverZone); foreach (var character in tracker.EnumerateAll().ToList()) { worldService.DestroyObject(character); } tracker.Clear(); } }
protected override void PrepareProtoStatusEffect() { base.PrepareProtoStatusEffect(); if (Api.IsClient) { return; } this.serverFrameOffset = (byte)this.Id.GetHashCode(); // cache the server zone prototype this.serverZone = this.ServerZoneProto; // cache the tile offsets this.serverTileOffsetsCircle = ShapeTileOffsetsHelper .GenerateOffsetsCircle(EnvironmentalRadiationLookupAreaDiameter) .ToArray(); // setup timer (tick every frame) TriggerEveryFrame.ServerRegister( callback: this.ServerGlobalUpdate, name: "System." + this.ShortId); }
public static void ExecuteZoneScripts( IProtoZone protoZone, bool isInitialSpawn = false) { var serverZoneInstance = protoZone.ServerZoneInstance; if (protoZone.AttachedScripts.Count == 0) { // No scripts attached to this zone return; } var trigger = isInitialSpawn ? (ProtoTrigger)Api.GetProtoEntity <TriggerWorldInit>() : (ProtoTrigger)Api.GetProtoEntity <TriggerTimeInterval>(); using var tempList = Api.Shared.GetTempList <IZoneScriptConfig>(); tempList.AddRange(protoZone.AttachedScripts); foreach (var script in tempList.AsList()) { script.ServerInvoke(trigger, serverZoneInstance); } }
private ClientZoneProvider(IProtoZone protoZone) { this.ProtoZone = protoZone; this.SyncFromServer(); }
public void ClientSendZoneModifications(IProtoZone protoZone, QuadTreeDiff diff) { Logger.Important($"Zone quadtree diff sent: {diff} for {protoZone}"); this.CallServer(_ => _.ServerRemote_ApplyZoneModififications(protoZone, diff)); }
public Task <QuadTreeSnapshot> ClientRequestZoneData(IProtoZone protoZone) { Logger.Important($"Zone quadtree requested: {protoZone}"); return(this.CallServer(_ => _.ServerRemote_GetServerZoneData(protoZone))); }
public void ClientInvokeZoneScripts(IProtoZone protoZone, bool isInitialSpawn) { this.CallServer(_ => _.ServerRemote_InvokeZoneScripts(protoZone, isInitialSpawn)); }
public string Execute(IProtoZone protoZone) { ExecuteZoneScripts(protoZone); return($"All spawn scripts for {protoZone} executed"); }
private TaskVisitZone(IProtoZone protoZone, string description) : base(description) { this.ProtoZone = protoZone; }
public ProtoZoneViewModel([NotNull] IProtoZone zone) : base(zone) { }
public ViewModelProtoZone(IProtoZone zone) { this.zone = zone; }
private RequirementVisitZone(IProtoZone protoZone, string description) : base(description) { this.ProtoZone = protoZone; }