public ViewModelPowerSwitch(IStaticWorldObject worldObject)
        {
            this.worldObject = worldObject;

            if (worldObject.ProtoStaticWorldObject is IProtoObjectElectricityProducer)
            {
                // producer
                var publicState = worldObject.GetPublicState <IObjectElectricityProducerPublicState>();
                publicState.ClientSubscribe(
                    _ => _.ElectricityProducerState,
                    _ => this.RefreshValue(),
                    this);

                this.ViewModelPowerStateOverlay = new ViewModelPowerStateOverlay(publicState);
            }
            else if (worldObject.ProtoStaticWorldObject is IProtoObjectElectricityConsumer)
            {
                // consumer
                var publicState = worldObject.GetPublicState <IObjectElectricityConsumerPublicState>();
                publicState.ClientSubscribe(
                    _ => _.ElectricityConsumerState,
                    _ => this.RefreshValue(),
                    this);

                this.ViewModelPowerStateOverlay = new ViewModelPowerStateOverlay(publicState);
            }
            else
            {
                throw new Exception("The object is not an electricity consumer or producer: " + this.worldObject);
            }

            this.RefreshValue();
            this.RefreshPowerAmountText();
        }
Esempio n. 2
0
        public ViewModelPowerSwitch(IStaticWorldObject worldObject)
        {
            this.worldObject  = worldObject;
            this.privateState = this.worldObject.GetPrivateState <IObjectElectricityStructurePrivateState>();

            this.privateState.ClientSubscribe(
                _ => _.PowerGridChargePercent,
                _ => { this.RefreshPowerGridChargePercent(); },
                this);

            this.privateState.ClientSubscribe(
                _ => _.ElectricityThresholds,
                _ => this.RefreshThresholds(),
                this);

            switch (worldObject.ProtoStaticWorldObject)
            {
            case IProtoObjectElectricityProducer:
            {
                // producer
                var publicState = worldObject.GetPublicState <IObjectElectricityProducerPublicState>();

                publicState.ClientSubscribe(
                    _ => _.ElectricityProducerState,
                    _ => this.RefreshCurrentState(),
                    this);

                this.ViewModelPowerStateOverlay = new ViewModelPowerStateOverlay(publicState);
                break;
            }

            case IProtoObjectElectricityConsumer:
            {
                // consumer
                var publicState = worldObject.GetPublicState <IObjectElectricityConsumerPublicState>();
                publicState.ClientSubscribe(
                    _ => _.ElectricityConsumerState,
                    _ => this.RefreshCurrentState(),
                    this);

                this.ViewModelPowerStateOverlay = new ViewModelPowerStateOverlay(publicState);
                break;
            }
            }

            this.RefreshCurrentState();
            this.RefreshPowerAmountText();
        }
Esempio n. 3
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]);
            }
        }
Esempio n. 4
0
        public static void ServerOnObjectLandClaimBuilt(
            ICharacter byCharacter,
            IStaticWorldObject landClaimStructure)
        {
            if (!(landClaimStructure?.ProtoStaticWorldObject
                  is IProtoObjectLandClaim))
            {
                throw new Exception("Not a land claim structure: " + landClaimStructure);
            }

            // create new area for this land claim structure
            var area             = Api.Server.World.CreateLogicObject <LandClaimArea>();
            var areaPrivateState = LandClaimArea.GetPrivateState(area);
            var areaPublicState  = LandClaimArea.GetPublicState(area);
            var founderName      = byCharacter.Name;

            // setup it
            areaPrivateState.ServerLandClaimWorldObject = landClaimStructure;
            areaPrivateState.LandClaimFounder           = founderName;
            areaPrivateState.LandOwners = new NetworkSyncList <string>()
            {
                founderName
            };

            areaPublicState.Title = founderName;
            areaPublicState.SetupAreaProperties(areaPrivateState);

            // set this area to the structure public state
            landClaimStructure.GetPublicState <ObjectLandClaimPublicState>()
            .LandClaimAreaObject = area;

            ServerOnAddLandOwner(area, byCharacter, notify: false);

            Logger.Important("Land claim area added: " + area);
        }
