Beispiel #1
0
        private bool CheckIsBarShouldBeVisible()
        {
            if (ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) ||
                Input.IsKeyHeld(InputKey.Alt, evenIfHandled: true) ||
                (this.lastStructurePointsValueUpdateTimestamp > 0 &&
                 Core.ClientRealTime - this.lastStructurePointsValueUpdateTimestamp
                 < SecondsToDisplayHealthbarAfterDamage) ||
                Api.IsEditor && Client.Characters.IsCurrentPlayerCharacterSpectator)
            {
                return(true);
            }

            if (ClientComponentObjectInteractionHelper.CurrentMouseOverObject
                == this.data.StaticWorldObject)
            {
                return(true);
            }

            if (this.isDamagedBelowThreshold)
            {
                var playerPosition = ClientCurrentCharacterHelper.Character.TilePosition;
                var tilePosition   = this.data.StaticWorldObject.TilePosition;
                return(tilePosition.TileSqrDistanceTo(playerPosition)
                       <= MaxDistance * MaxDistance);
            }

            return(false);
        }
Beispiel #2
0
        private bool CheckIsBarShouldBeVisible()
        {
            if (this.vehicle is null)
            {
                return(false);
            }

            if (ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) ||
                Input.IsKeyHeld(InputKey.Alt, evenIfHandled: true) ||
                Api.IsEditor && Client.Characters.IsCurrentPlayerCharacterSpectator ||
                (this.lastStructurePointsValueUpdateTimestamp > 0 &&
                 Core.ClientRealTime - this.lastStructurePointsValueUpdateTimestamp
                 < ClientComponentAutoDisplayStructurePointsBar.SecondsToDisplayHealthbarAfterDamage))
            {
                return(true);
            }

            if (this.IsDisplayedOnlyOnMouseOver &&
                (!ReferenceEquals(ClientComponentObjectInteractionHelper.MouseOverObject,
                                  this.vehicle)))
            {
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        static ClientLandClaimAreaManager()
        {
            RendererGraceAreas = new ClientLandClaimAreaRenderer(
                ZoneColorGraceArea,
                inflateSize: LandClaimSystem.LandClaimAreaGracePaddingSize,
                drawOrder: DrawOrder.Overlay - 3);

            RendererAreasOwnedByPlayer = new ClientLandClaimAreaRenderer(
                ZoneColorOwnedByPlayer,
                drawOrder: DrawOrder.Overlay - 2);

            RendererAreasNotOwnedByPlayer = new ClientLandClaimAreaRenderer(
                ZoneColorNotOwnedByPlayer,
                drawOrder: DrawOrder.Overlay - 1);

            Api.Client.World.WorldBoundsChanged += WorldBoundsChangedHandler;
            WorldBoundsChangedHandler();

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            ClientInputContext.Start("Land claim visualizer")
            .HandleAll(
                () =>
            {
                var isDisplayed = ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) ||
                                  Api.Client.Input.IsKeyHeld(InputKey.Alt) ||
                                  (ConstructionPlacementSystem
                                   .IsObjectPlacementComponentEnabled);

                RendererAreasOwnedByPlayer.IsVisible    = isDisplayed;
                RendererAreasNotOwnedByPlayer.IsVisible = isDisplayed;
                RendererGraceAreas.IsVisible            = isDisplayed;
            });
        }
Beispiel #4
0
        public static void ClientTryStartAction()
        {
            if (!(ClientHotbarSelectedItemManager.SelectedItem?.ProtoGameObject
                  is IProtoItemVehicleRepairKit))
            {
                // no tool is selected
                return;
            }

            if (!ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem))
            {
                // the tool is not currently used
                return;
            }

            var vehicleToRepair = ClientGetObjectToRepairAtCurrentMousePosition();

            if (vehicleToRepair is null)
            {
                return;
            }

            var currentCharacter = Client.Characters.CurrentPlayerCharacter;
            var privateState     = PlayerCharacter.GetPrivateState(currentCharacter);

            if (privateState.CurrentActionState is VehicleRepairActionState actionState &&
                ReferenceEquals(actionState.Vehicle, vehicleToRepair))
            {
                // the same object is already repairing
                return;
            }

            SharedStartAction(currentCharacter, vehicleToRepair);
        }
