Ejemplo n.º 1
0
        private static bool ServerProcessDecay(IStaticWorldObject worldObject, double serverTime, double deltaTime)
        {
            if (worldObject.IsDestroyed)
            {
                return(false);
            }

            if (!(worldObject.ProtoStaticWorldObject is IProtoObjectStructure protoObjectStructure))
            {
                // not a structure
                return(false);
            }

            var privateState = worldObject.GetPrivateState <StructurePrivateState>();

            if (serverTime < privateState.ServerDecayStartTime)
            {
                // this structure is not decaying
                return(false);
            }

            // need to decay this object
            if (LandClaimSystem.SharedIsLandClaimedByAnyone(worldObject.TilePosition))
            {
                // the object is in a land claim area
                if (!(worldObject.ProtoStaticWorldObject is IProtoObjectLandClaim))
                {
                    // only the land claim object can decay in the land claim area
                    return(false);
                }
            }

            protoObjectStructure.ServerApplyDecay(worldObject, deltaTime);
            return(true);
        }
Ejemplo n.º 2
0
        public ViewModelWindowTurret(IStaticWorldObject worldObjectTurret)
        {
            this.worldObjectTurret = worldObjectTurret;
            this.privateState      = worldObjectTurret.GetPrivateState <ObjectTurretPrivateState>();
            this.TurretModes       = Enum.GetValues(typeof(TurretMode))
                                     .Cast <TurretMode>()
                                     .ExceptOne(TurretMode.Disabled)
                                     .Select(e => new ViewModelEnum <TurretMode>(e))
                                     .OrderBy(vm => vm.Order)
                                     .ToArray();

            this.selectedTurretMode = this.privateState.TurretMode;
            this.privateState.ClientSubscribe(_ => _.TurretMode,
                                              _ => this.RefreshTurretMode(),
                                              this);

            this.containerAmmo = this.privateState.ContainerAmmo as IClientItemsContainer;
            if (this.containerAmmo is not null)
            {
                this.containerAmmo.StateHashChanged += this.ContainerAmmoStateHashChanged;

                this.ViewModelItemsContainerExchange = new ViewModelItemsContainerExchange(this.containerAmmo)
                {
                    ContainerTitle             = CoreStrings.Vehicle_Ammo,
                    IsManagementButtonsVisible = false
                };

                this.ProtoItemWeapon =
                    ((BaseItemsContainerTurretAmmo)this.ViewModelItemsContainerExchange.Container.ProtoGameObject)
                    .ProtoWeapon;
            }

            this.RefreshTurretMode();
        }
Ejemplo n.º 3
0
        private void ServerRemote_SetMode(IStaticWorldObject worldObject, WorldObjectAccessMode mode)
        {
            var character = ServerRemoteContext.Character;

            if (!InteractionCheckerSystem.SharedHasInteraction(character,
                                                               worldObject,
                                                               requirePrivateScope: true))
            {
                throw new Exception("The player character is not interacting with " + worldObject);
            }

            if (!WorldObjectOwnersSystem.SharedIsOwner(character, worldObject) &&
                !CreativeModeSystem.SharedIsInCreativeMode(character))
            {
                throw new Exception("The player character is not the owner of " + worldObject);
            }

            if (!(worldObject.ProtoStaticWorldObject is IProtoObjectWithAccessMode protoObjectWithAccessMode))
            {
                throw new Exception("This world object doesn't have an access mode");
            }

            if (mode == WorldObjectAccessMode.Closed &&
                !protoObjectWithAccessMode.IsClosedAccessModeAvailable)
            {
                throw new Exception("Closed access mode is not supported for " + protoObjectWithAccessMode);
            }

            var privateState = worldObject.GetPrivateState <IObjectWithAccessModePrivateState>();

            privateState.AccessMode = mode;
            Logger.Important($"Access mode changed: {mode}; {worldObject}", character);
        }