Esempio n. 5
0
        public ViewModelMeteoriteTooltipControl(IStaticWorldObject worldObjectMeteorite)
        {
            this.cooldownUntil = worldObjectMeteorite.GetPublicState <ObjectMineralMeteoritePublicState>()
                                 .CooldownUntilServerTime;

            this.RefreshTimeRemains();
        }
Esempio n. 6
0
        public ViewModelDepositCapacityStatsControl(IStaticWorldObject worldObjectDeposit)
        {
            this.worldObjectDeposit = worldObjectDeposit;
            if (worldObjectDeposit != null)
            {
                this.publicState  = worldObjectDeposit.GetPublicState <StaticObjectPublicState>();
                this.protoDeposit = (IProtoObjectDeposit)worldObjectDeposit.ProtoStaticWorldObject;

                this.ValueMax = this.protoDeposit.StructurePointsMax;

                // subscribe on updates
                this.publicState.ClientSubscribe(
                    _ => _.StructurePointsCurrent,
                    _ => this.RefreshDepletion(),
                    this);
            }
            else
            {
                // no deposit (assume depleted)
                this.ValueMax = 0;
            }

            this.RefreshDepletion();

            this.RefreshAvailableToClaim();
        }
Esempio n. 7
0
        public static IComponentAttachedControl CreateAndAttach(IStaticWorldObject worldObject)
        {
            var control = new ConstructionOrRepairRequirementsTooltip();

            control.WorldObject = worldObject;

            if (worldObject.ProtoStaticWorldObject is ProtoObjectConstructionSite)
            {
                // construction
                control.Setup(
                    constructionSitePublicState: ProtoObjectConstructionSite.GetPublicState(worldObject));
            }
            else
            {
                // repair
                control.Setup(
                    objectToRepairPublicState: worldObject.GetPublicState <StaticObjectPublicState>());
            }

            var centerOffset = worldObject.ProtoStaticWorldObject.SharedGetObjectCenterWorldOffset(worldObject);

            return(Api.Client.UI.AttachControl(
                       worldObject,
                       control,
                       positionOffset: centerOffset + (0, -0.6),
                       isFocusable: true));
        }
Esempio n. 8
0
 public StaticObjectStructurePointsData(
     IStaticWorldObject staticWorldObject,
     float structurePointsMax)
 {
     this.StaticWorldObject  = staticWorldObject;
     this.State              = staticWorldObject.GetPublicState <StaticObjectPublicState>();
     this.StructurePointsMax = structurePointsMax;
 }
Esempio n. 9
0
 protected override bool TestObject(IStaticWorldObject staticWorldObject)
 {
     return(staticWorldObject.ProtoGameObject is IProtoObjectPlant protoPlant &&
            protoPlant.SharedCanInteract(CurrentCharacter, staticWorldObject, false) &&
            SelectedItem?.ProtoItem is IProtoItemToolWateringCan wateringCan &&
            wateringCan.SharedCanWater(SelectedItem) &&
            !staticWorldObject.GetPublicState <PlantPublicState>().IsWatered);
 }
        public ViewModelWindowLandClaim(
            IStaticWorldObject landClaimWorldObject,
            ILogicObject area)
        {
            this.landClaimWorldObject = landClaimWorldObject;
            this.privateState         = LandClaimArea.GetPrivateState(area);

            var protoLandClaim = (IProtoObjectLandClaim)landClaimWorldObject.ProtoStaticWorldObject;
            var canEditOwners  = protoLandClaim
                                 .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,
                maxOwnersListLength: LandClaimSystemConstants.SharedLandClaimOwnersMax,
                displayedOwnersNumberAdjustment: -1);

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

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

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

            var objectPublicState = landClaimWorldObject.GetPublicState <ObjectLandClaimPublicState>();

            objectPublicState.ClientSubscribe(
                _ => _.LandClaimAreaObject,
                _ => this.RefreshSafeStorageAndPowerGrid(),
                this);

            this.RefreshSafeStorageAndPowerGrid();

            this.ViewModelProtoLandClaimInfoCurrent = new ViewModelProtoLandClaimInfo(this.protoObjectLandClaim);

            ItemsContainerLandClaimSafeStorage.ClientSafeItemsSlotsCapacityChanged
                += this.SafeItemsSlotsCapacityChangedHandler;

            this.RequestDecayInfoTextAsync();

            this.ViewModelShieldProtectionControl = new ViewModelShieldProtectionControl(
                LandClaimSystem.SharedGetLandClaimAreasGroup(area));
        }