Beispiel #5
0
        private static void Update()
        {
            var frameNumber = Api.Client.Core.ClientFrameNumber;

            using var tempChangesList =
                      Api.Shared.GetTempList <(IStaticWorldObject worldObject, StructureLandClaimIndicator control)>();

            var forceDisplayAll = ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) ||
                                  Api.Client.Input.IsKeyHeld(InputKey.Alt, evenIfHandled: true);

            var playerPosition = ClientCurrentCharacterHelper.Character?.TilePosition ?? Vector2Ushort.Zero;

            foreach (var pair in initializedOverlays)
            {
                var worldObject = pair.Key;
                if ((frameNumber + worldObject.Id) % 10 != 0)
                {
                    // don't refresh every object every frame
                    continue;
                }

                var isDisplayed = false;

                if (forceDisplayAll ||
                    IsNearby(worldObject, playerPosition))
                {
                    // can display only if close enough of if Alt/L key is held
                    isDisplayed = !LandClaimSystem.SharedIsObjectInsideAnyArea(worldObject);
                }

                var control = pair.Value;

                if (isDisplayed)
                {
                    if (control != null)
                    {
                        continue;
                    }

                    var component = SetupFor(worldObject, isClaimed: false);
                    control = (StructureLandClaimIndicator)component.Control;
                    tempChangesList.Add((worldObject, control));
                    continue;
                }

                if (control is null)
                {
                    continue;
                }

                tempChangesList.Add((worldObject, null));
                DestroyControl(control);
            }

            foreach (var entry in tempChangesList.AsList())
            {
                initializedOverlays[entry.worldObject] = entry.control;
            }
        }
 private static void ClientUpdate()
 {
     if (ClientConstructionCooldownIsWaitingButtonRelease &&
         !ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem))
     {
         ClientConstructionCooldownIsWaitingButtonRelease = false;
     }
 }
        private void ProcessInputUpdate()
        {
            if (this.publicState.IsDead)
            {
                // cannot use hotbar items
                this.InputIsUsingItem = false;
                return;
            }

            if (!MainMenuOverlay.IsHidden)
            {
                // cannot use hotbar items - main menu overlay is displayed
                this.InputIsUsingItem = false;
                return;
            }

            const bool evenIfHandled  = true;
            var        isQuickUseItem = (Input.IsKeyHeld(InputKey.Control, evenIfHandled) ||
                                         Input.IsKeyHeld(InputKey.Alt, evenIfHandled)) &&
                                        !(ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem, evenIfHandled) ||
                                          ClientInputManager.IsButtonHeld(GameButton.ActionInteract, evenIfHandled));

            foreach (var pair in KeysMapping)
            {
                if (!ClientInputManager.IsButtonDown(pair.Key))
                {
                    continue;
                }

                // the key was pressed
                var hotbarSlotId = pair.Value;

                if (isQuickUseItem)
                {
                    // try to use an item from the hotbar slot
                    var item = ClientHotbarSelectedItemManager.ContainerHotbar.GetItemAtSlot(hotbarSlotId);
                    ClientItemManagementCases.TryUseItem(item);
                }
                else
                {
                    // select the hotbar slot
                    ClientHotbarSelectedItemManager.SelectedSlotId = hotbarSlotId;
                }

                break;
            }

            var canUseHotbarItems = WindowsManager.OpenedWindowsCount == 0;

            if (!canUseHotbarItems)
            {
                this.InputIsUsingItem = false;
                return;
            }

            this.InputIsUsingItem = ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem);
        }
        private bool CheckIsBarShouldBeVisible()
        {
            if (ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) ||
                InputClientService.IsKeyHeld(InputKey.Alt, evenIfHandled: true))
            {
                return(true);
            }

            return(ClientComponentObjectInteractionHelper.CurrentMouseOverObject
                   == this.data.StaticWorldObject);
        }