Ejemplo n.º 4
0
        public ViewModelWindowLaunchpad(IStaticWorldObject worldObject)
        {
            this.worldObject          = worldObject;
            this.protoObjectLaunchpad = (ProtoObjectLaunchpad)worldObject.ProtoGameObject;

            this.privateState = worldObject.GetPrivateState <ObjectLaunchpadPrivateState>();
            this.publicState  = worldObject.GetPublicState <ObjectLaunchpadPublicState>();
            this.publicState.ClientSubscribe(_ => _.LaunchServerFrameTime,
                                             _ => this.NotifyPropertyChanged(nameof(this.IsLaunched)),
                                             this);

            this.publicState.ClientSubscribe(_ => _.LaunchedByPlayerName,
                                             _ => this.NotifyPropertyChanged(nameof(this.LaunchedByPlayerName)),
                                             this);

            this.Tasks = this.protoObjectLaunchpad
                         .TasksList
                         .Select((task, taskIndex) =>
                                 new ViewModelLaunchpadTask(worldObject, task, taskIndex, this.privateState))
                         .ToArray();

            this.privateState.ClientSubscribe(_ => _.TaskCompletionState,
                                              _ => this.NotifyPropertyChanged(nameof(this.IsUpgradeAvailable)),
                                              this);

            if (this.protoObjectLaunchpad.ConfigUpgrade.Entries.Count > 0)
            {
                this.ViewModelStructureUpgrade =
                    new ViewModelStructureUpgrade(this.protoObjectLaunchpad.ConfigUpgrade.Entries[0]);
            }
        }
Ejemplo n.º 5
0
        public ViewModelWorldObjectAccessModeEditor(IStaticWorldObject worldObject, bool canSetAccessMode)
        {
            this.worldObject      = worldObject;
            this.CanSetAccessMode = canSetAccessMode;

            if (!(worldObject.ProtoStaticWorldObject is IProtoObjectWithAccessMode protoObjectWithAccessMode))
            {
                throw new Exception("This world object doesn't have an access mode");
            }

            var accessModes = Enum.GetValues(typeof(WorldObjectAccessMode))
                              .Cast <WorldObjectAccessMode>();

            if (!protoObjectWithAccessMode.IsClosedAccessModeAvailable)
            {
                accessModes = accessModes.ExceptOne(WorldObjectAccessMode.Closed);
            }

            this.AccessModes = accessModes
                               .Select(e => new ViewModelEnum <WorldObjectAccessMode>(e))
                               .OrderBy(vm => vm.Order)
                               .ToArray();

            this.privateState = worldObject.GetPrivateState <IObjectWithAccessModePrivateState>();

            this.privateState.ClientSubscribe(
                _ => _.AccessMode,
                _ => this.RefreshAccessMode(),
                this);

            this.RefreshAccessMode();
        }
Ejemplo n.º 6
0
        public static void ServerRefreshLandClaimObject(IStaticWorldObject worldObject)
        {
            if (worldObject.IsDestroyed)
            {
                return;
            }

            if (!(worldObject.ProtoStaticWorldObject is IProtoObjectLandClaim))
            {
                // not a land claim structure
                return;
            }

            var area = LandClaimSystem.ServerGetLandClaimArea(worldObject);

            if (area == null)
            {
                // incorrect land claim - no area attached
                return;
            }

            var areaBounds = LandClaimSystem.SharedGetLandClaimAreaBounds(area);
            var owners     = LandClaimArea.GetPrivateState(area).LandOwners;

            foreach (var owner in owners)
            {
                var character = Server.Characters.GetPlayerCharacter(owner);
                if (character == null ||
                    !character.IsOnline)
                {
                    continue;
                }

                if (!areaBounds.Contains(character.TilePosition))
                {
                    continue;
                }

                // the land claim contains an online owner character
                // reset the decay timer for this land claim
                StructureDecaySystem.ServerResetDecayTimer(
                    worldObject.GetPrivateState <StructurePrivateState>());

                using (var tempVisitedAreas = Api.Shared.WrapObjectInTempList(area))
                {
                    ServerResetDecayTimerRecursively(tempVisitedAreas.AsList(),
                                                     areaBounds,
                                                     character);
                }

                return;
            }
        }