Esempio n. 11
0
        public static void RefreshDoorType(IStaticWorldObject door)
        {
            if (!(door.ProtoGameObject is IProtoObjectDoor))
            {
                // not a door
                return;
            }

            door.GetPublicState <ObjectDoorPublicState>().IsHorizontalDoor
                = IsHorizontalDoorNeeded(door.OccupiedTile, checkExistingDoor: false);
        }
Esempio n. 12
0
        public static bool SharedIsRelocatable(IStaticWorldObject objectStructure)
        {
            if (objectStructure.ProtoGameObject is not IProtoObjectStructure protoStructure)
            {
                return(false);
            }

            return(protoStructure.IsRelocatable &&
                   objectStructure.GetPublicState <StaticObjectPublicState>()
                   .StructurePointsCurrent
                   >= protoStructure.StructurePointsMax);
        }
 public ViewModelCrateIconControl(IStaticWorldObject worldObjectCrate)
 {
     this.worldObjectCrate = worldObjectCrate;
     this.publicState      = worldObjectCrate.GetPublicState <ObjectCratePublicState>();
     this.publicState.ClientSubscribe(_ => _.IconSource,
                                      _ =>
     {
         this.NotifyPropertyChanged(nameof(this.IsIconAvailable));
         this.NotifyPropertyChanged(nameof(this.Icon));
     },
                                      this);
 }