Beispiel #9
0
        static ClientLandClaimAreaManager()
        {
            RendererManagerGraceAreas = new ClientLandClaimGroupsRendererManager(
                LandClaimZoneColors.ZoneColorGraceArea,
                drawOrder: DrawOrder.Overlay - 3,
                isGraceAreaRenderer: true,
                isFlippedTexture: true);

            RendererManagerNotOwnedByPlayer = new ClientLandClaimGroupsRendererManager(
                LandClaimZoneColors.ZoneColorNotOwnedByPlayer,
                drawOrder: DrawOrder.Overlay - 2,
                isFlippedTexture: true);

            RendererManagerOwnedByPlayer = new ClientLandClaimGroupsRendererManager(
                LandClaimZoneColors.ZoneColorOwnedByPlayer,
                drawOrder: DrawOrder.Overlay - 1,
                isFlippedTexture: false);

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            ClientInputContext.Start("Land claim visualizer")
            .HandleAll(
                () =>
            {
                var isDisplayed =
                    ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) ||
                    Api.Client.Input.IsKeyHeld(InputKey.Alt,
                                               evenIfHandled: true) ||
                    ConstructionPlacementSystem.IsInObjectPlacementMode ||
                    ConstructionRelocationSystem.IsInObjectPlacementMode;

                if (isDisplayed)
                {
                    var isDisplayOverlays = Api.Client.Input.IsKeyHeld(InputKey.Control,
                                                                       evenIfHandled: true);

                    RendererManagerOwnedByPlayer.IsDisplayOverlays
                            = RendererManagerNotOwnedByPlayer.IsDisplayOverlays
                            = RendererManagerGraceAreas.IsDisplayOverlays
                            = isDisplayOverlays;
                }

                RendererManagerOwnedByPlayer.IsEnabled
                        = RendererManagerNotOwnedByPlayer.IsEnabled
                        = RendererManagerGraceAreas.IsEnabled
                        = isDisplayed;
            });
        }
Beispiel #10
0
        private bool CheckIsBarShouldBeVisible()
        {
            if (this.vehicle is null)
            {
                return(false);
            }

            var currentPlayerCharacter = Api.Client.Characters.CurrentPlayerCharacter;

            if (ReferenceEquals(this.vehiclePublicState.PilotCharacter,
                                currentPlayerCharacter))
            {
                return(this.IsArmorBarDisplayedWhenPiloted &&
                       GeneralOptionDisplayHealthbarAboveCurrentCharacter.IsDisplay &&
                       currentPlayerCharacter.ProtoGameObject.GetType() == typeof(PlayerCharacter));
            }

            if (ClientInputManager.IsButtonHeld(GameButton.DisplayLandClaim) ||
                Input.IsKeyHeld(InputKey.Alt, evenIfHandled: true) ||
                Api.IsEditor && Client.Characters.IsCurrentPlayerCharacterSpectator ||
                (this.lastStructurePointsValueUpdateTimestamp > 0 &&
                 Core.ClientRealTime - this.lastStructurePointsValueUpdateTimestamp
                 < ClientComponentAutoDisplayStructurePointsBar.SecondsToDisplayHealthbarAfterDamage))
            {
                return(true);
            }

            if (!this.IsArmorBarDisplayedWhenPiloted &&
                this.vehiclePublicState.PilotCharacter is not null)
            {
                return(false);
            }

            if (this.IsDisplayedOnlyOnMouseOver &&
                (!ReferenceEquals(ClientComponentObjectInteractionHelper.MouseOverObject,
                                  this.vehicle)))
            {
                return(false);
            }

            return(true);
        }
Beispiel #11
0
        private void ProcessInputUpdate()
        {
            if (this.publicState.IsDead)
            {
                // cannot use hotbar items
                this.InputIsUsingItem = false;
                return;
            }

            if (!MainMenuOverlay.IsHidden)
            {
                // cannot use hotbar items - main menu overlay is displayed
                this.InputIsUsingItem = false;
                return;
            }

            var keysMapping = Api.Client.Input.IsKeyHeld(InputKey.Control, evenIfHandled: true)
                                  ? KeysMappingWhileControlKeyHeld
                                  : KeysMapping;

            foreach (var pair in keysMapping)
            {
                if (ClientInputManager.IsButtonDown(pair.Key))
                {
                    // the key was pressed - select according slot
                    ClientHotbarSelectedItemManager.SelectedSlotId = pair.Value;
                    break;
                }
            }

            var canUseHotbarItems = WindowsManager.OpenedWindowsCount == 0;

            if (!canUseHotbarItems)
            {
                this.InputIsUsingItem = false;
                return;
            }

            this.InputIsUsingItem = ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem);
        }
