private static void LandClaimAreasElementRemoved( NetworkSyncList <ILogicObject> source, int index, ILogicObject value) { RemoveArea(value); }
protected override void OnCompletedOrCancelled() { base.OnCompletedOrCancelled(); if (Api.IsClient) { this.SharedFishingSession = null; return; } Api.Server.World.DestroyObject(this.SharedFishingSession); this.SharedFishingSession = null; if (this.IsCancelled) { // cancelled so bait was not used return; } this.ServerTryToDeductTheBait(); if (this.ServerIsSuccess) { return; } if (this.ServerIsPlayerTriedToCatch) { FishingSystem.ServerSendNotificationFishSlipOfTheHook(this.Character); } else { FishingSystem.ServerSendNotificationTooLate(this.Character); } }
private static void ServerResetDecayTimerForLandClaimAreasGroup(ILogicObject areasGroup) { var areasGroupPrivateState = LandClaimAreasGroup.GetPrivateState(areasGroup); var areasGroupPublicState = LandClaimAreasGroup.GetPublicState(areasGroup); var areas = areasGroupPrivateState.ServerLandClaimsAreas; // TODO: it's better to move this code to another place as this property is used in several other places areasGroupPublicState.IsFounderDemoPlayer = ServerGetIsFounderDemoPlayer(areas); // reset the decay timer for all land claim buildings inside this areas group var decayDelayDuration = LandClaimSystem.ServerGetDecayDelayDurationForLandClaimAreas( areas, areasGroupPublicState.IsFounderDemoPlayer, out _); foreach (var area in areas) { var worldObject = LandClaimArea.GetPrivateState(area) .ServerLandClaimWorldObject; StructureDecaySystem.ServerResetDecayTimer( worldObject.GetPrivateState <StructurePrivateState>(), decayDelayDuration); } }
protected virtual void ServerCreateEventArea( ILogicObject activeEvent, ushort circleRadius, out Vector2Ushort circlePosition, out Vector2Ushort eventPosition) { var stopwatch = Stopwatch.StartNew(); var world = Server.World; const int attemptsMax = 20; var attemptsRemains = attemptsMax; do { eventPosition = this.ServerPickEventPosition(activeEvent); // a valid spawn position found, try to create a search area circle which is including this location if (!this.ServerCreateEventSearchArea(world, eventPosition, circleRadius, out circlePosition)) { continue; } // search area created Logger.Important( $"Generating an event area took {attemptsMax - attemptsRemains} attempts, {stopwatch.ElapsedMilliseconds}ms (for {this})"); return; }while (--attemptsRemains > 0); throw new Exception("Unable to create the event area for " + activeEvent); }
public static string SharedGetAreaOwnerFactionClanTag(ILogicObject area) { var areasGroup = SharedGetLandClaimAreasGroup(area); var areasGroupPublicState = LandClaimAreasGroup.GetPublicState(areasGroup); return(areasGroupPublicState.FactionClanTag); }
private static ILogicObject ServerGetOwningFaction(IWorldObject worldObject) { ILogicObject faction = null; if (worldObject is IStaticWorldObject staticWorldObject) { var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(staticWorldObject); if (areasGroup is null) { throw new Exception( "Cannot modify faction access mode for an object without a faction land claim area"); } faction = LandClaimAreasGroup.GetPublicState(areasGroup).ServerFaction; } else if (worldObject.ProtoGameObject is IProtoVehicle) { var clanTag = worldObject.GetPublicState <VehiclePublicState>().ClanTag; if (string.IsNullOrEmpty(clanTag)) { throw new Exception("The vehicle doesn't belong to a faction: " + worldObject); } faction = FactionSystem.ServerGetFactionByClanTag(clanTag); } if (faction is null) { throw new Exception( "Cannot modify faction access mode for an object without a faction land claim area"); } return(faction); }
private static void ServerFactionMemberAccessRightsChangedHandler( ILogicObject faction, string characterName, FactionMemberAccessRights accessRights) { ServerRefreshFactionClaimAccess(faction); }
public override double ServerGetCurrentValue(ILogicObject faction) { var structures = new HashSet <IStaticWorldObject>(); var clanTag = FactionSystem.SharedGetClanTag(faction); foreach (var area in LandClaimSystem.SharedEnumerateAllFactionAreas(clanTag)) { var areaBounds = LandClaimSystem.SharedGetLandClaimAreaBounds(area, addGracePadding: false); ServerGatherValuableStructures(areaBounds, structures); } if (structures.Count == 0) { return(0); } var result = 0.0; foreach (var obj in structures) { result += ((IProtoObjectStructure)obj.ProtoGameObject).FactionWealthScorePoints; } return(result); }
public static void ServerAddActiveEventToPlayerScope(ICharacter character, ILogicObject activeEvent) { if (character.ServerIsOnline) { ServerWorld.ForceEnterScope(character, activeEvent); } }
public LandClaimMapData( ILogicObject area, WorldMapController worldMapController, ClientWorldMapLandClaimsGroupVisualizer landClaimGroupVisualizer, bool isFounder) { this.area = area; this.worldMapController = worldMapController; this.landClaimGroupVisualizer = landClaimGroupVisualizer; // add land claim mark control to map this.markControl = new WorldMapMarkLandClaim() { IsFounder = isFounder, Area = area }; var canvasPosition = this.GetAreaCanvasPosition(); Canvas.SetLeft(this.markControl, canvasPosition.X); Canvas.SetTop(this.markControl, canvasPosition.Y); Panel.SetZIndex(this.markControl, 12); worldMapController.AddControl(this.markControl); this.landClaimGroupVisualizer.Register(this.area); ClientUpdateHelper.UpdateCallback += this.UpdateCallback; }
public Invitation(ILogicObject party, ICharacter inviter, ICharacter invitee) { this.ToParty = party; this.Inviter = inviter; this.Invitee = invitee; this.ResetExpirationDate(); }
public bool Process (Segmentator s, ILogicObject o) { bool res = false; if(o.ObjectType == CellObjects.Heater || o.ObjectType == CellObjects.HeatingPipe || o.ObjectType == CellObjects.Sink || o.ObjectType == CellObjects.Toilet) return false; o.ObjectRect.Foreach((MapPoint p) => { WallPoint wp; wp = new WallPoint(p.X,p.Y); if(s.Doors.ContainsKey(wp.toInt())) res = true; wp = new WallPoint(p.X+1,p.Y); if(s.Doors.ContainsKey(wp.toInt())) res = true; wp = new WallPoint(p.X,p.Y+1); if(s.Doors.ContainsKey(wp.toInt())) res = true; wp = new WallPoint(p.X+1,p.Y+1); if(s.Doors.ContainsKey(wp.toInt())) res = true; }); return res; }
public void ClientSetCurrentFishingSession(ILogicObject currentFishingSession) { this.SharedFishingSession = currentFishingSession; var publicActionState = (FishingActionPublicActionState)this.CharacterPublicState.CurrentPublicActionState; publicActionState.ClientOnCurrentPlayerFishingSessionReceived(currentFishingSession); }
public static void ClientRechargeShield(ILogicObject areasGroup, double targetChargeElectricity) { Api.Assert(targetChargeElectricity > 0, "Incorrect charge amount"); var electricityCost = CalculateRequiredElectricityCost(areasGroup, targetChargeElectricity); if (electricityCost <= 0) { return; } var state = SharedGetShieldPublicStatus(areasGroup); if (state == ShieldProtectionStatus.Active) { throw new Exception("Cannot recharge active shield. It should be disabled."); } if (!PowerGridSystem.ServerBaseHasCharge(areasGroup, electricityCost)) { var message = PowerGridSystem.SetPowerModeResult.NotEnoughPower.GetDescription(); NotificationSystem.ClientShowNotification( message, null, color: NotificationColor.Bad); return; } Instance.CallServer(_ => _.ServerRemote_RechargeShield(areasGroup, targetChargeElectricity)); Logger.Important( $"Sent request to charge shield to {targetChargeElectricity:F2} (+{electricityCost:F2} EU)"); }
private void LogicObjectInitializedHandler(ILogicObject logicObject) { if (this.groupControllers.TryGetValue(logicObject, out var controller)) { controller.ReInitialize(); } }
/// <summary> /// Resets the faction karma when player joins or leaves a faction. /// As player cannot rejoin the faction easily (they need an invitation to rejoin and a cooldown applies), /// it's not possible to workaround the karma system by leaving a faction and rejoining it back. /// </summary> private static void ServerCharacterJoinedOrLeftFactionHandler( ICharacter character, ILogicObject faction, bool isJoined) { PlayerCharacter.GetPrivateState(character).ServerFactionKarma = 0; }
private static void ServerOnAddLandOwner(ILogicObject area, ICharacter playerToAdd, bool notify) { // add this with some delay to prevent from the bug when the player name listed twice due to the late delta-replication if (notify) { ServerTimersSystem.AddAction( delaySeconds: 0.1, OnAddLandOwner); } else { OnAddLandOwner(); } void OnAddLandOwner() { if (!ServerIsOwnedArea(area, playerToAdd)) { // The owner is already removed during the short delay? That's was quick! return; } ServerWorld.EnterPrivateScope(playerToAdd, area); if (notify) { Instance.CallClient( playerToAdd, _ => _.ClientRemote_OnLandOwnerStateChanged(area, true)); } } }
/// <summary> /// This method should be called only by LandClaimSystem. /// </summary> internal static void AddArea(ILogicObject area) { if (StateSubscriptionStorages.ContainsKey(area)) { return; } // register for group change event var stateSubscriptionStorage = new StateSubscriptionStorage(); StateSubscriptionStorages[area] = stateSubscriptionStorage; var areaPublicState = LandClaimArea.GetPublicState(area); areaPublicState.ClientSubscribe( o => o.LandClaimAreasGroup, newValue => { //Api.Logger.Dev($"Received LandClaimAreasGroup changed: {newValue} for {area}"); OnAreaModified(area); }, stateSubscriptionStorage); // register area RendererManagerGraceAreas.RegisterArea(area); var renderer = LandClaimSystem.ClientIsOwnedArea(area) ? RendererManagerOwnedByPlayer : RendererManagerNotOwnedByPlayer; renderer.RegisterArea(area); AreaAdded?.Invoke(area); }
private static void ServerTransferAreasGroupToFactionOwnership( ILogicObject faction, ICharacter byCharacter, ILogicObject areasGroup) { var areas = LandClaimAreasGroup.GetPrivateState(areasGroup).ServerLandClaimsAreas; foreach (var area in areas) { ServerUnregisterArea(area); } var publicState = LandClaimAreasGroup.GetPublicState(areasGroup); publicState.ServerSetFaction(faction); var centerTilePosition = new Vector2Ushort( (ushort)areas.Average(a => LandClaimArea.GetPublicState(a).LandClaimCenterTilePosition.X), (ushort)areas.Average(a => LandClaimArea.GetPublicState(a).LandClaimCenterTilePosition.Y)); Logger.Important( $"Transferred land claim areas group to the faction ownership: {areasGroup} at {centerTilePosition}"); FactionSystem.ServerOnLandClaimExpanded(faction, centerTilePosition, byCharacter); foreach (var area in areas) { ServerRegisterArea(area); } }
protected override void ServerTryFinishEvent(ILogicObject worldEvent) { var canFinish = true; foreach (var spawnedObject in GetPrivateState(worldEvent).SpawnedWorldObjects) { if (spawnedObject.IsDestroyed) { continue; } if (!Server.World.IsObservedByAnyPlayer(spawnedObject)) { Server.World.DestroyObject(spawnedObject); continue; } // still has a spawned object which cannot be destroyed as it's observed by a player canFinish = false; break; } if (canFinish) { base.ServerTryFinishEvent(worldEvent); } }
public void Register(ILogicObject area) { Controller controller; foreach (var pair in this.groupControllers) { controller = pair.Value; if (controller.Areas.Contains(area)) { throw new Exception("Already has area registered: " + area); } } var areasGroup = LandClaimArea.GetPublicState(area).LandClaimAreasGroup; if (areasGroup is null) { return; } if (!this.groupControllers.TryGetValue(areasGroup, out controller)) { controller = new Controller(areasGroup, this.worldMapController); this.groupControllers[areasGroup] = controller; } controller.Areas.Add(area); }
private void ServerCharacterJoinedOrLeftPartyOrFactionHandler( ICharacter playerCharacter, ILogicObject party, bool isJoined) { if (!playerCharacter.ServerIsOnline) { // it's not in online players list so no notifications necessary return; } var onlineStatusChangeReceivers = ServerGetOnlineStatusChangeReceivers(playerCharacter); this.CallClient(onlineStatusChangeReceivers, _ => _.ClientRemote_OnlinePlayerClanTagChanged( new Entry(playerCharacter.Name, FactionSystem.SharedGetClanTag(playerCharacter)))); if (!SharedIsListHidden) { return; } // need to notify current party and faction members that this player is online this.CallClient(onlineStatusChangeReceivers, _ => _.ClientRemote_OnlineStatusChanged( new Entry(playerCharacter.Name, FactionSystem.SharedGetClanTag(playerCharacter)), true)); }
protected override void ServerTryFinishEvent(ILogicObject worldEvent) { var canFinish = true; var spawnedWorldObjects = GetPrivateState(worldEvent).SpawnedWorldObjects; var list = spawnedWorldObjects; for (var index = list.Count - 1; index >= 0; index--) { var spawnedObject = list[index]; if (spawnedObject.IsDestroyed) { spawnedWorldObjects.RemoveAt(index); continue; } if (!Server.World.IsObservedByAnyPlayer(spawnedObject)) { Server.World.DestroyObject(spawnedObject); spawnedWorldObjects.RemoveAt(index); continue; } // still has a spawned object which cannot be destroyed as it's observed by a player canFinish = false; break; } if (canFinish) { base.ServerTryFinishEvent(worldEvent); } }
public override string SharedGetProgressText(ILogicObject activeEvent) { var publicState = GetPublicState(activeEvent); return(string.Format(ProgressTextFormat, publicState.ObjectsTotal - publicState.ObjectsRemains, publicState.ObjectsTotal)); }
public Controller( ILogicObject areasGroup, WorldMapController worldMapController) { this.areasGroup = areasGroup; this.worldMapController = worldMapController; this.ReInitialize(); }
public Controller( ClientWorldMapLandClaimsGroupVisualizer visualizer, ILogicObject areasGroup) { this.areasGroup = areasGroup; this.visualizer = visualizer; this.ReInitialize(); }
private static void LogicObjectDeinitializedHandler(ILogicObject obj) { if (obj.ProtoGameObject is IProtoEvent) { ClientWorldEventRegularNotificationManager.UnregisterEvent(obj); ClientWorldEventConsolidatedNotificationManager.UnregisterEvent(obj); } }
public static RectangleInt SharedGetLandClaimAreaBounds(ILogicObject area) { var publicState = LandClaimArea.GetPublicState(area); return(SharedCalculateLandClaimAreaBounds( publicState.LandClaimCenterTilePosition, publicState.LandClaimSize)); }
protected override Vector2Ushort ServerPickEventPosition(ILogicObject activeEvent) { // use center position of the zone var zoneInstance = ServerSpawnZones.Value.TakeByRandom(); return(new Vector2Ushort((ushort)zoneInstance.AllPositions.Average(p => p.X), (ushort)zoneInstance.AllPositions.Average(p => p.Y))); }
public static double SharedCalculateCooldownRemains(ILogicObject areasGroup) { var privateState = LandClaimAreasGroup.GetPrivateState(areasGroup); var time = IsServer ? Server.Game.FrameTime : Client.CurrentGame.ServerFrameTimeApproximated; return(Math.Max(0, privateState.ShieldProtectionCooldownExpirationTime - time)); }
protected override void ServerOnDropEventStarted(ILogicObject activeEvent) { var publicState = GetPublicState(activeEvent); ServerEventLocationManager.AddUsedLocation( publicState.AreaCirclePosition, publicState.AreaCircleRadius + 20, duration: TimeSpan.FromHours(12)); }
public bool Process (Segmentator s, ILogicObject o) { if(o is IHotWaterConsumer) { IHotWaterConsumer hot = o as IHotWaterConsumer; if(!hot.HasHotWater) return true; } return false; }