Esempio n. 14
0
        public ViewModelWindowSign(
            IStaticWorldObject worldObjectSign)
        {
            this.worldObjectSign = worldObjectSign;
            var publicState = worldObjectSign.GetPublicState <ObjectSignPublicState>();

            publicState.ClientSubscribe(
                _ => _.Text,
                newText => this.SignText = newText,
                this);

            this.SignText = publicState.Text;
        }
        public ViewModelWindowOilRefinery(
            IStaticWorldObject worldObject,
            ManufacturingState manufacturingState,
            ManufacturingState manufacturingStateProcessedGasoline,
            ManufacturingState manufacturingStateProcessedMineralOil,
            ManufacturingConfig manufacturingConfig,
            ManufacturingConfig manufacturingConfigProcessedGasoline,
            ManufacturingConfig manufacturingConfigProcessedMineralOil,
            LiquidContainerState liquidStateRawPetroleum,
            LiquidContainerState liquidStateProcessedGasoline,
            LiquidContainerState liquidStateProcessedMineralOil,
            LiquidContainerConfig liquidConfigRawPetroleum,
            LiquidContainerConfig liquidConfigProcessedGasoline,
            LiquidContainerConfig liquidConfigProcessedMineralOil)
        {
            this.WorldObjectManufacturer = worldObject;

            this.ViewModelManufacturingStateRawPetroleum = new ViewModelManufacturingState(
                worldObject,
                manufacturingState,
                manufacturingConfig);

            this.ViewModelManufacturingStateProcessedGasoline = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedGasoline,
                manufacturingConfigProcessedGasoline);

            this.ViewModelManufacturingStateProcessedMineralOil = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedMineralOil,
                manufacturingConfigProcessedMineralOil);

            this.ViewModelLiquidStateRawPetroleum = new ViewModelLiquidContainerState(
                liquidStateRawPetroleum,
                liquidConfigRawPetroleum);

            this.ViewModelLiquidStateProcessedGasoline = new ViewModelLiquidContainerState(
                liquidStateProcessedGasoline,
                liquidConfigProcessedGasoline);

            this.ViewModelLiquidStateProcessedMineralOil = new ViewModelLiquidContainerState(
                liquidStateProcessedMineralOil,
                liquidConfigProcessedMineralOil);

            // prepare active state property
            this.manufacturerPublicState = worldObject.GetPublicState <ObjectManufacturerPublicState>();
            this.manufacturerPublicState.ClientSubscribe(_ => _.IsActive,
                                                         _ => this.NotifyPropertyChanged(
                                                             nameof(this.IsManufacturingActive)),
                                                         this);
        }
        private static bool ServerIsTradingStationHasActiveLots(IStaticWorldObject tradingStation)
        {
            var publicState = tradingStation.GetPublicState <ObjectTradingStationPublicState>();

            foreach (var lot in publicState.Lots)
            {
                if (lot.State == TradingStationLotState.Available)
                {
                    return(true);
                }
            }

            return(false);
        }
        public ViewModelWindowOilCrackingPlant(
            IStaticWorldObject worldObject,
            ManufacturingState manufacturingState,
            ManufacturingState manufacturingStateProcessedGasoline,
            ManufacturingConfig manufacturingConfig,
            ManufacturingConfig manufacturingConfigProcessedGasoline,
            LiquidContainerState liquidStateMineralOil,
            LiquidContainerState liquidStateProcessedGasoline,
            LiquidContainerConfig liquidConfigMineralOil,
            LiquidContainerConfig liquidConfigProcessedGasoline)
        {
            this.WorldObjectManufacturer = worldObject;

            this.ViewModelManufacturingStateMineralOil = new ViewModelManufacturingState(
                worldObject,
                manufacturingState,
                manufacturingConfig);

            this.ViewModelManufacturingStateProcessedGasoline = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedGasoline,
                manufacturingConfigProcessedGasoline);

            this.ViewModelLiquidStateMineralOil = new ViewModelLiquidContainerState(
                liquidStateMineralOil,
                liquidConfigMineralOil);

            this.ViewModelLiquidStateProcessedGasoline = new ViewModelLiquidContainerState(
                liquidStateProcessedGasoline,
                liquidConfigProcessedGasoline);
            // prepare active state property
            this.manufacturerPublicState = worldObject.GetPublicState <ObjectManufacturerPublicState>();
            this.manufacturerPublicState.ClientSubscribe(_ => _.IsActive,
                                                         _ => NotifyPropertyChanged(nameof(IsManufacturingActive)), this);
            viewModelManufacturerExchange = new ViewModelManufacturerExchange(
                new List <IItemsContainer>
            {
                manufacturingState.ContainerOutput,
                manufacturingStateProcessedGasoline.ContainerOutput
            },
                new List <IItemsContainer>
            {
                manufacturingState.ContainerInput,
                manufacturingStateProcessedGasoline.ContainerInput
            },
                true);
        }
