示例#1
0
 private static void LandClaimAreasElementRemoved(
     NetworkSyncList <ILogicObject> source,
     int index,
     ILogicObject value)
 {
     RemoveArea(value);
 }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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);
        }
示例#5
0
        public static string SharedGetAreaOwnerFactionClanTag(ILogicObject area)
        {
            var areasGroup            = SharedGetLandClaimAreasGroup(area);
            var areasGroupPublicState = LandClaimAreasGroup.GetPublicState(areasGroup);

            return(areasGroupPublicState.FactionClanTag);
        }
示例#6
0
        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);
        }
示例#7
0
 private static void ServerFactionMemberAccessRightsChangedHandler(
     ILogicObject faction,
     string characterName,
     FactionMemberAccessRights accessRights)
 {
     ServerRefreshFactionClaimAccess(faction);
 }
示例#8
0
        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);
        }
示例#9
0
 public static void ServerAddActiveEventToPlayerScope(ICharacter character, ILogicObject activeEvent)
 {
     if (character.ServerIsOnline)
     {
         ServerWorld.ForceEnterScope(character, activeEvent);
     }
 }
示例#10
0
            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;
            }
示例#11
0
 public Invitation(ILogicObject party, ICharacter inviter, ICharacter invitee)
 {
     this.ToParty = party;
     this.Inviter = inviter;
     this.Invitee = invitee;
     this.ResetExpirationDate();
 }
示例#12
0
	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;
	}
示例#13
0
        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();
     }
 }
示例#16
0
 /// <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;
 }
示例#17
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);
        }
示例#19
0
        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);
            }
        }
示例#20
0
        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);
        }
示例#22
0
        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));
        }
示例#23
0
        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);
            }
        }
示例#24
0
        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();
 }
示例#26
0
 public Controller(
     ClientWorldMapLandClaimsGroupVisualizer visualizer,
     ILogicObject areasGroup)
 {
     this.areasGroup = areasGroup;
     this.visualizer = visualizer;
     this.ReInitialize();
 }
示例#27
0
 private static void LogicObjectDeinitializedHandler(ILogicObject obj)
 {
     if (obj.ProtoGameObject is IProtoEvent)
     {
         ClientWorldEventRegularNotificationManager.UnregisterEvent(obj);
         ClientWorldEventConsolidatedNotificationManager.UnregisterEvent(obj);
     }
 }
示例#28
0
        public static RectangleInt SharedGetLandClaimAreaBounds(ILogicObject area)
        {
            var publicState = LandClaimArea.GetPublicState(area);

            return(SharedCalculateLandClaimAreaBounds(
                       publicState.LandClaimCenterTilePosition,
                       publicState.LandClaimSize));
        }
示例#29
0
        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));
        }
示例#31
0
        protected override void ServerOnDropEventStarted(ILogicObject activeEvent)
        {
            var publicState = GetPublicState(activeEvent);

            ServerEventLocationManager.AddUsedLocation(
                publicState.AreaCirclePosition,
                publicState.AreaCircleRadius + 20,
                duration: TimeSpan.FromHours(12));
        }
示例#32
0
	public bool Process (Segmentator s, ILogicObject o)
	{
		if(o is IHotWaterConsumer)
		{
			IHotWaterConsumer hot = o as IHotWaterConsumer;
			if(!hot.HasHotWater)
				return true;
		}
		return false;
	}