예제 #1
0
        public static void SharedActionCompleted(ICharacter character, ConstructionActionState state)
        {
            var worldObject = state.WorldObject;

            Logger.Info($"Building/repairing completed: {worldObject} by {character}", character);

            var characterPrivateState = PlayerCharacter.GetPrivateState(character);

            if (characterPrivateState.CurrentActionState != state)
            {
                throw new Exception("Should be impossible!");
            }

            characterPrivateState.SetCurrentActionState(null);

            if (IsClient)
            {
                // play success sound
                Api.GetProtoEntity <ObjectConstructionSite>()
                .SharedGetObjectSoundPreset()
                .PlaySound(ObjectSound.InteractSuccess,
                           limitOnePerFrame: false,
                           volume: 0.5f);

                // attempt to start the action again (player can move the cursor to the new blueprint to continue building after this one)
                ClientTryStartAction(allowReplacingCurrentConstructionAction: false);
            }
        }
예제 #2
0
 public static void SharedOnNotEnoughItemsAvailable(ConstructionActionState state)
 {
     if (Api.IsClient)
     {
         // show the notification directly
         Instance.ClientRemote_ShowNotEnoughItemsNotification(state.ProtoItemConstructionTool);
     }
     else
     {
         Instance.CallClient(
             state.Character,
             _ => _.ClientRemote_ShowNotEnoughItemsNotification(state.ProtoItemConstructionTool));
     }
 }
예제 #3
0
        public static void SharedActionCompleted(ICharacter character, ConstructionActionState state)
        {
            var worldObject = state.WorldObject;

            Logger.Info($"Building/repairing completed: {worldObject} by {character}", character);

            var characterPrivateState = PlayerCharacter.GetPrivateState(character);

            if (characterPrivateState.CurrentActionState != state)
            {
                throw new Exception("Should be impossible!");
            }

            characterPrivateState.SetCurrentActionState(null);
        }
예제 #4
0
        private static void SharedStartAction(ICharacter character, IWorldObject worldObject)
        {
            if (!(worldObject?.ProtoGameObject is IProtoObjectStructure))
            {
                return;
            }

            var characterPrivateState = PlayerCharacter.GetPrivateState(character);
            var characterPublicState  = PlayerCharacter.GetPublicState(character);

            if (characterPrivateState.CurrentActionState is ConstructionActionState actionState &&
                actionState.WorldObject == worldObject)
            {
                // already building/repairing specified object
                return;
            }

            var selectedHotbarItem = characterPublicState.SelectedHotbarItem;

            if (!(selectedHotbarItem?.ProtoGameObject is IProtoItemToolToolbox))
            {
                // no tool is selected
                return;
            }

            actionState = new ConstructionActionState(character, (IStaticWorldObject)worldObject, selectedHotbarItem);
            if (!actionState.CheckIsNeeded())
            {
                // action is not needed
                Logger.Info($"Building/repairing is not required: {worldObject} by {character}", character);
                return;
            }

            if (!SharedCheckCanInteract(character, worldObject, writeToLog: true))
            {
                return;
            }

            if (!actionState.Config.IsAllowed)
            {
                // not allowed to build/repair
                // this code should never execute for a valid client
                Logger.Warning(
                    $"Building/repairing is not allowed by object build/repair config: {worldObject} by {character}",
                    character);

                if (Api.IsClient)
                {
                    NotificationSystem.ClientShowNotification(
                        // ReSharper disable once CanExtractXamlLocalizableStringCSharp
                        "Cannot construct",
                        // ReSharper disable once CanExtractXamlLocalizableStringCSharp
                        "Not constructable.",
                        NotificationColor.Bad,
                        selectedHotbarItem.ProtoItem.Icon);
                }

                return;
            }

            if (!actionState.ValidateRequiredItemsAvailable())
            {
                // action is not possible
                // logging is not required here - it's done automatically by the validation method
                return;
            }

            characterPrivateState.SetCurrentActionState(actionState);

            Logger.Info($"Building/repairing started: {worldObject} by {character}", character);

            if (IsClient)
            {
                // TODO: we need animation for building/repairing
                Instance.CallServer(_ => _.ServerRemote_StartAction(worldObject));
            }
        }