Esempio n. 18
0
        public ViewModelWindowManufacturer(
            IStaticWorldObject worldObjectManufacturer,
            ObjectManufacturerPrivateState privateState,
            ManufacturingConfig manufacturingConfig)
        {
            this.WorldObjectManufacturer = worldObjectManufacturer;
            var fuelBurningState   = privateState.FuelBurningState;
            var manufacturingState = privateState.ManufacturingState;

            // please note - the order of creating these view models is important for the proper container exchange order
            this.ViewModelFuelBurningState = fuelBurningState is not null
                                                 ? new ViewModelFuelBurningState(fuelBurningState)
                                                 : null;

            this.ViewModelManufacturingState = new ViewModelManufacturingState(
                worldObjectManufacturer,
                manufacturingState,
                manufacturingConfig);

            this.ViewModelBurningFuel = ViewModelBurningFuel.Create(worldObjectManufacturer, fuelBurningState);

            this.ViewModelManufacturingState.SubscribePropertyChange(
                _ => _.SelectedRecipe,
                this.RefreshIsNeedFuel);

            this.ViewModelManufacturingState.SubscribePropertyChange(
                _ => _.IsInputMatchSelectedRecipe,
                this.RefreshIsNeedFuel);

            this.ViewModelBurningFuel?.SubscribePropertyChange(
                _ => _.IsActive,
                this.RefreshIsNeedFuel);

            this.ViewModelFuelBurningState?.SubscribePropertyChange(
                _ => _.FuelUsageCurrentValue,
                this.RefreshIsNeedFuel);

            this.ViewModelManufacturingState.ContainerInput.StateHashChanged += this.ContainerInputStateChanged;

            this.RefreshIsNeedFuel();

            this.publicState = worldObjectManufacturer.GetPublicState <ObjectManufacturerPublicState>();
            this.publicState.ClientSubscribe(_ => _.IsActive,
                                             _ => this.NotifyPropertyChanged(nameof(this.IsManufacturingActive)),
                                             this);
        }
Esempio n. 19
0
        public ConstructionActionState(ICharacter character, IStaticWorldObject worldObject, IItem itemConstructionTool)
            : base(character)
        {
            this.WorldObject               = worldObject;
            this.ItemConstructionTool      = itemConstructionTool;
            this.ProtoItemConstructionTool = (IProtoItemToolToolbox)itemConstructionTool.ProtoGameObject;
            var protoStructure = (IProtoObjectStructure)worldObject.ProtoWorldObject;

            this.Config = protoStructure.GetStructureActiveConfig(worldObject);

            this.currentStageTimeRemainsSeconds = this.currentStageDurationSeconds =
                this.CalculateStageDurationSeconds(character, isFirstStage: true);
            this.ObjectPublicState = worldObject.GetPublicState <StaticObjectPublicState>();

            this.structurePointsMax     = protoStructure.SharedGetStructurePointsMax(worldObject);
            this.stageStructureAddValue = this.structurePointsMax / this.Config.StagesCount;
        }
        public DeconstructionActionState(
            ICharacter character,
            IStaticWorldObject worldObject,
            IItem itemCrowbarTool)
            : base(character)
        {
            this.WorldObject          = worldObject;
            this.ItemCrowbarTool      = itemCrowbarTool;
            this.ProtoItemCrowbarTool = (IProtoItemToolCrowbar)itemCrowbarTool?.ProtoGameObject;
            this.protoStructure       = (IProtoObjectStructure)worldObject.ProtoWorldObject;

            this.currentStageDurationSeconds = this.CalculateStageDurationSeconds(character, isFirstStage: true);

            this.currentStageTimeRemainsSeconds = this.currentStageDurationSeconds;
            this.ObjectPublicState = worldObject.GetPublicState <StaticObjectPublicState>();

            this.structurePointsMax = this.protoStructure.SharedGetStructurePointsMax(worldObject);

            // use build config to determine how many deconstruction steps required
            var stagesCount = 10;

            if (!(this.protoStructure is IProtoObjectLandClaim))
            {
                if (this.protoStructure.ConfigBuild.IsAllowed)
                {
                    stagesCount = this.protoStructure.ConfigBuild.StagesCount;
                }
                else
                {
                    stagesCount = this.protoStructure.GetStructureActiveConfig(worldObject)
                                  .StagesCount;
                }
            }

            if (stagesCount <= 0)
            {
                // force at least 1 deconstruction stage
                stagesCount = 1;
            }

            this.stageStructureRemoveValue = this.structurePointsMax / stagesCount;
            if (this.stageStructureRemoveValue < 1)
            {
                this.stageStructureRemoveValue = 1;
            }
        }
