Ejemplo n.º 1
0
        private bool SharedValidateCanCompleteTask(
            IStaticWorldObject worldObject,
            int taskIndex,
            ICharacter character)
        {
            var privateState = GetPrivateState(worldObject);

            var taskCompletionState = privateState.TaskCompletionState;

            if (taskCompletionState[taskIndex])
            {
                Logger.Warning("Task already completed", character);
                return(false);
            }

            if (InputItemsHelper.SharedPlayerHasRequiredItems(character,
                                                              this.TasksList[taskIndex].InputItems,
                                                              noCheckInCreativeMode: true))
            {
                return(true);
            }

            Logger.Warning("Not enough items to finish the task", character);

            if (IsClient)
            {
                NotificationSystem.ClientShowNotification(
                    ConstructionSystem.NotificationNotEnoughItems_Message,
                    color: NotificationColor.Bad,
                    icon: this.Icon);
            }

            return(false);
        }
Ejemplo n.º 2
0
        private void ServerRemote_BuildReactor(IStaticWorldObject worldObjectGenerator, byte reactorIndex)
        {
            this.VerifyGameObject(worldObjectGenerator);
            var character = ServerRemoteContext.Character;

            if (!this.SharedCanInteract(character, worldObjectGenerator, writeToLog: true))
            {
                return;
            }

            if (reactorIndex >= this.ReactorsCountMax)
            {
                throw new ArgumentOutOfRangeException(nameof(reactorIndex));
            }

            var privateState = GetPrivateState(worldObjectGenerator);
            var publicState  = GetPublicState(worldObjectGenerator);

            var reactorPrivateStates = privateState.ReactorStates;
            var reactorPrivateState  = reactorPrivateStates[reactorIndex];

            if (reactorPrivateState is not null)
            {
                throw new Exception($"The reactor is already built: #{reactorIndex} in {worldObjectGenerator}");
            }

            if (!InputItemsHelper.SharedPlayerHasRequiredItems(character,
                                                               this.BuildAdditionalReactorRequiredItems,
                                                               noCheckInCreativeMode: true))
            {
                throw new Exception($"Not enough items to build a reactor: #{reactorIndex} in {worldObjectGenerator}");
            }

            if (!CreativeModeSystem.SharedIsInCreativeMode(character))
            {
                InputItemsHelper.ServerDestroyItems(character, this.BuildAdditionalReactorRequiredItems);
            }

            reactorPrivateState = new ObjectGeneratorPragmiumReactorPrivateState();
            reactorPrivateStates[reactorIndex] = reactorPrivateState;

            this.ServerSetupReactorPrivateState(worldObjectGenerator, reactorPrivateState);

            var reactorPublicStates = publicState.ReactorStates;

            reactorPublicStates[reactorIndex] = new ObjectGeneratorPragmiumReactorPublicState();

            // force refresh over the network and properly binding the state owner object
            privateState.ReactorStates = reactorPrivateStates.ToArray();
            publicState.ReactorStates  = reactorPublicStates.ToArray();
        }
Ejemplo n.º 3
0
        public void ClientBuildReactor(IStaticWorldObject worldObjectGenerator, byte reactorIndex)
        {
            if (!InputItemsHelper.SharedPlayerHasRequiredItems(ClientCurrentCharacterHelper.Character,
                                                               this.BuildAdditionalReactorRequiredItems,
                                                               noCheckInCreativeMode: true))
            {
                NotificationSystem.ClientShowNotification(
                    ObjectTinkerTable.ErrorMessage_ComponentItemsRequried,
                    color: NotificationColor.Bad,
                    icon: this.Icon);
                return;
            }

            this.CallServer(_ => _.ServerRemote_BuildReactor(worldObjectGenerator, reactorIndex));
        }