Beispiel #12
0
        private void ClientOnPaintZone(List <Vector2Ushort> tilePositions, bool isRepeat)
        {
            var selectedZoneForBrush = this.settings.SelectedZoneForBrush;

            if (selectedZoneForBrush is null ||
                !selectedZoneForBrush.IsRendered)
            {
                // no zone selected for brush or zone is not visible
                return;
            }

            var protoZone    = selectedZoneForBrush.Zone;
            var zoneProvider = ClientZoneProvider.Get(protoZone);

            if (!zoneProvider.IsDataReceived)
            {
                return;
            }

            var world = Client.World;
            var onlyOnTheSameHeight = this.settings.IsAllowZoneChangeOnlyOnTheSameHeight;

            if (this.settings.IsFillZoneMode)
            {
                if (isRepeat)
                {
                    // fill doesn't support repeat
                    return;
                }

                tilePositions = EditorTileHelper.GatherAllTilePositionsOfTheSameProtoTile(
                    tilePositions[0],
                    onlyOnTheSameHeight,
                    ignoreCliffsAndSlopes: true);
            }

            this.lastUsedZoneProvider = zoneProvider;

            if (onlyOnTheSameHeight &&
                !isRepeat)
            {
                // capture height when starting painting the zone
                this.capturedHeight = this.settings.IsFillZoneMode
                                          ? world.GetTile(tilePositions[0]).Height
                                          : EditorTileHelper.CalculateAverageHeight(tilePositions);
            }

            var onlyOnTheSameTileProto = this.settings.IsAllowZoneChangeOnlyOnTheSameTileProto;

            if (onlyOnTheSameTileProto &&
                !isRepeat)
            {
                // capture tile proto when starting painting the zone
                this.capturedTileProto = this.settings.IsFillZoneMode
                                             ? world.GetTile(tilePositions[0]).ProtoTile
                                             : EditorTileHelper.CalculateMostFrequentTileProto(tilePositions);
            }

            // determine the mode - adding points to zone or removing them
            var isAddMode = ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem, evenIfHandled: true) ||
                            ClientInputManager.IsButtonUp(GameButton.ActionUseCurrentItem, evenIfHandled: true);

            if (isAddMode)
            {
                // remove points which are already added to the zone
                tilePositions.RemoveAll(tilePosition => zoneProvider.IsFilledPosition(tilePosition));
            }
            else
            {
                // remove points which are not presented in the zone
                tilePositions.RemoveAll(tilePosition => !zoneProvider.IsFilledPosition(tilePosition));
            }

            if (tilePositions.Count == 0)
            {
                // nothing to add/remove
                return;
            }

            if (onlyOnTheSameHeight)
            {
                // remove tiles with different height
                tilePositions.RemoveAll(
                    tilePosition =>
                {
                    var tile = world.GetTile(tilePosition);
                    return(tile.Height != this.capturedHeight
                           // also do not allow painting on cliffs and slopes
                           || tile.IsCliff ||
                           tile.IsSlope);
                });
                if (tilePositions.Count == 0)
                {
                    // nothing to add/remove
                    return;
                }
            }

            if (onlyOnTheSameTileProto)
            {
                // remove tiles with different proto
                var worldService = Client.World;
                tilePositions.RemoveAll(
                    tilePosition => worldService.GetTile(tilePosition).ProtoTile
                    != this.capturedTileProto);

                if (tilePositions.Count == 0)
                {
                    // nothing to add/remove
                    return;
                }
            }

            foreach (var tilePosition in tilePositions)
            {
                if (isAddMode)
                {
                    // add point to the zone
                    zoneProvider.SetFilledPosition(tilePosition);
                }
                else
                {
                    // remove point from the zone
                    zoneProvider.ResetFilledPosition(tilePosition);
                }
            }

            this.lastUsedZoneProvider.ApplyClientChanges(forcePushChangesImmediately: tilePositions.Count > 10000);
        }
        public void Update()
        {
            if (this.IsFrozen ||
                this.IsDestroyed)
            {
                return;
            }

            if (WindowsManager.OpenedWindowsCount > 0)
            {
                // a window is opened - disable all the renderers
                this.DestroyComponents();
                return;
            }

            if (this.delayRemainsSeconds > 0)
            {
                this.delayRemainsSeconds -= Client.Core.DeltaTime;
            }

            var isUpdateRequired = false;

            this.isCanBuildChanged = false;
            if (this.blueprintRenderer == null)
            {
                // first update called
                this.SetupComponents();
                isUpdateRequired = true;
            }

            if (!isUpdateRequired &&
                this.isCancelable)
            {
                if (ClientInputManager.IsButtonDown(GameButton.CancelOrClose) ||
                    ClientInputManager.IsButtonDown(GameButton.ActionInteract))
                {
                    // cancel/quit placement mode by Escape key or interaction (RMB click)
                    ClientInputManager.ConsumeButton(GameButton.CancelOrClose);
                    ClientInputManager.ConsumeButton(GameButton.ActionInteract);
                    this.Destroy();
                    return;
                }
            }

            var tilePosition         = Client.Input.MousePointedTilePosition;
            var tilePositionVector2D = tilePosition.ToVector2D();

            this.cachedTimeRemainsSeconds -= Client.Core.DeltaTime;

            var isCanBuildThisPhase = !isUpdateRequired;

            var isPositionChanged = this.SceneObject.Position != tilePositionVector2D;

            if (isUpdateRequired ||
                isPositionChanged ||
                this.cachedTimeRemainsSeconds <= 0)
            {
                this.SceneObject.Position = tilePositionVector2D;
                this.UpdateBlueprint(tilePosition);

                if (this.isRepeatCallbackIfHeld &&
                    (isPositionChanged ||
                     this.isCanBuildChanged) &&
                    (this.blueprintRenderer?.IsEnabled ?? false) &&
                    ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem))
                {
                    // mouse moved while LMB is held
                    this.OnPlaceSelected(tilePosition, isButtonHeld: true);
                }
            }

            if (isCanBuildThisPhase &&
                (this.blueprintRenderer?.IsEnabled ?? false) &&
                ClientInputManager.IsButtonDown(GameButton.ActionUseCurrentItem))
            {
                // clicked on place
                this.OnPlaceSelected(tilePosition, isButtonHeld: false);
            }
        }