Esempio n. 21
0
        public ViewModelWindowSignPicture(
            IStaticWorldObject worldObjectSign)
        {
            this.worldObjectSign = worldObjectSign;
            this.publicState     = worldObjectSign.GetPublicState <ObjectSignPublicState>();

            this.publicState.ClientSubscribe(
                _ => _.Text,
                newText => this.Refresh(),
                this);

            this.Images = SharedSignPictureHelper.AllImagesFileNames
                          .OrderBy(fileName => int.TryParse(fileName, out var result)
                                                                          ? result
                                                                          : 0)
                          .Select(f => new SignPictureData(f))
                          .ToArray();
            this.Refresh();
        }
Esempio n. 22
0
        public static IStaticWorldObject ServerUpgrade(
            IStaticWorldObject oldStructure,
            IProtoObjectStructure upgradeStructure,
            ICharacter character)
        {
            if (!(oldStructure?.ProtoStaticWorldObject
                  is IProtoObjectLandClaim))
            {
                throw new Exception("Not a land claim structure: " + oldStructure);
            }

            var tilePosition = oldStructure.TilePosition;
            var area         = ServerGetLandClaimArea(oldStructure);

            // release area
            oldStructure.GetPublicState <ObjectLandClaimPublicState>().LandClaimAreaObject = null;

            // destroy old structure
            ServerWorld.DestroyObject(oldStructure);

            // create new structure
            var upgradedObject = ServerWorld.CreateStaticWorldObject(upgradeStructure, tilePosition);

            // get area for the old land claim structure
            var areaPrivateState = LandClaimArea.GetPrivateState(area);
            var areaPublicState  = LandClaimArea.GetPublicState(area);

            // update it to use upgraded land claim structure
            areaPrivateState.ServerLandClaimWorldObject = upgradedObject;
            areaPublicState.SetupAreaProperties(areaPrivateState);

            // set this area to the structure public state
            upgradedObject.GetPublicState <ObjectLandClaimPublicState>()
            .LandClaimAreaObject = area;

            Logger.Important($"Successfully upgraded: {oldStructure} to {upgradedObject}", character);

            Instance.CallClient(
                Server.Characters.EnumerateAllPlayerCharacters(onlyOnline: true),
                _ => _.ClientRemote_OnLandClaimUpgraded(area));

            return(upgradedObject);
        }
Esempio n. 23
0
        private ViewModelBurningFuel(IStaticWorldObject worldObjectManufacturer, IFuelItemsContainer fuelItemsContainer)
        {
            // prepare active state property
            var manufacturerPublicState = worldObjectManufacturer.GetPublicState <ObjectManufacturerPublicState>();

            manufacturerPublicState.ClientSubscribe(_ => _.IsActive,
                                                    _ => RefreshIsManufacturerActive(),
                                                    this);
            RefreshIsManufacturerActive();

            void RefreshIsManufacturerActive()
            {
                this.IsActive = manufacturerPublicState.IsActive;
            }

            var(icon, color) = fuelItemsContainer.ClientGetFuelIconAndColor();
            this.FuelIcon    = Client.UI.GetTextureBrush(icon);
            this.FuelColor   = color;
        }
