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

            Logger.Important($"Hacking completed: {worldObject} by {character}", character);

            var characterPrivateState = PlayerCharacter.GetPrivateState(character);

            if (characterPrivateState.CurrentActionState != state)
            {
                Logger.Error("Should be impossible - current action state state doesn't match");
                return;
            }

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

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

            if (worldObject.ProtoGameObject is not IProtoObjectHackableContainer)
            {
                throw new Exception("Not a hackable container: " + worldObject);
            }

            var characterPrivateState = PlayerCharacter.GetPrivateState(character);

            if (characterPrivateState.CurrentActionState is HackingActionState actionState &&
                actionState.WorldObject == worldObject)
            {
                // already hacking
                return;
            }

            actionState = new HackingActionState(character, (IStaticWorldObject)worldObject);

            if (!actionState.CheckIsNeeded())
            {
                // action is not needed
                Logger.Important($"Hacking is not required: {worldObject} by {character}", character);
                return;
            }

            characterPrivateState.SetCurrentActionState(actionState);

            Logger.Important($"Hacking started: {worldObject} by {character}", character);

            if (IsClient)
            {
                Instance.CallServer(_ => _.ServerRemote_StartAction(worldObject));
            }
        }