Beispiel #14
0
        public static void ClientTryStartAction(bool allowReplacingCurrentConstructionAction)
        {
            if (!(ClientHotbarSelectedItemManager.SelectedItem?.ProtoGameObject
                  is IProtoItemToolToolbox))
            {
                // no tool is selected
                return;
            }

            if (!ClientInputManager.IsButtonHeld(GameButton.ActionUseCurrentItem))
            {
                // the tool is not currently used
                return;
            }

            var worldObjects = ClientGetObjectsAtCurrentMousePosition();

            IStaticWorldObject worldObjectToBuildOrRepair = null,
                               worldObjectToRelocate      = null;

            // find first damaged or incomplete structure there
            foreach (var worldObject in worldObjects)
            {
                if (!(worldObject.ProtoGameObject is IProtoObjectStructure protoObjectStructure))
                {
                    continue;
                }

                var maxStructurePointsMax =
                    protoObjectStructure.SharedGetStructurePointsMax((IStaticWorldObject)worldObject);
                var structurePointsCurrent =
                    worldObject.GetPublicState <StaticObjectPublicState>().StructurePointsCurrent;
                if (structurePointsCurrent < maxStructurePointsMax)
                {
                    worldObjectToBuildOrRepair = (IStaticWorldObject)worldObject;
                    break;
                }

                if (ConstructionRelocationSystem.SharedIsRelocatable((IStaticWorldObject)worldObject))
                {
                    worldObjectToRelocate = (IStaticWorldObject)worldObject;
                }
            }

            if (worldObjectToBuildOrRepair is null)
            {
                if (!(worldObjectToRelocate is null))
                {
                    ConstructionRelocationSystem.ClientStartRelocation(worldObjectToRelocate);
                }

                return;
            }

            var currentCharacter = Client.Characters.CurrentPlayerCharacter;
            var privateState     = PlayerCharacter.GetPrivateState(currentCharacter);

            if (privateState.CurrentActionState is ConstructionActionState actionState)
            {
                if (!allowReplacingCurrentConstructionAction)
                {
                    // already performing the action
                    return;
                }

                if (ReferenceEquals(actionState.WorldObject, worldObjectToBuildOrRepair))
                {
                    // the same object is already building/repairing
                    return;
                }
            }

            SharedStartAction(currentCharacter, worldObjectToBuildOrRepair);
        }