Esempio n. 24
0
        private static bool SharedIsCompatibleDoor(
            IStaticWorldObject worldObject,
            Tile tile,
            bool isConsiderConstructionSites,
            bool isHorizontal)
        {
            if (worldObject.ProtoWorldObject is IProtoObjectDoor &&
                isHorizontal == worldObject.GetPublicState <ObjectDoorPublicState>().IsHorizontalDoor)
            {
                return(true);
            }

            if (isConsiderConstructionSites &&
                ProtoObjectConstructionSite.SharedIsConstructionOf(worldObject, typeof(IProtoObjectDoor)) &&
                isHorizontal == DoorHelper.IsHorizontalDoorNeeded(tile, checkExistingDoor: true))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 25
0
        public ViewModelDepositCapacityStatsControl(IStaticWorldObject worldObjectDeposit, Vector2Ushort tilePosition)
        {
            this.worldObjectDeposit = worldObjectDeposit;
            this.tilePosition       = tilePosition;
            if (worldObjectDeposit is not null)
            {
                this.publicState  = worldObjectDeposit.GetPublicState <StaticObjectPublicState>();
                this.protoDeposit = (IProtoObjectDeposit)worldObjectDeposit.ProtoStaticWorldObject;

                this.ValueMax = this.protoDeposit.StructurePointsMax;

                // subscribe on updates
                this.publicState.ClientSubscribe(
                    _ => _.StructurePointsCurrent,
                    _ => this.RefreshDepletion(),
                    this);
            }

            this.RefreshAvailableToClaim();

            this.RefreshByTimer();
        }
Esempio n. 26
0
 protected override bool AdditionalValidation(IStaticWorldObject testWorldObject)
 {
     return(!ChopOnlyFullyGrown ||
            testWorldObject.GetPublicState <VegetationPublicState>()
            .IsFullGrown((IProtoObjectTree)testWorldObject.ProtoStaticWorldObject));
 }
Esempio n. 27
0
        private void ServerGatheringSystemGatherHandler(ICharacter character, IStaticWorldObject worldObject)
        {
            if (!(worldObject.ProtoStaticWorldObject is ObjectCorpse))
            {
                return;
            }

            // corpse gathered!
            // find the device and vial
            var itemDevice = character.SharedGetPlayerContainerEquipment()
                             .GetItemsOfProto(this)
                             .FirstOrDefault();

            if (itemDevice == null)
            {
                // don't have an equipped device
                return;
            }

            var protoItemVialEmpty = GetProtoEntity <ItemVialEmpty>();

            // require at least one vial
            if (!character.ContainsItemsOfType(protoItemVialEmpty, requiredCount: 1))
            {
                // don't have an empty vial
                this.CallClient(character, _ => _.ClientRemote_NotEnoughEmptyVials());
                return;
            }

            var protoMob = (IProtoCharacterCore)worldObject.GetPublicState <ObjectCorpse.PublicState>()
                           .ProtoCharacterMob;
            var healthMax     = protoMob.StatDefaultHealthMax;
            var maxVialsToUse = (ushort)MathHelper.Clamp(Math.Floor(healthMax / 100.0),
                                                         min: 1,
                                                         max: 10);

            // destroy empty vial
            Server.Items.DestroyItemsOfType(
                character,
                protoItemVialEmpty,
                maxVialsToUse,
                out var destroyedEmptyVialsCount);

            if (destroyedEmptyVialsCount == 0)
            {
                // cannot destroy any empty vial (should be impossible)
                return;
            }

            // spawn biomaterial vials
            var createItemResult = Server.Items.CreateItem <ItemVialBiomaterial>(character,
                                                                                 count: destroyedEmptyVialsCount);

            var itemChangedCount = NotificationSystem.SharedGetItemsChangedCount(createItemResult);

            itemChangedCount.Add(protoItemVialEmpty, -(int)destroyedEmptyVialsCount);
            NotificationSystem.ServerSendItemsNotification(character, itemChangedCount);

            ItemDurabilitySystem.ServerModifyDurability(itemDevice, -DurabilityDecreasePerUse);
            Logger.Info("Biomaterial collected successfully with Biomaterial collector", character);
        }
Esempio n. 28
0
        private void ServerGatheringSystemGatherHandler(ICharacter character, IStaticWorldObject worldObject)
        {
            if (!(worldObject.ProtoStaticWorldObject is ObjectCorpse))
            {
                return;
            }

            // corpse looted
            // find the device and vial
            var itemDevice = character.SharedGetPlayerContainerEquipment()
                             .GetItemsOfProto(this)
                             .FirstOrDefault();

            if (itemDevice is null)
            {
                // don't have an equipped device
                return;
            }

            var protoItemVialEmpty = GetProtoEntity <ItemVialEmpty>();

            // require at least one vial
            if (!character.ContainsItemsOfType(protoItemVialEmpty, requiredCount: 1))
            {
                // don't have an empty vial
                this.CallClient(character, _ => _.ClientRemote_NotEnoughEmptyVials());
                return;
            }

            var protoMob = worldObject.GetPublicState <ObjectCorpse.PublicState>()
                           .ProtoCharacterMob;
            var healthMax     = protoMob.StatDefaultHealthMax;
            var maxVialsToUse = (ushort)MathHelper.Clamp(
                Math.Floor(protoMob.BiomaterialValueMultiplier * healthMax / 100.0),
                min: 1,
                max: 10);

            // destroy empty vial
            Server.Items.DestroyItemsOfType(
                character,
                protoItemVialEmpty,
                maxVialsToUse,
                out var destroyedEmptyVialsCount);

            if (destroyedEmptyVialsCount == 0)
            {
                // cannot destroy any empty vial (should be impossible)
                return;
            }

            // spawn biomaterial vials
            var protoItemVialBiomaterial = Api.GetProtoEntity <ItemVialBiomaterial>();
            var createItemResult         = Server.Items.CreateItem(protoItemVialBiomaterial,
                                                                   character,
                                                                   count: destroyedEmptyVialsCount);

            if (!createItemResult.IsEverythingCreated)
            {
                createItemResult.Rollback();
                var groundItemsContainer =
                    ObjectGroundItemsContainer.ServerTryGetOrCreateGroundContainerAtTileOrNeighbors(character,
                                                                                                    character.Tile);
                if (groundItemsContainer is null)
                {
                    Logger.Error("Not enough space around the player to drop a full vial");
                    // restore items
                    Server.Items.CreateItem(protoItemVialEmpty,
                                            character,
                                            destroyedEmptyVialsCount);
                    return;
                }

                createItemResult = Server.Items.CreateItem(protoItemVialBiomaterial,
                                                           groundItemsContainer,
                                                           count: destroyedEmptyVialsCount);
                if (!createItemResult.IsEverythingCreated)
                {
                    createItemResult.Rollback();
                    Logger.Error("Not enough space around the player to drop a full vial");
                    // restore items
                    Server.Items.CreateItem(protoItemVialEmpty,
                                            character,
                                            destroyedEmptyVialsCount);
                    return;
                }

                NotificationSystem.ServerSendNotificationNoSpaceInInventoryItemsDroppedToGround(character,
                                                                                                protoItemVialBiomaterial);
            }

            var itemChangedCount = NotificationSystem.SharedGetItemsChangedCount(createItemResult);

            itemChangedCount.Add(protoItemVialEmpty, -(int)destroyedEmptyVialsCount);
            NotificationSystem.ServerSendItemsNotification(character, itemChangedCount);

            ItemDurabilitySystem.ServerModifyDurability(itemDevice, -DurabilityDecreasePerUse);
            Logger.Info("Biomaterial collected successfully with Biomaterial collector", character);
        }
Esempio n. 29
0
 public ViewModelTurretNoAmmoOverlay(IStaticWorldObject worldObject)
 {
     this.publicState = worldObject.GetPublicState <ObjectTurretPublicState>();
     this.Update();
     ClientUpdateHelper.UpdateCallback += this.Update;
 }
Esempio n. 30
0
 private static ObjectTradingStationPublicState GetPublicState(IStaticWorldObject tradingStation)
 {
     return(tradingStation.GetPublicState <ObjectTradingStationPublicState>());
 }