Ejemplo n.º 7
0
        public static bool ServerHasAccess(
            IStaticWorldObject worldObject,
            ICharacter character,
            bool writeToLog)
        {
            var privateState = worldObject.GetPrivateState <IObjectWithAccessModePrivateState>();

            return(ServerHasAccess(worldObject,
                                   character,
                                   privateState.AccessMode,
                                   writeToLog));
        }
        private static bool ServerProcessDecay(IStaticWorldObject worldObject, double serverTime)
        {
            if (worldObject.IsDestroyed)
            {
                return(false);
            }

            var protoObjectStructure = worldObject.ProtoStaticWorldObject as IProtoObjectStructure;

            if (protoObjectStructure == null)
            {
                // not a structure
                return(false);
            }

            var privateState = worldObject.GetPrivateState <StructurePrivateState>();

            if (serverTime < privateState.ServerDecayStartTime)
            {
                // this structure is not decaying
                return(false);
            }

            // need to decay this object
            var landClaimArea = LandClaimSystem.SharedGetAreaAtPosition(worldObject.TilePosition);

            if (landClaimArea != null)
            {
                // the object is in a land claim area
                if (!(worldObject.ProtoStaticWorldObject is IProtoObjectLandClaim))
                {
                    // only the land claim object can decay in the land claim area
                    return(false);
                }

                // this is a land claim object so it could decay
                // but first, ensure that it will not decay if there are any online owners nearby
                StructureLandClaimDecayResetSystem.ServerRefreshLandClaimObject(worldObject);
                if (serverTime < privateState.ServerDecayStartTime)
                {
                    // this land claim object is not decaying anymore (the timer has been just reset)
                    return(false);
                }
            }

            protoObjectStructure.ServerApplyDecay(
                worldObject,
                deltaTime: StructureConstants.StructureDecaySystemUpdateIntervalSeconds);

            return(true);
        }
Ejemplo n.º 9
0
        private void ServerRemote_SetDirectAccessMode(IStaticWorldObject worldObject, WorldObjectDirectAccessMode mode)
        {
            var character = ServerRemoteContext.Character;

            if (!(worldObject.ProtoGameObject is IProtoObjectWithAccessMode protoObjectWithAccessMode))
            {
                throw new Exception("This world object doesn't have an access mode");
            }

            if (!protoObjectWithAccessMode.SharedCanInteract(character, worldObject, writeToLog: true))
            {
                return;
            }

            var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(worldObject);

            if (areasGroup is not null &&
                LandClaimAreasGroup.GetPublicState(areasGroup).ServerFaction is not null)
            {
                throw new Exception(
                          "Cannot modify direct access mode for an object within a faction land claim area");
            }

            if (!WorldObjectOwnersSystem.SharedIsOwner(character, worldObject) &&
                !CreativeModeSystem.SharedIsInCreativeMode(character))
            {
                throw new Exception("The player character is not an owner of " + worldObject);
            }

            if (mode == WorldObjectDirectAccessMode.Closed &&
                !protoObjectWithAccessMode.IsClosedAccessModeAvailable)
            {
                throw new Exception("Closed access mode is not supported for " + protoObjectWithAccessMode);
            }

            if (mode == WorldObjectDirectAccessMode.OpensToEveryone &&
                !protoObjectWithAccessMode.IsEveryoneAccessModeAvailable)
            {
                throw new Exception("Everyone access mode is not supported for " + protoObjectWithAccessMode);
            }

            var privateState = worldObject.GetPrivateState <IObjectWithAccessModePrivateState>();

            if (privateState.DirectAccessMode == mode)
            {
                return;
            }

            privateState.DirectAccessMode = mode;
            Logger.Info($"Direct access mode changed: {mode}; {worldObject}", character);
        }
Ejemplo n.º 10
0
        public ViewModelWindowPowerThresholdsConfiguration(
            IStaticWorldObject worldObject,
            Action callbackSave,
            Action callbackCancel)
        {
            this.worldObject           = worldObject;
            this.callbackCancel        = callbackCancel;
            this.callbackSave          = callbackSave;
            this.IsElectricityProducer = worldObject.ProtoGameObject is IProtoObjectElectricityProducer;

            var privateState = worldObject.GetPrivateState <IObjectElectricityStructurePrivateState>();

            this.ApplyPreset(privateState.ElectricityThresholds);
        }
Ejemplo n.º 11
0
        public static void ClientSetElectricityThresholds(
            IStaticWorldObject worldObject,
            ElectricityThresholdsPreset thresholds)
        {
            thresholds = thresholds.Normalize(
                isProducer: worldObject.ProtoGameObject is IProtoObjectElectricityProducer);

            if (thresholds.Equals(worldObject.GetPrivateState <IObjectElectricityStructurePrivateState>()
                                  .ElectricityThresholds))
            {
                // no changes
                return;
            }

            Instance.CallServer(_ => _.ServerRemote_SetElectricityThresholds(worldObject, thresholds));
        }
Ejemplo n.º 12
0
        public ViewModelWindowLandClaim(
            IStaticWorldObject landClaimWorldObject,
            ILogicObject area)
        {
            this.landClaimWorldObject = landClaimWorldObject;

            this.privateState = LandClaimArea.GetPrivateState(area);

            var protoStructureWithOwnersList =
                ((IProtoObjectWithOwnersList)landClaimWorldObject.ProtoStaticWorldObject);
            var canEditOwners = protoStructureWithOwnersList
                                .SharedCanEditOwners(landClaimWorldObject, ClientCurrentCharacterHelper.Character);

            this.ViewModelOwnersEditor = new ViewModelWorldObjectOwnersEditor(
                this.privateState.LandOwners,
                callbackServerSetOwnersList: ownersList => LandClaimSystem.ClientSetAreaOwners(
                    area,
                    ownersList),
                title: AccessListTitle + ":",
                emptyListMessage: AccessListEmpty,
                canEditOwners: canEditOwners,
                // exclude founder name
                ownersListFilter: name => name != this.FounderName);

            this.protoObjectLandClaim =
                (IProtoObjectLandClaim)this.landClaimWorldObject.ProtoStaticWorldObject;

            var upgrade = this.protoObjectLandClaim.ConfigUpgrade.Entries.FirstOrDefault();

            if (upgrade != null)
            {
                this.ViewModelStructureUpgrade          = new ViewModelStructureUpgrade(upgrade);
                this.ViewModelProtoLandClaimInfoUpgrade = new ViewModelProtoLandClaimInfo(
                    (IProtoObjectLandClaim)upgrade.ProtoStructure);
            }

            this.ViewModelItemsContainerExchange = new ViewModelItemsContainerExchange(
                landClaimWorldObject.GetPrivateState <ObjectLandClaimPrivateState>().ItemsContainer,
                callbackTakeAllItemsSuccess: () => { })
            {
                IsContainerTitleVisible = false
            };

            this.ViewModelProtoLandClaimInfoCurrent = new ViewModelProtoLandClaimInfo(this.protoObjectLandClaim);
        }
Ejemplo n.º 13
0
        public ViewModelWorldObjectDirectAccessEditor(IStaticWorldObject worldObject, bool canSetAccessMode)
        {
            this.worldObject      = worldObject;
            this.CanSetAccessMode = canSetAccessMode;

            if (!(worldObject.ProtoGameObject is IProtoObjectWithAccessMode protoObjectWithAccessMode))
            {
                throw new Exception("This world object doesn't have an access mode");
            }

            IEnumerable <WorldObjectDirectAccessMode> accessModes
                = EnumExtensions.GetValues <WorldObjectDirectAccessMode>();

            if (!protoObjectWithAccessMode.IsClosedAccessModeAvailable)
            {
                accessModes = accessModes.ExceptOne(WorldObjectDirectAccessMode.Closed);
            }

            if (!protoObjectWithAccessMode.IsEveryoneAccessModeAvailable)
            {
                accessModes = accessModes.ExceptOne(WorldObjectDirectAccessMode.OpensToEveryone);
            }

            this.AccessModes = accessModes
                               .Select(e => new ViewModelAccessMode(e))
                               .OrderBy(vm => vm.Order)
                               .ToArray();

            this.privateState = worldObject.GetPrivateState <IObjectWithAccessModePrivateState>();

            this.privateState.ClientSubscribe(
                _ => _.DirectAccessMode,
                _ => this.RefreshAccessMode(),
                this);

            this.RefreshAccessMode();
        }
Ejemplo n.º 14
0
 private static ObjectTradingStationPrivateState GetPrivateState(IStaticWorldObject tradingStation)
 {
     return(tradingStation.GetPrivateState <ObjectTradingStationPrivateState>());
 }
Ejemplo n.º 15
0
 private static IObjectWithOwnersPrivateState GetPrivateState(IStaticWorldObject structure)
 {
     return(structure.GetPrivateState <IObjectWithOwnersPrivateState>());
 }